Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 9f452694b2d23dacae7f9cc757f9be50 > files > 929

docbook-style-xsl-1.78.1-1.fc17.noarch.rpm

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>length-in-points</title><link rel="stylesheet" type="text/css" href="../reference.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="../index.html" title="DocBook XSL Stylesheets: Reference Documentation"><link rel="up" href="generallibrary.html" title="General Library Templates"><link rel="prev" href="length-spec.html" title="length-spec"><link rel="next" href="pi-attribute.html" title="pi-attribute"><link rel="copyright" href="copyright.html" title="License"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">length-in-points</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="length-spec.html">Prev</a> </td><th width="60%" align="center">General Library Templates</th><td width="20%" align="right"> <a accesskey="n" href="pi-attribute.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="length-in-points"></a><div class="titlepage"></div>
<div class="refnamediv"><h2>length-in-points</h2><p>
length-in-points
 &#8212; Returns the size, in points, of a specified length
</p></div>

<div class="refsect1"><a name="idp9540224"></a><h2>Description</h2>

<p>The <code class="function">length-in-points</code> template converts a length
specification to points and returns that value as an unqualified
number.
</p>

<div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3>
<p>There is no way for the template to infer the size of an
<code class="literal">em</code>. It relies on the default <em class="parameter"><code>em.size</code></em>
which is initially <code class="literal">10</code> (for 10pt).</p>

<p>Similarly, converting pixels to points relies on the
<a href="../html/pixels.per.inch.html"><em class="parameter"><code>pixels.per.inch</code></em></a> parameter which is initially
<code class="literal">90</code>.
</p>
</div>

<a name="length-in-points.frag"></a><pre class="programlisting">
&lt;xsl:template name="length-in-points"&gt;
  &lt;xsl:param name="length" select="'0pt'"&gt;&lt;/xsl:param&gt;
  &lt;xsl:param name="em.size" select="10"&gt;&lt;/xsl:param&gt;
  &lt;xsl:param name="pixels.per.inch" select="90"&gt;&lt;/xsl:param&gt;

  &lt;xsl:variable name="magnitude"&gt;
    &lt;xsl:call-template name="length-magnitude"&gt;
      &lt;xsl:with-param name="length" select="$length"&gt;&lt;/xsl:with-param&gt;
    &lt;/xsl:call-template&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:variable name="units"&gt;
    &lt;xsl:value-of select="substring($length, string-length($magnitude)+1)"&gt;&lt;/xsl:value-of&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:choose&gt;
    &lt;xsl:when test="$units = 'pt'"&gt;
      &lt;xsl:value-of select="$magnitude"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'cm'"&gt;
      &lt;xsl:value-of select="$magnitude div 2.54 * 72.0"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'mm'"&gt;
      &lt;xsl:value-of select="$magnitude div 25.4 * 72.0"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'in'"&gt;
      &lt;xsl:value-of select="$magnitude * 72.0"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'pc'"&gt;
      &lt;xsl:value-of select="$magnitude * 12.0"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'px'"&gt;
      &lt;xsl:value-of select="$magnitude div $pixels.per.inch * 72.0"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:when test="$units = 'em'"&gt;
      &lt;xsl:value-of select="$magnitude * $em.size"&gt;&lt;/xsl:value-of&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:message&gt;
        &lt;xsl:text&gt;Unrecognized unit of measure: &lt;/xsl:text&gt;
        &lt;xsl:value-of select="$units"&gt;&lt;/xsl:value-of&gt;
        &lt;xsl:text&gt;.&lt;/xsl:text&gt;
      &lt;/xsl:message&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;
</pre>

</div>
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="length-spec.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="generallibrary.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pi-attribute.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">length-spec </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> pi-attribute</td></tr></table></div></body></html>