Fixed a bunch of bugs in the font sub-system:
* BFont::Face() was almost always wrong - also on the server side, _TranslateStyleToFace() was broken. * a clean font was not correctly initialized to be_plain_font * BFont::GetFamilyAndStyle() did not work correctly if either family or style was NULL - which is allowed, and shouldn't have let it abort its task. * FontServer::GetStyle() by ID did not work reliably under certain circumstances (but those were not reached with the current server) * BFont::SetFamilyAndStyle() did not work when family was NULL, and it also never set fFace correctly. * Introduced a FontFamily::GetStyleWithFace() * Renamed some FontFamily/FontStyle methods from ie. GetID() to ID() to match the style used everywhere else in BeOS. * Removed AS_SET_FAMILY_NAME as its no longer in use. * Lots of cleanup and simplification. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -30,7 +30,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <List.h>
|
#include <ObjectList.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
@@ -39,9 +39,8 @@
|
|||||||
class FontFamily;
|
class FontFamily;
|
||||||
class ServerFont;
|
class ServerFont;
|
||||||
|
|
||||||
enum font_format
|
enum font_format {
|
||||||
{
|
FONT_TRUETYPE = 0,
|
||||||
FONT_TRUETYPE=0,
|
|
||||||
FONT_TYPE_1,
|
FONT_TYPE_1,
|
||||||
FONT_OPENTYPE,
|
FONT_OPENTYPE,
|
||||||
FONT_BDF,
|
FONT_BDF,
|
||||||
@@ -69,8 +68,7 @@ typedef struct CachedFaceRec_
|
|||||||
such. Each value must be multiplied by the point size to determine size in pixels
|
such. Each value must be multiplied by the point size to determine size in pixels
|
||||||
|
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
FT_Short ascent;
|
FT_Short ascent;
|
||||||
FT_Short descent;
|
FT_Short descent;
|
||||||
FT_Short leading;
|
FT_Short leading;
|
||||||
@@ -85,103 +83,107 @@ typedef struct
|
|||||||
still offering plenty of information the style in question.
|
still offering plenty of information the style in question.
|
||||||
*/
|
*/
|
||||||
class FontStyle : public SharedObject, public BLocker {
|
class FontStyle : public SharedObject, public BLocker {
|
||||||
public:
|
public:
|
||||||
FontStyle(const char* filepath,
|
FontStyle(const char* filepath,
|
||||||
FT_Face face);
|
FT_Face face);
|
||||||
virtual ~FontStyle();
|
virtual ~FontStyle();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::IsFixedWidth(void)
|
\fn bool FontStyle::IsFixedWidth(void)
|
||||||
\brief Determines whether the font's character width is fixed
|
\brief Determines whether the font's character width is fixed
|
||||||
\return true if fixed, false if not
|
\return true if fixed, false if not
|
||||||
*/
|
*/
|
||||||
inline bool IsFixedWidth() const
|
inline bool IsFixedWidth() const
|
||||||
{ return fFTFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; }
|
{ return fFTFace->face_flags & FT_FACE_FLAG_FIXED_WIDTH; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::IsScalable(void)
|
\fn bool FontStyle::IsScalable(void)
|
||||||
\brief Determines whether the font can be scaled to any size
|
\brief Determines whether the font can be scaled to any size
|
||||||
\return true if scalable, false if not
|
\return true if scalable, false if not
|
||||||
*/
|
*/
|
||||||
inline bool IsScalable() const
|
inline bool IsScalable() const
|
||||||
{ return fFTFace->face_flags & FT_FACE_FLAG_SCALABLE; }
|
{ return fFTFace->face_flags & FT_FACE_FLAG_SCALABLE; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::HasKerning(void)
|
\fn bool FontStyle::HasKerning(void)
|
||||||
\brief Determines whether the font has kerning information
|
\brief Determines whether the font has kerning information
|
||||||
\return true if kerning info is available, false if not
|
\return true if kerning info is available, false if not
|
||||||
*/
|
*/
|
||||||
inline bool HasKerning() const
|
inline bool HasKerning() const
|
||||||
{ return fFTFace->face_flags & FT_FACE_FLAG_KERNING; }
|
{ return fFTFace->face_flags & FT_FACE_FLAG_KERNING; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::HasTuned(void)
|
\fn bool FontStyle::HasTuned(void)
|
||||||
\brief Determines whether the font contains strikes
|
\brief Determines whether the font contains strikes
|
||||||
\return true if it has strikes included, false if not
|
\return true if it has strikes included, false if not
|
||||||
*/
|
*/
|
||||||
inline bool HasTuned() const
|
inline bool HasTuned() const
|
||||||
{ return fFTFace->num_fixed_sizes > 0; }
|
{ return fFTFace->num_fixed_sizes > 0; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::TunedCount(void)
|
\fn bool FontStyle::TunedCount(void)
|
||||||
\brief Returns the number of strikes the style contains
|
\brief Returns the number of strikes the style contains
|
||||||
\return The number of strikes the style contains
|
\return The number of strikes the style contains
|
||||||
*/
|
*/
|
||||||
inline int32 TunedCount() const
|
inline int32 TunedCount() const
|
||||||
{ return fFTFace->num_fixed_sizes; }
|
{ return fFTFace->num_fixed_sizes; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::GlyphCount(void)
|
\fn bool FontStyle::GlyphCount(void)
|
||||||
\brief Returns the number of glyphs in the style
|
\brief Returns the number of glyphs in the style
|
||||||
\return The number of glyphs the style contains
|
\return The number of glyphs the style contains
|
||||||
*/
|
*/
|
||||||
inline uint16 GlyphCount() const
|
inline uint16 GlyphCount() const
|
||||||
{ return fFTFace->num_glyphs; }
|
{ return fFTFace->num_glyphs; }
|
||||||
/*!
|
/*!
|
||||||
\fn bool FontStyle::CharMapCount(void)
|
\fn bool FontStyle::CharMapCount(void)
|
||||||
\brief Returns the number of character maps the style contains
|
\brief Returns the number of character maps the style contains
|
||||||
\return The number of character maps the style contains
|
\return The number of character maps the style contains
|
||||||
*/
|
*/
|
||||||
inline uint16 CharMapCount() const
|
inline uint16 CharMapCount() const
|
||||||
{ return fFTFace->num_charmaps; }
|
{ return fFTFace->num_charmaps; }
|
||||||
|
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
inline FontFamily* Family() const
|
inline FontFamily* Family() const
|
||||||
{ return fFontFamily; }
|
{ return fFontFamily; }
|
||||||
inline uint16 GetID() const
|
inline uint16 ID() const
|
||||||
{ return fID; }
|
{ return fID; }
|
||||||
int32 GetFlags() const;
|
int32 Flags() const;
|
||||||
|
|
||||||
inline uint16 GetFace() const
|
inline uint16 Face() const
|
||||||
{ return fFace; }
|
{ return fFace; }
|
||||||
|
|
||||||
const char* GetPath() const;
|
const char* Path() const;
|
||||||
font_height GetHeight(const float& size) const;
|
font_height GetHeight(const float& size) const;
|
||||||
|
|
||||||
inline FT_Face GetFTFace() const
|
inline FT_Face GetFTFace() const
|
||||||
{ return fFTFace; }
|
{ return fFTFace; }
|
||||||
|
|
||||||
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
||||||
// 2.1.4 to 2.1.8
|
// 2.1.4 to 2.1.8
|
||||||
// int16 ConvertToUnicode(uint16 c);
|
// int16 ConvertToUnicode(uint16 c);
|
||||||
|
|
||||||
void AttachedToFamily(FontFamily* family);
|
|
||||||
void DetachedFromFamily();
|
|
||||||
|
|
||||||
protected:
|
void AttachedToFamily(FontFamily* family);
|
||||||
uint16 TranslateStyleToFace(const char *name) const;
|
void DetachedFromFamily();
|
||||||
|
|
||||||
friend class FontFamily;
|
|
||||||
|
|
||||||
FT_Face fFTFace;
|
private:
|
||||||
// CachedFace cachedface;
|
friend class FontFamily;
|
||||||
|
uint16 _TranslateStyleToFace(const char *name) const;
|
||||||
|
void _SetFontFamily(FontFamily* family)
|
||||||
|
{ fFontFamily = family; }
|
||||||
|
void _SetID(uint16 id)
|
||||||
|
{ fID = id; }
|
||||||
|
|
||||||
FontFamily* fFontFamily;
|
private:
|
||||||
|
FT_Face fFTFace;
|
||||||
|
// CachedFace cachedface;
|
||||||
|
|
||||||
BString fName;
|
FontFamily* fFontFamily;
|
||||||
BString fPath;
|
|
||||||
|
|
||||||
BRect fBounds;
|
BString fName;
|
||||||
|
BString fPath;
|
||||||
|
|
||||||
uint16 fID;
|
BRect fBounds;
|
||||||
uint16 fFace;
|
|
||||||
|
|
||||||
FontStyleHeight fHeight;
|
uint16 fID;
|
||||||
|
uint16 fFace;
|
||||||
|
|
||||||
|
FontStyleHeight fHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -192,32 +194,34 @@ protected:
|
|||||||
Arial Roman, Arial Italic, Arial Bold, etc.
|
Arial Roman, Arial Italic, Arial Bold, etc.
|
||||||
*/
|
*/
|
||||||
class FontFamily : public SharedObject {
|
class FontFamily : public SharedObject {
|
||||||
public:
|
public:
|
||||||
FontFamily(const char* namestr,
|
FontFamily(const char* namestr,
|
||||||
const uint16& index);
|
const uint16& index);
|
||||||
virtual ~FontFamily();
|
virtual ~FontFamily();
|
||||||
|
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
bool AddStyle(FontStyle* style);
|
bool AddStyle(FontStyle* style);
|
||||||
void RemoveStyle(const char* style);
|
void RemoveStyle(const char* style);
|
||||||
void RemoveStyle(FontStyle* style);
|
void RemoveStyle(FontStyle* style);
|
||||||
|
|
||||||
FontStyle* GetStyle(int32 index) const;
|
FontStyle* GetStyle(const char* style) const;
|
||||||
FontStyle* GetStyle(const char* style) const;
|
FontStyle* GetStyleWithFace(uint16 face) const;
|
||||||
|
FontStyle* GetStyleWithID(uint16 face) const;
|
||||||
uint16 GetID() const
|
|
||||||
{ return fID; }
|
uint16 ID() const
|
||||||
|
{ return fID; }
|
||||||
bool HasStyle(const char* style) const;
|
int32 Flags();
|
||||||
int32 CountStyles() const;
|
|
||||||
int32 GetFlags();
|
bool HasStyle(const char* style) const;
|
||||||
|
int32 CountStyles() const;
|
||||||
protected:
|
FontStyle* StyleAt(int32 index) const;
|
||||||
BString fName;
|
|
||||||
BList fStyles;
|
protected:
|
||||||
uint16 fID;
|
BString fName;
|
||||||
int32 fFlags;
|
BObjectList<FontStyle> fStyles;
|
||||||
|
uint16 fID;
|
||||||
|
int32 fFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /* FONT_FAMILY_H_ */
|
||||||
|
|||||||
@@ -28,43 +28,43 @@ class ServerFont;
|
|||||||
*/
|
*/
|
||||||
class FontServer : public BLocker {
|
class FontServer : public BLocker {
|
||||||
public:
|
public:
|
||||||
FontServer(void);
|
FontServer();
|
||||||
~FontServer(void);
|
~FontServer();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Determines whether the font server has started up properly
|
\brief Determines whether the font server has started up properly
|
||||||
\return true if so, false if not.
|
\return true if so, false if not.
|
||||||
*/
|
*/
|
||||||
bool IsInitialized(void) { return fInit; }
|
bool IsInitialized() { return fInit; }
|
||||||
int32 CountFamilies(void);
|
int32 CountFamilies();
|
||||||
int32 CountStyles(const char *family);
|
int32 CountStyles(const char *family);
|
||||||
void RemoveFamily(const char *family);
|
void RemoveFamily(const char *family);
|
||||||
void ScanSystemFolders(void);
|
void ScanSystemFolders();
|
||||||
status_t ScanDirectory(const char *path);
|
status_t ScanDirectory(const char *path);
|
||||||
void SaveList(void);
|
void SaveList();
|
||||||
|
|
||||||
const char *GetFamilyName(uint16 id) const;
|
const char *GetFamilyName(uint16 id) const;
|
||||||
const char *GetStyleName(const char *family, uint16 id) const;
|
const char *GetStyleName(const char *family, uint16 id) const;
|
||||||
|
|
||||||
FontStyle *GetStyle(const char *family, const char *face);
|
FontStyle *GetStyle(const char *family, const char *style, uint16 face = 0);
|
||||||
FontStyle *GetStyle(const char *family, uint16 id) const;
|
FontStyle *GetStyle(const char *family, uint16 id) const;
|
||||||
FontStyle *GetStyle(const uint16 &familyid, const uint16 &styleid);
|
FontStyle *GetStyle(uint16 familyID, uint16 styleID);
|
||||||
FontFamily *GetFamily(const uint16 &familyid) const;
|
FontFamily *GetFamily(uint16 familyID) const;
|
||||||
FontFamily *GetFamily(const char *name) const;
|
FontFamily *GetFamily(const char *name) const;
|
||||||
|
|
||||||
ServerFont *GetSystemPlain(void);
|
ServerFont *GetSystemPlain();
|
||||||
ServerFont *GetSystemBold(void);
|
ServerFont *GetSystemBold();
|
||||||
ServerFont *GetSystemFixed(void);
|
ServerFont *GetSystemFixed();
|
||||||
|
|
||||||
bool SetSystemPlain(const char *family, const char *style, float size);
|
bool SetSystemPlain(const char *family, const char *style, float size);
|
||||||
bool SetSystemBold(const char *family, const char *style, float size);
|
bool SetSystemBold(const char *family, const char *style, float size);
|
||||||
bool SetSystemFixed(const char *family, const char *style, float size);
|
bool SetSystemFixed(const char *family, const char *style, float size);
|
||||||
|
|
||||||
bool FontsNeedUpdated(void) { return fNeedUpdate; }
|
bool FontsNeedUpdated() { return fNeedUpdate; }
|
||||||
/*!
|
/*!
|
||||||
\brief Called when the fonts list has been updated
|
\brief Called when the fonts list has been updated
|
||||||
*/
|
*/
|
||||||
void FontsUpdated(void) { fNeedUpdate = false; }
|
void FontsUpdated() { fNeedUpdate = false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16 TranslateStyleToFace(const char *name) const;
|
uint16 TranslateStyleToFace(const char *name) const;
|
||||||
|
|||||||
@@ -66,16 +66,16 @@ class ServerFont {
|
|||||||
const char* GetStyle() const;
|
const char* GetStyle() const;
|
||||||
const char* GetFamily() const;
|
const char* GetFamily() const;
|
||||||
const char* GetPath() const
|
const char* GetPath() const
|
||||||
{ return fStyle->GetPath(); }
|
{ return fStyle->Path(); }
|
||||||
|
|
||||||
status_t SetFamilyAndStyle(uint16 familyID,
|
status_t SetFamilyAndStyle(uint16 familyID,
|
||||||
uint16 styleID);
|
uint16 styleID);
|
||||||
status_t SetFamilyAndStyle(uint32 fontID);
|
status_t SetFamilyAndStyle(uint32 fontID);
|
||||||
|
|
||||||
uint16 StyleID() const
|
uint16 StyleID() const
|
||||||
{ return fStyle->GetID(); }
|
{ return fStyle->ID(); }
|
||||||
uint16 FamilyID() const
|
uint16 FamilyID() const
|
||||||
{ return fStyle->Family()->GetID(); }
|
{ return fStyle->Family()->ID(); }
|
||||||
uint32 GetFamilyAndStyle() const;
|
uint32 GetFamilyAndStyle() const;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+72
-99
@@ -3,9 +3,12 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* DarkWyrm <[email protected]>
|
* DarkWyrm <[email protected]>
|
||||||
* Jérôme Duval, [email protected]
|
* Jérôme Duval, [email protected]
|
||||||
|
* Axel Dörfler, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -22,9 +25,6 @@
|
|||||||
|
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
// Globals
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// The actual objects which the globals point to
|
// The actual objects which the globals point to
|
||||||
static BFont sPlainFont;
|
static BFont sPlainFont;
|
||||||
@@ -39,9 +39,9 @@ const BFont *be_fixed_font = &sFixedFont;
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
_init_global_fonts()
|
_init_global_fonts()
|
||||||
{
|
{
|
||||||
_font_control_(&sPlainFont,AS_SET_SYSFONT_PLAIN,NULL);
|
_font_control_(&sPlainFont, AS_SET_SYSFONT_PLAIN, NULL);
|
||||||
_font_control_(&sBoldFont,AS_SET_SYSFONT_BOLD,NULL);
|
_font_control_(&sBoldFont, AS_SET_SYSFONT_BOLD, NULL);
|
||||||
_font_control_(&sFixedFont,AS_SET_SYSFONT_FIXED,NULL);
|
_font_control_(&sFixedFont, AS_SET_SYSFONT_FIXED, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +73,6 @@ _font_control_(BFont *font, int32 cmd, void *data)
|
|||||||
|
|
||||||
if (link.FlushWithReply(code) != B_OK
|
if (link.FlushWithReply(code) != B_OK
|
||||||
|| code != SERVER_TRUE) {
|
|| code != SERVER_TRUE) {
|
||||||
// Once again, this shouldn't ever happen, but I want to know about it
|
|
||||||
// if it does
|
|
||||||
printf("DEBUG: Couldn't initialize font in _font_control()\n");
|
printf("DEBUG: Couldn't initialize font in _font_control()\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -89,6 +87,7 @@ _font_control_(BFont *font, int32 cmd, void *data)
|
|||||||
link.Read<uint32>(&font->fFlags);
|
link.Read<uint32>(&font->fFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Private function used to replace the R5 hack which sets a system font
|
\brief Private function used to replace the R5 hack which sets a system font
|
||||||
\param which string denoting which font to set
|
\param which string denoting which font to set
|
||||||
@@ -101,14 +100,14 @@ _font_control_(BFont *font, int32 cmd, void *data)
|
|||||||
*/
|
*/
|
||||||
void
|
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)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!strcmp(which,"plain")
|
if (!strcmp(which, "plain")
|
||||||
|| !strcmp(which,"bold")
|
|| !strcmp(which, "bold")
|
||||||
|| !strcmp(which,"fixed")) {
|
|| !strcmp(which, "fixed")) {
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
link.StartMessage(AS_SET_SYSTEM_FONT);
|
link.StartMessage(AS_SET_SYSTEM_FONT);
|
||||||
@@ -179,7 +178,7 @@ get_font_family(int32 index, font_family *name, uint32 *flags)
|
|||||||
{
|
{
|
||||||
// Fix over R5, which does not check for NULL font family names - it just crashes
|
// Fix over R5, which does not check for NULL font family names - it just crashes
|
||||||
if (!name)
|
if (!name)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int32 code;
|
int32 code;
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
@@ -214,8 +213,8 @@ status_t
|
|||||||
get_font_style(font_family family, int32 index, font_style *name,
|
get_font_style(font_family family, int32 index, font_style *name,
|
||||||
uint32 *flags)
|
uint32 *flags)
|
||||||
{
|
{
|
||||||
if(!name)
|
if (!name)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int32 code;
|
int32 code;
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
@@ -259,8 +258,8 @@ status_t
|
|||||||
get_font_style(font_family family, int32 index, font_style *name,
|
get_font_style(font_family family, int32 index, font_style *name,
|
||||||
uint16 *face, uint32 *flags)
|
uint16 *face, uint32 *flags)
|
||||||
{
|
{
|
||||||
if(!name || !face)
|
if (!name || !face)
|
||||||
return B_ERROR;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
int32 code;
|
int32 code;
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
@@ -331,12 +330,10 @@ set_font_cache_info(uint32 id, void *set)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
// #pragma mark -
|
||||||
// BFont Class Definition
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
BFont::BFont(void)
|
BFont::BFont()
|
||||||
:
|
:
|
||||||
// initialise for be_plain_font (avoid circular definition)
|
// initialise for be_plain_font (avoid circular definition)
|
||||||
fFamilyID(0),
|
fFamilyID(0),
|
||||||
@@ -349,56 +346,28 @@ BFont::BFont(void)
|
|||||||
fFace(0),
|
fFace(0),
|
||||||
fFlags(0)
|
fFlags(0)
|
||||||
{
|
{
|
||||||
fHeight.ascent = 7.0;
|
if (be_plain_font != NULL && this != &sPlainFont)
|
||||||
fHeight.descent = 2.0;
|
*this = *be_plain_font;
|
||||||
fHeight.leading = 13.0;
|
else {
|
||||||
|
fHeight.ascent = 7.0;
|
||||||
fFamilyID = be_plain_font->fFamilyID;
|
fHeight.descent = 2.0;
|
||||||
fStyleID = be_plain_font->fStyleID;
|
fHeight.leading = 13.0;
|
||||||
fSize = be_plain_font->fSize;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BFont::BFont(const BFont &font)
|
BFont::BFont(const BFont &font)
|
||||||
{
|
{
|
||||||
fFamilyID = font.fFamilyID;
|
*this = font;
|
||||||
fStyleID = font.fStyleID;
|
|
||||||
fSize = font.fSize;
|
|
||||||
fShear = font.fShear;
|
|
||||||
fRotation = font.fRotation;
|
|
||||||
fSpacing = font.fSpacing;
|
|
||||||
fEncoding = font.fEncoding;
|
|
||||||
fFace = font.fFace;
|
|
||||||
fFlags = font.fFlags;
|
|
||||||
fHeight = font.fHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BFont::BFont(const BFont *font)
|
BFont::BFont(const BFont *font)
|
||||||
{
|
{
|
||||||
if (font) {
|
if (font)
|
||||||
fFamilyID = font->fFamilyID;
|
*this = *font;
|
||||||
fStyleID = font->fStyleID;
|
else
|
||||||
fSize = font->fSize;
|
*this = *be_plain_font;
|
||||||
fShear = font->fShear;
|
|
||||||
fRotation = font->fRotation;
|
|
||||||
fSpacing = font->fSpacing;
|
|
||||||
fEncoding = font->fEncoding;
|
|
||||||
fFace = font->fFace;
|
|
||||||
fFlags = font->fFlags;
|
|
||||||
fHeight = font->fHeight;
|
|
||||||
} else {
|
|
||||||
fFamilyID = be_plain_font->fFamilyID;
|
|
||||||
fStyleID = be_plain_font->fStyleID;
|
|
||||||
fSize = be_plain_font->fSize;
|
|
||||||
fShear = be_plain_font->fShear;
|
|
||||||
fRotation = be_plain_font->fRotation;
|
|
||||||
fSpacing = be_plain_font->fSpacing;
|
|
||||||
fEncoding = be_plain_font->fEncoding;
|
|
||||||
fFace = be_plain_font->fFace;
|
|
||||||
fFlags = be_plain_font->fFlags;
|
|
||||||
fHeight = be_plain_font->fHeight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -406,42 +375,30 @@ BFont::BFont(const BFont *font)
|
|||||||
\brief Sets the font's family and style all at once
|
\brief Sets the font's family and style all at once
|
||||||
\param family Font family to set
|
\param family Font family to set
|
||||||
\param style Font style to set
|
\param style Font style to set
|
||||||
\return B_ERROR if family or style do not exist or if style does not belong to family.
|
\return B_NAME_NOT_FOUND if family or style do not exist.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BFont::SetFamilyAndStyle(const font_family family, const font_style style)
|
BFont::SetFamilyAndStyle(const font_family family, const font_style style)
|
||||||
{
|
{
|
||||||
// R5 version always returns B_OK. That's a problem...
|
if (family == NULL && style == NULL)
|
||||||
if (!family)
|
return B_BAD_VALUE;
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
int32 code;
|
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
if (!style) {
|
link.StartMessage(AS_SET_FAMILY_AND_STYLE);
|
||||||
// The BeBook states that a NULL style means set only the family
|
link.AttachString(family);
|
||||||
link.StartMessage(AS_SET_FAMILY_NAME);
|
link.AttachString(style);
|
||||||
link.Attach(family, sizeof(font_family));
|
link.Attach<uint16>(fFace);
|
||||||
|
|
||||||
if (link.FlushWithReply(code) != B_OK
|
int32 status;
|
||||||
|| code != SERVER_TRUE)
|
if (link.FlushWithReply(status) != B_OK
|
||||||
return B_ERROR;
|
|| status != B_OK)
|
||||||
|
return status;
|
||||||
link.Read<uint16>(&fFamilyID);
|
|
||||||
} else {
|
|
||||||
link.StartMessage(AS_SET_FAMILY_AND_STYLE);
|
|
||||||
link.Attach(family, sizeof(font_family));
|
|
||||||
link.Attach(style, sizeof(font_style));
|
|
||||||
|
|
||||||
if (link.FlushWithReply(code) != B_OK
|
|
||||||
|| code != SERVER_TRUE)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
link.Read<uint16>(&fFamilyID);
|
|
||||||
link.Read<uint16>(&fStyleID);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
link.Read<uint16>(&fFamilyID);
|
||||||
|
link.Read<uint16>(&fStyleID);
|
||||||
|
link.Read<uint16>(&fFace);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,9 +534,19 @@ BFont::SetFlags(uint32 flags)
|
|||||||
void
|
void
|
||||||
BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
|
BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
|
||||||
{
|
{
|
||||||
if (!family || !style)
|
if (family == NULL && style == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// it's okay to call this function with either family or style set to NULL
|
||||||
|
|
||||||
|
font_family familyBuffer;
|
||||||
|
font_style styleBuffer;
|
||||||
|
|
||||||
|
if (family == NULL)
|
||||||
|
family = &familyBuffer;
|
||||||
|
if (style == NULL)
|
||||||
|
style = &styleBuffer;
|
||||||
|
|
||||||
int32 code;
|
int32 code;
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
@@ -588,8 +555,12 @@ BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
|
|||||||
link.Attach<uint16>(fStyleID);
|
link.Attach<uint16>(fStyleID);
|
||||||
|
|
||||||
if (link.FlushWithReply(code) != B_OK
|
if (link.FlushWithReply(code) != B_OK
|
||||||
|| code != SERVER_TRUE)
|
|| code != SERVER_TRUE) {
|
||||||
|
// the least we can do is to clear the buffers
|
||||||
|
memset(family, 0, sizeof(font_family));
|
||||||
|
memset(style, 0, sizeof(font_style));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
link.Read<font_family>(family);
|
link.Read<font_family>(family);
|
||||||
link.Read<font_style>(style);
|
link.Read<font_style>(style);
|
||||||
@@ -599,8 +570,7 @@ BFont::GetFamilyAndStyle(font_family *family, font_style *style) const
|
|||||||
uint32
|
uint32
|
||||||
BFont::FamilyAndStyle(void) const
|
BFont::FamilyAndStyle(void) const
|
||||||
{
|
{
|
||||||
uint32 token = (fFamilyID << 16) | fStyleID;
|
return (fFamilyID << 16UL) | fStyleID;
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -784,7 +754,7 @@ BFont::GetTunedInfo(int32 index, tuned_font_info *info) const
|
|||||||
link.Read<tuned_font_info>(info);
|
link.Read<tuned_font_info>(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TruncateString
|
|
||||||
void
|
void
|
||||||
BFont::TruncateString(BString *inOut, uint32 mode, float width) const
|
BFont::TruncateString(BString *inOut, uint32 mode, float width) const
|
||||||
{
|
{
|
||||||
@@ -795,7 +765,7 @@ BFont::TruncateString(BString *inOut, uint32 mode, float width) const
|
|||||||
GetTruncatedStrings(array, 1, mode, width, inOut);
|
GetTruncatedStrings(array, 1, mode, width, inOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTruncatedStrings
|
|
||||||
void
|
void
|
||||||
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||||
uint32 mode, float width, BString resultArray[]) const
|
uint32 mode, float width, BString resultArray[]) const
|
||||||
@@ -818,7 +788,7 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTruncatedStrings
|
|
||||||
void
|
void
|
||||||
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
||||||
uint32 mode, float width, char *resultArray[]) const
|
uint32 mode, float width, char *resultArray[]) const
|
||||||
@@ -842,15 +812,17 @@ BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringWidth
|
|
||||||
float
|
float
|
||||||
BFont::StringWidth(const char *string) const
|
BFont::StringWidth(const char *string) const
|
||||||
{
|
{
|
||||||
if (!string)
|
if (!string)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
||||||
int32 length = strlen(string);
|
int32 length = strlen(string);
|
||||||
float width;
|
float width;
|
||||||
GetStringWidths(&string, &length, 1, &width);
|
GetStringWidths(&string, &length, 1, &width);
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,6 +835,7 @@ BFont::StringWidth(const char *string, int32 length) const
|
|||||||
|
|
||||||
float width;
|
float width;
|
||||||
GetStringWidths(&string, &length, 1, &width);
|
GetStringWidths(&string, &length, 1, &width);
|
||||||
|
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -908,7 +881,7 @@ void
|
|||||||
BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta,
|
BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta,
|
||||||
float escapementArray[]) const
|
float escapementArray[]) const
|
||||||
{
|
{
|
||||||
if (!charArray || numChars < 1 || !escapementArray)
|
if (!charArray || numChars < 1 || !escapementArray)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// NOTE: The R5 implementation crashes if delta == NULL!
|
// NOTE: The R5 implementation crashes if delta == NULL!
|
||||||
@@ -953,7 +926,7 @@ void
|
|||||||
BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta,
|
BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *delta,
|
||||||
BPoint escapementArray[], BPoint offsetArray[]) const
|
BPoint escapementArray[], BPoint offsetArray[]) const
|
||||||
{
|
{
|
||||||
if (!charArray || numChars<1 || !escapementArray)
|
if (!charArray || numChars < 1 || !escapementArray)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32 code;
|
int32 code;
|
||||||
|
|||||||
+119
-88
@@ -36,13 +36,14 @@ FTC_Manager ftmanager;
|
|||||||
\param face FreeType handle for the font file after it is loaded - it will be kept open until the FontStyle is destroied
|
\param face FreeType handle for the font file after it is loaded - it will be kept open until the FontStyle is destroied
|
||||||
*/
|
*/
|
||||||
FontStyle::FontStyle(const char *filepath, FT_Face face)
|
FontStyle::FontStyle(const char *filepath, FT_Face face)
|
||||||
: fFTFace(face),
|
:
|
||||||
fFontFamily(NULL),
|
fFTFace(face),
|
||||||
fName(face->style_name),
|
fFontFamily(NULL),
|
||||||
fPath(filepath),
|
fName(face->style_name),
|
||||||
fBounds(0, 0, 0, 0),
|
fPath(filepath),
|
||||||
fID(0),
|
fBounds(0, 0, 0, 0),
|
||||||
fFace(TranslateStyleToFace(face->style_name))
|
fID(0),
|
||||||
|
fFace(_TranslateStyleToFace(face->style_name))
|
||||||
{
|
{
|
||||||
// cachedface = new CachedFaceRec;
|
// cachedface = new CachedFaceRec;
|
||||||
// cachedface->file_path = filepath;
|
// cachedface->file_path = filepath;
|
||||||
@@ -57,6 +58,7 @@ FontStyle::FontStyle(const char *filepath, FT_Face face)
|
|||||||
fHeight.units_per_em = face->units_per_EM;
|
fHeight.units_per_em = face->units_per_EM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Destructor
|
\brief Destructor
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ FontStyle::~FontStyle()
|
|||||||
// FT_Done_Face(fFTFace);
|
// FT_Done_Face(fFTFace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the name of the style as a string
|
\brief Returns the name of the style as a string
|
||||||
\return The style's name
|
\return The style's name
|
||||||
@@ -83,6 +86,7 @@ FontStyle::Name() const
|
|||||||
return fName.String();
|
return fName.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
font_height
|
font_height
|
||||||
FontStyle::GetHeight(const float &size) const
|
FontStyle::GetHeight(const float &size) const
|
||||||
{
|
{
|
||||||
@@ -99,29 +103,32 @@ FontStyle::GetHeight(const float &size) const
|
|||||||
return fh;
|
return fh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the path to the style's font file
|
\brief Returns the path to the style's font file
|
||||||
\return The style's font file path
|
\return The style's font file path
|
||||||
*/
|
*/
|
||||||
const char*
|
const char*
|
||||||
FontStyle::GetPath() const
|
FontStyle::Path() const
|
||||||
{
|
{
|
||||||
return fPath.String();
|
return fPath.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
FontStyle::GetFlags() const
|
FontStyle::Flags() const
|
||||||
{
|
{
|
||||||
int32 flags=0;
|
int32 flags = 0;
|
||||||
if(IsFixedWidth())
|
|
||||||
flags|=B_IS_FIXED;
|
if (IsFixedWidth())
|
||||||
|
flags |= B_IS_FIXED;
|
||||||
if(TunedCount()>0)
|
if (TunedCount() > 0)
|
||||||
flags|=B_HAS_TUNED_FONT;
|
flags |= B_HAS_TUNED_FONT;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Converts an ASCII character to Unicode for the style
|
\brief Converts an ASCII character to Unicode for the style
|
||||||
\param c An ASCII character
|
\param c An ASCII character
|
||||||
@@ -131,7 +138,8 @@ FontStyle::GetFlags() const
|
|||||||
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
// TODO: Re-enable when I understand how the FT2 Cache system changed from
|
||||||
// 2.1.4 to 2.1.8
|
// 2.1.4 to 2.1.8
|
||||||
/*
|
/*
|
||||||
int16 FontStyle::ConvertToUnicode(uint16 c)
|
int16
|
||||||
|
FontStyle::ConvertToUnicode(uint16 c)
|
||||||
{
|
{
|
||||||
FT_Face f;
|
FT_Face f;
|
||||||
if(FTC_Manager_LookupFace(ftmanager,(FTC_FaceID)cachedface,&f)!=0)
|
if(FTC_Manager_LookupFace(ftmanager,(FTC_FaceID)cachedface,&f)!=0)
|
||||||
@@ -142,34 +150,40 @@ int16 FontStyle::ConvertToUnicode(uint16 c)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
uint16
|
uint16
|
||||||
FontStyle::TranslateStyleToFace(const char *name) const
|
FontStyle::_TranslateStyleToFace(const char *name) const
|
||||||
{
|
{
|
||||||
if(!name)
|
if (name == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
BString str(name);
|
BString string(name);
|
||||||
|
uint16 face = 0;
|
||||||
|
|
||||||
if(str.IFindFirst("bold")!=B_ERROR)
|
if (string.IFindFirst("bold") >= 0)
|
||||||
return B_BOLD_FACE;
|
face |= B_BOLD_FACE;
|
||||||
if(str.IFindFirst("italic")!=B_ERROR)
|
|
||||||
return B_ITALIC_FACE;
|
if (string.IFindFirst("italic") >= 0
|
||||||
if(str.IFindFirst("oblique")!=B_ERROR)
|
|| string.IFindFirst("oblique") >= 0)
|
||||||
return B_ITALIC_FACE;
|
face |= B_ITALIC_FACE;
|
||||||
|
|
||||||
return B_REGULAR_FACE;
|
if (face == 0)
|
||||||
|
return B_REGULAR_FACE;
|
||||||
|
|
||||||
|
return face;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Constructor
|
\brief Constructor
|
||||||
\param namestr Name of the family
|
\param namestr Name of the family
|
||||||
*/
|
*/
|
||||||
FontFamily::FontFamily(const char *namestr, const uint16 &index)
|
FontFamily::FontFamily(const char *name, const uint16 &index)
|
||||||
{
|
{
|
||||||
fName = namestr;
|
fName = name;
|
||||||
fID = index;
|
fID = index;
|
||||||
|
|
||||||
// will stay uninitialized until needed
|
// will stay uninitialized until needed
|
||||||
fFlags = -1;
|
fFlags = -1;
|
||||||
}
|
}
|
||||||
@@ -188,6 +202,7 @@ FontFamily::~FontFamily()
|
|||||||
delete (FontStyle*)fStyles.ItemAt(i);
|
delete (FontStyle*)fStyles.ItemAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the name of the family
|
\brief Returns the name of the family
|
||||||
\return The family's name
|
\return The family's name
|
||||||
@@ -198,6 +213,7 @@ FontFamily::Name() const
|
|||||||
return fName.String();
|
return fName.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Adds the style to the family
|
\brief Adds the style to the family
|
||||||
\param face FreeType face handle used to obtain info about the font
|
\param face FreeType face handle used to obtain info about the font
|
||||||
@@ -212,57 +228,52 @@ FontFamily::AddStyle(FontStyle *style)
|
|||||||
|
|
||||||
// Don't add if it already is in the family.
|
// Don't add if it already is in the family.
|
||||||
int32 count = fStyles.CountItems();
|
int32 count = fStyles.CountItems();
|
||||||
for(int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
item = (FontStyle*)fStyles.ItemAt(i);
|
item = (FontStyle*)fStyles.ItemAt(i);
|
||||||
if (item->fName == style->fName)
|
if (item->Name() == style->Name())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
style->fFontFamily = this;
|
style->_SetFontFamily(this);
|
||||||
|
|
||||||
if (fStyles.CountItems() > 0) {
|
if (fStyles.CountItems() > 0) {
|
||||||
item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1);
|
item = (FontStyle*)fStyles.ItemAt(fStyles.CountItems() - 1);
|
||||||
style->fID = item->fID + 1;
|
style->_SetID(item->ID() + 1);
|
||||||
} else {
|
} else {
|
||||||
style->fID = 0;
|
style->_SetID(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fStyles.AddItem(style);
|
fStyles.AddItem(style);
|
||||||
AddDependent();
|
AddDependent();
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
// force a refresh if a request for font flags is needed
|
||||||
fFlags=-1;
|
fFlags = -1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Removes a style from the family and deletes it
|
\brief Removes a style from the family and deletes it
|
||||||
\param style Name of the style to be removed from the family
|
\param style Name of the style to be removed from the family
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
FontFamily::RemoveStyle(const char* style)
|
FontFamily::RemoveStyle(const char* styleName)
|
||||||
{
|
{
|
||||||
int32 count = fStyles.CountItems();
|
FontStyle *style = GetStyle(styleName);
|
||||||
if (!style || count < 1)
|
if (style == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FontStyle *fs;
|
fStyles.RemoveItem(style);
|
||||||
for (int32 i = 0; i < count; i++) {
|
delete style;
|
||||||
fs = (FontStyle*)fStyles.ItemAt(i);
|
|
||||||
if (fs && fs->fName.Compare(style) == 0) {
|
RemoveDependent();
|
||||||
if (fStyles.RemoveItem((void*)fs)) {
|
|
||||||
delete fs;
|
// force a refresh if a request for font flags is needed
|
||||||
RemoveDependent();
|
fFlags = -1;
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
|
||||||
fFlags = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Removes a style from the family. The caller is responsible for freeing the object
|
\brief Removes a style from the family. The caller is responsible for freeing the object
|
||||||
\param style The style to be removed from the family
|
\param style The style to be removed from the family
|
||||||
@@ -270,14 +281,15 @@ FontFamily::RemoveStyle(const char* style)
|
|||||||
void
|
void
|
||||||
FontFamily::RemoveStyle(FontStyle* style)
|
FontFamily::RemoveStyle(FontStyle* style)
|
||||||
{
|
{
|
||||||
if (fStyles.RemoveItem((void*)style)) {
|
if (fStyles.RemoveItem(style)) {
|
||||||
RemoveDependent();
|
RemoveDependent();
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
// force a refresh if a request for font flags is needed
|
||||||
fFlags = -1;
|
fFlags = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the number of styles in the family
|
\brief Returns the number of styles in the family
|
||||||
\return The number of styles in the family
|
\return The number of styles in the family
|
||||||
@@ -288,39 +300,31 @@ FontFamily::CountStyles() const
|
|||||||
return fStyles.CountItems();
|
return fStyles.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Determines whether the style belongs to the family
|
\brief Determines whether the style belongs to the family
|
||||||
\param style Name of the style being checked
|
\param style Name of the style being checked
|
||||||
\return True if it belongs, false if not
|
\return True if it belongs, false if not
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
FontFamily::HasStyle(const char *style) const
|
FontFamily::HasStyle(const char *styleName) const
|
||||||
{
|
{
|
||||||
int32 count = fStyles.CountItems();
|
return GetStyle(styleName) != NULL;
|
||||||
|
|
||||||
if (!style || count < 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
FontStyle *fs;
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
|
||||||
fs = (FontStyle*)fStyles.ItemAt(i);
|
|
||||||
if( fs && fs->fName.Compare(style) == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the name of a style in the family
|
\brief Returns the name of a style in the family
|
||||||
\param index list index of the style to be found
|
\param index list index of the style to be found
|
||||||
\return name of the style or NULL if the index is not valid
|
\return name of the style or NULL if the index is not valid
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontFamily::GetStyle(int32 index) const
|
FontFamily::StyleAt(int32 index) const
|
||||||
{
|
{
|
||||||
return (FontStyle*)fStyles.ItemAt(index);
|
return fStyles.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Get the FontStyle object for the name given
|
\brief Get the FontStyle object for the name given
|
||||||
\param style Name of the style to be obtained
|
\param style Name of the style to be obtained
|
||||||
@@ -329,27 +333,54 @@ FontFamily::GetStyle(int32 index) const
|
|||||||
The object returned belongs to the family and must not be deleted.
|
The object returned belongs to the family and must not be deleted.
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontFamily::GetStyle(const char *style) const
|
FontFamily::GetStyle(const char *styleName) const
|
||||||
{
|
{
|
||||||
int32 count=fStyles.CountItems();
|
int32 count = fStyles.CountItems();
|
||||||
if (!style || count < 1)
|
if (!styleName || count < 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
FontStyle *fs;
|
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
fs = (FontStyle*)fStyles.ItemAt(i);
|
FontStyle *style = fStyles.ItemAt(i);
|
||||||
if (fs && fs->fName.Compare(style) == 0)
|
if (!strcmp(style->Name(), styleName))
|
||||||
return fs;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FontStyle*
|
||||||
|
FontFamily::GetStyleWithID(uint16 id) const
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < fStyles.CountItems(); i++) {
|
||||||
|
FontStyle* style = fStyles.ItemAt(i);
|
||||||
|
if (style->ID() == id)
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FontStyle*
|
||||||
|
FontFamily::GetStyleWithFace(uint16 face) const
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < fStyles.CountItems(); i++) {
|
||||||
|
FontStyle* style = fStyles.ItemAt(i);
|
||||||
|
if (style->Face() == face)
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
FontFamily::GetFlags()
|
FontFamily::Flags()
|
||||||
{
|
{
|
||||||
if (fFlags == -1) {
|
if (fFlags == -1) {
|
||||||
fFlags = 0;
|
fFlags = 0;
|
||||||
|
|
||||||
for (int32 i = 0; i < fStyles.CountItems(); i++) {
|
for (int32 i = 0; i < fStyles.CountItems(); i++) {
|
||||||
FontStyle* style = (FontStyle*)fStyles.ItemAt(i);
|
FontStyle* style = (FontStyle*)fStyles.ItemAt(i);
|
||||||
if (style) {
|
if (style) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ FontServer::GetFamilyName(uint16 id) const
|
|||||||
{
|
{
|
||||||
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
|
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
|
||||||
FontFamily* family = (FontFamily*)fFamilies.ItemAt(i);
|
FontFamily* family = (FontFamily*)fFamilies.ItemAt(i);
|
||||||
if (family && family->GetID() == id)
|
if (family && family->ID() == id)
|
||||||
return family->Name();
|
return family->Name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +146,8 @@ FontStyle*
|
|||||||
FontServer::GetStyle(const char* familyName, uint16 id) const
|
FontServer::GetStyle(const char* familyName, uint16 id) const
|
||||||
{
|
{
|
||||||
FontFamily* family = GetFamily(familyName);
|
FontFamily* family = GetFamily(familyName);
|
||||||
|
if (family != NULL)
|
||||||
for (int32 i = 0; i < family->CountStyles(); i++) {
|
return family->GetStyleWithID(id);
|
||||||
FontStyle* style = family->GetStyle(i);
|
|
||||||
if (style && style->GetID() == id)
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -167,7 +163,7 @@ FontServer::GetStyle(const char* familyName, uint16 id) const
|
|||||||
FontFamily*
|
FontFamily*
|
||||||
FontServer::GetFamily(const char* name) const
|
FontServer::GetFamily(const char* name) const
|
||||||
{
|
{
|
||||||
if (!fInit)
|
if (!fInit || name == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int32 count = fFamilies.CountItems();
|
int32 count = fFamilies.CountItems();
|
||||||
@@ -407,12 +403,16 @@ FontServer::SaveList(void)
|
|||||||
\return The FontStyle having those attributes or NULL if not available
|
\return The FontStyle having those attributes or NULL if not available
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontServer::GetStyle(const char* familyName, const char* styleName)
|
FontServer::GetStyle(const char* familyName, const char* styleName, uint16 face)
|
||||||
{
|
{
|
||||||
FontFamily* family = GetFamily(familyName);
|
FontFamily* family = GetFamily(familyName);
|
||||||
|
if (family) {
|
||||||
if (family)
|
if (styleName == NULL) {
|
||||||
|
// try to get from face
|
||||||
|
return family->GetStyleWithFace(face);
|
||||||
|
}
|
||||||
return family->GetStyle(styleName);
|
return family->GetStyle(styleName);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -425,23 +425,22 @@ FontServer::GetStyle(const char* familyName, const char* styleName)
|
|||||||
\return The FontStyle having those attributes or NULL if not available
|
\return The FontStyle having those attributes or NULL if not available
|
||||||
*/
|
*/
|
||||||
FontStyle*
|
FontStyle*
|
||||||
FontServer::GetStyle(const uint16& familyID, const uint16& styleID)
|
FontServer::GetStyle(uint16 familyID, uint16 styleID)
|
||||||
{
|
{
|
||||||
FontFamily *family = GetFamily(familyID);
|
FontFamily *family = GetFamily(familyID);
|
||||||
|
|
||||||
if (family)
|
if (family)
|
||||||
return family->GetStyle(styleID);
|
return family->GetStyleWithID(styleID);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FontFamily*
|
FontFamily*
|
||||||
FontServer::GetFamily(const uint16& familyID) const
|
FontServer::GetFamily(uint16 familyID) const
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
|
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
|
||||||
FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
|
FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
|
||||||
if (family->GetID() == familyID)
|
if (family->ID() == familyID)
|
||||||
return family;
|
return family;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1174,7 +1174,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
fam[sizeof(font_family) - 1] = 0;
|
fam[sizeof(font_family) - 1] = 0;
|
||||||
fLink.StartMessage(SERVER_TRUE);
|
fLink.StartMessage(SERVER_TRUE);
|
||||||
fLink.Attach(fam, sizeof(font_family));
|
fLink.Attach(fam, sizeof(font_family));
|
||||||
fLink.Attach<uint32>(ffamily->GetFlags());
|
fLink.Attach<uint32>(ffamily->Flags());
|
||||||
} else
|
} else
|
||||||
fLink.StartMessage(SERVER_FALSE);
|
fLink.StartMessage(SERVER_FALSE);
|
||||||
|
|
||||||
@@ -1208,8 +1208,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
style[sizeof(font_style) - 1] = 0;
|
style[sizeof(font_style) - 1] = 0;
|
||||||
fLink.StartMessage(SERVER_TRUE);
|
fLink.StartMessage(SERVER_TRUE);
|
||||||
fLink.Attach(style, sizeof(font_style));
|
fLink.Attach(style, sizeof(font_style));
|
||||||
fLink.Attach<uint32>(fstyle->GetFace());
|
fLink.Attach<uint32>(fstyle->Face());
|
||||||
fLink.Attach<uint32>(fstyle->GetFlags());
|
fLink.Attach<uint32>(fstyle->Flags());
|
||||||
} else
|
} else
|
||||||
fLink.StartMessage(SERVER_FALSE);
|
fLink.StartMessage(SERVER_FALSE);
|
||||||
|
|
||||||
@@ -1227,27 +1227,27 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
// Returns:
|
// Returns:
|
||||||
// 1) font_family The name of the font family
|
// 1) font_family The name of the font family
|
||||||
// 2) font_style - name of the style
|
// 2) font_style - name of the style
|
||||||
uint16 famid, styid;
|
uint16 familyID, styleID;
|
||||||
font_family fam;
|
link.Read<uint16>(&familyID);
|
||||||
font_style sty;
|
link.Read<uint16>(&styleID);
|
||||||
|
|
||||||
link.Read<uint16>(&famid);
|
|
||||||
link.Read<uint16>(&styid);
|
|
||||||
|
|
||||||
gFontServer->Lock();
|
gFontServer->Lock();
|
||||||
FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
|
FontStyle *fontStyle = gFontServer->GetStyle(familyID, styleID);
|
||||||
if (fstyle) {
|
if (fontStyle != NULL) {
|
||||||
strncpy(fam, fstyle->Family()->Name(), sizeof(font_family) - 1);
|
font_family family;
|
||||||
strncpy(sty, fstyle->Name(), sizeof(font_style) - 1);
|
font_style style;
|
||||||
fam[sizeof(font_family) - 1] = 0;
|
|
||||||
sty[sizeof(font_style) - 1] = 0;
|
|
||||||
|
|
||||||
fLink.StartMessage(SERVER_TRUE);
|
strncpy(family, fontStyle->Family()->Name(), sizeof(font_family) - 1);
|
||||||
fLink.Attach(fam, sizeof(font_family));
|
family[sizeof(font_family) - 1] = 0;
|
||||||
fLink.Attach(sty, sizeof(font_style));
|
strncpy(style, fontStyle->Name(), sizeof(font_style) - 1);
|
||||||
|
style[sizeof(font_style) - 1] = 0;
|
||||||
|
|
||||||
|
fLink.StartMessage(B_OK);
|
||||||
|
fLink.Attach(family, sizeof(font_family));
|
||||||
|
fLink.Attach(style, sizeof(font_style));
|
||||||
} else
|
} else
|
||||||
fLink.StartMessage(SERVER_FALSE);
|
fLink.StartMessage(B_BAD_VALUE);
|
||||||
|
|
||||||
fLink.Flush();
|
fLink.Flush();
|
||||||
gFontServer->Unlock();
|
gFontServer->Unlock();
|
||||||
break;
|
break;
|
||||||
@@ -1319,7 +1319,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
float widthArray[numStrings];
|
float widthArray[numStrings];
|
||||||
int32 lengthArray[numStrings];
|
int32 lengthArray[numStrings];
|
||||||
char *stringArray[numStrings];
|
char *stringArray[numStrings];
|
||||||
for(int32 i=0; i<numStrings; i++) {
|
for (int32 i = 0; i < numStrings; i++) {
|
||||||
link.Read<int32>(&lengthArray[i]);
|
link.Read<int32>(&lengthArray[i]);
|
||||||
stringArray[i] = new char[lengthArray[i]];
|
stringArray[i] = new char[lengthArray[i]];
|
||||||
link.ReadString(&stringArray[i]);
|
link.ReadString(&stringArray[i]);
|
||||||
@@ -1333,7 +1333,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
font.SetSize(size);
|
font.SetSize(size);
|
||||||
font.SetSpacing(spacing);
|
font.SetSpacing(spacing);
|
||||||
|
|
||||||
for (int32 i=0; i<numStrings; i++)
|
for (int32 i = 0; i < numStrings; i++)
|
||||||
if (!stringArray[i] || lengthArray[i] <= 0)
|
if (!stringArray[i] || lengthArray[i] <= 0)
|
||||||
widthArray[i] = 0.0;
|
widthArray[i] = 0.0;
|
||||||
else
|
else
|
||||||
@@ -1349,7 +1349,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
fLink.StartMessage(SERVER_FALSE);
|
fLink.StartMessage(SERVER_FALSE);
|
||||||
|
|
||||||
fLink.Flush();
|
fLink.Flush();
|
||||||
for(int32 i=0; i<numStrings; i++) {
|
for (int32 i = 0; i < numStrings; i++) {
|
||||||
delete[] stringArray[i];
|
delete[] stringArray[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1437,30 +1437,6 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
gFontServer->Unlock();
|
gFontServer->Unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AS_SET_FAMILY_NAME:
|
|
||||||
{
|
|
||||||
FTRACE(("ServerApp %s: AS_SET_FAMILY_NAME\n", Signature()));
|
|
||||||
// Attached Data:
|
|
||||||
// 1) font_family - name of font family to use
|
|
||||||
|
|
||||||
// Returns:
|
|
||||||
// 1) uint16 - family ID
|
|
||||||
|
|
||||||
font_family fam;
|
|
||||||
link.Read(fam, sizeof(font_family));
|
|
||||||
|
|
||||||
gFontServer->Lock();
|
|
||||||
FontFamily *ffam = gFontServer->GetFamily(fam);
|
|
||||||
if (ffam) {
|
|
||||||
fLink.StartMessage(SERVER_TRUE);
|
|
||||||
fLink.Attach<uint16>(ffam->GetID());
|
|
||||||
} else
|
|
||||||
fLink.StartMessage(SERVER_FALSE);
|
|
||||||
|
|
||||||
fLink.Flush();
|
|
||||||
gFontServer->Unlock();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AS_SET_FAMILY_AND_STYLE:
|
case AS_SET_FAMILY_AND_STYLE:
|
||||||
{
|
{
|
||||||
FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE\n",
|
FTRACE(("ServerApp %s: AS_SET_FAMILY_AND_STYLE\n",
|
||||||
@@ -1468,27 +1444,35 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
|||||||
// 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
|
||||||
|
// 3) face - the font's current face
|
||||||
|
|
||||||
// Returns:
|
// Returns:
|
||||||
// 1) uint16 - family ID
|
// 1) uint16 - family ID
|
||||||
// 2) uint16 - style ID
|
// 2) uint16 - style ID
|
||||||
|
// 3) uint16 - face
|
||||||
|
|
||||||
font_family fam;
|
font_family family;
|
||||||
font_style sty;
|
font_style style;
|
||||||
link.Read(fam, sizeof(font_family));
|
uint16 face;
|
||||||
link.Read(sty, sizeof(font_style));
|
if (link.ReadString(family, sizeof(font_family)) == B_OK
|
||||||
|
&& link.ReadString(style, sizeof(font_style)) == B_OK
|
||||||
gFontServer->Lock();
|
&& link.Read<uint16>(&face) == B_OK) {
|
||||||
FontStyle *fstyle = gFontServer->GetStyle(fam, sty);
|
// get the font and return IDs and face
|
||||||
if (fstyle) {
|
gFontServer->Lock();
|
||||||
fLink.StartMessage(SERVER_TRUE);
|
FontStyle *fontStyle = gFontServer->GetStyle(family[0] ? family : NULL,
|
||||||
fLink.Attach<uint16>(fstyle->Family()->GetID());
|
style[0] ? style : NULL, face);
|
||||||
fLink.Attach<uint16>(fstyle->GetID());
|
if (fontStyle != NULL) {
|
||||||
|
fLink.StartMessage(B_OK);
|
||||||
|
fLink.Attach<uint16>(fontStyle->Family()->ID());
|
||||||
|
fLink.Attach<uint16>(fontStyle->ID());
|
||||||
|
fLink.Attach<uint16>(fontStyle->Face());
|
||||||
|
} else
|
||||||
|
fLink.StartMessage(B_NAME_NOT_FOUND);
|
||||||
|
gFontServer->Unlock();
|
||||||
} else
|
} else
|
||||||
fLink.StartMessage(SERVER_FALSE);
|
fLink.StartMessage(B_BAD_VALUE);
|
||||||
|
|
||||||
fLink.Flush();
|
fLink.Flush();
|
||||||
gFontServer->Unlock();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AS_SET_FAMILY_AND_STYLE_FROM_ID:
|
case AS_SET_FAMILY_AND_STYLE_FROM_ID:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ if $(TARGET_PLATFORM) != haiku {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UseLibraryHeaders agg ;
|
UseLibraryHeaders agg ;
|
||||||
UsePrivateHeaders app interface [ FDirName servers app ] ;
|
UsePrivateHeaders app interface shared [ FDirName servers app ] ;
|
||||||
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter drawing_modes ] ;
|
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter drawing_modes ] ;
|
||||||
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter font_support ] ;
|
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter font_support ] ;
|
||||||
UseFreeTypeHeaders ;
|
UseFreeTypeHeaders ;
|
||||||
|
|||||||
Reference in New Issue
Block a user