colored the example source code and corrected some typos
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
diff --git a/docs/internals/io-frames.html b/docs/internals/io-frames.html
index 923085c..61ad381 100644
--- a/docs/internals/io-frames.html
+++ b/docs/internals/io-frames.html
@@ -20,76 +20,79 @@ FreeType 2.0 I/O Frames</h1></center>
<center>
<h3>
-© 2000 David Turner (<a href="fichier :///david@freetype.org">david@freetype.org</a>)<br>
-© 2000 The FreeType Development Team (<a href="fichier :///devel@freetype.org">devel@freetype.org</a>)</h3></center>
+© 2000 David Turner (<a href="mailto:david@freetype.org">david@freetype.org</a>)<br>
+© 2000 The FreeType Development Team (<a href="http://www.freetype.org">www.freetype.org</a>)</h3></center>
<p><br>
<hr WIDTH="100%">
<br>
<h2>Introduction:</h2>
<ul>
- This document explains the concept of i/o <b>frames</b> as used in the FreeType 2
- source code. It also enumerates the various functions and macros that can be used
- to read them.
- <p>
- It is targetted to FreeType hackers, or more simply to developers who would like
- a better understanding of the library's source code.
+ This document explains the concept of i/o <b>frames</b> as used in the
+ FreeType 2 source code. It also enumerates the various functions and macros
+ that can be used to read them.
+ <p>
+ It is targetted to FreeType hackers, or more simply to developers who would
+ like a better understanding of the library's source code.
</ul>
<p><hr><p>
<h2>I. What frames are:</h2>
<ul>
- Simply speaking, a frame is an array of bytes in a font file that is "preloaded"
- into memory in order to be rapidly parsed. Frames are useful to ensure that every
- "load" is checked against end-of-file overruns, and provides nice functions
- to extract data in a variety of distinct formats.
- <p>
- But an example is certainly more meaningful than anything else:<p>
- <ul>
- <ul>
- <tt>error = read_short(stream, &str.value1);<br>
- <tt>if (error) goto ...<br>
- <br>
- <tt>error = read_ulong(stream, &str.value2);<br>
- <tt>if (error) goto ...<br>
- <br>
- <tt>error = read_ulong(stream, &str.value3);<br>
- <tt>if (error) goto ...<br>
- </ul>
- <p>
- can easily be replaced with:<p>
- <ul>
- <tt>error = FT_Access_Frame(stream, 2+4+4);<br>
- <tt>if (error) goto ...<br>
- <br>
- <tt>str.value1 = FT_Get_Short(stream);<br>
- <tt>str.value2 = FT_Get_ULong(stream);<br>
- <tt>str.value3 = FT_Get_ULong(stream);<br>
- <br>
- <tt>FT_Forget_Frame(stream);<br>
- </ul>
- <p>
- </ul>
- Here, the call to <tt>FT_Access_Frame</tt> will:<p>
- <ul>
- <li>Ensure that there are at least 2+4+4=10 bytes left in the stream.
- <li>"Preload" (for disk-based streams) 10 bytes from the current stream position.
- <li>Set the frame "cursor" to the first byte in the frame;
- </ul>
- <p>
- Each <tt>FT_Get_Short</tt> or <tt>FT_Get_ULong</tt> call will read a big-endian integer
- from the stream (2 bytes for <tt>FT_Get_Short</tt>, 4 bytes for <tt>FT_Get_ULong</tt>)
- and advance the frame cursor accordingly.
- <p>
- <tt>FT_Forget_Frame</tt> "releases" the frame from memory
- <p>
- There are several advantages to using frames :<p>
- <ul>
- <li>single-check when loading tables
- <li><em>making code clearer</em> by providing simple parsing functions.
- </ul>
- <p>
+ Simply speaking, a frame is an array of bytes in a font file that is
+ "preloaded" into memory in order to be rapidly parsed. Frames are useful to
+ ensure that every "load" is checked against end-of-file overruns, and
+ provides nice functions to extract data in a variety of distinct formats.
+ <p>
+ But an example is certainly more meaningful than anything else.
+ The following code:
+ <p>
+ <font color="blue"><pre>
+ error = read_short(stream, &str.value1);
+ if (error) goto ...
+
+ error = read_ulong(stream, &str.value2);
+ if (error) goto ...
+
+ error = read_ulong(stream, &str.value3);
+ if (error) goto ...
+ </pre></font>
+ can easily be replaced with:
+ <p>
+ <font color="blue"><pre>
+ error = FT_Access_Frame(stream, 2+4+4);
+ if (error) goto ...
+
+ str.value1 = FT_Get_Short(stream);
+ str.value2 = FT_Get_ULong(stream);
+ str.value3 = FT_Get_ULong(stream);
+
+ FT_Forget_Frame(stream);
+ </pre></font>
+ <p>
+ Here, the call to <tt>FT_Access_Frame</tt> will:<p>
+ <ul>
+ <li>Ensure that there are at least 2+4+4=10 bytes left in the stream.
+ <li>"Preload" (for disk-based streams) 10 bytes from the current
+ stream position.
+ <li>Set the frame "cursor" to the first byte in the frame;
+ </ul>
+ <p>
+ Each <tt>FT_Get_Short</tt> or <tt>FT_Get_ULong</tt> call will read a
+ big-endian integer from the stream (2 bytes for <tt>FT_Get_Short</tt>,
+ 4 bytes for <tt>FT_Get_ULong</tt>) and advance the frame cursor accordingly.
+ <p>
+ <tt>FT_Forget_Frame</tt> "releases" the frame from memory
+ <p>
+ There are several advantages to using frames :<p>
+ <ul>
+ <li>single-check when loading tables
+ <li><em>making code clearer</em> by providing simple parsing functions
+ <em>while keeping code safe</em> from file over-runs and invalid
+ offsets.
+ </ul>
+ <p>
</ul>
<p><hr><p>
@@ -101,58 +104,112 @@ FreeType 2.0 I/O Frames</h1></center>
these two variables are extremely used in the library, and doing this only
reduces our typing requirements and make the source code much clearer.
<p>
- <tt>error</tt> must be a local variable of type <tt>FT_Error</tt>,
+ Note that <tt>error</tt> must be a local variable of type <tt>FT_Error</tt>,<br>
while <tt>stream</tt> must be a local variable or argument of type <tt>FT_Stream</tt>;
<p>
- The macro used to access a frame is <tt>ACCESS_Frame(_size_)</tt>, it will
+ The macro used to access a frame is
+ <font color="purple"><tt><b>ACCESS_Frame(_size_)</b></tt></font>, it will
translate to:<p>
- <ul>
+ <ul><font color="blue">
<tt>(error=FT_Access_Frame(stream,_size_)) != FT_Err_Ok</tt>.
- </ul>
+ </font></ul>
<p>
- Similarly, the macro <tt>FORGET_Frame()</tt> translates to:<o>
- <ul>
+ Similarly, the macro
+ <font color="purple"><b><tt>FORGET_Frame()</tt></b></font>
+ translates to:<p>
+ <ul><font color="blue">
<tt>FT_Forget_Frame(stream)</tt>
- </ul>
+ </font></ul>
<p>
Extracting integers can be performed with the <tt>GET_xxx</tt> macros, like:<p>
<ul>
<table>
- <tr><td><tt><b>GET_Byte()</b></tt> <td>FT_Get_Byte(stream)
- <tr><td><tt><b>GET_Char()</b></tt> <td>((FT_Char)FT_Get_Byte(stream))
- <tr><td><tt><b>GET_Short()</b></tt> <td>FT_Get_Short(stream)
- <tr><td><tt><b>GET_UShort()</b></tt> <td>((FT_UShort)FT_Get_Short(stream))
- <tr><td><tt><b>GET_Offset()</b></tt> <td>FT_Get_Offset(stream)
- <tr><td><tt><b>GET_UOffset()</b></tt> <td>((FT_ULong)FT_Get_Offset(stream))
- <tr><td><tt><b>GET_Long()</b></tt> <td>FT_Get_Long(stream)
- <tr><td><tt><b>GET_ULong()</b></tt> <td>((FT_ULong)FT_Get_Long(stream))
+ <tr>
+ <td><b>Macro name</b> <td>Translation <td>Description
+
+ <tr><td><font color="purple"><tt><b>
+ GET_Byte()
+ </b></tt></font><td><font color="blue"><tt>
+ (FT_Get_Byte(stream))
+ </tt></font><td>
+ reads an 8-bit unsigned byte
+
+ <tr><td><font color="purple"><tt><b>
+ GET_Char()
+ </b></tt></font><td><font color="blue"><tt>
+ ((FT_Char)FT_Get_Byte(stream))
+ </tt></font><td>
+ reads an 8-bit <em>signed</em> byte
+
+ <tr><td><font color="purple"><tt><b>
+ GET_Short()
+ </b></tt></font><td><font color="blue"><tt>
+ (FT_Get_Short(stream))
+ </tt></font><td>
+ reads a 16-bit signed big-endian integer
+
+ <tr><td><font color="purple"><tt><b>
+ GET_UShort()
+ </b></tt></font><td><font color="blue"><tt>
+ ((FT_UShort)FT_Get_Short(stream))
+ </tt></font><td>
+ reads a 16-bit unsigned big-endian integer
+
+ <tr><td><font color="purple"><tt><b>
+ GET_Offset()
+ </b></tt></font><td><font color="blue"><tt>
+ (FT_Get_Offset(stream))
+ </tt></font><td>
+ reads a 24-bit signed big-endian integer
+
+ <tr><td><font color="purple"><tt><b>
+ GET_UOffset()
+ </b></tt></font><td><font color="blue"><tt>
+ ((FT_UOffset)FT_Get_Offset(stream))
+ </tt></font><td>
+ reads a 24-bit unsigned big-endian integer
+
+ <tr><td><font color="purple"><tt><b>
+ GET_Long()
+ </b></tt></font><td><font color="blue"><tt>
+ (FT_Get_Long(stream))
+ </tt></font><td>
+ reads a 32-bit signed big-endian integer
+
+ <tr><td><font color="purple"><tt><b>
+ GET_ULong()
+ </b></tt></font><td><font color="blue"><tt>
+ ((FT_ULong)FT_Get_Long(stream))
+ </tt></font><td>
+ reads a 32-bit unsigned big-endian integer
+
</table>
</ul>
<p>
(Note that an <b>Offset</b> is an integer stored with 3 bytes on the file).
<p>
All this means that the following code:<p>
- <ul>
- <tt>error = FT_Access_Frame(stream, 2+4+4);<br>
- <tt>if (error) goto ...<br>
- <br>
- <tt>str.value1 = FT_Get_Short(stream);<br>
- <tt>str.value2 = FT_Get_ULong(stream);<br>
- <tt>str.value3 = FT_Get_ULong(stream);<br>
- <br>
- <tt>FT_Forget_Frame(stream);<br>
- </ul>
+ <font color="blue"><pre>
+ error = FT_Access_Frame(stream, 2+4+4);
+ if (error) goto ...
+
+ str.value1 = FT_Get_Short(stream);
+ str.value2 = FT_Get_ULong(stream);
+ str.value3 = FT_Get_ULong(stream);
+
+ FT_Forget_Frame(stream);<br>
+ </pre></font>
<p>
Can be replaced with macros by:<p>
- <ul>
- <tt>if ( ACCESS_Frame( 2+4+4 ) ) goto ...<br>
- <br>
- <tt>str.value1 = GET_Short();<br>
- <tt>str.value2 = GET_ULong();<br>
- <tt>str.value3 = GET_ULong();<br>
- <br>
- <tt>FORGET_Frame();<br>
- </ul>
+ <font color="blue"><pre>
+ if ( ACCESS_Frame( 2+4+4 ) ) goto ...
+
+ str.value1 = GET_Short();
+ str.value2 = GET_ULong();
+ str.value3 = GET_ULong();
+
+ FORGET_Frame();
+ </pre></font>
<p>
Which is clearer. Notice that <b>error</b> and <b>stream</b> must be defined
locally though for this code to work.. !!
@@ -162,26 +219,29 @@ FreeType 2.0 I/O Frames</h1></center>
<h2>III. Alternatives:</h2>
<ul>
- It is sometimes useful to read small integers from a font file without using
- a frame. Some functions have been introduced in FreeType 2 to do just that,
- and they are of the form <tt>FT_Read_xxxx</tt>.
- <p>
- For example, <tt>FT_Read_Short( stream, &error )</tt> reads and returns a 2-byte
- big-endian short from a <tt>stream</tt>, and place an error code in the <tt>error</tt>
- variable.
- <p>
- Thus, reading a single big-endian integer is shorter than using a frame for it.
- <p>
- Note that there is also the macros <tt>READ_xxx()</tt> which translate to:<p>
- <ul>
- <tt>( FT_Read_xxx(stream,&error), error != FT_Err_Ok )</tt>
- </ul>
- <p>
- and can be used as in:<p>
- <ul>
- <tt>if ( READ_UShort(variable1) || READ_ULong (variable2) ) goto Fail;</tt><br>
- </ul>
- <p>
- when <b>error</b> and <b>stream</b> are already defined locally..
+ It is sometimes useful to read small integers from a font file without using
+ a frame. Some functions have been introduced in FreeType 2 to do just that,
+ and they are of the form <font color="blue"><tt>FT_Read_xxxx</tt></font>.
+ <p>
+ For example,
+ <font color="blue"><tt>FT_Read_Short( stream, &error )</tt></font> reads and
+ returns a 2-byte big-endian integer from a <tt>stream</tt>, and place an
+ error code in the <tt>error</tt> variable.
+ <p>
+ Thus, reading a single big-endian integer is shorter than using a frame
+ for it.
+ <p>
+ Note that there is also the macros
+ <font color="purple"><tt>READ_xxx()</tt></font> which translate to:<p>
+ <font color="blue"><pre>
+ <tt>( FT_Read_xxx(stream,&error), error != FT_Err_Ok )
+ </pre></font>
+ <p>
+ and can be used as in:<p>
+ <font color="blue"><pre>
+ if ( READ_UShort(variable1) || READ_ULong (variable2) ) goto Fail;
+ </pre></font>
+ <p>
+ when <b>error</b> and <b>stream</b> are already defined locally..
</ul>