From 744b47079493397aa2fbadab86c72c506598ec4e Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 19 May 2013 20:48:55 +0000 Subject: [PATCH] .uppdev git-svn-id: svn://ultimatepp.org/upp/trunk@6083 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/Glyph/FDraw.cpp | 30 ----------------- uppdev/Glyph/FDrawClip.cpp | 65 ------------------------------------- uppdev/Glyph/FDrawPut.cpp | 66 -------------------------------------- uppdev/Glyph/FDrawText.cpp | 55 ------------------------------- uppdev/Glyph/Glyph.cpp | 32 ++---------------- uppdev/Glyph/Glyph.upp | 4 --- uppdev/Glyph/TestDraw.cpp | 11 +++++++ uppdev/Glyph/glyph.h | 54 +++---------------------------- uppdev/Glyph/main.cpp | 6 ++-- 9 files changed, 20 insertions(+), 303 deletions(-) delete mode 100644 uppdev/Glyph/FDraw.cpp delete mode 100644 uppdev/Glyph/FDrawClip.cpp delete mode 100644 uppdev/Glyph/FDrawPut.cpp delete mode 100644 uppdev/Glyph/FDrawText.cpp diff --git a/uppdev/Glyph/FDraw.cpp b/uppdev/Glyph/FDraw.cpp deleted file mode 100644 index c9f196b8c..000000000 --- a/uppdev/Glyph/FDraw.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "glyph.h" - -dword FDraw::GetInfo() const -{ - return DRAWTEXTLINES; -} - -void FDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) -{ -} - -void FDraw::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) -{ -} - -void FDraw::DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) -{ - Width(width); - docolor = color; - Move(Point(x1, y1)); - Line(Point(x2, y2)); -} - -void FDraw::DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor) -{ -} - -void FDraw::DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor) -{ -} diff --git a/uppdev/Glyph/FDrawClip.cpp b/uppdev/Glyph/FDrawClip.cpp deleted file mode 100644 index 09ee6a439..000000000 --- a/uppdev/Glyph/FDrawClip.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "glyph.h" - -void FDraw::Init(const Rect& r) -{ - Cloff& c = cloff.Add(); - c.clip.Add(r); - c.offset = Point(0, 0); -} - -void FDraw::BeginOp() -{ - Cloff& c = cloff.Top(); - cloff.Add() <<= c; -} - -bool FDraw::ClipOp(const Rect& r) -{ - Cloff& c = cloff.Top(); - Cloff& c1 = cloff.Add(); - c1.clip = Intersection(c.clip, r + c.offset); - c1.offset = c.offset; - return c1.clip.GetCount(); -} - -bool FDraw::ClipoffOp(const Rect& r) -{ - Cloff& c = cloff.Top(); - Cloff& c1 = cloff.Add(); - c1.clip = Intersection(c.clip, r + c.offset); - c1.offset = c.offset + r.TopLeft(); - return c1.clip.GetCount(); -} - -bool FDraw::IntersectClipOp(const Rect& r) -{ - Cloff& c = cloff.Top(); - c.clip = Intersection(c.clip, r + c.offset); - return c.clip.GetCount(); -} - -bool FDraw::ExcludeClipOp(const Rect& r) -{ - Cloff& c = cloff.Top(); - bool dummy; - c.clip = Subtract(c.clip, r + c.offset, dummy); - return c.clip.GetCount(); -} - -bool FDraw::IsPaintingOp(const Rect& r) const -{ - return true; -} - -void FDraw::OffsetOp(Point p) -{ - Cloff& c = cloff.Top(); - Cloff& c1 = cloff.Add(); - c1.clip <<= c.clip; - c1.offset = c.offset + p; -} - -void FDraw::EndOp() -{ - cloff.Drop(); -} diff --git a/uppdev/Glyph/FDrawPut.cpp b/uppdev/Glyph/FDrawPut.cpp deleted file mode 100644 index 526a90c72..000000000 --- a/uppdev/Glyph/FDrawPut.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "glyph.h" - -struct sColorize : public ImageMaker -{ - Image img; - Color color; - - virtual String Key() const { - StringBuffer h; - RawCat(h, color); - RawCat(h, img.GetSerialId()); - return h; - } - - virtual Image Make() const { - return SetColorKeepAlpha(img, color); - } - -}; - -void FDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) -{ - if(!IsNull(color)) { - sColorize m; - m.img = img; - m.color = color; - SysDrawImageOp(x, y, MakeImage(m), src, Null); - return; - } - Rect sr(Point(x, y) + cloff.Top().offset, (src & img.GetSize()).GetSize()); - const Vector& clip = cloff.Top().clip; - for(int i = 0; i < clip.GetCount(); i++) { - Rect cr = clip[i] & sr; - if(!cr.IsEmpty()) - PutImage(cr.TopLeft(), img, Rect(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize())); - } -} - -void FDraw::SysDrawImageOp(int x, int y, const Image& img, Color color) -{ - SysDrawImageOp(x, y, img, img.GetSize(), color); -} - -void FDraw::DrawRectOp(int x, int y, int cx, int cy, Color color) -{ - Rect r = RectC(x, y, cx, cy); - r += cloff.Top().offset; - const Vector& clip = cloff.Top().clip; - for(int i = 0; i < clip.GetCount(); i++) { - Rect cr = clip[i] & r; - if(!cr.IsEmpty()) - PutRect(cr, color); - } -} - -void FDraw::PutHorz(int x, int y, int cx) -{ - RTIMING("PutHorz"); - DrawRect(x, y, cx, 1, docolor); -} - -void FDraw::PutVert(int x, int y, int cy) -{ - RTIMING("PutVert"); - DrawRect(x, y, 1, cy, docolor); -} diff --git a/uppdev/Glyph/FDrawText.cpp b/uppdev/Glyph/FDrawText.cpp deleted file mode 100644 index 0b11146e8..000000000 --- a/uppdev/Glyph/FDrawText.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "glyph.h" - -#define LTIMING(x) // RTIMING(x) - -struct sMakeGlyph : public ImageMaker -{ - int chr; - Font font; - int angle; - Color color; - - virtual String Key() const { - StringBuffer h; - RawCat(h, chr); - RawCat(h, font); - RawCat(h, angle); - RawCat(h, color); - return h; - } - - virtual Image Make() const { - 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()); - } -}; - -void FDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) -{ - sMakeGlyph g; - g.font = font; - g.color = ink; - g.angle = angle; - for(int i = 0; i < n; i++) { - g.chr = text[i]; - LTIMING("Paint glyph"); - if(font.GetHeight() > 200) { - 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 { - Image m = MakeImage(g); - Point h = m.GetHotSpot(); - SysDrawImageOp(x - h.x, y - h.y, m, m.GetSize(), Null); - } - x += dx ? *dx++ : font[g.chr]; - } -} diff --git a/uppdev/Glyph/Glyph.cpp b/uppdev/Glyph/Glyph.cpp index 1d0af8d2d..e541b2075 100644 --- a/uppdev/Glyph/Glyph.cpp +++ b/uppdev/Glyph/Glyph.cpp @@ -1,35 +1,5 @@ #include "glyph.h" -bool IsUniform(const RGBA *s, RGBA c, int add, int n) -{ - while(n-- > 0) { - if(*s != c) - return false; - s += add; - } - return true; -} - -Image AutoCrop(const Image& m, RGBA c) -{ - Size isz = m.GetSize(); - Rect r = isz; - for(r.top = 0; r.top < isz.cy && IsUniform(m[r.top], c, 1, isz.cx); r.top++) - ; - for(r.bottom = isz.cy; r.bottom > r.top && IsUniform(m[r.bottom - 1], c, 1, isz.cx); r.bottom--) - ; - if(r.bottom <= r.top) - return Null; - int h = r.GetHeight(); - const RGBA *p = m[r.top]; - for(r.left = 0; r.left < isz.cy && IsUniform(p + r.left, c, isz.cx, h); r.left++) - ; - for(r.right = isz.cx; r.right > r.left && IsUniform(p + r.right - 1, c, isz.cx, h); r.right--) - ; - Point p1 = m.GetHotSpot() - r.TopLeft(); - Point p2 = m.Get2ndSpot() - r.TopLeft(); - return WithHotSpots(Crop(m, r), p1.x, p1.y, p2.x, p2.y); -} Image RenderGlyph(Font fnt, int chr, Color color, int angle) { @@ -43,6 +13,7 @@ Image RenderGlyph(Font fnt, int chr, Color color, int angle) return AutoCrop(ib, RGBAZero()); } +/* Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz) { int cx = fnt[chr]; @@ -56,6 +27,7 @@ Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz) s->a = (s->a & 0xf8); return ib; } +*/ String CompressGlyph(const Image& m) { diff --git a/uppdev/Glyph/Glyph.upp b/uppdev/Glyph/Glyph.upp index 635268bb4..435eced4e 100644 --- a/uppdev/Glyph/Glyph.upp +++ b/uppdev/Glyph/Glyph.upp @@ -5,10 +5,6 @@ uses file glyph.h, TestDraw.cpp, - FDrawClip.cpp, - FDrawPut.cpp, - FDrawText.cpp, - FDraw.cpp, Glyph.cpp, main.cpp optimize_speed, text.qtf, diff --git a/uppdev/Glyph/TestDraw.cpp b/uppdev/Glyph/TestDraw.cpp index c141c6198..b9945b9f0 100644 --- a/uppdev/Glyph/TestDraw.cpp +++ b/uppdev/Glyph/TestDraw.cpp @@ -1,5 +1,7 @@ #include "glyph.h" +#define LTIMING(x) RTIMING(x) + void TestDraw::PutImage(Point p, const Image& m, const Rect& src) { draw->DrawImage(p.x, p.y, m, src); @@ -9,3 +11,12 @@ void TestDraw::PutRect(const Rect& r, Color color) { draw->DrawRect(r, color); } + +Image TestDraw::RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz) +{ + ImageBuffer ib(sz); + BufferPainter sw(ib); + sw.Clear(RGBAZero()); + sw.DrawText(at.x, at.y, angle, WString(chr, 1), fnt, color); + return ib; +} diff --git a/uppdev/Glyph/glyph.h b/uppdev/Glyph/glyph.h index 966c85540..d839c3efa 100644 --- a/uppdev/Glyph/glyph.h +++ b/uppdev/Glyph/glyph.h @@ -7,63 +7,17 @@ using namespace Upp; -Image AutoCrop(const Image& m, RGBA c); 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); -struct FDraw : Draw, DDARasterizer { - virtual dword GetInfo() const; - - virtual void BeginOp(); - virtual bool ClipOp(const Rect& r); - virtual bool ClipoffOp(const Rect& r); - virtual bool IntersectClipOp(const Rect& r); - virtual void OffsetOp(Point p); - virtual bool ExcludeClipOp(const Rect& r); - virtual void EndOp(); - virtual bool IsPaintingOp(const Rect& r) const; - - virtual void SysDrawImageOp(int x, int y, const Image& img, Color color); - virtual void SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color); - virtual void DrawRectOp(int x, int y, int cx, int cy, Color color); - - virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx); - - virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color); - virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor); - virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color); - virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count, const int *subpolygon_counts, int scc, const int *disjunct_polygon_counts, int dpcc, Color color, int width, Color outline, uint64 pattern, Color doxor); - virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count, const int *counts, int count_count, int width, Color color, Color doxor); - - virtual void PutHorz(int x, int y, int cx); - virtual void PutVert(int x, int y, int cy); - -//private: - struct Cloff { - Vector clip; - Point offset; - - void operator<<=(const Cloff& b) { clip <<= b.clip; offset = b.offset; } - }; - - Array cloff; - - Color docolor; - -public: - virtual void PutImage(Point p, const Image& m, const Rect& src) = 0; - virtual void PutRect(const Rect& r, Color color) = 0; - - void Init(const Rect& r); -}; - -struct TestDraw : FDraw { +struct TestDraw : SDraw { Draw *draw; - virtual void PutImage(Point p, const Image& m, const Rect& src); - virtual void PutRect(const Rect& r, Color color); + virtual void PutImage(Point p, const Image& m, const Rect& src); + virtual void PutRect(const Rect& r, Color color); + virtual Image RenderGlyph(Point at, int angle, int chr, Font fnt, Color color, Size sz); }; #endif diff --git a/uppdev/Glyph/main.cpp b/uppdev/Glyph/main.cpp index 83797be1e..5d12bdad0 100644 --- a/uppdev/Glyph/main.cpp +++ b/uppdev/Glyph/main.cpp @@ -69,15 +69,15 @@ void MyApp::Paint(Draw& w) fw.draw = &w; fw.Init(sz); - fw.DrawText(100, 100, "Ahoj!", Roman(400)); +// fw.DrawText(100, 100, "Ahoj!", Roman(400)); RichText txt = ParseQTF(LoadFile(GetDataFile("text.qtf"))); - if(0) { + if(1) { RTIMING("SDraw"); txt.Paint(Zoom(2, 10), fw, 0, 0, sz.cx); } - if(0) { + if(1) { RTIMING("Draw"); txt.Paint(Zoom(2, 10), w, 0, 0, sz.cx); }