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)
font
A Font to copy, optional.
copy
Copies the contents of another object into this object.
Perl
$font->copy($copy_from);
Python
font.copy(copy_from)
copy_from
A Font to copy.
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)
chars
A string, the sequence of characters to get bounding boxes for.
strings
A list of strings to get bounding boxes for.
mode
An integer, which metric the algorithm should used (one of the metric mode constants).
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)
chars
A string, the sequence of characters to get escapements or edges for.
delta
An escapement_delta structure.
Family
GetFamilyAndStyle
FamilyAndStyle
SetFamilyAndStyle
SetFamilyAndFace
GetFamilyAndStyle
returns two strings: the family name and the style.
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)
family
A string, the name of the family.
style
A string, the name of the style.
code
An integer, an integer family/style code.
face
An integer, one of the face constants.
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)
chars
A string, the sequence of characters to get glyphs for.
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)
encoding
An integer, one of the encoding constants.
face
An integer, one of the face constants.
width
A floating point number, the font false bold width.
flags
An integer, a combination of font flags.
rotation
A floating point number, the font rotation in degrees.
shear
A floating point number, the font shear in degrees; must be between 45 and 135.
size
A floating point number, the font size in points.
spacing
An integer, one of the spacing constants.
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)
start
,end
Integers, the range to check.
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)
string
A string to measure.
strings
A list of strings to measure.
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)
string
A String to truncate.
strings
A list of strings to truncate.
mode
An integer, the truncating mode (one of the truncation constants).
width
A floating point number, the maximum width of the truncated string.
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)
index
An integer, the index of the tuned font to check.
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)
name
A string, the name of the family to get styles for.
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)
index
An integer, the index of the font family to get information for.
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)
family
A string, the name of the family to get style information for.
index
An integer, the index of the font style to get information for.
update_font_families
Returns true
if the installed fonts have changed.
Perl
update_font_families($checkOnly);
Python
update_font_families(checkOnly)
checkOnly
A boolean, if
true
, the calling program's internal font list will be updated to reflect the change; otherwise it simply reports whether the list of installed fonts has changed. (Currently this parameter is ignored; this function will not update the internal font list.)
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.
B_UNICODE_UTF8
UTF-8
B_ISO_8859_1
Latin 1
B_ISO_8859_2
Latin 2
B_ISO_8859_3
Latin 3
B_ISO_8859_4
Latin 4
B_ISO_8859_5
Latin/Cyrillic
B_ISO_8859_6
Latin/Arabic
B_ISO_8859_7
Latin/Greek
B_ISO_8859_8
Latin/Hebrew
B_ISO_8859_9
Latin 5
B_ISO_8859_10
Latin 6
B_MACINTOSH_ROMAN
Macintosh Roman
Faces
Perl
use HaikuR1::Font qw(:faces)
Python
Python does not support export tags.
B_ITALIC_FACE
Characters are drawn italicized.
B_UNDERSCORE_FACE
Characters are drawn underlined.
B_NEGATIVE_FACE
Characters are drawn in the low color, while the background is drawn in the high color.
B_OUTLINED_FACE
Characters are drawn hollow, with a line around their border, but unfilled.
B_STRIKEOUT_FACE
Characters are drawn "struck-out," with a line drawn horizontally through the middle.
B_BOLD_FACE
Characters are drawn in boldface.
B_REGULAR_FACE
Characters are drawn normally.
- B_CONDENSED_FACE
- B_LIGHT_FACE
- B_HEAVY_FACE
File formats
Perl
use HaikuR1::Font qw(:font_file_format)
Python
Python does not support export tags.
- B_TRUETYPE_WINDOWS
- B_POSTSCRIPT_TYPE1_WINDOWS
Flag values
Perl
use HaikuR1::Font qw(:flags)
Python
Python does not support export tags.
- B_DISABLE_ANTIALIASING
- B_FORCE_ANTIALIASING
- B_HAS_TUNED_FONT
- B_IS_FIXED
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.
- B_FONT_FAMILY_LENGTH
- B_FONT_STYLE_LENGTH
Metric modes
Perl
use HaikuR1::Font qw(:font_metric_mode)
Python
Python does not support export tags.
- B_SCREEN_METRIC
- B_PRINTING_METRIC
Spacing values
Perl
use HaikuR1::Font qw(:font_spacing)
Python
Python does not support export tags.
- B_CHAR_SPACING
- B_STRING_SPACING
- B_BITMAP_SPACING
- B_FIXED_SPACING
Text direction
Perl
use HaikuR1::Font qw(:font_direction)
Python
Python does not support export tags.
- B_FONT_LEFT_TO_RIGHT
- B_FONT_RIGHT_TO_LEFT
Truncation
Perl
use HaikuR1::Font qw(:truncation)
Python
Python does not support export tags.
- B_NO_TRUNCATION
- B_TRUNCATE_END
- B_TRUNCATE_BEGINNING
- B_TRUNCATE_MIDDLE
- B_TRUNCATE_SMART
GLOBALS
Perl
use HaikuR1::Font qw(:globals)
Python
Python does not support export tags.
- be_plain_font
- be_bold_font
- be_fixed_font