60 g_log(
nullptr, G_LOG_LEVEL_WARNING,
"Pov-out err: ");
62 g_logv(
nullptr, G_LOG_LEVEL_WARNING,
fmt, args);
64 g_log(
nullptr, G_LOG_LEVEL_WARNING,
"\n");
82 g_return_val_if_fail(obj->style, ret);
83 ret *= SP_SCALE24_TO_FLOAT(obj->style->opacity.value);
114 char dbuf[G_ASCII_DTOSTR_BUF_SIZE+1];
115 g_ascii_formatd(dbuf, G_ASCII_DTOSTR_BUF_SIZE,
121#define DSTR(d) (dstr(d).c_str())
131 gchar *output = g_strdup_vprintf(
fmt, args);
146 out(
"<%s, %s>", DSTR(a), DSTR(b));
156 out(
"<%s, %s, %s>", DSTR(a), DSTR(b), DSTR(
c));
166 out(
"<%s, %s, %s, %s>", DSTR(a), DSTR(b), DSTR(
c), DSTR(d));
187 double startX,
double startY,
188 double startCtrlX,
double startCtrlY,
189 double endCtrlX,
double endCtrlY,
190 double endX,
double endY)
193 out(
" /*%4d*/ ", segNr);
194 vec2(startX, startY);
196 vec2(startCtrlX, startCtrlY);
198 vec2(endCtrlX, endCtrlY);
212 time_t tim = time(
nullptr);
213 out(
"/*###################################################################\n");
214 out(
"### This PovRay document was generated by Inkscape\n");
215 out(
"### http://www.inkscape.org\n");
216 out(
"### Created: %s", ctime(&tim));
218 out(
"#####################################################################\n");
220 out(
"### ============\n");
221 out(
"### POVRay information can be found at\n");
222 out(
"### http://www.povray.org\n");
224 out(
"### The 'AllShapes' objects at the bottom are provided as a\n");
225 out(
"### preview of how the output would look in a trace. However,\n");
226 out(
"### the main intent of this file is to provide the individual\n");
227 out(
"### shapes for inclusion in a POV project.\n");
229 out(
"### For an example of how to use this file, look at\n");
230 out(
"### share/examples/istest.pov\n");
232 out(
"### If you have any problems with this output, please see the\n");
233 out(
"### Inkscape project at http://www.inkscape.org, or visit\n");
234 out(
"### the #inkscape channel on irc.freenode.net . \n");
236 out(
"###################################################################*/\n");
238 out(
"/*###################################################################\n");
239 out(
"## Exports in this file\n");
240 out(
"##==========================\n");
244 out(
"###################################################################*/\n");
257 out(
"/*###################################################################\n");
258 out(
"### E N D F I L E\n");
259 out(
"###################################################################*/\n");
275 if (!is<SPShape>(
item))
278 auto shape = cast<SPShape>(
item);
279 if (shape->curve()->is_empty()) {
287 shapeInfo.
color =
"";
293 if (style && style->
fill.isColor()) {
317 int segmentCount = 0;
321 for (
const auto & pit : pathv)
330 if( !cit->isDegenerate() ) ++segmentCount;
334 out(
"/*###################################################\n");
335 out(
"### PRISM: %s\n",
id.c_str());
336 out(
"###################################################*/\n");
337 out(
"#declare %s = prism {\n",
id.c_str());
338 out(
" linear_sweep\n");
339 out(
" bezier_spline\n");
340 out(
" 1.0, //top\n");
341 out(
" 0.0, //bottom\n");
342 out(
" %d //nr points\n", segmentCount * 4);
356 for (
const auto & pit : pathv)
359 cminmax.
expandTo(pit.initialPoint());
368 if( cit->isDegenerate() )
376 p0[X], p0[Y], p0[X], p0[Y], p1[X], p1[Y], p1[X], p1[Y] );
381 std::vector<Geom::Point> points = cubic->controlPoints();
387 p0[X],p0[Y], p1[X],p1[Y], p2[X],p2[Y], p3[X],p3[Y]);
392 err(
"logical error, because pathv_to_linear_and_cubic_beziers was used");
396 if (segmentNr < segmentCount)
400 if (segmentNr > segmentCount)
402 err(
"Too many segments");
406 cminmax.
expandTo(cit->finalPoint());
413 double cminx = cminmax.
min()[X];
414 double cmaxx = cminmax.
max()[X];
415 double cminy = cminmax.
min()[Y];
416 double cmaxy = cminmax.
max()[Y];
418 out(
"#declare %s_MIN_X = %s;\n",
id.c_str(), DSTR(cminx));
419 out(
"#declare %s_CENTER_X = %s;\n",
id.c_str(), DSTR((cmaxx+cminx)/2.0));
420 out(
"#declare %s_MAX_X = %s;\n",
id.c_str(), DSTR(cmaxx));
421 out(
"#declare %s_WIDTH = %s;\n",
id.c_str(), DSTR(cmaxx-cminx));
422 out(
"#declare %s_MIN_Y = %s;\n",
id.c_str(), DSTR(cminy));
423 out(
"#declare %s_CENTER_Y = %s;\n",
id.c_str(), DSTR((cmaxy+cminy)/2.0));
424 out(
"#declare %s_MAX_Y = %s;\n",
id.c_str(), DSTR(cmaxy));
425 out(
"#declare %s_HEIGHT = %s;\n",
id.c_str(), DSTR(cmaxy-cminy));
426 if (shapeInfo.
color.length()>0)
427 out(
"#declare %s_COLOR = %s;\n",
428 id.c_str(), shapeInfo.
color.c_str());
429 out(
"/*###################################################\n");
430 out(
"### end %s\n",
id.c_str());
431 out(
"###################################################*/\n\n\n\n");
460 if (is<SPItem>(obj)) {
461 auto item = cast<SPItem>(obj);
483 double bignum = 1000000.0;
496 char *pfx = (
char *)
id.c_str();
497 out(
"/*###################################################\n");
498 out(
"### UNION OF ALL SHAPES IN DOCUMENT\n");
499 out(
"###################################################*/\n");
502 out(
" * Allow the user to redefine the finish{}\n");
503 out(
" * by declaring it before #including this file\n");
505 out(
"#ifndef (%s_Finish)\n", pfx);
506 out(
"#declare %s_Finish = finish {\n", pfx);
508 out(
" reflection 0.3\n");
509 out(
" specular 0.5\n");
513 out(
"#declare %s = union {\n",
id.c_str());
516 out(
" object { %s\n", povShape.id.c_str());
517 out(
" texture { \n");
518 if (povShape.color.length()>0)
519 out(
" pigment { %s }\n", povShape.color.c_str());
521 out(
" pigment { rgb <0,0,0> }\n");
522 out(
" finish { %s_Finish }\n", pfx);
529 double zinc = 0.2 / (double)
povShapes.size();
530 out(
"/*#### Same union, but with Z-diffs (actually Y in pov) ####*/\n");
533 out(
" * Allow the user to redefine the Z-Increment\n");
535 out(
"#ifndef (AllShapes_Z_Increment)\n");
536 out(
"#declare AllShapes_Z_Increment = %s;\n", DSTR(zinc));
539 out(
"#declare AllShapes_Z_Scale = 1.0;\n");
541 out(
"#declare %s_Z = union {\n", pfx);
545 out(
" object { %s\n", povShape.id.c_str());
546 out(
" texture { \n");
547 if (povShape.color.length()>0)
548 out(
" pigment { %s }\n", povShape.color.c_str());
550 out(
" pigment { rgb <0,0,0> }\n");
551 out(
" finish { %s_Finish }\n", pfx);
553 out(
" scale <1, %s_Z_Scale, 1>\n", pfx);
555 out(
"#declare %s_Z_Scale = %s_Z_Scale + %s_Z_Increment;\n\n",
561 out(
"#declare %s_MIN_X = %s;\n", pfx, DSTR(
minx));
562 out(
"#declare %s_CENTER_X = %s;\n", pfx, DSTR((
maxx+
minx)/2.0));
563 out(
"#declare %s_MAX_X = %s;\n", pfx, DSTR(
maxx));
564 out(
"#declare %s_WIDTH = %s;\n", pfx, DSTR(
maxx-
minx));
565 out(
"#declare %s_MIN_Y = %s;\n", pfx, DSTR(
miny));
566 out(
"#declare %s_CENTER_Y = %s;\n", pfx, DSTR((
maxy+
miny)/2.0));
567 out(
"#declare %s_MAX_Y = %s;\n", pfx, DSTR(
maxy));
568 out(
"#declare %s_HEIGHT = %s;\n", pfx, DSTR(
maxy-
miny));
569 out(
"/*##############################################\n");
570 out(
"### end %s\n",
id.c_str());
571 out(
"##############################################*/\n");
611 err(
"Could not output curves for %s", filename_utf8);
620 err(
"Could not write header for %s", filename_utf8);
628 err(
"Could not write footer for %s", filename_utf8);
641 for (String::iterator iter =
outbuf.begin() ; iter!=
outbuf.end(); ++iter)
701 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI
"\">\n"
702 "<name>" N_(
"PovRay Output")
"</name>\n"
703 "<id>org.inkscape.output.pov</id>\n"
705 "<extension>.pov</extension>\n"
706 "<mimetype>text/x-povray-script</mimetype>\n"
707 "<filetypename>" N_(
"PovRay (*.pov) (paths and shapes only)")
"</filetypename>\n"
708 "<filetypetooltip>" N_(
"PovRay Raytracer File")
"</filetypetooltip>\n"
710 "</inkscape-extension>",
711 std::make_unique<PovOutput>());
3x3 matrix representing an affine transformation.
Bezier curve with compile-time specified order.
void expandTo(CPoint const &p)
Enlarge the rectangle to contain the given point.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Point initialPoint() const
Get the first point in the path.
Two-dimensional point that doubles as a vector.
Axis aligned, non-empty rectangle.
The object that is the basis for the Extension system.
used for saving information about shapes
void vec4(double a, double b, double c, double d)
Output a 4d vector.
void segment(int segNr, double a0, double a1, double b0, double b1, double c0, double c1, double d0, double d1)
Output one bezier's start, start-control, end-control, and end nodes.
static void init()
Inkscape runtime startup call.
void vec3(double a, double b, double c)
Output a 3d vector.
void reset()
Reset variables to initial state.
void rgbf(double r, double g, double b, double f)
Output an rgbf color vector.
void saveDocument(SPDocument *doc, gchar const *filename)
Actual method to save document.
bool doCurve(SPItem *item, const String &id)
Output the SVG document's curve data as POV curves.
bool doTreeRecursive(SPDocument *doc, SPObject *obj)
Descend the svg tree recursively, translating data.
void out(const char *fmt,...) G_GNUC_PRINTF(2
Format text to our output buffer.
bool doTail()
Output the file footer.
void void vec2(double a, double b)
Output a 2d vector.
bool doTree(SPDocument *doc)
Output the curve data to buffer.
std::vector< PovShapeInfo > povShapes
bool check(Inkscape::Extension::Extension *module) override
Check whether we can actually output using this module.
Glib::ustring String
Our internal String definition.
bool doHeader()
Output the file header.
void save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) override
API call to perform the output to a file.
Typed SVG document implementation.
SPRoot * getRoot()
Returns our SPRoot.
Base class for visual SVG elements.
Geom::Affine i2dt_affine() const
Returns the transformation from item to desktop coords.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
char const * getId() const
Returns the objects current ID string.
T< SPAttr::FILL, SPIPaint > fill
fill
T< SPAttr::FILL_OPACITY, SPIScale24 > fill_opacity
fill-opacity
A way to clear the N_ macro, which is defined as an inline function.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
Specific curve type functions for Inkscape, not provided by lib2geom.
bool is_straight_curve(Geom::BezierCurve const &c)
Geom::PathVector pathv_to_linear_and_cubic_beziers(Geom::PathVector const &pathv)
Specific geometry functions for Inkscape, not provided my lib2geom.
Mini static library that contains the version of Inkscape.
static void err(const char *fmt,...)
static PovOutput::String dstr(double d)
We want to control floating output format.
static double effective_opacity(SPItem const *item)
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
void dump_fopen_call(char const *utf8name, char const *id)
FILE * fopen_utf8name(char const *utf8name, char const *mode)
Open a file with g_fopen().
Helper class to stream background task notifications as a series of messages.
char const * version_string
full version string
PathVector - a sequence of subpaths.
int const char va_start(args, fmt)
SPRoot: SVG <svg> implementation.
SPStyle - a style object for SPItem objects.