------------------------------------------------------------------------- -- (C) 1988, 1989 by Adobe Systems Incorporated. All rights reserved. -- -- This file may be freely copied and redistributed as long as: -- 1) This entire notice continues to be included in the file, -- 2) If the file has been modified in any way, a notice of such -- modification is conspicuously indicated. -- -- PostScript, Display PostScript, and Adobe are registered trademarks of -- Adobe Systems Incorporated. -- --------------------------------------------------------------------------- -- THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO CHANGE WITHOUT -- NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS -- INCORPORATED. ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR -- LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO WARRANTY OF ANY -- KIND (EXPRESS, IMPLIED OR STATUTORY) WITH RESPECT TO THIS INFORMATION, -- AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. ---------------------------------------------------------------------------- -- -- Ada Binding by Alex Blakemore Genoa Software Systems -- (C) 1993 by Genoa Software Systems, Inc. All rights reserved. -- -- The Ada binding may be freely distributed and used for any purpose as long as: -- it is not sold directly for profit. It may be used an part of a commercial -- product. My intent is that this binding be available to any interested party. --------------------------------------------------------------------------- with Posix_IO; package Adobe_Font_Metrics is -- WARNINGS ABOUT Ada VERSION -- This works fine for most purposes, but has limitations: -- most due to the fact that its a layer over a C implementation -- and the two approaches dont always mesh. -- float objects represented by 4 byte filler, -- Composite Data doesnt work yet -- boolean fields follow C version and use 4 byte integer -- 1 means true, 0 means false -- some mediation in package body necessary to convert -- from C style dynamic arrays to Ada style, should be portable -- but maybe not. -- for these reasons, a complete Ada version would be nice. type C_Strings is private; max_character_code : constant := 255; type character_width_vectors is array (0 .. max_character_code) of integer; type character_width_vector_ptrs is access character_width_vectors; type float_filler is new integer; -- Below are all of the data structure definitions. These structures -- try to map as closely as possible to grouping and naming of data -- in the AFM Files. -- Bounding box definition. Used for the Font BBox as well as the -- Character BBox. type BBox is record llx : integer; -- lower left x-position lly : integer; -- lower left y-position urx : integer; -- upper right x-position ury : integer; -- upper right y-position end record; -- Global Font information. -- The key that each field is associated with is in comments. For an -- explanation about each key and its value please refer to the AFM -- documentation (full title & version given above). type GlobalFontInfo is record afmVersion : C_Strings; -- key: StartFontMetrics fontName : C_Strings; -- key: FontName fullName : C_Strings; -- key: FullName familyName : C_Strings; -- key: FamilyName weight : C_Strings; -- key: Weight italicAngle : float_filler; -- key: ItalicAngle isFixedPitch : integer; -- key: IsFixedPitch fontBBox : BBox; -- key: FontBBox underlinePosition : integer; -- key: UnderlinePosition underlineThickness : integer; -- key: UnderlineThickness version : C_Strings; -- key: Version notice : C_Strings; -- key: Notice encodingScheme : C_Strings; -- key: EncodingScheme capHeight : integer; -- key: CapHeight xHeight : integer; -- key: XHeight ascender : integer; -- key: Ascender descender : integer; -- key: Descender end record; type GlobalFontInfo_Ptrs is access GlobalFontInfo; -- Ligature definition is a linked list since any character can have -- any number of ligatures. type Ligatures; type Ligature_Ptrs is access Ligatures; type Ligatures is record succ : C_Strings; lig : C_Strings; next : Ligature_Ptrs; end record; -- Character Metric Information. This structure is used only if ALL -- character metric information is requested. If only the character -- widths is requested, then only an array of the character x-widths -- is returned. -- -- The key that each field is associated with is in comments. For an -- explanation about each key and its value please refer to the -- Character Metrics section of the AFM documentation (full title -- & version given above). type CharMetricInfo is record code : integer; -- key: C wx : integer; -- key: WX wy : integer; -- together wx and wy are associated with key: W name : C_Strings; -- key: N charBBox : BBox; -- key: B ligs : Ligature_Ptrs; -- key: L (linked list; not a fixed number of Ls end record; type CharMetricInfo_arrays is array (Positive range <>) of CharMetricInfo; type CharMetricInfo_Ptrs is access CharMetricInfo_arrays; -- Track kerning data structure. -- The fields of this record are the five values associated with every -- TrackKern entry. -- -- For an explanation about each value please refer to the -- Track Kerning section of the AFM documentation (full title -- & version given above). type TrackKernData is record degree : integer; minPtSize : float_filler; minKernAmt : float_filler; maxPtSize : float_filler; maxKernAmt : float_filler; end record; type TrackKernData_arrays is array (Positive range <>) of TrackKernData; type TrackKernData_Ptrs is access TrackKernData_arrays; -- Pair Kerning data structure. -- The fields of this record are the four values associated with every -- KP entry. For KPX entries, the yamt will be zero. -- -- For an explanation about each value please refer to the -- Pair Kerning section of the AFM documentation (full title -- & version given above). type PairKernData is record name1 : C_Strings; name2 : C_Strings; xamt : integer; yamt : integer; end record; type PairKernData_arrays is array (Positive range <>) of PairKernData; type PairKernData_Ptrs is access PairKernData_arrays; -- PCC is a piece of a composite character. This is a sub structure of a -- compCharData described below. -- These fields will be filled in with the values from the key PCC. -- -- For an explanation about each key and its value please refer to the -- Composite Character section of the AFM documentation (full title -- & version given above). type Pcc is record pccName : C_Strings; deltax : integer; deltay : integer; end record; type Pcc_arrays is array (Positive range <>) of Pcc; type Pcc_Ptrs is access Pcc_arrays; -- Composite Character Information data structure. -- The fields ccName and numOfPieces are filled with the values associated -- with the key CC. The field pieces points to an array (size = numOfPieces) -- of information about each of the parts of the composite character. That -- array is filled in with the values from the key PCC. -- -- For an explanation about each key and its value please refer to the -- Composite Character section of the AFM documentation (full title -- & version given above). -- ******* Composite characters are not handled correctly yet ****** type CompCharData is record ccName : C_Strings; numOfPieces : positive; pieces : Pcc_Ptrs; end record; type CompCharData_arrays is array (Positive range <>) of CompCharData; type CompCharData_Ptrs is access CompCharData_arrays; -- FontInfo -- Record type containing pointers to all of the other data -- structures containing information about a font. -- A a record of this type is filled with data by the -- parseFile function. type FontInfo is record numOfChars : natural; numOfTracks : natural; numOfPairs : natural; numOfComps : natural; gfi : GlobalFontInfo_Ptrs; -- ptr to a GlobalFontInfo record cwi : character_width_vector_ptrs; -- ptr to 256 element array of just char widths cmi : CharMetricInfo_Ptrs; -- ptr to char metrics array tkd : TrackKernData_Ptrs; -- ptr to track kerning array pkd : PairKernData_Ptrs; -- ptr to pair kerning array ccd : CompCharData_Ptrs; -- ptr to comp char array end record; -- This header file defines the data structures used as well as the key -- strings that are currently recognized by this version of the AFM parser. -- This program is based on the document "Adobe Font Metrics Files, -- Specification Version 2.0". -- -- AFM files are separated into distinct sections of different data. Because -- of this, the parseAFM program can parse a specified file to only save -- certain sections of information based on the application's needs. A record -- containing the requested information will be returned to the application. -- -- AFM files are divided into five sections of data: -- 1) The Global Font Information -- 2) The Character Metrics Information -- 3) The Track Kerning Data -- 4) The Pair-Wise Kerning Data -- 5) The Composite Character Data -- -- Basically, the application can request any of these sections independent -- of what other sections are requested. In addition, in recognizing that -- many applications will want ONLY the x-width of characters and not all -- of the other character metrics information, there is a way to receive -- only the width information so as not to pay the storage cost for the -- unwanted data. An application should never request both the -- "quick and dirty" char metrics (widths only) and the Character Metrics -- Information since the Character Metrics Information will contain all -- of the character widths as well. type Read_Option_Kinds is (Global_Font_Info, Character_Widths_Only, All_Char_Metric_Info, Pair_Kerning_Info, Track_Kerning_Info, Composite_Char_Info); type Read_Options is array (Read_Option_Kinds) of boolean; parse_error : exception; early_EOF : exception; read_option_error : exception; not_yet_implemented : exception; procedure parse_afm_file (fd : in POSIX_IO.File_Descriptor; read_option_mask : in Read_Options; font_info : out FontInfo); function to_string (str : C_Strings) return string; procedure free (str : in out C_Strings); private Max_C_String : constant := 16 * 1024; subtype constrained_strings is string (1 .. Max_C_String); type C_Strings is access constrained_strings; -- looks kludgy, but much more likely to be implemented as an address -- than the simpler access string (which may likely involve a descriptor) -- so its more portable and the kludge is hidden, but strings longer than -- Max_C_String characters will be truncated. end Adobe_Font_Metrics;