Class GD2::Font::TrueType
In: lib/gd2/font.rb
Parent: Object

Methods

Classes and Modules

Class GD2::Font::TrueType::FontconfigError
Class GD2::Font::TrueType::FreeTypeError

Constants

CHARMAP_UNICODE = 0
CHARMAP_SHIFT_JIS = 1
CHARMAP_BIG5 = 2
FTEX_LINESPACE = 1
FTEX_CHARMAP = 2
FTEX_RESOLUTION = 4
FTEX_DISABLE_KERNING = 8
FTEX_XSHOW = 16
FTEX_FONTPATHNAME = 32
FTEX_FONTCONFIG = 64
FTEX_RETURNFONTPATHNAME = 128

External Aliases

new -> []

Attributes

charmap  [R]  The chosen charmap
fontpath  [R]  The effective path to this TrueType font
hdpi  [R]  The chosen horizontal resolution hint
kerning  [R]  Whether kerning is desired
linespacing  [R]  The chosen linespacing
vdpi  [R]  The chosen vertical resolution hint

Public Class methods

Set whether fontconfig support should be enabled. To use this, the GD library must have been built with fontconfig support. Raises an error if fontconfig support is unavailable.

Return a boolean indicating whether fontconfig support has been enabled. The default is false.

Instantiate a TrueType font given by fontname (either a pathname or a fontconfig pattern if fontconfig is enabled) and ptsize (a point size given as a floating point number).

The possible options are:

  • :linespacing => The desired line spacing for multiline text, expressed as a multiple of the font height. A line spacing of 1.0 is the minimum to guarantee that lines of text do not collide. The default according to GD is 1.05.
  • :charmap => Specify a preference for Unicode, Shift_JIS, or Big5 character encoding. Use one of the constants Font::TrueType::CHARMAP_UNICODE, Font::TrueType::CHARMAP_SHIFT_JIS, or Font::TrueType::CHARMAP_BIG5.
  • :hdpi => The horizontal resolution hint for the rendering engine. The default according to GD is 96 dpi.
  • :vdpi => The vertical resolution hint for the rendering engine. The default according to GD is 96 dpi.
  • :dpi => A shortcut to specify both :hdpi and :vdpi.
  • :kerning => A boolean to specify whether kerning tables should be used, if fontconfig is available. The default is true.

Public Instance methods

Return a hash describing the rectangle that would enclose the given string rendered in this font at the given angle. The returned hash contains the following keys:

  • :lower_left => The [x, y] coordinates of the lower left corner.
  • :lower_right => The [x, y] coordinates of the lower right corner.
  • :upper_right => The [x, y] coordinates of the upper right corner.
  • :upper_left => The [x, y] coordinates of the upper left corner.
  • :position => An array of floating point character position offsets for each character of the string, beginning with 0.0. The array also includes a final position indicating where the last character ends.

The upper, lower, left, and right references are relative to the text of the string, regardless of the angle.

[Validate]