Loading...
Searching...
No Matches
Public Member Functions | List of all members
BFont Class Reference

Represents a typeface including its family, style and size. More...

Public Member Functions

 BFont ()
 Creates a BFont object initialized to be_plain_font.
 
 BFont (const BFont &font)
 Creates and initializes a BFont object from another BFont object.
 
 BFont (const BFont *font)
 Creates and initializes a BFont object from a pointer to a BFont object.
 
unicode_block Blocks () const
 Gets a unicode_block object that identifies the Unicode blocks supported by this font face and family.
 
BRect BoundingBox () const
 Gets a BRect that encloses the font text.
 
int32 CountTuned () const
 Gets the number of tuned fonts for the font family and style.
 
font_direction Direction () const
 Gets the font direction, left-to-right or right-to left.
 
uint8 Encoding () const
 Gets the character encoding constant.
 
uint16 Face () const
 Gets the font face flags bitmap.
 
float FalseBoldWidth () const
 Gets the width of the font as if it were bold.
 
uint32 FamilyAndStyle () const
 Gets the code of the font family and style combination.
 
font_file_format FileFormat () const
 Gets whether the font is a TrueType™ or PostScript™ Type1 font.
 
uint32 Flags () const
 Gets the antialiasing flags.
 
void GetBoundingBoxesAsGlyphs (const char charArray[], int32 numChars, font_metric_mode mode, BRect boundingBoxArray[]) const
 Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each character in charArray.
 
void GetBoundingBoxesAsString (const char charArray[], int32 numChars, font_metric_mode mode, escapement_delta *delta, BRect boundingBoxArray[]) const
 Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each character in charArray with consideration to the horizontal space provided by the escapement delta.
 
void GetBoundingBoxesForStrings (const char *stringArray[], int32 numStrings, font_metric_mode mode, escapement_delta deltas[], BRect boundingBoxArray[]) const
 Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each string in stringArray with consideration to the horizontal space provided by the escapement deltas.
 
void GetEdges (const char charArray[], int32 numBytes, edge_info edgeArray[]) const
 Determines the edge information for each character in charArray and writes the result in edgeArray.
 
void GetEscapements (const char charArray[], int32 numChars, escapement_delta *delta, BPoint escapementArray[]) const
 Determines the escapements for each char in charArray and writes the result in escapementArray as an array of BPoint objects with consideration to the horizontal space provided by the escapement delta.
 
void GetEscapements (const char charArray[], int32 numChars, escapement_delta *delta, BPoint escapementArray[], BPoint offsetArray[]) const
 Determines the escapements for each char in charArray and writes the result in escapementArray as an array of BPoint objects with consideration to the horizontal space provided by the escapement delta and writes the offsets to offsetArray.
 
void GetEscapements (const char charArray[], int32 numChars, escapement_delta *delta, float escapementArray[]) const
 Determines the escapements for each char in charArray and writes the result in escapementArray with consideration to the horizontal space provided by the escapement delta.
 
void GetEscapements (const char charArray[], int32 numChars, float escapementArray[]) const
 Determines the escapements for each char in charArray and writes the result in escapementArray.
 
void GetFamilyAndStyle (font_family *family, font_style *style) const
 Writes out the name of the font family and/or font style.
 
void GetGlyphShapes (const char charArray[], int32 numChars, BShape *glyphShapeArray[]) const
 Writes an array of BShape objects to glyphShapeArray representing the glyph shapes of each character in charArray.
 
void GetHasGlyphs (const char charArray[], int32 numChars, bool hasArray[]) const
 Fills out hasArray with whether or not the font has a glyph for each character in charArray.
 
void GetHasGlyphs (const char charArray[], int32 numChars, bool hasArray[], bool useFallbacks) const
 Fills out hasArray with whether or not the font has a glyph for each character in charArray.
 
void GetHeight (font_height *height) const
 Fills out the font_height struct with the amount of vertical space surrounding a character.
 
void GetStringWidths (const char *stringArray[], const int32 lengthArray[], int32 numStrings, float widthArray[]) const
 Determines the amount of space required to draw each string in stringArray and writes the result in widthArray.
 
void GetTruncatedStrings (const char *stringArray[], int32 numStrings, uint32 mode, float width, BString resultArray[]) const
 Write truncated BString objects to resultArray given source BString objects in stringArray.
 
void GetTruncatedStrings (const char *stringArray[], int32 numStrings, uint32 mode, float width, char *resultArray[]) const
 Write truncated strings to resultArray given source BString objects in stringArray.
 
void GetTunedInfo (int32 index, tuned_font_info *info) const
 Writes information about the tuned font at index into info.
 
bool IncludesBlock (uint32 start, uint32 end) const
 Gets whether the font includes the specified Unicode block.
 
bool IsFixed () const
 Gets whether or not the font is fixed width.
 
bool IsFullAndHalfFixed () const
 Returns whether or not the font is fixed-width and contains both full and half-width characters.
 
bool operator!= (const BFont &font) const
 Inequality comparison overload method.
 
BFontoperator= (const BFont &font)
 Assignment overload method.
 
bool operator== (const BFont &font) const
 Equality comparison overload method.
 
void PrintToStream () const
 Writes information about the font to stdout.
 
float Rotation () const
 Gets the font rotation.
 
void SetEncoding (uint8 encoding)
 Sets the character encoding of the font for example B_UNICODE_UTF8 or B_ISO_8859_1.
 
void SetFace (uint16 face)
 Sets the font face according to the flags set by face.
 
void SetFalseBoldWidth (float width)
 Sets the false bold width.
 
status_t SetFamilyAndFace (const font_family family, uint16 face)
 Sets the font's family and face all at once.
 
status_t SetFamilyAndStyle (const font_family family, const font_style style)
 Sets the font's family and style all at once.
 
void SetFamilyAndStyle (uint32 code)
 Sets the font's family and style from a font identifier.
 
void SetFlags (uint32 flags)
 Sets font flags controlling antialiasing.
 
void SetRotation (float rotation)
 Sets the font rotation from the baseline in degrees.
 
void SetShear (float shear)
 Sets the angle in degrees relative to the baseline.
 
void SetSize (float size)
 Sets the font size.
 
void SetSpacing (uint8 spacing)
 Sets how characters are horizontally spaced relative to each other.
 
float Shear () const
 Gets the font shear.
 
float Size () const
 Gets the font size.
 
uint8 Spacing () const
 Gets the spacing constant.
 
float StringWidth (const char *string) const
 Determines the amount of space required to draw string in the current font.
 
float StringWidth (const char *string, int32 length) const
 Determines the amount of space required to draw string in the current font up to length characters.
 
void TruncateString (BString *inOut, uint32 mode, float width) const
 Truncates inOut to be no longer than width using the supplied truncation mode.
 

Detailed Description

Represents a typeface including its family, style and size.

The Interface Kit provides three prebuilt BFont objects which can be used but not modified.

A BFont object does nothing on its own but is used in combination with a view or control. Here is an example of creating a BFont object from a system font and assigning it to a view:

BFont font(be_plain_font);
font.SetSize(12.0);
font.SetEncoding(B_ISO_8859_1);
view->SetFont(&font);
@ B_ISO_8859_1
Definition: Font.h:57
Represents a typeface including its family, style and size.
Definition: Font.h:175

You may also create a BFont object from a view, modify it and reassign it back to the view like this:

BFont font;
view->GetFont(&font);
myView->SetFont(&font);
@ B_CHAR_SPACING
Definition: Font.h:24
@ B_ITALIC_FACE
Definition: Font.h:80
void SetSpacing(uint8 spacing)
Sets how characters are horizontally spaced relative to each other.
void SetFace(uint16 face)
Sets the font face according to the flags set by face.

You can change the way a font renders with the SetFamilyAndStyle(), SetFamilyAndFace(), SetSize(), SetShear(), SetRotation(), SetFalseBoldWidth(), SetSpacing(), SetEncoding(), SetFace(), and SetFlags() methods.

More information about the space taken up by a font can be determined by querying a BFont object using the following methods: StringWidth(), GetStringWidths() GetEscapements(), GetEdges(), GetHeight(), BoundingBox() GetBoundingBoxesAsGlyphs(), GetBoundingBoxesAsString(), and GetBoundingBoxesForStrings().

You can also perform intelligent string truncation with the TruncateString() and GetTruncatedStrings() methods.

Since
BeOS R3

Constructor & Destructor Documentation

◆ BFont() [1/3]

BFont::BFont ( )

Creates a BFont object initialized to be_plain_font.

See also
BView::GetFont()
Since
BeOS R3

◆ BFont() [2/3]

BFont::BFont ( const BFont font)

Creates and initializes a BFont object from another BFont object.

Parameters
fontThe BFont object to initialize from.
Since
BeOS R3

◆ BFont() [3/3]

BFont::BFont ( const BFont font)

Creates and initializes a BFont object from a pointer to a BFont object.

Parameters
fontThe pointer to a BFont object to initialize from.
Since
BeOS R3
Parameters
fontThe pointer to a BFont object to initialize from.
Since
BeOS R3

Member Function Documentation

◆ Blocks()

unicode_block BFont::Blocks ( ) const

Gets a unicode_block object that identifies the Unicode blocks supported by this font face and family.

Returns
A unicode_block object containing supported Unicode blocks.
Since
BeOS R4

◆ BoundingBox()

BRect BFont::BoundingBox ( ) const

Gets a BRect that encloses the font text.

Returns
A BRect that encloses the font text.
Since
BeOS R4

◆ CountTuned()

int32 BFont::CountTuned ( ) const

Gets the number of tuned fonts for the font family and style.

Returns
The number of tuned fonts.
Since
BeOS R3

◆ Direction()

font_direction BFont::Direction ( ) const

Gets the font direction, left-to-right or right-to left.

Returns
The font direction.
Since
BeOS R3

◆ Encoding()

uint8 BFont::Encoding ( ) const

Gets the character encoding constant.

Returns
The character encoding constant.
See also
SetEncoding()
Since
BeOS R3

◆ Face()

uint16 BFont::Face ( ) const

Gets the font face flags bitmap.

Returns
The font face flags bitmap.
See also
SetFace()
Since
BeOS R3

◆ FalseBoldWidth()

float BFont::FalseBoldWidth ( ) const

Gets the width of the font as if it were bold.

Returns
The font width of the bold font variety.
See also
SetFalseBoldWidth()
Since
Haiku R1

◆ FamilyAndStyle()

uint32 BFont::FamilyAndStyle ( ) const

Gets the code of the font family and style combination.

Returns
The family and style combination encoded as a unique integer.
See also
SetFamilyAndStyle(uint32 code)
Since
BeOS R3

◆ FileFormat()

font_file_format BFont::FileFormat ( ) const

Gets whether the font is a TrueType™ or PostScript™ Type1 font.

Returns
A font_file_format struct containing the font file format.
Since
BeOS R4

◆ Flags()

uint32 BFont::Flags ( ) const

Gets the antialiasing flags.

Returns
The antialiasing flags.
See also
SetFlags()
Since
BeOS R3

◆ GetBoundingBoxesAsGlyphs()

void BFont::GetBoundingBoxesAsGlyphs ( const char  charArray[],
int32  numChars,
font_metric_mode  mode,
BRect  boundingBoxArray[] 
) const

Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each character in charArray.

Each BRect object corresponds to the glyph of one character.

The font_metric_mode should contain one of the following values:

  • B_SCREEN_METRIC The bounding boxes should use the screen metric.
  • B_PRINTING_METRIC The bounding boxes should use the print metric.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
modeThe font_metric_mode to use, screen or printing.
boundingBoxArrayThe destination array of BRect bounding boxes.
Since
BeOS R4

◆ GetBoundingBoxesAsString()

void BFont::GetBoundingBoxesAsString ( const char  charArray[],
int32  numChars,
font_metric_mode  mode,
escapement_delta delta,
BRect  boundingBoxArray[] 
) const

Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each character in charArray with consideration to the horizontal space provided by the escapement delta.

Each BRect object corresponds to the glyph of one character.

The font_metric_mode should contain one of the following values:

  • B_SCREEN_METRIC The bounding boxes should use the screen metric.
  • B_PRINTING_METRIC The bounding boxes should use the print metric.

The provided escapement delta is applied as part of the bounding box calculations. This lets you specify a character spacing is looser or tighter than normal.

The escapement_delta structure contains the following values:

  • nonspace The amount of horizontal space to surround a visible glyph character with.
  • space The amount of horizontal space to surround a whitespace character with, for example B_TAB or B_SPACE.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
modeThe font_metric_mode to use, screen or printing.
deltaThe escapement_delta structure to use.
boundingBoxArrayThe destination array of BRect bounding boxes.
Since
BeOS R4

◆ GetBoundingBoxesForStrings()

void BFont::GetBoundingBoxesForStrings ( const char *  stringArray[],
int32  numStrings,
font_metric_mode  mode,
escapement_delta  deltas[],
BRect  boundingBoxArray[] 
) const

Writes an array of BRect objects to boundingBoxArray representing the bounding rectangles of each string in stringArray with consideration to the horizontal space provided by the escapement deltas.

Each BRect object corresponds to the bounding box of the entire string.

The font_metric_mode should contain one of the following values:

  • B_SCREEN_METRIC The bounding boxes should use the screen metric.
  • B_PRINTING_METRIC The bounding boxes should use the print metric.

The provided escapement deltas are applied as part of the bounding box calculations. This lets you specify a character spacing is looser or tighter than normal.

The escapement_delta structure contains the following values:

  • nonspace The amount of horizontal space to surround a visible glyph character with.
  • space The amount of horizontal space to surround a whitespace character with, for example B_TAB or B_SPACE.
Parameters
stringArrayThe source string array.
numStringsThe number of strings to consider in stringArray.
modeThe font_metric_mode to use, screen or printing.
deltasThe array of escapement_delta structures to use.
boundingBoxArrayThe destination array of BRect bounding boxes.
Since
BeOS R4

◆ GetEdges()

void BFont::GetEdges ( const char  charArray[],
int32  numChars,
edge_info  edgeArray[] 
) const

Determines the edge information for each character in charArray and writes the result in edgeArray.

The edge_info struct contains the following values:

  • left The distance that the character outline is inset from the left escapement boundary.
  • right The distance that the character outline is inset from the right escapement boundary.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
edgeArrayThe destination array of edge_info structs.
Since
BeOS R3

◆ GetEscapements() [1/4]

void BFont::GetEscapements ( const char  charArray[],
int32  numChars,
escapement_delta delta,
BPoint  escapementArray[] 
) const

Determines the escapements for each char in charArray and writes the result in escapementArray as an array of BPoint objects with consideration to the horizontal space provided by the escapement delta.

The escapement_delta structure contains the following values:

  • nonspace The amount of horizontal space to surround a visible glyph character with.
  • space The amount of horizontal space to surround a whitespace character with, for example B_TAB or B_SPACE.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
deltaThe escapement_delta structure to use.
escapementArrayThe destination array of escapements as BPoint objects.
Since
BeOS R4

◆ GetEscapements() [2/4]

void BFont::GetEscapements ( const char  charArray[],
int32  numChars,
escapement_delta delta,
BPoint  escapementArray[],
BPoint  offsetArray[] 
) const

Determines the escapements for each char in charArray and writes the result in escapementArray as an array of BPoint objects with consideration to the horizontal space provided by the escapement delta and writes the offsets to offsetArray.

The escapement_delta structure contains the following values:

  • nonspace The amount of horizontal space to surround a visible glyph character with.
  • space The amount of horizontal space to surround a whitespace character with, for example B_TAB or B_SPACE.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
deltaThe escapement_delta structure to use.
escapementArrayThe destination array of escapements as BPoint objects.
offsetArrayThe destination array of offsets as BPoint objects.
Since
BeOS R4

◆ GetEscapements() [3/4]

void BFont::GetEscapements ( const char  charArray[],
int32  numChars,
escapement_delta delta,
float  escapementArray[] 
) const

Determines the escapements for each char in charArray and writes the result in escapementArray with consideration to the horizontal space provided by the escapement delta.

The escapement_delta structure contains the following values:

  • nonspace The amount of horizontal space to surround a visible glyph character with.
  • space The amount of horizontal space to surround a whitespace character with, for example B_TAB or B_SPACE.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
deltaThe escapement_delta structure to use.
escapementArrayThe destination array to put the escapements.
Since
BeOS R3

◆ GetEscapements() [4/4]

void BFont::GetEscapements ( const char  charArray[],
int32  numChars,
float  escapementArray[] 
) const

Determines the escapements for each char in charArray and writes the result in escapementArray.

Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
escapementArrayThe destination array to put the escapements.
Since
BeOS R3

◆ GetFamilyAndStyle()

void BFont::GetFamilyAndStyle ( font_family *  family,
font_style *  style 
) const

Writes out the name of the font family and/or font style.

This method may be called with either family or style set to NULL in order to get one or the other.

Parameters
familyA font_family pointer to be filled out.
styleA font_style pointer to be filled out.
Since
BeOS R3

◆ GetGlyphShapes()

void BFont::GetGlyphShapes ( const char  charArray[],
int32  numChars,
BShape glyphShapeArray[] 
) const

Writes an array of BShape objects to glyphShapeArray representing the glyph shapes of each character in charArray.

Each BShape object corresponds to the glyph of one character.

Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
glyphShapeArrayThe destination array of BShape glyphs.
Since
BeOS R4

◆ GetHasGlyphs() [1/2]

void BFont::GetHasGlyphs ( const char  charArray[],
int32  numChars,
bool  hasArray[] 
) const

Fills out hasArray with whether or not the font has a glyph for each character in charArray.

true is written in hasArray if a glyph is found for the character, false otherwise.

Remarks
After the introduction of fallback fonts for missing glyphs, this is not exaclty what the name or the original desciption imply. As the objective of this method is to know if a string can be presented to the user without getting "no glyph" symbols, it will still write true if the queried font does not provide a glyph for a character but a fallback font does.
Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
hasArrayThe destination array of booleans.
Since
BeOS R4

◆ GetHasGlyphs() [2/2]

void BFont::GetHasGlyphs ( const char  charArray[],
int32  numChars,
bool  hasArray[],
bool  useFallbacks 
) const

Fills out hasArray with whether or not the font has a glyph for each character in charArray.

true is written in hasArray if the character has a glyph in the current font and false otherwise. Fallback fonts are also considered in the search if useFallbacks is true.

Parameters
charArrayThe source character array.
numCharsThe number of characters to consider in charArray.
hasArrayThe destination array of booleans.
useFallbacksWhether to consider fallback fonts in the answer.
Since
Haiku R1

◆ GetHeight()

void BFont::GetHeight ( font_height _height) const

Fills out the font_height struct with the amount of vertical space surrounding a character.

The font_height struct contains the following values:

  • ascent The distance characters can ascend above the baseline.
  • descent The distance characters can descend below the baseline.
  • leading The distance between lines, descent above to ascent below.
Parameters
_heightThe font_height struct to fill out.
Since
BeOS R3

◆ GetStringWidths()

void BFont::GetStringWidths ( const char *  stringArray[],
const int32  lengthArray[],
int32  numStrings,
float  widthArray[] 
) const

Determines the amount of space required to draw each string in stringArray and writes the result in widthArray.

Parameters
stringArrayThe source string array.
lengthArrayThe number of characters to consider for each string in stringArray
numStringsThe number of strings in stringArray.
widthArrayThe destination array to put the widths required to draw each string.
Since
BeOS R3

◆ GetTruncatedStrings() [1/2]

void BFont::GetTruncatedStrings ( const char *  stringArray[],
int32  numStrings,
uint32  mode,
float  width,
BString  resultArray[] 
) const

Write truncated BString objects to resultArray given source BString objects in stringArray.

The following truncation modes are supported:

  • B_TRUNCATE_BEGINNING Truncate from the beginning of the string.
  • B_TRUNCATE_MIDDLE Truncate from the middle of the string.
  • B_TRUNCATE_END Truncate from the end of the string.
  • B_TRUNCATE_SMART Truncate from anywhere, but do so so that each string is made unique after being truncated.
Parameters
stringArrayThe source string array.
numStringsThe number of strings in stringArray.
modeTruncation mode to use.
widthThe maximum width to truncate to.
resultArrayThe destination string array.
Since
BeOS R5

◆ GetTruncatedStrings() [2/2]

void BFont::GetTruncatedStrings ( const char *  stringArray[],
int32  numStrings,
uint32  mode,
float  width,
char *  resultArray[] 
) const

Write truncated strings to resultArray given source BString objects in stringArray.

resultArray is an array of pointers to string buffers which should be allocated ahead of time and should be at least 3 bytes longer than the matching input string. The 3 extra bytes provide enough room for the truncated output given that GetTruncatedStrings() truncates only a single-byte character from the input string and replaces it with an ellipsis character (which takes three bytes for the UTF-8 encoding), and adds a NUL-terminator.

The following truncation modes are supported:

  • B_TRUNCATE_BEGINNING Truncate from the beginning of the string.
  • B_TRUNCATE_MIDDLE Truncate from the middle of the string.
  • B_TRUNCATE_END Truncate from the end of the string.
  • B_TRUNCATE_SMART Truncate from anywhere, but do so so that each string is made unique after being truncated.
Parameters
stringArrayThe source string array.
numStringsThe number of strings in stringArray.
modeTruncation mode to use.
widthThe maximum width to truncate to.
resultArrayThe destination string array.
Since
BeOS R5

◆ GetTunedInfo()

void BFont::GetTunedInfo ( int32  index,
tuned_font_info info 
) const

Writes information about the tuned font at index into info.

The index begins at 0 and counts tuned fonts for current font family and style only.

Parameters
indexThe index of desired tuned font.
infoThe turned_font_info struct to be filled out.
Since
BeOS R3

◆ IncludesBlock()

bool BFont::IncludesBlock ( uint32  start,
uint32  end 
) const

Gets whether the font includes the specified Unicode block.

Since
Haiku R1

◆ IsFixed()

bool BFont::IsFixed ( ) const

Gets whether or not the font is fixed width.

Returns
true if the font is fixed width, false otherwise.
Since
BeOS R4

◆ IsFullAndHalfFixed()

bool BFont::IsFullAndHalfFixed ( ) const

Returns whether or not the font is fixed-width and contains both full and half-width characters.

A full-and-half-fixed font is one that contains characters of only two sizes, so that CJK languages can be properly supported.

Note
This was unimplemented in BeOS R5, but is implemented in Haiku.
Since
BeOS R4

◆ operator!=()

bool BFont::operator!= ( const BFont font) const

Inequality comparison overload method.

Parameters
fontThe BFont object to compare the current font to.
Returns
true if the fonts objects are NOT identical, true otherwise.
Since
BeOS R3

◆ operator=()

BFont & BFont::operator= ( const BFont font)

Assignment overload method.

Parameters
fontThe BFont object to assign from.
Since
BeOS R3

◆ operator==()

bool BFont::operator== ( const BFont font) const

Equality comparison overload method.

Parameters
fontThe BFont object to compare the current font to.
Returns
true if the fonts objects are identical, false otherwise.
Since
BeOS R3

◆ PrintToStream()

void BFont::PrintToStream ( ) const

Writes information about the font to stdout.

printf("BFont { %s (%d), %s (%d) 0x%x %f/%f %fpt (%f %f %f), %d }\n", family, fFamilyID, style, fStyleID, fFace, fShear, fRotation, fSize, fHeight.ascent, fHeight.descent, fHeight.leading, fEncoding);

Since
BeOS R3

◆ Rotation()

float BFont::Rotation ( ) const

Gets the font rotation.

Returns
The font rotation as an angle in degrees.
See also
SetRotation()
Since
BeOS R3

◆ SetEncoding()

void BFont::SetEncoding ( uint8  encoding)

Sets the character encoding of the font for example B_UNICODE_UTF8 or B_ISO_8859_1.

The following character encodings are supported:

  • B_UNICODE_UTF8
  • B_ISO_8859_1 aka Latin 1 aka "Western European".
  • B_ISO_8859_2 aka Latin 2 aka "Eastern European".
  • B_ISO_8859_3 aka Latin 3 aka "South European".
  • B_ISO_8859_4 aka Latin 4 aka "Northern European".
  • B_ISO_8859_5 aka "Latin/Cyrillic".
  • B_ISO_8859_6 aka "Latin/Arabic".
  • B_ISO_8859_7 aka "Latin/Greek".
  • B_ISO_8859_8 aka "Latin/Hebrew".
  • B_ISO_8859_9 aka Latin 5 aka "Latin/Turkish".
  • B_ISO_8859_10 aka Latin 6 aka "Nordic".
  • B_MACINTOSH_ROMAN

UTF-8 is the standard encoding used by classes in the Interface Kit. It is part of the Unicode® standard and allows Haiku to represent characters from all over the world while maintaining backwards compatibility with 7-bit ASCII codes.

Each of the encodings extend the ASCII codes and differ from each other only when the highest bit is set to 1, in other words, the value is greater than 127. Furthermore each of the encodings except for UTF-8 are represented by a single byte and consequently encompass a limited set of characters. Most of the encodings are in the ISO/IEC 8859 family of character codes with the notable exception of Macintosh Roman which is the standard encoding used by the classic Mac OS®.

If the value of the first byte of a UTF-8 character is greater than 127 it indicates that the character is a multibyte character and therefore you must look at the next byte (and possibly the third byte, or rarely even forth byte) to get the whole character.

Setting the character encoding on a view determines how BView::DrawString() interprets the values passed to it and also how BView::KeyDown() interprets the values representing the keys that the user presses.

Parameters
encodingThe character encoding to set the font to.
Since
BeOS R3

◆ SetFace()

void BFont::SetFace ( uint16  face)

Sets the font face according to the flags set by face.

The following font face flags are supported:

  • B_ITALIC_FACE Characters are slanted to the right.
  • B_UNDERSCORE_FACE Characters are underlined.
  • B_NEGATIVE_FACE High and low colors are reversed when drawing characters.
  • B_OUTLINED_FACE Characters are drawn hollowed out.
  • B_STRIKEOUT_FACE A horizontal line is drawn through their middle.
  • B_BOLD_FACE Characters are bold.
  • B_REGULAR_FACE Characters are drawn normally.
  • B_CONDENSED_FACE Characters are drawn condensed. Not in BeOS 5.
  • B_LIGHT_FACE Characters are drawn thiner than normal. Not in BeOS 5.
  • B_HEAVY_FACE Characters are drawn heavier than normal. Not in BeOS 5.
Parameters
faceThe bitmap of font face flags to set.
Since
BeOS R3

◆ SetFalseBoldWidth()

void BFont::SetFalseBoldWidth ( float  width)

Sets the false bold width.

Parameters
widthThe false bold width to set.
Since
Haiku R1

◆ SetFamilyAndFace()

status_t BFont::SetFamilyAndFace ( const font_family  family,
uint16  face 
)

Sets the font's family and face all at once.

Parameters
familyFont family to set.
faceFont face to set.
Note
To comply with the BeBook, this function will only set valid values, i.e. passing a nonexistent family will cause only the face to be set. Additionally, if a particular face does not exist in a family, the closest match will be chosen.
Returns
A status code, B_OK on success or an error code.
Return values
B_ERRORFamily does not exists or face has an invalid value.
Since
BeOS R4

◆ SetFamilyAndStyle() [1/2]

status_t BFont::SetFamilyAndStyle ( const font_family  family,
const font_style  style 
)

Sets the font's family and style all at once.

Parameters
familyFont family to set.
styleFont style to set.
Returns
A status code, B_OK on success or an error code.
Return values
B_BAD_VALUEfamily is NULL and style is NULL.
B_NAME_NOT_FOUNDFamily or style do not exist.
Since
BeOS R3

◆ SetFamilyAndStyle() [2/2]

void BFont::SetFamilyAndStyle ( uint32  code)

Sets the font's family and style from a font identifier.

Parameters
codeUnique font identifier obtained from the server.
Since
BeOS R3

◆ SetFlags()

void BFont::SetFlags ( uint32  flags)

Sets font flags controlling antialiasing.

The following flags are supported:

  • B_DISABLE_ANTIALIASING Disable antialiasing.
  • B_FORCE_ANTIALIASING Force antialiasing.
Parameters
flagsThe bitmap of flags to set.
Since
Haiku R1

◆ SetRotation()

void BFont::SetRotation ( float  rotation)

Sets the font rotation from the baseline in degrees.

The default baseline is 0° and rotates counterclockwise. Rotation is not supported by BTextView.

Parameters
rotationThe rotation in degrees to set the font to.
Since
BeOS R3

◆ SetShear()

void BFont::SetShear ( float  shear)

Sets the angle in degrees relative to the baseline.

The default shear is 90.0° measured counterclockwise. The shear range is from 45.0° to 135.0°.

Parameters
shearThe shear in degrees to set the font to.
Since
BeOS R3

◆ SetSize()

void BFont::SetSize ( float  size)

Sets the font size.

Parameters
sizeThe point size to set the font to.
Since
BeOS R3

◆ SetSpacing()

void BFont::SetSpacing ( uint8  spacing)

Sets how characters are horizontally spaced relative to each other.

  • B_CHAR_SPACING Position each character without adjustment. Best mode for printing. Characters may collide or overlap at small font sizes.
  • B_STRING_SPACING Optimizes the position of each character within its space. Collisions are unlikely but characters may touch each other. Best mode to use when the screen needs to match what appears on the printed page. Adding new characters requires the entire string to be redrawn.
  • B_BITMAP_SPACING The widths of the characters are chosen so that they never collide and rarely touch. Best mode for drawing small amounts of text. Character widths are integral values. Spacing on screen will not match spacing used by B_CHAR_SPACING mode for printing.
  • B_FIXED_SPACING Positions characters at a constant width. Must be used with fixed-width fonts otherwise B_CHAR_SPACING mode is used. All characters have an identical integral escapement.

B_STRING_SPACING and B_BITMAP_SPACING modes are relevant only for font sizes from 7.0pt to 18.0pt, above and below that range B_CHAR_SPACING produces nicer results. B_CHAR_SPACING is also always used for rotated or sheared text and when antialiasing is disabled.

Parameters
spacingThe spacing mode to set.
See also
BView::DrawString()
GetEscapements()
Since
BeOS R3

◆ Shear()

float BFont::Shear ( ) const

Gets the font shear.

Returns
The font shear as an angle from 45.0° to 135.0°.
See also
SetShear()
Since
BeOS R3

◆ Size()

float BFont::Size ( ) const

Gets the font size.

Returns
The font size in points.
See also
SetSize()
Since
BeOS R3

◆ Spacing()

uint8 BFont::Spacing ( ) const

Gets the spacing constant.

Returns
The spacing constant.
See also
SetSpacing()
Since
BeOS R3

◆ StringWidth() [1/2]

float BFont::StringWidth ( const char *  string) const

Determines the amount of space required to draw string in the current font.

Parameters
stringThe source string.
Returns
The width required to draw the string.
Since
BeOS R3

◆ StringWidth() [2/2]

float BFont::StringWidth ( const char *  string,
int32  length 
) const

Determines the amount of space required to draw string in the current font up to length characters.

Parameters
stringThe source string.
lengthThe number of characters in string to consider.
Returns
The width required to draw the string.
Since
BeOS R3

◆ TruncateString()

void BFont::TruncateString ( BString inOut,
uint32  mode,
float  width 
) const

Truncates inOut to be no longer than width using the supplied truncation mode.

The following truncation modes are supported:

  • B_NO_TRUNCATION Does nothing.
  • B_TRUNCATE_BEGINNING Truncate from the beginning of the string.
  • B_TRUNCATE_MIDDLE Truncate from the middle of the string.
  • B_TRUNCATE_END Truncate from the end of the string.
  • B_TRUNCATE_SMART Truncate from anywhere, but do so so that each string is made unique after being truncated.
Parameters
inOutThe BString to truncate.
modeTruncation mode to use.
widthThe maximum width to truncate to.
Since
BeOS R5