From 7d5778defa3ca2b0ae8da7604c9e01921b9aaa51 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 1 Apr 2005 09:18:25 +0000 Subject: [PATCH] Added support for GetEscapements() too. Still unfinished. Maybe this should be moved elsewhere? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12216 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/servers/app/ServerFont.h | 2 + src/kits/interface/Font.cpp | 6 ++ src/servers/app/ServerApp.cpp | 76 +++++++++++++++++++++++- src/servers/app/ServerFont.cpp | 51 +++++++++++++++- 4 files changed, 131 insertions(+), 4 deletions(-) diff --git a/headers/private/servers/app/ServerFont.h b/headers/private/servers/app/ServerFont.h index 3e96c9205e..20480a3ad2 100644 --- a/headers/private/servers/app/ServerFont.h +++ b/headers/private/servers/app/ServerFont.h @@ -72,6 +72,8 @@ public: uint16 GlyphCount(void) const { return fStyle->GlyphCount(); } uint16 CharMapCount(void) const { return fStyle->CharMapCount(); } BShape **GetGlyphShapes(const char charArray[], int32 numChars) const; + BPoint *GetEscapements(const char charArray[], int32 numChars, + BPoint offsetArray[]) const; FT_Face GetFTFace() const { return fStyle->GetFTFace(); }; diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 8670995a20..6150f6dfd9 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -966,6 +966,12 @@ BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta * link.StartMessage(AS_GET_ESCAPEMENTS); + link.Attach(fFamilyID); + link.Attach(fStyleID); + link.Attach(fSize); + link.Attach(fRotation); + link.Attach(fFlags); + link.Attach(numChars); if(offsetArray) diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index fd07da4239..581d751435 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1699,7 +1699,7 @@ void ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) // 9) port_id - reply port // Returns: - // 1) BShape with glyph shape + // 1) BShape - glyph shape // numChars times uint16 famid, styid; @@ -1734,10 +1734,82 @@ void ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg) BShape **shapes = font.GetGlyphShapes(charArray, numChars); if (shapes) { replylink.StartMessage(SERVER_TRUE); - for (int32 i = 0; i < numChars; i++) + for (int32 i = 0; i < numChars; i++) { replylink.AttachShape(*shapes[i]); + delete shapes[i]; + } replylink.Flush(); + delete shapes; + } else { + replylink.StartMessage(SERVER_FALSE); + replylink.Flush(); + } + } else { + replylink.StartMessage(SERVER_FALSE); + replylink.Flush(); + } + + break; + } + case AS_GET_ESCAPEMENTS: + { + // Attached Data: + // 1) uint16 - family ID + // 2) uint16 - style ID + // 3) float - point size + // 4) float - rotation + // 5) uint32 - flags + // 6) int32 - numChars + + // 7) char - char -\ both + // 8) BPoint - offset -/ (numChars times) + + // 9) port_id - reply port + + // Returns: + // 1) BPoint - escapement + // numChars times + + uint16 famid, styid; + uint32 flags; + float ptsize, rotation; + + msg.Read(&famid); + msg.Read(&styid); + msg.Read(&ptsize); + msg.Read(&rotation); + msg.Read(&flags); + + int32 numChars; + msg.Read(&numChars); + + char charArray[numChars]; + BPoint offsetArray[numChars]; + for (int32 i = 0; i < numChars; i++) { + msg.Read(&charArray[i]); + msg.Read(&offsetArray[i]); + } + + port_id replyport; + msg.Read(&replyport); + replylink.SetSendPort(replyport); + + ServerFont font; + if (font.SetFamilyAndStyle(famid, styid) == B_OK) { + font.SetSize(ptsize); + font.SetRotation(rotation); + font.SetFlags(flags); + + BPoint *esc = font.GetEscapements(charArray, numChars, offsetArray); + if (esc) { + replylink.StartMessage(SERVER_TRUE); + for (int32 i = 0; i < numChars; i++) { + replylink.Attach(esc[i]); + } + + replylink.Flush(); + delete esc; } else { replylink.StartMessage(SERVER_FALSE); replylink.Flush(); diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 532f358a1f..9a3115280d 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -263,8 +263,8 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const // Multiply togheter FT_Matrix_Multiply(&rmatrix, &smatrix); - FT_Vector pen; - FT_Set_Transform(face, &smatrix, &pen); + //FT_Vector pen; + //FT_Set_Transform(face, &smatrix, &pen); BShape **shapes = (BShape **)malloc(sizeof(BShape *) * numChars); for (int i = 0; i < numChars; i++) { @@ -279,6 +279,53 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const return shapes; } +BPoint * +ServerFont::GetEscapements(const char charArray[], int32 numChars, + BPoint offsetArray[]) const +{ + if (!charArray || numChars <= 0 || !offsetArray) + return NULL; + + FT_Face face = fStyle->GetFTFace(); + if (!face) + return NULL; + + FT_Set_Char_Size(face, 0, int32(fSize) * 64, 72, 72); + + Angle rotation(frotation); + Angle shear(fshear); + + // First, rotate + FT_Matrix rmatrix; + rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000); + rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000); + rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000); + rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000); + + // Next, shear + FT_Matrix smatrix; + smatrix.xx = (FT_Fixed)(0x10000); + smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000); + smatrix.yx = (FT_Fixed)(0); + smatrix.yy = (FT_Fixed)(0x10000); + + // Multiply togheter + FT_Matrix_Multiply(&rmatrix, &smatrix); + + //FT_Vector pen; + //FT_Set_Transform(face, &smatrix, &pen); + + BPoint *escapements = (BPoint *)malloc(sizeof(BPoint) * numChars); + for (int i = 0; i < numChars; i++) { + FT_Load_Char(face, charArray[i], FT_LOAD_NO_BITMAP); + escapements[i].x = float(face->glyph->metrics.width / 64) / fSize; + escapements[i].y = 0; + escapements[i] += offsetArray[i]; + } + + return escapements; +} + /*! \brief Sets the ServerFont instance to whatever font is specified \param familyID ID number of the family to set