From 2185eed6d2679fcb56d83287d9939d29608d9f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 23 Aug 2005 21:47:41 +0000 Subject: [PATCH] implemented GetHasGlyphs for real git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14056 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Font.cpp | 5 ++++- src/servers/app/ServerApp.cpp | 11 +++++++--- src/servers/app/ServerFont.cpp | 37 +++++++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 22a6b02e30..4d099b2d79 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -1174,7 +1174,10 @@ BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) con link.Attach(fFamilyID); link.Attach(fStyleID); link.Attach(numChars); - link.Attach(charArray, numChars); + + uint32 bytesInBuffer = UTF8CountBytes(charArray, numChars); + link.Attach(bytesInBuffer); + link.Attach(charArray, bytesInBuffer); if (link.FlushWithReply(code) != B_OK || code != SERVER_TRUE) diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 12801d3c3b..b3639b6b29 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1740,15 +1740,20 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // 1) uint16 - family ID // 2) uint16 - style ID // 3) int32 - numChars - // 4) char - chars (numChars times) + // 4) int32 - numBytes + // 5) char - the char buffer with size numBytes uint16 famid, styid; link.Read(&famid); link.Read(&styid); int32 numChars; link.Read(&numChars); - char charArray[numChars]; - link.Read(&charArray, numChars); + + uint32 numBytes; + link.Read(&numBytes); + + char* charArray = new char[numBytes]; + link.Read(charArray, numBytes); ServerFont font; if (font.SetFamilyAndStyle(famid, styid) == B_OK) { diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index f7f97252a4..cf59cf79d5 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -339,11 +339,42 @@ ServerFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[] if (!fStyle || !charArray || numChars <= 0 || !hasArray) return; - // TODO : implement for real + FT_Face face = fStyle->GetFTFace(); + if (!face) + return; - for (int i = 0; i < numChars; i++) { + FT_Set_Char_Size(face, 0, int32(fSize * 64), 72, 72); + + // UTF8 handling...this can probably be smarter + // Here is what I do in the AGGTextRenderer to handle UTF8... + // It is probably highly inefficient, so it should be reviewed. + int32 numBytes = UTF8CountBytes(charArray, numChars); + int32 convertedLength = numBytes * 2; + char* convertedBuffer = new char[convertedLength]; + + int32 state = 0; + status_t ret; + if ((ret = convert_from_utf8(B_UNICODE_CONVERSION, + charArray, &numBytes, + convertedBuffer, &convertedLength, + &state, B_SUBSTITUTE)) >= B_OK + && (ret = swap_data(B_INT16_TYPE, convertedBuffer, convertedLength, + B_SWAP_BENDIAN_TO_HOST)) >= B_OK) { + + uint16* glyphIndex = (uint16*)convertedBuffer; + // just to be sure + numChars = min_c((uint32)numChars, convertedLength / sizeof(uint16)); + + for (int i = 0; i < numChars; i++) { + hasArray[i] = FT_Get_Char_Index(face, glyphIndex[i]) > 0; + } + } + delete[] convertedBuffer; + + + /*for (int i = 0; i < numChars; i++) { hasArray[i] = true; - } + }*/ }