2005-11-07 14:02:39 +03:00
|
|
|
/*
|
2009-08-27 15:12:41 +04:00
|
|
|
* Copyright 2005-2009, Haiku, Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
2005-11-07 14:02:39 +03:00
|
|
|
*/
|
2002-11-07 03:42:03 +03:00
|
|
|
#ifndef _FONT_H_
|
|
|
|
#define _FONT_H_
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <InterfaceDefs.h>
|
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
class BPoint;
|
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
|
|
|
|
#define B_FONT_FAMILY_LENGTH 63
|
|
|
|
#define B_FONT_STYLE_LENGTH 63
|
2005-11-07 14:02:39 +03:00
|
|
|
typedef char font_family[B_FONT_FAMILY_LENGTH + 1];
|
2002-10-12 23:02:55 +04:00
|
|
|
typedef char font_style[B_FONT_STYLE_LENGTH + 1];
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// font spacing
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_CHAR_SPACING = 0,
|
|
|
|
B_STRING_SPACING = 1,
|
|
|
|
B_BITMAP_SPACING = 2,
|
|
|
|
B_FIXED_SPACING = 3
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
enum font_direction {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_FONT_LEFT_TO_RIGHT = 0,
|
|
|
|
B_FONT_RIGHT_TO_LEFT = 1
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// font flags
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
|
|
|
B_DISABLE_ANTIALIASING = 0x00000001,
|
|
|
|
B_FORCE_ANTIALIASING = 0x00000002
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// truncation modes
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_TRUNCATE_END = 0,
|
|
|
|
B_TRUNCATE_BEGINNING = 1,
|
|
|
|
B_TRUNCATE_MIDDLE = 2,
|
|
|
|
B_TRUNCATE_SMART = 3
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// font encodings
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_UNICODE_UTF8 = 0,
|
|
|
|
B_ISO_8859_1 = 1,
|
|
|
|
B_ISO_8859_2 = 2,
|
|
|
|
B_ISO_8859_3 = 3,
|
|
|
|
B_ISO_8859_4 = 4,
|
|
|
|
B_ISO_8859_5 = 5,
|
|
|
|
B_ISO_8859_6 = 6,
|
|
|
|
B_ISO_8859_7 = 7,
|
|
|
|
B_ISO_8859_8 = 8,
|
|
|
|
B_ISO_8859_9 = 9,
|
|
|
|
B_ISO_8859_10 = 10,
|
|
|
|
B_MACINTOSH_ROMAN = 11
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// flags for get_font_family() and get_font_style()
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_HAS_TUNED_FONT = 0x0001,
|
|
|
|
B_IS_FIXED = 0x0002
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
// font face flags
|
2002-10-12 23:02:55 +04:00
|
|
|
enum {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_ITALIC_FACE = 0x0001,
|
|
|
|
B_UNDERSCORE_FACE = 0x0002,
|
|
|
|
B_NEGATIVE_FACE = 0x0004,
|
|
|
|
B_OUTLINED_FACE = 0x0008,
|
|
|
|
B_STRIKEOUT_FACE = 0x0010,
|
|
|
|
B_BOLD_FACE = 0x0020,
|
2008-05-24 18:54:18 +04:00
|
|
|
B_REGULAR_FACE = 0x0040,
|
|
|
|
// new in Haiku:
|
|
|
|
B_CONDENSED_FACE = 0x0080,
|
|
|
|
B_LIGHT_FACE = 0x0100,
|
|
|
|
B_HEAVY_FACE = 0x0200,
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
enum font_metric_mode {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_SCREEN_METRIC = 0,
|
|
|
|
B_PRINTING_METRIC = 1
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
enum font_file_format {
|
2005-11-07 14:02:39 +03:00
|
|
|
B_TRUETYPE_WINDOWS = 0,
|
|
|
|
B_POSTSCRIPT_TYPE1_WINDOWS = 1
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
class unicode_block {
|
2009-08-26 14:58:22 +04:00
|
|
|
public:
|
|
|
|
inline unicode_block();
|
|
|
|
inline unicode_block(uint64 block2, uint64 block1);
|
|
|
|
|
|
|
|
inline bool Includes(const unicode_block& block) const;
|
|
|
|
inline unicode_block operator&(const unicode_block& block) const;
|
|
|
|
inline unicode_block operator|(const unicode_block& block) const;
|
|
|
|
inline unicode_block& operator=(const unicode_block& block);
|
|
|
|
inline bool operator==(const unicode_block& block) const;
|
|
|
|
inline bool operator!=(const unicode_block& block) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint64 fData[2];
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
struct edge_info {
|
|
|
|
float left;
|
|
|
|
float right;
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
struct font_height {
|
|
|
|
float ascent;
|
|
|
|
float descent;
|
|
|
|
float leading;
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
struct escapement_delta {
|
|
|
|
float nonspace;
|
|
|
|
float space;
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
struct font_cache_info {
|
|
|
|
int32 sheared_font_penalty;
|
|
|
|
int32 rotated_font_penalty;
|
|
|
|
float oversize_threshold;
|
|
|
|
int32 oversize_penalty;
|
|
|
|
int32 cache_size;
|
|
|
|
float spacing_size_threshold;
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
struct tuned_font_info {
|
|
|
|
float size;
|
|
|
|
float shear;
|
|
|
|
float rotation;
|
|
|
|
uint32 flags;
|
|
|
|
uint16 face;
|
|
|
|
};
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
class BShape;
|
|
|
|
class BString;
|
|
|
|
class BFontPrivate;
|
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
class BFont {
|
2009-08-26 14:58:22 +04:00
|
|
|
public:
|
|
|
|
BFont();
|
|
|
|
BFont(const BFont& font);
|
|
|
|
BFont(const BFont* font);
|
|
|
|
|
|
|
|
status_t SetFamilyAndStyle(const font_family family,
|
|
|
|
const font_style style);
|
|
|
|
void SetFamilyAndStyle(uint32 code);
|
|
|
|
status_t SetFamilyAndFace(const font_family family,
|
|
|
|
uint16 face);
|
|
|
|
|
|
|
|
void SetSize(float size);
|
|
|
|
void SetShear(float shear);
|
|
|
|
void SetRotation(float rotation);
|
|
|
|
void SetFalseBoldWidth(float width);
|
|
|
|
void SetSpacing(uint8 spacing);
|
|
|
|
void SetEncoding(uint8 encoding);
|
|
|
|
void SetFace(uint16 face);
|
|
|
|
void SetFlags(uint32 flags);
|
|
|
|
|
|
|
|
void GetFamilyAndStyle(font_family* family,
|
|
|
|
font_style* style) const;
|
|
|
|
uint32 FamilyAndStyle() const;
|
|
|
|
float Size() const;
|
|
|
|
float Shear() const;
|
|
|
|
float Rotation() const;
|
|
|
|
float FalseBoldWidth() const;
|
|
|
|
uint8 Spacing() const;
|
|
|
|
uint8 Encoding() const;
|
|
|
|
uint16 Face() const;
|
|
|
|
uint32 Flags() const;
|
|
|
|
|
|
|
|
font_direction Direction() const;
|
|
|
|
bool IsFixed() const;
|
|
|
|
bool IsFullAndHalfFixed() const;
|
|
|
|
BRect BoundingBox() const;
|
|
|
|
unicode_block Blocks() const;
|
|
|
|
font_file_format FileFormat() const;
|
|
|
|
|
|
|
|
int32 CountTuned() const;
|
|
|
|
void GetTunedInfo(int32 index,
|
|
|
|
tuned_font_info* info) const;
|
|
|
|
|
|
|
|
void TruncateString(BString* inOut, uint32 mode,
|
|
|
|
float width) const;
|
|
|
|
void GetTruncatedStrings(const char* stringArray[],
|
|
|
|
int32 numStrings, uint32 mode, float width,
|
|
|
|
BString resultArray[]) const;
|
|
|
|
void GetTruncatedStrings(const char* stringArray[],
|
|
|
|
int32 numStrings, uint32 mode,
|
|
|
|
float width, char* resultArray[]) const;
|
|
|
|
|
|
|
|
float StringWidth(const char* string) const;
|
|
|
|
float StringWidth(const char* string,
|
|
|
|
int32 length) const;
|
|
|
|
void GetStringWidths(const char* stringArray[],
|
|
|
|
const int32 lengthArray[],
|
|
|
|
int32 numStrings,
|
|
|
|
float widthArray[]) const;
|
|
|
|
|
|
|
|
void GetEscapements(const char charArray[],
|
|
|
|
int32 numChars,
|
|
|
|
float escapementArray[]) const;
|
|
|
|
void GetEscapements(const char charArray[],
|
|
|
|
int32 numChars, escapement_delta* delta,
|
|
|
|
float escapementArray[]) const;
|
|
|
|
void GetEscapements(const char charArray[],
|
|
|
|
int32 numChars, escapement_delta* delta,
|
|
|
|
BPoint escapementArray[]) const;
|
|
|
|
void GetEscapements(const char charArray[],
|
|
|
|
int32 numChars, escapement_delta* delta,
|
|
|
|
BPoint escapementArray[],
|
|
|
|
BPoint offsetArray[]) const;
|
|
|
|
|
|
|
|
void GetEdges(const char charArray[],
|
|
|
|
int32 numBytes,
|
|
|
|
edge_info edgeArray[]) const;
|
|
|
|
void GetHeight(font_height* height) const;
|
|
|
|
|
|
|
|
void GetBoundingBoxesAsGlyphs(
|
|
|
|
const char charArray[], int32 numChars,
|
|
|
|
font_metric_mode mode,
|
|
|
|
BRect boundingBoxArray[]) const;
|
|
|
|
void GetBoundingBoxesAsString(
|
|
|
|
const char charArray[], int32 numChars,
|
|
|
|
font_metric_mode mode,
|
|
|
|
escapement_delta* delta,
|
|
|
|
BRect boundingBoxArray[]) const;
|
|
|
|
void GetBoundingBoxesForStrings(
|
|
|
|
const char* stringArray[],
|
|
|
|
int32 numStrings, font_metric_mode mode,
|
|
|
|
escapement_delta deltas[],
|
|
|
|
BRect boundingBoxArray[]) const;
|
|
|
|
|
|
|
|
void GetGlyphShapes(const char charArray[],
|
|
|
|
int32 numChars,
|
|
|
|
BShape* glyphShapeArray[]) const;
|
|
|
|
|
|
|
|
void GetHasGlyphs(const char charArray[],
|
|
|
|
int32 numChars,
|
|
|
|
bool hasArray[]) const;
|
|
|
|
|
|
|
|
BFont& operator=(const BFont& font);
|
|
|
|
bool operator==(const BFont& font) const;
|
|
|
|
bool operator!=(const BFont& font) const;
|
|
|
|
|
|
|
|
void PrintToStream() const;
|
|
|
|
|
|
|
|
private:
|
2005-11-07 14:02:39 +03:00
|
|
|
friend void _init_global_fonts_();
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
void _GetExtraFlags() const;
|
|
|
|
void _GetBoundingBoxes(const char charArray[],
|
|
|
|
int32 numChars, font_metric_mode mode,
|
|
|
|
bool string_escapement,
|
|
|
|
escapement_delta* delta,
|
|
|
|
BRect boundingBoxArray[],
|
|
|
|
bool asString) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint16 fFamilyID;
|
|
|
|
uint16 fStyleID;
|
|
|
|
float fSize;
|
|
|
|
float fShear;
|
|
|
|
float fRotation;
|
|
|
|
float fFalseBoldWidth;
|
|
|
|
uint8 fSpacing;
|
|
|
|
uint8 fEncoding;
|
|
|
|
uint16 fFace;
|
|
|
|
uint32 fFlags;
|
|
|
|
mutable font_height fHeight;
|
|
|
|
mutable uint32 fExtraFlags;
|
|
|
|
|
|
|
|
uint32 _reserved[1];
|
2002-10-12 23:02:55 +04:00
|
|
|
};
|
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
// #pragma mark - BFont related declarations
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
extern const BFont* be_plain_font;
|
|
|
|
extern const BFont* be_bold_font;
|
|
|
|
extern const BFont* be_fixed_font;
|
2002-10-12 23:02:55 +04:00
|
|
|
|
|
|
|
int32 count_font_families(void);
|
2009-08-26 14:58:22 +04:00
|
|
|
status_t get_font_family(int32 index, font_family* name,
|
|
|
|
uint32* flags = NULL);
|
2002-10-12 23:02:55 +04:00
|
|
|
|
|
|
|
int32 count_font_styles(font_family name);
|
2009-08-26 14:58:22 +04:00
|
|
|
status_t get_font_style(font_family family, int32 index, font_style* name,
|
|
|
|
uint32* flags = NULL);
|
|
|
|
status_t get_font_style(font_family family, int32 index, font_style* name,
|
|
|
|
uint16* face, uint32* flags = NULL);
|
2005-11-07 14:02:39 +03:00
|
|
|
bool update_font_families(bool checkOnly);
|
2002-10-12 23:02:55 +04:00
|
|
|
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
|
|
|
// #pragma mark - unicode_block inlines
|
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
unicode_block::unicode_block()
|
|
|
|
{
|
|
|
|
fData[0] = fData[1] = 0LL;
|
|
|
|
}
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
unicode_block::unicode_block(uint64 block2, uint64 block1)
|
|
|
|
{
|
2002-10-12 23:02:55 +04:00
|
|
|
fData[0] = block1;
|
|
|
|
fData[1] = block2;
|
|
|
|
}
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
bool
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block::Includes(const unicode_block& block) const
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
|
|
|
return (fData[0] & block.fData[0]) == block.fData[0]
|
|
|
|
&& (fData[1] & block.fData[1]) == block.fData[1];
|
2002-10-12 23:02:55 +04:00
|
|
|
}
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
unicode_block
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block::operator&(const unicode_block& block) const
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
|
|
|
unicode_block result;
|
|
|
|
result.fData[0] = fData[0] & block.fData[0];
|
|
|
|
result.fData[1] = fData[1] & block.fData[1];
|
|
|
|
|
|
|
|
return result;
|
2002-10-12 23:02:55 +04:00
|
|
|
}
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
unicode_block
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block::operator|(const unicode_block& block) const
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
|
|
|
unicode_block result;
|
|
|
|
result.fData[0] = fData[0] | block.fData[0];
|
|
|
|
result.fData[1] = fData[1] | block.fData[1];
|
|
|
|
|
|
|
|
return result;
|
2002-10-12 23:02:55 +04:00
|
|
|
}
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2002-10-12 23:02:55 +04:00
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block&
|
|
|
|
unicode_block::operator=(const unicode_block& block)
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
2002-10-12 23:02:55 +04:00
|
|
|
fData[0] = block.fData[0];
|
|
|
|
fData[1] = block.fData[1];
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
bool
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block::operator==(const unicode_block& block) const
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
|
|
|
return fData[0] == block.fData[0] && fData[1] == block.fData[1];
|
2002-10-12 23:02:55 +04:00
|
|
|
}
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
|
2005-11-07 14:02:39 +03:00
|
|
|
bool
|
2009-08-26 14:58:22 +04:00
|
|
|
unicode_block::operator!=(const unicode_block& block) const
|
2005-11-07 14:02:39 +03:00
|
|
|
{
|
|
|
|
return fData[0] != block.fData[0] || fData[1] != block.fData[1];
|
2002-10-12 23:02:55 +04:00
|
|
|
}
|
|
|
|
|
2009-08-26 14:58:22 +04:00
|
|
|
#endif // _FONT_H_
|