2005-06-24 07:31:41 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2005, Haiku.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
2005-11-03 20:03:36 +03:00
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
2005-06-24 07:31:41 +04:00
|
|
|
*/
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
/** Manages font families and styles */
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
#include <FontFamily.h>
|
|
|
|
#include <FontManager.h>
|
|
|
|
#include <ServerConfig.h>
|
|
|
|
#include <ServerFont.h>
|
|
|
|
|
|
|
|
#include <Autolock.h>
|
2003-01-19 00:43:30 +03:00
|
|
|
#include <Directory.h>
|
|
|
|
#include <Entry.h>
|
|
|
|
#include <File.h>
|
2005-11-03 20:03:36 +03:00
|
|
|
#include <FindDirectory.h>
|
2003-01-19 00:43:30 +03:00
|
|
|
#include <Message.h>
|
2005-11-06 21:58:09 +03:00
|
|
|
#include <NodeMonitor.h>
|
2005-11-01 19:28:01 +03:00
|
|
|
#include <Path.h>
|
2003-01-19 00:43:30 +03:00
|
|
|
#include <String.h>
|
|
|
|
|
2005-11-01 20:49:01 +03:00
|
|
|
#include <new>
|
|
|
|
|
2005-11-13 02:27:14 +03:00
|
|
|
using std::nothrow;
|
2005-11-10 17:52:26 +03:00
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
//#define TRACE_FONT_MANAGER
|
|
|
|
#ifdef TRACE_FONT_MANAGER
|
|
|
|
# define FTRACE(x) printf x
|
2005-11-10 17:52:26 +03:00
|
|
|
#else
|
2005-12-19 15:02:17 +03:00
|
|
|
# define FTRACE(x) ;
|
2005-11-10 17:52:26 +03:00
|
|
|
#endif
|
2005-11-06 21:58:09 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
// TODO: needs some more work for multi-user support
|
|
|
|
|
2005-11-02 11:55:51 +03:00
|
|
|
FT_Library gFreeTypeLibrary;
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager *gFontManager = NULL;
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
struct FontManager::font_directory {
|
|
|
|
node_ref directory;
|
|
|
|
uid_t user;
|
|
|
|
gid_t group;
|
|
|
|
uint32 revision;
|
|
|
|
BObjectList<FontStyle> styles;
|
2003-08-02 04:13:30 +04:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
bool AlreadyScanned() const { return revision != 0; }
|
2005-11-10 17:52:26 +03:00
|
|
|
FontStyle* FindStyle(const node_ref& nodeRef) const;
|
2005-11-06 21:58:09 +03:00
|
|
|
};
|
2005-11-01 19:28:01 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
struct FontManager::font_mapping {
|
2005-11-10 17:52:26 +03:00
|
|
|
BString family;
|
|
|
|
BString style;
|
|
|
|
entry_ref ref;
|
2005-11-06 21:58:09 +03:00
|
|
|
};
|
2005-11-01 19:28:01 +03:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
FontStyle*
|
|
|
|
FontManager::font_directory::FindStyle(const node_ref& nodeRef) const
|
|
|
|
{
|
|
|
|
for (int32 i = styles.CountItems(); i-- > 0;) {
|
|
|
|
FontStyle* style = styles.ItemAt(i);
|
|
|
|
|
|
|
|
if (nodeRef == style->NodeRef())
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static status_t
|
|
|
|
set_entry(node_ref& nodeRef, const char* name, BEntry& entry)
|
|
|
|
{
|
|
|
|
entry_ref ref;
|
|
|
|
ref.device = nodeRef.device;
|
|
|
|
ref.directory = nodeRef.node;
|
|
|
|
|
|
|
|
status_t status = ref.set_name(name);
|
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return entry.SetTo(&ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-10 18:33:18 +03:00
|
|
|
static int
|
|
|
|
compare_font_families(const FontFamily* a, const FontFamily* b)
|
|
|
|
{
|
|
|
|
return strcmp(a->Name(), b->Name());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
//! Does basic set up so that directories can be scanned
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager::FontManager()
|
2005-11-03 20:03:36 +03:00
|
|
|
: BLooper("Font Manager"),
|
2005-11-10 17:52:26 +03:00
|
|
|
fDirectories(10, true),
|
|
|
|
fMappings(10, true),
|
2005-06-24 07:31:41 +04:00
|
|
|
fFamilies(20),
|
2005-11-06 21:58:09 +03:00
|
|
|
fScanned(false),
|
2005-11-01 20:49:01 +03:00
|
|
|
fNextID(0)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-02 11:55:51 +03:00
|
|
|
fInitStatus = FT_Init_FreeType(&gFreeTypeLibrary) == 0 ? B_OK : B_ERROR;
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
if (fInitStatus == B_OK) {
|
2005-11-06 21:58:09 +03:00
|
|
|
_AddSystemPaths();
|
|
|
|
_LoadRecentFontMappings();
|
|
|
|
|
2005-11-09 22:16:25 +03:00
|
|
|
fInitStatus = _SetDefaultFonts();
|
2005-11-03 20:03:36 +03:00
|
|
|
}
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
//! Frees items allocated in the constructor and shuts down FreeType
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager::~FontManager()
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-10 20:32:35 +03:00
|
|
|
delete fDefaultPlainFont;
|
|
|
|
delete fDefaultBoldFont;
|
|
|
|
delete fDefaultFixedFont;
|
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
// free families before we're done with FreeType
|
|
|
|
|
|
|
|
for (int32 i = fFamilies.CountItems(); i-- > 0;) {
|
|
|
|
delete fFamilies.ItemAt(i);
|
|
|
|
}
|
|
|
|
|
2005-11-02 11:55:51 +03:00
|
|
|
FT_Done_FreeType(gFreeTypeLibrary);
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
void
|
|
|
|
FontManager::MessageReceived(BMessage* message)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-06 21:58:09 +03:00
|
|
|
switch (message->what) {
|
|
|
|
case B_NODE_MONITOR:
|
2005-11-10 17:52:26 +03:00
|
|
|
{
|
|
|
|
// TODO: support removing fonts!
|
|
|
|
|
|
|
|
int32 opcode;
|
|
|
|
if (message->FindInt32("opcode", &opcode) != B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case B_ENTRY_CREATED:
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
node_ref nodeRef;
|
|
|
|
if (message->FindInt32("device", &nodeRef.device) != B_OK
|
|
|
|
|| message->FindInt64("directory", &nodeRef.node) != B_OK
|
|
|
|
|| message->FindString("name", &name) != B_OK)
|
|
|
|
break;
|
|
|
|
|
2005-11-10 20:32:35 +03:00
|
|
|
// TODO: make this better (possible under Haiku)
|
|
|
|
snooze(100000);
|
|
|
|
// let the font be written completely before trying to open it
|
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
BEntry entry;
|
|
|
|
if (set_entry(nodeRef, name, entry) != B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (entry.IsDirectory()) {
|
|
|
|
// a new directory to watch for us
|
|
|
|
_AddPath(entry);
|
|
|
|
} else {
|
|
|
|
// a new font
|
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
if (directory == NULL) {
|
|
|
|
// unknown directory? how come?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_AddFont(*directory, entry);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-10 20:32:35 +03:00
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
case B_ENTRY_MOVED:
|
|
|
|
{
|
|
|
|
// has the entry been moved into a monitored directory or has
|
|
|
|
// it been removed from one?
|
|
|
|
const char* name;
|
|
|
|
node_ref nodeRef;
|
|
|
|
uint64 fromNode;
|
|
|
|
uint64 node;
|
|
|
|
if (message->FindInt32("device", &nodeRef.device) != B_OK
|
|
|
|
|| message->FindInt64("to directory", &nodeRef.node) != B_OK
|
|
|
|
|| message->FindInt64("from directory", (int64 *)&fromNode) != B_OK
|
|
|
|
|| message->FindInt64("node", (int64 *)&node) != B_OK
|
|
|
|
|| message->FindString("name", &name) != B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
|
|
|
|
BEntry entry;
|
|
|
|
if (set_entry(nodeRef, name, entry) != B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (directory != NULL) {
|
|
|
|
// something has been added to our watched font directories
|
|
|
|
if (entry.IsDirectory()) {
|
|
|
|
// there is a new directory to watch for us
|
|
|
|
_AddPath(entry);
|
|
|
|
} else {
|
|
|
|
// test, if the source directory is one of ours as well
|
|
|
|
nodeRef.node = fromNode;
|
|
|
|
font_directory* fromDirectory = _FindDirectory(nodeRef);
|
|
|
|
if (fromDirectory != NULL) {
|
|
|
|
// find style in source and move it to the target
|
|
|
|
nodeRef.node = node;
|
|
|
|
FontStyle* style = fromDirectory->FindStyle(nodeRef);
|
|
|
|
if (style != NULL) {
|
|
|
|
fromDirectory->styles.RemoveItem(style, false);
|
|
|
|
directory->styles.AddItem(style);
|
|
|
|
}
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("font moved"));
|
2005-11-10 17:52:26 +03:00
|
|
|
} else {
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("font added: %s\n", name));
|
2005-11-10 17:52:26 +03:00
|
|
|
_AddFont(*directory, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// and entry has been removed from our font directories
|
|
|
|
if (entry.IsDirectory()) {
|
|
|
|
if (entry.GetNodeRef(&nodeRef) == B_OK
|
|
|
|
&& (directory = _FindDirectory(nodeRef)) != NULL)
|
|
|
|
_RemoveDirectory(directory);
|
2005-11-10 20:32:35 +03:00
|
|
|
} else {
|
|
|
|
// remove font style from directory
|
|
|
|
_RemoveStyle(nodeRef.device, fromNode, node);
|
|
|
|
}
|
2005-11-10 17:52:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-10 20:32:35 +03:00
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
case B_ENTRY_REMOVED:
|
|
|
|
{
|
|
|
|
node_ref nodeRef;
|
2005-11-10 20:32:35 +03:00
|
|
|
uint64 directoryNode;
|
2005-11-10 17:52:26 +03:00
|
|
|
if (message->FindInt32("device", &nodeRef.device) != B_OK
|
2005-11-10 20:32:35 +03:00
|
|
|
|| message->FindInt64("directory", (int64 *)&directoryNode) != B_OK
|
2005-11-10 17:52:26 +03:00
|
|
|
|| message->FindInt64("node", &nodeRef.node) != B_OK)
|
|
|
|
break;
|
|
|
|
|
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
if (directory != NULL) {
|
|
|
|
// the directory has been removed, so we remove it as well
|
|
|
|
_RemoveDirectory(directory);
|
|
|
|
} else {
|
2005-11-10 20:32:35 +03:00
|
|
|
// remove font style from directory
|
|
|
|
_RemoveStyle(nodeRef.device, directoryNode, nodeRef.node);
|
2005-11-10 17:52:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-06 21:58:09 +03:00
|
|
|
break;
|
2005-11-10 17:52:26 +03:00
|
|
|
}
|
2005-11-06 21:58:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FontManager::SaveRecentFontMappings()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-19 04:01:04 +03:00
|
|
|
void
|
|
|
|
FontManager::_AddDefaultMapping(const char* family, const char* style,
|
|
|
|
const char* path)
|
|
|
|
{
|
2005-12-19 15:02:17 +03:00
|
|
|
font_mapping* mapping = new (std::nothrow) font_mapping;
|
2005-12-19 04:01:04 +03:00
|
|
|
if (mapping == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mapping->family = family;
|
|
|
|
mapping->style = style;
|
|
|
|
BEntry entry(path);
|
|
|
|
|
|
|
|
if (entry.GetRef(&mapping->ref) != B_OK
|
|
|
|
|| !entry.Exists()
|
|
|
|
|| !fMappings.AddItem(mapping))
|
|
|
|
delete mapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
bool
|
|
|
|
FontManager::_LoadRecentFontMappings()
|
|
|
|
{
|
2005-12-19 04:01:04 +03:00
|
|
|
// default known mappings
|
|
|
|
// TODO: load them for real, and use these as a fallback
|
|
|
|
|
|
|
|
_AddDefaultMapping("Bitstream Vera Sans", "Roman",
|
|
|
|
"/boot/beos/etc/fonts/ttfonts/Vera.ttf");
|
|
|
|
_AddDefaultMapping("Bitstream Vera Sans", "Bold",
|
|
|
|
"/boot/beos/etc/fonts/ttfonts/VeraBd.ttf");
|
|
|
|
_AddDefaultMapping("Bitstream Vera Sans Mono", "Roman",
|
|
|
|
"/boot/beos/etc/fonts/ttfonts/VeraMono.ttf");
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
return false;
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-12-19 04:01:04 +03:00
|
|
|
status_t
|
|
|
|
FontManager::_AddMappedFont(const char* familyName, const char* styleName)
|
|
|
|
{
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("_AddMappedFont(family = \"%s\", style = \"%s\")\n",
|
|
|
|
familyName, styleName));
|
|
|
|
|
2005-12-19 04:01:04 +03:00
|
|
|
for (int32 i = 0; i < fMappings.CountItems(); i++) {
|
|
|
|
font_mapping* mapping = fMappings.ItemAt(i);
|
|
|
|
|
|
|
|
if (mapping->family == familyName) {
|
|
|
|
if (styleName != NULL && mapping->style != styleName)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BEntry entry(&mapping->ref);
|
|
|
|
if (entry.InitCheck() != B_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// find parent directory
|
|
|
|
|
|
|
|
node_ref nodeRef;
|
|
|
|
nodeRef.device = mapping->ref.device;
|
|
|
|
nodeRef.node = mapping->ref.directory;
|
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
if (directory == NULL) {
|
2005-12-19 15:02:17 +03:00
|
|
|
// unknown directory, maybe this is a user font - try
|
|
|
|
// to create the missing directory
|
|
|
|
BPath path(&entry);
|
|
|
|
if (path.GetParent(&path) != B_OK
|
|
|
|
|| _CreateDirectories(path.Path()) != B_OK
|
|
|
|
|| (directory = _FindDirectory(nodeRef)) == NULL)
|
|
|
|
continue;
|
2005-12-19 04:01:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return _AddFont(*directory, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
/*!
|
2005-11-10 20:32:35 +03:00
|
|
|
\brief Removes the style from the font directory.
|
|
|
|
|
|
|
|
It doesn't necessary delete the font style, if it's still
|
|
|
|
in use, though.
|
2003-01-20 02:04:58 +03:00
|
|
|
*/
|
2005-11-03 20:03:36 +03:00
|
|
|
void
|
2005-11-10 20:32:35 +03:00
|
|
|
FontManager::_RemoveStyle(font_directory& directory, FontStyle* style)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("font removed: %s\n", style->Name()));
|
2005-11-08 19:49:33 +03:00
|
|
|
|
2005-11-10 20:32:35 +03:00
|
|
|
directory.styles.RemoveItem(style);
|
|
|
|
directory.revision++;
|
2005-11-08 19:49:33 +03:00
|
|
|
|
2005-11-10 20:32:35 +03:00
|
|
|
fStyleHashTable.RemoveItem(*style);
|
|
|
|
|
|
|
|
style->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FontManager::_RemoveStyle(dev_t device, uint64 directoryNode, uint64 node)
|
|
|
|
{
|
|
|
|
// remove font style from directory
|
|
|
|
node_ref nodeRef;
|
|
|
|
nodeRef.device = device;
|
|
|
|
nodeRef.node = directoryNode;
|
|
|
|
|
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
if (directory != NULL) {
|
|
|
|
// find style in directory and remove it
|
|
|
|
nodeRef.node = node;
|
|
|
|
FontStyle* style = directory->FindStyle(nodeRef);
|
|
|
|
if (style != NULL)
|
|
|
|
_RemoveStyle(*directory, style);
|
2005-11-03 20:03:36 +03:00
|
|
|
}
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-09 22:16:25 +03:00
|
|
|
FontStyle*
|
|
|
|
FontManager::_GetDefaultStyle(const char *familyName, const char *styleName,
|
|
|
|
const char *fallbackFamily, const char *fallbackStyle,
|
|
|
|
uint16 fallbackFace)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-09 22:16:25 +03:00
|
|
|
// try to find a matching font
|
|
|
|
|
|
|
|
FontStyle* style = GetStyle(familyName, styleName);
|
2005-11-03 20:03:36 +03:00
|
|
|
if (style == NULL) {
|
2005-11-09 22:16:25 +03:00
|
|
|
style = GetStyle(fallbackFamily, fallbackStyle);
|
2005-11-04 12:49:25 +03:00
|
|
|
if (style == NULL) {
|
2005-11-09 22:16:25 +03:00
|
|
|
style = FindStyleMatchingFace(fallbackFace);
|
|
|
|
if (style == NULL && FamilyAt(0) != NULL)
|
2005-11-04 12:49:25 +03:00
|
|
|
style = FamilyAt(0)->StyleAt(0);
|
|
|
|
}
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
2005-11-03 20:03:36 +03:00
|
|
|
|
2005-11-09 22:16:25 +03:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Sets the fonts that will be used when you create an empty
|
|
|
|
ServerFont without specifying a style, as well as the default
|
|
|
|
Desktop fonts if there are no settings available.
|
|
|
|
*/
|
|
|
|
status_t
|
|
|
|
FontManager::_SetDefaultFonts()
|
|
|
|
{
|
|
|
|
FontStyle* style = _GetDefaultStyle(DEFAULT_PLAIN_FONT_FAMILY,
|
|
|
|
DEFAULT_PLAIN_FONT_STYLE, FALLBACK_PLAIN_FONT_FAMILY,
|
|
|
|
DEFAULT_PLAIN_FONT_STYLE,
|
|
|
|
B_REGULAR_FACE);
|
2005-11-06 21:58:09 +03:00
|
|
|
if (style == NULL)
|
|
|
|
return B_ERROR;
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
fDefaultPlainFont = new (std::nothrow) ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
|
2005-11-09 22:16:25 +03:00
|
|
|
if (fDefaultPlainFont == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
style = _GetDefaultStyle(DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
|
|
|
|
FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, B_BOLD_FACE);
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
fDefaultBoldFont = new (std::nothrow) ServerFont(*style, DEFAULT_BOLD_FONT_SIZE);
|
2005-11-09 22:16:25 +03:00
|
|
|
if (fDefaultBoldFont == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
style = _GetDefaultStyle(DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
|
|
|
|
FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, B_REGULAR_FACE);
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
fDefaultFixedFont = new (std::nothrow) ServerFont(*style, DEFAULT_FIXED_FONT_SIZE);
|
2005-11-09 22:16:25 +03:00
|
|
|
if (fDefaultFixedFont == NULL)
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
2005-11-09 22:16:25 +03:00
|
|
|
fDefaultFixedFont->SetSpacing(B_FIXED_SPACING);
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_OK;
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-08-12 18:55:46 +04:00
|
|
|
void
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::_AddSystemPaths()
|
2005-08-12 18:55:46 +04:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
BPath path;
|
2005-12-19 15:02:17 +03:00
|
|
|
if (find_directory(B_BEOS_FONTS_DIRECTORY, &path, true) == B_OK)
|
2005-11-03 20:03:36 +03:00
|
|
|
_AddPath(path.Path());
|
|
|
|
|
2005-08-12 18:55:46 +04:00
|
|
|
// We don't scan these in test mode to help shave off some startup time
|
|
|
|
#if !TEST_MODE
|
2006-02-27 17:01:48 +03:00
|
|
|
if (find_directory(B_COMMON_FONTS_DIRECTORY, &path, true) == B_OK)
|
2005-11-03 20:03:36 +03:00
|
|
|
_AddPath(path.Path());
|
2005-08-12 18:55:46 +04:00
|
|
|
#endif
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-01 20:49:01 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
void
|
|
|
|
FontManager::_ScanFontsIfNecessary()
|
|
|
|
{
|
|
|
|
if (!fScanned)
|
|
|
|
_ScanFonts();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Scans all currently known font directories
|
|
|
|
void
|
|
|
|
FontManager::_ScanFonts()
|
|
|
|
{
|
|
|
|
if (fScanned)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int32 i = fDirectories.CountItems(); i-- > 0;) {
|
|
|
|
font_directory* directory = fDirectories.ItemAt(i);
|
|
|
|
|
|
|
|
if (directory->AlreadyScanned())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_ScanFontDirectory(*directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
fScanned = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 20:49:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Adds the FontFamily/FontStyle that is represented by this path.
|
|
|
|
*/
|
2005-11-06 21:58:09 +03:00
|
|
|
status_t
|
2005-11-10 17:52:26 +03:00
|
|
|
FontManager::_AddFont(font_directory& directory, BEntry& entry)
|
2005-11-01 20:49:01 +03:00
|
|
|
{
|
2005-11-10 17:52:26 +03:00
|
|
|
node_ref nodeRef;
|
|
|
|
status_t status = entry.GetNodeRef(&nodeRef);
|
|
|
|
if (status < B_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
BPath path;
|
|
|
|
status = entry.GetPath(&path);
|
|
|
|
if (status < B_OK)
|
|
|
|
return status;
|
|
|
|
|
2005-11-01 20:49:01 +03:00
|
|
|
FT_Face face;
|
2005-11-02 11:55:51 +03:00
|
|
|
FT_Error error = FT_New_Face(gFreeTypeLibrary, path.Path(), 0, &face);
|
2005-11-01 20:49:01 +03:00
|
|
|
if (error != 0)
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_ERROR;
|
2005-11-01 20:49:01 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
FontFamily *family = _FindFamily(face->family_name);
|
2005-11-01 20:49:01 +03:00
|
|
|
if (family != NULL && family->HasStyle(face->style_name)) {
|
|
|
|
// prevent adding the same style twice
|
|
|
|
// (this indicates a problem with the installed fonts maybe?)
|
|
|
|
FT_Done_Face(face);
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_OK;
|
2005-11-01 20:49:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (family == NULL) {
|
2005-12-19 15:02:17 +03:00
|
|
|
family = new (std::nothrow) FontFamily(face->family_name, fNextID++);
|
2005-11-01 20:49:01 +03:00
|
|
|
if (family == NULL
|
2005-11-10 18:33:18 +03:00
|
|
|
|| !fFamilies.BinaryInsert(family, compare_font_families)) {
|
2005-11-01 20:49:01 +03:00
|
|
|
delete family;
|
|
|
|
FT_Done_Face(face);
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_NO_MEMORY;
|
2005-11-01 20:49:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("\tadd style: %s, %s\n", face->family_name, face->style_name));
|
2005-11-01 20:49:01 +03:00
|
|
|
|
|
|
|
// the FontStyle takes over ownership of the FT_Face object
|
2005-11-10 17:52:26 +03:00
|
|
|
FontStyle *style = new FontStyle(nodeRef, path.Path(), face);
|
2005-11-01 20:49:01 +03:00
|
|
|
if (!family->AddStyle(style))
|
|
|
|
delete style;
|
2005-11-06 21:58:09 +03:00
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
directory.styles.AddItem(style);
|
2005-11-08 19:49:33 +03:00
|
|
|
fStyleHashTable.AddItem(style);
|
2005-11-10 17:52:26 +03:00
|
|
|
|
|
|
|
if (directory.AlreadyScanned())
|
|
|
|
directory.revision++;
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
return B_OK;
|
2005-11-01 20:49:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
FontManager::font_directory*
|
|
|
|
FontManager::_FindDirectory(node_ref& nodeRef)
|
|
|
|
{
|
|
|
|
for (int32 i = fDirectories.CountItems(); i-- > 0;) {
|
|
|
|
font_directory* directory = fDirectories.ItemAt(i);
|
|
|
|
|
|
|
|
if (directory->directory == nodeRef)
|
|
|
|
return directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FontManager::_RemoveDirectory(font_directory* directory)
|
|
|
|
{
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("FontManager: Remove directory (%Ld)!\n", directory->directory.node));
|
2005-11-10 17:52:26 +03:00
|
|
|
|
|
|
|
fDirectories.RemoveItem(directory, false);
|
|
|
|
|
|
|
|
// TODO: remove styles from this directory!
|
|
|
|
|
|
|
|
watch_node(&directory->directory, B_STOP_WATCHING, this);
|
|
|
|
delete directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
status_t
|
|
|
|
FontManager::_AddPath(const char* path)
|
|
|
|
{
|
|
|
|
BEntry entry;
|
|
|
|
status_t status = entry.SetTo(path);
|
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
return _AddPath(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
|
2005-11-03 20:03:36 +03:00
|
|
|
{
|
2005-11-06 21:58:09 +03:00
|
|
|
node_ref nodeRef;
|
|
|
|
status_t status = entry.GetNodeRef(&nodeRef);
|
2005-11-03 20:03:36 +03:00
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
// check if we are already know this directory
|
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
font_directory* directory = _FindDirectory(nodeRef);
|
|
|
|
if (directory != NULL) {
|
|
|
|
*_newDirectory = directory;
|
|
|
|
return B_OK;
|
2005-11-06 21:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// it's a new one, so let's add it
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
directory = new (std::nothrow) font_directory;
|
2005-11-06 21:58:09 +03:00
|
|
|
if (directory == NULL)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
|
|
|
|
struct stat stat;
|
|
|
|
status = entry.GetStat(&stat);
|
|
|
|
if (status != B_OK) {
|
|
|
|
delete directory;
|
2005-11-03 20:03:36 +03:00
|
|
|
return status;
|
2005-11-06 21:58:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
directory->directory = nodeRef;
|
|
|
|
directory->user = stat.st_uid;
|
|
|
|
directory->group = stat.st_gid;
|
|
|
|
directory->revision = 0;
|
|
|
|
|
|
|
|
status = watch_node(&nodeRef, B_WATCH_DIRECTORY, this);
|
|
|
|
if (status != B_OK) {
|
|
|
|
// we cannot watch this directory - while this is unfortunate,
|
|
|
|
// it's not a critical error
|
|
|
|
printf("could not watch directory %ld:%Ld\n", nodeRef.device, nodeRef.node);
|
|
|
|
// TODO: should go into syslog()
|
2005-11-10 17:52:26 +03:00
|
|
|
} else {
|
|
|
|
BPath path(&entry);
|
2005-12-19 15:02:17 +03:00
|
|
|
FTRACE(("FontManager: now watching: %s\n", path.Path()));
|
2005-11-06 21:58:09 +03:00
|
|
|
}
|
2005-11-03 20:03:36 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
fDirectories.AddItem(directory);
|
|
|
|
|
|
|
|
if (_newDirectory)
|
|
|
|
*_newDirectory = directory;
|
|
|
|
|
|
|
|
fScanned = false;
|
2005-11-03 20:03:36 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-19 15:02:17 +03:00
|
|
|
/*!
|
|
|
|
\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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
/*!
|
|
|
|
\brief Scan a folder for all valid fonts
|
2005-11-01 20:49:01 +03:00
|
|
|
\param directoryPath Path of the folder to scan.
|
2003-01-20 02:04:58 +03:00
|
|
|
*/
|
2005-06-24 07:31:41 +04:00
|
|
|
status_t
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::_ScanFontDirectory(font_directory& fontDirectory)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
|
|
|
// This bad boy does all the real work. It loads each entry in the
|
|
|
|
// directory. If a valid font file, it adds both the family and the style.
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
BDirectory directory;
|
|
|
|
status_t status = directory.SetTo(&fontDirectory.directory);
|
2005-06-24 07:31:41 +04:00
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
BEntry entry;
|
|
|
|
while (directory.GetNextEntry(&entry) == B_OK) {
|
2005-11-03 20:03:36 +03:00
|
|
|
if (entry.IsDirectory()) {
|
|
|
|
// scan this directory recursively
|
2005-11-06 21:58:09 +03:00
|
|
|
font_directory* newDirectory;
|
|
|
|
if (_AddPath(entry, &newDirectory) == B_OK && newDirectory != NULL)
|
|
|
|
_ScanFontDirectory(*newDirectory);
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
continue;
|
|
|
|
}
|
2005-06-03 23:50:30 +04:00
|
|
|
|
|
|
|
// TODO: Commenting this out makes my "Unicode glyph lookup"
|
|
|
|
// work with our default fonts. The real fix is to select the
|
|
|
|
// Unicode char map (if supported), and/or adjust the
|
|
|
|
// utf8 -> glyph-index mapping everywhere to handle other
|
|
|
|
// char maps. We could also ignore fonts that don't support
|
|
|
|
// the Unicode lookup as a temporary "solution".
|
2005-06-24 07:31:41 +04:00
|
|
|
#if 0
|
|
|
|
FT_CharMap charmap = _GetSupportedCharmap(face);
|
|
|
|
if (!charmap) {
|
2003-01-19 00:43:30 +03:00
|
|
|
FT_Done_Face(face);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
face->charmap = charmap;
|
|
|
|
#endif
|
|
|
|
|
2005-11-10 17:52:26 +03:00
|
|
|
_AddFont(fontDirectory, entry);
|
2005-11-01 20:49:01 +03:00
|
|
|
// takes over ownership of the FT_Face object
|
2005-06-24 07:31:41 +04:00
|
|
|
}
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
fontDirectory.revision = 1;
|
2003-01-19 00:43:30 +03:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
/*!
|
|
|
|
\brief Finds and returns the first valid charmap in a font
|
|
|
|
|
|
|
|
\param face Font handle obtained from FT_Load_Face()
|
|
|
|
\return An FT_CharMap or NULL if unsuccessful
|
|
|
|
*/
|
2005-06-24 07:31:41 +04:00
|
|
|
FT_CharMap
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager::_GetSupportedCharmap(const FT_Face& face)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
for (int32 i = 0; i < face->num_charmaps; i++) {
|
|
|
|
FT_CharMap charmap = face->charmaps[i];
|
|
|
|
|
|
|
|
switch (charmap->platform_id) {
|
2003-01-19 00:43:30 +03:00
|
|
|
case 3:
|
|
|
|
// if Windows Symbol or Windows Unicode
|
2005-06-24 07:31:41 +04:00
|
|
|
if (charmap->encoding_id == 0 || charmap->encoding_id == 1)
|
2003-01-19 00:43:30 +03:00
|
|
|
return charmap;
|
|
|
|
break;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-19 00:43:30 +03:00
|
|
|
case 1:
|
|
|
|
// if Apple Unicode
|
2005-06-24 07:31:41 +04:00
|
|
|
if (charmap->encoding_id == 0)
|
2003-01-19 00:43:30 +03:00
|
|
|
return charmap;
|
|
|
|
break;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-19 00:43:30 +03:00
|
|
|
case 0:
|
|
|
|
// if Apple Roman
|
2005-06-24 07:31:41 +04:00
|
|
|
if (charmap->encoding_id == 0)
|
2003-01-19 00:43:30 +03:00
|
|
|
return charmap;
|
|
|
|
break;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-19 00:43:30 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
return NULL;
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-07 19:19:40 +03:00
|
|
|
int32
|
|
|
|
FontManager::CheckRevision(uid_t user)
|
|
|
|
{
|
|
|
|
BAutolock locker(this);
|
|
|
|
int32 revision = 0;
|
|
|
|
|
|
|
|
_ScanFontsIfNecessary();
|
|
|
|
|
|
|
|
for (int32 i = 0; i < fDirectories.CountItems(); i++) {
|
|
|
|
font_directory* directory = fDirectories.ItemAt(i);
|
|
|
|
|
|
|
|
// TODO: for now, add all directories
|
|
|
|
revision += directory->revision;
|
|
|
|
}
|
|
|
|
|
|
|
|
return revision;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
/*!
|
|
|
|
\brief Counts the number of font families available
|
|
|
|
\return The number of unique font families currently available
|
|
|
|
*/
|
|
|
|
int32
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::CountFamilies()
|
2005-11-03 20:03:36 +03:00
|
|
|
{
|
2005-11-06 21:58:09 +03:00
|
|
|
_ScanFontsIfNecessary();
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
return fFamilies.CountItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Counts the number of styles available in a font family
|
|
|
|
\param family Name of the font family to scan
|
|
|
|
\return The number of font styles currently available for the font family
|
|
|
|
*/
|
|
|
|
int32
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::CountStyles(const char *familyName)
|
2005-11-03 20:03:36 +03:00
|
|
|
{
|
2005-11-06 21:58:09 +03:00
|
|
|
_ScanFontsIfNecessary();
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
FontFamily *family = GetFamily(familyName);
|
|
|
|
if (family)
|
|
|
|
return family->CountStyles();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 19:28:01 +03:00
|
|
|
FontFamily*
|
2005-11-03 20:03:36 +03:00
|
|
|
FontManager::FamilyAt(int32 index) const
|
2005-11-01 19:28:01 +03:00
|
|
|
{
|
|
|
|
return fFamilies.ItemAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FontFamily*
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::_FindFamily(const char* name) const
|
2005-11-01 19:28:01 +03:00
|
|
|
{
|
|
|
|
if (name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2005-11-10 18:33:18 +03:00
|
|
|
FontFamily family(name, 0);
|
|
|
|
return const_cast<FontFamily*>(fFamilies.BinarySearch(family,
|
|
|
|
compare_font_families));
|
2005-11-01 19:28:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-06 21:58:09 +03:00
|
|
|
/*!
|
|
|
|
\brief Locates a FontFamily object by name
|
|
|
|
\param name The family to find
|
|
|
|
\return Pointer to the specified family or NULL if not found.
|
|
|
|
*/
|
|
|
|
FontFamily*
|
|
|
|
FontManager::GetFamily(const char* name)
|
|
|
|
{
|
|
|
|
if (name == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
FontFamily* family = _FindFamily(name);
|
|
|
|
if (family != NULL)
|
|
|
|
return family;
|
|
|
|
|
|
|
|
if (fScanned)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// try again
|
|
|
|
family = _FindFamily(name);
|
|
|
|
if (family != NULL)
|
|
|
|
return family;
|
|
|
|
|
|
|
|
// try font mappings before failing
|
2005-12-19 04:01:04 +03:00
|
|
|
if (_AddMappedFont(name) == B_OK)
|
|
|
|
return _FindFamily(name);
|
2005-11-06 21:58:09 +03:00
|
|
|
|
|
|
|
_ScanFonts();
|
|
|
|
return _FindFamily(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-01 19:28:01 +03:00
|
|
|
FontFamily*
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager::GetFamily(uint16 familyID) const
|
2005-11-01 19:28:01 +03:00
|
|
|
{
|
2005-11-08 19:49:33 +03:00
|
|
|
FontKey key(familyID, 0);
|
|
|
|
FontStyle* style = (FontStyle*)fStyleHashTable.GetValue(key);
|
|
|
|
if (style != NULL)
|
|
|
|
return style->Family();
|
2005-11-01 19:28:01 +03:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
FontStyle*
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::GetStyleByIndex(const char* familyName, int32 index)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
FontFamily* family = GetFamily(familyName);
|
2005-11-01 19:28:01 +03:00
|
|
|
if (family != NULL)
|
|
|
|
return family->StyleAt(index);
|
2003-01-19 00:43:30 +03:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-01 19:28:01 +03:00
|
|
|
/*!
|
|
|
|
\brief Retrieves the FontStyle object that comes closest to the one specified
|
|
|
|
|
|
|
|
\param family The font's family or NULL in which case \a familyID is used
|
|
|
|
\param style The font's style or NULL in which case \a styleID is used
|
|
|
|
\param familyID will only be used if \a family is NULL (or empty)
|
|
|
|
\param styleID will only be used if \a style is NULL (or empty)
|
|
|
|
\param face is used to specify the style if both \a style is NULL or empty
|
|
|
|
and styleID is 0xffff.
|
|
|
|
|
|
|
|
\return The FontStyle having those attributes or NULL if not available
|
|
|
|
*/
|
|
|
|
FontStyle*
|
2005-11-02 16:25:39 +03:00
|
|
|
FontManager::GetStyle(const char* familyName, const char* styleName, uint16 familyID,
|
2005-11-01 19:28:01 +03:00
|
|
|
uint16 styleID, uint16 face)
|
|
|
|
{
|
|
|
|
FontFamily* family;
|
|
|
|
|
|
|
|
// find family
|
|
|
|
|
|
|
|
if (familyName != NULL && familyName[0])
|
|
|
|
family = GetFamily(familyName);
|
|
|
|
else
|
|
|
|
family = GetFamily(familyID);
|
|
|
|
|
|
|
|
if (family == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// find style
|
|
|
|
|
2005-12-19 04:01:04 +03:00
|
|
|
if (styleName != NULL && styleName[0]) {
|
|
|
|
FontStyle* fontStyle = family->GetStyle(styleName);
|
|
|
|
if (fontStyle != NULL)
|
|
|
|
return fontStyle;
|
|
|
|
|
|
|
|
// before we fail, we try the mappings for a match
|
|
|
|
if (_AddMappedFont(family->Name(), styleName) == B_OK)
|
|
|
|
return family->GetStyle(styleName);
|
|
|
|
}
|
2005-11-01 19:28:01 +03:00
|
|
|
|
|
|
|
if (styleID != 0xffff)
|
|
|
|
return family->GetStyleByID(styleID);
|
|
|
|
|
|
|
|
// try to get from face
|
|
|
|
return family->GetStyleMatchingFace(face);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-17 05:05:50 +03:00
|
|
|
/*!
|
|
|
|
\brief Retrieves the FontStyle object
|
|
|
|
\param family ID for the font's family
|
|
|
|
\param style ID of the font's style
|
|
|
|
\return The FontStyle having those attributes or NULL if not available
|
|
|
|
*/
|
2005-06-24 07:31:41 +04:00
|
|
|
FontStyle*
|
2005-11-06 21:58:09 +03:00
|
|
|
FontManager::GetStyle(uint16 familyID, uint16 styleID) const
|
2005-01-17 05:05:50 +03:00
|
|
|
{
|
2005-11-08 19:49:33 +03:00
|
|
|
FontKey key(familyID, styleID);
|
|
|
|
return (FontStyle*)fStyleHashTable.GetValue(key);
|
2005-01-17 05:05:50 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2003-01-20 02:04:58 +03:00
|
|
|
/*!
|
2005-11-03 20:03:36 +03:00
|
|
|
\brief If you don't find your preferred font style, but are anxious
|
|
|
|
to have one fitting your needs, you may want to use this method.
|
2003-01-20 02:04:58 +03:00
|
|
|
*/
|
2005-11-03 20:03:36 +03:00
|
|
|
FontStyle*
|
|
|
|
FontManager::FindStyleMatchingFace(uint16 face) const
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
int32 count = fFamilies.CountItems();
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
FontFamily* family = fFamilies.ItemAt(i);
|
|
|
|
FontStyle* style = family->GetStyleMatchingFace(face);
|
|
|
|
if (style != NULL)
|
|
|
|
return style;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
return NULL;
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-10 20:32:35 +03:00
|
|
|
/*!
|
|
|
|
\brief This call is used by the FontStyle class - and the FontStyle class
|
|
|
|
only - to remove itself from the font manager.
|
|
|
|
At this point, the style is already no longer available to the user.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
FontManager::RemoveStyle(FontStyle* style)
|
|
|
|
{
|
|
|
|
FontFamily* family = style->Family();
|
|
|
|
if (family == NULL)
|
|
|
|
debugger("family is NULL!");
|
|
|
|
|
|
|
|
FontStyle* check = GetStyle(family->ID(), style->ID());
|
|
|
|
if (check != NULL)
|
|
|
|
debugger("style removed but still available!");
|
|
|
|
|
|
|
|
if (family->RemoveStyle(style)
|
|
|
|
&& family->CountStyles() == 0)
|
|
|
|
fFamilies.RemoveItem(family);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
const ServerFont*
|
2005-11-09 22:16:25 +03:00
|
|
|
FontManager::DefaultPlainFont() const
|
|
|
|
{
|
|
|
|
return fDefaultPlainFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ServerFont*
|
|
|
|
FontManager::DefaultBoldFont() const
|
|
|
|
{
|
|
|
|
return fDefaultBoldFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ServerFont*
|
|
|
|
FontManager::DefaultFixedFont() const
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-09 22:16:25 +03:00
|
|
|
return fDefaultFixedFont;
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
void
|
|
|
|
FontManager::AttachUser(uid_t userID)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
BAutolock locker(this);
|
2003-01-19 00:43:30 +03:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
/*
|
|
|
|
BPath path;
|
|
|
|
status_t status = find_directory(B_USER_FONTS_DIRECTORY, &path);
|
|
|
|
if (status != B_OK)
|
|
|
|
return status;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
_AddPath(path.Path());
|
2003-01-20 20:31:44 +03:00
|
|
|
*/
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
void
|
|
|
|
FontManager::DetachUser(uid_t userID)
|
2003-01-19 00:43:30 +03:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
BAutolock locker(this);
|
2003-01-19 00:43:30 +03:00
|
|
|
}
|
|
|
|
|