Re: Patch III - I hope the last
nico <[email protected]> Mon, 30 May 2005 21:20:22 +0200
| Newsgroups | gmane.text.docbook.db2latex.devel |
|---|---|
| Message-ID | <opsrlrz8kp9niby6@localhost> |
------------6l2j4dehyTShy1alABSRoz
Content-Type: text/plain; format=flowed; delsp=yes; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Hello,
>
> I added a support for the scalefit and align=3D"center" attribute of
> graphic of DocBook. The scalefit attribute crates a resizebox which
> makes the graphic to the size of the column (\columnwidth). maybe this
> should overwritten, in a costum style sheet.
> If the width and the height are specified, a bb=3D attibut is appended =
to
> the \includegraphics command. this is important for rendering png image=
s
> with LaTeX.
> The scalefit and the width attribut is abused, actuallay the semantic o=
f
> this paramters is different, but it works mostly in a way a user would
> expect. The height parameter does not exist in DocBook and the
> validation should fail ... There should be a better solution.
I would suggest to use directly the \includegraphics options. Example:
\includegraphics[scale=3D0.5,width=3D5cm,height=3D10cm,keepaspectratio=3D=
true]
Please find attached the stylesheet I use to render <imagedata>. Most of =
=20
the imagadata attributes combinations are supported. Any comment is =20
welcome.
Regards,
BG
------------6l2j4dehyTShy1alABSRoz
Content-Disposition: attachment; filename=mediaobject.xsl
Content-Type: application/octet-stream; name=mediaobject.xsl
Content-Transfer-Encoding: quoted-printable
<?xml version=3D'1.0'?>
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" versio=
n=3D'1.0'>
<!--#####################################################################=
#######
XSLT Stylesheet DocBook -> LaTeX=20
#####################################################################=
####### -->
<xsl:template match=3D"videoobject">
<xsl:apply-templates select=3D"videodata"/>
</xsl:template>
<xsl:template match=3D"audioobject">
<xsl:apply-templates select=3D"audiodata"/>
</xsl:template>
<xsl:template match=3D"textobject">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match=3D"mediaobject|inlinemediaobject">
<!--
within a figure don't put each mediaobject into a separate paragraph,=20
to let the subfigures correctly displayed.
-->
<xsl:if test=3D"self::mediaobject and not(parent::figure)">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test=3D"imageobject">
<xsl:apply-templates select=3D"imageobject[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select=3D"textobject[1]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test=3D"self::mediaobject and not(parent::figure)">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match=3D"imageobject">
<xsl:variable name=3D"figcount"
select=3D"count(ancestor::figure/mediaobject[imageobject]=
)"/>
<xsl:if test=3D"$figcount > 1">
<!-- space before subfigure to prevent from strange behaviour with ot=
her
subfigures -->
<xsl:text> \subfigure[</xsl:text>
<xsl:value-of select=3D"../caption"/>
<xsl:text>]{</xsl:text>
</xsl:if>
<xsl:if test=3D"$latex.figure.boxed =3D '1'">
<xsl:text>\fbox{</xsl:text>
</xsl:if>
<xsl:apply-templates select=3D"imagedata"/>
<xsl:if test=3D"$latex.figure.boxed =3D '1'">
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:if test=3D"$figcount > 1">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name=3D"unit.eval">
<xsl:param name=3D"length"/>
<xsl:param name=3D"prop" select=3D"''"/>
<xsl:choose>
<!-- percentage of something -->
<xsl:when test=3D"contains($length, '%') and substring-after($length, '=
%')=3D''">
<xsl:value-of select=3D"number(substring-before($length, '%')) div 10=
0"/>
<xsl:value-of select=3D"$prop"/>
</xsl:when>
<!-- pixel unit is not handled -->
<xsl:when test=3D"contains($length, 'px') and substring-after($length, =
'px')=3D''">
<xsl:message>Pixel unit not handled (replaced by pt)</xsl:message>
<xsl:value-of select=3D"number(substring-before($length, 'px'))"/>
<xsl:text>pt</xsl:text>
</xsl:when>
<!-- no unit provided means pixel -->
<xsl:when test=3D"$length and (number($length)=3D$length)">
<xsl:message>Pixel unit not handled (replaced by pt)</xsl:message>
<xsl:value-of select=3D"$length"/>
<xsl:text>pt</xsl:text>
</xsl:when>
<!-- hope the unit is handled -->
<xsl:otherwise>
<xsl:value-of select=3D"$length"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match=3D"imagedata" name=3D"imagedata">
<xsl:variable name=3D"filename">
<xsl:choose>
<xsl:when test=3D"@fileref">
<xsl:value-of select=3D"@fileref"/>
</xsl:when>
<xsl:when test=3D"@entityref">
<xsl:value-of select=3D"unparsed-entity-uri(@entityref)"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name=3D"width">
<xsl:call-template name=3D"unit.eval">
<xsl:with-param name=3D"length" select=3D"@width"/>
<xsl:with-param name=3D"prop" select=3D"'\linewidth'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name=3D"depth">
<xsl:call-template name=3D"unit.eval">
<xsl:with-param name=3D"length" select=3D"@depth"/>
<xsl:with-param name=3D"prop" select=3D"'\textheight'"/>
</xsl:call-template>
</xsl:variable>
<!-- viewport is valid only if there's some viewport spec, and content =
or scale.
TDG says that viewport spec without content/scale and scalefit=3D0=
is ignored. -->
<xsl:variable name=3D"viewport">
<xsl:choose>
<xsl:when test=3D"(@width or @depth) and (@contentwidth or @contentde=
pth or @scale)">
<xsl:value-of select=3D"1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=3D"0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:text>{</xsl:text>
<xsl:if test=3D"$viewport=3D1">
<xsl:text>\begin{minipage}[c]</xsl:text>
<xsl:if test=3D"@depth">
<!-- depth -->
<xsl:text>[</xsl:text>
<xsl:value-of select=3D"$depth"/>
<xsl:text>]</xsl:text>
<xsl:text>[</xsl:text>
<!-- vertical alignment (meaningfull only with depth) -->
<xsl:choose>
<xsl:when test=3D"@valign=3D'bottom'">
<xsl:text>b</xsl:text>
</xsl:when>
<xsl:when test=3D"@valign=3D'middle'">
<xsl:text>c</xsl:text>
</xsl:when>
<xsl:when test=3D"@valign=3D'top'">
<xsl:text>t</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>c</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>]</xsl:text>
</xsl:if>
<!-- width -->
<xsl:text>{</xsl:text>
<xsl:choose>
<xsl:when test=3D"@width">
<xsl:value-of select=3D"$width"/>
</xsl:when>
<xsl:when test=3D"ancestor::mediaobject">
<xsl:text>\linewidth</xsl:text>
</xsl:when>
<!-- TODO: inline viewport area should be as wide as the graphic -->
<!-- <xsl:text>\figwidth</xsl:text> -->
<xsl:otherwise>
<xsl:text>\linewidth</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>} </xsl:text>
</xsl:if>
<!-- horizontal alignment -->
<xsl:choose>
<xsl:when test=3D"@align=3D'center'">
<xsl:text>\centering </xsl:text>
</xsl:when>
<xsl:when test=3D"@align=3D'left'">
<xsl:text>\raggedright </xsl:text>
</xsl:when>
<xsl:when test=3D"@align=3D'right'">
<xsl:text>\raggedleft </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:text>{\includegraphics[</xsl:text>
<!-- TDG says that content, scale and scalefit are mutually exclusive -=
->
<xsl:choose>
<!-- content area spec -->
<xsl:when test=3D"@contentwidth or @contentdepth">=20
<xsl:choose>
<xsl:when test=3D"contains(@contentwidth, '%') and
substring-after(@contentwidth, '%')=3D''">
<xsl:text>scale=3D</xsl:text>
<xsl:value-of select=3D"number(substring-before(@contentwidth, '%=
')) div 100"/>
</xsl:when>
<xsl:when test=3D"contains(@contentdepth, '%') and
substring-after(@contentdepth, '%')=3D''">
<xsl:text>scale=3D</xsl:text>
<xsl:value-of select=3D"number(substring-before(@contentdepth, '%=
')) div 100"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test=3D"@contentwidth">
<xsl:text>width=3D</xsl:text>
<xsl:call-template name=3D"unit.eval">
<xsl:with-param name=3D"length" select=3D"@contentwidth"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:if test=3D"@contentdepth">
<xsl:text>height=3D</xsl:text>
<xsl:call-template name=3D"unit.eval">
<xsl:with-param name=3D"length" select=3D"@contentdepth"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- scaling -->
<xsl:when test=3D"@scale">=20
<xsl:text>scale=3D</xsl:text>
<xsl:value-of select=3D"number(@scale) div 100"/>
</xsl:when>
<!-- only viewport area spec with scalefit -->
<xsl:when test=3D"not(@scalefit) or @scalefit=3D'1'">
<xsl:if test=3D"@width">
<xsl:text>width=3D</xsl:text>
<xsl:value-of select=3D"$width"/>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:if test=3D"@depth">
<xsl:text>height=3D</xsl:text>
<xsl:value-of select=3D"$depth"/>
<xsl:text>,</xsl:text>
</xsl:if>
<!-- TDG says that scale to fit cannot be anamorphic -->
<xsl:text>keepaspectratio=3Dtrue</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:if test=3D"@format =3D 'PRN'">
<xsl:text>,angle=3D270</xsl:text>
</xsl:if>
<xsl:text>]{</xsl:text>
<xsl:value-of select=3D"$filename"/>
<xsl:text>}}\quad </xsl:text>
<xsl:if test=3D"$viewport=3D1">
<xsl:text>\end{minipage} </xsl:text>
</xsl:if>
<xsl:text>} </xsl:text>
</xsl:template>
</xsl:stylesheet>
------------6l2j4dehyTShy1alABSRoz--
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005