mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
.examples
git-svn-id: svn://ultimatepp.org/upp/trunk@14044 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
beed1f40b2
commit
0b91e2b10b
5 changed files with 180 additions and 0 deletions
28
examples/TextToSvgPath/TextToSvgPath.h
Normal file
28
examples/TextToSvgPath/TextToSvgPath.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef _TextToSvgPath_TextToSvgPath_h
|
||||
#define _TextToSvgPath_TextToSvgPath_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <RichEdit/RichEdit.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <TextToSvgPath/TextToSvgPath.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
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<TopWindow> {
|
||||
Preview preview;
|
||||
|
||||
void Render();
|
||||
|
||||
TextToSvgPathDlg();
|
||||
};
|
||||
|
||||
#endif
|
||||
18
examples/TextToSvgPath/TextToSvgPath.lay
Normal file
18
examples/TextToSvgPath/TextToSvgPath.lay
Normal file
|
|
@ -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<EditInt>, 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
|
||||
|
||||
15
examples/TextToSvgPath/TextToSvgPath.upp
Normal file
15
examples/TextToSvgPath/TextToSvgPath.upp
Normal file
|
|
@ -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";
|
||||
|
||||
63
examples/TextToSvgPath/ToSvg.cpp
Normal file
63
examples/TextToSvgPath/ToSvg.cpp
Normal file
|
|
@ -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;
|
||||
}
|
||||
56
examples/TextToSvgPath/main.cpp
Normal file
56
examples/TextToSvgPath/main.cpp
Normal file
|
|
@ -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<Button *>(q))
|
||||
q->WhenAction = [=] { Render(); };
|
||||
|
||||
face.Add(Font::ARIAL);
|
||||
face.Add(Font::ROMAN);
|
||||
face.Add(Font::COURIER);
|
||||
for(int i = Font::COURIER + 1; i < Font::GetFaceCount(); i++)
|
||||
if(Font::GetFaceInfo(i) & Font::SCALEABLE)
|
||||
face.Add(i);
|
||||
SetupFaceList(face);
|
||||
face <<= Font::ARIAL;
|
||||
height.MinMax(6, 500);
|
||||
|
||||
for(int i = 4; i < 500; i += i < 16 ? 1 : i < 32 ? 4 : i < 48 ? 8 : 16)
|
||||
height.AddList(i);
|
||||
height <<= 128;
|
||||
|
||||
svgpath.SetReadOnly();
|
||||
preview.SetFrame(ViewFrame());
|
||||
|
||||
copy.SetImage(CtrlImg::copy());
|
||||
copy << [=] {
|
||||
WriteClipboardText(preview.svgpath);
|
||||
};
|
||||
}
|
||||
|
||||
void TextToSvgPathDlg::Render()
|
||||
{
|
||||
Font fnt(~face, ~height);
|
||||
fnt.Bold(~bold);
|
||||
fnt.Italic(~italic);
|
||||
fnt.Underline(~underline);
|
||||
fnt.Strikeout(~strikeout);
|
||||
fnt.NonAntiAliased(~nonaa);
|
||||
|
||||
svgpath <<= preview.svgpath = TextToSvgPath(0, 0, (String)~text, fnt, ~singleline);
|
||||
preview.Refresh();
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TextToSvgPathDlg().Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue