From d0a688ee924b0f5ec82bf83d66b2fa97109ef452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 9 Nov 2005 18:34:48 +0000 Subject: [PATCH] Introduced and implemented new font command AS_GET_DEFAULT_SYSTEM_FONT that returns the default fonts of the app_server. Moved some font command implementations around to group them a bit better. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14800 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/ServerProtocol.h | 1 + src/servers/app/ServerApp.cpp | 230 ++++++++++++++++----------- 2 files changed, 139 insertions(+), 92 deletions(-) diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index f0cc9ea443..cc9250627e 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -114,6 +114,7 @@ enum { // Font-related server communications AS_SET_SYSTEM_FONT, AS_GET_SYSTEM_FONTS, + AS_GET_SYSTEM_DEFAULT_FONT, AS_GET_FONT_LIST_REVISION, AS_GET_FAMILY_AND_STYLES, diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 07ed5ee2e8..051a2d98d1 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1108,6 +1108,91 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) /* font messages */ + case AS_GET_SYSTEM_DEFAULT_FONT: + { + // input: + // 1) string - font type ("plain", ...) + + const char* family = NULL; + const char* style = NULL; + float size = 0; + + char type[B_OS_NAME_LENGTH]; + status_t status = link.ReadString(type, sizeof(type)); + if (status == B_OK) { + if (!strcmp(type, "plain")) { + // TODO: we should return an *existing* font here... + family = DEFAULT_PLAIN_FONT_FAMILY; + style = DEFAULT_PLAIN_FONT_STYLE; + size = DEFAULT_PLAIN_FONT_SIZE; + } else if (!strcmp(type, "bold")) { + family = DEFAULT_BOLD_FONT_FAMILY; + style = DEFAULT_BOLD_FONT_STYLE; + size = DEFAULT_BOLD_FONT_SIZE; + } else if (!strcmp(type, "fixed")) { + family = DEFAULT_FIXED_FONT_FAMILY; + style = DEFAULT_FIXED_FONT_STYLE; + size = DEFAULT_FIXED_FONT_SIZE; + } else + status = B_BAD_VALUE; + } + + if (status == B_OK) { + // returns: + // 1) string - family + // 2) string - style + // 3) float - size + + fLink.StartMessage(B_OK); + fLink.AttachString(family); + fLink.AttachString(style); + fLink.Attach(size); + } else + fLink.StartMessage(status); + + fLink.Flush(); + break; + } + case AS_GET_SYSTEM_FONTS: + { + FTRACE(("ServerApp %s: AS_GET_SYSTEM_FONTS\n", Signature())); + // Returns: + // 1) uint16 - family ID + // 2) uint16 - style ID + // 3) float - size in points + // 4) uint16 - face flags + // 5) uint32 - font flags + + DesktopSettings settings(fDesktop); + fLink.StartMessage(B_OK); + + for (int32 i = 0; i < 3; i++) { + ServerFont font; + switch (i) { + case 0: + settings.GetDefaultPlainFont(font); + fLink.AttachString("plain"); + break; + case 1: + settings.GetDefaultBoldFont(font); + fLink.AttachString("bold"); + break; + case 2: + settings.GetDefaultFixedFont(font); + fLink.AttachString("fixed"); + break; + } + + fLink.Attach(font.FamilyID()); + fLink.Attach(font.StyleID()); + fLink.Attach(font.Size()); + fLink.Attach(font.Face()); + fLink.Attach(font.Flags()); + } + + fLink.Flush(); + break; + } case AS_GET_FONT_LIST_REVISION: { STRACE(("ServerApp %s: AS_GET_FONT_LIST_REVISION\n", Signature())); @@ -1188,6 +1273,55 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) gFontManager->Unlock(); break; } + case AS_GET_FAMILY_AND_STYLE_IDS: + { + FTRACE(("ServerApp %s: AS_GET_FAMILY_AND_STYLE_IDS\n", Signature())); + // Attached Data: + // 1) font_family - name of font family to use + // 2) font_style - name of style in family + // 3) family ID - only used if 1) is empty + // 4) style ID - only used if 2) is empty + // 5) face - the font's current face + + // Returns: + // 1) uint16 - family ID + // 2) uint16 - style ID + // 3) uint16 - face + + font_family family; + font_style style; + uint16 familyID, styleID; + uint16 face; + if (link.ReadString(family, sizeof(font_family)) == B_OK + && link.ReadString(style, sizeof(font_style)) == B_OK + && link.Read(&familyID) == B_OK + && link.Read(&styleID) == B_OK + && link.Read(&face) == B_OK) { + // get the font and return IDs and face + gFontManager->Lock(); + + FontStyle *fontStyle = gFontManager->GetStyle(family, style, + familyID, styleID, face); + + if (fontStyle != NULL) { + fLink.StartMessage(B_OK); + fLink.Attach(fontStyle->Family()->ID()); + fLink.Attach(fontStyle->ID()); + + // we try to keep the font face close to what we got + face = fontStyle->PreservedFace(face); + + fLink.Attach(face); + } else + fLink.StartMessage(B_NAME_NOT_FOUND); + + gFontManager->Unlock(); + } else + fLink.StartMessage(B_BAD_VALUE); + + fLink.Flush(); + break; + } case AS_GET_FONT_FILE_FORMAT: { FTRACE(("ServerApp %s: AS_GET_FONT_FILE_FORMAT\n", Signature())); @@ -1370,95 +1504,6 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.Flush(); break; } - case AS_GET_FAMILY_AND_STYLE_IDS: - { - FTRACE(("ServerApp %s: AS_GET_FAMILY_AND_STYLE_IDS\n", Signature())); - // Attached Data: - // 1) font_family - name of font family to use - // 2) font_style - name of style in family - // 3) family ID - only used if 1) is empty - // 4) style ID - only used if 2) is empty - // 5) face - the font's current face - - // Returns: - // 1) uint16 - family ID - // 2) uint16 - style ID - // 3) uint16 - face - - font_family family; - font_style style; - uint16 familyID, styleID; - uint16 face; - if (link.ReadString(family, sizeof(font_family)) == B_OK - && link.ReadString(style, sizeof(font_style)) == B_OK - && link.Read(&familyID) == B_OK - && link.Read(&styleID) == B_OK - && link.Read(&face) == B_OK) { - // get the font and return IDs and face - gFontManager->Lock(); - - FontStyle *fontStyle = gFontManager->GetStyle(family, style, - familyID, styleID, face); - - if (fontStyle != NULL) { - fLink.StartMessage(B_OK); - fLink.Attach(fontStyle->Family()->ID()); - fLink.Attach(fontStyle->ID()); - - // we try to keep the font face close to what we got - face = fontStyle->PreservedFace(face); - - fLink.Attach(face); - } else - fLink.StartMessage(B_NAME_NOT_FOUND); - - gFontManager->Unlock(); - } else - fLink.StartMessage(B_BAD_VALUE); - - fLink.Flush(); - break; - } - case AS_GET_SYSTEM_FONTS: - { - FTRACE(("ServerApp %s: AS_GET_SYSTEM_FONTS\n", Signature())); - // Returns: - // 1) uint16 - family ID - // 2) uint16 - style ID - // 3) float - size in points - // 4) uint16 - face flags - // 5) uint32 - font flags - - DesktopSettings settings(fDesktop); - fLink.StartMessage(B_OK); - - for (int32 i = 0; i < 3; i++) { - ServerFont font; - switch (i) { - case 0: - settings.GetDefaultPlainFont(font); - fLink.AttachString("plain"); - break; - case 1: - settings.GetDefaultBoldFont(font); - fLink.AttachString("bold"); - break; - case 2: - settings.GetDefaultFixedFont(font); - fLink.AttachString("fixed"); - break; - } - - fLink.Attach(font.FamilyID()); - fLink.Attach(font.StyleID()); - fLink.Attach(font.Size()); - fLink.Attach(font.Face()); - fLink.Attach(font.Flags()); - } - - fLink.Flush(); - break; - } case AS_GET_FONT_HEIGHT: { FTRACE(("ServerApp %s: AS_GET_FONT_HEIGHT\n", Signature())); @@ -1907,6 +1952,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) break; } + /* screen commands */ + case AS_SCREEN_GET_MODE: { STRACE(("ServerApp %s: AS_SCREEN_GET_MODE\n", Signature())); @@ -2192,13 +2239,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - break; } default: - printf("ServerApp %s received unhandled message code offset %s\n", - Signature(), MsgCodeToBString(code).String()); + printf("ServerApp %s received unhandled message code %ld\n", + Signature(), code); if (link.NeedsReply()) { // the client is now blocking and waiting for a reply!