mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
SVG issues
git-svn-id: svn://ultimatepp.org/upp/trunk@926 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
00d350037a
commit
a355ab33da
11 changed files with 253 additions and 79 deletions
|
|
@ -1,41 +1,39 @@
|
|||
#ifndef _PainterExamples_Examples_h_
|
||||
#define _PainterExamples_Examples_h_
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <Painter/Painter.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <PainterSvg demo/Examples.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
void RegisterExample(const char *name, void (*ex)(Painter& pw));
|
||||
|
||||
struct App : TopWindow {
|
||||
virtual void Paint(Draw& w);
|
||||
|
||||
SplitterFrame split;
|
||||
ArrayCtrl list;
|
||||
FrameBottom< WithCtrlLayout<StaticRect> > ctrl;
|
||||
|
||||
typedef App CLASSNAME;
|
||||
|
||||
void DoPaint0(Painter& sw);
|
||||
void DoPaint(Painter& sw);
|
||||
void Print();
|
||||
void Benchmark();
|
||||
void Sync();
|
||||
void ToSlider(EditDouble *e, SliderCtrl *slider);
|
||||
void ToEdit(EditDouble *e, SliderCtrl *slider);
|
||||
void Pair(EditDouble& e, SliderCtrl& slider);
|
||||
void ToSlider();
|
||||
void Reset();
|
||||
void Serialize(Stream& s);
|
||||
|
||||
App();
|
||||
~App();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef _PainterExamples_Examples_h_
|
||||
#define _PainterExamples_Examples_h_
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <PainterSvg/PainterSvg.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <PainterSvg demo/Examples.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
void RegisterExample(const char *name, void (*ex)(Painter& pw));
|
||||
|
||||
struct App : TopWindow {
|
||||
virtual void Paint(Draw& w);
|
||||
|
||||
SplitterFrame split;
|
||||
ArrayCtrl list;
|
||||
FrameBottom< WithCtrlLayout<StaticRect> > ctrl;
|
||||
|
||||
typedef App CLASSNAME;
|
||||
|
||||
void DoPaint0(Painter& sw);
|
||||
void DoPaint(Painter& sw);
|
||||
void Print();
|
||||
void Benchmark();
|
||||
void Sync();
|
||||
void ToSlider(EditDouble *e, SliderCtrl *slider);
|
||||
void ToEdit(EditDouble *e, SliderCtrl *slider);
|
||||
void Pair(EditDouble& e, SliderCtrl& slider);
|
||||
void ToSlider();
|
||||
void Reset();
|
||||
void Serialize(Stream& s);
|
||||
|
||||
App();
|
||||
~App();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ description "Svg Painter demo";
|
|||
|
||||
uses
|
||||
CtrlLib,
|
||||
Painter;
|
||||
PainterSvg;
|
||||
|
||||
file
|
||||
SvgDemo.cpp,
|
||||
..\PainterSvg\ParseSvg.cpp,
|
||||
Examples.h,
|
||||
SvgDemo.cpp,
|
||||
main.cpp,
|
||||
Examples.lay;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
#include "Examples.h"
|
||||
|
||||
void ParseSVG(Painter& p, const char *svg);
|
||||
|
||||
void SvgDemo(Painter& sw)
|
||||
{
|
||||
String file = "C:\\demo.svg";
|
||||
|
||||
try {
|
||||
if (FileExists(file))
|
||||
ParseSVG(sw, file);
|
||||
else {
|
||||
sw.Scale(1./20);
|
||||
sw.Text(200, 200, "Please copy the svg file in '" + file + "'", Font(Font::ARIAL, 400));
|
||||
sw.Text(200, 700, "or change String file in SvgDemo.cpp", Font(Font::ARIAL, 400));
|
||||
sw.Opacity(1);
|
||||
sw.Stroke(1, Black());
|
||||
sw.Fill(Black());
|
||||
}
|
||||
}
|
||||
catch(XmlError e) {
|
||||
LOG("SVG XML error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
RegisterExample("Svg demo", SvgDemo);
|
||||
}
|
||||
#include "Examples.h"
|
||||
|
||||
void ParseSVG(Painter& p, const char *svg);
|
||||
|
||||
void SvgDemo(Painter& sw)
|
||||
{
|
||||
String file = "C:\\demo.svg";
|
||||
|
||||
try {
|
||||
if (FileExists(file))
|
||||
ParseSVG(sw, LoadFileBOM(file));
|
||||
else {
|
||||
sw.Scale(1./20);
|
||||
sw.Text(200, 200, "Please copy the svg file in '" + file + "'", Font(Font::ARIAL, 400));
|
||||
sw.Text(200, 700, "or change String file in SvgDemo.cpp", Font(Font::ARIAL, 400));
|
||||
sw.Opacity(1);
|
||||
sw.Stroke(1, Black());
|
||||
sw.Fill(Black());
|
||||
}
|
||||
}
|
||||
catch(XmlError e) {
|
||||
LOG("SVG XML error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
RegisterExample("Svg demo", SvgDemo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _PainterSvg_demo_icpp_init_stub
|
||||
#define _PainterSvg_demo_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Painter/init"
|
||||
#include "PainterSvg/init"
|
||||
#endif
|
||||
|
|
|
|||
13
bazaar/PainterSvg/PainterSvg.h
Normal file
13
bazaar/PainterSvg/PainterSvg.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _PainterSvg_PainterSvg_h
|
||||
#define _PainterSvg_PainterSvg_h
|
||||
|
||||
#include <Painter/Painter.h>
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
void ParseSVG(Painter& p, const char *svg);
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
||||
7
bazaar/PainterSvg/PainterSvg.upp
Normal file
7
bazaar/PainterSvg/PainterSvg.upp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
uses
|
||||
Painter;
|
||||
|
||||
file
|
||||
PainterSvg.h,
|
||||
ParseSvg.cpp;
|
||||
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <Painter/Painter.h>
|
||||
#include "PainterSvg.h"
|
||||
|
||||
using namespace Upp;
|
||||
NAMESPACE_UPP
|
||||
|
||||
Color GetSvgColor(const char *color);
|
||||
String GetValueStringXml(String str, const char* var);
|
||||
|
|
@ -616,9 +615,7 @@ void ParseG(Painter& p, XmlParser &xp, Svg2DTransform transf, SvgStyle style)
|
|||
}
|
||||
void ParseSVG(Painter& p, const char *svg)
|
||||
{
|
||||
String strXml = LoadFileBOM(svg);
|
||||
XmlParser xp(strXml);
|
||||
|
||||
XmlParser xp(svg);
|
||||
while(!xp.IsTag())
|
||||
xp.Skip();
|
||||
xp.PassTag("svg");
|
||||
|
|
@ -633,3 +630,4 @@ void ParseSVG(Painter& p, const char *svg)
|
|||
p.End();
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
4
bazaar/PainterSvg/init
Normal file
4
bazaar/PainterSvg/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _PainterSvg_icpp_init_stub
|
||||
#define _PainterSvg_icpp_init_stub
|
||||
#include "Painter/init"
|
||||
#endif
|
||||
15
bazaar/SvgView/SvgView.upp
Normal file
15
bazaar/SvgView/SvgView.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
description "Simple SVG viewer (PainterSvg demo)";
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
plugin\tif,
|
||||
plugin\jpg,
|
||||
plugin\gif,
|
||||
PainterSvg;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
8
bazaar/SvgView/init
Normal file
8
bazaar/SvgView/init
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _SvgView_icpp_init_stub
|
||||
#define _SvgView_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "plugin\tif/init"
|
||||
#include "plugin\jpg/init"
|
||||
#include "plugin\gif/init"
|
||||
#include "PainterSvg/init"
|
||||
#endif
|
||||
132
bazaar/SvgView/main.cpp
Normal file
132
bazaar/SvgView/main.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <PainterSvg/PainterSvg.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
class SvgView : public TopWindow {
|
||||
public:
|
||||
virtual bool Key(dword key, int);
|
||||
|
||||
private:
|
||||
ImageCtrl img;
|
||||
FileList files;
|
||||
Splitter splitter;
|
||||
String dir;
|
||||
FrameTop<Button> dirup;
|
||||
|
||||
void Load(const char *filename);
|
||||
void Enter();
|
||||
void DoDir();
|
||||
void DirUp();
|
||||
|
||||
public:
|
||||
typedef SvgView CLASSNAME;
|
||||
|
||||
void Serialize(Stream& s);
|
||||
void LoadDir(const char *d);
|
||||
void LoadDir() { LoadDir(dir); }
|
||||
|
||||
SvgView();
|
||||
};
|
||||
|
||||
void SvgView::Load(const char *filename)
|
||||
{
|
||||
img.SetImage(Null);
|
||||
ImageBuffer ib(GetSize());
|
||||
BufferPainter sw(ib);
|
||||
try {
|
||||
ParseSVG(sw, LoadFileBOM(filename));
|
||||
}
|
||||
catch(XmlError) {};
|
||||
img.SetImage(ib);
|
||||
}
|
||||
|
||||
void SvgView::LoadDir(const char *d)
|
||||
{
|
||||
files.Clear();
|
||||
dir = d;
|
||||
Title(dir);
|
||||
::Load(files, dir, "*.*");
|
||||
SortByExt(files);
|
||||
}
|
||||
|
||||
void SvgView::DirUp()
|
||||
{
|
||||
String n = DirectoryUp(dir);
|
||||
LoadDir(dir);
|
||||
files.FindSetCursor(n);
|
||||
}
|
||||
|
||||
void SvgView::Enter()
|
||||
{
|
||||
if(!files.IsCursor()) {
|
||||
Title(dir);
|
||||
return;
|
||||
}
|
||||
const FileList::File& f = files.Get(files.GetCursor());
|
||||
if(f.name == "..") {
|
||||
Title(dir);
|
||||
return;
|
||||
}
|
||||
String p = AppendFileName(dir, f.name);
|
||||
Title(p);
|
||||
if(!f.isdir)
|
||||
Load(p);
|
||||
}
|
||||
|
||||
void SvgView::DoDir()
|
||||
{
|
||||
if(!files.IsCursor())
|
||||
return;
|
||||
const FileList::File& f = files.Get(files.GetCursor());
|
||||
if(!f.isdir)
|
||||
return;
|
||||
LoadDir(AppendFileName(dir, f.name));
|
||||
}
|
||||
|
||||
bool SvgView::Key(dword key, int)
|
||||
{
|
||||
if(key == K_ENTER) {
|
||||
DoDir();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SvgView::Serialize(Stream& s)
|
||||
{
|
||||
int version = 0;
|
||||
s / version;
|
||||
SerializePlacement(s);
|
||||
s % files;
|
||||
s % dir;
|
||||
s % splitter;
|
||||
}
|
||||
|
||||
SvgView::SvgView()
|
||||
{
|
||||
splitter.Horz(files, img);
|
||||
splitter.SetPos(2700);
|
||||
Add(splitter.SizePos());
|
||||
|
||||
files.WhenEnterItem = THISBACK(Enter);
|
||||
files.WhenLeftDouble = THISBACK(DoDir);
|
||||
dirup.Height(max(CtrlImg::DirUp().GetSize().cy, Draw::GetStdFontCy() + 6));
|
||||
dirup.SetImage(CtrlImg::DirUp());
|
||||
dirup.NormalStyle();
|
||||
dirup <<= THISBACK(DirUp);
|
||||
files.AddFrame(dirup);
|
||||
|
||||
Sizeable().Zoomable();
|
||||
|
||||
dir = GetCurrentDirectory();
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
SvgView x;
|
||||
LoadFromFile(x);
|
||||
x.LoadDir();
|
||||
x.Run();
|
||||
StoreToFile(x);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue