Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef GFX_LAYOUT_H
00013 #define GFX_LAYOUT_H
00014
00015 #include "fontcache.h"
00016 #include "gfx_func.h"
00017 #include "core/smallmap_type.hpp"
00018
00019 #ifdef WITH_ICU
00020 #include "layout/ParagraphLayout.h"
00021 #define ICU_FONTINSTANCE : public LEFontInstance
00022 #else
00023 #define ICU_FONTINSTANCE
00024 #endif
00025
00029 class Font ICU_FONTINSTANCE {
00030 public:
00031 FontCache *fc;
00032 TextColour colour;
00033
00034 Font(FontSize size, TextColour colour);
00035
00036 #ifdef WITH_ICU
00037
00038
00039 le_int32 getUnitsPerEM() const;
00040 le_int32 getAscent() const;
00041 le_int32 getDescent() const;
00042 le_int32 getLeading() const;
00043 float getXPixelsPerEm() const;
00044 float getYPixelsPerEm() const;
00045 float getScaleFactorX() const;
00046 float getScaleFactorY() const;
00047 const void *getFontTable(LETag tableTag) const;
00048 const void *getFontTable(LETag tableTag, size_t &length) const;
00049 LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
00050 void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
00051 le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
00052 #endif
00053 };
00054
00056 typedef SmallMap<int, Font *> FontMap;
00057
00058 #ifndef WITH_ICU
00059
00079 class ParagraphLayout {
00080 public:
00082 class VisualRun {
00083 Font *font;
00084 GlyphID *glyphs;
00085 float *positions;
00086 int glyph_count;
00087
00088 public:
00089 VisualRun(Font *font, const WChar *chars, int glyph_count, int x);
00090 ~VisualRun();
00091 Font *getFont() const;
00092 int getGlyphCount() const;
00093 const GlyphID *getGlyphs() const;
00094 float *getPositions() const;
00095 int getLeading() const;
00096 };
00097
00099 class Line : public AutoDeleteSmallVector<VisualRun *, 4> {
00100 public:
00101 int getLeading() const;
00102 int getWidth() const;
00103 int countRuns() const;
00104 VisualRun *getVisualRun(int run) const;
00105 };
00106
00107 const WChar *buffer_begin;
00108 WChar *buffer;
00109 FontMap &runs;
00110
00111 ParagraphLayout(WChar *buffer, int length, FontMap &runs);
00112 Line *nextLine(int max_width);
00113 };
00114 #endif
00115
00121 class Layouter : public AutoDeleteSmallVector<ParagraphLayout::Line *, 4> {
00122 #ifdef WITH_ICU
00123 typedef UChar CharType;
00124 #else
00125 typedef WChar CharType;
00126 #endif
00127
00128 size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, WChar c);
00129 ParagraphLayout *GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &fontMapping);
00130
00131 CharType buffer[DRAW_STRING_BUFFER];
00132 SmallVector<Font *, 4> fonts;
00133
00134 public:
00135 Layouter(const char *str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL);
00136 ~Layouter();
00137 Dimension GetBounds();
00138 };
00139
00140 #endif