Fixed some style related functions and other oddities in FontServer.

Also applied our style guide on that class.
Renamed some public globals to match our style guide.
Made BitmapManager inherit from BLocker instead of duplicating its
functionality (incorrectly, did not check for B_INTERRUPTED) locally.
Some more cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13259 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-24 03:31:41 +00:00
parent 83f9178dbd
commit b5436616a3
12 changed files with 589 additions and 701 deletions
+12 -29
View File
@@ -1,36 +1,19 @@
//------------------------------------------------------------------------------ /*
// 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, */
// 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: BitmapManager.h
// Author: DarkWyrm <[email protected]>
// Description: Handler for allocating and freeing area memory for BBitmaps
// on the server side. Utilizes the BGET pool allocator.
//------------------------------------------------------------------------------
#ifndef BITMAP_MANAGER_H_ #ifndef BITMAP_MANAGER_H_
#define BITMAP_MANAGER_H_ #define BITMAP_MANAGER_H_
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#include <List.h> #include <List.h>
#include <OS.h> #include <OS.h>
#include <Rect.h> #include <Rect.h>
#include <Locker.h>
#include "BGet++.h" #include "BGet++.h"
#include "TokenHandler.h" #include "TokenHandler.h"
@@ -64,10 +47,10 @@ class BitmapManager {
area_id fBitmapArea; area_id fBitmapArea;
int8* fBuffer; int8* fBuffer;
TokenHandler fTokenizer; TokenHandler fTokenizer;
sem_id fLock; BLocker fLock;
AreaPool fMemPool; AreaPool fMemPool;
}; };
extern BitmapManager *bitmapmanager; extern BitmapManager *gBitmapManager;
#endif #endif /* BITMAP_MANAGER_H_ */
+22 -40
View File
@@ -1,29 +1,10 @@
//------------------------------------------------------------------------------ /*
// 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, */
// 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: FontServer.h
// Author: DarkWyrm <[email protected]>
// Description: Handles the largest part of the font subsystem
//
//------------------------------------------------------------------------------
#ifndef FONTSERVER_H_ #ifndef FONTSERVER_H_
#define FONTSERVER_H_ #define FONTSERVER_H_
@@ -31,6 +12,8 @@
#include <List.h> #include <List.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <Font.h> #include <Font.h>
#include <Locker.h>
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_CACHE_H #include FT_CACHE_H
@@ -43,19 +26,16 @@ class ServerFont;
\class FontServer FontServer.h \class FontServer FontServer.h
\brief Manager for the largest part of the font subsystem \brief Manager for the largest part of the font subsystem
*/ */
class FontServer class FontServer : public BLocker {
{
public: public:
FontServer(void); FontServer(void);
~FontServer(void); ~FontServer(void);
bool Lock(void);
void Unlock(void);
/*! /*!
\brief Determines whether the font server has started up properly \brief Determines whether the font server has started up properly
\return true if so, false if not. \return true if so, false if not.
*/ */
bool IsInitialized(void) { return init; } bool IsInitialized(void) { return fInit; }
int32 CountFamilies(void); int32 CountFamilies(void);
int32 CountStyles(const char *family); int32 CountStyles(const char *family);
void RemoveFamily(const char *family); void RemoveFamily(const char *family);
@@ -79,24 +59,26 @@ public:
bool SetSystemBold(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 SetSystemFixed(const char *family, const char *style, float size);
bool FontsNeedUpdated(void) { return need_update; } bool FontsNeedUpdated(void) { return fNeedUpdate; }
/*! /*!
\brief Called when the fonts list has been updated \brief Called when the fonts list has been updated
*/ */
void FontsUpdated(void) { need_update=false; } void FontsUpdated(void) { fNeedUpdate = false; }
protected: protected:
uint16 TranslateStyleToFace(const char *name) const; uint16 TranslateStyleToFace(const char *name) const;
FT_CharMap _GetSupportedCharmap(const FT_Face &face); FT_CharMap _GetSupportedCharmap(const FT_Face &face);
bool init;
sem_id lock; private:
BList *families; bool fInit;
ServerFont *plain, *bold, *fixed; BList fFamilies;
bool need_update; ServerFont *fPlain, *fBold, *fFixed;
bool fNeedUpdate;
}; };
extern FTC_Manager ftmanager; extern FTC_Manager ftmanager;
extern FT_Library ftlib; extern FT_Library ftlib;
extern FontServer *fontserver; extern FontServer *gFontServer;
#endif #endif /* FONTSERVER_H_ */
+30 -30
View File
@@ -71,7 +71,7 @@ static AppServer *sAppServer;
//RGBColor workspace_default_color(51,102,160); //RGBColor workspace_default_color(51,102,160);
//! System-wide GUI color object //! System-wide GUI color object
ColorSet gui_colorset; ColorSet gGUIColorSet;
/*! /*!
\brief Constructor \brief Constructor
@@ -104,22 +104,22 @@ AppServer::AppServer(void) :
sAppServer = this; sAppServer = this;
// Create the font server and scan the proper directories. // Create the font server and scan the proper directories.
fontserver = new FontServer; gFontServer = new FontServer;
fontserver->Lock(); gFontServer->Lock();
// Used for testing purposes // Used for testing purposes
// TODO: Re-enable scanning of all font directories when server is actually put to use // TODO: Re-enable scanning of all font directories when server is actually put to use
fontserver->ScanDirectory("/boot/beos/etc/fonts/ttfonts/"); gFontServer->ScanDirectory("/boot/beos/etc/fonts/ttfonts/");
// fontserver->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/"); // gFontServer->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/");
// fontserver->ScanDirectory("/boot/home/config/fonts/ttfonts/"); // gFontServer->ScanDirectory("/boot/home/config/fonts/ttfonts/");
// fontserver->ScanDirectory("/boot/home/config/fonts/psfonts/"); // gFontServer->ScanDirectory("/boot/home/config/fonts/psfonts/");
fontserver->SaveList(); gFontServer->SaveList();
if (!fontserver->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY, if (!gFontServer->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE, DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE) && DEFAULT_PLAIN_FONT_SIZE) &&
!fontserver->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY, !gFontServer->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE, DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE)) { DEFAULT_PLAIN_FONT_SIZE)) {
printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n", printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n",
@@ -129,10 +129,10 @@ AppServer::AppServer(void) :
DEFAULT_PLAIN_FONT_SIZE); DEFAULT_PLAIN_FONT_SIZE);
} }
if (!fontserver->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY, if (!gFontServer->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY,
DEFAULT_BOLD_FONT_STYLE, DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE) && DEFAULT_BOLD_FONT_SIZE) &&
!fontserver->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY, !gFontServer->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY,
DEFAULT_BOLD_FONT_STYLE, DEFAULT_BOLD_FONT_STYLE,
DEFAULT_BOLD_FONT_SIZE)) { DEFAULT_BOLD_FONT_SIZE)) {
printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n", printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n",
@@ -142,10 +142,10 @@ AppServer::AppServer(void) :
DEFAULT_BOLD_FONT_SIZE); DEFAULT_BOLD_FONT_SIZE);
} }
if (!fontserver->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY, if (!gFontServer->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY,
DEFAULT_FIXED_FONT_STYLE, DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE) && DEFAULT_FIXED_FONT_SIZE) &&
!fontserver->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY, !gFontServer->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY,
DEFAULT_FIXED_FONT_STYLE, DEFAULT_FIXED_FONT_STYLE,
DEFAULT_FIXED_FONT_SIZE)) { DEFAULT_FIXED_FONT_SIZE)) {
printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n", printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n",
@@ -155,12 +155,12 @@ AppServer::AppServer(void) :
DEFAULT_FIXED_FONT_SIZE); DEFAULT_FIXED_FONT_SIZE);
} }
fontserver->Unlock(); gFontServer->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
if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME,&gui_colorset)!=B_OK) if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK)
gui_colorset.SetToDefaults(); gGUIColorSet.SetToDefaults();
// Set up the Desktop // Set up the Desktop
gDesktop = new Desktop(); gDesktop = new Desktop();
@@ -170,7 +170,7 @@ AppServer::AppServer(void) :
InitializeColorMap(); InitializeColorMap();
// Create the bitmap allocator. Object declared in BitmapManager.cpp // Create the bitmap allocator. Object declared in BitmapManager.cpp
bitmapmanager = new BitmapManager(); gBitmapManager = new BitmapManager();
// This is necessary to mediate access between the Poller and app_server threads // This is necessary to mediate access between the Poller and app_server threads
fActiveAppLock = create_sem(1,"app_server_active_sem"); fActiveAppLock = create_sem(1,"app_server_active_sem");
@@ -194,7 +194,7 @@ AppServer::AppServer(void) :
Reached only when the server is asked to shut down in Test mode. Kills all apps, shuts down the Reached only when the server is asked to shut down in Test mode. Kills all apps, shuts down the
desktop, kills the housekeeping threads, etc. desktop, kills the housekeeping threads, etc.
*/ */
AppServer::~AppServer(void) AppServer::~AppServer()
{ {
debugger("We shouldn't be here! MainLoop()::B_QUIT_REQUESTED should see if we can exit the server.\n"); debugger("We shouldn't be here! MainLoop()::B_QUIT_REQUESTED should see if we can exit the server.\n");
/* /*
@@ -210,7 +210,7 @@ AppServer::~AppServer(void)
delete fAppList; delete fAppList;
release_sem(fAppListLock); release_sem(fAppListLock);
delete bitmapmanager; delete gBitmapManager;
delete gDesktop; delete gDesktop;
@@ -221,7 +221,7 @@ AppServer::~AppServer(void)
kill_thread(fCursorThreadID); kill_thread(fCursorThreadID);
kill_thread(fISThreadID); kill_thread(fISThreadID);
delete fontserver; delete gFontServer;
make_decorator=NULL; make_decorator=NULL;
*/ */
@@ -504,9 +504,9 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
case AS_UPDATED_CLIENT_FONTLIST: case AS_UPDATED_CLIENT_FONTLIST:
// received when the client-side global font list has been // received when the client-side global font list has been
// refreshed // refreshed
fontserver->Lock(); gFontServer->Lock();
fontserver->FontsUpdated(); gFontServer->FontsUpdated();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
case AS_QUERY_FONTS_CHANGED: case AS_QUERY_FONTS_CHANGED:
@@ -517,9 +517,9 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
// Attached data: // Attached data:
// 1) port_id reply port // 1) port_id reply port
fontserver->Lock(); gFontServer->Lock();
bool needs_update=fontserver->FontsNeedUpdated(); bool needsUpdate = gFontServer->FontsNeedUpdated();
fontserver->Unlock(); gFontServer->Unlock();
// Seeing how the client merely wants an answer, we'll skip the BPortLink // Seeing how the client merely wants an answer, we'll skip the BPortLink
// and all its overhead and just write the code to port. // and all its overhead and just write the code to port.
@@ -527,7 +527,7 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
if (msg.Read<port_id>(&replyport) < B_OK) if (msg.Read<port_id>(&replyport) < B_OK)
break; break;
BPrivate::PortLink replylink(replyport); BPrivate::PortLink replylink(replyport);
replylink.StartMessage(needs_update ? SERVER_TRUE : SERVER_FALSE); replylink.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE);
replylink.Flush(); replylink.Flush();
break; break;
} }
@@ -564,8 +564,8 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
release_sem(fAppListLock); release_sem(fAppListLock);
delete gDesktop; delete gDesktop;
delete bitmapmanager; delete gBitmapManager;
delete fontserver; delete gFontServer;
// we are now clear to exit // we are now clear to exit
exit_thread(0); exit_thread(0);
+2 -3
View File
@@ -87,9 +87,8 @@ private:
DisplayDriver *fDriver; DisplayDriver *fDriver;
}; };
extern BitmapManager *bitmapmanager; extern BitmapManager *gBitmapManager;
extern ColorSet gui_colorset; extern ColorSet gGUIColorSet;
extern AppServer *app_server;
extern port_id gAppServerPort; extern port_id gAppServerPort;
#endif /* _HAIKU_APP_SERVER_H_ */ #endif /* _HAIKU_APP_SERVER_H_ */
+31 -43
View File
@@ -1,40 +1,28 @@
//------------------------------------------------------------------------------ /*
// 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, */
// 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: /** Handler for allocating and freeing area memory for BBitmaps
// * on the server side. Utilizes the BGET pool allocator.
// 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: BitmapManager.cpp
// Author: DarkWyrm <[email protected]>
// Description: Handler for allocating and freeing area memory for BBitmaps
// on the server side. Utilizes the BGET pool allocator.
//------------------------------------------------------------------------------
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "ServerBitmap.h" #include <Autolock.h>
#include "ServerBitmap.h"
#include "BitmapManager.h" #include "BitmapManager.h"
//! The bitmap allocator for the server. Memory is allocated/freed by the AppServer class //! The bitmap allocator for the server. Memory is allocated/freed by the AppServer class
BitmapManager *bitmapmanager = NULL; BitmapManager *gBitmapManager = NULL;
//! Number of bytes to allocate to each area used for bitmap storage //! Number of bytes to allocate to each area used for bitmap storage
#define BITMAP_AREA_SIZE B_PAGE_SIZE * 2 #define BITMAP_AREA_SIZE B_PAGE_SIZE * 2
@@ -45,9 +33,8 @@ BitmapManager::BitmapManager()
fBitmapArea(B_ERROR), fBitmapArea(B_ERROR),
fBuffer(NULL), fBuffer(NULL),
fTokenizer(), fTokenizer(),
fLock(B_ERROR), fLock("BitmapManager Lock"),
fMemPool() fMemPool()
{ {
// When create_area is passed the B_ANY_ADDRESS flag, the address of the area // When create_area is passed the B_ANY_ADDRESS flag, the address of the area
// is stored in the pointer to a pointer. // is stored in the pointer to a pointer.
@@ -58,10 +45,6 @@ BitmapManager::BitmapManager()
if (fBitmapArea < B_OK) if (fBitmapArea < B_OK)
printf("PANIC: BitmapManager couldn't allocate area: %s\n", strerror(fBitmapArea)); printf("PANIC: BitmapManager couldn't allocate area: %s\n", strerror(fBitmapArea));
fLock = create_sem(1,"bmpmanager_fLock");
if (fLock < B_OK)
printf("PANIC: BitmapManager couldn't allocate fLocking semaphore!!\n");
fMemPool.AddToPool(fBuffer, BITMAP_AREA_SIZE); fMemPool.AddToPool(fBuffer, BITMAP_AREA_SIZE);
} }
@@ -75,8 +58,8 @@ BitmapManager::~BitmapManager()
delete bitmap; delete bitmap;
} }
} }
delete_area(fBitmapArea); delete_area(fBitmapArea);
delete_sem(fLock);
} }
/*! /*!
@@ -92,9 +75,14 @@ ServerBitmap*
BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags, BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
int32 bytesPerRow, screen_id screen) int32 bytesPerRow, screen_id screen)
{ {
ServerBitmap* bitmap = NULL; BAutolock locker(fLock);
if (acquire_sem(fLock) >= B_OK) {
bitmap = new(nothrow) ServerBitmap(bounds, space, flags, bytesPerRow); if (!locker.IsLocked())
return NULL;
ServerBitmap* bitmap = new(nothrow) ServerBitmap(bounds, space, flags, bytesPerRow);
if (bitmap == NULL)
return NULL;
// Server version of this code will also need to handle such things as // Server version of this code will also need to handle such things as
// bitmaps which accept child views by checking the flags. // bitmaps which accept child views by checking the flags.
@@ -118,8 +106,6 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
bitmap = NULL; bitmap = NULL;
} }
release_sem(fLock);
}
return bitmap; return bitmap;
} }
@@ -130,12 +116,14 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
void void
BitmapManager::DeleteBitmap(ServerBitmap *bitmap) BitmapManager::DeleteBitmap(ServerBitmap *bitmap)
{ {
if (acquire_sem(fLock) >= B_OK) { BAutolock locker(fLock);
if (!locker.IsLocked())
return;
if (fBitmapList.RemoveItem(bitmap)) { if (fBitmapList.RemoveItem(bitmap)) {
// Server code will require a check to ensure bitmap doesn't have its own area // Server code will require a check to ensure bitmap doesn't have its own area
fMemPool.ReleaseBuffer(bitmap->fBuffer); fMemPool.ReleaseBuffer(bitmap->fBuffer);
delete bitmap; delete bitmap;
} }
release_sem(fLock);
}
} }
+68 -55
View File
@@ -5,51 +5,54 @@
* Author: DarkWyrm <[email protected]> * Author: DarkWyrm <[email protected]>
*/ */
#include <Directory.h> #include <Directory.h>
#include <Rect.h> #include <Rect.h>
#include <File.h> #include <File.h>
#include <Message.h> #include <Message.h>
#include <Entry.h> #include <Entry.h>
#include "AppServer.h"
#include "ColorSet.h" #include "ColorSet.h"
#include "DefaultDecorator.h" #include "DefaultDecorator.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "DecorManager.h" #include "DecorManager.h"
// Globals // Globals
DecorManager gDecorManager; DecorManager gDecorManager;
extern ColorSet gui_colorset;
Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel, Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel,
int32 wflags); 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(const image_id &id, const char *name,
create_decorator *alloc); create_decorator *alloc);
~DecorInfo(void); ~DecorInfo(void);
image_id GetID(void) const { return fID; } image_id GetID(void) const { return fID; }
const char * GetName(void) const { return fName.String(); } const char* GetName(void) const { return fName.String(); }
Decorator * Instantiate(BRect rect, const char *title, Decorator* Instantiate(BRect rect, const char *title,
int32 wlook, int32 wfeel, int32 wlook, int32 wfeel,
int32 wflags, DisplayDriver *ddriver); int32 wflags, DisplayDriver *ddriver);
private: private:
image_id fID; image_id fID;
BString fName; BString fName;
create_decorator *fAllocator; create_decorator *fAllocator;
}; };
DecorInfo::DecorInfo(const image_id &id, const char *name, create_decorator *alloc) DecorInfo::DecorInfo(const image_id &id, const char *name, create_decorator *alloc)
: fID(id), :
fID(id),
fName(name), fName(name),
fAllocator(alloc) fAllocator(alloc)
{ {
} }
DecorInfo::~DecorInfo(void) DecorInfo::~DecorInfo(void)
{ {
// Do nothing. Normal programming practice would say that one should unload // Do nothing. Normal programming practice would say that one should unload
@@ -63,6 +66,7 @@ DecorInfo::~DecorInfo(void)
// when the app_server quits. It's not pretty, but it gets the job done. // when the app_server quits. It's not pretty, but it gets the job done.
} }
Decorator * Decorator *
DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel, DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel,
int32 wflags, DisplayDriver *ddriver) int32 wflags, DisplayDriver *ddriver)
@@ -71,17 +75,22 @@ DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel,
dec->SetDriver(ddriver); dec->SetDriver(ddriver);
gui_colorset.Lock(); gGUIColorSet.Lock();
dec->SetColors(gui_colorset); dec->SetColors(gGUIColorSet);
gui_colorset.Unlock(); gGUIColorSet.Unlock();
dec->SetTitle(title); dec->SetTitle(title);
return dec; return dec;
} }
DecorManager::DecorManager(void)
: fDecorList(0), // #pragma mark -
DecorManager::DecorManager()
:
fDecorList(0),
fCurrentDecor(NULL) fCurrentDecor(NULL)
{ {
// Start with the default decorator - index is always 0 // Start with the default decorator - index is always 0
@@ -100,37 +109,36 @@ DecorManager::DecorManager(void)
BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY); BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY);
// Fallback to the default decorator if something goes wrong // Fallback to the default decorator if something goes wrong
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(void)
DecorManager::~DecorManager()
{ {
EmptyList(); EmptyList();
} }
void void
DecorManager::RescanDecorators(void) DecorManager::RescanDecorators()
{ {
BDirectory dir(DECORATORS_DIR); BDirectory dir(DECORATORS_DIR);
if(dir.InitCheck() != B_OK) if (dir.InitCheck() != B_OK)
return; return;
entry_ref ref; entry_ref ref;
BString fullpath; BString fullpath;
while(dir.GetNextRef(&ref)==B_OK) while (dir.GetNextRef(&ref) == B_OK) {
{
fullpath = DECORATORS_DIR; fullpath = DECORATORS_DIR;
fullpath += ref.name; fullpath += ref.name;
@@ -141,11 +149,11 @@ DecorManager::RescanDecorators(void)
// 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 tempID = load_add_on(fullpath.String());
if(tempID == B_ERROR) if (tempID == B_ERROR)
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
@@ -158,17 +166,16 @@ DecorManager::RescanDecorators(void)
// Get the instantiation function // Get the instantiation function
status_t status = get_image_symbol(tempID, "instantiate_decorator", status_t status = get_image_symbol(tempID, "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(tempID);
continue; continue;
} }
fDecorList.AddItem( new DecorInfo(tempID, ref.name, createfunc) ); fDecorList.AddItem(new DecorInfo(tempID, ref.name, createfunc));
} }
} }
Decorator * Decorator *
DecorManager::AllocateDecorator(BRect rect, const char *title, DecorManager::AllocateDecorator(BRect rect, const char *title,
int32 wlook, int32 wfeel, int32 wlook, int32 wfeel,
@@ -176,35 +183,36 @@ DecorManager::AllocateDecorator(BRect rect, const char *title,
{ {
// 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
if(!fCurrentDecor) if (!fCurrentDecor) {
{
// We should *never* be here. If we do, it's a bug. // We should *never* be here. If we do, it's a bug.
debugger("DecorManager::AllocateDecorator has a NULL decorator"); debugger("DecorManager::AllocateDecorator has a NULL decorator");
return NULL; return NULL;
} }
return fCurrentDecor->Instantiate(rect,title,wlook,wfeel,wflags,ddriver); return fCurrentDecor->Instantiate(rect, title, wlook, wfeel, wflags, ddriver);
} }
int32 int32
DecorManager::CountDecorators(void) const DecorManager::CountDecorators(void) const
{ {
return fDecorList.CountItems(); return fDecorList.CountItems();
} }
int32 int32
DecorManager::GetDecorator(void) const DecorManager::GetDecorator(void) const
{ {
return fDecorList.IndexOf( fCurrentDecor ); return fDecorList.IndexOf(fCurrentDecor);
} }
bool bool
DecorManager::SetDecorator(const int32 &index) DecorManager::SetDecorator(const int32 &index)
{ {
DecorInfo *newDecInfo = (DecorInfo*) fDecorList.ItemAt(index); DecorInfo *newDecInfo = (DecorInfo*)fDecorList.ItemAt(index);
if(newDecInfo) if (newDecInfo) {
{
fCurrentDecor = newDecInfo; fCurrentDecor = newDecInfo;
return true; return true;
} }
@@ -212,24 +220,23 @@ DecorManager::SetDecorator(const int32 &index)
return false; return false;
} }
bool bool
DecorManager::SetR5Decorator(const int32 &value) DecorManager::SetR5Decorator(const int32 &value)
{ {
BString string; BString string;
switch(value) switch (value) {
{ case 0: string = "BeOS"; break;
case 0: string="BeOS"; break; case 1: string = "AmigaOS"; break;
case 1: string="AmigaOS"; break; case 2: string = "Windows"; break;
case 2: string="Windows"; break; case 3: string = "MacOS"; break;
case 3: string="MacOS"; break;
default: default:
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;
} }
@@ -237,49 +244,55 @@ DecorManager::SetR5Decorator(const int32 &value)
return false; return false;
} }
const char * const char *
DecorManager::GetDecoratorName(const int32 &index) DecorManager::GetDecoratorName(const int32 &index)
{ {
DecorInfo *info = (DecorInfo*) fDecorList.ItemAt(index); DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(index);
if(info) if (info)
return info->GetName(); return info->GetName();
return NULL; return NULL;
} }
void void
DecorManager::EmptyList(void) DecorManager::EmptyList(void)
{ {
for(int32 i=0; i < fDecorList.CountItems(); i++) for (int32 i = 0; i < fDecorList.CountItems(); i++) {
{ DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i);
DecorInfo *info=(DecorInfo*)fDecorList.ItemAt(i);
delete info; delete info;
} }
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 = (DecorInfo*) fDecorList.ItemAt(i);
if(info && strcmp(name, info->GetName())==0 ) if (info && strcmp(name, info->GetName()) == 0)
return info; return info;
} }
return NULL; return NULL;
} }
// #pragma mark -
// This is the allocator function for the default decorator // This is the allocator function for the default decorator
Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) Decorator*
create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags)
{ {
return new DefaultDecorator(rect,wlook,wfeel,wflags); return new DefaultDecorator(rect, wlook, wfeel, wflags);
} }
+12 -27
View File
@@ -1,29 +1,13 @@
//------------------------------------------------------------------------------ /*
// 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, */
// 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: /** Default and fallback decorator for the app_server - the yellow tabs */
//
// 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.cpp
// Author: DarkWyrm <[email protected]>
// Description: Default and fallback decorator for the app_server
//
//------------------------------------------------------------------------------
#include <stdio.h> #include <stdio.h>
@@ -53,7 +37,8 @@ DefaultDecorator::DefaultDecorator(BRect rect, int32 wlook, int32 wfeel, int32 w
: Decorator(rect, wlook, wfeel, wflags), : Decorator(rect, wlook, wfeel, wflags),
fTruncatedTitle("") fTruncatedTitle("")
{ {
ServerFont font(_look == B_FLOATING_WINDOW_LOOK ? *fontserver->GetSystemPlain() : *fontserver->GetSystemBold()); ServerFont font(_look == B_FLOATING_WINDOW_LOOK ?
*gFontServer->GetSystemPlain() : *gFontServer->GetSystemBold());
font.SetFlags(B_FORCE_ANTIALIASING); font.SetFlags(B_FORCE_ANTIALIASING);
font.SetSpacing(B_STRING_SPACING); font.SetSpacing(B_STRING_SPACING);
SetFont(&font); SetFont(&font);
+200 -238
View File
@@ -1,29 +1,14 @@
//------------------------------------------------------------------------------ /*
// 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, */
// 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: /** Handles the largest part of the font subsystem */
//
// 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: FontServer.cpp
// Author: DarkWyrm <[email protected]>
// Description: Handles the largest part of the font subsystem
//
//------------------------------------------------------------------------------
#include <String.h> #include <String.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
@@ -37,27 +22,37 @@
#include <ServerFont.h> #include <ServerFont.h>
#include "ServerConfig.h" #include "ServerConfig.h"
extern FTC_Manager ftmanager; extern FTC_Manager ftmanager;
FT_Library ftlib; FT_Library ftlib;
FontServer *fontserver=NULL; FontServer *gFontServer = NULL;
//#define PRINT_FONT_LIST //#define PRINT_FONT_LIST
/*! /*!
\brief Access function to request a face via the FreeType font cache \brief Access function to request a face via the FreeType font cache
*/ */
static FT_Error face_requester(FTC_FaceID face_id, FT_Library library, static FT_Error
face_requester(FTC_FaceID face_id, FT_Library library,
FT_Pointer request_data, FT_Face *aface) FT_Pointer request_data, FT_Face *aface)
{ {
CachedFace face = (CachedFace) face_id; CachedFace face = (CachedFace) face_id;
return FT_New_Face(ftlib,face->file_path.String(),face->face_index,aface); return FT_New_Face(ftlib, face->file_path.String(), face->face_index,aface);
} }
// #pragma mark -
//! Does basic set up so that directories can be scanned //! Does basic set up so that directories can be scanned
FontServer::FontServer(void) FontServer::FontServer(void)
: BLocker("font server lock"),
fFamilies(20),
fPlain(NULL),
fBold(NULL),
fFixed(NULL)
{ {
lock=create_sem(1,"fontserver_lock"); fInit = FT_Init_FreeType(&ftlib) == 0;
init=(FT_Init_FreeType(&ftlib)==0)?true:false;
/* /*
Fire up the font caching subsystem. Fire up the font caching subsystem.
@@ -66,37 +61,18 @@ FontServer::FontServer(void)
these numbers in the future to maximize performance for your "average" these numbers in the future to maximize performance for your "average"
application. application.
*/ */
if(FTC_Manager_New(ftlib,0,0,0,&face_requester,NULL,&ftmanager)!=0 if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0)
&& init) fInit = false;
init=false;
families=new BList(20);
plain=NULL;
bold=NULL;
fixed=NULL;
} }
//! Frees items allocated in the constructor and shuts down FreeType //! Frees items allocated in the constructor and shuts down FreeType
FontServer::~FontServer(void) FontServer::~FontServer(void)
{ {
delete_sem(lock);
delete families;
FTC_Manager_Done(ftmanager); FTC_Manager_Done(ftmanager);
FT_Done_FreeType(ftlib); FT_Done_FreeType(ftlib);
} }
//! Locks access to the font server
bool
FontServer::Lock(void)
{
return acquire_sem(lock) >= B_OK;
}
//! Unlocks access to the font server
void FontServer::Unlock(void)
{
release_sem(lock);
}
/*! /*!
\brief Counts the number of font families available \brief Counts the number of font families available
@@ -104,78 +80,83 @@ void FontServer::Unlock(void)
*/ */
int32 FontServer::CountFamilies(void) int32 FontServer::CountFamilies(void)
{ {
if(init) if (fInit)
return families->CountItems(); return fFamilies.CountItems();
return 0; return 0;
} }
/*! /*!
\brief Counts the number of styles available in a font family \brief Counts the number of styles available in a font family
\param family Name of the font family to scan \param family Name of the font family to scan
\return The number of font styles currently available for the font family \return The number of font styles currently available for the font family
*/ */
int32 FontServer::CountStyles(const char *family) int32
FontServer::CountStyles(const char *familyName)
{ {
FontFamily *f=GetFamily(family); FontFamily *family = GetFamily(familyName);
if(f) if (family)
{ return family->CountStyles();
return f->CountStyles();
}
return 0; return 0;
} }
/*! /*!
\brief Removes a font family from the font list \brief Removes a font family from the font list
\param family The family to remove \param family The family to remove
*/ */
void FontServer::RemoveFamily(const char *family) void
FontServer::RemoveFamily(const char *familyName)
{ {
FontFamily *f=GetFamily(family); FontFamily *family = GetFamily(familyName);
if(f) if (family) {
{ fFamilies.RemoveItem(family);
families->RemoveItem(f); delete family;
delete f;
} }
} }
const char *FontServer::GetFamilyName(uint16 id) const
const char*
FontServer::GetFamilyName(uint16 id) const
{ {
FontFamily *fam; for (int32 i = 0; i < fFamilies.CountItems(); i++) {
for(int32 i=0; i<families->CountItems(); i++) FontFamily* family = (FontFamily*)fFamilies.ItemAt(i);
{ if (family && family->GetID() == id)
fam=(FontFamily*)families->ItemAt(i); return family->Name();
if(fam && fam->GetID()==id)
return fam->Name();
} }
return NULL; return NULL;
} }
const char *FontServer::GetStyleName(const char *family, uint16 id) const
const char*
FontServer::GetStyleName(const char* familyName, uint16 id) const
{ {
FontFamily *fam=GetFamily(family); FontStyle* style = GetStyle(familyName, id);
FontStyle *sty; if (style != NULL)
for(int32 i=0; i<families->CountItems(); i++) return style->Name();
{
sty=fam->GetStyle(i);
if(sty && sty->GetID()==id)
return sty->Name();
}
return NULL; return NULL;
} }
FontStyle *FontServer::GetStyle(const char *family, uint16 id) const
FontStyle*
FontServer::GetStyle(const char* familyName, uint16 id) const
{ {
FontFamily *fam=GetFamily(family); FontFamily* family = GetFamily(familyName);
FontStyle *sty;
for(int32 i=0; i<families->CountItems(); i++) for (int32 i = 0; i < family->CountStyles(); i++) {
{ FontStyle* style = family->GetStyle(i);
sty=fam->GetStyle(i); if (style && style->GetID() == id)
if(sty && sty->GetID()==id) return style;
return sty;
} }
return NULL; return NULL;
} }
/*! /*!
\brief Protected function which locates a FontFamily object \brief Protected function which locates a FontFamily object
\param name The family to find \param name The family to find
@@ -183,21 +164,24 @@ FontStyle *FontServer::GetStyle(const char *family, uint16 id) const
Do NOT delete the FontFamily returned by this function. Do NOT delete the FontFamily returned by this function.
*/ */
FontFamily *FontServer::GetFamily(const char *name) const FontFamily*
FontServer::GetFamily(const char* name) const
{ {
if(!init) if (!fInit)
return NULL; return NULL;
int32 count=families->CountItems(), i;
FontFamily *family; int32 count = fFamilies.CountItems();
for(i=0; i<count; i++)
{ for (int32 i = 0; i < count; i++) {
family=(FontFamily*)families->ItemAt(i); FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
if(strcmp(family->Name(),name)==0) if (!strcmp(family->Name(), name))
return family; return family;
} }
return NULL; return NULL;
} }
/*! /*!
\brief Scan a folder for all valid fonts \brief Scan a folder for all valid fonts
\param fontspath Path of the folder to scan. \param fontspath Path of the folder to scan.
@@ -212,42 +196,28 @@ FontFamily *FontServer::GetFamily(const char *name) const
- \c B_FILE_ERROR An invalid file prevented the operation. - \c B_FILE_ERROR An invalid file prevented the operation.
- \c B_NO_MORE_FDS All file descriptors are in use (too many open files). - \c B_NO_MORE_FDS All file descriptors are in use (too many open files).
*/ */
status_t FontServer::ScanDirectory(const char *fontspath) status_t
FontServer::ScanDirectory(const char *directoryPath)
{ {
// 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);
if (status != B_OK)
return status;
BEntry entry; BEntry entry;
while (dir.GetNextEntry(&entry) == B_OK) {
BPath path; BPath path;
entry_ref ref; status = entry.GetPath(&path);
status_t stat; if (status < B_OK)
int32 refcount,i, validcount=0;
FT_Face face;
FT_Error error;
FT_CharMap charmap;
FontFamily *family;
FontStyle *style;
stat=dir.SetTo(fontspath);
if(stat!=B_OK)
return stat;
refcount=dir.CountEntries();
for(i=0;i<refcount;i++)
{
if(dir.GetNextEntry(&entry)==B_ENTRY_NOT_FOUND)
break;
stat=entry.GetPath(&path);
if(stat!=B_OK)
continue; continue;
error=FT_New_Face(ftlib,path.Path(),0,&face); FT_Face face;
FT_Error error = FT_New_Face(ftlib, path.Path(), 0, &face);
if (error!=0) if (error != 0)
continue; continue;
// TODO: Commenting this out makes my "Unicode glyph lookup" // TODO: Commenting this out makes my "Unicode glyph lookup"
@@ -256,100 +226,88 @@ status_t FontServer::ScanDirectory(const char *fontspath)
// utf8 -> glyph-index mapping everywhere to handle other // utf8 -> glyph-index mapping everywhere to handle other
// char maps. We could also ignore fonts that don't support // char maps. We could also ignore fonts that don't support
// the Unicode lookup as a temporary "solution". // the Unicode lookup as a temporary "solution".
/* charmap=_GetSupportedCharmap(face); #if 0
if(!charmap) FT_CharMap charmap = _GetSupportedCharmap(face);
{ if (!charmap) {
FT_Done_Face(face); FT_Done_Face(face);
continue; continue;
} }
face->charmap=charmap;*/ face->charmap = charmap;
#endif
family=GetFamily(face->family_name); FontFamily *family = GetFamily(face->family_name);
if (family == NULL) {
if(!family)
{
#ifdef PRINT_FONT_LIST #ifdef PRINT_FONT_LIST
printf("Font Family: %s\n",face->family_name); printf("Font Family: %s\n", face->family_name);
#endif #endif
family=new FontFamily(face->family_name,families->CountItems()); family = new FontFamily(face->family_name, fFamilies.CountItems());
families->AddItem(family); fFamilies.AddItem(family);
} }
if(family->HasStyle(face->style_name)) if (family->HasStyle(face->style_name)) {
{
FT_Done_Face(face); FT_Done_Face(face);
continue; continue;
} }
#ifdef PRINT_FONT_LIST #ifdef PRINT_FONT_LIST
printf("\tFont Style: %s\n",face->style_name); printf("\tFont Style: %s\n", face->style_name);
#endif #endif
style=new FontStyle(path.Path(),face); FontStyle *style = new FontStyle(path.Path(), face);
if(!family->AddStyle(style)) if (!family->AddStyle(style))
delete style; delete style;
else
validcount++;
// FT_Face is kept open in FontStyle and will be unset in the // FT_Face is kept open in FontStyle and will be unset in the
// FontStyle destructor // FontStyle destructor
}
} // end for(i<refcount) fNeedUpdate = true;
dir.Unset();
need_update=true;
return B_OK; return B_OK;
} }
/*! /*!
\brief Finds and returns the first valid charmap in a font \brief Finds and returns the first valid charmap in a font
\param face Font handle obtained from FT_Load_Face() \param face Font handle obtained from FT_Load_Face()
\return An FT_CharMap or NULL if unsuccessful \return An FT_CharMap or NULL if unsuccessful
*/ */
FT_CharMap FontServer::_GetSupportedCharmap(const FT_Face &face) FT_CharMap
FontServer::_GetSupportedCharmap(const FT_Face& face)
{ {
int32 i; for (int32 i = 0; i < face->num_charmaps; i++) {
FT_CharMap charmap; FT_CharMap charmap = face->charmaps[i];
for(i=0; i< face->num_charmaps; i++)
{
charmap=face->charmaps[i];
switch(charmap->platform_id)
{
case 3:
{
// if Windows Symbol or Windows Unicode
if(charmap->encoding_id==0 || charmap->encoding_id==1)
return charmap;
break;
}
case 1:
{
// if Apple Unicode
if(charmap->encoding_id==0)
return charmap;
break;
}
case 0:
{
// if Apple Roman
if(charmap->encoding_id==0)
return charmap;
break;
}
default:
{
break;
}
}
}
return NULL;
switch (charmap->platform_id) {
case 3:
// if Windows Symbol or Windows Unicode
if (charmap->encoding_id == 0 || charmap->encoding_id == 1)
return charmap;
break;
case 1:
// if Apple Unicode
if (charmap->encoding_id == 0)
return charmap;
break;
case 0:
// if Apple Roman
if (charmap->encoding_id == 0)
return charmap;
break;
default:
break;
}
}
return NULL;
} }
/*! /*!
\brief This saves all family names and styles to the file specified in \brief This saves all family names and styles to the file specified in
ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage. ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage.
@@ -364,7 +322,8 @@ FT_CharMap FontServer::_GetSupportedCharmap(const FT_Face &face)
Additionally, any fonts which have bitmap strikes contained in them or any fonts which Additionally, any fonts which have bitmap strikes contained in them or any fonts which
are fixed-width are named in the arrays 'tuned' and 'fixed'. are fixed-width are named in the arrays 'tuned' and 'fixed'.
*/ */
void FontServer::SaveList(void) void
FontServer::SaveList(void)
{ {
/* int32 famcount=0, stycount=0,i=0,j=0; /* int32 famcount=0, stycount=0,i=0,j=0;
FontFamily *fam; FontFamily *fam;
@@ -424,85 +383,95 @@ void FontServer::SaveList(void)
*/ */
} }
/*! /*!
\brief Retrieves the FontStyle object \brief Retrieves the FontStyle object
\param family The font's family \param family The font's family
\param style The font's style \param style The font's style
\return The FontStyle having those attributes or NULL if not available \return The FontStyle having those attributes or NULL if not available
*/ */
FontStyle *FontServer::GetStyle(const char *family, const char *style) FontStyle*
FontServer::GetStyle(const char* familyName, const char* styleName)
{ {
FontFamily *ffam=GetFamily(family); FontFamily* family = GetFamily(familyName);
if (family)
return family->GetStyle(styleName);
if(ffam)
{
FontStyle *fsty=ffam->GetStyle(style);
return fsty;
}
return NULL; return NULL;
} }
/*! /*!
\brief Retrieves the FontStyle object \brief Retrieves the FontStyle object
\param family ID for the font's family \param family ID for the font's family
\param style ID of the font's style \param style ID of the font's style
\return The FontStyle having those attributes or NULL if not available \return The FontStyle having those attributes or NULL if not available
*/ */
FontStyle *FontServer::GetStyle(const uint16 &familyid, const uint16 &styleid) FontStyle*
FontServer::GetStyle(const uint16& familyID, const uint16& styleID)
{ {
FontFamily *fam=GetFamily(familyid); FontFamily *family = GetFamily(familyID);
if(fam)
{ if (family)
FontStyle *sty=fam->GetStyle(styleid); return family->GetStyle(styleID);
return sty;
}
return NULL; return NULL;
} }
FontFamily *FontServer::GetFamily(const uint16 &familyid) const
FontFamily*
FontServer::GetFamily(const uint16& familyID) const
{ {
for(int32 i=0; i<families->CountItems(); i++) for (int32 i = 0; i < fFamilies.CountItems(); i++) {
{ FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
FontFamily *fam=(FontFamily*)families->ItemAt(i); if (family->GetID() == familyID)
if(fam->GetID()==familyid) return family;
return fam;
} }
return NULL; return NULL;
} }
/*! /*!
\brief Returns the current object used for the regular style \brief Returns the current object used for the regular style
\return A ServerFont pointer which is the plain font. \return A ServerFont pointer which is the plain font.
Do NOT delete this object. If you access it, make a copy of it. Do NOT delete this object. If you access it, make a copy of it.
*/ */
ServerFont *FontServer::GetSystemPlain(void) ServerFont*
FontServer::GetSystemPlain()
{ {
return plain; return fPlain;
} }
/*! /*!
\brief Returns the current object used for the bold style \brief Returns the current object used for the bold style
\return A ServerFont pointer which is the bold font. \return A ServerFont pointer which is the bold font.
Do NOT delete this object. If you access it, make a copy of it. Do NOT delete this object. If you access it, make a copy of it.
*/ */
ServerFont *FontServer::GetSystemBold(void) ServerFont*
FontServer::GetSystemBold()
{ {
return bold; return fBold;
} }
/*! /*!
\brief Returns the current object used for the fixed style \brief Returns the current object used for the fixed style
\return A ServerFont pointer which is the fixed font. \return A ServerFont pointer which is the fixed font.
Do NOT delete this object. If you access it, make a copy of it. Do NOT delete this object. If you access it, make a copy of it.
*/ */
ServerFont *FontServer::GetSystemFixed(void) ServerFont*
FontServer::GetSystemFixed()
{ {
return fixed; return fFixed;
} }
/*! /*!
\brief Sets the system's plain font to the specified family and style \brief Sets the system's plain font to the specified family and style
\param family Name of the font's family \param family Name of the font's family
@@ -511,22 +480,20 @@ ServerFont *FontServer::GetSystemFixed(void)
\return true if successful, false if not. \return true if successful, false if not.
*/ */
bool FontServer::SetSystemPlain(const char *family, const char *style, float size) bool
FontServer::SetSystemPlain(const char* familyName, const char* styleName, float size)
{ {
FontFamily *fam=GetFamily(family); FontStyle *style = GetStyle(familyName, styleName);
if(!fam) if (style == NULL)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
return false; return false;
if(plain) delete fPlain;
delete plain; fPlain = new ServerFont(style, size);
plain=new ServerFont(sty,size);
return true; return true;
} }
/*! /*!
\brief Sets the system's bold font to the specified family and style \brief Sets the system's bold font to the specified family and style
\param family Name of the font's family \param family Name of the font's family
@@ -535,22 +502,20 @@ bool FontServer::SetSystemPlain(const char *family, const char *style, float siz
\return true if successful, false if not. \return true if successful, false if not.
*/ */
bool FontServer::SetSystemBold(const char *family, const char *style, float size) bool
FontServer::SetSystemBold(const char* familyName, const char* styleName, float size)
{ {
FontFamily *fam=GetFamily(family); FontStyle *style = GetStyle(familyName, styleName);
if(!fam) if (style == NULL)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
return false; return false;
if(bold) delete fBold;
delete bold; fBold = new ServerFont(style, size);
bold=new ServerFont(sty,size);
return true; return true;
} }
/*! /*!
\brief Sets the system's fixed font to the specified family and style \brief Sets the system's fixed font to the specified family and style
\param family Name of the font's family \param family Name of the font's family
@@ -559,19 +524,16 @@ bool FontServer::SetSystemBold(const char *family, const char *style, float size
\return true if successful, false if not. \return true if successful, false if not.
*/ */
bool FontServer::SetSystemFixed(const char *family, const char *style, float size) bool
FontServer::SetSystemFixed(const char* familyName, const char* styleName, float size)
{ {
FontFamily *fam=GetFamily(family); FontStyle *style = GetStyle(familyName, styleName);
if(!fam) if (style == NULL)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
return false; return false;
if(fixed) delete fFixed;
delete fixed; fFixed = new ServerFont(style, size);
fixed=new ServerFont(sty,size);
return true; return true;
} }
+15 -30
View File
@@ -1,31 +1,16 @@
//------------------------------------------------------------------------------ /*
// 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, * Adi Oanca <[email protected]>
// and/or sell copies of the Software, and to permit persons to whom the * Stephan Aßmus <[email protected]>
// Software is furnished to do so, subject to the following conditions: */
//
// The above copyright notice and this permission notice shall be included in /** Data classes for working with BView states and draw parameters */
// 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: LayerData.cpp
// Author: DarkWyrm <[email protected]>
// Adi Oanca <[email protected]>
// Stephan Aßmus <[email protected]>
// Description: Data classes for working with BView states and draw parameters
//
//------------------------------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include <Region.h> #include <Region.h>
@@ -55,8 +40,8 @@ DrawData::DrawData()
fLineJoinMode(B_BEVEL_JOIN), fLineJoinMode(B_BEVEL_JOIN),
fMiterLimit(B_DEFAULT_MITER_LIMIT) fMiterLimit(B_DEFAULT_MITER_LIMIT)
{ {
if (fontserver && fontserver->GetSystemPlain()) if (gFontServer && gFontServer->GetSystemPlain())
fFont = *(fontserver->GetSystemPlain()); fFont = *(gFontServer->GetSystemPlain());
fEscapementDelta.space = 0; fEscapementDelta.space = 0;
fEscapementDelta.nonspace = 0; fEscapementDelta.nonspace = 0;
+59 -58
View File
@@ -10,6 +10,7 @@
* Axel Dörfler, axeld@pinc-software.de * Axel Dörfler, axeld@pinc-software.de
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -765,7 +766,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&flags); link.Read<int32>(&flags);
link.Read<int32>(&bytesPerRow); link.Read<int32>(&bytesPerRow);
if (link.Read<screen_id>(&screenID) == B_OK) { if (link.Read<screen_id>(&screenID) == B_OK) {
bitmap = bitmapmanager->CreateBitmap(frame, colorSpace, flags, bitmap = gBitmapManager->CreateBitmap(frame, colorSpace, flags,
bytesPerRow, screenID); bytesPerRow, screenID);
} }
@@ -805,7 +806,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
STRACE(("ServerApp %s: Deleting Bitmap %ld\n", fSignature.String(), id)); STRACE(("ServerApp %s: Deleting Bitmap %ld\n", fSignature.String(), id));
fBitmapList.RemoveItem(bitmap); fBitmapList.RemoveItem(bitmap);
bitmapmanager->DeleteBitmap(bitmap); gBitmapManager->DeleteBitmap(bitmap);
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
} else } else
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
@@ -1076,13 +1077,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// using a ColorSet object // using a ColorSet object
gui_colorset.Lock(); gGUIColorSet.Lock();
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<ColorSet>(gui_colorset); fLink.Attach<ColorSet>(gGUIColorSet);
fLink.Flush(); fLink.Flush();
gui_colorset.Unlock(); gGUIColorSet.Unlock();
break; break;
} }
@@ -1094,9 +1095,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// Attached data: // Attached data:
// 1) ColorSet new colors to use // 1) ColorSet new colors to use
gui_colorset.Lock(); gGUIColorSet.Lock();
link.Read<ColorSet>(&gui_colorset); link.Read<ColorSet>(&gGUIColorSet);
gui_colorset.Unlock(); gGUIColorSet.Unlock();
BroadcastToAllApps(AS_UPDATE_COLORS); BroadcastToAllApps(AS_UPDATE_COLORS);
break; break;
@@ -1106,12 +1107,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
STRACE(("ServerApp %s: Get UI color\n", fSignature.String())); STRACE(("ServerApp %s: Get UI color\n", fSignature.String()));
RGBColor color; RGBColor color;
int32 whichcolor; int32 whichColor;
link.Read<int32>(&whichcolor); link.Read<int32>(&whichColor);
gui_colorset.Lock(); gGUIColorSet.Lock();
color = gui_colorset.AttributeToColor(whichcolor); color = gGUIColorSet.AttributeToColor(whichColor);
gui_colorset.Unlock(); gGUIColorSet.Unlock();
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<rgb_color>(color.GetColor32()); fLink.Attach<rgb_color>(color.GetColor32());
@@ -1126,9 +1127,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// received when the client-side global font list has been // received when the client-side global font list has been
// refreshed // refreshed
fontserver->Lock(); gFontServer->Lock();
fontserver->FontsUpdated(); gFontServer->FontsUpdated();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_QUERY_FONTS_CHANGED: case AS_QUERY_FONTS_CHANGED:
@@ -1157,8 +1158,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
int32 id; int32 id;
link.Read<int32>(&id); link.Read<int32>(&id);
fontserver->Lock(); gFontServer->Lock();
FontFamily *ffamily = fontserver->GetFamily(id); FontFamily *ffamily = gFontServer->GetFamily(id);
if (ffamily) { if (ffamily) {
font_family fam; font_family fam;
strcpy(fam, ffamily->Name()); strcpy(fam, ffamily->Name());
@@ -1168,7 +1169,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_STYLE_NAME: case AS_GET_STYLE_NAME:
@@ -1189,8 +1190,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read(fam,sizeof(font_family)); link.Read(fam,sizeof(font_family));
link.Read<int32>(&styid); link.Read<int32>(&styid);
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(fam, styid); FontStyle *fstyle = gFontServer->GetStyle(fam, styid);
if (fstyle) { if (fstyle) {
font_family sty; font_family sty;
strcpy(sty, fstyle->Name()); strcpy(sty, fstyle->Name());
@@ -1202,7 +1203,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_FAMILY_AND_STYLE: case AS_GET_FAMILY_AND_STYLE:
@@ -1222,8 +1223,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint16>(&famid); link.Read<uint16>(&famid);
link.Read<uint16>(&styid); link.Read<uint16>(&styid);
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid); FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) { if (fstyle) {
strcpy(fam, fstyle->Family()->Name()); strcpy(fam, fstyle->Family()->Name());
strcpy(sty, fstyle->Name()); strcpy(sty, fstyle->Name());
@@ -1235,7 +1236,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_FONT_DIRECTION: case AS_GET_FONT_DIRECTION:
@@ -1257,8 +1258,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid); link.Read<int32>(&famid);
link.Read<int32>(&styid); link.Read<int32>(&styid);
/* fontserver->Lock(); /* gFontServer->Lock();
FontStyle *fstyle=fontserver->GetStyle(famid,styid); FontStyle *fstyle=gFontServer->GetStyle(famid,styid);
if(fstyle) if(fstyle)
{ {
font_direction dir=fstyle->GetDirection(); font_direction dir=fstyle->GetDirection();
@@ -1273,7 +1274,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.Flush(); fLink.Flush();
// } // }
// fontserver->Unlock(); // gFontServer->Unlock();
break; break;
} }
case AS_GET_STRING_WIDTH: case AS_GET_STRING_WIDTH:
@@ -1354,8 +1355,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid); link.Read<int32>(&famid);
link.Read<int32>(&styid); link.Read<int32>(&styid);
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid); FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) { if (fstyle) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(fstyle->TunedCount()); fLink.Attach<int32>(fstyle->TunedCount());
@@ -1363,7 +1364,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_TUNED_INFO: case AS_GET_TUNED_INFO:
@@ -1396,8 +1397,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid); link.Read<int32>(&famid);
link.Read<int32>(&styid); link.Read<int32>(&styid);
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid); FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) { if (fstyle) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<bool>(fstyle->IsFixedWidth()); fLink.Attach<bool>(fstyle->IsFixedWidth());
@@ -1405,7 +1406,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_FAMILY_NAME: case AS_SET_FAMILY_NAME:
@@ -1420,8 +1421,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
font_family fam; font_family fam;
link.Read(fam, sizeof(font_family)); link.Read(fam, sizeof(font_family));
fontserver->Lock(); gFontServer->Lock();
FontFamily *ffam = fontserver->GetFamily(fam); FontFamily *ffam = gFontServer->GetFamily(fam);
if (ffam) { if (ffam) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(ffam->GetID()); fLink.Attach<uint16>(ffam->GetID());
@@ -1429,7 +1430,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_FAMILY_AND_STYLE: case AS_SET_FAMILY_AND_STYLE:
@@ -1449,8 +1450,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read(fam, sizeof(font_family)); link.Read(fam, sizeof(font_family));
link.Read(sty, sizeof(font_style)); link.Read(sty, sizeof(font_style));
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(fam, sty); FontStyle *fstyle = gFontServer->GetStyle(fam, sty);
if (fstyle) { if (fstyle) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(fstyle->Family()->GetID()); fLink.Attach<uint16>(fstyle->Family()->GetID());
@@ -1459,7 +1460,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_FAMILY_AND_STYLE_FROM_ID: case AS_SET_FAMILY_AND_STYLE_FROM_ID:
@@ -1511,13 +1512,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// Returns: // Returns:
// 1) int32 - # of font families // 1) int32 - # of font families
fontserver->Lock(); gFontServer->Lock();
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(fontserver->CountFamilies()); fLink.Attach<int32>(gFontServer->CountFamilies());
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_COUNT_FONT_STYLES: case AS_COUNT_FONT_STYLES:
@@ -1531,8 +1532,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
font_family fam; font_family fam;
link.Read(fam,sizeof(font_family)); link.Read(fam,sizeof(font_family));
fontserver->Lock(); gFontServer->Lock();
FontFamily *ffam = fontserver->GetFamily(fam); FontFamily *ffam = gFontServer->GetFamily(fam);
if (ffam) { if (ffam) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(ffam->CountStyles()); fLink.Attach<int32>(ffam->CountStyles());
@@ -1540,7 +1541,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_SYSFONT_PLAIN: case AS_SET_SYSFONT_PLAIN:
@@ -1553,8 +1554,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags // 4) uint16 - face flags
// 5) uint32 - font flags // 5) uint32 - font flags
fontserver->Lock(); gFontServer->Lock();
ServerFont *sf = fontserver->GetSystemPlain(); ServerFont *sf = gFontServer->GetSystemPlain();
if (sf) { if (sf) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID()); fLink.Attach<uint16>(sf->FamilyID());
@@ -1566,7 +1567,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_FONT_HEIGHT: case AS_GET_FONT_HEIGHT:
@@ -1582,8 +1583,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint16>(&styid); link.Read<uint16>(&styid);
link.Read<float>(&ptsize); link.Read<float>(&ptsize);
fontserver->Lock(); gFontServer->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid); FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) { if (fstyle) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<font_height>(fstyle->GetHeight(ptsize)); fLink.Attach<font_height>(fstyle->GetHeight(ptsize));
@@ -1591,7 +1592,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_SYSFONT_BOLD: case AS_SET_SYSFONT_BOLD:
@@ -1604,8 +1605,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags // 4) uint16 - face flags
// 5) uint32 - font flags // 5) uint32 - font flags
fontserver->Lock(); gFontServer->Lock();
ServerFont *sf = fontserver->GetSystemBold(); ServerFont *sf = gFontServer->GetSystemBold();
if (sf) { if (sf) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID()); fLink.Attach<uint16>(sf->FamilyID());
@@ -1617,7 +1618,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_SET_SYSFONT_FIXED: case AS_SET_SYSFONT_FIXED:
@@ -1630,8 +1631,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags // 4) uint16 - face flags
// 5) uint32 - font flags // 5) uint32 - font flags
fontserver->Lock(); gFontServer->Lock();
ServerFont *sf = fontserver->GetSystemFixed(); ServerFont *sf = gFontServer->GetSystemFixed();
if (sf) { if (sf) {
fLink.StartMessage(SERVER_TRUE); fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID()); fLink.Attach<uint16>(sf->FamilyID());
@@ -1643,7 +1644,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE); fLink.StartMessage(SERVER_FALSE);
fLink.Flush(); fLink.Flush();
fontserver->Unlock(); gFontServer->Unlock();
break; break;
} }
case AS_GET_GLYPH_SHAPES: case AS_GET_GLYPH_SHAPES:
+77 -87
View File
@@ -1,29 +1,12 @@
//------------------------------------------------------------------------------ /*
// 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 <bpmagic@columbus.rr.com>
// the rights to use, copy, modify, merge, publish, distribute, sublicense, */
// 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: ServerFont.cpp
// Author: DarkWyrm <[email protected]>
// Description: Shadow BFont class
//
//------------------------------------------------------------------------------
#include <ByteOrder.h> #include <ByteOrder.h>
#include <Shape.h> #include <Shape.h>
#include <String.h> #include <String.h>
@@ -40,6 +23,71 @@
#include "ServerFont.h" #include "ServerFont.h"
// functions needed to convert a freetype vector graphics to a BShape
inline BPoint
VectorToPoint(FT_Vector *vector)
{
BPoint result;
result.x = float(int32(vector->x)) / 2097152;
result.y = -float(int32(vector->y)) / 2097152;
return result;
}
int
MoveToFunc(FT_Vector *to, void *user)
{
((BShape *)user)->MoveTo(VectorToPoint(to));
return 0;
}
int
LineToFunc(FT_Vector *to, void *user)
{
((BShape *)user)->LineTo(VectorToPoint(to));
return 0;
}
int
ConicToFunc(FT_Vector *control, FT_Vector *to, void *user)
{
BPoint controls[3];
controls[0] = VectorToPoint(control);
controls[1] = VectorToPoint(to);
controls[2] = controls[1];
((BShape *)user)->BezierTo(controls);
return 0;
}
int
CubicToFunc(FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *user)
{
BPoint controls[3];
controls[0] = VectorToPoint(control1);
controls[1] = VectorToPoint(control2);
controls[2] = VectorToPoint(to);
((BShape *)user)->BezierTo(controls);
return 0;
}
// is_white_space
inline bool
is_white_space(uint16 glyph)
{
// TODO: handle them all!
if (glyph == ' ' || glyph == B_TAB)
return true;
return false;
}
// #pragma mark -
/*! /*!
\brief Constructor \brief Constructor
\param style Style object to which the ServerFont belongs \param style Style object to which the ServerFont belongs
@@ -191,9 +239,9 @@ ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID)
{ {
FontStyle* style = NULL; FontStyle* style = NULL;
if (fontserver->Lock()) { if (gFontServer->Lock()) {
style = fontserver->GetStyle(familyID, styleID); style = gFontServer->GetStyle(familyID, styleID);
fontserver->Unlock(); gFontServer->Unlock();
} }
if (!style) if (!style)
@@ -228,55 +276,6 @@ ServerFont::GetFamilyAndStyle(void) const
return (FamilyID() << 16) | StyleID(); return (FamilyID() << 16) | StyleID();
} }
// functions needed to convert a freetype vector graphics to a BShape
inline BPoint
VectorToPoint(FT_Vector *vector)
{
BPoint result;
result.x = float(int32(vector->x)) / 2097152;
result.y = -float(int32(vector->y)) / 2097152;
return result;
}
int
MoveToFunc(FT_Vector *to, void *user)
{
((BShape *)user)->MoveTo(VectorToPoint(to));
return 0;
}
int
LineToFunc(FT_Vector *to, void *user)
{
((BShape *)user)->LineTo(VectorToPoint(to));
return 0;
}
int
ConicToFunc(FT_Vector *control, FT_Vector *to, void *user)
{
BPoint controls[3];
controls[0] = VectorToPoint(control);
controls[1] = VectorToPoint(to);
controls[2] = controls[1];
((BShape *)user)->BezierTo(controls);
return 0;
}
int
CubicToFunc(FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *user)
{
BPoint controls[3];
controls[0] = VectorToPoint(control1);
controls[1] = VectorToPoint(control2);
controls[2] = VectorToPoint(to);
((BShape *)user)->BezierTo(controls);
return 0;
}
BShape ** BShape **
ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const
@@ -386,15 +385,6 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars,
return escapements; return escapements;
} }
// is_white_space
inline bool
is_white_space(uint16 glyph)
{
// TODO: handle them all!
if (glyph == ' ' || glyph == B_TAB)
return true;
return false;
}
// GetEscapements // GetEscapements
bool bool
+2 -2
View File
@@ -89,8 +89,8 @@ Painter::Painter()
fPatternHandler(new PatternHandler()), fPatternHandler(new PatternHandler()),
fTextRenderer(new AGGTextRenderer()) fTextRenderer(new AGGTextRenderer())
{ {
if (fontserver && fontserver->GetSystemPlain()) if (gFontServer && gFontServer->GetSystemPlain())
fFont = *fontserver->GetSystemPlain(); fFont = *gFontServer->GetSystemPlain();
_UpdateFont(); _UpdateFont();
_UpdateLineWidth(); _UpdateLineWidth();