diff --git a/src/servers/app/proto7/DisplayDriver.cpp b/src/servers/app/proto7/DisplayDriver.cpp index 97ff36cff8..b16c3c1b14 100644 --- a/src/servers/app/proto7/DisplayDriver.cpp +++ b/src/servers/app/proto7/DisplayDriver.cpp @@ -45,6 +45,16 @@ int32 DisplayDriver::GetMode(void) 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) { return false; diff --git a/src/servers/app/proto7/DisplayDriver.h b/src/servers/app/proto7/DisplayDriver.h index b51d5f5a30..141609dc47 100644 --- a/src/servers/app/proto7/DisplayDriver.h +++ b/src/servers/app/proto7/DisplayDriver.h @@ -98,6 +98,8 @@ public: virtual void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat); virtual void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d); 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); uint8 GetDepth(void); diff --git a/src/servers/app/proto7/ScreenDriver.cpp b/src/servers/app/proto7/ScreenDriver.cpp index b60d0e32ec..adc90c8fa6 100644 --- a/src/servers/app/proto7/ScreenDriver.cpp +++ b/src/servers/app/proto7/ScreenDriver.cpp @@ -1590,12 +1590,131 @@ void ScreenDriver::InvertRect(BRect r) Unlock(); } -void ScreenDriver::DrawChar(char c, BPoint pt, LayerData *d) + +float ScreenDriver::StringWidth(const char *string, int32 length, LayerData *d) { - char st[2]; - st[0]=c; - st[1]='\0'; - DrawString(st,1,pt,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; + 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(lengthadvance.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(lengthmetrics.horiBearingYmetrics.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) diff --git a/src/servers/app/proto7/ScreenDriver.h b/src/servers/app/proto7/ScreenDriver.h index 3af6f2bdd8..07fbb28949 100644 --- a/src/servers/app/proto7/ScreenDriver.h +++ b/src/servers/app/proto7/ScreenDriver.h @@ -53,7 +53,6 @@ public: // virtual void CopyBits(BRect src, BRect dest); virtual void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest); // 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 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 StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d); 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); protected: void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d); diff --git a/src/servers/app/proto7/ViewDriver.cpp b/src/servers/app/proto7/ViewDriver.cpp index f8176aeba3..3e5b8ec562 100644 --- a/src/servers/app/proto7/ViewDriver.cpp +++ b/src/servers/app/proto7/ViewDriver.cpp @@ -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(lengthadvance.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(lengthmetrics.horiBearingYmetrics.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) { 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; screenwin->view->Invalidate(r); - r.PrintToStream(); screenwin->Unlock(); FT_Done_Face(face); diff --git a/src/servers/app/proto7/ViewDriver.h b/src/servers/app/proto7/ViewDriver.h index dafe339360..4d5b7186ed 100644 --- a/src/servers/app/proto7/ViewDriver.h +++ b/src/servers/app/proto7/ViewDriver.h @@ -101,6 +101,8 @@ public: // void StrokeShape(SShape *sh, LayerData *d, int8 *pat); void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, int8 *pat); 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); VDWindow *screenwin; protected: