From bb96bd0a70d1cd2ac657a59016e70a1df4923909 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 4 Feb 2006 22:20:00 +0000 Subject: [PATCH] * Fixed GetGlyphShapes(). The BShapes that are outputted are correct now but the app_server still cannot draw them correctly. * Changed the allocation to new for GetGlyphShapes() and GetEscapements() as the data is deleted in ServerApp.cpp * Minor cleanup git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16231 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/libs/freetype2/freetype/ftimage.h | 2 +- src/kits/interface/Font.cpp | 10 +++--- src/servers/app/ServerApp.cpp | 24 ++++++------- src/servers/app/ServerFont.cpp | 44 +++++++++++++---------- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/headers/libs/freetype2/freetype/ftimage.h b/headers/libs/freetype2/freetype/ftimage.h index e92ace3a18..f1f9aa2762 100644 --- a/headers/libs/freetype2/freetype/ftimage.h +++ b/headers/libs/freetype2/freetype/ftimage.h @@ -612,7 +612,7 @@ FT_BEGIN_HEADER /* accuracy during scan-conversion). The transformation is simple: */ /* */ /* x' = (x << shift) - delta */ - /* y' = (x << shift) - delta */ + /* y' = (y << shift) - delta */ /* */ /* Set the value of `shift' and `delta' to 0 to get the original */ /* point coordinates. */ diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index dd0a9aff68..ccfad4bcb8 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -1274,7 +1274,7 @@ BFont::GetGlyphShapes(const char charArray[], int32 numChars, BShape *glyphShape // TODO: implement code specifically for passing BShapes to and from the server if (!charArray || numChars < 1 || !glyphShapeArray) return; - + int32 code; BPrivate::AppServerLink link; @@ -1285,9 +1285,11 @@ BFont::GetGlyphShapes(const char charArray[], int32 numChars, BShape *glyphShape link.Attach(fShear); link.Attach(fRotation); link.Attach(fFlags); - 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 != B_OK) @@ -1303,7 +1305,7 @@ BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) con { if (!charArray || numChars < 1 || !hasArray) return; - + int32 code; BPrivate::AppServerLink link; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index a7efa9a781..b643a00769 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1565,7 +1565,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 5) float - rotation // 6) uint32 - flags // 7) int32 - numChars - // 8) char - chars (numChars times) + // 8) int32 - numBytes + // 8) char - chars (bytesInBuffer times) // Returns: // 1) BShape - glyph shape @@ -1582,11 +1583,12 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(&rotation); link.Read(&flags); - int32 numChars; + int32 numChars, numBytes; link.Read(&numChars); + link.Read(&numBytes); - char charArray[numChars]; - link.Read(&charArray, numChars); + char charArray[numBytes]; + link.Read(&charArray, numBytes); ServerFont font; status_t status = font.SetFamilyAndStyle(familyID, styleID); @@ -1620,21 +1622,19 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 1) uint16 - family ID // 2) uint16 - style ID // 3) int32 - numChars - // 4) int32 - numBytes - // 5) char - the char buffer with size numBytes + // 4) int32 - numBytes + // 5) char - the char buffer with size numBytes uint16 familyID, styleID; link.Read(&familyID); link.Read(&styleID); - int32 numChars; + int32 numChars, numBytes; link.Read(&numChars); - - uint32 numBytes; - link.Read(&numBytes); + link.Read(&numBytes); char* charArray = new char[numBytes]; link.Read(charArray, numBytes); - + ServerFont font; status_t status = font.SetFamilyAndStyle(familyID, styleID); if (status == B_OK) { @@ -1738,7 +1738,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) fLink.Attach(escapements[i]); } - delete escapements; + delete[] escapements; } else fLink.StartMessage(B_ERROR); } else diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index e660f0f4d9..a7d7da8877 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -30,11 +30,12 @@ inline BPoint VectorToPoint(FT_Vector *vector) { BPoint result; - result.x = float(int32(vector->x)) / 2097152; - result.y = -float(int32(vector->y)) / 2097152; + result.x = float(vector->x) / 64; + result.y = -float(vector->y) / 64; return result; } + int MoveToFunc(FT_Vector *to, void *user) { @@ -42,6 +43,7 @@ MoveToFunc(FT_Vector *to, void *user) return 0; } + int LineToFunc(FT_Vector *to, void *user) { @@ -49,34 +51,35 @@ LineToFunc(FT_Vector *to, void *user) 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) { @@ -320,54 +323,57 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const { if (!charArray || numChars <= 0) return NULL; - + FT_Outline_Funcs funcs; funcs.move_to = MoveToFunc; funcs.line_to = LineToFunc; funcs.conic_to = ConicToFunc; funcs.cubic_to = CubicToFunc; - + funcs.shift = 0; + funcs.delta = 0; + FaceGetter getter(fStyle); FT_Face face = getter.Face(); 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); - - BShape **shapes = (BShape **)malloc(sizeof(BShape *) * numChars); + + BShape **shapes = new BShape *[numChars]; for (int i = 0; i < numChars; i++) { shapes[i] = new BShape(); shapes[i]->Clear(); + // TODO : this is wrong (the nth char isn't charArray[i]) FT_Load_Char(face, charArray[i], FT_LOAD_NO_BITMAP); FT_Outline outline = face->glyph->outline; FT_Outline_Decompose(&outline, &funcs, shapes[i]); shapes[i]->Close(); } - + return shapes; } @@ -500,7 +506,7 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars, // of the BeBook. Have actual tests been done here? // TODO: handle UTF8... see below!! - BPoint *escapements = (BPoint *)malloc(sizeof(BPoint) * numChars); + BPoint *escapements = new BPoint[numChars]; for (int i = 0; i < numChars; i++) { // TODO : this is wrong (the nth char isn't charArray[i]) FT_Load_Char(face, charArray[i], FT_LOAD_NO_BITMAP);