Added support for BFont::GetGlyphShapes. Not finished yet and untested, delivery method as to be changed.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12214 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2005-04-01 07:00:32 +00:00
parent 3661cae99c
commit ebf8af66c9
5 changed files with 197 additions and 3 deletions
+1
View File
@@ -71,6 +71,7 @@ public:
int32 TunedCount(void) const { return fStyle->TunedCount(); } int32 TunedCount(void) const { return fStyle->TunedCount(); }
uint16 GlyphCount(void) const { return fStyle->GlyphCount(); } uint16 GlyphCount(void) const { return fStyle->GlyphCount(); }
uint16 CharMapCount(void) const { return fStyle->CharMapCount(); } uint16 CharMapCount(void) const { return fStyle->CharMapCount(); }
BShape **GetGlyphShapes(const char charArray[], int32 numChars) const;
FT_Face GetFTFace() const { return fStyle->GetFTFace(); }; FT_Face GetFTFace() const { return fStyle->GetFTFace(); };
+7 -1
View File
@@ -1147,8 +1147,14 @@ BFont::GetGlyphShapes(const char charArray[], int32 numChars, BShape *glyphShape
link.StartMessage(AS_GET_GLYPH_SHAPES); link.StartMessage(AS_GET_GLYPH_SHAPES);
link.Attach<int32>(numChars); link.Attach<uint16>(fFamilyID);
link.Attach<uint16>(fStyleID);
link.Attach<float>(fSize);
link.Attach<float>(fShear);
link.Attach<float>(fRotation);
link.Attach<uint32>(fFlags);
link.Attach<int32>(numChars);
for(int32 i = 0; i < numChars; i++) for(int32 i = 0; i < numChars; i++)
link.Attach<char>(charArray[i]); link.Attach<char>(charArray[i]);
+1 -1
View File
@@ -146,7 +146,6 @@ uint16 FontStyle::TranslateStyleToFace(const char *name) const
if(str.IFindFirst("bold")!=B_ERROR) if(str.IFindFirst("bold")!=B_ERROR)
return B_BOLD_FACE; return B_BOLD_FACE;
if(str.IFindFirst("italic")!=B_ERROR) if(str.IFindFirst("italic")!=B_ERROR)
return B_ITALIC_FACE; return B_ITALIC_FACE;
if(str.IFindFirst("oblique")!=B_ERROR) if(str.IFindFirst("oblique")!=B_ERROR)
@@ -155,6 +154,7 @@ uint16 FontStyle::TranslateStyleToFace(const char *name) const
return B_REGULAR_FACE; return B_REGULAR_FACE;
} }
/*! /*!
\brief Constructor \brief Constructor
\param namestr Name of the family \param namestr Name of the family
+79
View File
@@ -34,6 +34,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ScrollBar.h> #include <ScrollBar.h>
#include <Shape.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
#include "AppServer.h" #include "AppServer.h"
@@ -1684,6 +1685,84 @@ void ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg)
break; break;
} }
case AS_GET_GLYPH_SHAPES:
{
// Attached Data:
// 1) uint16 - family ID
// 2) uint16 - style ID
// 3) float - point size
// 4) float - shear
// 5) float - rotation
// 6) uint32 - flags
// 7) int32 - numChars
// 8) char - chars (numChars times)
// 9) port_id - reply port
// Returns:
// 1) size_t - message size
// 2) flattened BMessage containing archived BShape
// numChars times
uint16 famid, styid;
uint32 flags;
float ptsize, shear, rotation;
msg.Read<uint16>(&famid);
msg.Read<uint16>(&styid);
msg.Read<float>(&ptsize);
msg.Read<float>(&shear);
msg.Read<float>(&rotation);
msg.Read<uint32>(&flags);
int32 numChars;
msg.Read<int32>(&numChars);
char charArray[numChars];
for (int32 i = 0; i < numChars; i++)
msg.Read<char>(&charArray[i]);
port_id replyport;
msg.Read<port_id>(&replyport);
replylink.SetSendPort(replyport);
ServerFont font;
if (font.SetFamilyAndStyle(famid, styid) == B_OK) {
font.SetSize(ptsize);
font.SetShear(shear);
font.SetRotation(rotation);
font.SetFlags(flags);
BShape **shapes = font.GetGlyphShapes(charArray, numChars);
if (shapes) {
replylink.StartMessage(SERVER_TRUE);
for (int32 i = 0; i < numChars; i++) {
BMessage message;
if (shapes[i]->Archive(&message) != B_OK)
break;
delete shapes[i];
size_t size = message.FlattenedSize();
char *buffer = new char[size];
if (message.Flatten(buffer, size) != B_OK) {
delete buffer;
break;
}
replylink.Attach<size_t>(size);
replylink.Attach(buffer, size);
}
replylink.Flush();
} else {
replylink.StartMessage(SERVER_FALSE);
replylink.Flush();
}
} else {
replylink.StartMessage(SERVER_FALSE);
replylink.Flush();
}
break;
}
default: default:
{ {
STRACE(("ServerApp %s received unhandled message code offset %s\n",fSignature.String(), STRACE(("ServerApp %s received unhandled message code offset %s\n",fSignature.String(),
+108
View File
@@ -24,8 +24,12 @@
// Description: Shadow BFont class // Description: Shadow BFont class
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#include <Shape.h>
#include "ServerFont.h" #include "ServerFont.h"
#include "FontServer.h" #include "FontServer.h"
#include "Angle.h"
#include FT_FREETYPE_H
#include FT_OUTLINE_H
/*! /*!
\brief Constructor \brief Constructor
@@ -171,6 +175,110 @@ void ServerFont::Height(font_height *fh)
*fh=fStyle->GetHeight(fSize); *fh=fStyle->GetHeight(fSize);
} }
// 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
{
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;
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);
BShape **shapes = (BShape **)malloc(sizeof(BShape *) * numChars);
for (int i = 0; i < numChars; i++) {
shapes[i] = new BShape();
shapes[i]->Clear();
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;
}
/*! /*!
\brief Sets the ServerFont instance to whatever font is specified \brief Sets the ServerFont instance to whatever font is specified
\param familyID ID number of the family to set \param familyID ID number of the family to set