app_server: push FontManager knowledge to FontStyle creation

Change-Id: I98a68a894642147d398faf22591a22afef4c3ba2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6060
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Máximo Castañeda 2023-02-10 17:08:56 +01:00 committed by Adrien Destugues
parent cb190a7dee
commit 85d52d335d
6 changed files with 19 additions and 40 deletions

View File

@ -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));
// 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 family;
return B_NO_MEMORY;

View File

@ -12,8 +12,6 @@
#include "FontFamily.h"
#include "GlobalFontManager.h"
#include <FontPrivate.h>
@ -98,7 +96,7 @@ FontFamily::Name() const
\param style pointer to FontStyle object to be added
*/
bool
FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
FontFamily::AddStyle(FontStyle* style)
{
if (!style)
return false;
@ -115,7 +113,6 @@ FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
return false;
style->_SetFontFamily(this, fNextID++);
style->_SetFontManager(fontManager);
// force a refresh if a request for font flags is needed
fFlags = kInvalidFamilyFlags;
@ -130,16 +127,8 @@ FontFamily::AddStyle(FontStyle* style, AppFontManager* fontManager)
The font style will not be deleted.
*/
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)
return false;

View File

@ -13,7 +13,6 @@
#include <ObjectList.h>
#include <String.h>
#include "AppFontManager.h"
#include "FontStyle.h"
@ -31,10 +30,8 @@ public:
const char* Name() const;
bool AddStyle(FontStyle* style,
AppFontManager* fontManager = NULL);
bool RemoveStyle(FontStyle* style,
AppFontManager* fontManager = NULL);
bool AddStyle(FontStyle* style);
bool RemoveStyle(FontStyle* style);
FontStyle* GetStyle(const char* style) const;
FontStyle* GetStyleMatchingFace(uint16 face) const;

View File

@ -11,8 +11,8 @@
#include "FontFamily.h"
#include "FontManager.h"
#include "ServerFont.h"
#include "GlobalFontManager.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
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),
fName(face->style_name),
@ -39,7 +40,8 @@ FontStyle::FontStyle(node_ref& nodeRef, const char* path, FT_Face face)
fBounds(0, 0, 0, 0),
fFace(_TranslateStyleToFace(face->style_name)),
fFullAndHalfFixed(false),
fFontData(NULL)
fFontData(NULL),
fFontManager(fontManager)
{
fName.Truncate(B_FONT_STYLE_LENGTH);
// 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()
{
// make sure the font server is ours
if (fFamily != NULL) {
if (fFontManager != NULL && fFontManager->Lock()) {
if (fFamily != NULL && fFontManager->Lock()) {
fFontManager->RemoveStyle(this);
fFontManager->Unlock();
} else if (gFontManager->Lock()) {
gFontManager->RemoveStyle(this);
gFontManager->Unlock();
}
}
FT_Done_Face(fFreeTypeFace);

View File

@ -22,12 +22,10 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include "AppFontManager.h"
struct node_ref;
class AppFontManager;
class FontFamily;
class FontManagerBase;
class ServerFont;
@ -41,7 +39,7 @@ class ServerFont;
class FontStyle : public BReferenceable {
public:
FontStyle(node_ref& nodeRef, const char* path,
FT_Face face);
FT_Face face, FontManagerBase* fontManager);
virtual ~FontStyle();
const node_ref& NodeRef() const { return fNodeRef; }
@ -145,8 +143,6 @@ class FontStyle : public BReferenceable {
friend class FontFamily;
uint16 _TranslateStyleToFace(const char *name) const;
void _SetFontFamily(FontFamily* family, uint16 id);
void _SetFontManager(AppFontManager* fontManager)
{ fFontManager = fontManager; }
private:
FT_Face fFreeTypeFace;
BString fName;
@ -164,7 +160,7 @@ class FontStyle : public BReferenceable {
FT_Byte* fFontData;
uint32 fFontDataSize;
AppFontManager* fFontManager;
FontManagerBase* fFontManager;
};
#endif // FONT_STYLE_H_

View File

@ -733,7 +733,7 @@ GlobalFontManager::_AddFont(font_directory& directory, BEntry& entry)
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
// 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)) {
delete style;
delete family;