1 #ifndef DRAW_H
2 #define DRAW_H
3
4 #define SYSTEMDRAW 1
5
6 #include <Core/Core.h>
7
8 #ifdef flagCFONTS
9 #define CUSTOM_FONTSYS
10 #endif
11
12 namespace Upp {
13
14 class Drawing;
15 class Draw;
16 class Painting;
17 class SystemDraw;
18 class ImageDraw;
19
20 #include "Image.h"
21
22 const int FONT_V = 40;
23
24 struct FontGlyphConsumer {
25 virtual void Move(Pointf p) = 0;
26 virtual void Line(Pointf p) = 0;
27 virtual void Quadratic(Pointf p1, Pointf p2) = 0;
28 virtual void Cubic(Pointf p1, Pointf p2, Pointf p3) = 0;
29 virtual void Close() = 0;
30 };
31
32 #include "FontInt.h"
33
34 class FontInfo;
35
36 class Font : public ValueType<Font, FONT_V, Moveable<Font> >{
37 union {
38 int64 data;
39 struct {
40 word face;
41 word flags;
42 int16 height;
43 int16 width;
44 } v;
45 };
46
47 enum {
48 FONT_BOLD = 0x8000,
49 FONT_ITALIC = 0x4000,
50 FONT_UNDERLINE = 0x2000,
51 FONT_STRIKEOUT = 0x1000,
52 FONT_NON_ANTI_ALIASED = 0x800,
53 FONT_TRUE_TYPE_ONLY = 0x400
54 };
55
56 static Font AStdFont;
57 static Size StdFontSize;
58 static bool std_font_override;
59
60 static void SetStdFont0(Font font);
61 static Vector<FaceInfo>& FaceList();
62 static void SyncStdFont();
63 static void InitStdFont();
64
65 const CommonFontInfo& Fi() const;
66
67 friend void sInitFonts();
68 friend String GetFontDataSys(Font font);
69
70 public:
71 enum {
72 FIXEDPITCH = 0x0001,
73 SCALEABLE = 0x0002,
74 TTF = 0x0004,
75 SPECIAL = 0x0010,
76 SERIFSTYLE = 0x0020,
77 SCRIPTSTYLE = 0x0040,
78 };
79
80 static int GetFaceCount();
81 static String GetFaceName(int index);
82 static int FindFaceNameIndex(const String& name);
83 static dword GetFaceInfo(int index);
84 static void SetFace(int index, const String& name, dword info);
85 static void SetFace(int index, const String& name);
86
87 static void SetDefaultFont(Font font);
88 static void SetStdFont(Font font);
89 static Font GetStdFont();
90 static Size GetStdFontSize();
91
92 enum {
93 STDFONT,
94 SERIF,
95 SANSSERIF,
96 MONOSPACE,
97 #ifdef PLATFORM_WIN32
98 SYMBOL,
99 WINGDINGS,
100 TAHOMA,
101 #endif
102 OTHER,
103
104 // Backward compatibility:
105 ROMAN = SERIF,
106 ARIAL = SANSSERIF,
107 COURIER = MONOSPACE,
108 SCREEN_SERIF = SERIF,
109 SCREEN_SANS = SANSSERIF,
110 SCREEN_FIXED = MONOSPACE,
111 };
112
GetFace()113 int GetFace() const { return v.face; }
114 int GetHeight() const;
GetWidth()115 int GetWidth() const { return v.width; }
IsBold()116 bool IsBold() const { return v.flags & FONT_BOLD; }
IsItalic()117 bool IsItalic() const { return v.flags & FONT_ITALIC; }
IsUnderline()118 bool IsUnderline() const { return v.flags & FONT_UNDERLINE; }
IsStrikeout()119 bool IsStrikeout() const { return v.flags & FONT_STRIKEOUT; }
IsNonAntiAliased()120 bool IsNonAntiAliased() const { return v.flags & FONT_NON_ANTI_ALIASED; } // deprecated
IsTrueTypeOnly()121 bool IsTrueTypeOnly() const { return v.flags & FONT_TRUE_TYPE_ONLY; } // deprecated
122 String GetFaceName() const;
123 String GetFaceNameStd() const;
124 dword GetFaceInfo() const;
AsInt64()125 int64 AsInt64() const { return data; }
126
127 void RealizeStd();
128
Face(int n)129 Font& Face(int n) { v.face = n; return *this; }
Height(int n)130 Font& Height(int n) { v.height = n; return *this; }
Width(int n)131 Font& Width(int n) { v.width = n; return *this; }
Bold()132 Font& Bold() { v.flags |= FONT_BOLD; return *this; }
NoBold()133 Font& NoBold() { v.flags &= ~FONT_BOLD; return *this; }
Bold(bool b)134 Font& Bold(bool b) { return b ? Bold() : NoBold(); }
Italic()135 Font& Italic() { v.flags |= FONT_ITALIC; return *this; }
NoItalic()136 Font& NoItalic() { v.flags &= ~FONT_ITALIC; return *this; }
Italic(bool b)137 Font& Italic(bool b) { return b ? Italic() : NoItalic(); }
Underline()138 Font& Underline() { v.flags |= FONT_UNDERLINE; return *this; }
NoUnderline()139 Font& NoUnderline() { v.flags &= ~FONT_UNDERLINE; return *this; }
Underline(bool b)140 Font& Underline(bool b) { return b ? Underline() : NoUnderline(); }
Strikeout()141 Font& Strikeout() { v.flags |= FONT_STRIKEOUT; return *this; }
NoStrikeout()142 Font& NoStrikeout() { v.flags &= ~FONT_STRIKEOUT; return *this; }
Strikeout(bool b)143 Font& Strikeout(bool b) { return b ? Strikeout() : NoStrikeout(); }
NonAntiAliased()144 Font& NonAntiAliased() { v.flags |= FONT_NON_ANTI_ALIASED; return *this; }
NoNonAntiAliased()145 Font& NoNonAntiAliased() { v.flags &= ~FONT_NON_ANTI_ALIASED; return *this; } // deprecated
NonAntiAliased(bool b)146 Font& NonAntiAliased(bool b) { return b ? NonAntiAliased() : NoNonAntiAliased(); } // deprecated
TrueTypeOnly()147 Font& TrueTypeOnly() { v.flags |= FONT_TRUE_TYPE_ONLY; return *this; } // deprecated
NoTrueTypeOnly()148 Font& NoTrueTypeOnly() { v.flags &= ~FONT_TRUE_TYPE_ONLY; return *this; } // deprecated
TrueTypeOnly(bool b)149 Font& TrueTypeOnly(bool b) { return b ? TrueTypeOnly() : NoTrueTypeOnly(); } // deprecated
150
151 Font& FaceName(const String& name);
152
operator()153 Font operator()() const { return *this; }
operator()154 Font operator()(int n) const { return Font(*this).Height(n); }
155
GetAscent()156 int GetAscent() const { return Fi().ascent; }
GetDescent()157 int GetDescent() const { return Fi().descent; }
GetCy()158 int GetCy() const { return GetAscent() + GetDescent(); }
GetExternal()159 int GetExternal() const { return Fi().external; }
GetInternal()160 int GetInternal() const { return Fi().internal; }
GetLineHeight()161 int GetLineHeight() const { return GetCy() + GetExternal(); }
GetOverhang()162 int GetOverhang() const { return Fi().overhang; }
GetAveWidth()163 int GetAveWidth() const { return Fi().avewidth; }
GetMaxWidth()164 int GetMaxWidth() const { return Fi().maxwidth; }
165 bool IsNormal(int ch) const;
166 bool IsComposed(int ch) const;
167 bool IsReplaced(int ch) const;
168 bool IsMissing(int ch) const;
169 int HasChar(int ch) const;
170 int GetWidth(int c) const;
171 int operator[](int c) const { return GetWidth(c); }
172 int GetLeftSpace(int c) const;
173 int GetRightSpace(int c) const;
IsFixedPitch()174 bool IsFixedPitch() const { return Fi().fixedpitch; }
IsScaleable()175 bool IsScaleable() const { return Fi().scaleable; }
IsSpecial()176 bool IsSpecial() const { return GetFaceInfo() & SPECIAL; }
IsTrueType()177 bool IsTrueType() const { return Fi().ttf; }
IsSerif()178 bool IsSerif() const { return GetFaceInfo() & SERIFSTYLE; }
IsScript()179 bool IsScript() const { return GetFaceInfo() & SCRIPTSTYLE; }
180
181 String GetTextFlags() const;
182 void ParseTextFlags(const char *s);
183
184 String GetData() const;
185
186 void Render(FontGlyphConsumer& sw, double x, double y, int ch) const;
187
188 void Serialize(Stream& s);
189 void Jsonize(JsonIO& jio);
190 void Xmlize(XmlIO& xio);
191
192 bool operator==(Font f) const { return v.face == f.v.face && v.flags == f.v.flags &&
193 v.width == f.v.width && v.height == f.v.height; }
194 bool operator!=(Font f) const { return !operator==(f); }
195
GetHashValue()196 hash_t GetHashValue() const { return CombineHash(v.width, v.flags, v.height, v.face); }
IsNullInstance()197 bool IsNullInstance() const { return v.face == 0xffff; }
SetNull()198 void SetNull() { v.face = 0xffff; v.height = v.width = 0; v.flags = 0; }
Font()199 Font() { v.height = v.width = 0; v.face = v.flags = 0; }
Font(int face,int height)200 Font(int face, int height) { v.face = face; v.height = height; v.flags = 0; v.width = 0; }
Font(const Nuller &)201 Font(const Nuller&) { SetNull(); }
202
Value()203 operator Value() const { return RichToValue(*this); }
Font(const Value & q)204 Font(const Value& q) { *this = q.Get<Font>(); }
205
206 // BW compatibility
207 FontInfo Info() const;
208 };
209
210
211 //BW compatibility
212 class FontInfo { // Obsolete!
213 Font font;
214 friend class Font;
215 public:
GetAscent()216 int GetAscent() const { return font.GetAscent(); }
GetDescent()217 int GetDescent() const { return font.GetDescent(); }
GetExternal()218 int GetExternal() const { return font.GetExternal(); }
GetInternal()219 int GetInternal() const { return font.GetInternal(); }
GetHeight()220 int GetHeight() const { return font.GetCy(); }
GetLineHeight()221 int GetLineHeight() const { return font.GetLineHeight(); }
GetOverhang()222 int GetOverhang() const { return font.GetOverhang(); }
GetAveWidth()223 int GetAveWidth() const { return font.GetAveWidth(); }
GetMaxWidth()224 int GetMaxWidth() const { return font.GetMaxWidth(); }
HasChar(int c)225 int HasChar(int c) const { return font.HasChar(c); }
GetWidth(int c)226 int GetWidth(int c) const { return font.GetWidth(c); }
227 int operator[](int c) const { return GetWidth(c); }
GetLeftSpace(int c)228 int GetLeftSpace(int c) const { return font.GetLeftSpace(c); }
GetRightSpace(int c)229 int GetRightSpace(int c) const { return font.GetRightSpace(c); }
IsFixedPitch()230 bool IsFixedPitch() const { return font.IsFixedPitch(); }
IsScaleable()231 bool IsScaleable() const { return font.IsScaleable(); }
GetFontHeight()232 int GetFontHeight() const { return font.GetHeight(); }
GetFont()233 Font GetFont() const { return font; }
234 };
235
236 struct ComposedGlyph {
237 wchar basic_char;
238 Point mark_pos;
239 wchar mark_char;
240 Font mark_font;
241 };
242
243 bool Compose(Font fnt, int chr, ComposedGlyph& cs);
244
245 template<>
246 String AsString(const Font& f);
247
SetStdFont(Font font)248 inline void SetStdFont(Font font) { Font::SetStdFont(font); }
GetStdFont()249 inline Font GetStdFont() { return Font::GetStdFont(); }
GetStdFontSize()250 inline Size GetStdFontSize() { return Font::GetStdFontSize(); } // deprecated
GetStdFontCy()251 inline int GetStdFontCy() { return GetStdFontSize().cy; }
252
253 Font StdFont();
254
StdFont(int h)255 inline Font StdFont(int h) { return StdFont().Height(h); }
256
257 inline Font Serif(int n = -32000) { return Font(Font::SCREEN_SERIF, n); }
258 inline Font SansSerif(int n = -32000) { return Font(Font::SCREEN_SANS, n); }
259 inline Font Monospace(int n = -32000) { return Font(Font::SCREEN_FIXED, n); }
260
261 inline Font Roman(int n = -32000) { return Font(Font::SCREEN_SERIF, n); } // deprecated
262 inline Font Arial(int n = -32000) { return Font(Font::SCREEN_SANS, n); } // deprecated
263 inline Font Courier(int n = -32000) { return Font(Font::SCREEN_FIXED, n); } // deprecated
264
265 inline Font ScreenSerif(int n = -32000) { return Font(Font::SCREEN_SERIF, n); } // deprecated
266 inline Font ScreenSans(int n = -32000) { return Font(Font::SCREEN_SANS, n); } // deprecated
267 inline Font ScreenFixed(int n = -32000) { return Font(Font::SCREEN_FIXED, n); } // deprecated
268
269 #ifdef PLATFORM_WIN32 // backward comaptibility
270 inline Font Tahoma(int n = -32000) { return Font(Font::TAHOMA, n); }
271 #endif
272
273 Size GetTextSize(const wchar *text, Font font, int n = -1);
274 Size GetTextSize(const WString& text, Font font);
275 Size GetTextSize(const char *text, byte charset, Font font, int n = -1);
276 Size GetTextSize(const char *text, Font font, int n = -1);
277 Size GetTextSize(const String& text, Font font);
278
279 enum {
280 PEN_NULL = -1,
281 PEN_SOLID = -2,
282 PEN_DASH = -3,
283 #ifndef PLATFORM_WINCE
284 PEN_DOT = -4,
285 PEN_DASHDOT = -5,
286 PEN_DASHDOTDOT = -6,
287 #endif
288 };
289
290 class Image;
291
292 Color SBlack();
293 Color SGray();
294 Color SLtGray();
295 Color SWhiteGray();
296 Color SWhite();
297 Color SRed();
298 Color SGreen();
299 Color SBrown();
300 Color SBlue();
301 Color SMagenta();
302 Color SCyan();
303 Color SYellow();
304 Color SLtRed();
305 Color SLtGreen();
306 Color SLtYellow();
307 Color SLtBlue();
308 Color SLtMagenta();
309 Color SLtCyan();
310
311 Color SColorPaper();
312 Color SColorText();
313 Color SColorFace();
314 Color SColorHighlight();
315 Color SColorHighlightText();
316 Color SColorMenu();
317 Color SColorMenuText();
318 Color SColorInfo();
319 Color SColorInfoText();
320 Color SColorMark();
321 Color SColorMenuMark();
322 Color SColorDisabled();
323 Color SColorLight();
324 Color SColorLabel();
325 Color SColorShadow();
326
327 Color SColorLtFace();
328 Color SColorDkShadow();
329
330 void SBlack_Write(Color c);
331 void SGray_Write(Color c);
332 void SLtGray_Write(Color c);
333 void SWhiteGray_Write(Color c);
334 void SWhite_Write(Color c);
335 void SRed_Write(Color c);
336 void SGreen_Write(Color c);
337 void SBrown_Write(Color c);
338 void SBlue_Write(Color c);
339 void SMagenta_Write(Color c);
340 void SCyan_Write(Color c);
341 void SYellow_Write(Color c);
342 void SLtRed_Write(Color c);
343 void SLtGreen_Write(Color c);
344 void SLtYellow_Write(Color c);
345 void SLtBlue_Write(Color c);
346 void SLtMagenta_Write(Color c);
347 void SLtCyan_Write(Color c);
348
349 void SColorPaper_Write(Color c);
350 void SColorText_Write(Color c);
351 void SColorHighlight_Write(Color c);
352 void SColorHighlightText_Write(Color c);
353 void SColorMenu_Write(Color c);
354 void SColorMenuText_Write(Color c);
355 void SColorInfo_Write(Color c);
356 void SColorInfoText_Write(Color c);
357 void SColorMark_Write(Color c);
358 void SColorMenuMark_Write(Color c);
359 void SColorDisabled_Write(Color c);
360 void SColorLight_Write(Color c);
361 void SColorFace_Write(Color c);
362 void SColorLabel_Write(Color c);
363 void SColorShadow_Write(Color c);
364
365 void SColorLtFace_Write(Color c);
366 void SColorDkShadow_Write(Color c);
367
InvertColor()368 inline Color InvertColor() { return Color::Special(255); } // Special color that with DrawRect actually inverts the rectangle
DefaultInk()369 inline Color DefaultInk() { return Color::Special(254); } // SColorText on screen, Black on other outputs
370
371 extern bool dark_theme__;
372
IsDarkTheme()373 inline bool IsDarkTheme() { return dark_theme__; }
374
AdjustIfDark(Color c)375 inline Color AdjustIfDark(Color c) { return IsDarkTheme() ? DarkThemeCached(c) : c; }
376
377 Drawing AsDrawing(const Painting& pw);
378
379 class Painting : public ValueType<Painting, 48, Moveable<Painting> > {
380 String cmd;
381 ValueArray data;
382 Sizef size;
383
384 friend class PaintingPainter;
385 friend class Painter;
386
387 public:
GetSize()388 Sizef GetSize() const { return size; }
389
Clear()390 void Clear() { size = Null; data.Clear(); cmd.Clear(); }
Serialize(Stream & s)391 void Serialize(Stream& s) { s % cmd % data % size; }
Xmlize(XmlIO & xio)392 void Xmlize(XmlIO& xio) { XmlizeBySerialize(xio, *this); }
Jsonize(JsonIO & jio)393 void Jsonize(JsonIO& jio) { JsonizeBySerialize(jio, *this); }
IsNullInstance()394 bool IsNullInstance() const { return cmd.IsEmpty(); }
SetNull()395 void SetNull() { size = Null; }
396 bool operator==(const Painting& b) const { return cmd == b.cmd && data == b.data && size == b.size; }
GetHashValue()397 hash_t GetHashValue() const { return CombineHash(cmd, data); }
ToString()398 String ToString() const { return "painting " + AsString(size); }
399
Value()400 operator Value() const { return RichToValue(*this); }
Painting(const Value & q)401 Painting(const Value& q) { *this = q.Get<Painting>(); }
402
Painting()403 Painting() { SetNull(); }
Painting(const Nuller &)404 Painting(const Nuller&) { SetNull(); }
405 };
406
407 enum {
408 MODE_ANTIALIASED = 0,
409 MODE_NOAA = 1,
410 MODE_SUBPIXEL = 2,
411 };
412
413 bool HasPainter();
414 void PaintImageBuffer(ImageBuffer& ib, const Painting& p, Size sz, Point pos, int mode = MODE_ANTIALIASED);
415 void PaintImageBuffer(ImageBuffer& ib, const Painting& p, int mode = MODE_ANTIALIASED);
416 void PaintImageBuffer(ImageBuffer& ib, const Drawing& p, int mode = MODE_ANTIALIASED);
417
418 class Draw : NoCopy {
419 struct DrawingPos;
420
421 public:
422 enum {
423 DOTS = 0x001,
424 PRINTER = 0x004,
425 NATIVE = 0x008,
426 DATABANDS = 0x010,
427 DRAWTEXTLINES = 0x020,
428 DRAWING = 0x040,
429 };
430
431 virtual dword GetInfo() const = 0;
432
433 virtual Size GetPageSize() const;
434 virtual void StartPage();
435 virtual void EndPage();
436
437 virtual void BeginOp() = 0;
438 virtual void EndOp() = 0;
439 virtual void OffsetOp(Point p) = 0;
440 virtual bool ClipOp(const Rect& r) = 0;
441 virtual bool ClipoffOp(const Rect& r) = 0;
442 virtual bool ExcludeClipOp(const Rect& r) = 0;
443 virtual bool IntersectClipOp(const Rect& r) = 0;
444 virtual bool IsPaintingOp(const Rect& r) const = 0;
445 virtual Rect GetPaintRect() const;
446
447 virtual void DrawRectOp(int x, int y, int cx, int cy, Color color) = 0;
448 virtual void SysDrawImageOp(int x, int y, const Image& img, Color color);
449 virtual void SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color);
450 virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
451 virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
452 virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color) = 0;
453
454 virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
455 const int *counts, int count_count,
456 int width, Color color, Color doxor) = 0;
457 virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
458 const int *subpolygon_counts, int scc,
459 const int *disjunct_polygon_counts, int dpcc,
460 Color color, int width, Color outline,
461 uint64 pattern, Color doxor) = 0;
462 virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color) = 0;
463
464 virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) = 0;
465 virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
466 Color ink, int n, const int *dx) = 0;
467 virtual void DrawDrawingOp(const Rect& target, const Drawing& w);
468 virtual void DrawPaintingOp(const Rect& target, const Painting& w);
469
470 virtual Size GetNativeDpi() const;
471 virtual void BeginNative();
472 virtual void EndNative();
473
474 virtual int GetCloffLevel() const;
475
476 virtual void Escape(const String& data);
477
478 virtual ~Draw();
479
480 // --------------
481 Size GetPixelsPerInch() const;
482 Size GetPageMMs() const;
483
Dots()484 bool Dots() const { return GetInfo() & DOTS; }
Pixels()485 bool Pixels() const { return !Dots(); }
IsPrinter()486 bool IsPrinter() const { return GetInfo() & PRINTER; }
IsNative()487 bool IsNative() const { return GetInfo() & NATIVE; }
488
489 int GetNativeX(int x) const;
490 int GetNativeY(int y) const;
491 void Native(int& x, int& y) const;
492 void Native(Point& p) const;
493 void Native(Size& sz) const;
494 void Native(Rect& r) const;
495
Begin()496 void Begin() { BeginOp(); }
End()497 void End() { EndOp(); }
Offset(Point p)498 void Offset(Point p) { OffsetOp(p); }
499 void Offset(int x, int y);
Clip(const Rect & r)500 bool Clip(const Rect& r) { return ClipOp(r); }
501 bool Clip(int x, int y, int cx, int cy);
Clipoff(const Rect & r)502 bool Clipoff(const Rect& r) { return ClipoffOp(r); }
503 bool Clipoff(int x, int y, int cx, int cy);
ExcludeClip(const Rect & r)504 bool ExcludeClip(const Rect& r) { return ExcludeClipOp(r); }
505 bool ExcludeClip(int x, int y, int cx, int cy);
IntersectClip(const Rect & r)506 bool IntersectClip(const Rect& r) { return IntersectClipOp(r); }
507 bool IntersectClip(int x, int y, int cx, int cy);
IsPainting(const Rect & r)508 bool IsPainting(const Rect& r) const { return IsPaintingOp(r); }
509 bool IsPainting(int x, int y, int cx, int cy) const;
510
511 void DrawRect(int x, int y, int cx, int cy, Color color);
512 void DrawRect(const Rect& rect, Color color);
513
514 void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src);
515 void DrawImage(int x, int y, int cx, int cy, const Image& img);
516 void DrawImage(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
517 void DrawImage(int x, int y, int cx, int cy, const Image& img, Color color);
518
519 void DrawImage(const Rect& r, const Image& img, const Rect& src);
520 void DrawImage(const Rect& r, const Image& img);
521 void DrawImage(const Rect& r, const Image& img, const Rect& src, Color color);
522 void DrawImage(const Rect& r, const Image& img, Color color);
523
524 void DrawImage(int x, int y, const Image& img, const Rect& src);
525 void DrawImage(int x, int y, const Image& img);
526 void DrawImage(int x, int y, const Image& img, const Rect& src, Color color);
527 void DrawImage(int x, int y, const Image& img, Color color);
528
529 void DrawData(int x, int y, int cx, int cy, const String& data, const char *type);
530 void DrawData(const Rect& r, const String& data, const char *type);
531
532 void DrawLine(int x1, int y1, int x2, int y2, int width = 0, Color color = DefaultInk());
533 void DrawLine(Point p1, Point p2, int width = 0, Color color = DefaultInk());
534
535 void DrawEllipse(const Rect& r, Color color = DefaultInk(),
536 int pen = Null, Color pencolor = DefaultInk());
537 void DrawEllipse(int x, int y, int cx, int cy, Color color = DefaultInk(),
538 int pen = Null, Color pencolor = DefaultInk());
539
540 void DrawArc(const Rect& rc, Point start, Point end, int width = 0, Color color = DefaultInk());
541
542 void DrawPolyPolyline(const Point *vertices, int vertex_count,
543 const int *counts, int count_count,
544 int width = 0, Color color = DefaultInk(), Color doxor = Null);
545 void DrawPolyPolyline(const Vector<Point>& vertices, const Vector<int>& counts,
546 int width = 0, Color color = DefaultInk(), Color doxor = Null);
547 void DrawPolyline(const Point *vertices, int count,
548 int width = 0, Color color = DefaultInk(), Color doxor = Null);
549 void DrawPolyline(const Vector<Point>& vertices,
550 int width = 0, Color color = DefaultInk(), Color doxor = Null);
551
552 void DrawPolyPolyPolygon(const Point *vertices, int vertex_count,
553 const int *subpolygon_counts, int subpolygon_count_count,
554 const int *disjunct_polygon_counts, int disjunct_polygon_count_count,
555 Color color = DefaultInk(), int width = 0, Color outline = Null,
556 uint64 pattern = 0, Color doxor = Null);
557 void DrawPolyPolyPolygon(const Vector<Point>& vertices,
558 const Vector<int>& subpolygon_counts,
559 const Vector<int>& disjunct_polygon_counts,
560 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
561 void DrawPolyPolygon(const Point *vertices, int vertex_count,
562 const int *subpolygon_counts, int subpolygon_count_count,
563 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
564 void DrawPolyPolygon(const Vector<Point>& vertices, const Vector<int>& subpolygon_counts,
565 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
566 void DrawPolygons(const Point *vertices, int vertex_count,
567 const int *polygon_counts, int polygon_count_count,
568 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
569 void DrawPolygons(const Vector<Point>& vertices, const Vector<int>& polygon_counts,
570 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
571 void DrawPolygon(const Point *vertices, int vertex_count,
572 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
573 void DrawPolygon(const Vector<Point>& vertices,
574 Color color = DefaultInk(), int width = 0, Color outline = Null, uint64 pattern = 0, Color doxor = Null);
575
DrawDrawing(const Rect & r,const Drawing & iw)576 void DrawDrawing(const Rect& r, const Drawing& iw) { DrawDrawingOp(r, iw); }
577 void DrawDrawing(int x, int y, int cx, int cy, const Drawing& iw);
578 void DrawDrawing(int x, int y, const Drawing& iw);
579
DrawPainting(const Rect & r,const Painting & iw)580 void DrawPainting(const Rect& r, const Painting& iw) { DrawPaintingOp(r, iw); }
581 void DrawPainting(int x, int y, int cx, int cy, const Painting& iw);
582 void DrawPainting(int x, int y, const Painting& iw);
583
584 void DrawText(int x, int y, int angle, const wchar *text, Font font = StdFont(),
585 Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
586 void DrawText(int x, int y, const wchar *text, Font font = StdFont(),
587 Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
588
589 void DrawText(int x, int y, const WString& text, Font font = StdFont(),
590 Color ink = DefaultInk(), const int *dx = NULL);
591 void DrawText(int x, int y, int angle, const WString& text, Font font = StdFont(),
592 Color ink = DefaultInk(), const int *dx = NULL);
593
594 void DrawText(int x, int y, int angle, const char *text, byte charset,
595 Font font = StdFont(), Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
596 void DrawText(int x, int y, const char *text, byte charset, Font font = StdFont(),
597 Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
598
599 void DrawText(int x, int y, int angle, const char *text,
600 Font font = StdFont(), Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
601 void DrawText(int x, int y, const char *text, Font font = StdFont(),
602 Color ink = DefaultInk(), int n = -1, const int *dx = NULL);
603
604 void DrawText(int x, int y, const String& text, Font font = StdFont(),
605 Color ink = DefaultInk(), const int *dx = NULL);
606 void DrawText(int x, int y, int angle, const String& text, Font font = StdFont(),
607 Color ink = DefaultInk(), const int *dx = NULL);
608
609 static void SinCos(int angle, double& sina, double& cosa);
610
611 // deprecated:
SetStdFont(Font font)612 static void SetStdFont(Font font) { UPP::SetStdFont(font); }
GetStdFont()613 static Font GetStdFont() { return UPP::GetStdFont(); }
GetStdFontSize()614 static Size GetStdFontSize() { return UPP::GetStdFontSize(); }
GetStdFontCy()615 static int GetStdFontCy() { return GetStdFontSize().cy; }
GetPagePixels()616 Size GetPagePixels() const { return GetPageSize(); }
617
618 protected:
ResolveInk(Color c)619 Color ResolveInk(Color c) const { return c == DefaultInk() ? GetDefaultInk() : c; }
620 virtual Color GetDefaultInk() const;
621 };
622
623 void DrawImageBandRLE(Draw& w, int x, int y, const Image& m, int minp);
624
625 class DataDrawer {
626 typedef DataDrawer *(*Factory)();
FactoryFn()627 template <class T> static DataDrawer *FactoryFn() { return new T; }
628 static void AddFormat(const char *id, Factory f);
629 static VectorMap<String, void *>& Map();
630
631 public:
632 virtual void Open(const String& data, int cx, int cy) = 0;
633 virtual void Render(ImageBuffer& ib) = 0;
634 virtual ~DataDrawer();
635
636 static One<DataDrawer> Create(const String& id);
637
Register(const char * id)638 template <class T> static void Register(const char *id) { AddFormat(id, &DataDrawer::FactoryFn<T>); }
639 };
640
641 class Drawing : public ValueType<Drawing, 49, Moveable<Drawing> > {
642 Size size;
643 String data;
644 ValueArray val;
645
646 friend class DrawingDraw;
647 friend class Draw;
648
649 public:
650 operator bool() const { return !data.IsEmpty(); }
GetSize()651 Size GetSize() const { return size; }
SetSize(Size sz)652 void SetSize(Size sz) { size = sz; }
SetSize(int cx,int cy)653 void SetSize(int cx, int cy) { size = Size(cx, cy); }
654
655 Size RatioSize(int cx, int cy) const;
RatioSize(Size sz)656 Size RatioSize(Size sz) const { return RatioSize(sz.cx, sz.cy); }
657
Clear()658 void Clear() { data.Clear(); size = Null; }
659
660 void Append(Drawing& dw);
661
662 void Serialize(Stream& s);
Xmlize(XmlIO & xio)663 void Xmlize(XmlIO& xio) { XmlizeBySerialize(xio, *this); }
Jsonize(JsonIO & jio)664 void Jsonize(JsonIO& jio) { JsonizeBySerialize(jio, *this); }
665
IsNullInstance()666 bool IsNullInstance() const { return data.IsEmpty(); }
SetNull()667 void SetNull() { size = Null; data.Clear(); }
668
669 bool operator==(const Drawing& b) const { return val == b.val && data == b.data && size == b.size; }
ToString()670 String ToString() const { return "drawing " + AsString(size); }
GetHashValue()671 hash_t GetHashValue() const { return CombineHash(data, val); }
672
Value()673 operator Value() const { return RichToValue(*this); }
Drawing(const Value & src)674 Drawing(const Value& src) { *this = src.Get<Drawing>(); }
675
Drawing()676 Drawing() { SetNull(); }
Drawing(const Nuller &)677 Drawing(const Nuller&) { SetNull(); }
678 };
679
680 class DrawingDraw : public Draw {
681 public:
682 virtual dword GetInfo() const;
683 virtual Size GetPageSize() const;
684 virtual Rect GetPaintRect() const;
685
686 virtual void BeginOp();
687 virtual void EndOp();
688 virtual void OffsetOp(Point p);
689 virtual bool ClipOp(const Rect& r);
690 virtual bool ClipoffOp(const Rect& r);
691 virtual bool ExcludeClipOp(const Rect& r);
692 virtual bool IntersectClipOp(const Rect& r);
693 virtual bool IsPaintingOp(const Rect& r) const;
694
695 virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
696 virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
697 virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
698 virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
699 virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
700 const int *counts, int count_count,
701 int width, Color color, Color doxor);
702 virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
703 const int *subpolygon_counts, int scc,
704 const int *disjunct_polygon_counts, int dpcc,
705 Color color, int width, Color outline,
706 uint64 pattern, Color doxor);
707 virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
708 virtual void DrawArcOp(const Rect& rc, Point start, Point end, int pen, Color pencolor);
709 virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
710 Color ink, int n, const int *dx);
711
712 virtual void DrawDrawingOp(const Rect& target, const Drawing& w);
713 virtual void DrawPaintingOp(const Rect& target, const Painting& w);
714
715 virtual void Escape(const String& data);
716
717 private:
718 Size size;
719 bool dots;
720 StringStream drawing;
721 ValueArray val;
722
723 Stream& DrawingOp(int code);
724
725 public:
726 void Create(int cx, int cy, bool dots = true);
727 void Create(Size sz, bool dots = true);
728
GetSize()729 Size GetSize() const { return size; }
730
731 Drawing GetResult();
Drawing()732 operator Drawing() { return GetResult(); }
733
734 DrawingDraw();
735 DrawingDraw(int cx, int cy, bool dots = true);
736 DrawingDraw(Size sz, bool dots = true);
737 };
738
739 class NilDraw : public Draw {
740 public:
741 virtual dword GetInfo() const;
742 virtual Size GetPageSize() const;
743 virtual void BeginOp();
744 virtual void EndOp();
745 virtual void OffsetOp(Point p);
746 virtual bool ClipOp(const Rect& r);
747 virtual bool ClipoffOp(const Rect& r);
748 virtual bool ExcludeClipOp(const Rect& r);
749 virtual bool IntersectClipOp(const Rect& r);
750 virtual bool IsPaintingOp(const Rect& r) const;
751 virtual Rect GetPaintRect() const;
752
753 virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
754 virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
755 virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
756 virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
757 virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
758 const int *counts, int count_count,
759 int width, Color color, Color doxor);
760 virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
761 const int *subpolygon_counts, int scc,
762 const int *disjunct_polygon_counts, int dpcc,
763 Color color, int width, Color outline,
764 uint64 pattern, Color doxor);
765 virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
766 virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
767 virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
768 Color ink, int n, const int *dx);
769 virtual void DrawDrawingOp(const Rect& target, const Drawing& w);
770 virtual void DrawPaintingOp(const Rect& target, const Painting& w);
771 };
772
773 struct DrawProxy : Draw {
774 Draw *ptr;
775
SetTargetDrawProxy776 void SetTarget(Draw *w) { ptr = w; }
777
778 virtual dword GetInfo() const;
779
780 virtual Size GetPageSize() const;
781 virtual void StartPage();
782 virtual void EndPage();
783
784 virtual void BeginOp();
785 virtual void EndOp();
786 virtual void OffsetOp(Point p);
787 virtual bool ClipOp(const Rect& r);
788 virtual bool ClipoffOp(const Rect& r);
789 virtual bool ExcludeClipOp(const Rect& r);
790 virtual bool IntersectClipOp(const Rect& r);
791 virtual bool IsPaintingOp(const Rect& r) const;
792 virtual Rect GetPaintRect() const;
793
794 virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
795 virtual void SysDrawImageOp(int x, int y, const Image& img, Color color);
796 virtual void SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color);
797 virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
798 virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
799 virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
800
801 virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
802 const int *counts, int count_count,
803 int width, Color color, Color doxor);
804 virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
805 const int *subpolygon_counts, int scc,
806 const int *disjunct_polygon_counts, int dpcc,
807 Color color, int width, Color outline,
808 uint64 pattern, Color doxor);
809 virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
810
811 virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
812 virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
813 Color ink, int n, const int *dx);
814 virtual void DrawDrawingOp(const Rect& target, const Drawing& w);
815 virtual void DrawPaintingOp(const Rect& target, const Painting& w);
816
817 virtual Size GetNativeDpi() const;
818 virtual void BeginNative();
819 virtual void EndNative();
820
821 virtual int GetCloffLevel() const;
822
823 virtual void Escape(const String& data);
824 };
825
826 class ImageAnyDraw : public Draw {
827 Draw *draw;
828
829 void Init(Size sz);
830
831 public:
832 virtual dword GetInfo() const;
833 virtual Size GetPageSize() const;
834 virtual void BeginOp();
835 virtual void EndOp();
836 virtual void OffsetOp(Point p);
837 virtual bool ClipOp(const Rect& r);
838 virtual bool ClipoffOp(const Rect& r);
839 virtual bool ExcludeClipOp(const Rect& r);
840 virtual bool IntersectClipOp(const Rect& r);
841 virtual bool IsPaintingOp(const Rect& r) const;
842 virtual Rect GetPaintRect() const;
843
844 virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
845 virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
846 virtual void DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id);
847 virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
848 virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
849 const int *counts, int count_count,
850 int width, Color color, Color doxor);
851 virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
852 const int *subpolygon_counts, int scc,
853 const int *disjunct_polygon_counts, int dpcc,
854 Color color, int width, Color outline,
855 uint64 pattern, Color doxor);
856 virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
857 virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
858 virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
859 Color ink, int n, const int *dx);
860 virtual void DrawDrawingOp(const Rect& target, const Drawing& w);
861 virtual void DrawPaintingOp(const Rect& target, const Painting& w);
862
863 public:
864 static bool IsAvailable();
865
866 operator Image() const;
867
868 ImageAnyDraw(Size sz);
869 ImageAnyDraw(int cx, int cy);
870
871 ~ImageAnyDraw();
872 };
873
874 void AddNotEmpty(Vector<Rect>& result, int left, int right, int top, int bottom);
875 bool Subtract(const Rect& r, const Rect& sub, Vector<Rect>& result);
876 bool Subtract(const Vector<Rect>& rr, const Rect& sub, Vector<Rect>& result);
877 Vector<Rect> Subtract(const Vector<Rect>& rr, const Rect& sub, bool& changed);
878 Vector<Rect> Intersect(const Vector<Rect>& b, const Rect& a, bool& changed);
879
880 void Subtract(Vector<Rect>& rr, const Rect& sub);
881 void Union(Vector<Rect>& rr, const Rect& add);
882
883 Vector<Rect> Intersection(const Vector<Rect>& b, const Rect& a);
884
885 void AddRefreshRect(Vector<Rect>& invalid, const Rect& _r);
886
887 void DrawDragFrame(Draw& w, const Rect& r, int n, const int *pattern, Color color, int animation);
888 void DrawDragFrame(Draw& w, const Rect& r, int n, int pattern, Color color, int animation);
889
890 void DrawRect(Draw& w, const Rect& rect, const Image& img, bool ralgn = false); //??? TODO
891 void DrawRect(Draw& w, int x, int y, int cx, int cy, const Image& img, bool ra = false);
892
893 void DrawTiles(Draw& w, int x, int y, int cx, int cy, const Image& img);
894 void DrawTiles(Draw& w, const Rect& rect, const Image& img);
895
896 void DrawFatFrame(Draw& w, int x, int y, int cx, int cy, Color color, int n);
897 void DrawFatFrame(Draw& w, const Rect& r, Color color, int n);
898
899 void DrawFrame(Draw& w, int x, int y, int cx, int cy,
900 Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor);
901 void DrawFrame(Draw& w, const Rect& r,
902 Color leftcolor, Color topcolor, Color rightcolor, Color bottomcolor);
903 void DrawFrame(Draw& w, int x, int y, int cx, int cy,
904 Color topleftcolor, Color bottomrightcolor);
905 void DrawFrame(Draw& w, const Rect& r,
906 Color topleftcolor, Color bottomrightcolor);
907 void DrawFrame(Draw& w, int x, int y, int cx, int cy, Color color);
908 void DrawFrame(Draw& w, const Rect& r, Color color);
909
910 void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *colors_ltrd); //TODO
911 void DrawBorder(Draw& w, const Rect& r, const ColorF *colors_ltrd);
912
913 const ColorF *BlackBorder();
914 const ColorF *WhiteBorder();
915 const ColorF *ButtonPushBorder();
916 const ColorF *EdgeButtonBorder();
917 const ColorF *DefButtonBorder();
918 const ColorF *ButtonBorder();
919 const ColorF *InsetBorder();
920 const ColorF *OutsetBorder();
921 const ColorF *ThinOutsetBorder();
922 const ColorF *ThinInsetBorder();
923
924 void DrawBorder(Draw& w, int x, int y, int cx, int cy, const ColorF *(*colors_ltrd)());
925 void DrawBorder(Draw& w, const Rect& r, const ColorF *(*colors_ltrd)());
926
927 void DrawRectMinusRect(Draw& w, const Rect& rect, const Rect& inner, Color color);
928
929 void DrawHighlightImage(Draw& w, int x, int y, const Image& img, bool highlight = true,
930 bool enabled = true, Color maskcolor = SColorPaper);
931
932 Color GradientColor(Color fc, Color tc, int i, int n);
933
934 void DrawTextEllipsis(Draw& w, int x, int y, int cx, const char *text, const char *ellipsis,
935 Font font = StdFont(), Color ink = SColorText(), int n = -1);
936 void DrawTextEllipsis(Draw& w, int x, int y, int cx, const wchar *text, const char *ellipsis,
937 Font font = StdFont(), Color ink = SColorText(), int n = -1);
938
939 Size GetTLTextSize(const wchar *text, Font font = StdFont());
940 int GetTLTextHeight(const wchar *s, Font font = StdFont());
941 void DrawTLText(Draw& draw, int x, int y, int cx, const wchar *text, Font font = StdFont(),
942 Color ink = SColorText(), int accesskey = 0);
943
944 enum {
945 BUTTON_NORMAL, BUTTON_OK, BUTTON_HIGHLIGHT, BUTTON_PUSH, BUTTON_DISABLED, BUTTON_CHECKED,
946 BUTTON_VERTICAL = 0x100,
947 BUTTON_EDGE = 0x200,
948 BUTTON_TOOL = 0x400,
949 BUTTON_SCROLL = 0x800,
950 };
951
952 void DrawXPButton(Draw& w, Rect r, int type);
953
954 struct PdfSignatureInfo;
955 typedef String (*DrawingToPdfFnType)(const Array<Drawing>& report, Size pagesize, int margin,
956 bool pdfa, const PdfSignatureInfo *sign);
957
958 void SetDrawingToPdfFn(DrawingToPdfFnType Pdf);
959 DrawingToPdfFnType GetDrawingToPdfFn();
960
961 #include "Display.h"
962 #include "Cham.h"
963 #include "DDARasterizer.h"
964 #include "SDraw.h"
965
966 }
967
968 #endif
969