freetypefont.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef __FREETYPEFONT_H
  2. #define __FREETYPEFONT_H
  3. #include <api/font/svc_fonti.h>
  4. #include <tataki/blending/blending.h>
  5. #include <bfc/string/StringW.h>
  6. // begin relative to freetype include directory
  7. #include <ft2build.h>
  8. #include <freetype/freetype.h>
  9. #include <freetype/ftglyph.h>
  10. // end relative to freetype include directory
  11. class ifc_canvas;
  12. class SkinBitmap;
  13. class FreeTypeFont : public svc_fontI
  14. {
  15. public:
  16. FreeTypeFont();
  17. virtual ~FreeTypeFont();
  18. virtual void textOut(ifc_canvas *c, int x, int y, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  19. virtual void textOut2(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  20. virtual void textOutEllipsed(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  21. virtual void textOutWrapped(ifc_canvas *c, int x, int y, int w, int h, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  22. virtual void textOutWrappedPathed(ifc_canvas *c, int x, int y, int w, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  23. virtual void textOutCentered(ifc_canvas *c, RECT *r, const wchar_t *txt, int size, int bold, int opaque, int underline, int italic, int align, COLORREF color, COLORREF bkcolor, int xoffset, int yoffset, int antialias);
  24. virtual int getTextWidth(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialias);
  25. virtual int getTextHeight(ifc_canvas *c, const wchar_t *text, int size, int bold, int underline, int italic, int antialias);
  26. virtual int getTextHeight2(ifc_canvas *c, int size, int bold, int underline, int italic, int antialias);
  27. virtual void getTextExtent(ifc_canvas *c, const wchar_t *text, int *w, int *h, int size, int bold, int underline, int italic, int antialias);
  28. virtual int isBitmap();
  29. virtual const wchar_t *getFaceName() { return facename; }
  30. virtual void setFontFace(const wchar_t *face) { facename = face; }
  31. virtual void setFontId(const wchar_t *id) { font_id = id; }
  32. virtual const wchar_t *getFontId() { return font_id; }
  33. virtual int getScriptId() { return scriptid; }
  34. virtual void setScriptId(int id) { scriptid = id; }
  35. virtual const wchar_t *getFontSvcName() { return L"Freetype"; }
  36. static const char *getServiceName() { return "Freetype font renderer"; }
  37. protected:
  38. int addFontResource( OSFILETYPE font, const wchar_t *name );
  39. int addFontResource2( void *data, int datalen, const wchar_t *name );
  40. void prepareCanvas(ifc_canvas *c, int size, int bold, int opaque, int underline, int italic, COLORREF color, COLORREF bkcolor, const wchar_t *txt, int width = -1, int height = -1 );
  41. void restoreCanvas(ifc_canvas *c, int x, int y );
  42. int drawChar( int x, int y, unsigned long c, COLORREF color, int antialias);
  43. int getAscent();
  44. protected:
  45. StringW font_id;
  46. StringW facename;
  47. int scriptid;
  48. private:
  49. void updateCharmap();
  50. void drawText(int x, int y, const wchar_t *txt, int len, COLORREF color, int antialias);
  51. int tweakSize(const wchar_t *face, int size);
  52. wchar_t *filenameToFontFace(const wchar_t *pszFile);
  53. inline unsigned __int8 overlay(unsigned __int8 c, unsigned __int8 b, int amount, int r, int z)
  54. {
  55. if (curboldstrength == 2 && z == r-1) {
  56. if (c < b)
  57. return Blenders::BLEND_ADJ1(c, b, 0xB0);
  58. return MIN(255, c+b);
  59. }
  60. return MIN(255, c+b);
  61. }
  62. FT_Library flib;
  63. char *fontbuffer;
  64. int fontbufferlen;
  65. FT_Face font;
  66. FT_Face font_bold;
  67. FT_Face font_italic;
  68. FT_Face font_bolditalic;
  69. SkinBitmap *blt;
  70. int lastchar;
  71. int curboldstrength;
  72. int cursize;
  73. int direction;
  74. int last_encoding;
  75. CfgItem *optionsitem;
  76. };
  77. #endif//__FREETYPEFONT_H