app_server: push FontManager knowledge to FontStyle creation
Change-Id: I98a68a894642147d398faf22591a22afef4c3ba2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6060 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
cb190a7dee
commit
85d52d335d
@@ -74,9 +74,9 @@ AppFontManager::_AddUserFont(FT_Face face, node_ref nodeRef, const char* path,
|
|||||||
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
|
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
|
||||||
|
|
||||||
// the FontStyle takes over ownership of the FT_Face object
|
// the FontStyle takes over ownership of the FT_Face object
|
||||||
FontStyle* style = new (std::nothrow) FontStyle(nodeRef, path, face);
|
FontStyle* style = new (std::nothrow) FontStyle(nodeRef, path, face, this);
|
||||||
|
|
||||||
if (style == NULL || !family->AddStyle(style, this)) {
|
if (style == NULL || !family->AddStyle(style)) {
|
||||||
delete style;
|
delete style;
|
||||||
delete family;
|
delete family;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
#include "FontFamily.h"
|
#include "FontFamily.h"
|
||||||
|
|
||||||
#include "GlobalFontManager.h"
|
|
||||||
|
|
||||||
#include <FontPrivate.h>
|
#include <FontPrivate.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -98,7 +96,7 @@ FontFamily::Name() const
|
|||||||
\param style pointer to FontStyle object to be added
|
\param style pointer to FontStyle object to be added
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
|
FontFamily::AddStyle(FontStyle* style)
|
||||||
{
|
{
|
||||||
if (!style)
|
if (!style)
|
||||||
return false;
|
return false;
|
||||||
@@ -115,7 +113,6 @@ FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
style->_SetFontFamily(this, fNextID++);
|
style->_SetFontFamily(this, fNextID++);
|
||||||
style->_SetFontManager(fontManager);
|
|
||||||
|
|
||||||
// force a refresh if a request for font flags is needed
|
// force a refresh if a request for font flags is needed
|
||||||
fFlags = kInvalidFamilyFlags;
|
fFlags = kInvalidFamilyFlags;
|
||||||
@@ -130,16 +127,8 @@ FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
|
|||||||
The font style will not be deleted.
|
The font style will not be deleted.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
FontFamily::RemoveStyle(FontStyle* style, AppFontManager* fontManager)
|
FontFamily::RemoveStyle(FontStyle* style)
|
||||||
{
|
{
|
||||||
if (!gFontManager->IsLocked() && fontManager == NULL) {
|
|
||||||
debugger("FontFamily::RemoveStyle() called without having the global font manager locked!");
|
|
||||||
return false;
|
|
||||||
} else if (fontManager != NULL && !fontManager->IsLocked()) {
|
|
||||||
debugger("FontFamily::RemoveStyle() called without having the app font manager locked!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (style == NULL)
|
if (style == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include "AppFontManager.h"
|
|
||||||
#include "FontStyle.h"
|
#include "FontStyle.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -31,10 +30,8 @@ public:
|
|||||||
|
|
||||||
const char* Name() const;
|
const char* Name() const;
|
||||||
|
|
||||||
bool AddStyle(FontStyle* style,
|
bool AddStyle(FontStyle* style);
|
||||||
AppFontManager* fontManager = NULL);
|
bool RemoveStyle(FontStyle* style);
|
||||||
bool RemoveStyle(FontStyle* style,
|
|
||||||
AppFontManager* fontManager = NULL);
|
|
||||||
|
|
||||||
FontStyle* GetStyle(const char* style) const;
|
FontStyle* GetStyle(const char* style) const;
|
||||||
FontStyle* GetStyleMatchingFace(uint16 face) const;
|
FontStyle* GetStyleMatchingFace(uint16 face) const;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "FontFamily.h"
|
#include "FontFamily.h"
|
||||||
|
#include "FontManager.h"
|
||||||
#include "ServerFont.h"
|
#include "ServerFont.h"
|
||||||
#include "GlobalFontManager.h"
|
|
||||||
|
|
||||||
#include <FontPrivate.h>
|
#include <FontPrivate.h>
|
||||||
|
|
||||||
@@ -28,7 +28,8 @@ static BLocker sFontLock("font lock");
|
|||||||
\param face FreeType handle for the font file after it is loaded - it will
|
\param face FreeType handle for the font file after it is loaded - it will
|
||||||
be kept open until the FontStyle is destroyed
|
be kept open until the FontStyle is destroyed
|
||||||
*/
|
*/
|
||||||
FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
|
FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face,
|
||||||
|
FontManagerBase* fontManager)
|
||||||
:
|
:
|
||||||
fFreeTypeFace(face),
|
fFreeTypeFace(face),
|
||||||
fName(face->style_name),
|
fName(face->style_name),
|
||||||
@@ -39,7 +40,8 @@ FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
|
|||||||
fBounds(0, 0, 0, 0),
|
fBounds(0, 0, 0, 0),
|
||||||
fFace(_TranslateStyleToFace(face->style_name)),
|
fFace(_TranslateStyleToFace(face->style_name)),
|
||||||
fFullAndHalfFixed(false),
|
fFullAndHalfFixed(false),
|
||||||
fFontData(NULL)
|
fFontData(NULL),
|
||||||
|
fFontManager(fontManager)
|
||||||
{
|
{
|
||||||
fName.Truncate(B_FONT_STYLE_LENGTH);
|
fName.Truncate(B_FONT_STYLE_LENGTH);
|
||||||
// make sure this style can be found using the Be API
|
// make sure this style can be found using the Be API
|
||||||
@@ -94,14 +96,9 @@ FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
|
|||||||
FontStyle::~FontStyle()
|
FontStyle::~FontStyle()
|
||||||
{
|
{
|
||||||
// make sure the font server is ours
|
// make sure the font server is ours
|
||||||
if (fFamily != NULL) {
|
if (fFamily != NULL && fFontManager->Lock()) {
|
||||||
if (fFontManager != NULL && fFontManager->Lock()) {
|
fFontManager->RemoveStyle(this);
|
||||||
fFontManager->RemoveStyle(this);
|
fFontManager->Unlock();
|
||||||
fFontManager->Unlock();
|
|
||||||
} else if (gFontManager->Lock()) {
|
|
||||||
gFontManager->RemoveStyle(this);
|
|
||||||
gFontManager->Unlock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_Done_Face(fFreeTypeFace);
|
FT_Done_Face(fFreeTypeFace);
|
||||||
@@ -278,4 +275,4 @@ FontStyle::SetFontData(FT_Byte* location, uint32 size)
|
|||||||
|
|
||||||
fFontDataSize = size;
|
fFontDataSize = size;
|
||||||
fFontData = location;
|
fFontData = location;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,10 @@
|
|||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
|
||||||
#include "AppFontManager.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct node_ref;
|
struct node_ref;
|
||||||
class AppFontManager;
|
|
||||||
class FontFamily;
|
class FontFamily;
|
||||||
|
class FontManagerBase;
|
||||||
class ServerFont;
|
class ServerFont;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ class ServerFont;
|
|||||||
class FontStyle : public BReferenceable {
|
class FontStyle : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
FontStyle(node_ref& nodeRef, const char* path,
|
FontStyle(node_ref& nodeRef, const char* path,
|
||||||
FT_Face face);
|
FT_Face face, FontManagerBase* fontManager);
|
||||||
virtual ~FontStyle();
|
virtual ~FontStyle();
|
||||||
|
|
||||||
const node_ref& NodeRef() const { return fNodeRef; }
|
const node_ref& NodeRef() const { return fNodeRef; }
|
||||||
@@ -145,8 +143,6 @@ class FontStyle : public BReferenceable {
|
|||||||
friend class FontFamily;
|
friend class FontFamily;
|
||||||
uint16 _TranslateStyleToFace(const char *name) const;
|
uint16 _TranslateStyleToFace(const char *name) const;
|
||||||
void _SetFontFamily(FontFamily* family, uint16 id);
|
void _SetFontFamily(FontFamily* family, uint16 id);
|
||||||
void _SetFontManager(AppFontManager* fontManager)
|
|
||||||
{ fFontManager = fontManager; }
|
|
||||||
private:
|
private:
|
||||||
FT_Face fFreeTypeFace;
|
FT_Face fFreeTypeFace;
|
||||||
BString fName;
|
BString fName;
|
||||||
@@ -164,7 +160,7 @@ class FontStyle : public BReferenceable {
|
|||||||
|
|
||||||
FT_Byte* fFontData;
|
FT_Byte* fFontData;
|
||||||
uint32 fFontDataSize;
|
uint32 fFontDataSize;
|
||||||
AppFontManager* fFontManager;
|
FontManagerBase* fFontManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FONT_STYLE_H_
|
#endif // FONT_STYLE_H_
|
||||||
|
|||||||
@@ -733,7 +733,7 @@ GlobalFontManager::_AddFont(font_directory& directory, BEntry& entry)
|
|||||||
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
|
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
|
||||||
|
|
||||||
// the FontStyle takes over ownership of the FT_Face object
|
// the FontStyle takes over ownership of the FT_Face object
|
||||||
FontStyle* style = new (std::nothrow) FontStyle(nodeRef, path.Path(), face);
|
FontStyle* style = new (std::nothrow) FontStyle(nodeRef, path.Path(), face, this);
|
||||||
if (style == NULL || !family->AddStyle(style)) {
|
if (style == NULL || !family->AddStyle(style)) {
|
||||||
delete style;
|
delete style;
|
||||||
delete family;
|
delete family;
|
||||||
|
|||||||
Reference in New Issue
Block a user