* the FontManager is now a looper (but doesn't do anything useful yet).

* moved the system default font functionality into the DesktopSettings class.
* ServerFont::SetStyle() is now a public method.
* Improved font fallback routines: they will never end up without a font if
  there is at least one font installed.
* fixed some minor bugs in the DecorManager.
* Decorator now get a DesktopSettings object passed - dunno if that's a good
  idea (since we'll have to open the DesktopSettings header), but it works
  for now (and something like this is probably needed anyway).
* a clean ServerFont is now set to the system default font - and not to the
  (user chosen) desktop default font anymore (since the font manager doesn't
  know about that one).
* Improved font directory scanning in the font manager a bit, it's now using
  find_directory() instead of hard-coded paths.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14666 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-03 17:03:36 +00:00
parent c0ebc619bf
commit 05bd1efe5b
20 changed files with 557 additions and 489 deletions
+18 -35
View File
@@ -1,33 +1,15 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2005, Haiku, Inc. * Copyright 2001-2005, Haiku.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * DarkWyrm <[email protected]>
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Stephan Aßmus <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Decorator.h
// Author: DarkWyrm <[email protected]>
// Stephan Aßmus <[email protected]>
// Description: Base class for window decorators
//
//------------------------------------------------------------------------------
#ifndef _DECORATOR_H_ #ifndef _DECORATOR_H_
#define _DECORATOR_H_ #define _DECORATOR_H_
#include <Rect.h> #include <Rect.h>
#include <Region.h> #include <Region.h>
#include <String.h> #include <String.h>
@@ -36,10 +18,12 @@
#include "ColorSet.h" #include "ColorSet.h"
#include "LayerData.h" #include "LayerData.h"
class DesktopSettings;
class DisplayDriver; class DisplayDriver;
class ServerFont; class ServerFont;
class BRegion; class BRegion;
typedef enum { typedef enum {
DEC_NONE = 0, DEC_NONE = 0,
DEC_ZOOM, DEC_ZOOM,
@@ -63,10 +47,8 @@ typedef enum {
class Decorator { class Decorator {
public: public:
Decorator(BRect rect, Decorator(DesktopSettings& settings, BRect rect,
int32 wlook, int32 look, int32 feel, int32 flags);
int32 wfeel,
int32 wflags);
virtual ~Decorator(); virtual ~Decorator();
void SetColors(const ColorSet &cset); void SetColors(const ColorSet &cset);
@@ -145,7 +127,7 @@ class Decorator {
virtual void _DrawFrame(BRect r); virtual void _DrawFrame(BRect r);
virtual void _DrawTab(BRect r); virtual void _DrawTab(BRect r);
virtual void _DrawClose(BRect r); virtual void _DrawClose(BRect r);
virtual void _DrawTitle(BRect r); virtual void _DrawTitle(BRect r);
virtual void _DrawZoom(BRect r); virtual void _DrawZoom(BRect r);
@@ -153,7 +135,7 @@ class Decorator {
virtual void _SetFocus(); virtual void _SetFocus();
virtual void _SetColors(); virtual void _SetColors();
ColorSet* _colors; ColorSet* _colors;
DisplayDriver* _driver; DisplayDriver* _driver;
DrawData _drawdata; DrawData _drawdata;
@@ -182,6 +164,7 @@ class Decorator {
// add-on stuff // add-on stuff
typedef float get_version(void); typedef float get_version(void);
typedef Decorator* create_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags); typedef Decorator* create_decorator(DesktopSettings& desktopSettings, BRect rect,
int32 look, int32 feel, int32 flags);
#endif #endif /* _DECORATOR_H_ */
+26 -20
View File
@@ -10,9 +10,7 @@
#define FONT_MANAGER_H #define FONT_MANAGER_H
#include <Font.h> #include <Looper.h>
#include <Locker.h>
#include <OS.h>
#include <ObjectList.h> #include <ObjectList.h>
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -31,20 +29,19 @@ class ServerFont;
\class FontManager FontManager.h \class FontManager FontManager.h
\brief Manager for the largest part of the font subsystem \brief Manager for the largest part of the font subsystem
*/ */
class FontManager : public BLocker { class FontManager : public BLooper {
public: public:
FontManager(); FontManager();
~FontManager(); virtual ~FontManager();
status_t InitCheck() { return fInitStatus; } status_t InitCheck() { return fInitStatus; }
int32 CountFamilies(); virtual void MessageReceived(BMessage* message);
int32 CountStyles(const char *family);
void RemoveFamily(const char *family); int32 CountFamilies() const;
void ScanSystemFolders(); int32 CountStyles(const char *family) const;
status_t ScanDirectory(const char *path); FontFamily* FamilyAt(int32 index) const;
FontFamily* GetFamilyByIndex(int32 index) const;
FontFamily *GetFamily(uint16 familyID) const; FontFamily *GetFamily(uint16 familyID) const;
FontFamily *GetFamily(const char *name) const; FontFamily *GetFamily(const char *name) const;
@@ -53,14 +50,11 @@ class FontManager : public BLocker {
uint16 styleID = 0xffff, uint16 face = 0); uint16 styleID = 0xffff, uint16 face = 0);
FontStyle *GetStyle(const char *family, uint16 styleID); FontStyle *GetStyle(const char *family, uint16 styleID);
FontStyle *GetStyle(uint16 familyID, uint16 styleID); FontStyle *GetStyle(uint16 familyID, uint16 styleID);
FontStyle* FindStyleMatchingFace(uint16 face) const;
ServerFont *GetSystemPlain(); ServerFont* GetFont(const char *family, const char *style, float size);
ServerFont *GetSystemBold(); ServerFont* GetFont(uint16 face, float size);
ServerFont *GetSystemFixed(); const ServerFont* DefaultFont() const;
bool SetSystemPlain(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 FontsNeedUpdated() { return fNeedUpdate; } bool FontsNeedUpdated() { return fNeedUpdate; }
/*! /*!
@@ -68,15 +62,27 @@ class FontManager : public BLocker {
*/ */
void FontsUpdated() { fNeedUpdate = false; } void FontsUpdated() { fNeedUpdate = false; }
void AttachUser(uid_t userID);
void DetachUser(uid_t userID);
private: private:
void _AddFont(BPath &path); void _SetDefaultFont();
void _ScanSystemFonts();
status_t _AddPath(const char* path);
status_t _AddPath(BEntry& entry);
void _RemoveFamily(const char *family);
status_t _ScanDirectory(BEntry &entry);
void _AddFont(BPath& path);
FT_CharMap _GetSupportedCharmap(const FT_Face &face); FT_CharMap _GetSupportedCharmap(const FT_Face &face);
private: private:
status_t fInitStatus; status_t fInitStatus;
BObjectList<node_ref> fFontDirectories;
BObjectList<FontFamily> fFamilies; BObjectList<FontFamily> fFamilies;
ServerFont *fPlain, *fBold, *fFixed; ServerFont *fDefaultFont;
bool fNeedUpdate; bool fNeedUpdate;
int32 fNextID; int32 fNextID;
}; };
+3 -3
View File
@@ -60,15 +60,15 @@
# define DEFAULT_PLAIN_FONT_FAMILY "Bitstream Vera Sans" # define DEFAULT_PLAIN_FONT_FAMILY "Bitstream Vera Sans"
# define FALLBACK_PLAIN_FONT_FAMILY "Swis721 BT" # define FALLBACK_PLAIN_FONT_FAMILY "Swis721 BT"
# define DEFAULT_PLAIN_FONT_STYLE "Roman" # define DEFAULT_PLAIN_FONT_STYLE "Roman"
# define DEFAULT_PLAIN_FONT_SIZE 12 # define DEFAULT_PLAIN_FONT_SIZE 12.0f
# define DEFAULT_BOLD_FONT_FAMILY "Bitstream Vera Sans" # define DEFAULT_BOLD_FONT_FAMILY "Bitstream Vera Sans"
# define FALLBACK_BOLD_FONT_FAMILY "Swis721 BT" # define FALLBACK_BOLD_FONT_FAMILY "Swis721 BT"
# define DEFAULT_BOLD_FONT_STYLE "Bold" # define DEFAULT_BOLD_FONT_STYLE "Bold"
# define DEFAULT_BOLD_FONT_SIZE 12 # define DEFAULT_BOLD_FONT_SIZE 12.0f
# define DEFAULT_FIXED_FONT_FAMILY "Bitstream Vera Sans Mono" # define DEFAULT_FIXED_FONT_FAMILY "Bitstream Vera Sans Mono"
# define FALLBACK_FIXED_FONT_FAMILY "Courier10 BT" # define FALLBACK_FIXED_FONT_FAMILY "Courier10 BT"
# define DEFAULT_FIXED_FONT_STYLE "Roman" # define DEFAULT_FIXED_FONT_STYLE "Roman"
# define DEFAULT_FIXED_FONT_SIZE 12 # define DEFAULT_FIXED_FONT_SIZE 12.0f
// This is the port capacity for all monitoring objects - ServerApps // This is the port capacity for all monitoring objects - ServerApps
// and ServerWindows // and ServerWindows
#define DEFAULT_MONITOR_PORT_SIZE 30 #define DEFAULT_MONITOR_PORT_SIZE 30
+6 -7
View File
@@ -5,9 +5,10 @@
* 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]
*/ */
#ifndef SERVERFONT_H_ #ifndef SERVER_FONT_H
#define SERVERFONT_H_ #define SERVER_FONT_H
#include <Font.h> #include <Font.h>
@@ -62,7 +63,8 @@ class ServerFont {
const char* GetFamily() const; const char* GetFamily() const;
const char* GetPath() const const char* GetPath() const
{ return fStyle->Path(); } { return fStyle->Path(); }
void SetStyle(FontStyle& style);
status_t SetFamilyAndStyle(uint16 familyID, status_t SetFamilyAndStyle(uint16 familyID,
uint16 styleID); uint16 styleID);
status_t SetFamilyAndStyle(uint32 fontID); status_t SetFamilyAndStyle(uint32 fontID);
@@ -151,8 +153,6 @@ class ServerFont {
protected: protected:
friend class FontStyle; friend class FontStyle;
void _SetStyle(FontStyle* style);
FontStyle* fStyle; FontStyle* fStyle;
edge_info fEdges; edge_info fEdges;
@@ -167,5 +167,4 @@ protected:
uint32 fEncoding; uint32 fEncoding;
}; };
#endif #endif /* SERVER_FONT_H */
+3 -42
View File
@@ -100,49 +100,10 @@ AppServer::AppServer()
// Create the font server and scan the proper directories. // Create the font server and scan the proper directories.
gFontManager = new FontManager; gFontManager = new FontManager;
gFontManager->Lock(); if (gFontManager->InitCheck() != B_OK)
gFontManager->ScanSystemFolders(); debugger("font manager could not be initialized!");
if (!gFontManager->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY, gFontManager->Run();
DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE) &&
!gFontManager->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE)) {
printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n",
DEFAULT_PLAIN_FONT_FAMILY,
FALLBACK_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE);
}
if (!gFontManager->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY,
DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE) &&
!gFontManager->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY,
DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE)) {
printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n",
DEFAULT_BOLD_FONT_FAMILY,
FALLBACK_BOLD_FONT_FAMILY,
DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE);
}
if (!gFontManager->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY,
DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE) &&
!gFontManager->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY,
DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE)) {
printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n",
DEFAULT_FIXED_FONT_FAMILY,
FALLBACK_FIXED_FONT_FAMILY,
DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE);
}
gFontManager->Unlock();
// Load the GUI colors here and set the global set to the values contained therein. If this // Load the GUI colors here and set the global set to the values contained therein. If this
// is not possible, set colors to the defaults // is not possible, set colors to the defaults
+78 -77
View File
@@ -7,14 +7,17 @@
#include <Directory.h> #include <Directory.h>
#include <Rect.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <Message.h> #include <Message.h>
#include <Entry.h> #include <Path.h>
#include <Rect.h>
#include "AppServer.h" #include "AppServer.h"
#include "ColorSet.h" #include "ColorSet.h"
#include "DefaultDecorator.h" #include "DefaultDecorator.h"
#include "Desktop.h"
#include "DesktopSettings.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "DecorManager.h" #include "DecorManager.h"
@@ -23,37 +26,38 @@
DecorManager gDecorManager; DecorManager gDecorManager;
Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel,
int32 wflags);
// This is a class used only by the DecorManager to track all the decorators in memory // This is a class used only by the DecorManager to track all the decorators in memory
class DecorInfo { class DecorInfo {
public: public:
DecorInfo(const image_id &id, const char *name, DecorInfo(image_id id, const char* name,
create_decorator *alloc); create_decorator* allocator = NULL);
~DecorInfo(void); ~DecorInfo();
image_id GetID(void) const { return fID; }
const char* GetName(void) const { return fName.String(); } status_t InitCheck() const;
Decorator* Instantiate(BRect rect, const char *title,
int32 wlook, int32 wfeel, image_id ID() const { return fID; }
int32 wflags, DisplayDriver *ddriver); const char* Name() const { return fName.String(); }
private:
image_id fID; Decorator* Instantiate(Desktop* desktop, BRect rect, const char* title,
BString fName; int32 look, int32 feel, int32 flags);
create_decorator *fAllocator;
private:
image_id fID;
BString fName;
create_decorator *fAllocator;
}; };
DecorInfo::DecorInfo(const image_id &id, const char *name, create_decorator *alloc) DecorInfo::DecorInfo(image_id id, const char* name, create_decorator* allocator)
: :
fID(id), fID(id),
fName(name), fName(name),
fAllocator(alloc) fAllocator(allocator)
{ {
} }
DecorInfo::~DecorInfo(void) DecorInfo::~DecorInfo()
{ {
// Do nothing. Normal programming practice would say that one should unload // Do nothing. Normal programming practice would say that one should unload
// the object's associate image_id. However, there is some funkiness with // the object's associate image_id. However, there is some funkiness with
@@ -68,20 +72,30 @@ DecorInfo::~DecorInfo(void)
Decorator * Decorator *
DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel, DecorInfo::Instantiate(Desktop* desktop, BRect rect, const char *title,
int32 wflags, DisplayDriver *ddriver) int32 look, int32 feel, int32 flags)
{ {
Decorator *dec = fAllocator(rect, wlook, wfeel, wflags); DesktopSettings settings(desktop);
Decorator *decorator;
dec->SetDriver(ddriver);
try {
if (fAllocator != NULL)
decorator = fAllocator(settings, rect, look, feel, flags);
else
decorator = new DefaultDecorator(settings, rect, look, feel, flags);
} catch (...) {
return NULL;
}
decorator->SetDriver(desktop->GetDisplayDriver());
gGUIColorSet.Lock(); gGUIColorSet.Lock();
dec->SetColors(gGUIColorSet); decorator->SetColors(gGUIColorSet);
gGUIColorSet.Unlock(); gGUIColorSet.Unlock();
dec->SetTitle(title); decorator->SetTitle(title);
return dec; return decorator;
} }
@@ -94,9 +108,9 @@ DecorManager::DecorManager()
fCurrentDecor(NULL) fCurrentDecor(NULL)
{ {
// Start with the default decorator - index is always 0 // Start with the default decorator - index is always 0
DecorInfo *defaultDecor = new DecorInfo(-1, "Default", create_default_decorator); DecorInfo *defaultDecor = new DecorInfo(-1, "Default", NULL);
fDecorList.AddItem( defaultDecor ); fDecorList.AddItem(defaultDecor);
// Add any on disk // Add any on disk
RescanDecorators(); RescanDecorators();
@@ -112,18 +126,18 @@ DecorManager::DecorManager()
if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) { if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) {
BString itemtext; BString itemtext;
if (settings.FindString("decorator", &itemtext) == B_OK) { if (settings.FindString("decorator", &itemtext) == B_OK) {
fCurrentDecor = FindDecor(itemtext.String()); fCurrentDecor = _FindDecor(itemtext.String());
} }
} }
if (!fCurrentDecor) if (!fCurrentDecor)
fCurrentDecor = (DecorInfo*) fDecorList.ItemAt(0L); fCurrentDecor = (DecorInfo*)fDecorList.ItemAt(0L);
} }
DecorManager::~DecorManager() DecorManager::~DecorManager()
{ {
EmptyList(); _EmptyList();
} }
@@ -136,11 +150,10 @@ DecorManager::RescanDecorators()
return; return;
entry_ref ref; entry_ref ref;
BString fullpath;
while (dir.GetNextRef(&ref) == B_OK) { while (dir.GetNextRef(&ref) == B_OK) {
fullpath = DECORATORS_DIR; BPath path;
fullpath += ref.name; path.SetTo(DECORATORS_DIR);
path.Append(ref.name);
// Because this function is used for both initialization and for keeping // Because this function is used for both initialization and for keeping
// the list up to date, check for existence in the list. Note that we // the list up to date, check for existence in the list. Note that we
@@ -149,11 +162,11 @@ DecorManager::RescanDecorators()
// been deleted, it is still available until the next boot, at which point // been deleted, it is still available until the next boot, at which point
// it will obviously not be loaded. // it will obviously not be loaded.
if (FindDecor(ref.name)) if (_FindDecor(ref.name))
continue; continue;
image_id tempID = load_add_on(fullpath.String()); image_id image = load_add_on(path.Path());
if (tempID == B_ERROR) if (image != B_OK)
continue; continue;
// As of now, we do nothing with decorator versions, but the possibility // As of now, we do nothing with decorator versions, but the possibility
@@ -161,25 +174,25 @@ DecorManager::RescanDecorators()
// to do so. If we *did* do anything with decorator versions, the // to do so. If we *did* do anything with decorator versions, the
// assignment would go here. // assignment would go here.
create_decorator *createfunc; create_decorator* createFunc;
// Get the instantiation function // Get the instantiation function
status_t status = get_image_symbol(tempID, "instantiate_decorator", status_t status = get_image_symbol(image, "instantiate_decorator",
B_SYMBOL_TYPE_TEXT, (void**)&createfunc); B_SYMBOL_TYPE_TEXT, (void**)&createFunc);
if (status != B_OK) { if (status != B_OK) {
unload_add_on(tempID); unload_add_on(image);
continue; continue;
} }
fDecorList.AddItem(new DecorInfo(tempID, ref.name, createfunc)); // TODO: unload images until they are actually used!
fDecorList.AddItem(new DecorInfo(image, ref.name, createFunc));
} }
} }
Decorator * Decorator *
DecorManager::AllocateDecorator(BRect rect, const char *title, DecorManager::AllocateDecorator(Desktop* desktop, BRect rect, const char *title,
int32 wlook, int32 wfeel, int32 look, int32 feel, int32 flags)
int32 wflags, DisplayDriver *ddriver)
{ {
// Create a new instance of the current decorator. Ownership is that of the caller // Create a new instance of the current decorator. Ownership is that of the caller
@@ -189,26 +202,26 @@ DecorManager::AllocateDecorator(BRect rect, const char *title,
return NULL; return NULL;
} }
return fCurrentDecor->Instantiate(rect, title, wlook, wfeel, wflags, ddriver); return fCurrentDecor->Instantiate(desktop, rect, title, look, feel, flags);
} }
int32 int32
DecorManager::CountDecorators(void) const DecorManager::CountDecorators() const
{ {
return fDecorList.CountItems(); return fDecorList.CountItems();
} }
int32 int32
DecorManager::GetDecorator(void) const DecorManager::GetDecorator() const
{ {
return fDecorList.IndexOf(fCurrentDecor); return fDecorList.IndexOf(fCurrentDecor);
} }
bool bool
DecorManager::SetDecorator(const int32 &index) DecorManager::SetDecorator(int32 index)
{ {
DecorInfo *newDecInfo = (DecorInfo*)fDecorList.ItemAt(index); DecorInfo *newDecInfo = (DecorInfo*)fDecorList.ItemAt(index);
@@ -222,7 +235,7 @@ DecorManager::SetDecorator(const int32 &index)
bool bool
DecorManager::SetR5Decorator(const int32 &value) DecorManager::SetR5Decorator(int32 value)
{ {
BString string; BString string;
@@ -235,7 +248,7 @@ DecorManager::SetR5Decorator(const int32 &value)
return false; return false;
} }
DecorInfo *newDecInfo = FindDecor(string.String()); DecorInfo *newDecInfo = _FindDecor(string.String());
if (newDecInfo) { if (newDecInfo) {
fCurrentDecor = newDecInfo; fCurrentDecor = newDecInfo;
return true; return true;
@@ -246,53 +259,41 @@ DecorManager::SetR5Decorator(const int32 &value)
const char * const char *
DecorManager::GetDecoratorName(const int32 &index) DecorManager::GetDecoratorName(int32 index)
{ {
DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(index); DecorInfo *info = fDecorList.ItemAt(index);
if (info) if (info)
return info->GetName(); return info->Name();
return NULL; return NULL;
} }
void void
DecorManager::EmptyList(void) DecorManager::_EmptyList()
{ {
for (int32 i = 0; i < fDecorList.CountItems(); i++) { for (int32 i = 0; i < fDecorList.CountItems(); i++) {
DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i); delete fDecorList.ItemAt(i);;
delete info;
} }
fDecorList.MakeEmpty();
fCurrentDecor = NULL; fCurrentDecor = NULL;
} }
DecorInfo* DecorInfo*
DecorManager::FindDecor(const char *name) DecorManager::_FindDecor(const char *name)
{ {
if (!name) if (!name)
return NULL; return NULL;
for (int32 i = 0; i < fDecorList.CountItems(); i++) { for (int32 i = 0; i < fDecorList.CountItems(); i++) {
DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i); DecorInfo* info = fDecorList.ItemAt(i);
if (info && strcmp(name, info->GetName()) == 0) if (strcmp(name, info->Name()) == 0)
return info; return info;
} }
return NULL; return NULL;
} }
// #pragma mark -
// This is the allocator function for the default decorator
Decorator*
create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags)
{
return new DefaultDecorator(rect, wlook, wfeel, wflags);
}
+35 -33
View File
@@ -4,50 +4,52 @@
* *
* Author: DarkWyrm <[email protected]> * Author: DarkWyrm <[email protected]>
*/ */
#ifndef DECORMANAGER_H #ifndef DECOR_MANAGER_H
#define DECORMANAGER_H #define DECOR_MANAGER_H
#include <image.h> #include <image.h>
#include <String.h> #include <String.h>
#include <Locker.h> #include <Locker.h>
#include <List.h> #include <ObjectList.h>
#include "Decorator.h" #include "Decorator.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
class DecorInfo; class DecorInfo;
class Desktop;
class DecorManager : public BLocker
{ class DecorManager : public BLocker {
public: public:
DecorManager(void); DecorManager();
~DecorManager(void); ~DecorManager();
void RescanDecorators(void); void RescanDecorators();
Decorator * AllocateDecorator(BRect rect, const char *title, Decorator* AllocateDecorator(Desktop* desktop, BRect rect,
int32 wlook, int32 wfeel, const char *title, int32 look, int32 feel,
int32 wflags, DisplayDriver *ddriver); int32 flags);
int32 CountDecorators(void) const; int32 CountDecorators() const;
int32 GetDecorator(void) const; int32 GetDecorator() const;
bool SetDecorator(const int32 &index); bool SetDecorator(int32 index);
bool SetR5Decorator(const int32 &value); bool SetR5Decorator(int32 value);
const char * GetDecoratorName(const int32 &index); const char* GetDecoratorName(int32 index);
// TODO: Implement this method once the rest of the necessary infrastructure // TODO: Implement this method once the rest of the necessary infrastructure
// is in place // is in place
// status_t GetPreview(const int32 &index, ServerBitmap *bitmap); //status_t GetPreview(int32 index, ServerBitmap *bitmap);
private: private:
void EmptyList(void); void _EmptyList();
DecorInfo* FindDecor(const char *name); DecorInfo* _FindDecor(const char *name);
BList fDecorList; BObjectList<DecorInfo> fDecorList;
DecorInfo* fCurrentDecor; DecorInfo* fCurrentDecor;
}; };
extern DecorManager gDecorManager; extern DecorManager gDecorManager;
#endif #endif /* DECOR_MANAGER_H */
+20 -32
View File
@@ -1,36 +1,23 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2005, Haiku, Inc. * Copyright 2001-2005, Haiku.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * DarkWyrm <[email protected]>
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Stephan Aßmus <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions:
// /** Base class for window decorators */
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Decorator.cpp
// Author: DarkWyrm <[email protected]>
// Stephan Aßmus <[email protected]>
// Description: Base class for window decorators
//
//------------------------------------------------------------------------------
#include <Region.h>
#include "ColorSet.h" #include "ColorSet.h"
#include "Decorator.h" #include "Decorator.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
#include <Region.h>
#include <stdio.h> #include <stdio.h>
/*! /*!
\brief Constructor \brief Constructor
\param rect Size of client area \param rect Size of client area
@@ -41,14 +28,15 @@
Does general initialization of internal data members and creates a colorset Does general initialization of internal data members and creates a colorset
object. object.
*/ */
Decorator::Decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) Decorator::Decorator(DesktopSettings& settings, BRect rect, int32 look,
int32 feel, int32 flags)
: _colors(new ColorSet()), : _colors(new ColorSet()),
_driver(NULL), _driver(NULL),
_drawdata(), _drawdata(),
_look(wlook), _look(look),
_feel(wfeel), _feel(feel),
_flags(wflags), _flags(flags),
_zoomrect(), _zoomrect(),
_closerect(), _closerect(),
+17 -10
View File
@@ -4,24 +4,26 @@
* *
* Authors: * Authors:
* DarkWyrm <[email protected]> * DarkWyrm <[email protected]>
* Stephan Aßmus <[email protected]>
*/ */
/** Default and fallback decorator for the app_server - the yellow tabs */ /** Default and fallback decorator for the app_server - the yellow tabs */
#include <stdio.h> #include "DefaultDecorator.h"
#include <Rect.h>
#include <View.h>
#include "ColorUtils.h" #include "ColorUtils.h"
#include "DesktopSettings.h"
#include "DisplayDriver.h" #include "DisplayDriver.h"
#include "FontManager.h" #include "FontManager.h"
#include "LayerData.h" #include "LayerData.h"
#include "PatternHandler.h" #include "PatternHandler.h"
#include "RGBColor.h" #include "RGBColor.h"
#include "DefaultDecorator.h" #include <Rect.h>
#include <View.h>
#include <stdio.h>
//#define USE_VIEW_FILL_HACK //#define USE_VIEW_FILL_HACK
@@ -33,12 +35,17 @@
# define STRACE(x) ; # define STRACE(x) ;
#endif #endif
DefaultDecorator::DefaultDecorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags)
: Decorator(rect, wlook, wfeel, wflags), DefaultDecorator::DefaultDecorator(DesktopSettings& settings, BRect rect,
fTruncatedTitle("") int32 look, int32 feel, int32 flags)
: Decorator(settings, rect, look, feel, flags)
{ {
ServerFont font(_look == B_FLOATING_WINDOW_LOOK ? ServerFont font;
*gFontManager->GetSystemPlain() : *gFontManager->GetSystemBold()); if (_look == B_FLOATING_WINDOW_LOOK)
settings.GetDefaultPlainFont(font);
else
settings.GetDefaultBoldFont(font);
font.SetFlags(B_FORCE_ANTIALIASING); font.SetFlags(B_FORCE_ANTIALIASING);
font.SetSpacing(B_STRING_SPACING); font.SetSpacing(B_STRING_SPACING);
SetFont(&font); SetFont(&font);
+18 -34
View File
@@ -1,43 +1,27 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, Haiku, Inc. * Copyright 2001-2005, Haiku.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * DarkWyrm <[email protected]>
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Stephan Aßmus <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the */
// Software is furnished to do so, subject to the following conditions: #ifndef DEFAULT_DECORATOR_H
// #define DEFAULT_DECORATOR_H
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: DefaultDecorator.h
// Author: DarkWyrm <[email protected]>
// Description: Fallback decorator for the app_server
//
//------------------------------------------------------------------------------
#ifndef _DEFAULT_DECORATOR_H_
#define _DEFAULT_DECORATOR_H_
#include "Decorator.h" #include "Decorator.h"
#include <Region.h> #include <Region.h>
class Desktop;
class DefaultDecorator: public Decorator { class DefaultDecorator: public Decorator {
public: public:
DefaultDecorator(BRect frame, DefaultDecorator(DesktopSettings& settings, BRect frame,
int32 look, int32 look, int32 feel, int32 flags);
int32 feel,
int32 flags);
virtual ~DefaultDecorator(); virtual ~DefaultDecorator();
virtual void MoveBy(float x, float y); virtual void MoveBy(float x, float y);
virtual void MoveBy(BPoint pt); virtual void MoveBy(BPoint pt);
virtual void ResizeBy(float x, float y); virtual void ResizeBy(float x, float y);
@@ -98,4 +82,4 @@ private:
int32 fTruncatedTitleLength; int32 fTruncatedTitleLength;
}; };
#endif #endif /* DEFAULT_DECORATOR_H */
+2
View File
@@ -75,6 +75,7 @@ Desktop::Desktop(uid_t userID)
return; return;
fLink.SetReceiverPort(fMessagePort); fLink.SetReceiverPort(fMessagePort);
gFontManager->AttachUser(fUserID);
} }
@@ -87,6 +88,7 @@ Desktop::~Desktop()
delete fSettings; delete fSettings;
delete_port(fMessagePort); delete_port(fMessagePort);
gFontManager->DetachUser(fUserID);
} }
+119
View File
@@ -11,6 +11,8 @@
#include "DesktopSettings.h" #include "DesktopSettings.h"
#include "DesktopSettingsPrivate.h" #include "DesktopSettingsPrivate.h"
#include "Desktop.h" #include "Desktop.h"
#include "FontManager.h"
#include "ServerConfig.h"
DesktopSettings::Private::Private() DesktopSettings::Private::Private()
@@ -30,6 +32,17 @@ DesktopSettings::Private::~Private()
void void
DesktopSettings::Private::_SetDefaults() DesktopSettings::Private::_SetDefaults()
{ {
_SetFont(fPlainFont, DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE, FALLBACK_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE,
B_REGULAR_FACE);
_SetFont(fBoldFont, DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE, FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE,
B_BOLD_FACE);
_SetFont(fFixedFont, DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE, FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE,
B_REGULAR_FACE);
fFixedFont.SetSpacing(B_FIXED_SPACING);
fMouseMode = B_NORMAL_MOUSE; fMouseMode = B_NORMAL_MOUSE;
// init scrollbar info // init scrollbar info
@@ -54,6 +67,28 @@ DesktopSettings::Private::_SetDefaults()
} }
void
DesktopSettings::Private::_SetFont(ServerFont &font, const char *familyName,
const char *styleName, float size, const char *fallbackFamily,
const char *fallbackStyle, uint16 fallbackFace)
{
BAutolock locker(gFontManager);
// try to find a matching font
FontStyle* style = gFontManager->GetStyle(familyName, styleName);
if (style == NULL) {
style = gFontManager->GetStyle(fallbackFamily, fallbackStyle);
if (style == NULL) {
style = gFontManager->FindStyleMatchingFace(fallbackFace);
}
}
if (style != NULL)
font.SetStyle(*style);
}
status_t status_t
DesktopSettings::Private::_Load() DesktopSettings::Private::_Load()
{ {
@@ -69,6 +104,48 @@ DesktopSettings::Private::Save()
} }
void
DesktopSettings::Private::SetDefaultPlainFont(const ServerFont &font)
{
fPlainFont = font;
}
const ServerFont &
DesktopSettings::Private::DefaultPlainFont() const
{
return fPlainFont;
}
void
DesktopSettings::Private::SetDefaultBoldFont(const ServerFont &font)
{
fBoldFont = font;
}
const ServerFont &
DesktopSettings::Private::DefaultBoldFont() const
{
return fBoldFont;
}
void
DesktopSettings::Private::SetDefaultFixedFont(const ServerFont &font)
{
fFixedFont = font;
}
const ServerFont &
DesktopSettings::Private::DefaultFixedFont() const
{
return fFixedFont;
}
void void
DesktopSettings::Private::SetScrollBarInfo(const scroll_bar_info& info) DesktopSettings::Private::SetScrollBarInfo(const scroll_bar_info& info)
{ {
@@ -174,6 +251,48 @@ DesktopSettings::~DesktopSettings()
} }
void
DesktopSettings::SetDefaultPlainFont(const ServerFont &font)
{
fSettings->SetDefaultPlainFont(font);
}
void
DesktopSettings::GetDefaultPlainFont(ServerFont &font) const
{
font = fSettings->DefaultPlainFont();
}
void
DesktopSettings::SetDefaultBoldFont(const ServerFont &font)
{
fSettings->SetDefaultBoldFont(font);
}
void
DesktopSettings::GetDefaultBoldFont(ServerFont &font) const
{
font = fSettings->DefaultBoldFont();
}
void
DesktopSettings::SetDefaultFixedFont(const ServerFont &font)
{
fSettings->SetDefaultFixedFont(font);
}
void
DesktopSettings::GetDefaultFixedFont(ServerFont &font) const
{
font = fSettings->DefaultFixedFont();
}
void void
DesktopSettings::SetScrollBarInfo(const scroll_bar_info& info) DesktopSettings::SetScrollBarInfo(const scroll_bar_info& info)
{ {
+10
View File
@@ -14,6 +14,7 @@
#include <Message.h> #include <Message.h>
class Desktop; class Desktop;
class ServerFont;
static const int32 kMaxWorkspaces = 32; static const int32 kMaxWorkspaces = 32;
@@ -26,6 +27,15 @@ class DesktopSettings {
status_t Save(); status_t Save();
void SetDefaultPlainFont(const ServerFont& font);
void GetDefaultPlainFont(ServerFont& font) const;
void SetDefaultBoldFont(const ServerFont& font);
void GetDefaultBoldFont(ServerFont& font) const;
void SetDefaultFixedFont(const ServerFont& font);
void GetDefaultFixedFont(ServerFont& font) const;
void SetScrollBarInfo(const scroll_bar_info& info); void SetScrollBarInfo(const scroll_bar_info& info);
void GetScrollBarInfo(scroll_bar_info& info) const; void GetScrollBarInfo(scroll_bar_info& info) const;
+17
View File
@@ -10,6 +10,7 @@
#include "DesktopSettings.h" #include "DesktopSettings.h"
#include "ServerFont.h"
#include <Locker.h> #include <Locker.h>
@@ -21,6 +22,15 @@ class DesktopSettings::Private : public BLocker {
status_t Save(); status_t Save();
void SetDefaultPlainFont(const ServerFont& font);
const ServerFont& DefaultPlainFont() const;
void SetDefaultBoldFont(const ServerFont& font);
const ServerFont& DefaultBoldFont() const;
void SetDefaultFixedFont(const ServerFont& font);
const ServerFont& DefaultFixedFont() const;
void SetScrollBarInfo(const scroll_bar_info &info); void SetScrollBarInfo(const scroll_bar_info &info);
const scroll_bar_info& ScrollBarInfo() const; const scroll_bar_info& ScrollBarInfo() const;
@@ -39,8 +49,15 @@ class DesktopSettings::Private : public BLocker {
private: private:
void _SetDefaults(); void _SetDefaults();
void _SetFont(ServerFont& font, const char* family, const char* style,
float size, const char *fallbackFamily,
const char* fallbackStyle, uint16 fallbackFace);
status_t _Load(); status_t _Load();
ServerFont fPlainFont;
ServerFont fBoldFont;
ServerFont fFixedFont;
scroll_bar_info fScrollBarInfo; scroll_bar_info fScrollBarInfo;
menu_info fMenuInfo; menu_info fMenuInfo;
mode_mouse fMouseMode; mode_mouse fMouseMode;
+145 -131
View File
@@ -4,23 +4,26 @@
* *
* Authors: * Authors:
* DarkWyrm <bpmagic@columbus.rr.com> * DarkWyrm <bpmagic@columbus.rr.com>
* Axel Dörfler, axeld@pinc-software.de
*/ */
/** Handles the largest part of the font subsystem */ /** Manages font families and styles */
#include <FontFamily.h>
#include <FontManager.h>
#include <ServerConfig.h>
#include <ServerFont.h>
#include <Autolock.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h>
#include <Message.h> #include <Message.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <FontManager.h>
#include <FontFamily.h>
#include <ServerFont.h>
#include "ServerConfig.h"
#include <new> #include <new>
@@ -50,15 +53,22 @@ face_requester(FTC_FaceID face_id, FT_Library library,
//! Does basic set up so that directories can be scanned //! Does basic set up so that directories can be scanned
FontManager::FontManager() FontManager::FontManager()
: BLocker("font server lock"), : BLooper("Font Manager"),
fFamilies(20), fFamilies(20),
fPlain(NULL), fDefaultFont(NULL),
fBold(NULL),
fFixed(NULL),
fNextID(0) fNextID(0)
{ {
fInitStatus = FT_Init_FreeType(&gFreeTypeLibrary) == 0 ? B_OK : B_ERROR; fInitStatus = FT_Init_FreeType(&gFreeTypeLibrary) == 0 ? B_OK : B_ERROR;
if (fInitStatus == B_OK) {
_ScanSystemFonts();
if (CountFamilies() != 0)
_SetDefaultFont();
else
fInitStatus = B_ENTRY_NOT_FOUND;
}
/* /*
Fire up the font caching subsystem. Fire up the font caching subsystem.
The three zeros tell FreeType to use the defaults, which are 2 faces, The three zeros tell FreeType to use the defaults, which are 2 faces,
@@ -79,30 +89,10 @@ FontManager::~FontManager()
} }
/*! void
\brief Counts the number of font families available FontManager::MessageReceived(BMessage* message)
\return The number of unique font families currently available
*/
int32
FontManager::CountFamilies(void)
{ {
return fFamilies.CountItems(); // nothing to do here yet
}
/*!
\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
FontManager::CountStyles(const char *familyName)
{
FontFamily *family = GetFamily(familyName);
if (family)
return family->CountStyles();
return 0;
} }
@@ -111,7 +101,7 @@ FontManager::CountStyles(const char *familyName)
\param family The family to remove \param family The family to remove
*/ */
void void
FontManager::RemoveFamily(const char *familyName) FontManager::_RemoveFamily(const char *familyName)
{ {
FontFamily *family = GetFamily(familyName); FontFamily *family = GetFamily(familyName);
if (family) { if (family) {
@@ -121,17 +111,36 @@ FontManager::RemoveFamily(const char *familyName)
} }
/*!
\brief Sets the font that will be used when you create an empty
ServerFont without specifying a style.
*/
void
FontManager::_SetDefaultFont()
{
FontStyle* style = GetStyle(DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE);
if (style == NULL) {
style = FindStyleMatchingFace(B_REGULAR_FACE);
if (style == NULL)
style = FamilyAt(0)->StyleAt(0);
}
fDefaultFont = new ServerFont(*style, DEFAULT_PLAIN_FONT_SIZE);
}
//! Scans the four default system font folders //! Scans the four default system font folders
void void
FontManager::ScanSystemFolders(void) FontManager::_ScanSystemFonts()
{ {
ScanDirectory("/boot/beos/etc/fonts/ttfonts/"); BPath path;
if (find_directory(B_BEOS_FONTS_DIRECTORY, &path) == 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
ScanDirectory("/boot/beos/etc/fonts/PS-Type1/"); if (find_directory(B_COMMON_FONTS_DIRECTORY, &path) == B_OK)
ScanDirectory("/boot/home/config/fonts/ttfonts/"); _AddPath(path.Path());
ScanDirectory("/boot/home/config/fonts/psfonts/");
#endif #endif
} }
@@ -176,29 +185,62 @@ FontManager::_AddFont(BPath &path)
} }
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
FontManager::_AddPath(BEntry& entry)
{
status_t status = _ScanDirectory(entry);
if (status != B_OK)
return status;
node_ref nodeRef;
if (entry.GetNodeRef(&nodeRef) != B_OK)
return status;
// TODO: don't add it twice!
// TODO: monitor this directory!
return B_OK;
}
/*! /*!
\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.
*/ */
status_t status_t
FontManager::ScanDirectory(const char *directoryPath) FontManager::_ScanDirectory(BEntry& entry)
{ {
// This bad boy does all the real work. It loads each entry in the // 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. // directory. If a valid font file, it adds both the family and the style.
// Both family and style are stored internally as BStrings. Once everything // Both family and style are stored internally as BStrings. Once everything
BDirectory dir; BDirectory dir;
status_t status = dir.SetTo(directoryPath); status_t status = dir.SetTo(&entry);
if (status != B_OK) if (status != B_OK)
return status; return status;
BEntry entry;
while (dir.GetNextEntry(&entry) == B_OK) { while (dir.GetNextEntry(&entry) == B_OK) {
BPath path; BPath path;
status = entry.GetPath(&path); status = entry.GetPath(&path);
if (status < B_OK) if (status < B_OK)
continue; continue;
if (entry.IsDirectory()) {
// scan this directory recursively
_AddPath(entry);
continue;
}
// TODO: Commenting this out makes my "Unicode glyph lookup" // TODO: Commenting this out makes my "Unicode glyph lookup"
// work with our default fonts. The real fix is to select the // work with our default fonts. The real fix is to select the
@@ -265,8 +307,35 @@ FontManager::_GetSupportedCharmap(const FT_Face& face)
} }
/*!
\brief Counts the number of font families available
\return The number of unique font families currently available
*/
int32
FontManager::CountFamilies() const
{
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
FontManager::CountStyles(const char *familyName) const
{
FontFamily *family = GetFamily(familyName);
if (family)
return family->CountStyles();
return 0;
}
FontFamily* FontFamily*
FontManager::GetFamilyByIndex(int32 index) const FontManager::FamilyAt(int32 index) const
{ {
return fFamilies.ItemAt(index); return fFamilies.ItemAt(index);
} }
@@ -378,106 +447,51 @@ FontManager::GetStyle(uint16 familyID, uint16 styleID)
/*! /*!
\brief Returns the current object used for the regular style \brief If you don't find your preferred font style, but are anxious
\return A ServerFont pointer which is the plain font. to have one fitting your needs, you may want to use this method.
Do NOT delete this object. If you access it, make a copy of it.
*/ */
ServerFont* FontStyle*
FontManager::GetSystemPlain() FontManager::FindStyleMatchingFace(uint16 face) const
{ {
return fPlain; int32 count = fFamilies.CountItems();
for (int32 i = 0; i < count; i++) {
FontFamily* family = fFamilies.ItemAt(i);
FontStyle* style = family->GetStyleMatchingFace(face);
if (style != NULL)
return style;
}
return NULL;
} }
/*! const ServerFont*
\brief Returns the current object used for the bold style FontManager::DefaultFont() const
\return A ServerFont pointer which is the bold font.
Do NOT delete this object. If you access it, make a copy of it.
*/
ServerFont*
FontManager::GetSystemBold()
{ {
return fBold; return fDefaultFont;
} }
/*! void
\brief Returns the current object used for the fixed style FontManager::AttachUser(uid_t userID)
\return A ServerFont pointer which is the fixed font.
Do NOT delete this object. If you access it, make a copy of it.
*/
ServerFont*
FontManager::GetSystemFixed()
{ {
return fFixed; BAutolock locker(this);
/*
BPath path;
status_t status = find_directory(B_USER_FONTS_DIRECTORY, &path);
if (status != B_OK)
return status;
_AddPath(path.Path());
*/
} }
/*! void
\brief Sets the system's plain font to the specified family and style FontManager::DetachUser(uid_t userID)
\param family Name of the font's family
\param style Name of the style desired
\param size Size desired
\return true if successful, false if not.
*/
bool
FontManager::SetSystemPlain(const char* familyName, const char* styleName, float size)
{ {
FontStyle *style = GetStyle(familyName, styleName); BAutolock locker(this);
if (style == NULL)
return false;
delete fPlain;
fPlain = new ServerFont(*style, size);
return true;
}
/*!
\brief Sets the system's bold font to the specified family and style
\param family Name of the font's family
\param style Name of the style desired
\param size Size desired
\return true if successful, false if not.
*/
bool
FontManager::SetSystemBold(const char* familyName, const char* styleName, float size)
{
FontStyle *style = GetStyle(familyName, styleName);
if (style == NULL)
return false;
delete fBold;
fBold = new ServerFont(*style, size);
return true;
}
/*!
\brief Sets the system's fixed font to the specified family and style
\param family Name of the font's family
\param style Name of the style desired
\param size Size desired
\return true if successful, false if not.
*/
bool
FontManager::SetSystemFixed(const char* familyName, const char* styleName, float size)
{
FontStyle *style = GetStyle(familyName, styleName);
if (style == NULL)
return false;
delete fFixed;
fFixed = new ServerFont(*style, size);
return true;
} }
+2 -4
View File
@@ -21,7 +21,6 @@
#include "LayerData.h" #include "LayerData.h"
// constructor
DrawData::DrawData() DrawData::DrawData()
: fOrigin(0.0, 0.0), : fOrigin(0.0, 0.0),
fScale(1.0), fScale(1.0),
@@ -34,7 +33,6 @@ DrawData::DrawData()
fAlphaFncMode(B_ALPHA_OVERLAY), fAlphaFncMode(B_ALPHA_OVERLAY),
fPenLocation(0.0, 0.0), fPenLocation(0.0, 0.0),
fPenSize(1.0), fPenSize(1.0),
fFont(*gFontManager->GetSystemPlain()),
fFontAliasing(false), fFontAliasing(false),
fSubPixelPrecise(false), fSubPixelPrecise(false),
fLineCapMode(B_BUTT_CAP), fLineCapMode(B_BUTT_CAP),
@@ -44,14 +42,14 @@ DrawData::DrawData()
fUnscaledFontSize = fFont.Size(); fUnscaledFontSize = fFont.Size();
} }
// copy constructor
DrawData::DrawData(const DrawData& from) DrawData::DrawData(const DrawData& from)
: fClippingRegion(NULL) : fClippingRegion(NULL)
{ {
*this = from; *this = from;
} }
// copy constructor
DrawData::DrawData(const DrawData* from) DrawData::DrawData(const DrawData* from)
: fOrigin(0.0, 0.0), : fOrigin(0.0, 0.0),
fScale(1.0), fScale(1.0),
+17 -35
View File
@@ -1134,27 +1134,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
gFontManager->Lock(); gFontManager->Lock();
bool needsUpdate = gFontManager->FontsNeedUpdated(); bool needsUpdate = gFontManager->FontsNeedUpdated();
gFontManager->Unlock(); gFontManager->Unlock();
if(checkonly) if (checkonly) {
{
fLink.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE); fLink.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE);
fLink.Flush(); fLink.Flush();
} } else {
else fLink.StartMessage(SERVER_FALSE);
{ fLink.Flush();
if(needsUpdate)
{
gFontManager->Lock();
gFontManager->ScanSystemFolders();
gFontManager->Unlock();
fLink.StartMessage(SERVER_TRUE);
fLink.Flush();
}
else
{
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
}
} }
break; break;
} }
@@ -1172,7 +1158,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
gFontManager->Lock(); gFontManager->Lock();
FontFamily *family = gFontManager->GetFamilyByIndex(index); FontFamily *family = gFontManager->FamilyAt(index);
if (family) { if (family) {
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.AttachString(family->Name()); fLink.AttachString(family->Name());
@@ -1555,32 +1541,28 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags // 4) uint16 - face flags
// 5) uint32 - font flags // 5) uint32 - font flags
gFontManager->Lock(); DesktopSettings settings(fDesktop);
ServerFont *font = NULL; ServerFont font;
switch (code) { switch (code) {
case AS_SET_SYSFONT_PLAIN: case AS_SET_SYSFONT_PLAIN:
font = gFontManager->GetSystemPlain(); settings.GetDefaultPlainFont(font);
break; break;
case AS_SET_SYSFONT_BOLD: case AS_SET_SYSFONT_BOLD:
font = gFontManager->GetSystemBold(); settings.GetDefaultBoldFont(font);
break; break;
case AS_SET_SYSFONT_FIXED: case AS_SET_SYSFONT_FIXED:
font = gFontManager->GetSystemFixed(); settings.GetDefaultFixedFont(font);
break; break;
} }
if (font != NULL) { fLink.StartMessage(B_OK);
fLink.StartMessage(B_OK); fLink.Attach<uint16>(font.FamilyID());
fLink.Attach<uint16>(font->FamilyID()); fLink.Attach<uint16>(font.StyleID());
fLink.Attach<uint16>(font->StyleID()); fLink.Attach<float>(font.Size());
fLink.Attach<float>(font->Size()); fLink.Attach<uint16>(font.Face());
fLink.Attach<uint16>(font->Face()); fLink.Attach<uint32>(font.Flags());
fLink.Attach<uint32>(font->Flags());
} else
fLink.StartMessage(B_BAD_VALUE);
gFontManager->Unlock();
fLink.Flush(); fLink.Flush();
break; break;
} }
+18 -21
View File
@@ -147,7 +147,7 @@ ServerFont::ServerFont()
: :
fStyle(NULL) fStyle(NULL)
{ {
*this = *gFontManager->GetSystemPlain(); *this = *gFontManager->DefaultFont();
} }
@@ -190,8 +190,7 @@ ServerFont::operator=(const ServerFont& font)
fEncoding = font.fEncoding; fEncoding = font.fEncoding;
fBounds = font.fBounds; fBounds = font.fBounds;
_SetStyle(font.fStyle); SetStyle(*font.fStyle);
return *this; return *this;
} }
@@ -232,6 +231,21 @@ ServerFont::GetFamily() const
} }
void
ServerFont::SetStyle(FontStyle& style)
{
if (&style != fStyle) {
// detach from old style
if (fStyle)
fStyle->Release();
// attach to new style
fStyle = &style;
fStyle->Acquire();
}
}
/*! /*!
\brief Sets the ServerFont instance to whatever font is specified \brief Sets the ServerFont instance to whatever font is specified
\param familyID ID number of the family to set \param familyID ID number of the family to set
@@ -254,7 +268,7 @@ ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID)
if (!style) if (!style)
return B_ERROR; return B_ERROR;
_SetStyle(style); SetStyle(*style);
style->Release(); style->Release();
return B_OK; return B_OK;
@@ -708,20 +722,3 @@ ServerFont::TruncateString(BString* inOut, uint32 mode, float width) const
} }
} }
void
ServerFont::_SetStyle(FontStyle* style)
{
if (style == NULL)
debugger("set NULL style!");
if (style != fStyle) {
// detach from old style
if (fStyle)
fStyle->Release();
// attach to new style
fStyle = style;
fStyle->Acquire();
}
}
+3 -2
View File
@@ -24,6 +24,7 @@
#include "MessagePrivate.h" #include "MessagePrivate.h"
#include "PortLink.h" #include "PortLink.h"
#include "RootLayer.h" #include "RootLayer.h"
#include "ServerApp.h"
#include "ServerWindow.h" #include "ServerWindow.h"
#include "TokenHandler.h" #include "TokenHandler.h"
#include "Workspace.h" #include "Workspace.h"
@@ -110,8 +111,8 @@ WinBorder::WinBorder(const BRect &frame,
QuietlySetFeel(feel); QuietlySetFeel(feel);
if (fFeel != B_NO_BORDER_WINDOW_LOOK) { if (fFeel != B_NO_BORDER_WINDOW_LOOK) {
fDecorator = gDecorManager.AllocateDecorator(frame, name, fLook, fFeel, fDecorator = gDecorManager.AllocateDecorator(window->App()->GetDesktop(), frame,
fWindowFlags, fDriver); name, fLook, fFeel, fWindowFlags);
if (fDecorator) if (fDecorator)
fDecorator->GetSizeLimits(&fMinWidth, &fMinHeight, &fMaxWidth, &fMaxHeight); fDecorator->GetSizeLimits(&fMinWidth, &fMinHeight, &fMaxWidth, &fMaxHeight);
} }
@@ -89,9 +89,6 @@ Painter::Painter()
fPatternHandler(new PatternHandler()), fPatternHandler(new PatternHandler()),
fTextRenderer(new AGGTextRenderer()) fTextRenderer(new AGGTextRenderer())
{ {
if (gFontManager && gFontManager->GetSystemPlain())
fFont = *gFontManager->GetSystemPlain();
_UpdateFont(); _UpdateFont();
_UpdateLineWidth(); _UpdateLineWidth();
} }