CrImage::Font::Face
Face is a font face. Its glyphs are often derived from a font file, such as "Comic_Sans_MS.ttf", but a face has a specific size, style, weight and hinting. For example, the 12pt and 18pt versions of Comic Sans are two different faces, even if derived from the same font file.
A Face is not safe for concurrent use by multiple fibers, as its methods may re-use implementation-specific caches and mask image buffers.
To create a Face, look to other modules that implement specific font file formats.
Instance methods
glyph returns the Draw.draw_mask parameters (dr, mask, maskp) to draw r's glyph at the sub-pixel destination location dot, and that glyph's advance width.
It returns !ok if the face does not contain a glyph for r.
The contents of the mask image returned by one glyph call may change after the next glyph call. Callers that want to cache the mask must make a copy.
glyph_advance returns the advance width of r's glyph.
It returns !ok if the face does not contain a glyph for r.
glyph_bounds returns the bounding box of r's glyph, drawn at a dot equal to the origin, and that glyph's advance width.
It returns !ok if the face does not contain a glyph for r.
The glyph's ascent and descent equal -bounds.min.y and +bounds.max.y. A visual depiction of what these metrics are is at https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/Art/glyph_metrics_2x.png
Render a glyph by its index.
Convert a character to its glyph index. Returns 0 if the character is not in the font.
Returns true if this face has vertical metrics (for vertical text layout).
kern returns the horizontal adjustment for the kerning pair (r0, r1). A positive kern means to move the glyphs further apart.
Returns the line height for this face in pixels.
This is the recommended vertical distance between baselines of consecutive lines of text.
Example:
line_height = face.line_height
y = 50
lines.each do |line|
drawer.draw_text(line, 10, y)
y += line_height
end
Lookup ligature substitution for a glyph sequence. Returns {ligature_glyph, glyphs_consumed} or {0, 0} if no ligature.
Measures the width of a string in pixels.
This is a convenience method that returns the advance width of the text as an integer pixel value.
Parameters:
text: The string to measure
Returns: Width in pixels
Example:
width = face.measure("Hello, World!")
puts "Text is #{width} pixels wide"
Returns true if this face supports ligature substitution. Default implementation returns false.
Returns the bounding rectangle for rendered text.
The rectangle represents the visual bounds of the text, with the origin at (0, 0). The min.y will typically be negative (above baseline) and max.y positive (below baseline).
Parameters:
text: The string to measure
Returns: Rectangle with text bounds in pixels
Example:
bounds = face.text_bounds("Hello")
puts "Width: #{bounds.width}, Height: #{bounds.height}"
Returns both width and height of text as a tuple.
This is a convenience method for quickly getting text dimensions.
Parameters:
text: The string to measure
Returns: Tuple of {width, height} in pixels
Example:
width, height = face.text_size("Hello")
Get vertical advance for a character (used for vertical text layout). Returns {advance, ok} where ok is false if glyph not found.
Get vertical advance by glyph index.