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
This commit is contained in:
Michael Lotz 2005-04-01 09:18:25 +00:00
parent c2da902f2e
commit 7d5778defa
4 changed files with 131 additions and 4 deletions

View File

@ -72,6 +72,8 @@ public:
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; 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(); }; FT_Face GetFTFace() const { return fStyle->GetFTFace(); };

View File

@ -966,6 +966,12 @@ BFont::GetEscapements(const char charArray[], int32 numChars, escapement_delta *
link.StartMessage(AS_GET_ESCAPEMENTS); link.StartMessage(AS_GET_ESCAPEMENTS);
link.Attach<uint16>(fFamilyID);
link.Attach<uint16>(fStyleID);
link.Attach<float>(fSize);
link.Attach<float>(fRotation);
link.Attach<uint32>(fFlags);
link.Attach<int32>(numChars); link.Attach<int32>(numChars);
if(offsetArray) if(offsetArray)

View File

@ -1699,7 +1699,7 @@ void ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg)
// 9) port_id - reply port // 9) port_id - reply port
// Returns: // Returns:
// 1) BShape with glyph shape // 1) BShape - glyph shape
// numChars times // numChars times
uint16 famid, styid; uint16 famid, styid;
@ -1734,10 +1734,82 @@ void ServerApp::DispatchMessage(int32 code, LinkMsgReader &msg)
BShape **shapes = font.GetGlyphShapes(charArray, numChars); BShape **shapes = font.GetGlyphShapes(charArray, numChars);
if (shapes) { if (shapes) {
replylink.StartMessage(SERVER_TRUE); replylink.StartMessage(SERVER_TRUE);
for (int32 i = 0; i < numChars; i++) for (int32 i = 0; i < numChars; i++) {
replylink.AttachShape(*shapes[i]); replylink.AttachShape(*shapes[i]);
delete shapes[i];
}
replylink.Flush(); 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<uint16>(&famid);
msg.Read<uint16>(&styid);
msg.Read<float>(&ptsize);
msg.Read<float>(&rotation);
msg.Read<uint32>(&flags);
int32 numChars;
msg.Read<int32>(&numChars);
char charArray[numChars];
BPoint offsetArray[numChars];
for (int32 i = 0; i < numChars; i++) {
msg.Read<char>(&charArray[i]);
msg.Read<BPoint>(&offsetArray[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.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<BPoint>(esc[i]);
}
replylink.Flush();
delete esc;
} else { } else {
replylink.StartMessage(SERVER_FALSE); replylink.StartMessage(SERVER_FALSE);
replylink.Flush(); replylink.Flush();

View File

@ -263,8 +263,8 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const
// Multiply togheter // Multiply togheter
FT_Matrix_Multiply(&rmatrix, &smatrix); FT_Matrix_Multiply(&rmatrix, &smatrix);
FT_Vector pen; //FT_Vector pen;
FT_Set_Transform(face, &smatrix, &pen); //FT_Set_Transform(face, &smatrix, &pen);
BShape **shapes = (BShape **)malloc(sizeof(BShape *) * numChars); BShape **shapes = (BShape **)malloc(sizeof(BShape *) * numChars);
for (int i = 0; i < numChars; i++) { for (int i = 0; i < numChars; i++) {
@ -279,6 +279,53 @@ ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const
return shapes; 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 \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