From f8e66767752a4e9e660ad026d656fb8c39a77384 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 19 May 2013 15:44:02 +0000 Subject: [PATCH] .uppdev git-svn-id: svn://ultimatepp.org/upp/trunk@6082 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/Glyph/FDrawText.cpp | 26 +++++++++++++++----------- uppdev/Glyph/Glyph.cpp | 11 ++++++----- uppdev/Glyph/glyph.h | 4 +--- uppdev/Glyph/main.cpp | 13 ++++++++++++- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/uppdev/Glyph/FDrawText.cpp b/uppdev/Glyph/FDrawText.cpp index 37569258a..0b11146e8 100644 --- a/uppdev/Glyph/FDrawText.cpp +++ b/uppdev/Glyph/FDrawText.cpp @@ -1,5 +1,7 @@ #include "glyph.h" +#define LTIMING(x) // RTIMING(x) + struct sMakeGlyph : public ImageMaker { int chr; @@ -17,8 +19,10 @@ struct sMakeGlyph : public ImageMaker } virtual Image Make() const { - RTIMING("Render glyph"); - return RenderGlyph(font, chr, color, angle); + LTIMING("Render glyph"); + Point at(font[chr], font.GetLineHeight()); + int n = 2 * (at.x + at.y); + return AutoCrop(RenderGlyph(at, angle, chr, font, color, Size(n, n)), RGBAZero()); } }; @@ -27,18 +31,18 @@ void FDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Co sMakeGlyph g; g.font = font; g.color = ink; - g.angle = angle; // TODO! + g.angle = angle; for(int i = 0; i < n; i++) { g.chr = text[i]; - RTIMING("Paint glyph"); + LTIMING("Paint glyph"); if(font.GetHeight() > 200) { - Size sz(font[g.chr], font.GetLineHeight()); - int w = 2 * (sz.cx + sz.cy); - Size bandsz(w, 32); - for(int yy = 0; yy < w; yy += bandsz.cy) { - Image m = RenderGlyph(font, g.chr, ink, angle, bandsz, Point(0, -yy)); - if(yy & 1) - SysDrawImageOp(x - (sz.cx + sz.cy), y + yy - (sz.cx + sz.cy), m, m.GetSize(), Null); + Point at(font[g.chr], font.GetLineHeight()); + int n = at.x + at.y; + Size bandsz(2 * n, 32); + for(int yy = 0; yy < n; yy += bandsz.cy) { + Image m = RenderGlyph(Point(0, -yy), angle, g.chr, font, ink, bandsz); + DDUMP(m.GetSize()); + SysDrawImageOp(x, y + yy, m, m.GetSize(), Null); } } else { diff --git a/uppdev/Glyph/Glyph.cpp b/uppdev/Glyph/Glyph.cpp index 3fd5ae00a..1d0af8d2d 100644 --- a/uppdev/Glyph/Glyph.cpp +++ b/uppdev/Glyph/Glyph.cpp @@ -43,16 +43,17 @@ Image RenderGlyph(Font fnt, int chr, Color color, int angle) return AutoCrop(ib, RGBAZero()); } -Image RenderGlyph(Font fnt, int chr, Color color, int angle, Size sz, Point offset) +Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz) { int cx = fnt[chr]; int cy = fnt.GetLineHeight(); ImageBuffer ib(sz); - BufferPainter sw(ib, MODE_ANTIALIASED); - sw.Offset(offset); + BufferPainter sw(ib); sw.Clear(RGBAZero()); - sw.DrawText(cx + cy, cx + cy, angle, WString(chr, 1), fnt, color); - ib.SetHotSpot(Point(cx + cy, cx + cy)); + sw.DrawText(at.x, at.y, angle, WString(chr, 1), fnt, color); + ib.SetHotSpot(at); + for(RGBA *s = ib; s < ib.End(); s++) + s->a = (s->a & 0xf8); return ib; } diff --git a/uppdev/Glyph/glyph.h b/uppdev/Glyph/glyph.h index 2ead109e6..966c85540 100644 --- a/uppdev/Glyph/glyph.h +++ b/uppdev/Glyph/glyph.h @@ -8,9 +8,7 @@ using namespace Upp; Image AutoCrop(const Image& m, RGBA c); -Image RenderGlyph(Font fnt, int chr, Color color, int angle); - -Image RenderGlyph(Font fnt, int chr, Color color, int angle, Size sz, Point offset); +Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz); String CompressGlyph(const Image& m); Image DecompressGlyph(const String& g, Color c); diff --git a/uppdev/Glyph/main.cpp b/uppdev/Glyph/main.cpp index 741ad28e5..83797be1e 100644 --- a/uppdev/Glyph/main.cpp +++ b/uppdev/Glyph/main.cpp @@ -69,7 +69,18 @@ void MyApp::Paint(Draw& w) fw.draw = &w; fw.Init(sz); - fw.DrawText(0, 0, "Ahoj!", Roman(400)); + fw.DrawText(100, 100, "Ahoj!", Roman(400)); + + + RichText txt = ParseQTF(LoadFile(GetDataFile("text.qtf"))); + if(0) { + RTIMING("SDraw"); + txt.Paint(Zoom(2, 10), fw, 0, 0, sz.cx); + } + if(0) { + RTIMING("Draw"); + txt.Paint(Zoom(2, 10), w, 0, 0, sz.cx); + } /* fw.cloff.Add(); fw.cloff.Top().offset = Point(0, 0);