From 0b91e2b10b77199575b8b969812230aee865d9f7 Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 19 Feb 2020 14:55:49 +0000 Subject: [PATCH] .examples git-svn-id: svn://ultimatepp.org/upp/trunk@14044 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/TextToSvgPath/TextToSvgPath.h | 28 +++++++++++ examples/TextToSvgPath/TextToSvgPath.lay | 18 +++++++ examples/TextToSvgPath/TextToSvgPath.upp | 15 ++++++ examples/TextToSvgPath/ToSvg.cpp | 63 ++++++++++++++++++++++++ examples/TextToSvgPath/main.cpp | 56 +++++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 examples/TextToSvgPath/TextToSvgPath.h create mode 100644 examples/TextToSvgPath/TextToSvgPath.lay create mode 100644 examples/TextToSvgPath/TextToSvgPath.upp create mode 100644 examples/TextToSvgPath/ToSvg.cpp create mode 100644 examples/TextToSvgPath/main.cpp diff --git a/examples/TextToSvgPath/TextToSvgPath.h b/examples/TextToSvgPath/TextToSvgPath.h new file mode 100644 index 000000000..59e38de8a --- /dev/null +++ b/examples/TextToSvgPath/TextToSvgPath.h @@ -0,0 +1,28 @@ +#ifndef _TextToSvgPath_TextToSvgPath_h +#define _TextToSvgPath_TextToSvgPath_h + +#include +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +String TextToSvgPath(double x, double y, const char *text, Font fnt, bool singleline); + +struct Preview : Ctrl { + String svgpath; + + virtual void Paint(Draw& w); +}; + +struct TextToSvgPathDlg : public WithTextToSvgPathLayout { + Preview preview; + + void Render(); + + TextToSvgPathDlg(); +}; + +#endif diff --git a/examples/TextToSvgPath/TextToSvgPath.lay b/examples/TextToSvgPath/TextToSvgPath.lay new file mode 100644 index 000000000..9da33e679 --- /dev/null +++ b/examples/TextToSvgPath/TextToSvgPath.lay @@ -0,0 +1,18 @@ +LAYOUT(TextToSvgPathLayout, 704, 588) + ITEM(Label, dv___0, SetLabel(t_("Text")).LeftPosZ(8, 33).TopPosZ(28, 19)) + ITEM(EditString, text, LeftPosZ(44, 428).TopPosZ(28, 19)) + ITEM(Label, dv___2, SetLabel(t_("Font")).LeftPosZ(8, 33).TopPosZ(4, 19)) + ITEM(DropList, face, LeftPosZ(44, 188).TopPosZ(4, 19)) + ITEM(Label, dv___4, SetLabel(t_("Height")).LeftPosZ(252, 39).TopPosZ(4, 19)) + ITEM(WithDropChoice, height, LeftPosZ(292, 56).TopPosZ(4, 19)) + ITEM(Option, bold, SetLabel(t_("Bold")).LeftPosZ(356, 52).TopPosZ(4, 18)) + ITEM(Option, italic, SetLabel(t_("Italic")).LeftPosZ(408, 52).TopPosZ(4, 18)) + ITEM(Option, underline, SetLabel(t_("Underline")).LeftPosZ(460, 72).TopPosZ(4, 18)) + ITEM(Option, strikeout, SetLabel(t_("Strikeout")).LeftPosZ(532, 68).TopPosZ(4, 18)) + ITEM(Option, nonaa, SetLabel(t_("NonAntiAliased")).LeftPosZ(600, 96).TopPosZ(4, 18)) + ITEM(LineEdit, svgpath, LeftPosZ(8, 688).TopPosZ(52, 268)) + UNTYPED(preview, LeftPosZ(8, 688).TopPosZ(324, 260)) + ITEM(Button, copy, SetLabel(t_("Copy path to clipboard")).LeftPosZ(568, 128).TopPosZ(28, 20)) + ITEM(Option, singleline, SetLabel(t_("Single line")).LeftPosZ(480, 80).TopPosZ(28, 20)) +END_LAYOUT + diff --git a/examples/TextToSvgPath/TextToSvgPath.upp b/examples/TextToSvgPath/TextToSvgPath.upp new file mode 100644 index 000000000..4d67498b0 --- /dev/null +++ b/examples/TextToSvgPath/TextToSvgPath.upp @@ -0,0 +1,15 @@ +description "GUI application that converts text to SVG path\377"; + +uses + CtrlLib, + RichEdit; + +file + TextToSvgPath.h, + ToSvg.cpp, + main.cpp, + TextToSvgPath.lay; + +mainconfig + "" = "GUI"; + diff --git a/examples/TextToSvgPath/ToSvg.cpp b/examples/TextToSvgPath/ToSvg.cpp new file mode 100644 index 000000000..122eaf454 --- /dev/null +++ b/examples/TextToSvgPath/ToSvg.cpp @@ -0,0 +1,63 @@ +#include "TextToSvgPath.h" + +struct TextToSvg : FontGlyphConsumer { + String t; + + void Put(Pointf p); + + virtual void Move(Pointf p); + virtual void Line(Pointf p); + virtual void Quadratic(Pointf p1, Pointf p2); + virtual void Cubic(Pointf p1, Pointf p2, Pointf p3); + virtual void Close(); +}; + +void TextToSvg::Put(Pointf p) +{ + t << Format("%.2f %.2f ", p.x, p.y); +} + +void TextToSvg::Move(Pointf p) +{ + t << 'M'; + Put(p); +} + +void TextToSvg::Line(Pointf p) +{ + t << 'L'; + Put(p); +} + +void TextToSvg::Quadratic(Pointf p1, Pointf p) +{ + t << 'Q'; + Put(p1); + Put(p); +} + +void TextToSvg::Cubic(Pointf p1, Pointf p2, Pointf p) +{ + t << 'C'; + Put(p1); + Put(p2); + Put(p); +} + +void TextToSvg::Close() +{ + t << 'Z'; +} + +String TextToSvgPath(double x, double y, const char *text, Font fnt, bool singleline) +{ + WString ws = ToUnicode(text, CHARSET_DEFAULT); + TextToSvg t; + for(const wchar *s = ~ws; *s; s++) { + fnt.Render(t, x, y, *s); + x += fnt[*s]; + if(!singleline) + t.t << "\n"; + } + return t.t; +} diff --git a/examples/TextToSvgPath/main.cpp b/examples/TextToSvgPath/main.cpp new file mode 100644 index 000000000..2d6849c8a --- /dev/null +++ b/examples/TextToSvgPath/main.cpp @@ -0,0 +1,56 @@ +#include "TextToSvgPath.h" + +void Preview::Paint(Draw& w) +{ + DrawPainter sw(w, GetSize()); + sw.Clear(SWhite()); + sw.Path(svgpath).Fill(SBlack()); +} + +TextToSvgPathDlg::TextToSvgPathDlg() +{ + CtrlLayout(*this, "Text to SVG path converter"); + for(Ctrl *q = GetFirstChild(); q; q = q->GetNext()) + if(!dynamic_cast