Added StringWidth() and StringHeight() calls
Removed redundant DrawChar() implementation from ScreenDriver git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1970 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -45,6 +45,16 @@ int32 DisplayDriver::GetMode(void)
|
|||||||
return buffer_mode;
|
return buffer_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float DisplayDriver::StringWidth(const char *string, int32 length, LayerData *d)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float DisplayDriver::StringHeight(const char *string, int32 length, LayerData *d)
|
||||||
|
{
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
bool DisplayDriver::DumpToFile(const char *path)
|
bool DisplayDriver::DumpToFile(const char *path)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ public:
|
|||||||
virtual void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
virtual void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
||||||
virtual void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d);
|
virtual void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d);
|
||||||
virtual void SetMode(int32 mode);
|
virtual void SetMode(int32 mode);
|
||||||
|
virtual float StringWidth(const char *string, int32 length, LayerData *d);
|
||||||
|
virtual float StringHeight(const char *string, int32 length, LayerData *d);
|
||||||
virtual bool DumpToFile(const char *path);
|
virtual bool DumpToFile(const char *path);
|
||||||
|
|
||||||
uint8 GetDepth(void);
|
uint8 GetDepth(void);
|
||||||
|
|||||||
@@ -1590,12 +1590,131 @@ void ScreenDriver::InvertRect(BRect r)
|
|||||||
Unlock();
|
Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenDriver::DrawChar(char c, BPoint pt, LayerData *d)
|
|
||||||
|
float ScreenDriver::StringWidth(const char *string, int32 length, LayerData *d)
|
||||||
{
|
{
|
||||||
char st[2];
|
if(!string || !d || !d->font)
|
||||||
st[0]=c;
|
return 0.0;
|
||||||
st[1]='\0';
|
Lock();
|
||||||
DrawString(st,1,pt,d);
|
|
||||||
|
ServerFont *font=d->font;
|
||||||
|
FontStyle *style=font->Style();
|
||||||
|
|
||||||
|
if(!style)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
FT_Face face;
|
||||||
|
FT_GlyphSlot slot;
|
||||||
|
FT_UInt glyph_index, previous=0;
|
||||||
|
FT_Vector pen,delta;
|
||||||
|
int16 error=0;
|
||||||
|
int32 strlength,i;
|
||||||
|
float returnval;
|
||||||
|
|
||||||
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't create face object\n");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
|
||||||
|
|
||||||
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't set character size - error 0x%x\n",error);
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the pen position in 26.6 cartesian space coordinates
|
||||||
|
pen.x=0;
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
strlength=strlen(string);
|
||||||
|
if(length<strlength)
|
||||||
|
strlength=length;
|
||||||
|
|
||||||
|
for(i=0;i<strlength;i++)
|
||||||
|
{
|
||||||
|
// get kerning and move pen
|
||||||
|
if(use_kerning && previous && glyph_index)
|
||||||
|
{
|
||||||
|
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
|
||||||
|
pen.x+=delta.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
error=FT_Load_Char(face,string[i],FT_LOAD_MONOCHROME);
|
||||||
|
|
||||||
|
// increment pen position
|
||||||
|
pen.x+=slot->advance.x;
|
||||||
|
previous=glyph_index;
|
||||||
|
}
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
FT_Done_Face(face);
|
||||||
|
|
||||||
|
returnval=pen.x>>6;
|
||||||
|
return returnval;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ScreenDriver::StringHeight(const char *string, int32 length, LayerData *d)
|
||||||
|
{
|
||||||
|
if(!string || !d || !d->font)
|
||||||
|
return 0.0;
|
||||||
|
Lock();
|
||||||
|
|
||||||
|
ServerFont *font=d->font;
|
||||||
|
FontStyle *style=font->Style();
|
||||||
|
|
||||||
|
if(!style)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
FT_Face face;
|
||||||
|
FT_GlyphSlot slot;
|
||||||
|
int16 error=0;
|
||||||
|
int32 strlength,i;
|
||||||
|
float returnval=0.0,ascent=0.0,descent=0.0;
|
||||||
|
|
||||||
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't create face object\n");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't set character size - error 0x%x\n",error);
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
strlength=strlen(string);
|
||||||
|
if(length<strlength)
|
||||||
|
strlength=length;
|
||||||
|
|
||||||
|
for(i=0;i<strlength;i++)
|
||||||
|
{
|
||||||
|
FT_Load_Char(face,string[i],FT_LOAD_RENDER);
|
||||||
|
if(slot->metrics.horiBearingY<slot->metrics.height)
|
||||||
|
descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent);
|
||||||
|
else
|
||||||
|
ascent=MAX(slot->bitmap.rows,ascent);
|
||||||
|
}
|
||||||
|
Unlock();
|
||||||
|
|
||||||
|
FT_Done_Face(face);
|
||||||
|
|
||||||
|
returnval=ascent+descent;
|
||||||
|
return returnval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL)
|
void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL)
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ public:
|
|||||||
// virtual void CopyBits(BRect src, BRect dest);
|
// virtual void CopyBits(BRect src, BRect dest);
|
||||||
virtual void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest);
|
virtual void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest);
|
||||||
// virtual void DrawPicture(SPicture *pic, BPoint pt);
|
// virtual void DrawPicture(SPicture *pic, BPoint pt);
|
||||||
virtual void DrawChar(char c, BPoint pt, LayerData *d);
|
|
||||||
virtual void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL);
|
virtual void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL);
|
||||||
|
|
||||||
// virtual void FillArc(BRect r, float angle, float span, LayerData *d, int8 *pat);
|
// virtual void FillArc(BRect r, float angle, float span, LayerData *d, int8 *pat);
|
||||||
@@ -83,6 +82,8 @@ public:
|
|||||||
virtual void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
virtual void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
||||||
// virtual void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d);
|
// virtual void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d);
|
||||||
virtual void SetMode(int32 mode);
|
virtual void SetMode(int32 mode);
|
||||||
|
float StringWidth(const char *string, int32 length, LayerData *d);
|
||||||
|
float StringHeight(const char *string, int32 length, LayerData *d);
|
||||||
// virtual bool DumpToFile(const char *path);
|
// virtual bool DumpToFile(const char *path);
|
||||||
protected:
|
protected:
|
||||||
void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d);
|
void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d);
|
||||||
|
|||||||
@@ -997,6 +997,132 @@ printf("ViewDriver::SetLayerData font had a NULL family\n");
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ViewDriver::StringWidth(const char *string, int32 length, LayerData *d)
|
||||||
|
{
|
||||||
|
if(!string || !d || !d->font)
|
||||||
|
return 0.0;
|
||||||
|
screenwin->Lock();
|
||||||
|
|
||||||
|
ServerFont *font=d->font;
|
||||||
|
FontStyle *style=font->Style();
|
||||||
|
|
||||||
|
if(!style)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
FT_Face face;
|
||||||
|
FT_GlyphSlot slot;
|
||||||
|
FT_UInt glyph_index, previous=0;
|
||||||
|
FT_Vector pen,delta;
|
||||||
|
int16 error=0;
|
||||||
|
int32 strlength,i;
|
||||||
|
float returnval;
|
||||||
|
|
||||||
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't create face object\n");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING;
|
||||||
|
|
||||||
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't set character size - error 0x%x\n",error);
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the pen position in 26.6 cartesian space coordinates
|
||||||
|
pen.x=0;
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
strlength=strlen(string);
|
||||||
|
if(length<strlength)
|
||||||
|
strlength=length;
|
||||||
|
|
||||||
|
for(i=0;i<strlength;i++)
|
||||||
|
{
|
||||||
|
// get kerning and move pen
|
||||||
|
if(use_kerning && previous && glyph_index)
|
||||||
|
{
|
||||||
|
FT_Get_Kerning(face, previous, glyph_index,ft_kerning_default, &delta);
|
||||||
|
pen.x+=delta.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
error=FT_Load_Char(face,string[i],FT_LOAD_MONOCHROME);
|
||||||
|
|
||||||
|
// increment pen position
|
||||||
|
pen.x+=slot->advance.x;
|
||||||
|
previous=glyph_index;
|
||||||
|
}
|
||||||
|
screenwin->Unlock();
|
||||||
|
|
||||||
|
FT_Done_Face(face);
|
||||||
|
|
||||||
|
returnval=pen.x>>6;
|
||||||
|
return returnval;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ViewDriver::StringHeight(const char *string, int32 length, LayerData *d)
|
||||||
|
{
|
||||||
|
if(!string || !d || !d->font)
|
||||||
|
return 0.0;
|
||||||
|
screenwin->Lock();
|
||||||
|
|
||||||
|
ServerFont *font=d->font;
|
||||||
|
FontStyle *style=font->Style();
|
||||||
|
|
||||||
|
if(!style)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
FT_Face face;
|
||||||
|
FT_GlyphSlot slot;
|
||||||
|
int16 error=0;
|
||||||
|
int32 strlength,i;
|
||||||
|
float returnval=0.0,ascent=0.0,descent=0.0;
|
||||||
|
|
||||||
|
error=FT_New_Face(ftlib, style->GetPath(), 0, &face);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't create face object\n");
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
printf("Couldn't set character size - error 0x%x\n",error);
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot=face->glyph;
|
||||||
|
|
||||||
|
strlength=strlen(string);
|
||||||
|
if(length<strlength)
|
||||||
|
strlength=length;
|
||||||
|
|
||||||
|
for(i=0;i<strlength;i++)
|
||||||
|
{
|
||||||
|
FT_Load_Char(face,string[i],FT_LOAD_RENDER);
|
||||||
|
if(slot->metrics.horiBearingY<slot->metrics.height)
|
||||||
|
descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent);
|
||||||
|
else
|
||||||
|
ascent=MAX(slot->bitmap.rows,ascent);
|
||||||
|
}
|
||||||
|
screenwin->Unlock();
|
||||||
|
|
||||||
|
FT_Done_Face(face);
|
||||||
|
|
||||||
|
returnval=ascent+descent;
|
||||||
|
return returnval;
|
||||||
|
}
|
||||||
|
|
||||||
void ViewDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL)
|
void ViewDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL)
|
||||||
{
|
{
|
||||||
if(!string || !d || !d->font)
|
if(!string || !d || !d->font)
|
||||||
@@ -1142,7 +1268,6 @@ void ViewDriver::DrawString(const char *string, int32 length, BPoint pt, LayerDa
|
|||||||
r.bottom=pt.y+face->height;
|
r.bottom=pt.y+face->height;
|
||||||
|
|
||||||
screenwin->view->Invalidate(r);
|
screenwin->view->Invalidate(r);
|
||||||
r.PrintToStream();
|
|
||||||
screenwin->Unlock();
|
screenwin->Unlock();
|
||||||
|
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ public:
|
|||||||
// void StrokeShape(SShape *sh, LayerData *d, int8 *pat);
|
// void StrokeShape(SShape *sh, LayerData *d, int8 *pat);
|
||||||
void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat);
|
||||||
void SetMode(int32 mode);
|
void SetMode(int32 mode);
|
||||||
|
float StringWidth(const char *string, int32 length, LayerData *d);
|
||||||
|
float StringHeight(const char *string, int32 length, LayerData *d);
|
||||||
// bool DumpToFile(const char *path);
|
// bool DumpToFile(const char *path);
|
||||||
VDWindow *screenwin;
|
VDWindow *screenwin;
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user