diff options
Diffstat (limited to 'libjin/Graphics/Font/TTF.cpp')
-rw-r--r-- | libjin/Graphics/Font/TTF.cpp | 165 |
1 files changed, 11 insertions, 154 deletions
diff --git a/libjin/Graphics/Font/TTF.cpp b/libjin/Graphics/Font/TTF.cpp index dac6733..ea340e4 100644 --- a/libjin/Graphics/Font/TTF.cpp +++ b/libjin/Graphics/Font/TTF.cpp @@ -235,28 +235,13 @@ namespace graphics return t; } - void TTF::print(const Sentence& t, int x, int y, int lineheight, int spacing) + void TTF::print(const Content& t, int x, int y, int lineheight, int spacing) { Page* page = typeset(t, lineheight, spacing); print(page, x, y); delete page; } - void TTF::print(unicode::Iterator itor, int x, int y, int lineheight, int spacing) - { - Page* page = typeset(itor, lineheight, spacing); - print(page, x, y); - delete page; - } - - void TTF::print(const Text& text, int x, int y,int lineheight, int spacing) - { - Iterator itor(text); - Page* page = typeset(itor, lineheight, spacing); - print(page, x, y); - delete page; - } - #define glyphvertices_push(_x, _y, _u, _v) \ vertex.x = _x; vertex.y = _y;\ vertex.u = _u; vertex.v = _v;\ @@ -282,39 +267,7 @@ namespace graphics glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \ }while(0) - Page* TTF::typeset(unicode::Iterator itor, int lineheight, int spacing) - { - Page* page = new Page(); - page->font = this; - vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; - vector<GlyphVertex>& glyphvertices = page->glyphvertices; - int texture = -1; - TTFGlyph* glyph = nullptr; - GlyphVertex vertex; - Vector2<int> p(0, 0); - int i = 0; - for (; itor != itor.end(); ++itor) - { - Codepoint c = *itor; - if (c == 0x0D) - continue; - if (c == 0x0A) - { - /* new line */ - p.y += lineheight; - p.x = 0; - continue; - } - glyphlize(c); - p.x += glyph->width + spacing; - i += 4; - } - itor.toBegin(); - getTextBox(itor, &page->size.w, &page->size.h, lineheight, spacing); - return page; - } - - Page* TTF::typeset(const Sentence& text, int lineheight, int spacing) + Page* TTF::typeset(const Content& text, int lineheight, int spacing) { Page* page = new Page(); page->font = this; @@ -346,35 +299,7 @@ namespace graphics Page* TTF::typeset(const Text& text, int lineheight, int spacing) { - Page* page = new Page(); - page->font = this; - vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist; - vector<GlyphVertex>& glyphvertices = page->glyphvertices; - int texture = -1; - TTFGlyph* glyph = nullptr; - GlyphVertex vertex; - Vector2<int> p(0, 0); - int i = 0; - Iterator itor(text); - for (; itor != itor.end(); ++itor) - { - Codepoint c = *itor; - if (c == 0x0D) - continue; - if (c == 0x0A) - { - /* new line */ - p.y += lineheight; - p.x = 0; - continue; - } - glyphlize(c); - p.x += glyph->width + spacing; - i += 4; - } - itor.toBegin(); - getTextBox(itor, &page->size.w, &page->size.h, lineheight, spacing); - return page; + return typeset(*text, lineheight, spacing); } void TTF::print(const Page* page, int x, int y) @@ -396,6 +321,11 @@ namespace graphics } } + void TTF::print(const unicode::Text& text, int x, int y, int lineheight, int spacing /* = 0 */) + { + print(*text, x, y, lineheight, spacing); + } + int TTF::getCharWidth(int c) { int adw, lsb; @@ -410,7 +340,7 @@ namespace graphics return descent; } - int TTF::getTextWidth(const Sentence& t, int spacing) + int TTF::getTextWidth(const Content& t, int spacing) { ttf->pushTTFsize(ttfsize); int res = 0; @@ -432,7 +362,7 @@ namespace graphics return res; } - int TTF::getTextHeight(const Sentence& t, int lineheight) + int TTF::getTextHeight(const Content& t, int lineheight) { ttf->pushTTFsize(ttfsize); int res = 0; @@ -452,7 +382,7 @@ namespace graphics return res; } - void TTF::getTextBox(const Sentence& text, int* w, int* h, int lineheight, int spacing) + void TTF::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing) { ttf->pushTTFsize(ttfsize); *w = 0; @@ -481,79 +411,6 @@ namespace graphics ttf->popTTFsize(); } - int TTF::getTextWidth(unicode::Iterator itor, int spacing) - { - ttf->pushTTFsize(ttfsize); - int res = 0; - int tmp = 0; - for (Codepoint c = *itor; itor != itor.end(); ++itor) - { - if (c == 0x0D) - continue; - if (c == 0x0A) - { - tmp = 0; - continue; - } - tmp += getCharWidth(c) + spacing; - if (tmp > res) - res = tmp; - } - ttf->popTTFsize(); - return res; - } - - int TTF::getTextHeight(unicode::Iterator itor, int lineheight) - { - ttf->pushTTFsize(ttfsize); - int res = 0; - bool newline = true; - for (Codepoint c = *itor; itor != itor.end(); ++itor) - { - if (c == 0x0A) - newline = true; - else if (c == 0x0D); - else if (newline) - { - newline = false; - res += lineheight; - } - } - ttf->popTTFsize(); - return res; - } - - void TTF::getTextBox(unicode::Iterator itor, int* w, int* h, int lineheight, int spacing) - { - ttf->pushTTFsize(ttfsize); - *w = 0; - *h = 0; - int tmp = 0; - bool newline = true; - unicode::Codepoint c; - for (; itor != itor.end(); ++itor) - { - c = *itor; - if (c == 0x0D) - continue; - if (c == 0x0A) - { - tmp = 0; - newline = true; - continue; - } - else if (newline) - { - newline = false; - *h += lineheight; - } - tmp += getCharWidth(c) + spacing; - if (tmp > *w) - *w = tmp; - } - ttf->popTTFsize(); - } - TTF::TTFGlyph& TTF::bakeGlyph(unsigned int character) { int w, h, xoff, yoff; |