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

View File

@ -1,36 +1,19 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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 <bpmagic@columbus.rr.com>
// Description: Handler for allocating and freeing area memory for BBitmaps
// on the server side. Utilizes the BGET pool allocator.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
#ifndef BITMAP_MANAGER_H_
#define BITMAP_MANAGER_H_
#include <GraphicsDefs.h>
#include <List.h>
#include <OS.h>
#include <Rect.h>
#include <Locker.h>
#include "BGet++.h"
#include "TokenHandler.h"
@ -64,10 +47,10 @@ class BitmapManager {
area_id fBitmapArea;
int8* fBuffer;
TokenHandler fTokenizer;
sem_id fLock;
BLocker fLock;
AreaPool fMemPool;
};
extern BitmapManager *bitmapmanager;
extern BitmapManager *gBitmapManager;
#endif
#endif /* BITMAP_MANAGER_H_ */

View File

@ -1,29 +1,10 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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 <bpmagic@columbus.rr.com>
// Description: Handles the largest part of the font subsystem
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
#ifndef FONTSERVER_H_
#define FONTSERVER_H_
@ -31,6 +12,8 @@
#include <List.h>
#include <SupportDefs.h>
#include <Font.h>
#include <Locker.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_CACHE_H
@ -43,19 +26,16 @@ class ServerFont;
\class FontServer FontServer.h
\brief Manager for the largest part of the font subsystem
*/
class FontServer
{
class FontServer : public BLocker {
public:
FontServer(void);
~FontServer(void);
bool Lock(void);
void Unlock(void);
/*!
\brief Determines whether the font server has started up properly
\return true if so, false if not.
*/
bool IsInitialized(void) { return init; }
bool IsInitialized(void) { return fInit; }
int32 CountFamilies(void);
int32 CountStyles(const char *family);
void RemoveFamily(const char *family);
@ -79,24 +59,26 @@ public:
bool SetSystemBold(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
*/
void FontsUpdated(void) { need_update=false; }
void FontsUpdated(void) { fNeedUpdate = false; }
protected:
uint16 TranslateStyleToFace(const char *name) const;
FT_CharMap _GetSupportedCharmap(const FT_Face &face);
bool init;
sem_id lock;
BList *families;
ServerFont *plain, *bold, *fixed;
bool need_update;
private:
bool fInit;
BList fFamilies;
ServerFont *fPlain, *fBold, *fFixed;
bool fNeedUpdate;
};
extern FTC_Manager ftmanager;
extern FT_Library ftlib;
extern FontServer *fontserver;
extern FontServer *gFontServer;
#endif
#endif /* FONTSERVER_H_ */

View File

@ -71,7 +71,7 @@ static AppServer *sAppServer;
//RGBColor workspace_default_color(51,102,160);
//! System-wide GUI color object
ColorSet gui_colorset;
ColorSet gGUIColorSet;
/*!
\brief Constructor
@ -104,22 +104,22 @@ AppServer::AppServer(void) :
sAppServer = this;
// Create the font server and scan the proper directories.
fontserver = new FontServer;
fontserver->Lock();
gFontServer = new FontServer;
gFontServer->Lock();
// Used for testing purposes
// TODO: Re-enable scanning of all font directories when server is actually put to use
fontserver->ScanDirectory("/boot/beos/etc/fonts/ttfonts/");
// fontserver->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/");
// fontserver->ScanDirectory("/boot/home/config/fonts/ttfonts/");
// fontserver->ScanDirectory("/boot/home/config/fonts/psfonts/");
fontserver->SaveList();
gFontServer->ScanDirectory("/boot/beos/etc/fonts/ttfonts/");
// gFontServer->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/");
// gFontServer->ScanDirectory("/boot/home/config/fonts/ttfonts/");
// gFontServer->ScanDirectory("/boot/home/config/fonts/psfonts/");
gFontServer->SaveList();
if (!fontserver->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,
if (!gFontServer->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY,
DEFAULT_PLAIN_FONT_STYLE,
DEFAULT_PLAIN_FONT_SIZE) &&
!fontserver->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY,
!gFontServer->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",
@ -129,10 +129,10 @@ AppServer::AppServer(void) :
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_SIZE) &&
!fontserver->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY,
!gFontServer->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",
@ -142,10 +142,10 @@ AppServer::AppServer(void) :
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_SIZE) &&
!fontserver->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY,
!gFontServer->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",
@ -155,12 +155,12 @@ AppServer::AppServer(void) :
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
// is not possible, set colors to the defaults
if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME,&gui_colorset)!=B_OK)
gui_colorset.SetToDefaults();
if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK)
gGUIColorSet.SetToDefaults();
// Set up the Desktop
gDesktop = new Desktop();
@ -170,7 +170,7 @@ AppServer::AppServer(void) :
InitializeColorMap();
// 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
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
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");
/*
@ -210,7 +210,7 @@ AppServer::~AppServer(void)
delete fAppList;
release_sem(fAppListLock);
delete bitmapmanager;
delete gBitmapManager;
delete gDesktop;
@ -221,7 +221,7 @@ AppServer::~AppServer(void)
kill_thread(fCursorThreadID);
kill_thread(fISThreadID);
delete fontserver;
delete gFontServer;
make_decorator=NULL;
*/
@ -504,9 +504,9 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
case AS_UPDATED_CLIENT_FONTLIST:
// received when the client-side global font list has been
// refreshed
fontserver->Lock();
fontserver->FontsUpdated();
fontserver->Unlock();
gFontServer->Lock();
gFontServer->FontsUpdated();
gFontServer->Unlock();
break;
case AS_QUERY_FONTS_CHANGED:
@ -517,9 +517,9 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
// Attached data:
// 1) port_id reply port
fontserver->Lock();
bool needs_update=fontserver->FontsNeedUpdated();
fontserver->Unlock();
gFontServer->Lock();
bool needsUpdate = gFontServer->FontsNeedUpdated();
gFontServer->Unlock();
// Seeing how the client merely wants an answer, we'll skip the BPortLink
// 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)
break;
BPrivate::PortLink replylink(replyport);
replylink.StartMessage(needs_update ? SERVER_TRUE : SERVER_FALSE);
replylink.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE);
replylink.Flush();
break;
}
@ -564,8 +564,8 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg)
release_sem(fAppListLock);
delete gDesktop;
delete bitmapmanager;
delete fontserver;
delete gBitmapManager;
delete gFontServer;
// we are now clear to exit
exit_thread(0);

View File

@ -87,9 +87,8 @@ private:
DisplayDriver *fDriver;
};
extern BitmapManager *bitmapmanager;
extern ColorSet gui_colorset;
extern AppServer *app_server;
extern BitmapManager *gBitmapManager;
extern ColorSet gGUIColorSet;
extern port_id gAppServerPort;
#endif /* _HAIKU_APP_SERVER_H_ */

View File

@ -1,40 +1,28 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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.cpp
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Description: Handler for allocating and freeing area memory for BBitmaps
// on the server side. Utilizes the BGET pool allocator.
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
/** Handler for allocating and freeing area memory for BBitmaps
* on the server side. Utilizes the BGET pool allocator.
*/
#include <new>
#include <stdio.h>
#include <string.h>
#include "ServerBitmap.h"
#include <Autolock.h>
#include "ServerBitmap.h"
#include "BitmapManager.h"
//! 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
#define BITMAP_AREA_SIZE B_PAGE_SIZE * 2
@ -45,9 +33,8 @@ BitmapManager::BitmapManager()
fBitmapArea(B_ERROR),
fBuffer(NULL),
fTokenizer(),
fLock(B_ERROR),
fLock("BitmapManager Lock"),
fMemPool()
{
// When create_area is passed the B_ANY_ADDRESS flag, the address of the area
// is stored in the pointer to a pointer.
@ -58,10 +45,6 @@ BitmapManager::BitmapManager()
if (fBitmapArea < B_OK)
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);
}
@ -75,8 +58,8 @@ BitmapManager::~BitmapManager()
delete bitmap;
}
}
delete_area(fBitmapArea);
delete_sem(fLock);
}
/*!
@ -92,9 +75,14 @@ ServerBitmap*
BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
int32 bytesPerRow, screen_id screen)
{
ServerBitmap* bitmap = NULL;
if (acquire_sem(fLock) >= B_OK) {
bitmap = new(nothrow) ServerBitmap(bounds, space, flags, bytesPerRow);
BAutolock locker(fLock);
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
// bitmaps which accept child views by checking the flags.
@ -118,8 +106,6 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
bitmap = NULL;
}
release_sem(fLock);
}
return bitmap;
}
@ -130,12 +116,14 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags,
void
BitmapManager::DeleteBitmap(ServerBitmap *bitmap)
{
if (acquire_sem(fLock) >= B_OK) {
BAutolock locker(fLock);
if (!locker.IsLocked())
return;
if (fBitmapList.RemoveItem(bitmap)) {
// Server code will require a check to ensure bitmap doesn't have its own area
fMemPool.ReleaseBuffer(bitmap->fBuffer);
delete bitmap;
}
release_sem(fLock);
}
}

View File

@ -5,28 +5,29 @@
* Author: DarkWyrm <bpmagic@columbus.rr.com>
*/
#include <Directory.h>
#include <Rect.h>
#include <File.h>
#include <Message.h>
#include <Entry.h>
#include "AppServer.h"
#include "ColorSet.h"
#include "DefaultDecorator.h"
#include "ServerConfig.h"
#include "DecorManager.h"
// Globals
DecorManager gDecorManager;
extern ColorSet gui_colorset;
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
class DecorInfo
{
class DecorInfo {
public:
DecorInfo(const image_id &id, const char *name,
create_decorator *alloc);
@ -37,19 +38,21 @@ public:
int32 wlook, int32 wfeel,
int32 wflags, DisplayDriver *ddriver);
private:
image_id fID;
BString fName;
create_decorator *fAllocator;
};
DecorInfo::DecorInfo(const image_id &id, const char *name, create_decorator *alloc)
: fID(id),
:
fID(id),
fName(name),
fAllocator(alloc)
{
}
DecorInfo::~DecorInfo(void)
{
// 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.
}
Decorator *
DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel,
int32 wflags, DisplayDriver *ddriver)
@ -71,17 +75,22 @@ DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel,
dec->SetDriver(ddriver);
gui_colorset.Lock();
dec->SetColors(gui_colorset);
gui_colorset.Unlock();
gGUIColorSet.Lock();
dec->SetColors(gGUIColorSet);
gGUIColorSet.Unlock();
dec->SetTitle(title);
return dec;
}
DecorManager::DecorManager(void)
: fDecorList(0),
// #pragma mark -
DecorManager::DecorManager()
:
fDecorList(0),
fCurrentDecor(NULL)
{
// Start with the default decorator - index is always 0
@ -100,11 +109,9 @@ DecorManager::DecorManager(void)
BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY);
// 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;
if( settings.FindString("decorator", &itemtext) == B_OK )
{
if (settings.FindString("decorator", &itemtext) == B_OK) {
fCurrentDecor = FindDecor(itemtext.String());
}
}
@ -113,13 +120,15 @@ DecorManager::DecorManager(void)
fCurrentDecor = (DecorInfo*) fDecorList.ItemAt(0L);
}
DecorManager::~DecorManager(void)
DecorManager::~DecorManager()
{
EmptyList();
}
void
DecorManager::RescanDecorators(void)
DecorManager::RescanDecorators()
{
BDirectory dir(DECORATORS_DIR);
@ -129,8 +138,7 @@ DecorManager::RescanDecorators(void)
entry_ref ref;
BString fullpath;
while(dir.GetNextRef(&ref)==B_OK)
{
while (dir.GetNextRef(&ref) == B_OK) {
fullpath = DECORATORS_DIR;
fullpath += ref.name;
@ -158,9 +166,7 @@ DecorManager::RescanDecorators(void)
// Get the instantiation function
status_t status = get_image_symbol(tempID, "instantiate_decorator",
B_SYMBOL_TYPE_TEXT, (void**)&createfunc);
if (status != B_OK)
{
if (status != B_OK) {
unload_add_on(tempID);
continue;
}
@ -169,6 +175,7 @@ DecorManager::RescanDecorators(void)
}
}
Decorator *
DecorManager::AllocateDecorator(BRect rect, const char *title,
int32 wlook, int32 wfeel,
@ -176,8 +183,7 @@ DecorManager::AllocateDecorator(BRect rect, const char *title,
{
// 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.
debugger("DecorManager::AllocateDecorator has a NULL decorator");
return NULL;
@ -186,25 +192,27 @@ DecorManager::AllocateDecorator(BRect rect, const char *title,
return fCurrentDecor->Instantiate(rect, title, wlook, wfeel, wflags, ddriver);
}
int32
DecorManager::CountDecorators(void) const
{
return fDecorList.CountItems();
}
int32
DecorManager::GetDecorator(void) const
{
return fDecorList.IndexOf(fCurrentDecor);
}
bool
DecorManager::SetDecorator(const int32 &index)
{
DecorInfo *newDecInfo = (DecorInfo*)fDecorList.ItemAt(index);
if(newDecInfo)
{
if (newDecInfo) {
fCurrentDecor = newDecInfo;
return true;
}
@ -212,13 +220,13 @@ DecorManager::SetDecorator(const int32 &index)
return false;
}
bool
DecorManager::SetR5Decorator(const int32 &value)
{
BString string;
switch(value)
{
switch (value) {
case 0: string = "BeOS"; break;
case 1: string = "AmigaOS"; break;
case 2: string = "Windows"; break;
@ -228,8 +236,7 @@ DecorManager::SetR5Decorator(const int32 &value)
}
DecorInfo *newDecInfo = FindDecor(string.String());
if(newDecInfo)
{
if (newDecInfo) {
fCurrentDecor = newDecInfo;
return true;
}
@ -237,6 +244,7 @@ DecorManager::SetR5Decorator(const int32 &value)
return false;
}
const char *
DecorManager::GetDecoratorName(const int32 &index)
{
@ -248,11 +256,11 @@ DecorManager::GetDecoratorName(const int32 &index)
return NULL;
}
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);
delete info;
}
@ -260,14 +268,14 @@ DecorManager::EmptyList(void)
fCurrentDecor = NULL;
}
DecorInfo*
DecorManager::FindDecor(const char *name)
{
if (!name)
return NULL;
for(int32 i=0; i<fDecorList.CountItems(); i++)
{
for (int32 i = 0; i < fDecorList.CountItems(); i++) {
DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i);
if (info && strcmp(name, info->GetName()) == 0)
@ -277,8 +285,13 @@ DecorManager::FindDecor(const char *name)
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)
Decorator*
create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags)
{
return new DefaultDecorator(rect, wlook, wfeel, wflags);
}

View File

@ -1,29 +1,13 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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: DefaultDecorator.cpp
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Description: Default and fallback decorator for the app_server
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
/** Default and fallback decorator for the app_server - the yellow tabs */
#include <stdio.h>
@ -53,7 +37,8 @@ DefaultDecorator::DefaultDecorator(BRect rect, int32 wlook, int32 wfeel, int32 w
: Decorator(rect, wlook, wfeel, wflags),
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.SetSpacing(B_STRING_SPACING);
SetFont(&font);

View File

@ -1,29 +1,14 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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.cpp
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Description: Handles the largest part of the font subsystem
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
/** Handles the largest part of the font subsystem */
#include <String.h>
#include <Directory.h>
#include <Entry.h>
@ -37,27 +22,37 @@
#include <ServerFont.h>
#include "ServerConfig.h"
extern FTC_Manager ftmanager;
FT_Library ftlib;
FontServer *fontserver=NULL;
FontServer *gFontServer = NULL;
//#define PRINT_FONT_LIST
/*!
\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)
{
CachedFace face = (CachedFace) face_id;
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
FontServer::FontServer(void)
: BLocker("font server lock"),
fFamilies(20),
fPlain(NULL),
fBold(NULL),
fFixed(NULL)
{
lock=create_sem(1,"fontserver_lock");
init=(FT_Init_FreeType(&ftlib)==0)?true:false;
fInit = FT_Init_FreeType(&ftlib) == 0;
/*
Fire up the font caching subsystem.
@ -66,37 +61,18 @@ FontServer::FontServer(void)
these numbers in the future to maximize performance for your "average"
application.
*/
if(FTC_Manager_New(ftlib,0,0,0,&face_requester,NULL,&ftmanager)!=0
&& init)
init=false;
families=new BList(20);
plain=NULL;
bold=NULL;
fixed=NULL;
if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0)
fInit = false;
}
//! Frees items allocated in the constructor and shuts down FreeType
FontServer::~FontServer(void)
{
delete_sem(lock);
delete families;
FTC_Manager_Done(ftmanager);
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
@ -104,78 +80,83 @@ void FontServer::Unlock(void)
*/
int32 FontServer::CountFamilies(void)
{
if(init)
return families->CountItems();
if (fInit)
return fFamilies.CountItems();
return 0;
}
/*!
\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 FontServer::CountStyles(const char *family)
int32
FontServer::CountStyles(const char *familyName)
{
FontFamily *f=GetFamily(family);
if(f)
{
return f->CountStyles();
}
FontFamily *family = GetFamily(familyName);
if (family)
return family->CountStyles();
return 0;
}
/*!
\brief Removes a font family from the font list
\param family The family to remove
*/
void FontServer::RemoveFamily(const char *family)
void
FontServer::RemoveFamily(const char *familyName)
{
FontFamily *f=GetFamily(family);
if(f)
{
families->RemoveItem(f);
delete f;
FontFamily *family = GetFamily(familyName);
if (family) {
fFamilies.RemoveItem(family);
delete family;
}
}
const char *FontServer::GetFamilyName(uint16 id) const
const char*
FontServer::GetFamilyName(uint16 id) const
{
FontFamily *fam;
for(int32 i=0; i<families->CountItems(); i++)
{
fam=(FontFamily*)families->ItemAt(i);
if(fam && fam->GetID()==id)
return fam->Name();
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
FontFamily* family = (FontFamily*)fFamilies.ItemAt(i);
if (family && family->GetID() == id)
return family->Name();
}
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 *sty;
for(int32 i=0; i<families->CountItems(); i++)
{
sty=fam->GetStyle(i);
if(sty && sty->GetID()==id)
return sty->Name();
}
FontStyle* style = GetStyle(familyName, id);
if (style != NULL)
return style->Name();
return NULL;
}
FontStyle *FontServer::GetStyle(const char *family, uint16 id) const
FontStyle*
FontServer::GetStyle(const char* familyName, uint16 id) const
{
FontFamily *fam=GetFamily(family);
FontStyle *sty;
for(int32 i=0; i<families->CountItems(); i++)
{
sty=fam->GetStyle(i);
if(sty && sty->GetID()==id)
return sty;
FontFamily* family = GetFamily(familyName);
for (int32 i = 0; i < family->CountStyles(); i++) {
FontStyle* style = family->GetStyle(i);
if (style && style->GetID() == id)
return style;
}
return NULL;
}
/*!
\brief Protected function which locates a FontFamily object
\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.
*/
FontFamily *FontServer::GetFamily(const char *name) const
FontFamily*
FontServer::GetFamily(const char* name) const
{
if(!init)
if (!fInit)
return NULL;
int32 count=families->CountItems(), i;
FontFamily *family;
for(i=0; i<count; i++)
{
family=(FontFamily*)families->ItemAt(i);
if(strcmp(family->Name(),name)==0)
int32 count = fFamilies.CountItems();
for (int32 i = 0; i < count; i++) {
FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
if (!strcmp(family->Name(), name))
return family;
}
return NULL;
}
/*!
\brief Scan a folder for all valid fonts
\param fontspath Path of the folder to scan.
@ -212,41 +196,27 @@ FontFamily *FontServer::GetFamily(const char *name) const
- \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).
*/
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
// 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
BDirectory dir;
status_t status = dir.SetTo(directoryPath);
if (status != B_OK)
return status;
BEntry entry;
while (dir.GetNextEntry(&entry) == B_OK) {
BPath path;
entry_ref ref;
status_t stat;
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)
status = entry.GetPath(&path);
if (status < B_OK)
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)
continue;
@ -256,29 +226,27 @@ status_t FontServer::ScanDirectory(const char *fontspath)
// utf8 -> glyph-index mapping everywhere to handle other
// char maps. We could also ignore fonts that don't support
// the Unicode lookup as a temporary "solution".
/* charmap=_GetSupportedCharmap(face);
if(!charmap)
{
#if 0
FT_CharMap charmap = _GetSupportedCharmap(face);
if (!charmap) {
FT_Done_Face(face);
continue;
}
face->charmap=charmap;*/
face->charmap = charmap;
#endif
family=GetFamily(face->family_name);
if(!family)
{
FontFamily *family = GetFamily(face->family_name);
if (family == NULL) {
#ifdef PRINT_FONT_LIST
printf("Font Family: %s\n", face->family_name);
#endif
family=new FontFamily(face->family_name,families->CountItems());
families->AddItem(family);
family = new FontFamily(face->family_name, fFamilies.CountItems());
fFamilies.AddItem(family);
}
if(family->HasStyle(face->style_name))
{
if (family->HasStyle(face->style_name)) {
FT_Done_Face(face);
continue;
}
@ -287,69 +255,59 @@ status_t FontServer::ScanDirectory(const char *fontspath)
printf("\tFont Style: %s\n", face->style_name);
#endif
style=new FontStyle(path.Path(),face);
FontStyle *style = new FontStyle(path.Path(), face);
if (!family->AddStyle(style))
delete style;
else
validcount++;
// FT_Face is kept open in FontStyle and will be unset in the
// FontStyle destructor
}
} // end for(i<refcount)
dir.Unset();
need_update=true;
fNeedUpdate = true;
return B_OK;
}
/*!
\brief Finds and returns the first valid charmap in a font
\param face Font handle obtained from FT_Load_Face()
\return An FT_CharMap or NULL if unsuccessful
*/
FT_CharMap FontServer::_GetSupportedCharmap(const FT_Face &face)
{
int32 i;
FT_CharMap charmap;
for(i=0; i< face->num_charmaps; i++)
{
charmap=face->charmaps[i];
switch(charmap->platform_id)
FT_CharMap
FontServer::_GetSupportedCharmap(const FT_Face& face)
{
for (int32 i = 0; i < face->num_charmaps; i++) {
FT_CharMap 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;
return NULL;
}
/*!
\brief This saves all family names and styles to the file specified in
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
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;
FontFamily *fam;
@ -424,85 +383,95 @@ void FontServer::SaveList(void)
*/
}
/*!
\brief Retrieves the FontStyle object
\param family The font's family
\param style The font's style
\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;
}
/*!
\brief Retrieves the FontStyle object
\param family ID for the font's family
\param style ID of the font's style
\return The FontStyle having those attributes or NULL if not available
*/
FontStyle *FontServer::GetStyle(const uint16 &familyid, const uint16 &styleid)
FontStyle*
FontServer::GetStyle(const uint16& familyID, const uint16& styleID)
{
FontFamily *fam=GetFamily(familyid);
if(fam)
{
FontStyle *sty=fam->GetStyle(styleid);
return sty;
}
FontFamily *family = GetFamily(familyID);
if (family)
return family->GetStyle(styleID);
return NULL;
}
FontFamily *FontServer::GetFamily(const uint16 &familyid) const
FontFamily*
FontServer::GetFamily(const uint16& familyID) const
{
for(int32 i=0; i<families->CountItems(); i++)
{
FontFamily *fam=(FontFamily*)families->ItemAt(i);
if(fam->GetID()==familyid)
return fam;
for (int32 i = 0; i < fFamilies.CountItems(); i++) {
FontFamily *family = (FontFamily*)fFamilies.ItemAt(i);
if (family->GetID() == familyID)
return family;
}
return NULL;
}
/*!
\brief Returns the current object used for the regular style
\return A ServerFont pointer which is the plain font.
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
\return A ServerFont pointer which is the bold font.
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
\return A ServerFont pointer which is the fixed font.
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
\param family Name of the font's family
@ -511,22 +480,20 @@ ServerFont *FontServer::GetSystemFixed(void)
\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);
if(!fam)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
FontStyle *style = GetStyle(familyName, styleName);
if (style == NULL)
return false;
if(plain)
delete plain;
delete fPlain;
fPlain = new ServerFont(style, size);
plain=new ServerFont(sty,size);
return true;
}
/*!
\brief Sets the system's bold font to the specified family and style
\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.
*/
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);
if(!fam)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
FontStyle *style = GetStyle(familyName, styleName);
if (style == NULL)
return false;
if(bold)
delete bold;
delete fBold;
fBold = new ServerFont(style, size);
bold=new ServerFont(sty,size);
return true;
}
/*!
\brief Sets the system's fixed font to the specified family and style
\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.
*/
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);
if(!fam)
return false;
FontStyle *sty=fam->GetStyle(style);
if(!sty)
FontStyle *style = GetStyle(familyName, styleName);
if (style == NULL)
return false;
if(fixed)
delete fixed;
delete fFixed;
fFixed = new ServerFont(style, size);
fixed=new ServerFont(sty,size);
return true;
}

View File

@ -1,31 +1,16 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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: LayerData.cpp
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Adi Oanca <adioanca@mymail.ro>
// Stephan Aßmus <superstippi@gmx.de>
// Description: Data classes for working with BView states and draw parameters
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* Adi Oanca <adioanca@mymail.ro>
* Stephan Aßmus <superstippi@gmx.de>
*/
/** Data classes for working with BView states and draw parameters */
#include <stdio.h>
#include <Region.h>
@ -55,8 +40,8 @@ DrawData::DrawData()
fLineJoinMode(B_BEVEL_JOIN),
fMiterLimit(B_DEFAULT_MITER_LIMIT)
{
if (fontserver && fontserver->GetSystemPlain())
fFont = *(fontserver->GetSystemPlain());
if (gFontServer && gFontServer->GetSystemPlain())
fFont = *(gFontServer->GetSystemPlain());
fEscapementDelta.space = 0;
fEscapementDelta.nonspace = 0;

View File

@ -10,6 +10,7 @@
* Axel Dörfler, axeld@pinc-software.de
*/
#include <stdio.h>
#include <string.h>
@ -765,7 +766,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&flags);
link.Read<int32>(&bytesPerRow);
if (link.Read<screen_id>(&screenID) == B_OK) {
bitmap = bitmapmanager->CreateBitmap(frame, colorSpace, flags,
bitmap = gBitmapManager->CreateBitmap(frame, colorSpace, flags,
bytesPerRow, screenID);
}
@ -805,7 +806,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
STRACE(("ServerApp %s: Deleting Bitmap %ld\n", fSignature.String(), id));
fBitmapList.RemoveItem(bitmap);
bitmapmanager->DeleteBitmap(bitmap);
gBitmapManager->DeleteBitmap(bitmap);
fLink.StartMessage(SERVER_TRUE);
} else
fLink.StartMessage(SERVER_FALSE);
@ -1076,13 +1077,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// using a ColorSet object
gui_colorset.Lock();
gGUIColorSet.Lock();
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<ColorSet>(gui_colorset);
fLink.Attach<ColorSet>(gGUIColorSet);
fLink.Flush();
gui_colorset.Unlock();
gGUIColorSet.Unlock();
break;
}
@ -1094,9 +1095,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// Attached data:
// 1) ColorSet new colors to use
gui_colorset.Lock();
link.Read<ColorSet>(&gui_colorset);
gui_colorset.Unlock();
gGUIColorSet.Lock();
link.Read<ColorSet>(&gGUIColorSet);
gGUIColorSet.Unlock();
BroadcastToAllApps(AS_UPDATE_COLORS);
break;
@ -1106,12 +1107,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
STRACE(("ServerApp %s: Get UI color\n", fSignature.String()));
RGBColor color;
int32 whichcolor;
link.Read<int32>(&whichcolor);
int32 whichColor;
link.Read<int32>(&whichColor);
gui_colorset.Lock();
color = gui_colorset.AttributeToColor(whichcolor);
gui_colorset.Unlock();
gGUIColorSet.Lock();
color = gGUIColorSet.AttributeToColor(whichColor);
gGUIColorSet.Unlock();
fLink.StartMessage(SERVER_TRUE);
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
// refreshed
fontserver->Lock();
fontserver->FontsUpdated();
fontserver->Unlock();
gFontServer->Lock();
gFontServer->FontsUpdated();
gFontServer->Unlock();
break;
}
case AS_QUERY_FONTS_CHANGED:
@ -1157,8 +1158,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
int32 id;
link.Read<int32>(&id);
fontserver->Lock();
FontFamily *ffamily = fontserver->GetFamily(id);
gFontServer->Lock();
FontFamily *ffamily = gFontServer->GetFamily(id);
if (ffamily) {
font_family fam;
strcpy(fam, ffamily->Name());
@ -1168,7 +1169,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_STYLE_NAME:
@ -1189,8 +1190,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read(fam,sizeof(font_family));
link.Read<int32>(&styid);
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(fam, styid);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(fam, styid);
if (fstyle) {
font_family sty;
strcpy(sty, fstyle->Name());
@ -1202,7 +1203,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_FAMILY_AND_STYLE:
@ -1222,8 +1223,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint16>(&famid);
link.Read<uint16>(&styid);
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) {
strcpy(fam, fstyle->Family()->Name());
strcpy(sty, fstyle->Name());
@ -1235,7 +1236,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_FONT_DIRECTION:
@ -1257,8 +1258,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid);
link.Read<int32>(&styid);
/* fontserver->Lock();
FontStyle *fstyle=fontserver->GetStyle(famid,styid);
/* gFontServer->Lock();
FontStyle *fstyle=gFontServer->GetStyle(famid,styid);
if(fstyle)
{
font_direction dir=fstyle->GetDirection();
@ -1273,7 +1274,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.Flush();
// }
// fontserver->Unlock();
// gFontServer->Unlock();
break;
}
case AS_GET_STRING_WIDTH:
@ -1354,8 +1355,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid);
link.Read<int32>(&styid);
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(fstyle->TunedCount());
@ -1363,7 +1364,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_TUNED_INFO:
@ -1396,8 +1397,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<int32>(&famid);
link.Read<int32>(&styid);
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<bool>(fstyle->IsFixedWidth());
@ -1405,7 +1406,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_SET_FAMILY_NAME:
@ -1420,8 +1421,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
font_family fam;
link.Read(fam, sizeof(font_family));
fontserver->Lock();
FontFamily *ffam = fontserver->GetFamily(fam);
gFontServer->Lock();
FontFamily *ffam = gFontServer->GetFamily(fam);
if (ffam) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(ffam->GetID());
@ -1429,7 +1430,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
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(sty, sizeof(font_style));
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(fam, sty);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(fam, sty);
if (fstyle) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(fstyle->Family()->GetID());
@ -1459,7 +1460,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_SET_FAMILY_AND_STYLE_FROM_ID:
@ -1511,13 +1512,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// Returns:
// 1) int32 - # of font families
fontserver->Lock();
gFontServer->Lock();
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(fontserver->CountFamilies());
fLink.Attach<int32>(gFontServer->CountFamilies());
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_COUNT_FONT_STYLES:
@ -1531,8 +1532,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
font_family fam;
link.Read(fam,sizeof(font_family));
fontserver->Lock();
FontFamily *ffam = fontserver->GetFamily(fam);
gFontServer->Lock();
FontFamily *ffam = gFontServer->GetFamily(fam);
if (ffam) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<int32>(ffam->CountStyles());
@ -1540,7 +1541,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_SET_SYSFONT_PLAIN:
@ -1553,8 +1554,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags
// 5) uint32 - font flags
fontserver->Lock();
ServerFont *sf = fontserver->GetSystemPlain();
gFontServer->Lock();
ServerFont *sf = gFontServer->GetSystemPlain();
if (sf) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID());
@ -1566,7 +1567,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_FONT_HEIGHT:
@ -1582,8 +1583,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
link.Read<uint16>(&styid);
link.Read<float>(&ptsize);
fontserver->Lock();
FontStyle *fstyle = fontserver->GetStyle(famid, styid);
gFontServer->Lock();
FontStyle *fstyle = gFontServer->GetStyle(famid, styid);
if (fstyle) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<font_height>(fstyle->GetHeight(ptsize));
@ -1591,7 +1592,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_SET_SYSFONT_BOLD:
@ -1604,8 +1605,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags
// 5) uint32 - font flags
fontserver->Lock();
ServerFont *sf = fontserver->GetSystemBold();
gFontServer->Lock();
ServerFont *sf = gFontServer->GetSystemBold();
if (sf) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID());
@ -1617,7 +1618,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_SET_SYSFONT_FIXED:
@ -1630,8 +1631,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
// 4) uint16 - face flags
// 5) uint32 - font flags
fontserver->Lock();
ServerFont *sf = fontserver->GetSystemFixed();
gFontServer->Lock();
ServerFont *sf = gFontServer->GetSystemFixed();
if (sf) {
fLink.StartMessage(SERVER_TRUE);
fLink.Attach<uint16>(sf->FamilyID());
@ -1643,7 +1644,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
fLink.StartMessage(SERVER_FALSE);
fLink.Flush();
fontserver->Unlock();
gFontServer->Unlock();
break;
}
case AS_GET_GLYPH_SHAPES:

View File

@ -1,29 +1,12 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// 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 <bpmagic@columbus.rr.com>
// Description: Shadow BFont class
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
#include <ByteOrder.h>
#include <Shape.h>
#include <String.h>
@ -40,6 +23,71 @@
#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
\param style Style object to which the ServerFont belongs
@ -191,9 +239,9 @@ ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID)
{
FontStyle* style = NULL;
if (fontserver->Lock()) {
style = fontserver->GetStyle(familyID, styleID);
fontserver->Unlock();
if (gFontServer->Lock()) {
style = gFontServer->GetStyle(familyID, styleID);
gFontServer->Unlock();
}
if (!style)
@ -228,55 +276,6 @@ ServerFont::GetFamilyAndStyle(void) const
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 **
ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const
@ -386,15 +385,6 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars,
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
bool

View File

@ -89,8 +89,8 @@ Painter::Painter()
fPatternHandler(new PatternHandler()),
fTextRenderer(new AGGTextRenderer())
{
if (fontserver && fontserver->GetSystemPlain())
fFont = *fontserver->GetSystemPlain();
if (gFontServer && gFontServer->GetSystemPlain())
fFont = *gFontServer->GetSystemPlain();
_UpdateFont();
_UpdateLineWidth();