/usr/share/doc/xgridfit/html/if.html is in xgridfit-doc 2.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>xgridfit</title>
<link rel="stylesheet" href="oeg.css" media="screen" type="text/css" />
<link rel="stylesheet" href="parchment.css" media="screen"
type="text/css" title="parchment" />
<link rel="alternate stylesheet" href="legible.css" media="screen"
type="text/css" title="legible" />
<style type="text/css" media="print"> @import "oeg.print.css"; </style>
<meta name="AUTHOR" content="Peter S. Baker" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="jumplist">
<a href="http://sourceforge.net"><img src="" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a>
<a href="http://xgridfit.sourceforge.net/">Home Page</a>
<a href="http://sourceforge.net/projects/xgridfit">Project Page</a>
<a href="http://sourceforge.net/project/showfiles.php?group_id=159705">Download</a>
<a href="http://xgridfit.cvs.sourceforge.net/xgridfit/xgridfit/">CVS repository</a>
<hr/>
<a href="#if-el"><if></a>
<a href="#compile-if"><compile-if></a>
<a href="#looping">Looping</a>
</div>
<div id="content">
<h1>Conditional Execution and Looping</h1>
<h2 id="if-el">The <if> element</h2>
<p>
Xgridfit's mechanism for executing code conditionally is simple:
the <if> element contains code that is executed if the
expression in the <tt>test</tt> attribute evaluates as true
(non-zero):
</p>
<pre>
<if test="pixels-per-em &lt; 20">
<!-- execute code -->
</if>
</pre>
<p>
The <if> element may also contain an <else> element at
the end; this is executed only if <tt>test</tt> evaluates as false
(zero):
</p>
<pre>
<if test="pixels-per-em &lt; 20">
<!-- do this if test is true -->
<else>
<!-- do this if test is false -->
</else>
</if>
</pre>
<p>
Xgridfit's <if> element resembles the XSLT's <if>
(though <else> is an addition). Remember, when writing the
<tt>test</tt> attribute, that Xgridfit requires operators in
expressions to be surrounded by whitespace.
</p>
<p>
You should also be aware that the TrueType engine frequently
executes code conditionally even without the explicit use of
<if>. The <a href="cvt.html#cut-in-expl">control value
cut-in</a> is consulted to determine whether to use a measurement
from the original outline or one from the Control Value Table in
moving points, and the (apparently) little-used <a
href="reference.html#set-single-width-cut-in">single-width
cut-in</a> is similar. Every <a
href="deltas.html#delta-set"><delta-set></a> represents code
that is executed conditionally--a point is moved only at a
particular resolution.
</p>
<h2 id="compile-if">The <compile-if> element</h2>
<p>
The <compile-if> element provides for conditional
compilation: the code inside the element is compiled only if the
expression in the <tt>test</tt> attribute evaluates to "true"
(non-zero) at compile time. The <tt>test</tt> attribute may
contain only expressions that can be evaluated at compile time:
constants, number literals, control values (indexes only). Only a
few operators are permitted: <tt>+ - = != &gt; &lt;
&gt;= &lt;= or and not</tt>.
</p>
<p>
<compile-if> is allowed anywhere that other programming is
allowed (except within a <move> element), and can contain
any other programming (including other <compile-if>
elements). Here's a simple example:
</p>
<pre>
<macro name="anchor-to-baseline">
<param name="pt"/>
<param name="pt2" value="-1"/>
<param name="pt3" value="-1"/>
<move distance="baseline" round="no" cut-in="no">
<point num="pt"/>
</move>
<compile-if test="pt2 &gt;= 0">
<align>
<point num="pt2"/>
</align>
</compile-if>
<compile-if test="pt3 &gt;= 0">
<align>
<point num="pt3"/>
</align>
</compile-if>
</macro>
</pre>
<p>
This macro anchors one, two or three points to the baseline so
that they won't be moved later. The param "pt" is required: it is
a point that is always moved by the first "move" element. Params
"pt2" and "pt3" are optional; they have impossible default
values. But if reasonable point numbers are passed to the macro
for "pt2" and "pt3" then the two "align" elements are
compiled. Here are a couple of calls to the macro:
</p>
<pre>
<call-macro name="anchor-to-baseline">
<with-param name="pt" value="bottom-left"/>
</call-macro>
<call-macro name="anchor-to-baseline">
<with-param name="pt" value="bottom-left"/>
<with-param name="pt2" value="bottom-mid"/>
<with-param name="pt3" value="bottom-right"/>
</call-macro>
</pre>
<p>
Another way to compile code conditionally is to include the
<tt>compile-if</tt> attribute on a <move>, <align>,
<interpolate>, <shift> or <delta> element. These
are the elements that can be nested inside a <move>, where
the <compile-if> element is not allowed. Using this
attribute, we can rewrite the "anchor-to-baseline" macro as
follows:
</p>
<pre>
<macro id="anchor-to-baseline">
<param name="pt"/>
<param name="pt2" value="-1"/>
<param name="pt3" value="-1"/>
<move distance="baseline" round="no" cut-in="no">
<point num="pt"/>
<align compile-if="pt2 &gt;= 0 and pt3 &lt; 0">
<point num="pt2"/>
</align>
<align compile-if="pt2 &gt;= 0 and pt3 &gt;= 0">
<point num="pt2"/>
<point num="pt3"/>
</align>
</move>
</macro>
</pre>
<p>
The advantage of this method is that it enables the Good
Programming Practice of building blocks of code around the visible
features of a glyph while still permitting conditional
compilation. It also produces slightly more compact and efficient
code than the earlier example. The disadvantage is that it is
somewhat more awkward to write three different <align>
elements. However, it may well be worth doing so in a macro.
</p>
<p>
You may include, as the last child of a <compile-if>
element, an <else> element containing code to
compile if <tt>test</tt> evaluates as false. This works the same
way as the <else> clause in an <if> element.
</p>
<h2 id="looping">Looping</h2>
<p>
Xgridfit does not have an explicit looping mechanism such as the
for-loop of C and other languages. Certain TrueType instructions
can loop through a collection of points; Xgridfit exploits this
capability and extends it by allowing more than one <point>
or <range> element to be included in an <align>,
<shift>, <interpolate>, or <toggle-points>
element (the <range> element is itself a looping
mechanism). Xgridfit exploits other looping mechanisms of TrueType
when it allows more than one <delta-set> in a <delta>
or <control-value-delta> element and more than one
<param-set> in a <call-function> element.
</p>
</div>
</body>
</html>
|