/Applications/Inkscape.app/Contents/Resources/bin/inkscape --export-png output.png -w 1024 -h 768 input.svg
I would like to launch or create a shared library with this functionality only.
The input file need to parse, and I don't know how is done the rendering, but I need only as png into a file.
Any hints?
So far:
from main.cpp is executed:
sp_main_console
inkscape_application_init
sp_process_file_list
SPDocument *doc = NULL;
try {
doc = Inkscape::Extension::open(NULL, filename);
} catch (Inkscape::Extension::Input::no_extension_found &e) {
doc = NULL;
} catch (Inkscape::Extension::Input::open_failed &e) {
doc = NULL;
}
inkscape_add_document
...
static int sp_do_export_png(SPDocument *doc)
...
sp_export_png_file
sp_png_write_rgba_striped - it will open the file finally...
http://bazaar.launchpad.net/~inkscape.d ... -write.cpp
Maybe this is the "headless rendering" part:
Code: Select all
struct SPEBP ebp;
ebp.width = width;
ebp.height = height;
ebp.background = bgcolor;
/* Create new drawing */
Inkscape::Drawing drawing;
drawing.setExact(true); // export with maximum blur rendering quality
unsigned const dkey = SPItem::display_key_new(1);
// Create ArenaItems and set transform
drawing.setRoot(doc->getRoot()->invoke_show(drawing, dkey, SP_ITEM_SHOW_DISPLAY));
drawing.root()->setTransform(affine);
ebp.drawing = &drawing;
or this?
Code: Select all
static int
sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data)
{
struct SPEBP *ebp = (struct SPEBP *) data;
if (ebp->status) {
if (!ebp->status((float) row / ebp->height, ebp->data)) return 0;
}
num_rows = MIN(num_rows, static_cast<int>(ebp->sheight));
num_rows = MIN(num_rows, static_cast<int>(ebp->height - row));
/* Set area of interest */
// bbox is now set to the entire image to prevent discontinuities
// in the image when blur is used (the borders may still be a bit
// off, but that's less noticeable).
Geom::IntRect bbox = Geom::IntRect::from_xywh(0, row, ebp->width, num_rows);
/* Update to renderable state */
ebp->drawing->update(bbox);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, ebp->width);
unsigned char *px = g_new(guchar, num_rows * stride);
cairo_surface_t *s = cairo_image_surface_create_for_data(
px, CAIRO_FORMAT_ARGB32, ebp->width, num_rows, stride);
Inkscape::DrawingContext ct(s, bbox.min());
ct.setSource(ebp->background);
ct.setOperator(CAIRO_OPERATOR_SOURCE);
ct.paint();
ct.setOperator(CAIRO_OPERATOR_OVER);
/* Render */
ebp->drawing->render(ct, bbox);
cairo_surface_destroy(s);
*to_free = px;
// PNG stores data as unpremultiplied big-endian RGBA, which means
// it's identical to the GdkPixbuf format.
convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride);
for (int r = 0; r < num_rows; r++) {
rows[r] = px + r * stride;
}
return num_rows;
}