54 #include "pugixml.hpp"
56 namespace blender ::io ::gpencil {
59 GpencilExporterSVG::GpencilExporterSVG(
const char *filename,
const GpencilIOParams *iparams)
70 create_document_header();
76 export_gpencil_layers();
89 std::wstring wstr(filename_cstr_16);
90 result = main_doc_.save_file(wstr.c_str());
101 void GpencilExporterSVG::create_document_header()
104 pugi::xml_node decl = main_doc_.prepend_child(pugi::node_declaration);
105 decl.append_attribute(
"version") =
"1.0";
106 decl.append_attribute(
"encoding") =
"UTF-8";
108 pugi::xml_node comment = main_doc_.append_child(pugi::node_comment);
111 comment.set_value(txt);
113 pugi::xml_node doctype = main_doc_.append_child(pugi::node_doctype);
115 "svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
116 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"");
118 main_node_ = main_doc_.append_child(
"svg");
119 main_node_.append_attribute(
"version").set_value(
"1.0");
120 main_node_.append_attribute(
"x").set_value(
"0px");
121 main_node_.append_attribute(
"y").set_value(
"0px");
122 main_node_.append_attribute(
"xmlns").set_value(
"http://www.w3.org/2000/svg");
130 main_node_.append_attribute(
"width").set_value((
width +
"px").c_str());
131 main_node_.append_attribute(
"height").set_value((
height +
"px").c_str());
132 std::string viewbox =
"0 0 " +
width +
" " +
height;
133 main_node_.append_attribute(
"viewBox").set_value(viewbox.c_str());
137 void GpencilExporterSVG::export_gpencil_layers()
149 pugi::xml_node clip_node = main_node_.append_child(
"clipPath");
155 frame_node_ = main_node_.append_child(
"g");
157 frame_node_.append_attribute(
"id").set_value(frametxt.c_str());
161 frame_node_.append_attribute(
"clip-path")
165 pugi::xml_node ob_node = frame_node_.append_child(
"g");
168 sprintf(obtxt,
"blender_object_%s", ob->
id.
name + 2);
169 ob_node.append_attribute(
"id").set_value(obtxt);
182 if ((gpf ==
nullptr) || (gpf->
strokes.
first ==
nullptr)) {
187 std::string txt =
"Layer: ";
188 txt.append(gpl->info);
189 ob_node.append_child(pugi::node_comment).set_value(txt.c_str());
191 pugi::xml_node node_gpl = ob_node.append_child(
"g");
192 node_gpl.append_attribute(
"id").set_value(gpl->info);
195 if (gps->totpoints < 2) {
206 gps_duplicate->
mat_nr + 1);
216 gps_duplicate->
thickness += gpl->line_change;
228 export_stroke_to_polyline(gpl, gps_duplicate, node_gpl, is_stroke,
true);
234 export_stroke_to_polyline(gpl, gps_duplicate, node_gpl, is_stroke,
false);
245 export_stroke_to_path(gpl, gps_perimeter, node_gpl,
false);
262 void GpencilExporterSVG::export_stroke_to_path(
bGPDlayer *gpl,
264 pugi::xml_node node_gpl,
267 pugi::xml_node node_gps = node_gpl.append_child(
"path");
270 std::string stroke_hex;
277 node_gps.append_attribute(
"fill-opacity")
284 stroke_hex = rgb_to_hexstr(
col);
286 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
287 node_gps.append_attribute(
"stroke").set_value(
"none");
289 std::string txt =
"M";
290 for (
const int i : IndexRange(gps->
totpoints)) {
303 node_gps.append_attribute(
"d").set_value(txt.c_str());
311 void GpencilExporterSVG::export_stroke_to_polyline(
bGPDlayer *gpl,
313 pugi::xml_node node_gpl,
314 const bool is_stroke,
333 pugi::xml_node node_gps = node_gpl.append_child(do_fill || cyclic ?
"polygon" :
"polyline");
335 color_string_set(gpl, gps, node_gps, do_fill);
337 if (is_stroke && !do_fill) {
338 node_gps.append_attribute(
"stroke-width").set_value((radius * 2.0f) - gpl->
line_change);
342 for (
const int i : IndexRange(gps->
totpoints)) {
351 node_gps.append_attribute(
"points").set_value(txt.c_str());
359 void GpencilExporterSVG::color_string_set(
bGPDlayer *gpl,
361 pugi::xml_node node_gps,
371 std::string stroke_hex = rgb_to_hexstr(
col);
372 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
373 node_gps.append_attribute(
"stroke").set_value(
"none");
379 std::string stroke_hex = rgb_to_hexstr(
col);
380 node_gps.append_attribute(
"stroke").set_value(stroke_hex.c_str());
381 node_gps.append_attribute(
"stroke-opacity")
385 node_gps.append_attribute(
"fill").set_value(
"none");
386 node_gps.append_attribute(
"stroke-linecap").set_value(round_cap ?
"round" :
"square");
389 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
411 std::string hexcolor)
413 pugi::xml_node rect_node =
node.append_child(
"rect");
414 rect_node.append_attribute(
"x").set_value(
x);
415 rect_node.append_attribute(
"y").set_value(
y);
416 rect_node.append_attribute(
"width").set_value(
width);
417 rect_node.append_attribute(
"height").set_value(
height);
418 rect_node.append_attribute(
"fill").set_value(
"none");
419 if (thickness > 0.0f) {
420 rect_node.append_attribute(
"stroke").set_value(hexcolor.c_str());
421 rect_node.append_attribute(
"stroke-width").set_value(thickness);
439 std::string hexcolor)
441 pugi::xml_node nodetxt =
node.append_child(
"text");
443 nodetxt.append_attribute(
"x").set_value(
x);
444 nodetxt.append_attribute(
"y").set_value(
y);
446 nodetxt.append_attribute(
"font-size").set_value(
size);
447 nodetxt.append_attribute(
"fill").set_value(hexcolor.c_str());
448 nodetxt.text().set(text.c_str());
452 std::string GpencilExporterSVG::rgb_to_hexstr(
const float color[3])
458 sprintf(hex_string,
"#%02X%02X%02X",
r, g, b);
460 std::string hexstr = hex_string;
#define GPENCIL_ALPHA_OPACITY_THRESH
void BKE_gpencil_free_stroke(struct bGPDstroke *gps)
struct bGPDstroke * BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src, const bool dup_points, const bool dup_curve)
float BKE_gpencil_stroke_average_pressure_get(struct bGPDstroke *gps)
bool BKE_gpencil_stroke_sample(struct bGPdata *gpd, struct bGPDstroke *gps, const float dist, const bool select)
struct bGPDstroke * BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d, struct bGPdata *gpd, const struct bGPDlayer *gpl, struct bGPDstroke *gps, const int subdivisions, const float diff_mat[4][4])
bool BKE_gpencil_stroke_is_pressure_constant(struct bGPDstroke *gps)
General operations, lookup, etc. for materials.
struct MaterialGPencilStyle * BKE_gpencil_material_settings(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
float mat4_to_scale(const float M[4][4])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
@ GP_MATERIAL_STROKE_SHOW
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static void add_text(pugi::xml_node node, float x, float y, std::string text, const float size, std::string hexcolor)
static void add_rect(pugi::xml_node node, float x, float y, float width, float height, float thickness, std::string hexcolor)
float stroke_point_radius_get(struct bGPDlayer *gpl, struct bGPDstroke *gps)
blender::Vector< ObjectZ > ob_list_
struct Depsgraph * depsgraph_
void create_object_list()
struct RegionView3D * rv3d_
void prepare_stroke_export_colors(struct Object *ob, struct bGPDstroke *gps)
float2 gpencil_3D_point_to_2D(const float3 co)
void filename_set(const char *filename)
float stroke_average_opacity_get()
void prepare_layer_export_matrix(struct Object *ob, struct bGPDlayer *gpl)
@ GP_EXPORT_NORM_THICKNESS
#define SVG_EXPORTER_NAME
#define SVG_EXPORTER_VERSION
bool ED_gpencil_stroke_material_visible(Object *ob, const bGPDstroke *gps)
void *(* MEM_callocN)(size_t len, const char *str)
std::string to_string(const T &n)
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)