Implemented caching of the font_height, as suggested by Stefano - seems to work fine.

Also added some TODO items (mostly to SetFace()).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14612 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-01 12:03:43 +00:00
parent 8e7b3607e5
commit ec769ec5b2
+35 -16
View File
@@ -26,6 +26,8 @@
#include <Font.h> #include <Font.h>
const float kUninitializedAscent = INFINITY;
// The actual objects which the globals point to // The actual objects which the globals point to
static BFont sPlainFont; static BFont sPlainFont;
static BFont sBoldFont; static BFont sBoldFont;
@@ -62,15 +64,13 @@ _font_control_(BFont *font, int32 cmd, void *data)
|| (cmd != AS_SET_SYSFONT_PLAIN && cmd != AS_SET_SYSFONT_BOLD || (cmd != AS_SET_SYSFONT_PLAIN && cmd != AS_SET_SYSFONT_BOLD
&& cmd != AS_SET_SYSFONT_FIXED)) { && cmd != AS_SET_SYSFONT_FIXED)) {
// this shouldn't ever happen, but just in case.... // this shouldn't ever happen, but just in case....
printf("DEBUG: Bad parameters in _font_control_()\n");
return; return;
} }
int32 code;
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(cmd); link.StartMessage(cmd);
int32 code;
if (link.FlushWithReply(code) != B_OK if (link.FlushWithReply(code) != B_OK
|| code != SERVER_TRUE) { || code != SERVER_TRUE) {
printf("DEBUG: Couldn't initialize font in _font_control()\n"); printf("DEBUG: Couldn't initialize font in _font_control()\n");
@@ -80,11 +80,14 @@ _font_control_(BFont *font, int32 cmd, void *data)
// there really isn't that much data that we need to set for such cases -- most // there really isn't that much data that we need to set for such cases -- most
// of them need to be set to the defaults. The stuff that can change are family, // of them need to be set to the defaults. The stuff that can change are family,
// style/face, size, and height. // style/face, size, and height.
// NOTE: this code assumes it's only called
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);
link.Read<uint16>(&font->fFace); link.Read<uint16>(&font->fFace);
link.Read<uint32>(&font->fFlags); link.Read<uint32>(&font->fFlags);
font->fHeight.ascent = kUninitializedAscent;
} }
@@ -288,14 +291,17 @@ get_font_style(font_family family, int32 index, font_style *name,
*/ */
bool bool
update_font_families(bool check_only) update_font_families(bool checkOnly)
{ {
int32 code; int32 code;
bool value; bool value;
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
// TODO: get some kind of change counter or timestamp and use node-monitoring
// for fonts in the app_server
link.StartMessage(AS_QUERY_FONTS_CHANGED); link.StartMessage(AS_QUERY_FONTS_CHANGED);
link.Attach<bool>(check_only); link.Attach<bool>(checkOnly);
if (link.FlushWithReply(code) != B_OK if (link.FlushWithReply(code) != B_OK
|| code != SERVER_TRUE) || code != SERVER_TRUE)
@@ -399,6 +405,8 @@ BFont::SetFamilyAndStyle(const font_family family, const font_style style)
link.Read<uint16>(&fFamilyID); link.Read<uint16>(&fFamilyID);
link.Read<uint16>(&fStyleID); link.Read<uint16>(&fStyleID);
link.Read<uint16>(&fFace); link.Read<uint16>(&fFace);
fHeight.ascent = kUninitializedAscent;
return B_OK; return B_OK;
} }
@@ -416,7 +424,7 @@ BFont::SetFamilyAndStyle(uint32 fontcode)
// addition to stuff like underlining and strikethrough. As a result, this will // addition to stuff like underlining and strikethrough. As a result, this will
// need a trip to the server and, thus, be slower than R5's in order to be correct // need a trip to the server and, thus, be slower than R5's in order to be correct
uint16 family,style,face; uint16 family, style, face;
int32 code; int32 code;
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
@@ -435,6 +443,7 @@ BFont::SetFamilyAndStyle(uint32 fontcode)
fStyleID = style; fStyleID = style;
fFamilyID = family; fFamilyID = family;
fHeight.ascent = kUninitializedAscent;
// Mask off any references in the face to Bold/Normal/Italic and set the face // Mask off any references in the face to Bold/Normal/Italic and set the face
// value to reflect the new font style // value to reflect the new font style
@@ -478,6 +487,7 @@ BFont::SetFamilyAndFace(const font_family family, uint16 face)
} else } else
fFace = face; fFace = face;
fHeight.ascent = kUninitializedAscent;
return B_OK; return B_OK;
} }
@@ -486,6 +496,7 @@ void
BFont::SetSize(float size) BFont::SetSize(float size)
{ {
fSize = size; fSize = size;
fHeight.ascent = kUninitializedAscent;
} }
@@ -493,6 +504,7 @@ void
BFont::SetShear(float shear) BFont::SetShear(float shear)
{ {
fShear = shear; fShear = shear;
fHeight.ascent = kUninitializedAscent;
} }
@@ -500,6 +512,7 @@ void
BFont::SetRotation(float rotation) BFont::SetRotation(float rotation)
{ {
fRotation = rotation; fRotation = rotation;
fHeight.ascent = kUninitializedAscent;
} }
@@ -520,7 +533,12 @@ BFont::SetEncoding(uint8 encoding)
void void
BFont::SetFace(uint16 face) BFont::SetFace(uint16 face)
{ {
// TODO: Should the server ignore faces it doesn't have, or should
// it try to emulate faces it doesn't have, or should it correct
// the face value to something it has?
// TODO: don't we have to update the fStyleID?
fFace = face; fFace = face;
fHeight.ascent = kUninitializedAscent;
} }
@@ -989,16 +1007,13 @@ BFont::GetEdges(const char charArray[], int32 numChars, edge_info edgeArray[]) c
void void
BFont::GetHeight(font_height *height) const BFont::GetHeight(font_height *_height) const
{ {
if (height) { if (_height == NULL)
// R5's version actually contacts the server in this call. The more and more return;
// I work with this class, the more and more I can't wait for R2 to fix it. Yeesh.
// TODO: As we have a fHeight member, maybe we could cache the height there ? if (fHeight.ascent == kUninitializedAscent) {
// If the size/family/style change, we can ABUSE the fFlags member and set a bit // we don't have the font height cached yet
// there, so that if that bit is high, this method would have to contact the
// server, otherwise it'll use the cached value. Or something like that.
int32 code;
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_GET_FONT_HEIGHT); link.StartMessage(AS_GET_FONT_HEIGHT);
@@ -1006,12 +1021,16 @@ BFont::GetHeight(font_height *height) const
link.Attach<uint16>(fStyleID); link.Attach<uint16>(fStyleID);
link.Attach<float>(fSize); link.Attach<float>(fSize);
int32 code;
if (link.FlushWithReply(code) != B_OK if (link.FlushWithReply(code) != B_OK
|| code != SERVER_TRUE) || code != SERVER_TRUE)
return; return;
link.Read<font_height>(height); // who put that "const" to this method? :-)
link.Read<font_height>(const_cast<font_height *>(&fHeight));
} }
*_height = fHeight;
} }