Haiku API Bindings
Font
Not logged in

Documentation | InterfaceKit | Font

SYNOPSIS

Perl

use HaikuR1::Font qw(be_plain_font);

# need an Application in order to initialize the font list
# (don't need to run the app, just create it)
my $app = HaikuR1::Application->new('application/whatever');

my $font = HaikuR1::Font->new(be_plain_font);

Python

from HaikuR1.ApplicationKit import Application
from HaikuR1.InterfaceKit import Font, be_plain_font

# need an Application in order to initialize the font list
# (don't need to run the app, just create it)
app = Application('application/whatever')

font = Font(be_plain_font)

DESCRIPTION

Exposes the BFont object.

For more information on Font, see the Be Book class description, the Be Book overview, and the Haiku Book class description.

METHODS

Constructor

Creates a Font.

Perl

HaikuR1::Font->new($font);

Python

Font(font)

copy

Copies the contents of another object into this object.

Perl

$font->copy($copy_from);

Python

font.copy(copy_from)

Blocks

Returns the supported Unicode blocks.

Perl

$font->Blocks();

Python

font.Blocks()

Bounding boxes

BoundingBox

GetBoundingBoxesAsGlyphs

GetBoundingBoxesAsString

GetBoundingBoxesForStrings

Gets the bounding boxes of the glyphs for the given characters as Rect objects. GetBoundingBoxesAsGlyphs gets the boxes for each character using character spacing; GetBoundingBoxesAsString gets them using string spacing. GetBoundingBoxesForStrings gets the bounding box for each entire string.

BoundingBox returns a Rect that can enclose the entire font in its current style and size.

Perl

$font->BoundingBox();
$font->GetBoundingBoxesAsGlyphs($chars, $mode);
$font->GetBoundingBoxesAsString($chars, $mode);
$font->GetBoundingBoxesForStrings($strings, $mode);

Python

font.BoundingBox()
font.GetBoundingBoxesAsGlyphs(chars, mode)
font.GetBoundingBoxesAsString(chars, mode)
font.GetBoundingBoxesForStrings(strings, mode)

Direction

Returns the font direction (one of the direction constants).

Perl

$font->Direction();

Python

font.Direction()

Escapements and edges

GetEscapements

GetEdges

GetEscapements returns two lists; each list will contain one element for each character in the input string. Both lists will contain Points; in the first list the Point will represent an escapement and in the second list it will represent an offset.

Essentially, this function measures a string just as StringWidth does, but 1) it measures the width of each individual character, and 2) it returns the widths in escapement units, which must be multiplied by the font size to get the pixel widths.

The escapement indicates a value by which the pen is moved after drawing a character; the Point's x value indicates the horizontal amount and the y value indicates the vertical amount. Usually the vertical amount will be 0, but for example if the font is rotated, there will be a vertical change as well.

The offset array adjusts the relative position of the character.

See the Be Book description of GetEscapements for more information on these two methods.

GetEdges returns a list of edge_info structures.

Perl

$font->GetEscapements($chars, $delta);
$font->GetEdges($chars);

Python

font.GetEscapements(chars, delta)
font.GetEdges(chars)

Family

GetFamilyAndStyle

FamilyAndStyle

SetFamilyAndStyle

SetFamilyAndFace

GetFamilyAndStyle returns two strings: the family name and the style. returns a unique integer code. SetFamilyAndStyle can take either two strings or an integer code. You may also pass the empty value in place of one of the strings in order to set only the other value. SetFamilyAndFace takes one string and one integer.

The family/style codes are manage by the application server and are not persistent; they may change if you install or uninstall fonts, or reboot the computer.

Perl

$font->GetFamilyAndStyle();
$font->FamilyAndStyle();
$font->SetFamilyAndStyle($family, $style);
$font->SetFamilyAndStyle($code);
$font->SetFamilyAndFace($family, $face);

Python

font.GetFamilyAndStyle()
font.FamilyAndStyle()
font.SetFamilyAndStyle(family, style)
font.SetFamilyAndStyle(code)
font.SetFamilyAndFace(family, face)

FileFormat

Returns the format of the file containing the font.

Perl

$font->FileFormat();

Python

font.FileFormat()

Fixed-width

IsFixed

IsFullAndHalfFixed

Returns true if the font is fixed.

A "full and half" fixed width font contains two different fixed widths (one for Kanji and one for Roman). At the moment, this is not supported; all fonts return false.

Perl

$font->IsFixed();
$font->IsFullAndHalfFixed();

Python

font.IsFixed()
font.IsFullAndHalfFixed()

PrintToStream

Prints information about the font to standard output.

Perl

$font->PrintToStream();

Python

font.PrintToStream()

Glyphs

GetGlyphShapes

GetHasGlyphs

GetGlyphShapes gets the glyph for each character in the given string as a Shape object. GetHasGlyphs gets a list of booleans indicating whether each character in the string has a glyph in the font.

Perl

$font->GetGlyphShapes($chars);
$font->GetHasGlyphs($chars);

Python

font.GetGlyphShapes(chars)
font.GetHasGlyphs(chars)

Height

GetHeight

Gets the height of the font as a font_height structure.

Perl

$font->GetHeight();

Python

font.GetHeight()

Settings

Encoding

SetEncoding

Face

SetFace

FalseBoldWidth

SetFalseBoldWidth

Flags

SetFlags

Rotation

SetRotation

Shear

SetShear

Size

SetSize

Spacing

SetSpacing

Gets or sets a particular setting.

Perl

$font->Encoding();
$font->SetEncoding($encoding);
$font->Face();
$font->SetFace($face);
$font->FalseBoldWidth();
$font->SetFalseBoldWidth($width);
$font->Flags();
$font->SetFlags($flags);
$font->Rotation();
$font->SetRotation($rotation);
$font->Shear();
$font->SetShear($shear);
$font->Size();
$font->SetSize($size);
$font->Spacing();
$font->SetSpacing($spacing);

Python

font.Encoding()
font.SetEncoding(encoding)
font.Face()
font.SetFace(face)
font.FalseBoldWidth()
font.SetFalseBoldWidth(width)
font.Flags()
font.SetFlags(flags)
font.Rotation()
font.SetRotation(rotation)
font.Shear()
font.SetShear(shear)
font.Size()
font.SetSize(size)
font.Spacing()
font.SetSpacing(spacing)

IncludesBlock

Indicates whether the Font includes the given range of code points.

Note that this method will return true if even one character in the range has a glyph in the Font.

Perl

$font->IncludesBlock($start, $end);

Python

font.IncludesBlock(start, end)

StringWidth

GetStringWidths

Gets the width of a string in the Font.

Perl

$font->StringWidth($string);
$font->GetStringWidths($strings);

Python

font.StringWidth(string)
font.GetStringWidths(strings)

TruncateString

GetTruncatedStrings

Truncates a string in place.

Perl

$font->TruncateString($string, $mode, $width);
$font->GetTruncatedStrings($strings, $mode, $width);

Python

font.TruncateString(string, mode, width)
font.GetTruncatedStrings(strings, mode, width)

Tuned fonts

CountTuned

GetTunedInfo

Returns information about tuned fonts. GetTunedInfo returns a tuned_font_info structure.

A tuned font is a bitmap font that has been generated from an outline font to look good when displayed on screen. They are generally useful for low-resolution displays. They are not used when printing.

(Well, Haiku doesn't use them when printing; some fonts designed for use by printers contain hand-tuned versions of common font sizes like 10 and 12.)

Perl

$font->CountTuned();
$font->GetTunedInfo($index);

Python

font.CountTuned()
font.GetTunedInfo(index)

FUNCTIONS

Perl

These may be exported with the tag :functions.

count_font_families

Returns the number of installed font families.

Perl

count_font_families();

Python

count_font_families()

count_font_styles

Returns the number of styles for the given family.

Perl

count_font_styles($name);

Python

count_font_styles(name)

get_font_family

Returns information about a font family; returns two items: the name and an integer, which can be compared against the flag constants.

Perl

get_font_family($index);

Python

get_font_family(index)

get_font_list

This function is not part of the Haiku API; it is a convenience function provided by the bindings that combines the count_font_families, count_font_styles, get_font_family, and get_font_style functions.

It returns a native list of native maps. Each map has three items: name, flags, and styles. styles is also a native list of native maps; each of these maps has three items: name, face, and flags.

Perl

get_font_list();

Python

get_font_list()

get_font_style

Returns information about a font style; returns three items: the name and two integers; the first can be compared against the face constants and the second can be compared against the flag constants.

Perl

get_font_style($family, $index);

Python

get_font_style(family, index)

update_font_families

Returns true if the installed fonts have changed.

Perl

update_font_families($checkOnly);

Python

update_font_families(checkOnly)

OPERATORS

==

Returns true if the Fonts are equal - same family, face, shear, etc.

!=

Returns true if the Fonts are not equal.

CONSTANTS

Encodings

Perl

use HaikuR1::Font qw(:encodings)

Python

Python does not support export tags.

Faces

Perl

use HaikuR1::Font qw(:faces)

Python

Python does not support export tags.

File formats

Perl

use HaikuR1::Font qw(:font_file_format)

Python

Python does not support export tags.

Flag values

Perl

use HaikuR1::Font qw(:flags)

Python

Python does not support export tags.

Lengths

These are mostly used internally by the C++ code, but they have been made available so you can determine the maximum length for a font family string or a font style string.

Perl

use HaikuR1::Font qw(:lengths)

Python

Python does not support export tags.

Metric modes

Perl

use HaikuR1::Font qw(:font_metric_mode)

Python

Python does not support export tags.

Spacing values

Perl

use HaikuR1::Font qw(:font_spacing)

Python

Python does not support export tags.

Text direction

Perl

use HaikuR1::Font qw(:font_direction)

Python

Python does not support export tags.

Truncation

Perl

use HaikuR1::Font qw(:truncation)

Python

Python does not support export tags.

GLOBALS

Perl

use HaikuR1::Font qw(:globals)

Python

Python does not support export tags.