package fontforge-of-ocaml

  1. Overview
  2. Docs

Glyph refers to a fontforge Glyph object. It has no independent life of its own, it always lives within a font. It has all the things you expect to be associated with a glyph: a glyph name, a unicode encoding, a drawing layer, GPOS/GSUB features... This type may not be pickled. This type may not be created directly -- all glyphs are bound to a font and must be created through the font. See Font.createChar function. API: partialy implemented (compared to the Python API) but all members and functions are listed.

Selection

type t

Methods

TODO

  • val addAnchorPoint
val addExtrema : ?flags:string -> ?emsize:int -> t -> unit

Extrema should be marked by on-curve points. If a curve lacks a point at an extrema this command will add one. Flags may be one of the following strings:

  • all - Add all missing extrema
  • only_good - Only add extrema on longer splines (with respect to the em-size). Default flag.
  • only_good_rm - As above but also merge away on-curve points which are very close to, but not on, an added extremum.
val addReference : glyphname:string -> ?transform:PsMat.t -> t -> unit

Extrema should be marked by on-curve points. If a curve lacks a point at an extrema this command will add one. Flags may be one of the following strings:

  • all - Add all missing extrema
  • only_good - Only add extrema on longer splines (with respect to the em-size). Default flag.
  • only_good_rm - As above but also merge away on-curve points which are very close to, but not on, an added extremum.

Adds a reference to the specified glyph into the current glyph. Optionally specifying a transformation matrix

val addHint : is_vertical:bool -> start:float -> width:float -> t -> unit

Adds a reference to the specified glyph into the current glyph. Optionally specifying a transformation matrix

Adds a postscript hint. Takes a boolean flag indicating whether the hint is horizontal or vertical, a start location and the hint's width.

val addPosSub : ((Table.lookup_pos_sub_t * 'b) * 'b Table.args_t) Table.lookup_subtable_t -> 'b Table.args_t -> t -> unit

Adds a postscript hint. Takes a boolean flag indicating whether the hint is horizontal or vertical, a start location and the hint's width.

Adds position/substitution data to the glyph. The number and type of the arguments vary acording to the type of the lookup containing the subtable. The first argument should always be a lookup subtable name. If the lookup is for single substitutions then the second argument should be a string containing a single glyph name. For multiple and alternated substitutions a tuple of glyph names. For ligatures, a tuple of the ligature components (glyph names). For single positionings the second through fifth arguments should be small integers representing the adjustment along the appropriate axis. For pairwise positionings (kerning) the second argument should be the name of the other glyph being kerned with, and the third through tenth should be small integers – or, if there are exactly three arguments then the third specifies traditional, one-axis, kerning. If there is a previously existing entry, this will replace it (except for ligatures).

TODO

  • val appendAccent
val autoHint : t -> unit

Generates PostScript hints for this glyph.

val autoInstr : t -> unit

Generates PostScript hints for this glyph.

Generates TrueType instructions for this glyph.

val autoTrace : t -> unit

Generates TrueType instructions for this glyph.

Auto traces any background images.

val build : t -> unit

Auto traces any background images.

If the character is a composite character, then clears it and inserts references to its components.

val canonicalContours : t -> unit

If the character is a composite character, then clears it and inserts references to its components.

Orders the contours in the current glyph 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 current glyph 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 current glyph 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.

TODO

  • val changeWeight
val condenseExtend : c_factor:float -> c_add:float -> ?sb_factor:float -> ?sb_add:float -> ?correct:bool -> t -> unit

Condenses or extends the size of the counters and side-bearings of the glyph. The first two arguments provide information on shrinking/growing the counters, the second two the sidebearings. If the last two are omitted they default to the same values as the first two. A counter's width will become: new_width = c_factor * old_width + c_add

If present the correct argument allows you to specify whether you want to correct for the italic angle before condensing the glyph. (it defaults to True).

val clear : t -> unit

Condenses or extends the size of the counters and side-bearings of the glyph. The first two arguments provide information on shrinking/growing the counters, the second two the sidebearings. If the last two are omitted they default to the same values as the first two. A counter's width will become: new_width = c_factor * old_width + c_add

If present the correct argument allows you to specify whether you want to correct for the italic angle before condensing the glyph. (it defaults to True).

Clears the contents of the glyph (and marks it as not worth outputting).

val cluster : ?within:float -> ?max:float -> t -> unit

Clears the contents of the glyph (and marks it as not worth outputting).

Moves clustered coordinates to a standard central value. See also round.

val correctDirection : t -> unit

Moves clustered coordinates to a standard central value. See also round.

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

val exclude : Layer.t -> t -> unit

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

Removes the excluded area from the current glyph. Takes an argument which is a layer. See also removeOverlap and intersect.

TODO

  • val export
  • val getPosSub: string -> t -> ??
val importOutlines : filename:string -> ?flags:string list -> t -> unit

Uses the file's extension to determine behavior. Imports outline descriptions (eps, svg, glif files) into the forground layer. Imports image descriptions (bmp, png, xbm, etc.) into the background layer. Optionally, flags can be used to control PostScript import, it'll be ignored for other file types. Flags is a list of strings?

val intersect : t -> unit

Uses the file's extension to determine behavior. Imports outline descriptions (eps, svg, glif files) into the forground layer. Imports image descriptions (bmp, png, xbm, etc.) into the background layer. Optionally, flags can be used to control PostScript import, it'll be ignored for other file types. Flags is a list of strings?

Leaves only areas in the intersection of contours. See also removeOverlap and exclude.

val isWorthOutputting : t -> bool

Leaves only areas in the intersection of contours. See also removeOverlap and exclude.

Returns whether the glyph is worth outputting into a font file. Basically a glyph is worth outputting if it contains any contours, or references or has had its width set.

val preserveLayerAsUndo : ?layer_dohints:(int * bool) -> t -> unit

Returns whether the glyph is worth outputting into a font file. Basically a glyph is worth outputting if it contains any contours, or references or has had its width set.

Normally undo handling is turned off during python scripting. If you wish you may tell fontforge to preserve the current state of a layer so that whatever you do later can be undone by the user. You may omit the layer parameter (in which case the currently active layer will be used). You may also request that hints be preserved (they are not, by default).

val removeOverlap : t -> unit

Normally undo handling is turned off during python scripting. If you wish you may tell fontforge to preserve the current state of a layer so that whatever you do later can be undone by the user. You may omit the layer parameter (in which case the currently active layer will be used). You may also request that hints be preserved (they are not, by default).

Removes overlapping areas. See also intersect and exclude.

val removePosSub : name:string -> t -> unit

Removes overlapping areas. See also intersect and exclude.

Removes all data from the glyph corresponding to the given lookup-subtable. If the name is "*" then all data will be removed.

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

Removes all data from the glyph corresponding to the given lookup-subtable. If the name is "*" then all data will be removed.

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

val selfIntersects : t -> bool

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

Returns whether any of the contours in this glyph intersects any other contour in the glyph (including itself).

val transform : matrix:PsMat.t -> ?flags:string list -> t -> unit

Returns whether any of the contours in this glyph intersects any other contour in the glyph (including itself).

Transforms the glyph by the matrix. The optional flags argument should be a tuple containing any of the following strings:

  • partialRefs - Don't transform any references in the glyph, but do transform their offsets. This is useful if the refered glyph will be (or has been) transformed.
  • round - Round to int after the transformation is done.
val nltransform : xexpr:string -> yexpr:string -> t -> unit

Transforms the glyph by the matrix. The optional flags argument should be a tuple containing any of the following strings:

  • partialRefs - Don't transform any references in the glyph, but do transform their offsets. This is useful if the refered glyph will be (or has been) transformed.
  • round - Round to int after the transformation is done.

xexpr and yexpr are strings specifying non-linear transformations that will be applied to all points in the current layer (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 unlinkRef : ?refname:string -> t -> unit

xexpr and yexpr are strings specifying non-linear transformations that will be applied to all points in the current layer (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 the reference to the glyph named ref-name. If ref-name is omitted, unlinks all references.

val unlinkThisGlyph : t -> unit

Unlinks the reference to the glyph named ref-name. If ref-name is omitted, unlinks all references.

Unlinks all the references to the current glyph within any other glyph in the font.

val useRefsMetrics : name:string -> ?flag:bool -> t -> unit

Unlinks all the references to the current glyph within any other glyph in the font.

Finds a reference with the given name and sets the "use_my_metrics" flag on it (so this glyph will have the same advance width as the glyph the reference points to). If the optional flag argument is False, then the glyph will no longer have its metrics bound to the reference.

val validate : ?force:bool -> t -> int

Finds a reference with the given name and sets the "use_my_metrics" flag on it (so this glyph will have the same advance width as the glyph the reference points to). If the optional flag argument is False, then the glyph will no longer have its metrics bound to the reference.

Validates the glyph and returns the validation_state of the glyph (except bit 0x1 will always be clear). If the glyph passed the validation then the return value will be 0 (not 0x1). Otherwise the return value will be the set of errors found. If force is specified true this will always be validated, if force is unspecified (or specified as false) then it will return the cached value if it is known, otherwise will validate it.

val draw : GlyphPen.t -> t -> unit

Validates the glyph and returns the validation_state of the glyph (except bit 0x1 will always be clear). If the glyph passed the validation then the return value will be 0 (not 0x1). Otherwise the return value will be the set of errors found. If force is specified true this will always be validated, if force is unspecified (or specified as false) then it will return the cached value if it is known, otherwise will validate it.

Draw the glyph's outline to the pen argument.

val glyphPen : ?replace:bool -> t -> GlyphPen.t

Draw the glyph's outline to the pen argument.

Creates a new glyphPen which will draw into the current glyph. By default the pen will replace any existing contours and references, but setting the optional keyword argument, replace to false will retain the old contents.

Attributes

Submodules giving read and write access to FontForge glyph attributes. Readonly attributes are implemented as functions.

module type BoolAttr = Attr with type t = t and type attr = bool
module type IntAttr = Attr with type t = t and type attr = int
module type StringAttr = Attr with type t = t and type attr = string

Returns currently active layer in the glyph (as an integer). May be set to an integer or a layer name to change the active layer. Not implemented: set the attribute from a layer name

TODO

  • module Atuni: ???Attr
  • module AnchorPoints: ???Attr
  • module AnchorPointsWithSel: ???Attr
  • module Background: ???Attr
module Changed : BoolAttr
module Color : IntAttr

TODO

  • module Comments: UTF8Attr
  • module Dhints: FloatTuple2Tuple3ListAttr
val encoding : t -> int

Returns the glyph's encoding in the font's encoding. (readonly) If the glyph has multiple encodings, one will be picked at random. If the glyph is not in the font's encoding then a number will be returned beyond the encoding size (or in some cases -1 will be returned). Note: an Ocaml IntAttr module is not used there since the Python attribute font is read only.

val font : t -> Font.t

Returns the glyph's encoding in the font's encoding. (readonly) If the glyph has multiple encodings, one will be picked at random. If the glyph is not in the font's encoding then a number will be returned beyond the encoding size (or in some cases -1 will be returned). Note: an Ocaml IntAttr module is not used there since the Python attribute font is read only.

The font containing this glyph. Note: an Ocaml FontAttr module is not used there since the Python attribute font is read only.

TODO

  • module Foreground: ??Attr

TODO

  • module Hhints: FloatTuple2ListAttr
  • module HorizontalComponents: ??Attr
  • module HorizontalComponentItalicCorrection : ??Attr
val layer_cnt : t -> int

The number of layers in this glyph. Cannot be set. Note: an Ocaml IntAttr module is not used there since the Python attribute font is read only.

TODO seems to be readonly

  • module Layers: ??Attr
  • module Layerrefs: ??Attr
  • module Lcarets: ??Attr

TODO

  • module ManualHints: ??Attr
  • module MathKern: ??Attr
  • module Persistant: ??Attr
  • module References: ??Attr

TODO

  • module Temporary: ??Attr

The Tex height. The special value of -32768 (0x8000) means the field is unspecified. An unspecified value will not go into the output tables, a value of 0 will.

module Texdepth : IntAttr

The Tex height. The special value of -32768 (0x8000) means the field is unspecified. An unspecified value will not go into the output tables, a value of 0 will.

The Tex depth. The special value of -32768 (0x8000) means the field is unspecified. An unspecified value will not go into the output tables, a value of 0 will.

TODO

  • module Ttinstrs: ??Attr
module Unicode : IntAttr

The glyph's unicode code point, or -1

The glyph's unicode code point, or -1

TODO

  • module VerticalComponents: ??Attr
  • module VerticalComponentsItalicCorrection: ??Attr
  • module VerticalVariants: ??Attr
  • module Vhints: ??Attr
module Vwidth : IntAttr
module Width : IntAttr
val originalgid : t -> int
val script : t -> string

A string containing the OpenType 4 letter tag for the script associated with this glyph (readonly).

val validation_state : t -> int

A (readonly) bit mask indicating some problems this glyph might have. 0x1 If set then this glyph has been validated. If unset then other bits are meaningless. 0x2 Glyph has an open contour. 0x4 Glyph intersects itself somewhere. 0x8 At least one contour is drawn in the wrong direction 0x10 At least one reference in the glyph has been flipped (and so is drawn in the wrong direction) 0x20 Missing extrema 0x40 A glyph name referred to from this glyph, in an opentype table, is not present in the font. 0x80 PostScript has a limit of 1500 points in a glyph. 0x100 PostScript has a limit of 96 hints in a glyph. 0x200 Invalid glyph name. TrueType only, errors in original file 0x400 More points in a glyph than allowed in 'maxp' 0x800 More paths in a glyph than allowed in 'maxp' 0x1000 More points in a composite glyph than allowed in 'maxp' 0x2000 More paths in a composite glyph than allowed in 'maxp' 0x4000 Instructions longer than allowed in 'maxp' 0x8000 More references in a glyph than allowed in 'maxp' 0x10000 References nested more deeply than allowed in 'maxp' 0x40000 Points too far apart. TrueType and Type2 fonts are limited to 16 bit numbers, and so adjacent points must be within 32767 em-units of each other. 0x80000 Points non-integral. TrueType points and control points must be integer aligned. (FontForge will round them if they aren't) 0x100000 Missing anchor. According to the opentype spec, if a glyph contains an anchor point for one anchor class in a subtable, it must contain anchor points for all anchor classes in the subtable. Even it, logically, they do not apply and are unnecessary. 0x200000 Duplicate glyph name. Two (or more) glyphs in this font have the same name. When outputting a PostScript font only one of them will ever be seen. It's a little hard to detect this in normal use, but if you change the encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter the glyph name, both of them should be selected. 0x400000 Duplicate unicode code point. Two (or more) glyphs in this font have the code point. When outputting an sfnt (TrueType/OpenType) font only one of them will ever be seen. It's a little hard to detect this in normal use, but if you change the encoding to "Glyph Order", and then use Edit->Select->Wildcard and enter the code point, both of them should be selected. 0x800000 Overlapped hints. Either the glyph has no hint masks and there are overlapped hints, or a hint mask specifies two overlapping hints.

OCaml

Innovation. Community. Security.