<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 — 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"> <xsl:template name="length-in-points"> <xsl:param name="length" select="'0pt'"></xsl:param> <xsl:param name="em.size" select="10"></xsl:param> <xsl:param name="pixels.per.inch" select="90"></xsl:param> <xsl:variable name="magnitude"> <xsl:call-template name="length-magnitude"> <xsl:with-param name="length" select="$length"></xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:variable name="units"> <xsl:value-of select="substring($length, string-length($magnitude)+1)"></xsl:value-of> </xsl:variable> <xsl:choose> <xsl:when test="$units = 'pt'"> <xsl:value-of select="$magnitude"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'cm'"> <xsl:value-of select="$magnitude div 2.54 * 72.0"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'mm'"> <xsl:value-of select="$magnitude div 25.4 * 72.0"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'in'"> <xsl:value-of select="$magnitude * 72.0"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'pc'"> <xsl:value-of select="$magnitude * 12.0"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'px'"> <xsl:value-of select="$magnitude div $pixels.per.inch * 72.0"></xsl:value-of> </xsl:when> <xsl:when test="$units = 'em'"> <xsl:value-of select="$magnitude * $em.size"></xsl:value-of> </xsl:when> <xsl:otherwise> <xsl:message> <xsl:text>Unrecognized unit of measure: </xsl:text> <xsl:value-of select="$units"></xsl:value-of> <xsl:text>.</xsl:text> </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template> </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>