package fontforge-of-ocaml

  1. Overview
  2. Docs

FontForge Font object. It generally contains a list of glyphs, an encoding to order those glyphs, a fontname, a list of GPOS/GSUB lookups and many other things. API: almost complete (all listed even the unimplemented ones) compared to the Python API.

FontForge module

type t

Abstract type for fonts

Python workarounds

val contains_glyphname : glyphname:string -> t -> bool

Equivalent to the Python expression: glyphname in font. Returns whether the font contains a glyph with the given name.

val contains_unicode : unicode:int -> t -> bool

Equivalent to the Python expression: glyphname in font. Returns whether the font contains a glyph with the given name.

Equivalent to the Python expression: unicode in font. Returns whether the font contains a glyph with that encoding.

val glyph_from_name : glyphname:string -> t -> Glyph.t

Equivalent to the Python access font[glyphname] from a string. Returns the glyph with that name.

val glyph_from_code : unicode:int -> t -> Glyph.t

Equivalent to the Python access font[glyphname] from a string. Returns the glyph with that name.

Equivalent to the Python access font[unicode] from an integer. Returns the glyph at that encoding.

Methods

val addAnchorClass : subtable:string -> anchorclass:string -> t -> unit

Adds an anchor class to the specified (anchor) subtable.

TODO

  • gpos_pair
  • val addKerningClass
type lookup_script_t

Abstract type for script languages of lookup features

val lookupScript : script:string -> languages:string list -> lookup_script_t

Abstract type for script languages of lookup features

i.e. let script = lookupScript ~script:"latn" ~languages:["dflt"]

type lookup_feature_t

i.e. let script = lookupScript ~script:"latn" ~languages:["dflt"]

Abstract type for lookup features

val lookupFeature : feature:string -> scripts:lookup_script_t list -> lookup_feature_t

Abstract type for lookup features

i.e. let feature = lookupFeature feature:"liga" scripts:[script]

val addLookup : 'a Table.lookup_table_t -> 'a Table.t -> flags:string list -> 'a TypedFeature.t -> ?others:'a TypedFeature.t list -> ?after_lookupname:string -> t -> unit

i.e. let feature = lookupFeature feature:"liga" scripts:[script]

Creates a new lookup with the given name, type and flags. It will tag it with any indicated features. The type of one of

  • gsub_single
  • gsub_multiple
  • gsub_alternate
  • gsub_ligature
  • gsub_context
  • gsub_contextchain
  • gsub_revesechain
  • morx_indic
  • morx_context
  • morx_insert
  • gpos_single
  • gpos_pair
  • gpos_cursive
  • gpos_mark2base
  • gpos_mark2ligature
  • gpos_mark2mark
  • gpos_context
  • gpos_contextchain
  • kern_statemachine

The flags argument is a tuple of strings. At most one of these strings may be the name of a mark class. The others are:

  • right_to_left
  • ignore_bases
  • ignore_ligatures
  • ignore_marks

A feature-script-lang tuple is a tuple with one entry for each feature (there may be no entries if there are no features). Each entry is itself a two element tuple, the first entry is a string containing a 4 letter feature tag, and the second entry is another tuple (potentially empty) with an entry for each script for which the feature is active. Each entry here is itself a two element tuple. The first element is a 4 letter script tag and the second is a tuple of languages. Each entry in the language tuple is a four letter language.

  • Example: (("liga",(("latn",("dflt")),)),) The optional final argument allows you to specify the ordering of the lookup. If not specified the lookup will be come the first lookup in its table.
val addLookupSubtable : 'a Table.lookup_subtable_t -> ?after_subtable:string -> t -> unit

Creates a new lookup with the given name, type and flags. It will tag it with any indicated features. The type of one of

  • gsub_single
  • gsub_multiple
  • gsub_alternate
  • gsub_ligature
  • gsub_context
  • gsub_contextchain
  • gsub_revesechain
  • morx_indic
  • morx_context
  • morx_insert
  • gpos_single
  • gpos_pair
  • gpos_cursive
  • gpos_mark2base
  • gpos_mark2ligature
  • gpos_mark2mark
  • gpos_context
  • gpos_contextchain
  • kern_statemachine

The flags argument is a tuple of strings. At most one of these strings may be the name of a mark class. The others are:

  • right_to_left
  • ignore_bases
  • ignore_ligatures
  • ignore_marks

A feature-script-lang tuple is a tuple with one entry for each feature (there may be no entries if there are no features). Each entry is itself a two element tuple, the first entry is a string containing a 4 letter feature tag, and the second entry is another tuple (potentially empty) with an entry for each script for which the feature is active. Each entry here is itself a two element tuple. The first element is a 4 letter script tag and the second is a tuple of languages. Each entry in the language tuple is a four letter language.

  • Example: (("liga",(("latn",("dflt")),)),) The optional final argument allows you to specify the ordering of the lookup. If not specified the lookup will be come the first lookup in its table.

Creates a new subtable within the specified lookup. The lookup name should be a string specifying an existing lookup. The subtable name should also be a string and should not match any currently existing subtable in the lookup. The optional final argument allows you to specify the ordering within the lookup. If not specified this subtable will be first in the lookup. If you want to create a subtable in a contextual lookup, then use addContextualSubtable below. If you want to create a kerning class subtable, then use addKerningClass above.

TODO

  • val addContextualSubtable: lookupname:string -> subtable:string -> subtabletype:string -> rule: ?? -> ?afterSubtable:string -> ?bclasses:string -> mclasses: string -> ?fclasses:string -> ?bclassnames:string -> ?mclassnames:string -> ?fclassnames:string -> t -> unit
  • addSmallCaps
  • alterKerningClass
  • autoKern
  • appendSFNTName
val buildOrReplaceAALTFeatures : t -> unit

Removes any existing AALT features (and any lookups solely controled by such features) and creates new ones containing all possible single and alternate substutions available for each glyph.

val cidConvertByCMap : filename:string -> t -> unit

Removes any existing AALT features (and any lookups solely controled by such features) and creates new ones containing all possible single and alternate substutions available for each glyph.

Converts a normal font into a CID-keyed font with one subfont using the CMAP to determine the mapping.

TODO

  • cidConvertTo
val cidFlatten : t -> unit

Converts a CID font into a normal font (glyphs will be in CID order).

val cidInsertBlankSubFont : t -> unit

Converts a CID font into a normal font (glyphs will be in CID order).

Adds a new (blank) sub-font into a cid-keyed font and changes the current sub-font to be it.

val cidFlattenByCMap : filename:string -> t -> unit

Adds a new (blank) sub-font into a cid-keyed font and changes the current sub-font to be it.

Converts a CID font into a normal font (glyphs will be in CID order).

val cidRemoveSubFont : t -> unit

Converts a CID font into a normal font (glyphs will be in CID order).

Removes the current subfont from a cid-keyed font.

val close : t -> unit

Removes the current subfont from a cid-keyed font.

Frees memory for the current font. Warning: Any python pointers to it will become invalid.

TODO

  • compareFonts
val createChar : unicode:int -> ?name:string -> t -> Glyph.t

Create (and return) a character at the specified unicode codepoint in this font and optionally name it. If you wish to create an glyph with no unicode codepoint set the first argument to -1 and specify a name. If there is already a character there, return it (it will not be renamed).

TODO

  • createInterpolatedGlyph
  • createMappedChar
  • find
  • indEncodingSlot
  • glyphs
val generate : filename:string -> t -> unit

TODO: adds optional args for generate

TODO

  • generateTtc
  • generateFeatureFile
  • genericGlyphChange
  • getKerningClass
  • getLookupInfo
  • getLookupSubtables
  • getLookupSubtableAnchorClasses
  • getLookupOfSubtable
  • getSubtableOfAnchor
  • importBitmaps
  • importLookups
  • interpolateFonts
  • isKerningClass
  • isVerticalKerning
  • italicize
val lookupSetFeatureList : lookupname:string -> features:lookup_feature_t list -> t -> unit

Sets the feature list of indicated lookup. The feature-script-lang tuple is described at addLookup function.

val lookupSetFlags : lookupname:string -> flags:string list -> t -> unit

Sets the feature list of indicated lookup. The feature-script-lang tuple is described at addLookup function.

Sets the lookup flags for the named lookup. At most one of these strings may be the name of a mark class. The others are:

  • right_to_left
  • ignore_bases
  • ignore_ligatures
  • ignore_marks
val lookupSetStoreLigatureInAfm : lookupname:string -> store:bool -> t -> unit

Sets the lookup flags for the named lookup. At most one of these strings may be the name of a mark class. The others are:

  • right_to_left
  • ignore_bases
  • ignore_ligatures
  • ignore_marks

Sets whether this ligature lookup contains data to store in the afm.

val mergeFonts : filename:string -> ?preserveCrossFontKerning:bool -> t -> unit

Sets whether this ligature lookup contains data to store in the afm.

Merges the font in the file into the current font.

val mergeFeature : filename:string -> t -> unit

Merges the font in the file into the current font.

Merge feature and lookup information from an adobe feature file, or metrics information from the (afm,tfm,etc) file into the current font.

val mergeKern : filename:string -> t -> unit

Merge feature and lookup information from an adobe feature file, or metrics information from the (afm,tfm,etc) file into the current font.

Deprecated name for mergeFeature above

val mergeLookups : lookupname1:string -> lookupname2:string -> t -> unit

Deprecated name for mergeFeature above

The lookups must be of the same type. All subtables from lookupname2 will be moved to lookupname1, the features list of lookupname2 will be merged with that of lookupname1, and lookupname2 will be removed.

val mergeLookupSubtables : subtable1:string -> subtable2:string -> t -> unit

The lookups must be of the same type. All subtables from lookupname2 will be moved to lookupname1, the features list of lookupname2 will be merged with that of lookupname1, and lookupname2 will be removed.

The subtables must be in the same lookup. Not all lookup types allow their subtables to be merged (contextual subtables may not be merged, kerning classes may not be (kerning pairs may be)). Any information bound to subtable2 will be bound to subtable1 and subtable2 will be removed.

TODO

  • printSample
val randomText : script:string -> ?lang:string -> t -> string

Returns a random text sample using the letter frequencies of the specified script (and optionally language). Both script and language should be expressed as strings containing OpenType Script and Language tags. "dflt" is a reasonable language tag. If the language is not specified, one will be chosen at random. If FontForge has no frequency information for the script/language specified it will use the letters in the script with equal frequencies.

val regenBitmaps : sizes:int list -> t -> unit

Returns a random text sample using the letter frequencies of the specified script (and optionally language). Both script and language should be expressed as strings containing OpenType Script and Language tags. "dflt" is a reasonable language tag. If the language is not specified, one will be chosen at random. If FontForge has no frequency information for the script/language specified it will use the letters in the script with equal frequencies.

A tuple with an entry for each bitmap strike to be regenerated (rerasterized). Each strike is identified by pixelsize (if the strike is a grey scale font it will be indicated by (bitmap-depth<<16)|pixelsize.

val removeAnchorClass : anchorclass:string -> t -> unit

Removes the named AnchorClass (and all associated points) from the font.

val removeLookup : lookup:string -> t -> unit

Removes the named AnchorClass (and all associated points) from the font.

Remove the lookup (and any subtables within it).

val removeLookupSubtable : subtable:string -> t -> unit

Remove the lookup (and any subtables within it).

Remove the subtable (and all data associated with it).

val removeGlyph : Selection.request_t -> t -> unit

Remove the subtable (and all data associated with it).

You may either pass in a FontForge glyph object (from this font) or identify a glyph in the font by unicode code point or name. In any case the glyph will be removed from the font. WARNING: This frees fontforge's storage to this glyph. If you have any python pointers (also FFglyph.t value) to that storage they will be looking at garbage. This does not go through the usual python reference mechanism.

val removeGlyph_from_unicode : unicode:int -> t -> unit

You may either pass in a FontForge glyph object (from this font) or identify a glyph in the font by unicode code point or name. In any case the glyph will be removed from the font. WARNING: This frees fontforge's storage to this glyph. If you have any python pointers (also FFglyph.t value) to that storage they will be looking at garbage. This does not go through the usual python reference mechanism.

Shortcut using removeGlyph.

val removeGlyph_from_glyphname : glyphname:string -> t -> unit

Shortcut using removeGlyph.

Shortcut using removeGlyph.

val removeGlyph_from_glyph : glyph:Glyph.t -> t -> unit

Shortcut using removeGlyph.

Shortcut using removeGlyph.

type replace_spec_t

Abstract type for replaceAll function.

val from_Layer : srch:Layer.t -> rpl:Layer.t -> replace_spec_t

Abstract type for replaceAll function.

For replacing a FFlayer by another one.

val from_Contour : srch:Contour.t -> rpl:Contour.t -> replace_spec_t

For replacing a FFlayer by another one.

For replacing a FFcontour by another one.

val replaceAll : spec:replace_spec_t -> ?error_bound:float -> t -> unit

For replacing a FFcontour by another one.

Searches the font for all occurences of the srch contour (or layer) and replaces them with the replace contour (or layer).

val replaceAll_from_Layer : srch:Layer.t -> rpl:Layer.t -> ?error_bound:float -> t -> unit

Searches the font for all occurences of the srch contour (or layer) and replaces them with the replace contour (or layer).

Idem replaceAll from a layer

val replaceAll_from_Contour : srch:Contour.t -> rpl:Contour.t -> ?error_bound:float -> t -> unit

Idem replaceAll from a layer

Idem replaceAll from a contour

val revert : t -> unit

Reloads the font from the disk. Caveat: if you have any pointers to glyphs which live in the font those pointers will no longer be valid, and using them will cause crashes. This is very un-python-like.

val revertFromBackup : t -> unit

Reloads the font from the disk. Caveat: if you have any pointers to glyphs which live in the font those pointers will no longer be valid, and using them will cause crashes. This is very un-python-like.

Reloads the font from the backup file on the disk. Caveat: if you have any pointers to glyphs which live in the font those pointers will no longer be valid, and using them will cause crashes. This is very un-python-like.

val save : filename:string -> t -> unit

Reloads the font from the backup file on the disk. Caveat: if you have any pointers to glyphs which live in the font those pointers will no longer be valid, and using them will cause crashes. This is very un-python-like.

Saves the font to an sfd file. See also generate()

val saveNamelist : filename:string -> t -> unit

Saves the font to an sfd file. See also generate()

Saves the font's namelist to a file.

val getTableData : tablename:string -> t -> string

Saves the font's namelist to a file.

Gets binary data from any saved table. FontForge will save 'fpgm', 'prep', 'cvt ' and 'maxp'. FontForge may also save tables which you explicitly request. Do not expect to get binary data for tables like 'GPOS' or 'glyf' which FontForge will generate when it creates a font... that information is not currently available. Returns a binary string.

TODO

  • setTableData: tablename:string -> ?? -> t -> unit
val validate : ?force:bool -> t -> int

Validates the font and returns a bit mask of all errors from all glyphs (as defined in the validation_state of a glyph -- except bit 0x1 is clear). If the font passed the validation then the return value will be 0 (not 0x1). Otherwise the return value will be the set of errors found. Note: The set of errors is slightly different for TrueType and PostScript output. The returned mask contains the list of potential errors. You must figure out which apply to you.

Normally each glyph will cache its validation_state and it will not be recalculated. If you pass a non-zero argument to the routine then it will force recalculation of each glyph -- this can be slow.s

val addExtrema : t -> unit

Extrema should be marked by on-curve points. If a curve in any selected glyph lacks a point at a significant extremum this command will add one.

val addSmallCaps : t -> unit

Extrema should be marked by on-curve points. If a curve in any selected glyph lacks a point at a significant extremum this command will add one.

For all selected upper or lower case letters in the latin, greek and cyrillic scripts this will try to create a small caps version of that glyph in a new glyph slot. So if you select "A" (or "a") then a glyph "a.sc" will be created (if "a.sc" already exists, it will be reused, and its current contents cleared). The contents of "a.sc" will be based on the upper case variant of this glyph (and that variant must be present for the command to work). FontForge will also create two lookups (unless appropriate ones already exist) one, bound to the feature 'c2sc' will map upper case letters to small caps, the other, bound to feature 'smcp' will map lower case letters to small caps.

val autoHint : t -> unit

For all selected upper or lower case letters in the latin, greek and cyrillic scripts this will try to create a small caps version of that glyph in a new glyph slot. So if you select "A" (or "a") then a glyph "a.sc" will be created (if "a.sc" already exists, it will be reused, and its current contents cleared). The contents of "a.sc" will be based on the upper case variant of this glyph (and that variant must be present for the command to work). FontForge will also create two lookups (unless appropriate ones already exist) one, bound to the feature 'c2sc' will map upper case letters to small caps, the other, bound to feature 'smcp' will map lower case letters to small caps.

Generates PostScript hints for all selected glyphs.

val autoInstr : t -> unit

Generates PostScript hints for all selected glyphs.

Generates TrueType instructions for all selected glyphs.

val autoTrace : t -> unit

Generates TrueType instructions for all selected glyphs.

Auto traces any background images in all selected glyphs.

val build : t -> unit

Auto traces any background images in all selected glyphs.

If any of the selected characters is a composite character, then this command will clear it and insert references to its components (this command can create new glyphs).

val canonicalContours : t -> unit

If any of the selected characters is a composite character, then this command will clear it and insert references to its components (this command can create new glyphs).

Orders the contours in the selected glyphs by the x coordinate of their leftmost point. This can reduce the size of the charstring needed to describe the glyph(s).

val canonicalStart : t -> unit

Orders the contours in the selected glyphs by the x coordinate of their leftmost point. This can reduce the size of the charstring needed to describe the glyph(s).

Sets the start point of all the contours of the selected glyphs to be the leftmost point on the contour. If there are several points with that value then use the one which is closest to the baseline. This can reduce the size of the charstring needed to describe the glyph(s). By regularizing things it can also make more things available to be put in subroutines.

val clear : t -> unit

Sets the start point of all the contours of the selected glyphs to be the leftmost point on the contour. If there are several points with that value then use the one which is closest to the baseline. This can reduce the size of the charstring needed to describe the glyph(s). By regularizing things it can also make more things available to be put in subroutines.

Clears the contents of all selected glyphs.

val copy : t -> unit

Clears the contents of all selected glyphs.

Copies all selected glyphs into (fontforge's internal) clipboard.

val copyReference : t -> unit

Copies all selected glyphs into (fontforge's internal) clipboard.

Copies all selected glyphs (as references) into (fontforge's internal) clipboard.

val correctDirection : t -> unit

Copies all selected glyphs (as references) into (fontforge's internal) clipboard.

Orients all contours so that external ones are clockwise and internal counter-clockwise in all selected glyphs.

val correctReferences : t -> unit

Orients all contours so that external ones are clockwise and internal counter-clockwise in all selected glyphs.

Checks a font for glyphs with mixed contours and references (or references with transformation matrices which cannot be represented truetype (ie. scaling by 2 or more)). If a mixed case is discovered fontforge will take the contours out of the glyph, put them in a new glyph, and make a reference to the new glyph.

val cut : t -> unit

Checks a font for glyphs with mixed contours and references (or references with transformation matrices which cannot be represented truetype (ie. scaling by 2 or more)). If a mixed case is discovered fontforge will take the contours out of the glyph, put them in a new glyph, and make a reference to the new glyph.

Copies all selected glyphs into (fontforge's internal) clipboard. And then clears them.

val paste : t -> unit

Copies all selected glyphs into (fontforge's internal) clipboard. And then clears them.

Pastes the contents of (fontforge's internal) clipboard into the selected glyphs -- and removes what was there before.

val intersect : t -> unit

Pastes the contents of (fontforge's internal) clipboard into the selected glyphs -- and removes what was there before.

Leaves only areas in the intersection of contours in all selected glyphs. See also removeOverlap.

val pasteInto : t -> unit

Leaves only areas in the intersection of contours in all selected glyphs. See also removeOverlap.

Pastes the contents of (fontforge's internal) clipboard into the selected glyphs -- and retains what was there before.

val removeOverlap : t -> unit

Pastes the contents of (fontforge's internal) clipboard into the selected glyphs -- and retains what was there before.

Removes overlapping areas in all selected glyphs. See also intersect.

val replaceWithReference : ?fudge:float -> t -> unit

Removes overlapping areas in all selected glyphs. See also intersect.

Finds any glyph which contains an inline copy of one of the selected glyphs, and converts that copy into a reference to the appropriate glyph. Selection is changed to the set of glyphs which the command alters. If specified the fudge argument specifies the error allowed for coordinate differences.

val round : ?factor:float -> t -> unit

Finds any glyph which contains an inline copy of one of the selected glyphs, and converts that copy into a reference to the appropriate glyph. Selection is changed to the set of glyphs which the command alters. If specified the fudge argument specifies the error allowed for coordinate differences.

Rounds the x and y coordinates of each point in all selected glyphs. If factor is specified then new-coord = round(factor*old-coord)/factor. See also cluster.

TODO

  • simplify
  • stroke
val transform : matrix:PsMat.t -> t -> unit

Transforms all selected glyphs by the matrix.

val nltransform : xexpr:string -> yexpr:string -> t -> unit

Transforms all selected glyphs by the matrix.

xexpr and yexpr are strings specifying non-linear transformations that will be applied to all points in the selected glyphs of the font (with xexpr being applied to x values, and yexpr to y values, of course). The syntax for the expressions is explained in the non-linear transform dialog.

val unlinkReferences : t -> unit

xexpr and yexpr are strings specifying non-linear transformations that will be applied to all points in the selected glyphs of the font (with xexpr being applied to x values, and yexpr to y values, of course). The syntax for the expressions is explained in the non-linear transform dialog.

Unlinks all references in all selected glyphs and replaces them with splines.

Attributes

Submodules giving read and write access to FontForge contour attributes.

module type IntAttr = Attr with type t = t and type attr = int
module type StringAttr = Attr with type t = t and type attr = string
module type SelectionAttr = Attr with type t = t and type attr = Selection.t
module Ascent : IntAttr
module Descent : IntAttr
module Em : IntAttr