* Implemented automatic font_directory creation for font_mappings.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15584 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -79,6 +79,7 @@ class FontManager : public BLooper {
|
|||||||
void _AddSystemPaths();
|
void _AddSystemPaths();
|
||||||
font_directory* _FindDirectory(node_ref& nodeRef);
|
font_directory* _FindDirectory(node_ref& nodeRef);
|
||||||
void _RemoveDirectory(font_directory* directory);
|
void _RemoveDirectory(font_directory* directory);
|
||||||
|
status_t _CreateDirectories(const char* path);
|
||||||
status_t _AddPath(const char* path);
|
status_t _AddPath(const char* path);
|
||||||
status_t _AddPath(BEntry& entry, font_directory** _newDirectory = NULL);
|
status_t _AddPath(BEntry& entry, font_directory** _newDirectory = NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -29,11 +29,11 @@
|
|||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
//#define TRACE_WATCHING
|
//#define TRACE_FONT_MANAGER
|
||||||
#ifdef TRACE_WATCHING
|
#ifdef TRACE_FONT_MANAGER
|
||||||
# define WTRACE(x) printf x
|
# define FTRACE(x) printf x
|
||||||
#else
|
#else
|
||||||
# define WTRACE(x) ;
|
# define FTRACE(x) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -220,9 +220,9 @@ FontManager::MessageReceived(BMessage* message)
|
|||||||
fromDirectory->styles.RemoveItem(style, false);
|
fromDirectory->styles.RemoveItem(style, false);
|
||||||
directory->styles.AddItem(style);
|
directory->styles.AddItem(style);
|
||||||
}
|
}
|
||||||
WTRACE(("font moved"));
|
FTRACE(("font moved"));
|
||||||
} else {
|
} else {
|
||||||
WTRACE(("font added: %s\n", name));
|
FTRACE(("font added: %s\n", name));
|
||||||
_AddFont(*directory, entry);
|
_AddFont(*directory, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ void
|
|||||||
FontManager::_AddDefaultMapping(const char* family, const char* style,
|
FontManager::_AddDefaultMapping(const char* family, const char* style,
|
||||||
const char* path)
|
const char* path)
|
||||||
{
|
{
|
||||||
font_mapping* mapping = new (nothrow) font_mapping;
|
font_mapping* mapping = new (std::nothrow) font_mapping;
|
||||||
if (mapping == NULL)
|
if (mapping == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -311,6 +311,9 @@ FontManager::_LoadRecentFontMappings()
|
|||||||
status_t
|
status_t
|
||||||
FontManager::_AddMappedFont(const char* familyName, const char* styleName)
|
FontManager::_AddMappedFont(const char* familyName, const char* styleName)
|
||||||
{
|
{
|
||||||
|
FTRACE(("_AddMappedFont(family = \"%s\", style = \"%s\")\n",
|
||||||
|
familyName, styleName));
|
||||||
|
|
||||||
for (int32 i = 0; i < fMappings.CountItems(); i++) {
|
for (int32 i = 0; i < fMappings.CountItems(); i++) {
|
||||||
font_mapping* mapping = fMappings.ItemAt(i);
|
font_mapping* mapping = fMappings.ItemAt(i);
|
||||||
|
|
||||||
@@ -329,8 +332,13 @@ FontManager::_AddMappedFont(const char* familyName, const char* styleName)
|
|||||||
nodeRef.node = mapping->ref.directory;
|
nodeRef.node = mapping->ref.directory;
|
||||||
font_directory* directory = _FindDirectory(nodeRef);
|
font_directory* directory = _FindDirectory(nodeRef);
|
||||||
if (directory == NULL) {
|
if (directory == NULL) {
|
||||||
// unknown directory, maybe this is a user font
|
// unknown directory, maybe this is a user font - try
|
||||||
continue;
|
// to create the missing directory
|
||||||
|
BPath path(&entry);
|
||||||
|
if (path.GetParent(&path) != B_OK
|
||||||
|
|| _CreateDirectories(path.Path()) != B_OK
|
||||||
|
|| (directory = _FindDirectory(nodeRef)) == NULL)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _AddFont(*directory, entry);
|
return _AddFont(*directory, entry);
|
||||||
@@ -350,7 +358,7 @@ FontManager::_AddMappedFont(const char* familyName, const char* styleName)
|
|||||||
void
|
void
|
||||||
FontManager::_RemoveStyle(font_directory& directory, FontStyle* style)
|
FontManager::_RemoveStyle(font_directory& directory, FontStyle* style)
|
||||||
{
|
{
|
||||||
WTRACE(("font removed: %s\n", style->Name()));
|
FTRACE(("font removed: %s\n", style->Name()));
|
||||||
|
|
||||||
directory.styles.RemoveItem(style);
|
directory.styles.RemoveItem(style);
|
||||||
directory.revision++;
|
directory.revision++;
|
||||||
@@ -416,21 +424,21 @@ FontManager::_SetDefaultFonts()
|
|||||||
if (style == NULL)
|
if (style == NULL)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fDefaultPlainFont = new (nothrow) ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
|
fDefaultPlainFont = new (std::nothrow) ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
|
||||||
if (fDefaultPlainFont == NULL)
|
if (fDefaultPlainFont == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
style = _GetDefaultStyle(DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
|
style = _GetDefaultStyle(DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
|
||||||
FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, B_BOLD_FACE);
|
FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, B_BOLD_FACE);
|
||||||
|
|
||||||
fDefaultBoldFont = new (nothrow) ServerFont(*style, DEFAULT_BOLD_FONT_SIZE);
|
fDefaultBoldFont = new (std::nothrow) ServerFont(*style, DEFAULT_BOLD_FONT_SIZE);
|
||||||
if (fDefaultBoldFont == NULL)
|
if (fDefaultBoldFont == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
style = _GetDefaultStyle(DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
|
style = _GetDefaultStyle(DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
|
||||||
FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, B_REGULAR_FACE);
|
FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, B_REGULAR_FACE);
|
||||||
|
|
||||||
fDefaultFixedFont = new (nothrow) ServerFont(*style, DEFAULT_FIXED_FONT_SIZE);
|
fDefaultFixedFont = new (std::nothrow) ServerFont(*style, DEFAULT_FIXED_FONT_SIZE);
|
||||||
if (fDefaultFixedFont == NULL)
|
if (fDefaultFixedFont == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -443,19 +451,13 @@ void
|
|||||||
FontManager::_AddSystemPaths()
|
FontManager::_AddSystemPaths()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_BEOS_FONTS_DIRECTORY, &path, true) == B_OK) {
|
if (find_directory(B_BEOS_FONTS_DIRECTORY, &path, true) == B_OK)
|
||||||
_AddPath(path.Path());
|
_AddPath(path.Path());
|
||||||
if (path.Append("ttfonts") == B_OK)
|
|
||||||
_AddPath(path.Path());
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't scan these in test mode to help shave off some startup time
|
// We don't scan these in test mode to help shave off some startup time
|
||||||
#if !TEST_MODE
|
#if !TEST_MODE
|
||||||
if (find_directory(B_COMMON_FONTS_DIRECTORY, &path, true) == B_OK) {
|
if (find_directory(B_COMMON_FONTS_DIRECTORY, &path, true) == B_OK)
|
||||||
_AddPath(path.Path());
|
_AddPath(path.Path());
|
||||||
if (path.Append("ttfonts") == B_OK)
|
|
||||||
_AddPath(path.Path());
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +520,7 @@ FontManager::_AddFont(font_directory& directory, BEntry& entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (family == NULL) {
|
if (family == NULL) {
|
||||||
family = new (nothrow) FontFamily(face->family_name, fNextID++);
|
family = new (std::nothrow) FontFamily(face->family_name, fNextID++);
|
||||||
if (family == NULL
|
if (family == NULL
|
||||||
|| !fFamilies.BinaryInsert(family, compare_font_families)) {
|
|| !fFamilies.BinaryInsert(family, compare_font_families)) {
|
||||||
delete family;
|
delete family;
|
||||||
@@ -527,7 +529,7 @@ FontManager::_AddFont(font_directory& directory, BEntry& entry)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WTRACE(("\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 FontStyle(nodeRef, path.Path(), face);
|
FontStyle *style = new FontStyle(nodeRef, path.Path(), face);
|
||||||
@@ -561,7 +563,7 @@ FontManager::_FindDirectory(node_ref& nodeRef)
|
|||||||
void
|
void
|
||||||
FontManager::_RemoveDirectory(font_directory* directory)
|
FontManager::_RemoveDirectory(font_directory* directory)
|
||||||
{
|
{
|
||||||
WTRACE(("FontManager: Remove directory (%Ld)!\n", directory->directory.node));
|
FTRACE(("FontManager: Remove directory (%Ld)!\n", directory->directory.node));
|
||||||
|
|
||||||
fDirectories.RemoveItem(directory, false);
|
fDirectories.RemoveItem(directory, false);
|
||||||
|
|
||||||
@@ -602,7 +604,7 @@ FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
|
|||||||
|
|
||||||
// it's a new one, so let's add it
|
// it's a new one, so let's add it
|
||||||
|
|
||||||
directory = new (nothrow) font_directory;
|
directory = new (std::nothrow) font_directory;
|
||||||
if (directory == NULL)
|
if (directory == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -626,7 +628,7 @@ FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
|
|||||||
// TODO: should go into syslog()
|
// TODO: should go into syslog()
|
||||||
} else {
|
} else {
|
||||||
BPath path(&entry);
|
BPath path(&entry);
|
||||||
WTRACE(("FontManager: now watching: %s\n", path.Path()));
|
FTRACE(("FontManager: now watching: %s\n", path.Path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fDirectories.AddItem(directory);
|
fDirectories.AddItem(directory);
|
||||||
@@ -639,6 +641,59 @@ FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Creates all unknown font_directories of the specified path - but
|
||||||
|
only if one of its parent directories is already known.
|
||||||
|
|
||||||
|
This method is used to create the font_directories for font_mappings.
|
||||||
|
It recursively walks upwards in the directory hierarchy until it finds
|
||||||
|
a known font_directory (or hits the root directory, in which case it
|
||||||
|
bails out).
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
FontManager::_CreateDirectories(const char* path)
|
||||||
|
{
|
||||||
|
FTRACE(("_CreateDirectories(path = %s)\n", path));
|
||||||
|
|
||||||
|
if (!strcmp(path, "/")) {
|
||||||
|
// we walked our way up to the root
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
BEntry entry;
|
||||||
|
status_t status = entry.SetTo(path);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
node_ref nodeRef;
|
||||||
|
status = entry.GetNodeRef(&nodeRef);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
// check if we are already know this directory
|
||||||
|
|
||||||
|
font_directory* directory = _FindDirectory(nodeRef);
|
||||||
|
if (directory != NULL)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
// We don't know this one yet - keep walking the path upwards
|
||||||
|
// and try to find a match.
|
||||||
|
|
||||||
|
BPath parent(path);
|
||||||
|
status = parent.GetParent(&parent);
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
status = _CreateDirectories(parent.Path());
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
// We have our match, create sub directory
|
||||||
|
|
||||||
|
return _AddPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Scan a folder for all valid fonts
|
\brief Scan a folder for all valid fonts
|
||||||
\param directoryPath Path of the folder to scan.
|
\param directoryPath Path of the folder to scan.
|
||||||
|
|||||||
Reference in New Issue
Block a user