Skip to content

Commit

Permalink
Initial svg file support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dov committed Apr 13, 2018
1 parent e3b7f6f commit ffac9ea
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 79 deletions.
6 changes: 6 additions & 0 deletions src/GivPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class GivPainter {
virtual void fill() = 0;
virtual void stroke() = 0;
virtual void close_path() = 0;
virtual void set_do_paint_by_index(bool do_paint_by_index) = 0;

virtual void set_dashes(int num_dashes,
double* dashes) = 0;
virtual void set_arrow(bool do_start_arrow,
Expand All @@ -58,6 +60,10 @@ class GivPainter {
double arrow_d4=-1,
double arrow_d5=-1
)=0;
virtual void render_svg_path(agg::svg::path_renderer *svg,
double mx, double my,
double scalex, double scaley) = 0;

};

#endif
15 changes: 15 additions & 0 deletions src/GivPainterAgg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,18 @@ GivPainterAgg::label_to_color(int label,
gg = 1.0/255*(((label+1) >> 8) % 256);
rr = 1.0/255*(((label+1) >> 16) % 256);
}

void GivPainterAgg::render_svg_path(agg::svg::path_renderer *svg,
double mx, double my,
double scalex, double scaley)
{
agg::trans_affine AggTransform(scalex,0,0,scaley,mx,my);
typedef agg::pixfmt_rgba32 pixfmt;
typedef agg::renderer_base<pixfmt> renderer_base;

// Render the svg in the buffer.
svg->render(d->pf, d->sl, d->rbase,
AggTransform,
d->rbase.clip_box()
);
}
73 changes: 38 additions & 35 deletions src/GivPainterAgg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,50 @@ class GivPainterAgg : public GivPainter {
bool do_antialiased);
virtual ~GivPainterAgg();

virtual void set_set_idx(int set_idx);
virtual void set_color(double red, double green, double blue, double alpha);
virtual int set_line_width(double line_width);
void set_set_idx(int set_idx) override;
void set_color(double red, double green, double blue, double alpha) override;
int set_line_width(double line_width) override;

int add_mark(GivMarkType mark_type,
double mark_size_x, double mark_size_y,
double x, double y) override;
int add_ellipse(double x, double y,
double sizex, double sizey,
double angle) override;
int add_text(const char *text,
double x, double y,
int text_align,
bool do_pango_markup) override;
int add_line_segment(double x0, double y0,
double x1, double y1,
bool do_polygon = false
) override;
void fill() override;
void stroke() override;
void close_path() override;
void draw_marks() override;
int set_text_size(double text_size) override;
int set_font(const char* font) override;
void set_do_paint_by_index(bool do_paint_by_index) override;
void set_dashes(int num_dashes,
double* dashes) override;
void set_arrow(bool do_start_arrow,
bool do_end_arrow,
double arrow_d1=-1,
double arrow_d2=-1,
double arrow_d3=-1,
double arrow_d4=-1,
double arrow_d5=-1
) override;
void render_svg_path(agg::svg::path_renderer *svg,
double mx, double my,
double scalex, double scaley) override;

virtual int add_mark(GivMarkType mark_type,
double mark_size_x, double mark_size_y,
double x, double y);
virtual int add_ellipse(double x, double y,
double sizex, double sizey,
double angle);
virtual int add_text(const char *text,
double x, double y,
int text_align,
bool do_pango_markup);
virtual int add_line_segment(double x0, double y0,
double x1, double y1,
bool do_polygon = false
);
virtual void fill();
virtual void stroke();
virtual void close_path();
virtual void draw_marks();
virtual int set_text_size(double text_size);
virtual int set_font(const char* font);
void set_do_paint_by_index(bool do_paint_by_index);
virtual void set_dashes(int num_dashes,
double* dashes);
virtual void set_arrow(bool do_start_arrow,
bool do_end_arrow,
double arrow_d1=-1,
double arrow_d2=-1,
double arrow_d3=-1,
double arrow_d4=-1,
double arrow_d5=-1
);
static void label_to_color(int label,
// output
double& rr,
double& gg,
double& bb);

private:
GivPainterAggPriv *d;
};
Expand Down
8 changes: 8 additions & 0 deletions src/GivPainterCairo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ GivPainterCairo::set_arrow(bool do_start_arrow,
d->do_end_arrow = do_end_arrow;
}

void GivPainterCairo::render_svg_path(agg::svg::path_renderer *svg,
double mx, double my,
double scalex, double scaley)
{
// TBD - Use svgpp or resvg!
}

void
GivPainterCairo::label_to_color(int label,
// output
Expand Down Expand Up @@ -512,3 +519,4 @@ draw_arrow(cairo_t *cr,
cairo_fill(cr);
cairo_restore(cr);
}

60 changes: 32 additions & 28 deletions src/GivPainterCairo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,45 @@ class GivPainterCairo : public GivPainter {
void set_cairo(cairo_t *cairo,
bool do_antialiased);
void set_swap_blue_red(bool whether);
virtual void set_set_idx(int set_idx);
virtual void set_color(double red, double green, double blue, double alpha);
virtual int set_line_width(double line_width);
void set_set_idx(int set_idx) override;
void set_color(double red, double green, double blue, double alpha) override;
int set_line_width(double line_width) override;

virtual int add_mark(GivMarkType mark_type,
int add_mark(GivMarkType mark_type,
double mark_size_x, double mark_size_y,
double x, double y);
virtual int add_ellipse(double x, double y,
double x, double y) override;
int add_ellipse(double x, double y,
double sizex, double sizey,
double angle);
virtual int add_text(const char *text,
double angle) override;
int add_text(const char *text,
double x, double y,
int text_align,
bool do_pango_markup);
virtual int add_line_segment(double x0, double y0,
bool do_pango_markup) override;
int add_line_segment(double x0, double y0,
double x1, double y1,
bool do_polygon=false);
virtual void fill();
virtual void stroke();
virtual void close_path();
virtual void draw_marks();
void set_do_paint_by_index(bool do_paint_by_index);
virtual int set_text_size(double text_size);
virtual int set_font(const char* font_name);
virtual void set_dashes(int num_dashes,
double* dashes);
virtual void set_arrow(bool do_start_arrow,
bool do_end_arrow,
double arrow_d1=-1,
double arrow_d2=-1,
double arrow_d3=-1,
double arrow_d4=-1,
double arrow_d5=-1
);
bool do_polygon=false) override;
void fill() override;
void stroke() override;
void close_path() override;
void draw_marks() override;
void set_do_paint_by_index(bool do_paint_by_index) override;
int set_text_size(double text_size) override;
int set_font(const char* font_name) override;
void set_dashes(int num_dashes,
double* dashes) override;
void set_arrow(bool do_start_arrow,
bool do_end_arrow,
double arrow_d1=-1,
double arrow_d2=-1,
double arrow_d3=-1,
double arrow_d4=-1,
double arrow_d5=-1
) override;

void render_svg_path(agg::svg::path_renderer *svg,
double mx, double my,
double scalex, double scaley) override;

static void label_to_color(int label,
// output
double& rr,
Expand Down
5 changes: 5 additions & 0 deletions src/GivRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ void GivRenderer::paint()
if (!dataset->is_visible)
continue;

if (dataset->svg)
// TBD - add transformation
painter.render_svg_path(dataset->svg,
-shift_x,-shift_y,scale_x,scale_y);

painter.set_set_idx(ds_idx);

// Create negative color values for "invisible" datasets
Expand Down
2 changes: 1 addition & 1 deletion src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env_command_line.Program('giv-remote-client',

libpath = ["#/src","#/src/plis",'#/src'] + env['LIBPATH']
libs = env['LIBS']
cpppath = ["gtkimageviewer"] + env['CPPPATH'] + ["glib-jsonrpc/"]
cpppath = ["gtkimageviewer"] + env['CPPPATH'] + ["glib-jsonrpc/","agg"]
cppdefines = ['PACKAGE_DOC_DIR=\'"${PACKAGE_DOC_DIR}"\'',
'PACKAGE_PLUGIN_DIR=\'"${PACKAGE_PLUGIN_DIR}"\'',
]
Expand Down
8 changes: 4 additions & 4 deletions src/agg/agg_allocator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************
* Project: XJet custom allocators for agg *
* Project: Custom allocators for agg *
* Module: *
* Module Description: *
* *
Expand All @@ -12,10 +12,10 @@

#include <string>

class EXJetAggOutOfMemory : public std::string
class EAggOutOfMemory : public std::string
{
public:
EXJetAggOutOfMemory(const char *msg="") : std::string(msg) {}
EAggOutOfMemory(const char *msg="") : std::string(msg) {}
};

namespace agg
Expand All @@ -33,7 +33,7 @@ namespace agg
static T* allocate(unsigned num) {
T* mem = new T [num];
if (mem == NULL)
throw EXJetAggOutOfMemory();
throw EAggOutOfMemory();
return mem;
}
static void deallocate(T* ptr, unsigned) { delete [] ptr; }
Expand Down
6 changes: 3 additions & 3 deletions src/agg/agg_svg_gradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#define SVG_GRADIENTS_H


#include "agg_color_rgba.h"
#include "agg_trans_affine.h"
#include <agg_color_rgba.h>
#include <agg_trans_affine.h>
#include <string.h>
#include <string>
#include <map>
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace agg {
{
unsigned i;
unsigned start = uround(m_color_profile[0].offset * color_lut_size);
unsigned end=0;
unsigned end;
color_type c = m_color_profile[0].color;
c.opacity(c.opacity() * opaque);
for(i = 0; i < start; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/agg/agg_svg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ namespace svg

end--;

int length = int(end - begin + 2);
int32 length = end - begin + 2;
char* result = new char[length];
memcpy(result, begin, length - 1);
result[length - 1] = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/agg/agg_svg_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ namespace svg

~parser();
parser(path_renderer& path);
parser(const parser&) = delete;
parser & operator=(const parser&) = delete;

void parse(const char* fname);
void parse_string(const char* svg_string);
Expand Down
3 changes: 3 additions & 0 deletions src/giv-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ giv_dataset_t *new_giv_dataset(int num_datasets)
dataset_p->tree_path_string = NULL;
dataset_p->is_visible = TRUE;
dataset_p->arrow_type = ARROW_TYPE_NONE;
dataset_p->svg = NULL;

return dataset_p;
}
Expand All @@ -92,6 +93,8 @@ void free_giv_data_set(giv_dataset_t *dataset_p)
p.text_object=NULL;
}
g_array_free(dataset_p->points, TRUE);
if (dataset_p->svg)
delete dataset_p->svg;
g_free(dataset_p);
}

2 changes: 2 additions & 0 deletions src/giv-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define GIV_DATA_H

#include <gtk/gtk.h>
#include "agg/agg_svg_path_renderer.h"

enum
{
Expand Down Expand Up @@ -89,6 +90,7 @@ typedef struct
gdouble *dashes;
gdouble shadow_offset_x;
gdouble shadow_offset_y;
agg::svg::path_renderer *svg = NULL; // svg path if data has svg
} giv_dataset_t;

typedef struct
Expand Down
Loading

0 comments on commit ffac9ea

Please sign in to comment.