Re: [docbook-apps] Fitting tall images in PDF

From
<>
Date
2014-01-06T19:57:47+00:00
ID
Thread
Re: [docbook-apps] Fitting tall images in PDF
Bob,

These are a great start. I am interested in this because I currently use a 
hack to use a full page landscape figure. We use a landscape mechanical drawing 
rotated to fit on a letter page. To do this I have to use a PI :

 

     <!-- ============== Flipping a figure 90 
degrees - Landscape  ================== 
     Use it 
this way
     
<figure>
           
<?landscapeFigure?><title>My figure 
title</title>
               
...
      
</figure>
     -->
    
<xsl:template 
match="figure[processing-instruction('landscapeFigure')]">
     
<fo:block-container 
reference-orientation="90"
          
margin-left="0in" 
margin-right="0in"
          
margin-top="0.25in" 
margin-bottom="0in"
          
padding-top="0in" padding-bottom="0in" display-align="before"> 

       
<xsl:apply-imports/>
    
</fo:block-container>
</xsl:template>

Then use scalefit=1 and width=100% to get it to full page with a caption. 
Using the scale-up-to-fit attribute could alleviate some of these hacks that I 
use.

 

My 2 cents.

 

 

Regards,

Dean Nelson 

 

In a message dated 1/6/2014 9:59:03 A.M. Pacific Standard Time, 
 writes:

> 
  Really this should be a feature of the stock xslts though.

Indeeed, 
  Antenna House also supports it since version 6.  Any 
suggestions 
  about how to fit this feature into the XSL? Here are some 
requirements 
  that I see:

1.  It needs to support "scale-up-to-fit" values as 
  well, and both 
values supported on either content-height or 
  content-width.

2.  I think we need to be able to specify it for an 
  individual image as 
well as for the global default behavior if no other 
  scaling is specified.

3.  For an individual image, setting 
  @contentwidth="scale-down-to-fit" 
in imagedata could work, since that 
  attribute accepts CDATA (while 
@scalefit in DocBook 5 does not).  
  Same for contentdepth.  But what 
happens with this value in HTML 
  output?

4.  The global setting should be controlled by a param for 
  backwards 
compatibility, but should there be separate params for 
  content-width and 
content-height?  I think so.

5.  For 
  global fallback, we already have an empty $default.image.width 
param which 
  could be set to either value.  We would have to add a 
  
$default.image.depth.

Any other thoughts or 
  requirements?

Here is the current template that contains the logic for 
  setting 
@content-width in the XSL-FO:

<xsl:template 
  name="image.content.width">
   <xsl:param name="scalefit" 
  select="0"/>
   <xsl:param name="scale" 
  select="'1.0'"/>

   <xsl:choose>
  
     <xsl:when test="$ignore.image.scaling != 
  0">auto</xsl:when>
     <xsl:when 
  test="contains(@contentwidth,'%')">
       
  <xsl:value-of select="@contentwidth"/>
     
  </xsl:when>
     <xsl:when 
  test="@contentwidth">
       <xsl:call-template 
  name="length-spec">
         <xsl:with-param 
  name="length" select="@contentwidth"/>
         
  <xsl:with-param name="default.units" select="'px'"/>
    
     </xsl:call-template>
     
  </xsl:when>
     <xsl:when test="number($scale) != 
  1.0">
       <xsl:value-of select="$scale * 
  100"/>
       
  <xsl:text>%</xsl:text>
     
  </xsl:when>
     <xsl:when test="$scalefit = 
  1">scale-to-fit</xsl:when>
     
  <xsl:otherwise>auto</xsl:otherwise>
   
  </xsl:choose>
</xsl:template>

I think adding these 
  clauses after the second test would handle a 
specific 
  instance:

<xsl:when test="@contentwidth = 
  
'scale-down-to-fit'">scale-down-to-fit</xsl:when>
<xsl:when 
  test="@contentwidth = 
  
'scale-up-to-fit'">scale-up-to-fit</xsl:when>

And this for 
  default behavior, added before the $scale clause:

<xsl:when 
  test="$default.image.width != ''"><xsl:value-of 
  
select="$default.image.width"/></xsl:when>

Does that look 
  right?

-- 
Bob Stayton
Sagehill 
  Enterprises


On 1/6/2014 7:09 AM, David Cramer 
  wrote:
> Hi Mark,
> I'd edit the fo and run it through your fo 
  processor to confirm that
> scale-down-to-fit gives the result you 
  want.
>
> For production you'll want to customize the templates 
  from graphics.xsl
> to make the right stuff come out in the fo. In 
  particular the templates
> <xsl:template 
  name="image.content.width"> and <xsl:template
> 
  name="image.content.height"> are important.
>
> Really this 
  should be a feature of the stock xslts though.
>
> 
  Regards,
> David
>
> On 01/05/2014 03:58 AM, Mark Craig 
  wrote:
>> Thanks Bob and David,
>>
>> What's the 
  right way to pass the "scale-down-to-fit" attribute value
>> into the 
  FO?
>>
>> I've tried adding them as attributes on 
  <imagedata> with some XSL that I
>> was using before to handle 
  wide images. Here's the template where
>> 
  xmlns:db="http://docbook.org/ns/docbook" 
  exclude-result-prefixes="db":
>>
>>   
  <xsl:template match="db:imagedata">
>>    
  <xsl:element name="imagedata" 
  namespace="http://docbook.org/ns/docbook">
>>     
  <xsl:apply-templates select="node()|@*"/>
>>     
  <xsl:attribute 
  name="contentdepth">scale-down-to-fit</xsl:attribute>
>>  
     <xsl:attribute 
  name="contentwidth">scale-down-to-fit</xsl:attribute>
>>  
     <xsl:attribute 
  name="align">center</xsl:attribute>
>>    
  </xsl:element>
>>   
  </xsl:template>
>>
>> After this transformation and 
  running the stylesheets,
>> text-align="center" shows up in the 
  resulting .fo, but the others are
>> null: content-width="" 
  content-height="".
>>
>> Is there a stylesheet customization 
  I should apply to allow those
>> attribute values to pass through to 
  the FO?
>>
>> Or do I need to edit the FO after it gets 
  generated?
>>
>> Regards,
>> Mark
>
> 
  ---------------------------------------------------------------------
> 
  To unsubscribe, e-mail: 
> 
  For additional commands, e-mail: 
  
>
>
>
>

---------------------------------------------------------------------
To 
  unsubscribe, e-mail: 
For 
  additional commands, e-mail: