home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / documentation / documents / a252font < prev    next >
Text File  |  1999-04-27  |  25KB  |  549 lines

  1. > Fonts.Formats
  2.  
  3. Font File Formats
  4. -----------------
  5.  
  6. In all the formats described below, 2-byte quantities are little-endian:
  7. that is, the least significant byte comes first, followed by the
  8. most-significant.  The values are unsigned unless otherwise stated.
  9.  
  10.  
  11. IntMetrics / IntMet<n>:
  12.         
  13.         40      Name of font, padded with <cr>
  14.         4       16
  15.         4       16
  16.         1       nlo = low-byte of number of defined characters
  17.         1       version number of file format:
  18.                         0       flags and nhi must be 0
  19.                         1       **** not supported ****
  20.                         2       you can set the flags as described
  21.                                 and nchars can be > 255
  22.         1       flags:
  23.                 bit 0 set => there is no bbox data (use Outlines)
  24.                 bit 1 set => there is no x-offset data
  25.                 bit 2 set => there is no y-offset data
  26.                 bit 3 set => there is more data after the metrics
  27.                 bit 4 reserved (must be 0)
  28.                 bit 5 set => character map size precedes map
  29.                 bit 6 set => kern characters are 16-bit, else 8-bit
  30.                 bit 7 reserved (must be 0)
  31.         1       nhi = high byte of number of defined characters
  32.  
  33.                 n = nlo + 256*nhi
  34.  
  35.                 If flags bit 5 set:
  36.         2       m = character map size (lo,hi) (0 => no map)
  37.                 m = 256 if flags bit 5 clear
  38.  
  39.         m       character mapping (ie. indices into following arrays)
  40.                 if not present, index = character code
  41.  
  42.                 Note that since the mapping table is 8-bit, there cannot be
  43.                 one if n > 256.
  44.  
  45.                 Tables giving bounding boxes (1/1000th em) of characters:
  46.                 If flags bit 0 clear:
  47.         2n      signed x0 2-byte values
  48.         2n      signed y0 2-byte values
  49.         2n      signed x1 2-byte values
  50.         2n      signed y1 2-byte values
  51.  
  52.                 Tables of character widths:
  53.                 If flags bit 1 clear:
  54.         2n      signed 2-byte x-offsets after printing each character
  55.                 If flags bit 2 clear:
  56.         2n      signed 2-byte y-offsets after printing each character
  57.  
  58.  
  59.         To calculate offset to here:
  60.  
  61.                   nlo = byte at offset 48 in file
  62.                   nhi = byte at offset 51 in file
  63.                 flags = byte at offset 49 in file
  64.                     n = nlo + 256*nhi  ^^->Acorn, you mean 50 me thinks....
  65.  
  66.                 offset = 52
  67.                 if (flags bit 5 clear) then offset += 256
  68.                                        else offset += 2 + byte(52) + 256*byte(53)
  69.                 if (flags bit 0 clear) then offset += 8n
  70.                 if (flags bit 1 clear) then offset += 2n
  71.                 if (flags bit 2 clear) then offset += 2n
  72.  
  73.                 If flags bit 3 set:
  74.  
  75.         8       table of 4 2-byte unsigned offsets from start of table:
  76.                     entry 0 = offset to 'miscellaneous' data
  77.                     entry 1 = offset to kern pair data
  78.                     entry 2 = offset to reserved area #1
  79.                     entry 3 = offset to reserved area #2
  80.  
  81.                 The entries must be consecutive in the file, so the end of
  82.                 one area coincides with the beginning of the next.  The
  83.                 areas are not necessarily word-aligned, and the space at the
  84.                 end of each area is reserved (ie. there must not be any
  85.                 'dead' space at the end of an area).
  86.  
  87.         Area 0: Miscellaneous data:
  88.  
  89.         8       font bounding box in 1/1000th em (signed x0,y0,x1,y1)
  90.         2       default x-offset per char (if flags bit 1 set)
  91.         2       default y-offset per char (if flags bit 2 set)
  92.         2       italic h-offset per em (-1000 * TAN(italic angle))
  93.         1       underline position (signed, in 1/256th of an em)
  94.         1       underline thickness (unsigned, in 1/256th of an em)
  95.         2       CapHeight (1/1000th em, 2-byte signed)
  96.         2       XHeight (1/1000th em, 2-byte signed)
  97.         2       Descender (1/1000th em, 2-byte signed)
  98.         2       Ascender (1/1000th em, 2-byte signed)
  99.         4       reserved field (must be 0)
  100.  
  101.         Area 1: Kern pair data:
  102.  
  103.                 flags bit 6 clr => character codes are 8-bit
  104.                 flags bit 6 set => character codes are 16-bit (lo,hi)
  105.  
  106.         1 or 2  left-hand letter code                          ]
  107.         1 or 2  right-hand letter code                ]        ]
  108.         2       x-kern amount (if flags bit 1 clear)  ] repeat ] repeat
  109.         2       y-kern amount (if flags bit 2 clear)  ]        ]
  110.         1 or 2  0 => end of list for this letter               ]
  111.         1 or 2  0 => end of kerns
  112.  
  113.                 Or, in pseudo-Backus-Naur notation:
  114.  
  115.                   <kerns> ::= <kernsforaletter>* <letter 0>
  116.         <kernsforaletter> ::= <letter> <kernpair>* <letter 0>
  117.                <kernpair> ::= <letter> <x-offset> <y-offset>
  118.                  <letter> ::= <8-bit character code> if flags bit 6 clear
  119.                            or <16-bit character code> if flags bit 6 set
  120.                <x-offset> ::= <signed 16-bit offset in 1/1000 em>
  121.                            or <null> if flags bit 1 set
  122.                <y-offset> ::= <signed 16-bit offset in 1/1000 em>
  123.                            or <null> if flags bit 2 set
  124.                <letter 0> ::= <<letter> with code 0>
  125.  
  126.         Area 2: Reserved (must be null)
  127.  
  128.         Area 3: Reserved (must be null)
  129.  
  130.  
  131. x90y45:
  132.  
  133.         Index:
  134.                 1       point size (not multiplied by 16)
  135.                 1       bits per pixel (4)
  136.                 1       pixels per inch (x-direction)
  137.                 1       pixels per inch (y-direction)
  138.                 4       reserved (was checksum) - must be 0
  139.                 4       offset of pixel data in file
  140.                 4       size of pixel data
  141.                 ...     more of the same
  142.                 1       0
  143.  
  144.         Pixel data:
  145.                 4       x-size in 1/16ths point * pixels per inch (x)
  146.                 4       y-size in 1/16ths point * pixels per inch (y)
  147.                 4       pixels per inch (x-direction)
  148.                 4       pixels per inch (y-direction)
  149.                 1       x0    - maximum bounding box for any character
  150.                 1       y0    - bottom-left is inclusive
  151.                 1       x1    - top-right is exclusive
  152.                 1       y1    - all coordinates are in pixels
  153.                 512     2-byte offsets from table start of character data
  154.                         0 => character is not defined
  155.                         (pixel data is limited to 64K per block)
  156.  
  157.         Character data:
  158.  
  159.                 1       x0      - bounding box
  160.                 1       y0
  161.                 1       x1-x0
  162.                 1       y1-y0
  163.                 4*n     4-bpp, consecutive rows bottom->top
  164.                               not aligned until the end
  165.  
  166.  
  167. Outlines / Outlines<n> / f9999x9999 / b9999x9999:
  168.  
  169.         b9999x9999      1-bpp definition
  170.         a9999x9999      4-bpp (anti-aliased) definition
  171.         Outlines        the outline file
  172.  
  173.               '9999' = pixel size (ie. point size * 16 * dpi / 72)
  174.                        zero-suppressed decimal number
  175.  
  176.         File header:
  177.                 4       "FONT"  - identification word
  178.                 1       Bits per pixel: 0 = outlines
  179.                                         1 = 1 bpp
  180.                                         4 = 4 bpp
  181.                 1       Version number of file format
  182.                                4: no "don't draw skeleton lines unless smaller than this" byte present
  183.                                5: byte at [table+512] = max pixel size for skeleton lines (0 => always do it)
  184.                                6: byte at [chunk+indexsize] = dependency mask (see below)
  185.                                7: flag word precedes index in chunk (offsets are rel. to index, not chunk)
  186.                                8: file offset array is in a different place
  187.                 2       if bpp = 0: design size of font
  188.                         if bpp > 0: flags:
  189.                               bit 0 set => horizontal subpixel placement
  190.                               bit 1 set => vertical subpixel placement
  191.                               bit 6 set => flag word precedes index in chunk (version 7 onwards)
  192.                               bits 2..5, 7 must be 0
  193.                               NB: for outline files, bit 6 is derived from the version number
  194.                                   but if present, its value must suit the version number
  195.                 2       x0      - font bounding box (16-bit signed)
  196.                 2       y0      - units are pixels or design units
  197.                 2       x1-x0   - x0,y0 inclusive, x1,y1 exclusive
  198.                 2       y1-y0
  199.  
  200.                 If Version < 8: nchunks = 8
  201.  
  202.                 4       file offset of 0..31 chunk (word-aligned)
  203.                 4       file offset of 32..63 chunk
  204.                 ...
  205.                 4       file offset of 224..255 chunk
  206.                 4       file offset of end (ie. size of file)
  207.                         if offset(n+1)=offset(n), then chunk n is null.
  208.  
  209.                 Else (Version >= 8): nchunks = as defined below
  210.  
  211.                 4       file offset of area containing file offsets of chunks
  212.                 4       number of defined chunks
  213.                 4       ns = number of scaffold index entries (including entry[0] = size)
  214.                 4       scaffold flags:
  215.                                 bit 0 set => ALL scaffold base chars are 16-bit
  216.                                 bit 1 set => these outlines should not be anti-aliased (eg. System.Fixed)
  217.                                 bit 2 set => fill using non-zero winding rule, else odd-even.
  218.                                 bits 3..31 reserved (must be 0)
  219.                 4*5     all reserved (must be 0)
  220.  
  221.      Table start:
  222.                 2       n = size of table/scaffold data
  223.  
  224.          Bitmaps: (n=10 normally - other values are reserved)
  225.                 2       x-size (1/16th point)
  226.                 2       x-res (dpi)
  227.                 2       y-size (1/16th point)
  228.                 2       y-res (dpi)
  229.  
  230.          Outlines:
  231.            ns*2-2       2-byte offsets to scaffold data:
  232.  
  233.                         If scaffold flags bit 0 clear:
  234.                           bits 0..14 = offset of scaffold data from table start
  235.                           bit 15 set => base char code is 2 bytes, else 1
  236.  
  237.                         If scaffold flags bit 0 set:
  238.                           bits 0..15 = offset of scaffold data from table start
  239.                           base char code is always 2 bytes
  240.  
  241.                         0 => no scaffold data for char
  242.  
  243.                 1       Skeleton threshold pixel size
  244.                         (if file format version >= 5)
  245.                         When rastering the outlines, skeleton lines will
  246.                         only be drawn if either the x-or y- pixel size is
  247.                         less than this value (except if value=0, which means
  248.                         'always draw skeleton lines').
  249.                 ?       ... sets of scaffold data (see below)
  250.  
  251.      Table end: ?       description of contents of file:
  252.                         <Font name>, 0, "Outlines", 0
  253.                                         "999x999 point at 999x999 dpi", 0
  254.                         padded with zeros until word-aligned
  255.  
  256.                 If Version >= 8:
  257.  
  258.                 4       file offset of chunk 0
  259.                 4       file offset of chunk 1
  260.                 ...
  261.                 4       file offset of chunk (nchunks-1)
  262.                 4       file offset of end of file
  263.  
  264.                 All versions:
  265.  
  266.                         ... word-aligned chunks follow
  267.  
  268.      Scaffold data:
  269.               1 or 2    char code of 'base' scaffold entry (0 ==> none)
  270.                 1       bit n set ==> x-scaffold line n defined in base char
  271.                 1       bit n set ==> y-scaffold line n defined in base char
  272.                 1       bit n set ==> x-scaffold line n defined locally
  273.                 1       bit n set ==> y-scaffold line n defined locally
  274.                         ... local scaffold lines follow
  275.      Scaffold lines:
  276.                 2       bits 0..11 = coordinate (signed)
  277.                         bits 12..14 = scaffold link index (0 => none)
  278.                         bit 15 set => 'linear' scaffold link
  279.                 1       width (254 ==> L-tangent, 255 ==> R-tangent)
  280.  
  281.      Chunk data:
  282.                 4       flag word (not present before file format version 7):
  283.                               bit 0 set => horizontal subpixel placement
  284.                               bit 1 set => vertical subpixel placement
  285.                               bit 7 set => dependency byte(s) present (see below)
  286.                               bits 2..6 and 8..30 must be 0
  287.                               bit 31 must be 1
  288.  
  289.                 4 * 32  offset from index start to character
  290.                         0 => character is not defined
  291.                            * 4 for vertical placement
  292.                            * 4 for horizontal placement
  293.                         Character index is more tightly bound than vertical
  294.                         placement which is more tightly bound than
  295.                         horizontal placement.
  296.  
  297.                 n      Dependency byte(s) (if outline file, version >= 6).
  298.                         One bit required for each chunk in file.
  299.                         Bit n set => chunk n must be loaded in order to
  300.                         rasterise this chunk.  This is required for
  301.                         composite characters which include characters from
  302.                         other chunks (see below).
  303.  
  304.                         ... character data follows (word-aligned at end of chunk)
  305.  
  306.                         Note: All character definitions must follow the
  307.                               index in the order in which they are specified
  308.                               in the index.  This is to allow the font
  309.                               editor to easily determine the size of each
  310.                               character.
  311.  
  312.      Char data:
  313.                 1       flags:
  314.                            bit 0 set => coords are 12-bit, else 8-bit
  315.                            bit 1 set => data is 1-bpp, else 4-bpp
  316.                            bit 2 set => initial pixel is black, else white
  317.                            bit 3 set => data is outline, else bitmap
  318.                            if bit 3 clr: bits 4..7 = 'f' value for char (0 ==> not encoded)
  319.                            if bit 3 set: bit 4 set => composite character
  320.                                          bit 5 set => with an accent as well
  321.                                          bit 6 set => ascii codes within this char are 16-bit, else 8-bit
  322.                                          bit 7 reserved (must be 0)
  323.  
  324.          if flag bits 3 and 4 set:
  325.                 1 or 2     character code of base character
  326.            if flag bit 5 set:
  327.                 1 or 2     character code of accent
  328.                 2 or 3     x,y offset of accent character
  329.  
  330.          if flag bits 3 or 4 clear:
  331.                 2 or 3     x0, y0  sign-extended 8- or 12- bit coordinates
  332.                 2 or 3     xs, ys  width, height (bbox = x0,y0,x0+xs,y0+ys)
  333.                 n          data: (depends on type of file)
  334.                              1-bpp uncrunched: rows from bottom->top
  335.                              4-bpp uncrunched: rows from bottom->top
  336.                              1-bpp crunched: list of (packed) run-lengths
  337.                              outlines: list of move/line/curve segments
  338.                            word-aligned at the end of the character data
  339.  
  340. Outline char format
  341. -------------------
  342.  
  343. Here the 'pixel bounding box' is actually the bounding box of the outline in
  344. terms of the design size of the font (in the file header).  The data
  345. following the bounding box consists of a series of move/line/curve segments
  346. followed by a terminator and an optional extra set of line segments followed
  347. by another terminator.  When constructing the bitmap from the outlines, the
  348. font manager will fill the first set of line segments to half-way through
  349. the boundary using an even-odd fill, and will thin-stroke the second set of
  350. line segments (if present).  See the documentation on the Draw module for
  351. further details.
  352.  
  353. If the font is version 8 or greater then it can specifiy that the winding
  354. rule be either non-zero or odd-even, this is to provide compatibility with
  355. other type face formats (see above in scaffold flags).
  356.  
  357. Each line segment consists of:
  358.  
  359.         1       bits 0..1 = segment type:
  360.                             0 => terminator (see below)
  361.                             1 => move to x,y
  362.                             2 => line to x,y
  363.                             3 => curve to x1,y1,x2,y2,x3,y3
  364.                 bits 2..4 = x-scaffold link
  365.                 bits 5..7 = y-scaffold link
  366.                 ... coordinates (design units) follow
  367.  
  368. Terminator:
  369.                 bit 2 set => stroke paths follow
  370.                              (same format, but paths are not closed)
  371.                 bit 3 set => composite character inclusions follow:
  372.  
  373. Composite character inclusions:
  374.  
  375.         1 or 2  character code of character to include (0 => finished)
  376.         2 or 3  x,y offset of this inclusion (design units)
  377.  
  378. The coordinates are either 8- or 12-bit sign-extended, depending on bit 0 of
  379. the character flags (see above), including the composite character
  380. inclusions.
  381.  
  382. The character codes in the composite character sections are either 8- or
  383. 16-bit (low-byte first), depending on bit 6 of the character flags.
  384.  
  385. The scaffold links associated with each line segment relate to the last
  386. point specified in the definition of that move/line/curve, and the control
  387. points of a bezier curve have the same links as their nearest endpoint.
  388.  
  389. Note that if a character includes another, the appropriate bit in the parent
  390. character's chunk dependency flags must be set.  This byte tells the Font
  391. Manager which extra chunk(s) must be loaded in order to rasterise the parent
  392. character's chunk.
  393.  
  394.  
  395. 1-bpp uncompacted format
  396. ------------------------
  397.  
  398. 1 bit per pixel, bit set => paint in foreground colour, in rows from
  399. bottom-left to top-right, not aligned until word-aligned at the end of the
  400. character.
  401.  
  402.  
  403. 1-bpp compacted data format
  404. ---------------------------
  405.  
  406. The whole character is initially treated as a stream of bits, as for the
  407. uncompacted form.  The bit stream is then scanned row by row, with
  408. consecutive duplicate rows being replaced by a 'repeat count', and alternate
  409. runs of black and white pixels are noted.  The repeat counts and run counts
  410. are then themselves encoded in a set of 4-bit entries.
  411.  
  412. Bit 2 of the character flags determine whether the initial pixel is black or
  413. white (black = foreground), and bits 4..7 are the value of 'f' (see below).
  414. The character is then represented as a series of packed numbers, which
  415. represent the length of the next run of pixels.  These runs can span more
  416. than one row, and after each run the pixel colour is changed over.  Special
  417. values are used to denote row repeats.
  418.  
  419. <packed number> ==
  420.           0         followed by n-1 zeroes, followed by n+1 nibbles
  421.                     = resulting number + (13-f)*16 + f+1 - 16
  422.    i =    1 .. f    i
  423.    i =  f+1 .. 13   (i-f-1)*16 + next nibble + f + 1
  424.          14         followed by n=<packed number> = repeat count of n
  425.          15         repeat count of 1 (ie. 1 extra copy of this row)
  426.  
  427. The optimal value of f lies between 1 and 12, and must be computed
  428. individually for each character, by scanning the data and calculating the
  429. length of the output for each possible value.  The value yielding the
  430. shortest result is then used, unless that is larger than the bitmap itself,
  431. in which case the bitmap is used.
  432.  
  433. Repeat counts operate on the current row, as understood by the unpacking
  434. algorithm, ie. at the end of the row the repeat count is used to duplicate
  435. the row as many times as necessary.  This effectively means that the repeat
  436. count applies to the row containing the first pixel of the next run to start
  437. up.
  438.  
  439. Note that rows consisting of entirely white or entirely black pixels cannot
  440. always be represented by using repeat counts, since the run may span more
  441. than one row, so a long run count is used instead.
  442.  
  443.  
  444. Encoding files
  445. --------------
  446.  
  447. An encoding file is a text file which contains a set of identifiers which
  448. indicate which characters appear in which positions in a font.
  449.  
  450. Each identifier is preceded by a "/", and the characters are numbered from
  451. 0, increasing by 1 with each identifier found.
  452.  
  453. Comments are introduced by "%", and continue until the next control
  454. character.
  455.  
  456. The following special comment lines are understood by the font manager:
  457.  
  458.         %%RISCOS_BasedOn <baseencoding>
  459.         %%RISCOS_Alphabet <alphabet>
  460.  
  461. where <baseencoding> and <alphabet> denote positive decimal integers.
  462.  
  463. Both lines are optional, and they indicate respectively the number of the
  464. base encoding and the alphabet number of this encoding.
  465.  
  466. If the %%RISCOS_BasedOn line is not present, then the Font Manager assumes
  467. that the target encoding describes the actual positions of the glyphs in an
  468. existing file, the data for which is in:
  469.  
  470.         <font directory>.IntMetrics<alphabet>
  471.         <font directory>.Outlines<alphabet>
  472.  
  473. where <alphabet> is null if the %%RISCOS_Alphabet line is omitted.
  474.  
  475. (In fact the leafnames are shortened to fit in 10 characters, by removing
  476. characters from just before the <alphabet> suffix).
  477.  
  478. In this case the IntMetrics and Outlines files are used directly, since
  479. there is a one-to-one correspondence between the positions of the characters
  480. in the datafiles and the positions required in the font.
  481.  
  482. If the %%RISCOS_BasedOn line IS present, then the Font Manager accesses the
  483. following datafiles:
  484.  
  485.         <font directory>.IntMetrics<baseencoding>
  486.         <font directory>.Outlines<baseencoding>
  487.  
  488. and assumes that the positions of the glyphs in the datafiles are as given
  489. by the contents of the base encoding file.
  490.  
  491. The base encoding is called "/Base<n>", and lives in the Encodings directory
  492. under Font$Path, along with all the other encodings.  Because it is preceded
  493. by a "/", the Font Manager does not return it in the list of encodings
  494. returned by Font_ListFonts.
  495.  
  496. Note that only one encoding file with a given name can apply to all the
  497. fonts known to the system.  Because of this, a given encoding can only be
  498. either a direct encoding, where the alphabet number is used to reference the
  499. datafiles, or an indirect encoding, where the base encoding number specifies
  500. the datafile names.
  501.  
  502. Here is the start of a sample base encoding ("/Base0"):
  503.  
  504.         % /Base0 encoding
  505.  
  506.         %%RISCOS_Alphabet 0
  507.  
  508.         /.notdef /.NotDef /.NotDef /.NotDef
  509.         /zero /one /two /three /four /five /six /seven /eight
  510.  
  511. Here is the start of a sample encoding file ("Latin1"):
  512.  
  513.         % Latin 1 encoding
  514.  
  515.         %%RISCOS_BasedOn 0
  516.         %%RISCOS_Alphabet 101
  517.  
  518.         /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  519.         /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  520.         /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  521.         /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  522.         /space /exclam /quotedbl /numbersign
  523.         /dollar /percent /ampersand /quotesingle
  524.  
  525. (Note that the sample /Base0 file is not the same as the released one).
  526.  
  527. These illustrate several points:
  528.  
  529.     1.  The %% lines must appear before the first identifier.
  530.  
  531.     2.  Character 0 in any encoding must be called ".notdef", and represent
  532.         a null character.
  533.  
  534.     3.  Other null characters in the base encoding must be called ".NotDef",
  535.         to distinguish them from character 0.
  536.  
  537.     4.  Non-base encoding files wanting to refer to the null character
  538.         should use ".notdef" in all cases.
  539.  
  540.     5.  The other character names should follow the Adobe PostScript names
  541.         wherever possible.  This is to enable the encoding to refer to Adobe
  542.         character names when included as part of a print job by the
  543.         PostScript printer driver.
  544.  
  545.     6.  The number of characters desribed by the base encoding can be
  546.         anything from 0 to 768, and should refer to distinct characters
  547.         (apart from the ".NotDef"s).  Other encodings, however, must
  548.         contain exactly 256 characters, which need not be distinct.
  549.