package fontforge-of-ocaml

  1. Overview
  2. Docs

A Contour is a collection of points. A contour may be either based on cubic or quadratic splines.

If based on cubic splines there should be either 0 or 2 off-curve points between every two on-curve points. If there are no off-curve points then we have a line between those two points. If there are 2 off-curve points we have a cubic bezier curve between the two end points.

If based on quadratic splines things are more complex. Again, two adjacent on-curve points yield a line between those points. Two on-curve points with an off-curve point between them yields a quadratic bezier curve. However if there are two adjacent off-curve points then an on-curve point will be interpolated between them. (This should be familiar to anyone who has read the truetype 'glyf' table docs).

For examples of what these splines can look like see the section on bezier curves.

A contour may be open in which case it is just a long wiggly line, or closed when it is more like a circle with an inside and an outside. Unless you are making stroked fonts all your contours should eventually be closed.

Contours may also be expressed in terms of Raph Levien's spiro points. This is an alternate representation for the contour, and is not always available (Only if fontforge.hasSpiro() is True. If available the spiro member will return a tuple of spiro control points, while assigning to this member will change the shape of the contour to match the new spiros.

Two contours may be compared to see if they describe similar paths.

API: uncomplete (compared to the Python API)

Glyph

type t

Abstract type for contours

Python workarounds

exception Index_out_of_bounds
val nth : int -> t -> Point.t

Related to the python expression: c[i]. The ith point on the contour. You may assign to this using set_nth.

  • raises [Index_out_of_bounds].
val set_nth : int -> Point.t -> t -> unit

Related to the python expression: c[i]. The ith point on the contour. You may assign to this using set_nth.

  • raises [Index_out_of_bounds].

Related to the python assignement: c[i] = pt.

  • raises [Index_out_of_bounds].
val len : t -> int

Related to the python assignement: c[i] = pt.

  • raises [Index_out_of_bounds].

The number of points in the contour.

val extract : min:int -> max:int -> t -> t

Related to the python expression: c[min:max]. The contour containing points between i and j excluded.

val add_contour : t -> t -> t

Related to the python expression: c[min:max]. The contour containing points between i and j excluded.

Related to the python expression: c+d. A contour concatenating c and d (another contour).

val add_point : Point.t -> t -> t

Related to the python expression: c+d. A contour concatenating c and d (another contour).

Related to the python expression: c+d. A contour concatenating c and d (a point).

val append_contour : t -> t -> unit

Related to the python expression: c+d. A contour concatenating c and d (a point).

Related to the python assignement: c+=d. Appends d (another contour) to c.

val append_point : Point.t -> t -> unit

Related to the python assignement: c+=d. Appends d (another contour) to c.

Related to the python assignement: c+=d. Appends d (a point) to c.

val to_list : t -> Point.t list

Returns the point list of the contour.

Iterators
val iter : f:(Point.t -> unit) -> t -> unit

Iterates on the contour points.

val iteri : f:(int -> Point.t -> unit) -> t -> unit

Iterates on the contour points.

val map : f:(Point.t -> 'a) -> t -> 'a list
val mapi : f:(int -> Point.t -> 'a) -> t -> 'a list
val fold : init:'a -> f:('a -> Point.t -> 'a) -> t -> 'a

Methods

val contains_point : Point.t -> t -> bool
val contains_coord : coord -> t -> bool
val dup : t -> t

Returns a deep copy of the contour. That is, it copies the points that make up the contour.

val isEmpty : t -> bool

Returns a deep copy of the contour. That is, it copies the points that make up the contour.

val moveTo : x:int -> y:int -> t -> unit

Adds an initial, on-curve point at (x,y) to the contour.

val moveToCoord : coord -> t -> unit

Adds an initial, on-curve point at (x,y) to the contour.

Idem moveTo with float coords.

val lineTo : x:int -> y:int -> ?nth:int -> t -> unit

Idem moveTo with float coords.

Adds an line to the contour. If the optional third argument is given, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

val lineToCoord : coord -> ?nth:int -> t -> unit

Adds an line to the contour. If the optional third argument is given, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

Idem LineTo with float coords.

val cubicToCoord : cp1:coord -> cp2:coord -> pt:coord -> ?nth:int -> t -> unit

Idem LineTo with float coords.

Adds a cubic curve to the contour (requires Is_quadratic set to false). If the optional fourth argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

val cubicTo : cpx1:int -> cpy1:int -> cpx2:int -> cpy2:int -> x:int -> y:int -> ?nth:int -> t -> unit

Adds a cubic curve to the contour (requires Is_quadratic set to false). If the optional fourth argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

Idem cubicToCoord with int coords.

val quadraticToCoord : cp:coord -> pt:coord -> ?nth:int -> t -> unit

Idem cubicToCoord with int coords.

Adds a quadratic curve to the contour (requires Is_quadratic set to true). If the optional third argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

val quadraticTo : cpx:int -> cpy:int -> x:int -> y:int -> ?nth:int -> t -> unit

Adds a quadratic curve to the contour (requires Is_quadratic set to true). If the optional third argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour.

Idem quadraticToCoord with int coords.

val insertPtCoord : pt:coord -> ?onCurve:bool -> ?nth:int -> t -> unit

Idem quadraticToCoord with int coords.

Adds point to the contour. If the optional third argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour. The point may be either a point or a tuple with three members (x,y,on_curve)

val insertPt : x:int -> y:int -> ?onCurve:bool -> ?nth:int -> t -> unit

Adds point to the contour. If the optional third argument is give, the line will be added after the pos'th point, otherwise it will be at the end of the contour. The point may be either a point or a tuple with three members (x,y,on_curve)

Idem insertPtCoord with int coords.

val insertPoint : pt:Point.t -> ?nth:int -> t -> unit

Idem insertPtCoord with int coords.

Idem insertPt.

val makeFirst : int -> t -> unit

Rotate the point list so that the pos'th point becomes the first point.

val isClockwise : t -> int

Rotate the point list so that the pos'th point becomes the first point.

Returns whether the contour is drawn in a clockwise direction. A return value of -1 indicates that no consistant direction could be found (the contour self-intersects).

val reverseDirection : t -> unit

Returns whether the contour is drawn in a clockwise direction. A return value of -1 indicates that no consistant direction could be found (the contour self-intersects).

Reverse the order in which the contour is drawn (turns a clockwise contour into a counter-clockwise one). See also layer.correctDirection.

TODO

  • val similar
  • val xBoundsAtY
  • val yBoundsAtX
  • val addExtrema
  • val cluster
val merge : int list -> t -> unit

Removes the on-curve point a the given position and rearranges the other points to make the curve as similar to the original as possible. All of the listed position will be removed. See Also simplify.

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

Rounds the x and y coordinates. If factor is specified then new-coord = round(factor*old-coord)/factor. See Also cluster

val selfIntersects : t -> bool

Returns whether this contour intersects itself.

TODO

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

TODO

  • boundingBox
  • getSplineAfterPoint
val draw : GlyphPen.t -> t -> unit

TODO

  • val reduce

Attributes

Submodules giving read and write access to FontForge contour attributes.

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

Whether the contour should be interpretted as a set of quadratic or cubic splines. Setting this value has the side effect of converting the point list to the appropriate format.

module Closed : BoolAttr

Whether the contour should be interpretted as a set of quadratic or cubic splines. Setting this value has the side effect of converting the point list to the appropriate format.

module Name : StringAttr

Whether the contour is open or closed.

TODO module Spiro

OCaml

Innovation. Community. Security.