More font work:

* Simplified server communication a bit: instead of separate queries for font
  direction, "is fixed", ... there is now a private extra flags field that is
  filled on demand.
* The server command names now describe what the command does, and are not simply
  named after the BFont method (AS_SET_FAMILY_AND_STYLE vs. AS_GET_FAMILY_AND_STYLE_IDS).
* Replaced B_SET_SYSFONT_{PLAIN|BOLD|FIXED} with a single B_GET_SYSTEM_FONTS.
* Rewrote Font.h and added our license.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-07 11:02:39 +00:00
parent a175829ffc
commit b2cc345461
6 changed files with 391 additions and 461 deletions
+95 -118
View File
@@ -1,18 +1,21 @@
/*
* Copyright 2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _FONT_H_ #ifndef _FONT_H_
#define _FONT_H_ #define _FONT_H_
#include <BeBuild.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
/*----------------------------------------------------------------*/
/*----- BFont defines and structures -----------------------------*/
#define B_FONT_FAMILY_LENGTH 63 #define B_FONT_FAMILY_LENGTH 63
typedef char font_family[B_FONT_FAMILY_LENGTH + 1];
#define B_FONT_STYLE_LENGTH 63 #define B_FONT_STYLE_LENGTH 63
typedef char font_family[B_FONT_FAMILY_LENGTH + 1];
typedef char font_style[B_FONT_STYLE_LENGTH + 1]; typedef char font_style[B_FONT_STYLE_LENGTH + 1];
// font spacing
enum { enum {
B_CHAR_SPACING = 0, B_CHAR_SPACING = 0,
B_STRING_SPACING = 1, B_STRING_SPACING = 1,
@@ -25,11 +28,13 @@ enum font_direction {
B_FONT_RIGHT_TO_LEFT = 1 B_FONT_RIGHT_TO_LEFT = 1
}; };
// font flags
enum { enum {
B_DISABLE_ANTIALIASING = 0x00000001, B_DISABLE_ANTIALIASING = 0x00000001,
B_FORCE_ANTIALIASING = 0x00000002 B_FORCE_ANTIALIASING = 0x00000002
}; };
// truncation modes
enum { enum {
B_TRUNCATE_END = 0, B_TRUNCATE_END = 0,
B_TRUNCATE_BEGINNING = 1, B_TRUNCATE_BEGINNING = 1,
@@ -37,6 +42,7 @@ enum {
B_TRUNCATE_SMART = 3 B_TRUNCATE_SMART = 3
}; };
// font encodings
enum { enum {
B_UNICODE_UTF8 = 0, B_UNICODE_UTF8 = 0,
B_ISO_8859_1 = 1, B_ISO_8859_1 = 1,
@@ -52,18 +58,13 @@ enum {
B_MACINTOSH_ROMAN = 11 B_MACINTOSH_ROMAN = 11
}; };
enum { // flags for get_font_family() and get_font_style()
B_SCREEN_FONT_CACHE = 0x0001,
B_PRINTING_FONT_CACHE = 0x0002,
B_DEFAULT_CACHE_SETTING = 0x0004,
B_APP_CACHE_SETTING = 0x0008
};
enum { enum {
B_HAS_TUNED_FONT = 0x0001, B_HAS_TUNED_FONT = 0x0001,
B_IS_FIXED = 0x0002 B_IS_FIXED = 0x0002
}; };
// font face flags
enum { enum {
B_ITALIC_FACE = 0x0001, B_ITALIC_FACE = 0x0001,
B_UNDERSCORE_FACE = 0x0002, B_UNDERSCORE_FACE = 0x0002,
@@ -137,9 +138,10 @@ class BShape;
class BString; class BString;
class BFontPrivate; class BFontPrivate;
class BFont { class BFont {
public: public:
BFont(void); BFont();
BFont(const BFont &font); BFont(const BFont &font);
BFont(const BFont *font); BFont(const BFont *font);
@@ -158,100 +160,79 @@ public:
void GetFamilyAndStyle(font_family *family, void GetFamilyAndStyle(font_family *family,
font_style *style) const; font_style *style) const;
uint32 FamilyAndStyle(void) const; uint32 FamilyAndStyle() const;
float Size(void) const; float Size() const;
float Shear(void) const; float Shear() const;
float Rotation(void) const; float Rotation() const;
uint8 Spacing(void) const; uint8 Spacing() const;
uint8 Encoding(void) const; uint8 Encoding() const;
uint16 Face(void) const; uint16 Face() const;
uint32 Flags(void) const; uint32 Flags() const;
font_direction Direction(void) const; font_direction Direction() const;
bool IsFixed(void) const; bool IsFixed() const;
bool IsFullAndHalfFixed(void) const; bool IsFullAndHalfFixed() const;
BRect BoundingBox(void) const; BRect BoundingBox() const;
unicode_block Blocks(void) const; unicode_block Blocks() const;
font_file_format FileFormat(void) const; font_file_format FileFormat() const;
int32 CountTuned(void) const; int32 CountTuned() const;
void GetTunedInfo(int32 index, tuned_font_info *info) const; void GetTunedInfo(int32 index, tuned_font_info *info) const;
void TruncateString(BString* in_out, void TruncateString(BString* inOut, uint32 mode,
uint32 mode,
float width) const; float width) const;
void GetTruncatedStrings(const char *stringArray[], void GetTruncatedStrings(const char *stringArray[],
int32 numStrings, int32 numStrings, uint32 mode, float width,
uint32 mode,
float width,
BString resultArray[]) const; BString resultArray[]) const;
void GetTruncatedStrings(const char *stringArray[], void GetTruncatedStrings(const char *stringArray[],
int32 numStrings, int32 numStrings, uint32 mode, float width,
uint32 mode,
float width,
char *resultArray[]) const; char *resultArray[]) const;
float StringWidth(const char *string) const; float StringWidth(const char *string) const;
float StringWidth(const char *string, int32 length) const; float StringWidth(const char *string, int32 length) const;
void GetStringWidths(const char *stringArray[], void GetStringWidths(const char *stringArray[],
const int32 lengthArray[], const int32 lengthArray[], int32 numStrings,
int32 numStrings,
float widthArray[]) const; float widthArray[]) const;
void GetEscapements(const char charArray[], void GetEscapements(const char charArray[], int32 numChars,
int32 numChars,
float escapementArray[]) const; float escapementArray[]) const;
void GetEscapements(const char charArray[], void GetEscapements(const char charArray[], int32 numChars,
int32 numChars, escapement_delta *delta, float escapementArray[]) const;
escapement_delta *delta, void GetEscapements(const char charArray[], int32 numChars,
float escapementArray[]) const; escapement_delta *delta, BPoint escapementArray[]) const;
void GetEscapements(const char charArray[], void GetEscapements(const char charArray[], int32 numChars,
int32 numChars, escapement_delta *delta, BPoint escapementArray[],
escapement_delta *delta,
BPoint escapementArray[]) const;
void GetEscapements(const char charArray[],
int32 numChars,
escapement_delta *delta,
BPoint escapementArray[],
BPoint offsetArray[]) const; BPoint offsetArray[]) const;
void GetEdges(const char charArray[], void GetEdges(const char charArray[], int32 numBytes,
int32 numBytes,
edge_info edgeArray[]) const; edge_info edgeArray[]) const;
void GetHeight(font_height *height) const; void GetHeight(font_height *height) const;
void GetBoundingBoxesAsGlyphs(const char charArray[], void GetBoundingBoxesAsGlyphs(const char charArray[],
int32 numChars, int32 numChars, font_metric_mode mode,
font_metric_mode mode,
BRect boundingBoxArray[]) const; BRect boundingBoxArray[]) const;
void GetBoundingBoxesAsString(const char charArray[], void GetBoundingBoxesAsString(const char charArray[],
int32 numChars, int32 numChars, font_metric_mode mode,
font_metric_mode mode, escapement_delta *delta, BRect boundingBoxArray[]) const;
escapement_delta *delta,
BRect boundingBoxArray[]) const;
void GetBoundingBoxesForStrings(const char *stringArray[], void GetBoundingBoxesForStrings(const char *stringArray[],
int32 numStrings, int32 numStrings, font_metric_mode mode,
font_metric_mode mode,
escapement_delta deltas[], escapement_delta deltas[],
BRect boundingBoxArray[]) const; BRect boundingBoxArray[]) const;
void GetGlyphShapes(const char charArray[], void GetGlyphShapes(const char charArray[], int32 numChars,
int32 numChars,
BShape *glyphShapeArray[]) const; BShape *glyphShapeArray[]) const;
void GetHasGlyphs(const char charArray[], void GetHasGlyphs(const char charArray[], int32 numChars,
int32 numChars,
bool hasArray[]) const; bool hasArray[]) const;
BFont& operator=(const BFont &font); BFont& operator=(const BFont &font);
bool operator==(const BFont &font) const; bool operator==(const BFont &font) const;
bool operator!=(const BFont &font) const; bool operator!=(const BFont &font) const;
void PrintToStream(void) const; void PrintToStream() const;
private: private:
friend void _init_global_fonts_();
friend void _font_control_(BFont*, int32, void*);
uint16 fFamilyID; uint16 fFamilyID;
uint16 fStyleID; uint16 fStyleID;
@@ -263,35 +244,18 @@ friend void _font_control_(BFont*, int32, void*);
uint16 fFace; uint16 fFace;
uint32 fFlags; uint32 fFlags;
mutable font_height fHeight; mutable font_height fHeight;
uint32 _reserved[3]; mutable uint32 fExtraFlags;
uint32 _reserved[2];
void SetPacket(void *packet) const; status_t _GetExtraFlags() const;
void GetTruncatedStrings64(const char *stringArray[], void _GetBoundingBoxes(const char charArray[],
int32 numStrings, int32 numChars, font_metric_mode mode,
uint32 mode, bool string_escapement, escapement_delta *delta,
float width,
char *resultArray[]) const;
void GetTruncatedStrings64(const char *stringArray[],
int32 numStrings,
uint32 mode,
float width,
BString resultArray[]) const;
void _GetEscapements_(const char charArray[],
int32 numChars,
escapement_delta *delta,
uint8 mode,
float *escapements,
float *offsets = NULL) const;
void _GetBoundingBoxes_(const char charArray[],
int32 numChars,
font_metric_mode mode,
bool string_escapement,
escapement_delta *delta,
BRect boundingBoxArray[]) const; BRect boundingBoxArray[]) const;
}; };
/*----------------------------------------------------------------*/
/*----- BFont related declarations -------------------------------*/ // BFont related declarations
extern const BFont *be_plain_font; extern const BFont *be_plain_font;
extern const BFont *be_bold_font; extern const BFont *be_bold_font;
@@ -305,54 +269,67 @@ status_t get_font_style(font_family family, int32 index, font_style *name,
uint32 *flags = NULL); uint32 *flags = NULL);
status_t get_font_style(font_family family, int32 index, font_style *name, status_t get_font_style(font_family family, int32 index, font_style *name,
uint16 *face, uint32 *flags = NULL); uint16 *face, uint32 *flags = NULL);
bool update_font_families(bool check_only); bool update_font_families(bool checkOnly);
status_t get_font_cache_info(uint32 id, void *set);
status_t set_font_cache_info(uint32 id, void *set);
/*----------------------------------------------------------------*/ // unicode_block inlines
/*----- unicode_block inlines ------------------------------------*/
unicode_block::unicode_block() { fData[0] = fData[1] = 0LL; } unicode_block::unicode_block()
{
fData[0] = fData[1] = 0LL;
}
unicode_block::unicode_block(uint64 block2, uint64 block1) { unicode_block::unicode_block(uint64 block2, uint64 block1)
{
fData[0] = block1; fData[0] = block1;
fData[1] = block2; fData[1] = block2;
} }
bool unicode_block::Includes(const unicode_block &block) const { bool
return (((fData[0] & block.fData[0]) == block.fData[0]) && unicode_block::Includes(const unicode_block &block) const
((fData[1] & block.fData[1]) == block.fData[1])); {
return (fData[0] & block.fData[0]) == block.fData[0]
&& (fData[1] & block.fData[1]) == block.fData[1];
} }
unicode_block unicode_block::operator&(const unicode_block &block) const { unicode_block
unicode_block res; unicode_block::operator&(const unicode_block &block) const
{
unicode_block result;
result.fData[0] = fData[0] & block.fData[0];
result.fData[1] = fData[1] & block.fData[1];
res.fData[0] = fData[0] & block.fData[0]; return result;
res.fData[1] = fData[1] & block.fData[1];
return res;
} }
unicode_block unicode_block::operator|(const unicode_block &block) const { unicode_block
unicode_block res; unicode_block::operator|(const unicode_block &block) const
{
unicode_block result;
result.fData[0] = fData[0] | block.fData[0];
result.fData[1] = fData[1] | block.fData[1];
res.fData[0] = fData[0] | block.fData[0]; return result;
res.fData[1] = fData[1] | block.fData[1];
return res;
} }
unicode_block &unicode_block::operator=(const unicode_block &block) { unicode_block &
unicode_block::operator=(const unicode_block &block)
{
fData[0] = block.fData[0]; fData[0] = block.fData[0];
fData[1] = block.fData[1]; fData[1] = block.fData[1];
return *this; return *this;
} }
bool unicode_block::operator==(const unicode_block &block) const { bool
return ((fData[0] == block.fData[0]) && (fData[1] == block.fData[1])); unicode_block::operator==(const unicode_block &block) const
{
return fData[0] == block.fData[0] && fData[1] == block.fData[1];
} }
bool unicode_block::operator!=(const unicode_block &block) const { bool
return ((fData[0] != block.fData[0]) || (fData[1] != block.fData[1])); unicode_block::operator!=(const unicode_block &block) const
{
return fData[0] != block.fData[0] || fData[1] != block.fData[1];
} }
#endif /* _FONT_H_ */ #endif /* _FONT_H_ */
+7 -11
View File
@@ -113,23 +113,23 @@ enum {
// Font-related server communications // Font-related server communications
AS_SET_SYSTEM_FONT, AS_SET_SYSTEM_FONT,
AS_GET_SYSTEM_FONTS,
AS_QUERY_FONTS_CHANGED, AS_QUERY_FONTS_CHANGED,
AS_UPDATED_CLIENT_FONTLIST, AS_UPDATED_CLIENT_FONTLIST,
AS_GET_FAMILY_NAME, AS_GET_FAMILY_NAME,
AS_GET_STYLE_NAME, AS_GET_STYLE_NAME,
AS_COUNT_FONT_FAMILIES,
AS_COUNT_FONT_STYLES,
AS_GET_FAMILY_AND_STYLE, AS_GET_FAMILY_AND_STYLE,
AS_GET_FONT_DIRECTION, AS_GET_FAMILY_AND_STYLE_IDS,
AS_GET_FONT_BOUNDING_BOX, AS_GET_FONT_BOUNDING_BOX,
AS_GET_TUNED_COUNT, AS_GET_TUNED_COUNT,
AS_GET_TUNED_INFO, AS_GET_TUNED_INFO,
AS_GET_FONT_HEIGHT, AS_GET_FONT_HEIGHT,
AS_GET_FONT_FILE_FORMAT, AS_GET_FONT_FILE_FORMAT,
AS_GET_EXTRA_FONT_FLAGS,
AS_QUERY_FONT_FIXED,
AS_SET_FAMILY_AND_STYLE,
AS_COUNT_FONT_FAMILIES,
AS_COUNT_FONT_STYLES,
AS_GET_STRING_WIDTHS, AS_GET_STRING_WIDTHS,
AS_GET_EDGES, AS_GET_EDGES,
@@ -141,10 +141,6 @@ enum {
AS_GET_GLYPH_SHAPES, AS_GET_GLYPH_SHAPES,
AS_GET_TRUNCATED_STRINGS, AS_GET_TRUNCATED_STRINGS,
AS_SET_SYSFONT_PLAIN,
AS_SET_SYSFONT_BOLD,
AS_SET_SYSFONT_FIXED,
// Screen methods // Screen methods
AS_SCREEN_GET_MODE, AS_SCREEN_GET_MODE,
AS_SCREEN_SET_MODE, AS_SCREEN_SET_MODE,
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef FONT_PRIVATE_H
#define FONT_PRIVATE_H
// extra flags (shares B_IS_FIXED and B_HAS_TUNED_FONT)
enum {
B_PRIVATE_FONT_IS_FULL_AND_HALF_FIXED = 0x04,
B_PRIVATE_FONT_HAS_KERNING = 0x08,
B_PRIVATE_FONT_DIRECTION_MASK = 0x30,
};
#define B_PRIVATE_FONT_DIRECTION_SHIFT 8
#endif /* FONT_PRIVATE_H */
+84 -113
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2005, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <AppServerLink.h> #include <AppServerLink.h>
#include <Font.h>
#include <Message.h> #include <Message.h>
#include <PortLink.h> #include <PortLink.h>
#include <Rect.h> #include <Rect.h>
@@ -22,11 +23,11 @@
#include <moreUTF8.h> #include <moreUTF8.h>
#include <truncate_string.h> #include <truncate_string.h>
#include <FontPrivate.h>
#include <Font.h>
const float kUninitializedAscent = INFINITY; const float kUninitializedAscent = INFINITY;
const uint32 kUninitializedExtraFlags = 0xffffffff;
// The actual objects which the globals point to // The actual objects which the globals point to
static BFont sPlainFont; static BFont sPlainFont;
@@ -38,49 +39,32 @@ const BFont *be_bold_font = &sBoldFont;
const BFont *be_fixed_font = &sFixedFont; const BFont *be_fixed_font = &sFixedFont;
extern "C" void
_init_global_fonts()
{
_font_control_(&sPlainFont, AS_SET_SYSFONT_PLAIN, NULL);
_font_control_(&sBoldFont, AS_SET_SYSFONT_BOLD, NULL);
_font_control_(&sFixedFont, AS_SET_SYSFONT_FIXED, NULL);
}
/*!
\brief Private function originally used by Be. Now used for initialization
\param font The font to initialize
\param cmd message code to send to the app_server
\param data unused
While it is not known what Be used it for, Haiku uses it to initialize the
three system fonts when the interface kit is initialized when an app starts.
*/
void void
_font_control_(BFont *font, int32 cmd, void *data) _init_global_fonts_()
{ {
if (!font
|| (cmd != AS_SET_SYSFONT_PLAIN && cmd != AS_SET_SYSFONT_BOLD
&& cmd != AS_SET_SYSFONT_FIXED)) {
// this shouldn't ever happen, but just in case....
return;
}
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(cmd); link.StartMessage(AS_GET_SYSTEM_FONTS);
int32 code; int32 code;
if (link.FlushWithReply(code) != B_OK if (link.FlushWithReply(code) != B_OK
|| code != B_OK) { || code != B_OK) {
printf("DEBUG: Couldn't initialize font in _font_control()\n"); printf("DEBUG: Couldn't initialize global fonts!\n");
return; return;
} }
// there really isn't that much data that we need to set for such cases -- most char type[B_OS_NAME_LENGTH];
// of them need to be set to the defaults. The stuff that can change are family,
// style/face, size, and height. while (link.ReadString(type, sizeof(type)) >= B_OK && type[0]) {
// NOTE: this code assumes it's only called BFont dummy;
BFont *font = &dummy;
if (!strcmp(type, "plain"))
font = &sPlainFont;
else if (!strcmp(type, "bold"))
font = &sBoldFont;
else if (!strcmp(type, "fixed"))
font = &sFixedFont;
link.Read<uint16>(&font->fFamilyID); link.Read<uint16>(&font->fFamilyID);
link.Read<uint16>(&font->fStyleID); link.Read<uint16>(&font->fStyleID);
link.Read<float>(&font->fSize); link.Read<float>(&font->fSize);
@@ -88,7 +72,18 @@ _font_control_(BFont *font, int32 cmd, void *data)
link.Read<uint32>(&font->fFlags); link.Read<uint32>(&font->fFlags);
font->fHeight.ascent = kUninitializedAscent; font->fHeight.ascent = kUninitializedAscent;
font->fExtraFlags = kUninitializedExtraFlags;
} }
}
// TODO: the following functions are private Be API functions - if no problems
// arise by not exporting these symbols, we can just remove them
#if 0
void _font_control_(BFont *font, int32 cmd, void *data) {}
status_t get_font_cache_info(uint32 id, void *set) { return B_ERROR; }
status_t set_font_cache_info(uint32 id, void *set) { return B_ERROR; }
#endif
/*! /*!
@@ -105,12 +100,10 @@ void
_set_system_font_(const char *which, font_family family, font_style style, _set_system_font_(const char *which, font_family family, font_style style,
float size) float size)
{ {
if (!which) if (which == NULL || strcmp(which, "plain")
|| strcmp(which, "bold") || strcmp(which, "fixed"))
return; return;
if (!strcmp(which, "plain")
|| !strcmp(which, "bold")
|| !strcmp(which, "fixed")) {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_SET_SYSTEM_FONT); link.StartMessage(AS_SET_SYSTEM_FONT);
@@ -120,7 +113,6 @@ _set_system_font_(const char *which, font_family family, font_style style,
link.Attach<float>(size); link.Attach<float>(size);
link.Flush(); link.Flush();
} }
}
/*! /*!
@@ -293,30 +285,6 @@ update_font_families(bool checkOnly)
} }
status_t
get_font_cache_info(uint32 id, void *set)
{
// TODO: Implement
// Note that the only reliable data from this function will probably be the cache size
// Depending on how the font cache is implemented, this function and the corresponding
// set function will either see major revision or completely disappear in R2.
return B_ERROR;
}
status_t
set_font_cache_info(uint32 id, void *set)
{
// TODO: Implement
// Note that this function will likely only set the cache size in our implementation
// because of (a) the lack of knowledge on R5's font system and (b) the fact that it
// is a completely different font engine.
return B_ERROR;
}
// #pragma mark - // #pragma mark -
@@ -331,7 +299,8 @@ BFont::BFont()
fSpacing(0), fSpacing(0),
fEncoding(0), fEncoding(0),
fFace(0), fFace(0),
fFlags(0) fFlags(0),
fExtraFlags(kUninitializedExtraFlags)
{ {
if (be_plain_font != NULL && this != &sPlainFont) if (be_plain_font != NULL && this != &sPlainFont)
*this = *be_plain_font; *this = *be_plain_font;
@@ -373,7 +342,7 @@ BFont::SetFamilyAndStyle(const font_family family, const font_style style)
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_SET_FAMILY_AND_STYLE); link.StartMessage(AS_GET_FAMILY_AND_STYLE_IDS);
link.AttachString(family); link.AttachString(family);
link.AttachString(style); link.AttachString(style);
link.Attach<uint16>(fFamilyID); link.Attach<uint16>(fFamilyID);
@@ -412,7 +381,7 @@ BFont::SetFamilyAndStyle(uint32 fontcode)
family = (fontcode & 0xFFFF0000) >> 16; family = (fontcode & 0xFFFF0000) >> 16;
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_SET_FAMILY_AND_STYLE); link.StartMessage(AS_GET_FAMILY_AND_STYLE_IDS);
link.AttachString(NULL); // no family and style name link.AttachString(NULL); // no family and style name
link.AttachString(NULL); link.AttachString(NULL);
link.Attach<uint16>(family); link.Attach<uint16>(family);
@@ -446,7 +415,7 @@ status_t
BFont::SetFamilyAndFace(const font_family family, uint16 face) BFont::SetFamilyAndFace(const font_family family, uint16 face)
{ {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_SET_FAMILY_AND_STYLE); link.StartMessage(AS_GET_FAMILY_AND_STYLE_IDS);
link.AttachString(family); link.AttachString(family);
link.AttachString(NULL); // no style given link.AttachString(NULL); // no style given
link.Attach<uint16>(fFamilyID); link.Attach<uint16>(fFamilyID);
@@ -558,96 +527,76 @@ BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
uint32 uint32
BFont::FamilyAndStyle(void) const BFont::FamilyAndStyle() const
{ {
return (fFamilyID << 16UL) | fStyleID; return (fFamilyID << 16UL) | fStyleID;
} }
float float
BFont::Size(void) const BFont::Size() const
{ {
return fSize; return fSize;
} }
float float
BFont::Shear(void) const BFont::Shear() const
{ {
return fShear; return fShear;
} }
float float
BFont::Rotation(void) const BFont::Rotation() const
{ {
return fRotation; return fRotation;
} }
uint8 uint8
BFont::Spacing(void) const BFont::Spacing() const
{ {
return fSpacing; return fSpacing;
} }
uint8 uint8
BFont::Encoding(void) const BFont::Encoding() const
{ {
return fEncoding; return fEncoding;
} }
uint16 uint16
BFont::Face(void) const BFont::Face() const
{ {
return fFace; return fFace;
} }
uint32 uint32
BFont::Flags(void) const BFont::Flags() const
{ {
return fFlags; return fFlags;
} }
font_direction font_direction
BFont::Direction(void) const BFont::Direction() const
{ {
BPrivate::AppServerLink link; if (_GetExtraFlags() != B_OK)
link.StartMessage(AS_GET_FONT_DIRECTION);
link.Attach<uint16>(fFamilyID);
link.Attach<uint16>(fStyleID);
int32 code;
if (link.FlushWithReply(code) != B_OK
|| code != B_OK)
return B_FONT_LEFT_TO_RIGHT; return B_FONT_LEFT_TO_RIGHT;
font_direction fdir; return (font_direction)(fExtraFlags >> B_PRIVATE_FONT_DIRECTION_SHIFT);
link.Read<font_direction>(&fdir);
return fdir;
} }
bool bool
BFont::IsFixed(void) const BFont::IsFixed() const
{ {
BPrivate::AppServerLink link; _GetExtraFlags();
link.StartMessage(AS_QUERY_FONT_FIXED); return (fExtraFlags & B_IS_FIXED) != 0;
link.Attach<uint16>(fFamilyID);
link.Attach<uint16>(fStyleID);
int32 code;
if (link.FlushWithReply(code) != B_OK
|| code != B_OK)
return false;
bool fixed;
link.Read<bool>(&fixed);
return fixed;
} }
@@ -659,14 +608,15 @@ BFont::IsFixed(void) const
*/ */
bool bool
BFont::IsFullAndHalfFixed(void) const BFont::IsFullAndHalfFixed() const
{ {
return false; _GetExtraFlags();
return (fExtraFlags & B_PRIVATE_FONT_IS_FULL_AND_HALF_FIXED) != 0;
} }
BRect BRect
BFont::BoundingBox(void) const BFont::BoundingBox() const
{ {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_GET_FONT_BOUNDING_BOX); link.StartMessage(AS_GET_FONT_BOUNDING_BOX);
@@ -685,7 +635,7 @@ BFont::BoundingBox(void) const
unicode_block unicode_block
BFont::Blocks(void) const BFont::Blocks() const
{ {
// TODO: Add Block support // TODO: Add Block support
return unicode_block(); return unicode_block();
@@ -693,7 +643,7 @@ BFont::Blocks(void) const
font_file_format font_file_format
BFont::FileFormat(void) const BFont::FileFormat() const
{ {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_GET_FONT_FILE_FORMAT); link.StartMessage(AS_GET_FONT_FILE_FORMAT);
@@ -715,7 +665,7 @@ BFont::FileFormat(void) const
int32 int32
BFont::CountTuned(void) const BFont::CountTuned() const
{ {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_GET_TUNED_COUNT); link.StartMessage(AS_GET_TUNED_COUNT);
@@ -1014,7 +964,7 @@ void
BFont::GetBoundingBoxesAsGlyphs(const char charArray[], int32 numChars, font_metric_mode mode, BFont::GetBoundingBoxesAsGlyphs(const char charArray[], int32 numChars, font_metric_mode mode,
BRect boundingBoxArray[]) const BRect boundingBoxArray[]) const
{ {
_GetBoundingBoxes_(charArray, numChars, mode, false, NULL, boundingBoxArray); _GetBoundingBoxes(charArray, numChars, mode, false, NULL, boundingBoxArray);
} }
@@ -1022,12 +972,12 @@ void
BFont::GetBoundingBoxesAsString(const char charArray[], int32 numChars, font_metric_mode mode, BFont::GetBoundingBoxesAsString(const char charArray[], int32 numChars, font_metric_mode mode,
escapement_delta *delta, BRect boundingBoxArray[]) const escapement_delta *delta, BRect boundingBoxArray[]) const
{ {
_GetBoundingBoxes_(charArray, numChars, mode, true, delta, boundingBoxArray); _GetBoundingBoxes(charArray, numChars, mode, true, delta, boundingBoxArray);
} }
void void
BFont::_GetBoundingBoxes_(const char charArray[], int32 numChars, font_metric_mode mode, BFont::_GetBoundingBoxes(const char charArray[], int32 numChars, font_metric_mode mode,
bool string_escapement, escapement_delta *delta, BRect boundingBoxArray[]) const bool string_escapement, escapement_delta *delta, BRect boundingBoxArray[]) const
{ {
if (!charArray || numChars < 1 || !boundingBoxArray) if (!charArray || numChars < 1 || !boundingBoxArray)
@@ -1213,9 +1163,30 @@ BFont::operator!=(const BFont &font) const
void void
BFont::PrintToStream(void) const BFont::PrintToStream() const
{ {
printf("FAMILY STYLE %f %f %f %f %f %f\n", fSize, fShear, fRotation, fHeight.ascent, printf("FAMILY STYLE %f %f %f %f %f %f\n", fSize, fShear, fRotation, fHeight.ascent,
fHeight.descent, fHeight.leading); fHeight.descent, fHeight.leading);
} }
status_t
BFont::_GetExtraFlags() const
{
// TODO: this has to be const in order to allow other font getters to stay const as well
if (fExtraFlags != kUninitializedExtraFlags)
return B_OK;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_EXTRA_FONT_FLAGS);
link.Attach<uint16>(fFamilyID);
link.Attach<uint16>(fStyleID);
status_t status = B_ERROR;
if (link.FlushWithReply(status) != B_OK
|| status != B_OK)
return status;
link.Read<uint32>(&fExtraFlags);
return B_OK;
}
+14 -30
View File
@@ -1,31 +1,15 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2005, Haiku * Copyright 2001-2005, Haiku, Inc.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * DarkWyrm <[email protected]>
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Caz <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the * Axel Dörfler, [email protected]e
// Software is furnished to do so, subject to the following conditions: */
//
// The above copyright notice and this permission notice shall be included in /** Global functions and variables for the Interface Kit */
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: InterfaceDefs.cpp
// Author: DarkWyrm <[email protected]>
// Caz <[email protected]>
// Axel Dörfler <[email protected]>
// Description: Global functions and variables for the Interface Kit
//
//------------------------------------------------------------------------------
#include <Application.h> #include <Application.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <Menu.h> #include <Menu.h>
@@ -53,7 +37,7 @@
#include "truncate_string.h" #include "truncate_string.h"
// Private definitions not placed in public headers // Private definitions not placed in public headers
extern "C" void _init_global_fonts(); void _init_global_fonts_();
extern "C" status_t _fini_interface_kit_(); extern "C" status_t _fini_interface_kit_();
using namespace BPrivate; using namespace BPrivate;
@@ -810,7 +794,7 @@ _init_interface_kit_()
BTextView::sWidthAtom = 0; BTextView::sWidthAtom = 0;
BTextView::sWidths = new _BWidthBuffer_; BTextView::sWidths = new _BWidthBuffer_;
_init_global_fonts(); _init_global_fonts_();
_menu_info_ptr_ = &BMenu::sMenuInfo; _menu_info_ptr_ = &BMenu::sMenuInfo;
status_t status = load_menu_settings(BMenu::sMenuInfo); status_t status = load_menu_settings(BMenu::sMenuInfo);
+35 -51
View File
@@ -18,16 +18,19 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <syslog.h>
#include <AppDefs.h> #include <AppDefs.h>
#include <Autolock.h> #include <Autolock.h>
#include <ColorSet.h>
#include <List.h> #include <List.h>
#include <ScrollBar.h> #include <ScrollBar.h>
#include <ServerProtocol.h>
#include <Shape.h> #include <Shape.h>
#include <String.h> #include <String.h>
#include <ColorSet.h>
#include <ServerProtocol.h>
#include <FontPrivate.h>
#include "AppServer.h" #include "AppServer.h"
#include "BGet++.h" #include "BGet++.h"
#include "BitmapManager.h" #include "BitmapManager.h"
@@ -38,10 +41,10 @@
#include "DrawingEngine.h" #include "DrawingEngine.h"
#include "FontManager.h" #include "FontManager.h"
#include "HWInterface.h" #include "HWInterface.h"
//#include "DrawState.h"
#include "OffscreenServerWindow.h" #include "OffscreenServerWindow.h"
#include "RAMLinkMsgReader.h" #include "RAMLinkMsgReader.h"
#include "RootLayer.h" #include "RootLayer.h"
#include "ServerApp.h"
#include "ServerBitmap.h" #include "ServerBitmap.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "ServerCursor.h" #include "ServerCursor.h"
@@ -52,9 +55,6 @@
#include "Utils.h" #include "Utils.h"
#include "WinBorder.h" #include "WinBorder.h"
#include "ServerApp.h"
#include <syslog.h>
//#define DEBUG_SERVERAPP //#define DEBUG_SERVERAPP
#ifdef DEBUG_SERVERAPP #ifdef DEBUG_SERVERAPP
@@ -1227,35 +1227,6 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
gFontManager->Unlock(); gFontManager->Unlock();
break; break;
} }
case AS_GET_FONT_DIRECTION:
{
FTRACE(("ServerApp %s: AS_GET_FONT_DIRECTION\n", Signature()));
// Attached Data:
// 1) uint16 - family ID
// 2) uint16 - style ID
// Returns:
// 1) font_direction direction of font
int32 familyID, styleID;
link.Read<int32>(&familyID);
link.Read<int32>(&styleID);
gFontManager->Lock();
FontStyle *fontStyle = gFontManager->GetStyle(familyID, styleID);
if (fontStyle) {
font_direction direction = fontStyle->Direction();
fLink.StartMessage(B_OK);
fLink.Attach<font_direction>(direction);
} else
fLink.StartMessage(B_BAD_VALUE);
gFontManager->Unlock();
fLink.Flush();
break;
}
case AS_GET_FONT_FILE_FORMAT: case AS_GET_FONT_FILE_FORMAT:
{ {
FTRACE(("ServerApp %s: AS_GET_FONT_FILE_FORMAT\n", Signature())); FTRACE(("ServerApp %s: AS_GET_FONT_FILE_FORMAT\n", Signature()));
@@ -1411,16 +1382,16 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.Flush(); fLink.Flush();
break; break;
} }
case AS_QUERY_FONT_FIXED: case AS_GET_EXTRA_FONT_FLAGS:
{ {
FTRACE(("ServerApp %s: AS_QUERY_FONT_FIXED unimplmemented\n", FTRACE(("ServerApp %s: AS_GET_EXTRA_FONT_FLAGS\n",
Signature())); Signature()));
// Attached Data: // Attached Data:
// 1) uint16 - family ID // 1) uint16 - family ID
// 2) uint16 - style ID // 2) uint16 - style ID
// Returns: // Returns:
// 1) bool - font is/is not fixed // 1) uint32 - extra font flags
uint16 familyID, styleID; uint16 familyID, styleID;
link.Read<uint16>(&familyID); link.Read<uint16>(&familyID);
link.Read<uint16>(&styleID); link.Read<uint16>(&styleID);
@@ -1430,7 +1401,18 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
FontStyle *fontStyle = gFontManager->GetStyle(familyID, styleID); FontStyle *fontStyle = gFontManager->GetStyle(familyID, styleID);
if (fontStyle != NULL) { if (fontStyle != NULL) {
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<bool>(fontStyle->IsFixedWidth());
uint32 flags = 0;
if (fontStyle->IsFixedWidth())
flags |= B_IS_FIXED;
if (fontStyle->HasTuned())
flags |= B_HAS_TUNED_FONT;
if (fontStyle->HasKerning())
flags |= B_PRIVATE_FONT_HAS_KERNING;
flags |= uint32(fontStyle->Direction()) << B_PRIVATE_FONT_DIRECTION_SHIFT;
fLink.Attach<uint32>(flags);
} else } else
fLink.StartMessage(B_BAD_VALUE); fLink.StartMessage(B_BAD_VALUE);
@@ -1438,10 +1420,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.Flush(); fLink.Flush();
break; break;
} }
case AS_SET_FAMILY_AND_STYLE: case AS_GET_FAMILY_AND_STYLE_IDS:
{ {
FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE\n", FTRACE(("ServerApp %s: AS_GET_FAMILY_AND_STYLE_IDS\n", Signature()));
Signature()));
// Attached Data: // Attached Data:
// 1) font_family - name of font family to use // 1) font_family - name of font family to use
// 2) font_style - name of style in family // 2) font_style - name of style in family
@@ -1527,11 +1508,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.Flush(); fLink.Flush();
break; break;
} }
case AS_SET_SYSFONT_PLAIN: case AS_GET_SYSTEM_FONTS:
case AS_SET_SYSFONT_BOLD:
case AS_SET_SYSFONT_FIXED:
{ {
FTRACE(("ServerApp %s: AS_SET_SYSFONT_PLAIN\n", Signature())); FTRACE(("ServerApp %s: AS_GET_SYSTEM_FONTS\n", Signature()));
// Returns: // Returns:
// 1) uint16 - family ID // 1) uint16 - family ID
// 2) uint16 - style ID // 2) uint16 - style ID
@@ -1540,26 +1519,31 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 5) uint32 - font flags // 5) uint32 - font flags
DesktopSettings settings(fDesktop); DesktopSettings settings(fDesktop);
fLink.StartMessage(B_OK);
for (int32 i = 0; i < 3; i++) {
ServerFont font; ServerFont font;
switch (code) { switch (i) {
case AS_SET_SYSFONT_PLAIN: case 0:
settings.GetDefaultPlainFont(font); settings.GetDefaultPlainFont(font);
fLink.AttachString("plain");
break; break;
case AS_SET_SYSFONT_BOLD: case 1:
settings.GetDefaultBoldFont(font); settings.GetDefaultBoldFont(font);
fLink.AttachString("bold");
break; break;
case AS_SET_SYSFONT_FIXED: case 2:
settings.GetDefaultFixedFont(font); settings.GetDefaultFixedFont(font);
fLink.AttachString("fixed");
break; break;
} }
fLink.StartMessage(B_OK);
fLink.Attach<uint16>(font.FamilyID()); fLink.Attach<uint16>(font.FamilyID());
fLink.Attach<uint16>(font.StyleID()); fLink.Attach<uint16>(font.StyleID());
fLink.Attach<float>(font.Size()); fLink.Attach<float>(font.Size());
fLink.Attach<uint16>(font.Face()); fLink.Attach<uint16>(font.Face());
fLink.Attach<uint32>(font.Flags()); fLink.Attach<uint32>(font.Flags());
}
fLink.Flush(); fLink.Flush();
break; break;