From a505beca6d90044fb1a5b2884ef357240231d331 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 13 May 2013 11:52:48 +0000 Subject: [PATCH] .uppdev: FDraw git-svn-id: svn://ultimatepp.org/upp/trunk@6065 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppdev/Glyph/FDraw.cpp | 18 +++-------- uppdev/Glyph/FDrawClip.cpp | 37 +++++++++++++++++++--- uppdev/Glyph/FDrawPut.cpp | 15 ++++++--- uppdev/Glyph/FDrawText.cpp | 39 +++++++++++++++++++++++ uppdev/Glyph/Glyph.cpp | 14 ++++---- uppdev/Glyph/Glyph.upp | 2 ++ uppdev/Glyph/glyph.h | 35 ++++++++++++-------- uppdev/Glyph/main.cpp | 30 ++++++++++-------- uppdev/Glyph/text.qtf | 65 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 200 insertions(+), 55 deletions(-) create mode 100644 uppdev/Glyph/FDrawText.cpp create mode 100644 uppdev/Glyph/text.qtf diff --git a/uppdev/Glyph/FDraw.cpp b/uppdev/Glyph/FDraw.cpp index 8ae32eae8..c9f196b8c 100644 --- a/uppdev/Glyph/FDraw.cpp +++ b/uppdev/Glyph/FDraw.cpp @@ -2,31 +2,23 @@ dword FDraw::GetInfo() const { - return 0; -} - -void FDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) -{ + return DRAWTEXTLINES; } void FDraw::DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) { } -void FDraw::DrawDrawingOp(const Rect& target, const Drawing& w) -{ -} - 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) { -} - -void FDraw::DrawPaintingOp(const Rect& target, const Painting& w) -{ + 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) diff --git a/uppdev/Glyph/FDrawClip.cpp b/uppdev/Glyph/FDrawClip.cpp index 1bee6f02a..09ee6a439 100644 --- a/uppdev/Glyph/FDrawClip.cpp +++ b/uppdev/Glyph/FDrawClip.cpp @@ -1,38 +1,65 @@ #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) { - return false; + 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) { - return false; + 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) { - return false; + Cloff& c = cloff.Top(); + c.clip = Intersection(c.clip, r + c.offset); + return c.clip.GetCount(); } bool FDraw::ExcludeClipOp(const Rect& r) { - return false; + 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 false; + 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 index 21f3c6f6b..526a90c72 100644 --- a/uppdev/Glyph/FDrawPut.cpp +++ b/uppdev/Glyph/FDrawPut.cpp @@ -29,12 +29,8 @@ void FDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Colo } Rect sr(Point(x, y) + cloff.Top().offset, (src & img.GetSize()).GetSize()); const Vector& clip = cloff.Top().clip; - DLOG("======="); for(int i = 0; i < clip.GetCount(); i++) { Rect cr = clip[i] & sr; - DDUMP(cr); - DDUMP(sr); - DDUMP(src); if(!cr.IsEmpty()) PutImage(cr.TopLeft(), img, Rect(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize())); } @@ -57,3 +53,14 @@ void FDraw::DrawRectOp(int x, int y, int cx, int cy, Color 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 new file mode 100644 index 000000000..8dd14e9a9 --- /dev/null +++ b/uppdev/Glyph/FDrawText.cpp @@ -0,0 +1,39 @@ +#include "glyph.h" + +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 { + RTIMING("Render glyph"); + return RenderGlyph(font, chr, color, angle); + } +}; + +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; // TODO! + for(int i = 0; i < n; i++) { + g.chr = text[i]; + RTIMING("Paint glyph"); + 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 43ba42ec4..bd0259d8a 100644 --- a/uppdev/Glyph/Glyph.cpp +++ b/uppdev/Glyph/Glyph.cpp @@ -28,19 +28,21 @@ Image AutoCrop(const Image& m, RGBA c) ; r.right++; r.bottom++; - return WithHotSpot(Crop(m, r), 20, 20); + 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) +Image RenderGlyph(Font fnt, int chr, Color color, int angle) { int cx = fnt[chr]; int cy = fnt.GetLineHeight(); - ImageBuffer ib(2 * cx, 2 * cy); + ImageBuffer ib(2 * (cx + cy), 2 * (cx + cy)); BufferPainter sw(ib, MODE_ANTIALIASED); sw.Clear(RGBAZero()); - sw.DrawText(cx / 2, cy / 2, WString(chr, 1), fnt, Black()); - ib.SetHotSpot(Point(20, 20)); - return ib; + sw.DrawText(cx + cy, cx + cy, angle, WString(chr, 1), fnt, color); + ib.SetHotSpot(Point(cx + cy, cx + cy)); + return AutoCrop(ib, RGBAZero()); } String CompressGlyph(const Image& m) diff --git a/uppdev/Glyph/Glyph.upp b/uppdev/Glyph/Glyph.upp index 7a5eb51df..635268bb4 100644 --- a/uppdev/Glyph/Glyph.upp +++ b/uppdev/Glyph/Glyph.upp @@ -7,9 +7,11 @@ file TestDraw.cpp, FDrawClip.cpp, FDrawPut.cpp, + FDrawText.cpp, FDraw.cpp, Glyph.cpp, main.cpp optimize_speed, + text.qtf, help.txt, glyph.iml; diff --git a/uppdev/Glyph/glyph.h b/uppdev/Glyph/glyph.h index e2ffd479a..686498eb2 100644 --- a/uppdev/Glyph/glyph.h +++ b/uppdev/Glyph/glyph.h @@ -8,29 +8,22 @@ using namespace Upp; Image AutoCrop(const Image& m, RGBA c); -Image RenderGlyph(Font fnt, int chr); +Image RenderGlyph(Font fnt, int chr, Color color, int angle); + String CompressGlyph(const Image& m); Image DecompressGlyph(const String& g, Color c); -struct FDraw : Draw { - struct Cloff { - Vector clip; - Point offset; - }; - - Array cloff; - +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 bool IsPaintingOp(const Rect& r) const; 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); @@ -39,15 +32,31 @@ struct FDraw : Draw { 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 DrawDrawingOp(const Rect& target, const Drawing& w); 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 DrawPaintingOp(const Rect& target, const Painting& w); 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 { diff --git a/uppdev/Glyph/main.cpp b/uppdev/Glyph/main.cpp index 0f8720f4a..290917ca9 100644 --- a/uppdev/Glyph/main.cpp +++ b/uppdev/Glyph/main.cpp @@ -12,17 +12,6 @@ using namespace Upp; #define IMAGEFILE #include -struct ColorRenderer : DDARasterizer { - Draw *draw; - Color color; - - virtual void PutHorz(int x, int y, int cx) { - draw->DrawRect(x, y, cx, 1, color); - } - virtual void PutVert(int x, int y, int cy) { - draw->DrawRect(x, y, 1, cy, color); - } -}; struct MyApp : TopWindow { Point p; @@ -58,9 +47,10 @@ void MyApp::Paint(Draw& w) { Size sz = GetSize(); - w.DrawRect(sz, Gray()); + w.DrawRect(sz, White()); Vector clip; + clip.Add(RectC(50, 50, 10, 10)); clip.Add(RectC(100, 100, 20, 20)); clip.Add(RectC(200, 100, 40, 40)); @@ -68,18 +58,30 @@ void MyApp::Paint(Draw& w) clip.Add(RectC(200, 200, 40, 40)); clip.Add(RectC(220, 210, 30, 30)); + SeedRandom(); + for(int i = 0; i < 20; i++) + clip.Add(RectC(Random(sz.cx), Random(sz.cy), Random(100), Random(100))); + +// clip.Add(sz); TestDraw fw; + fw.Cy(sz.cy); fw.draw = &w; + fw.Init(sz); +/* fw.cloff.Add(); fw.cloff.Top().offset = Point(0, 0); for(int i = 0; i < clip.GetCount(); i++) { w.DrawRect(clip[i], LtGray()); fw.cloff.Top().clip.Add(clip[i]); } - +*/ + String txt = LoadFile(GetDataFile("text.qtf")); + ParseQTF(txt).Paint(Zoom(2, 10), fw, 0, 0, sz.cx); + +// fw.DrawText(sz.cx / 2, sz.cy / 2, -3600 * Bearing(p - sz / 2) / M_2PI, +// "Hello world! abcdefghijklmnopqrstuv", Roman(40).Underline(), Red()); fw.DrawImage(p.x, p.y, CtrlImg::reporticon(), RectC(0, 0, 20, 12), Blue()); -// fw.DrawRect(p.x, p.y, 16, 16, Red()); } GUI_APP_MAIN diff --git a/uppdev/Glyph/text.qtf b/uppdev/Glyph/text.qtf new file mode 100644 index 000000000..1cd5b9e24 --- /dev/null +++ b/uppdev/Glyph/text.qtf @@ -0,0 +1,65 @@ +[ $$0,0#00000000000000000000000000000000:Default] +[*C@3+75 $$1,1#36268203433472503231438721581057:code] +[*/+117 $$2,0#07143242482611002448121871408047:title] +[@(128.0.255)2 $$3,0#65874547464505293575048467215454:QTF Chr] +[{_}%EN-US +[s0;= [*8 QTF]&] +[s0; &] +[s0; QTF is the native format of Ultimate`+`+ rich texts (formatted +texts).&] +[s0; &] +[s0; It is byte oriented format. Bytes with values 2`-31 are ignored. +Other are interpreted as characters or formatting commands.&] +[s0; &] +[s0; Letters ([@4 a]`-[@4 zA]`-[@4 Z]), numbers ([@4 0]`-[@4 9]), space (32) +and characters&] +[s0; &] +[s0; [*@4 . , ; ! ? % ( ) / < > #]&] +[s0; &] +[s0; and bytes greater than 127 are guaranteed to be never used as +command characters (not even in future versions of QTF). Other +characters should be prefixed with escape character `` (reverse +apostrophe). Group of characters can be escaped using byte 1. +Example:&] +[s0; &] +[s1; `\"`\1a`[x`]`\1`[`* bold`]`\"&] +[s0; &] +[s0; Byte 0 represents the end of input sequence.&] +[s0; &] +[s0; Dimension units of QTF are dots `- one dot is defined as 1/600 +of inch.&] +[s0; &] +[s0; Colors are described as either number [@(128.0.255) 0]`-[@(128.0.255) 9], +with meaning&] +[s0; &] +[ {{1000:1000:1000:1000:1000:1000:1000:1000:1000:1000<96;>96;f4; [s0;%- [* 0]] +:: [s0;%- [* 1]] +:: [s0;%- [* 2]] +:: [s0;%- [* 3]] +:: [s0;%- [* 4]] +:: [s0;%- [* 5]] +:: [s0;%- [* 6]] +:: [s0;%- [* 7]] +:: [s0;%- [* 8]] +:: [s0;%- [* 9]] +::l/0r/0t/0b/0@0 [s0; ] +::@1 [s0; ] +::@2 [s0; ] +::@3 [s0; ] +::@4 [s0; ] +::@5 [s0; ] +::@6 [s0; ] +::@7 [s0; ] +::@8 [s0; ] +::@9 [s0; ] +::l/25r/25t/15b/15@2 [s0;%- [1 Black]] +:: [s0; [1 LtGray]] +:: [s0; [1 White]] +:: [s0;%- [1 Red]] +:: [s0;%- [1 Green]] +:: [s0;%- [1 Blue]] +:: [s0;%- [1 LtRed]] +:: [s0;%- [1 WhiteGray]] +:: [s0;%- [1 LtCyan]] +:: [s0;%- [1 Yellow]]}}&] +[s0; &]