8
* Lauris Kaplinski <lauris@kaplinski.com>
9
* bulia byak <buliabyak@users.sf.net>
10
* Ulf Erikson <ulferikson@users.sf.net>
12
* Basic printing code, EXCEPT image and
13
* ascii85 filter is in public domain
15
* Image printing and Ascii85 filter:
17
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
18
* Copyright (C) 1997-98 Peter Kirchgessner
19
* George White <aa056@chebucto.ns.ca>
20
* Austin Donnelly <austin@gimp.org>
22
* Licensed under GNU GPL
34
#include <glib/gmem.h>
35
#include <libnr/n-art-bpath.h>
36
#include <libnr/nr-point-matrix-ops.h>
38
#include <gtk/gtkstock.h>
39
#include <gtk/gtkvbox.h>
40
#include <gtk/gtkframe.h>
41
#include <gtk/gtkradiobutton.h>
42
#include <gtk/gtkcombo.h>
43
#include <gtk/gtklabel.h>
44
#include <gtk/gtkentry.h>
45
#include <gtk/gtktooltips.h>
47
#include <glibmm/i18n.h>
48
#include "display/nr-arena-item.h"
49
#include "display/canvas-bpath.h"
52
#include "sp-linear-gradient.h"
53
#include "sp-radial-gradient.h"
55
#include "libnrtype/font-instance.h"
56
#include "libnrtype/font-style-to-pos.h"
58
#include <unit-constants.h>
61
#include "extension/system.h"
62
#include "extension/print.h"
72
PrintPDF::PrintPDF() :
79
PrintPDF::~PrintPDF(void)
81
/* fixme: should really use pclose for popen'd streams */
82
if (_stream) fclose(_stream);
84
/* restore default signal handling for SIGPIPE */
85
#if !defined(_WIN32) && !defined(__WIN32__)
86
(void) signal(SIGPIPE, SIG_DFL);
93
PrintPDF::setup(Inkscape::Extension::Print * mod)
95
static gchar const *const pdr[] = {"72", "75", "100", "144", "150", "200", "300", "360", "600", "1200", "2400", NULL};
98
Inkscape::XML::Node *repr = ((SPModule *) mod)->repr;
101
unsigned int ret = FALSE;
104
GtkTooltips *tt = gtk_tooltips_new();
105
g_object_ref((GObject *) tt);
106
gtk_object_sink((GtkObject *) tt);
108
GtkWidget *dlg = gtk_dialog_new_with_buttons(_("Print Destination"),
109
// SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window,
111
(GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT),
118
gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK);
120
GtkWidget *vbox = GTK_DIALOG(dlg)->vbox;
121
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
122
/* Print properties frame */
123
GtkWidget *f = gtk_frame_new(_("Print properties"));
124
gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);
125
GtkWidget *vb = gtk_vbox_new(FALSE, 4);
126
gtk_container_add(GTK_CONTAINER(f), vb);
127
gtk_container_set_border_width(GTK_CONTAINER(vb), 4);
129
bool const p2bm = mod->get_param_bool("bitmap");
130
GtkWidget *rb = gtk_radio_button_new_with_label(NULL, _("Print using PDF operators"));
131
gtk_tooltips_set_tip((GtkTooltips *) tt, rb,
132
_("Use PDF vector operators. The resulting image is usually smaller "
133
"in file size and can be arbitrarily scaled, but "
134
"patterns will be lost."), NULL);
135
if (!p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE);
136
gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0);
137
rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group((GtkRadioButton *) rb), _("Print as bitmap"));
138
gtk_tooltips_set_tip((GtkTooltips *) tt, rb,
139
_("Print everything as bitmap. The resulting image is usually larger "
140
"in file size and cannot be arbitrarily scaled without quality loss, "
141
"but all objects will be rendered exactly as displayed."), NULL);
142
if (p2bm) gtk_toggle_button_set_active((GtkToggleButton *) rb, TRUE);
143
gtk_box_pack_start(GTK_BOX(vb), rb, FALSE, FALSE, 0);
145
GtkWidget *hb = gtk_hbox_new(FALSE, 4);
146
gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0);
147
GtkWidget *combo = gtk_combo_new();
148
gtk_combo_set_value_in_list(GTK_COMBO(combo), FALSE, FALSE);
149
gtk_combo_set_use_arrows(GTK_COMBO(combo), TRUE);
150
gtk_combo_set_use_arrows_always(GTK_COMBO(combo), TRUE);
151
gtk_widget_set_size_request(combo, 64, -1);
152
gtk_tooltips_set_tip((GtkTooltips *) tt, GTK_COMBO(combo)->entry,
153
_("Preferred resolution (dots per inch) of bitmap"), NULL);
156
for (unsigned i = 0; pdr[i] != NULL; i++) {
157
sl = g_list_prepend(sl, (gpointer) pdr[i]);
159
sl = g_list_reverse(sl);
160
gtk_combo_set_popdown_strings(GTK_COMBO(combo), sl);
163
gchar const *val = mod->get_param_string("resolution");
164
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), val);
166
gtk_box_pack_end(GTK_BOX(hb), combo, FALSE, FALSE, 0);
167
GtkWidget *l = gtk_label_new(_("Resolution:"));
168
gtk_box_pack_end(GTK_BOX(hb), l, FALSE, FALSE, 0);
170
/* Print destination frame */
171
f = gtk_frame_new(_("Print destination"));
172
gtk_box_pack_start(GTK_BOX(vbox), f, FALSE, FALSE, 4);
173
vb = gtk_vbox_new(FALSE, 4);
174
gtk_container_add(GTK_CONTAINER(f), vb);
175
gtk_container_set_border_width(GTK_CONTAINER(vb), 4);
177
l = gtk_label_new(_("Printer name (as given by lpstat -p);\n"
178
"leave empty to use the system default printer.\n"
179
"Use '> filename' to print to file.\n"
180
"Use '| prog arg...' to pipe to a program."));
181
gtk_box_pack_start(GTK_BOX(vb), l, FALSE, FALSE, 0);
183
GtkWidget *e = gtk_entry_new();
185
gchar const *val = mod->get_param_string("destination");
186
gtk_entry_set_text(GTK_ENTRY(e), ( val != NULL
190
gtk_box_pack_start(GTK_BOX(vb), e, FALSE, FALSE, 0);
192
// pressing enter in the destination field is the same as clicking Print:
193
gtk_entry_set_activates_default(GTK_ENTRY(e), TRUE);
195
gtk_widget_show_all(vbox);
197
int const response = gtk_dialog_run(GTK_DIALOG(dlg));
199
g_object_unref((GObject *) tt);
201
if (response == GTK_RESPONSE_OK) {
205
_bitmap = gtk_toggle_button_get_active((GtkToggleButton *) rb);
206
sstr = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
207
_dpi = (unsigned int) MAX((int)(atof(sstr)), 1);
208
/* Arrgh, have to do something */
209
fn = gtk_entry_get_text(GTK_ENTRY(e));
210
/* skip leading whitespace, bug #1068483 */
211
while (fn && *fn==' ') { fn++; }
212
/* g_print("Printing to %s\n", fn); */
214
mod->set_param_bool("bitmap", _bitmap);
215
mod->set_param_string("resolution", (gchar *)sstr);
216
mod->set_param_string("destination", (gchar *)fn);
220
gtk_widget_destroy(dlg);
226
PrintPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
228
gboolean epsexport = false;
230
_latin1_encoded_fonts.clear();
231
_newlatin1font_proc_defined = false;
237
gsize bytesWritten = 0;
238
GError *error = NULL;
239
gchar const *utf8_fn = mod->get_param_string("destination");
240
gchar *local_fn = g_filename_from_utf8( utf8_fn,
241
-1, &bytesRead, &bytesWritten, &error);
242
gchar const *fn = local_fn;
244
/* TODO: Replace the below fprintf's with something that does the right thing whether in
245
* gui or batch mode (e.g. --print=blah). Consider throwing an exception: currently one of
246
* the callers (sp_print_document_to_file, "ret = mod->begin(doc)") wrongly ignores the
252
while (isspace(*fn)) fn += 1;
254
osp = popen(fn, "wb");
256
osp = _popen(fn, "wb");
259
fprintf(stderr, "inkscape: popen(%s): %s\n",
260
fn, strerror(errno));
264
} else if (*fn == '>') {
266
epsexport = g_str_has_suffix(fn,".eps");
267
while (isspace(*fn)) fn += 1;
268
Inkscape::IO::dump_fopen_call(fn, "K");
269
osf = Inkscape::IO::fopen_utf8name(fn, "wb+");
271
fprintf(stderr, "inkscape: fopen(%s): %s\n",
272
fn, strerror(errno));
277
/* put cwd stuff in here */
279
? g_strdup_printf("lpr -P %s", fn) /* FIXME: quote fn */
282
osp = popen(qn, "wb");
284
osp = _popen(qn, "wb");
287
fprintf(stderr, "inkscape: popen(%s): %s\n",
288
qn, strerror(errno));
299
/* fixme: this is kinda icky */
300
#if !defined(_WIN32) && !defined(__WIN32__)
301
(void) signal(SIGPIPE, SIG_IGN);
305
pdf_file = new PdfFile(_stream);
306
doc_info = pdf_file->begin_document(1.4);
307
*doc_info << " /Title(" << doc->name << ")\n";
308
*doc_info << " /Author(" << g_get_real_name() << ")\n";
309
// *doc_info << " /Subject(" << "?" << ")\n";
310
// *doc_info << " /Keywords(" << "?" << ")\n";
311
*doc_info << " /Creator(" << "www.inkscape.org" << ")\n";
312
*doc_info << " /Producer(" << "Inkscape " << PACKAGE_STRING << ")\n";
313
//the date should be in ISO/IEC 8824
316
glong time_hh, time_mm, time_ss;
317
#if GLIB_CHECK_VERSION(2,9,0)
318
g_date_set_time_t (&date, time (NULL));
320
g_date_set_time(&date, time (NULL));
322
gchar date_str[100], time_str[100];
323
g_date_strftime(date_str, 99, "%Y%m%d", &date);
324
g_get_current_time(<ime);
325
time_hh=(ltime.tv_sec/3600)%24;
326
time_mm=(ltime.tv_sec/60)%60;
327
time_ss=(ltime.tv_sec)%60;
328
g_snprintf(time_str, 99, "%02ld%02ld%02ld", time_hh, time_mm, time_ss);
329
*doc_info << " /CreationDate(D:" << date_str << time_str << "Z)\n";
330
// *doc_info << " /CreationDate(D:" << date_str << time_str << "OHH'mm')\n";
332
/* flush this to test output stream as early as possible */
333
if (fflush(_stream)) {
334
/*g_print("caught error in sp_module_print_plain_begin\n");*/
335
if (ferror(_stream)) {
336
g_print("Error %d on output stream: %s\n", errno,
339
g_print("Printing failed\n");
340
/* fixme: should use pclose() for pipes */
347
// width and height in pt
348
_width = sp_document_width(doc) * PT_PER_PX;
349
_height = sp_document_height(doc) * PT_PER_PX;
352
bool pageBoundingBox;
353
pageBoundingBox = mod->get_param_bool("pageBoundingBox");
354
// printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE");
355
if (pageBoundingBox) {
358
d.y1 = ceil(_height);
360
SPItem* doc_item = SP_ITEM(sp_document_root(doc));
361
sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
362
// convert from px to pt
369
page_stream = pdf_file->begin_page( (int) d.x0, (int) d.y0,
370
(int) d.x1, (int) d.y1 );
373
*page_stream << PT_PER_PX << " 0 0 "
374
<< -PT_PER_PX << " 0 " << (int) ceil(_height)
376
// from now on we can output px, but they will be treated as pt
383
PrintPDF::finish(Inkscape::Extension::Print *mod)
385
if (!_stream) return 0;
388
double const dots_per_pt = _dpi / PT_PER_IN;
390
double const x0 = 0.0;
391
double const y0 = 0.0;
392
double const x1 = x0 + _width;
393
double const y1 = y0 + _height;
395
/* Bitmap width/height in bitmap dots. */
396
int const width = (int) (_width * dots_per_pt + 0.5);
397
int const height = (int) (_height * dots_per_pt + 0.5);
400
affine.c[0] = width / ((x1 - x0) * PX_PER_PT);
403
affine.c[3] = height / ((y1 - y0) * PX_PER_PT);
404
affine.c[4] = -affine.c[0] * x0;
405
affine.c[5] = -affine.c[3] * y0;
407
nr_arena_item_set_transform(mod->root, &affine);
409
guchar *const px = g_new(guchar, 4 * width * 64);
411
for (int y = 0; y < height; y += 64) {
412
/* Set area of interest. */
417
bbox.y1 = MIN(height, y + 64);
419
/* Update to renderable state. */
421
nr_matrix_set_identity(&gc.transform);
422
nr_arena_item_invoke_update(mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
424
/* This should take guchar* instead of unsigned char*) */
426
nr_pixblock_setup_extern(&pb, NR_PIXBLOCK_MODE_R8G8B8A8N,
427
bbox.x0, bbox.y0, bbox.x1, bbox.y1,
428
(guchar*)px, 4 * width, FALSE, FALSE);
429
memset(px, 0xff, 4 * width * 64);
430
nr_arena_item_invoke_render(mod->root, &bbox, &pb, 0);
431
/* Blitter goes here */
433
imgt.c[0] = (bbox.x1 - bbox.x0) / dots_per_pt;
436
imgt.c[3] = (bbox.y1 - bbox.y0) / dots_per_pt;
438
imgt.c[5] = _height - y / dots_per_pt - (bbox.y1 - bbox.y0) / dots_per_pt;
440
print_image(_stream, px, bbox.x1 - bbox.x0, bbox.y1 - bbox.y0, 4 * width, &imgt);
446
pdf_file->end_page(page_stream);
447
pdf_file->end_document(doc_info);
451
/* Flush stream to be sure. */
452
(void) fflush(_stream);
454
/* fixme: should really use pclose for popen'd streams */
457
_latin1_encoded_fonts.clear();
463
PrintPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity)
465
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
466
if (_bitmap) return 0;
468
*page_stream << "q\n";
469
*page_stream << transform->c[0] << " "
470
<< transform->c[1] << " "
471
<< transform->c[2] << " "
472
<< transform->c[3] << " "
473
<< transform->c[4] << " "
474
<< transform->c[5] << " cm\n";
480
PrintPDF::release(Inkscape::Extension::Print *mod)
482
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
483
if (_bitmap) return 0;
485
*page_stream << "Q\n";
491
PrintPDF::comment(Inkscape::Extension::Print *mod, char const *comment)
493
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
494
if (_bitmap) return 0;
496
*page_stream << "% " << comment;
502
PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style, NRRect const *pbox)
504
g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR
505
|| ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
506
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) );
508
if (style->fill.type == SP_PAINT_TYPE_COLOR) {
511
if (style->opacity.set)
512
alpha *= SP_SCALE24_TO_FLOAT(style->opacity.value);
514
if (style->fill_opacity.set)
515
alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value);
518
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);
519
*pdf_alpha << "<< /Type /ExtGState\n";
520
*pdf_alpha << " /ca " << alpha << "\n";
521
*pdf_alpha << " /AIS false\n";
522
*pdf_alpha << ">>\n";
524
*page_stream << pdf_alpha->get_name()
527
pdf_file->end_resource(pdf_alpha);
530
g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
531
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
533
if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {
535
SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));
536
sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built
538
NR::Point p1 (lg->x1.computed, lg->y1.computed);
539
NR::Point p2 (lg->x2.computed, lg->y2.computed);
540
if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
541
// convert to userspace
542
NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
548
for (gint i = 0; unsigned(i) < lg->vector.stops.size(); i++) {
549
alpha *= lg->vector.stops[i].opacity;
552
if (alpha != 1.0 || style->opacity.set) {
553
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);
554
*pdf_gstate << "<< /Type /ExtGState\n";
556
if (style->opacity.set) {
557
*pdf_gstate << " /ca " << SP_SCALE24_TO_FLOAT(style->opacity.value) << "\n";
558
*pdf_gstate << " /AIS false\n";
562
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_shading);
563
PdfObject *pdf_smask = pdf_file->begin_resource(pdf_none);
564
PdfObject *pdf_xobj = pdf_file->begin_resource(pdf_none);
567
*pdf_gstate << " /SMask " << pdf_smask->get_id() << " 0 R\n";
570
*pdf_alpha << "<<\n/ShadingType 2\n/ColorSpace /DeviceGray\n";
571
*pdf_alpha << "/Coords [" << p1[NR::X] << " " << p1[NR::Y] << " " << p2[NR::X] << " " << p2[NR::Y] <<"]\n";
572
*pdf_alpha << "/Extend [true true]\n";
573
*pdf_alpha << "/Domain [0 1]\n";
574
*pdf_alpha << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
576
for (gint i = 0; unsigned(i) < lg->vector.stops.size() - 1; i++) {
577
*pdf_alpha << "<<\n/FunctionType 2\n/Domain [0 1]\n";
578
*pdf_alpha << "/C0 [" << lg->vector.stops[i].opacity << "]\n";
579
*pdf_alpha << "/C1 [" << lg->vector.stops[i+1].opacity << "]\n";
580
*pdf_alpha << "/N 1\n>>\n";
582
*pdf_alpha << "]\n/Domain [0 1]\n";
583
*pdf_alpha << "/Bounds [ ";
584
for (gint i=0;unsigned(i)<lg->vector.stops.size()-2;i++) {
585
*pdf_alpha << lg->vector.stops[i+1].offset <<" ";
588
*pdf_alpha << "/Encode [ ";
589
for (gint i=0;unsigned(i)<lg->vector.stops.size()-1;i++) {
590
*pdf_alpha << "0 1 ";
593
*pdf_alpha << ">>\n>>\n";
596
*pdf_smask << "<< /Type /Mask\n";
597
*pdf_smask << " /S /Alpha\n";
598
*pdf_smask << " /BC [0.0]\n";
599
*pdf_smask << " /G " << pdf_xobj->get_id() << " 0 R\n";
600
*pdf_smask << ">>\n";
603
*pdf_xobj << "<< /Type /XObject\n";
604
*pdf_xobj << " /Subtype /Form\n";
605
*pdf_xobj << " /FormType 1\n";
606
*pdf_xobj << " /BBox ["
610
<< pbox->y1 << "]\n";
611
*pdf_xobj << " /Group\n";
612
*pdf_xobj << " << /Type /Group\n";
613
*pdf_xobj << " /S /Transparency\n";
614
*pdf_xobj << " /CS /DeviceGray \n";
615
*pdf_xobj << " >>\n";
617
Inkscape::SVGOStringStream os;
618
os.setf(std::ios::fixed);
621
<< pbox->x0 << " " << pbox->y0 << " m\n"
622
<< pbox->x1 << " " << pbox->y0 << " l\n"
623
<< pbox->x1 << " " << pbox->y1 << " l\n"
624
<< pbox->x0 << " " << pbox->y1 << " l\n"
625
<< pbox->x0 << " " << pbox->y0 << " l\n"
629
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
630
if (g->gradientTransform_set) {
631
os << g->gradientTransform[0] << " "
632
<< g->gradientTransform[1] << " "
633
<< g->gradientTransform[2] << " "
634
<< g->gradientTransform[3] << " "
635
<< g->gradientTransform[4] << " "
636
<< g->gradientTransform[5] << " cm\n";
639
os << pdf_alpha->get_name() << " sh\n";
641
*pdf_xobj << " /Length " << strlen(os.str().c_str()) << "\n";
643
*pdf_xobj << "stream\n";
644
*pdf_xobj << os.str().c_str();
645
*pdf_xobj << "endstream\n";
648
pdf_file->end_resource(pdf_alpha);
649
pdf_file->end_resource(pdf_smask);
650
pdf_file->end_resource(pdf_xobj);
653
*pdf_gstate << ">>\n";
655
*page_stream << pdf_gstate->get_name() << " gs\n";
657
pdf_file->end_resource(pdf_gstate);
659
} else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {
661
SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));
662
sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built
664
NR::Point c (rg->cx.computed, rg->cy.computed);
665
NR::Point f (rg->fx.computed, rg->fy.computed);
666
double r = rg->r.computed;
667
if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
668
// convert to userspace
669
NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
672
r *= bbox2user.expansion();
676
for (gint i = 0; unsigned(i) < rg->vector.stops.size(); i++) {
677
alpha *= rg->vector.stops[i].opacity;
680
if (alpha != 1.0 || style->opacity.set) {
681
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);
682
*pdf_gstate << "<< /Type /ExtGState\n";
684
if (style->opacity.set) {
685
*pdf_gstate << " /ca " << SP_SCALE24_TO_FLOAT(style->opacity.value) << "\n";
686
*pdf_gstate << " /AIS false\n";
690
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_shading);
691
PdfObject *pdf_smask = pdf_file->begin_resource(pdf_none);
692
PdfObject *pdf_xobj = pdf_file->begin_resource(pdf_none);
695
*pdf_gstate << " /SMask " << pdf_smask->get_id() << " 0 R\n";
698
*pdf_alpha << "<<\n/ShadingType 3\n/ColorSpace /DeviceGray\n";
699
*pdf_alpha << "/Coords ["<< f[NR::X] <<" "<< f[NR::Y] <<" 0 "<< c[NR::X] <<" "<< c[NR::Y] <<" "<< r <<"]\n";
700
*pdf_alpha << "/Extend [true true]\n";
701
*pdf_alpha << "/Domain [0 1]\n";
702
*pdf_alpha << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
704
for (gint i = 0; unsigned(i) < rg->vector.stops.size() - 1; i++) {
705
*pdf_alpha << "<<\n/FunctionType 2\n/Domain [0 1]\n";
706
*pdf_alpha << "/C0 [" << rg->vector.stops[i].opacity << "]\n";
707
*pdf_alpha << "/C1 [" << rg->vector.stops[i+1].opacity << "]\n";
708
*pdf_alpha << "/N 1\n>>\n";
710
*pdf_alpha << "]\n/Domain [0 1]\n";
711
*pdf_alpha << "/Bounds [ ";
713
for (gint i=0;unsigned(i)<rg->vector.stops.size()-2;i++) {
714
*pdf_alpha << rg->vector.stops[i+1].offset <<" ";
717
*pdf_alpha << "/Encode [ ";
718
for (gint i=0;unsigned(i)<rg->vector.stops.size()-1;i++) {
719
*pdf_alpha << "0 1 ";
722
*pdf_alpha << ">>\n>>\n";
725
*pdf_smask << "<< /Type /Mask\n";
726
*pdf_smask << " /S /Alpha\n";
727
*pdf_smask << " /BC [0.0]\n";
728
*pdf_smask << " /G " << pdf_xobj->get_id() << " 0 R\n";
729
*pdf_smask << ">>\n";
732
*pdf_xobj << "<< /Type /XObject\n";
733
*pdf_xobj << " /Subtype /Form\n";
734
*pdf_xobj << " /FormType 1\n";
735
*pdf_xobj << " /BBox ["
739
<< pbox->y1 << "]\n";
740
*pdf_xobj << " /Group\n";
741
*pdf_xobj << " << /Type /Group\n";
742
*pdf_xobj << " /S /Transparency\n";
743
*pdf_xobj << " /CS /DeviceGray \n";
744
*pdf_xobj << " >>\n";
746
Inkscape::SVGOStringStream os;
747
os.setf(std::ios::fixed);
750
<< pbox->x0 << " " << pbox->y0 << " m\n"
751
<< pbox->x1 << " " << pbox->y0 << " l\n"
752
<< pbox->x1 << " " << pbox->y1 << " l\n"
753
<< pbox->x0 << " " << pbox->y1 << " l\n"
754
<< pbox->x0 << " " << pbox->y0 << " l\n"
758
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
759
if (g->gradientTransform_set) {
760
os << g->gradientTransform[0] << " "
761
<< g->gradientTransform[1] << " "
762
<< g->gradientTransform[2] << " "
763
<< g->gradientTransform[3] << " "
764
<< g->gradientTransform[4] << " "
765
<< g->gradientTransform[5] << " cm\n";
768
os << pdf_alpha->get_name() << " sh\n";
770
*pdf_xobj << " /Length " << strlen(os.str().c_str()) << "\n";
772
*pdf_xobj << "stream\n";
773
*pdf_xobj << os.str().c_str();
774
*pdf_xobj << "endstream\n";
777
pdf_file->end_resource(pdf_alpha);
778
pdf_file->end_resource(pdf_smask);
779
pdf_file->end_resource(pdf_xobj);
782
*pdf_gstate << ">>\n";
784
*page_stream << pdf_gstate->get_name() << " gs\n";
786
pdf_file->end_resource(pdf_gstate);
793
PrintPDF::print_fill_style(SVGOStringStream &os, SPStyle const *const style, NRRect const *pbox)
795
g_return_if_fail( style->fill.type == SP_PAINT_TYPE_COLOR
796
|| ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
797
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) );
799
if (style->fill.type == SP_PAINT_TYPE_COLOR) {
801
sp_color_get_rgb_floatv(&style->fill.value.color, rgb);
803
*page_stream << rgb[0] << " " << rgb[1] << " " << rgb[2] << " rg\n";
805
g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
806
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
808
if (SP_IS_LINEARGRADIENT (SP_STYLE_FILL_SERVER (style))) {
810
SPLinearGradient *lg=SP_LINEARGRADIENT(SP_STYLE_FILL_SERVER (style));
811
sp_gradient_ensure_vector(SP_GRADIENT(lg)); // when exporting from commandline, vector is not built
813
NR::Point p1 (lg->x1.computed, lg->y1.computed);
814
NR::Point p2 (lg->x2.computed, lg->y2.computed);
815
if (pbox && SP_GRADIENT(lg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
816
// convert to userspace
817
NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
822
PdfObject *pdf_shade = pdf_file->begin_resource(pdf_shading);
824
*pdf_shade << "<<\n/ShadingType 2\n/ColorSpace /DeviceRGB\n";
825
*pdf_shade << "/Coords [" << p1[NR::X] << " " << p1[NR::Y] << " " << p2[NR::X] << " " << p2[NR::Y] <<"]\n";
826
*pdf_shade << "/Extend [true true]\n";
827
*pdf_shade << "/Domain [0 1]\n";
828
*pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
830
for (gint i = 0; unsigned(i) < lg->vector.stops.size() - 1; i++) {
832
sp_color_get_rgb_floatv(&lg->vector.stops[i].color, rgb);
833
*pdf_shade << "<<\n/FunctionType 2\n/Domain [0 1]\n";
834
*pdf_shade << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";
835
sp_color_get_rgb_floatv(&lg->vector.stops[i+1].color, rgb);
836
*pdf_shade << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";
837
*pdf_shade << "/N 1\n>>\n";
839
*pdf_shade << "]\n/Domain [0 1]\n";
840
*pdf_shade << "/Bounds [ ";
841
for (gint i=0;unsigned(i)<lg->vector.stops.size()-2;i++) {
842
*pdf_shade << lg->vector.stops[i+1].offset <<" ";
845
*pdf_shade << "/Encode [ ";
846
for (gint i=0;unsigned(i)<lg->vector.stops.size()-1;i++) {
847
*pdf_shade << "0 1 ";
850
*pdf_shade << ">>\n>>\n";
851
*page_stream << pdf_shade->get_name() << " ";
853
pdf_file->end_resource(pdf_shade);
854
} else if (SP_IS_RADIALGRADIENT (SP_STYLE_FILL_SERVER (style))) {
856
SPRadialGradient *rg=SP_RADIALGRADIENT(SP_STYLE_FILL_SERVER (style));
857
sp_gradient_ensure_vector(SP_GRADIENT(rg)); // when exporting from commandline, vector is not built
859
NR::Point c (rg->cx.computed, rg->cy.computed);
860
NR::Point f (rg->fx.computed, rg->fy.computed);
861
double r = rg->r.computed;
862
if (pbox && SP_GRADIENT(rg)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
863
// convert to userspace
864
NR::Matrix bbox2user(pbox->x1 - pbox->x0, 0, 0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0);
867
r *= bbox2user.expansion();
870
PdfObject *pdf_shade = pdf_file->begin_resource(pdf_shading);
872
*pdf_shade << "<<\n/ShadingType 3\n/ColorSpace /DeviceRGB\n";
873
*pdf_shade << "/Coords ["<< f[NR::X] <<" "<< f[NR::Y] <<" 0 "<< c[NR::X] <<" "<< c[NR::Y] <<" "<< r <<"]\n";
874
*pdf_shade << "/Extend [true true]\n";
875
*pdf_shade << "/Domain [0 1]\n";
876
*pdf_shade << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
878
for (gint i = 0; unsigned(i) < rg->vector.stops.size() - 1; i++) {
880
sp_color_get_rgb_floatv(&rg->vector.stops[i].color, rgb);
881
*pdf_shade << "<<\n/FunctionType 2\n/Domain [0 1]\n";
882
*pdf_shade << "/C0 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";
883
sp_color_get_rgb_floatv(&rg->vector.stops[i+1].color, rgb);
884
*pdf_shade << "/C1 [" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "]\n";
885
*pdf_shade << "/N 1\n>>\n";
887
*pdf_shade << "]\n/Domain [0 1]\n";
888
*pdf_shade << "/Bounds [ ";
890
for (gint i=0;unsigned(i)<rg->vector.stops.size()-2;i++) {
891
*pdf_shade << rg->vector.stops[i+1].offset <<" ";
894
*pdf_shade << "/Encode [ ";
895
for (gint i=0;unsigned(i)<rg->vector.stops.size()-1;i++) {
896
*pdf_shade << "0 1 ";
899
*pdf_shade << ">>\n>>\n";
901
*page_stream << pdf_shade->get_name() << " ";
903
pdf_file->end_resource(pdf_shade);
909
PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style)
913
sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);
914
*page_stream << rgb[0] << " " << rgb[1] << " " << rgb[2] << " RG\n";
918
if (style->opacity.set)
919
alpha *= SP_SCALE24_TO_FLOAT(style->opacity.value);
921
if (style->stroke_opacity.set)
922
alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);
925
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);
926
*pdf_alpha << "<< /Type /ExtGState\n";
927
*pdf_alpha << " /CA " << alpha << "\n";
928
*pdf_alpha << " /AIS false\n";
929
*pdf_alpha << ">>\n";
931
*page_stream << pdf_alpha->get_name() << " gs\n";
933
pdf_file->end_resource(pdf_alpha);
936
// There are rare cases in which for a solid line stroke_dasharray_set is true. To avoid
937
// invalid PS-lines such as "[0.0000000 0.0000000] 0.0000000 setdash", which should be "[] 0 setdash",
938
// we first check if all components of stroke_dash.dash are 0.
939
bool LineSolid = true;
940
if (style->stroke_dash.n_dash &&
941
style->stroke_dash.dash )
944
while (LineSolid && (i < style->stroke_dash.n_dash)) {
945
if (style->stroke_dash.dash[i] > 0.00000001)
951
for (i = 0; i < style->stroke_dash.n_dash; i++) {
955
*page_stream << style->stroke_dash.dash[i];
957
*page_stream << "] " << style->stroke_dash.offset << " d\n";
959
*page_stream << "[] 0 d\n";
962
*page_stream << "[] 0 d\n";
965
*page_stream << style->stroke_width.computed << " w\n";
966
*page_stream << style->stroke_linejoin.computed << " j\n";
967
*page_stream << style->stroke_linecap.computed << " J\n";
969
( style->stroke_miterlimit.value > 1 ?
970
style->stroke_miterlimit.value : 1 ) << " M\n";
975
PrintPDF::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *const style,
976
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
978
Inkscape::SVGOStringStream os;
979
os.setf(std::ios::fixed);
981
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
982
if (_bitmap) return 0;
984
if ( style->fill.type == SP_PAINT_TYPE_COLOR ) {
985
*page_stream << "q\n";
986
print_fill_style(os, style, pbox);
987
print_fill_alpha(os, style, pbox);
988
print_bpath(os, bpath->path);
989
if (style->fill_rule.value == SP_WIND_RULE_EVENODD) {
990
*page_stream << "f*\n";
992
*page_stream << "f\n";
994
*page_stream << "Q\n";
996
else if ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
997
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) )
999
*page_stream << "q\n";
1000
print_bpath(os, bpath->path);
1002
if (style->fill_rule.value == SP_WIND_RULE_EVENODD) {
1003
g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
1004
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
1005
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
1006
*page_stream << "W* n\n";
1007
print_fill_alpha(os, style, pbox);
1008
if (g->gradientTransform_set) {
1009
*page_stream << "q\n";
1010
*page_stream << g->gradientTransform[0] << " "
1011
<< g->gradientTransform[1] << " "
1012
<< g->gradientTransform[2] << " "
1013
<< g->gradientTransform[3] << " "
1014
<< g->gradientTransform[4] << " "
1015
<< g->gradientTransform[5] << " cm\n";
1017
print_fill_style(os, style, pbox);
1018
*page_stream << "sh\n";
1019
if (g->gradientTransform_set) {
1020
*page_stream << "Q\n";
1023
g_assert( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
1024
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) );
1025
SPGradient const *g = SP_GRADIENT(SP_STYLE_FILL_SERVER(style));
1026
*page_stream << "W n\n";
1027
print_fill_alpha(os, style, pbox);
1028
if (g->gradientTransform_set) {
1029
*page_stream << "q\n";
1030
*page_stream << g->gradientTransform[0] << " "
1031
<< g->gradientTransform[1] << " "
1032
<< g->gradientTransform[2] << " "
1033
<< g->gradientTransform[3] << " "
1034
<< g->gradientTransform[4] << " "
1035
<< g->gradientTransform[5] << " cm\n";
1037
print_fill_style(os, style, pbox);
1038
*page_stream << "sh\n";
1039
if (g->gradientTransform_set) {
1040
*page_stream << "Q\n";
1044
*page_stream << "Q\n";
1052
PrintPDF::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,
1053
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
1055
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
1056
if (_bitmap) return 0;
1058
if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
1059
Inkscape::SVGOStringStream os;
1060
os.setf(std::ios::fixed);
1062
*page_stream << "q\n";
1064
print_stroke_style(os, style);
1065
print_bpath(os, bpath->path);
1066
*page_stream << "S\n";
1068
*page_stream << "Q\n";
1075
PrintPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs,
1076
NRMatrix const *transform, SPStyle const *style)
1078
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
1079
if (_bitmap) return 0;
1083
return print_image(_stream, px, w, h, rs, transform);
1085
fprintf(_stream, "gsave\n");
1086
fprintf(_stream, "/rowdata %d string def\n", 3 * w);
1087
fprintf(_stream, "[%g %g %g %g %g %g] concat\n",
1094
fprintf(_stream, "%d %d 8 [%d 0 0 -%d 0 %d]\n", w, h, w, h, h);
1095
fprintf(_stream, "{currentfile rowdata readhexstring pop}\n");
1096
fprintf(_stream, "false 3 colorimage\n");
1098
for (unsigned int r = 0; r < h; r++) {
1100
unsigned int c0, c1, c;
1102
for (c0 = 0; c0 < w; c0 += 24) {
1103
c1 = MIN(w, c0 + 24);
1104
for (c = c0; c < c1; c++) {
1105
static char const xtab[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
1106
fputc(xtab[s[0] >> 4], _stream);
1107
fputc(xtab[s[0] & 0xf], _stream);
1108
fputc(xtab[s[1] >> 4], _stream);
1109
fputc(xtab[s[1] & 0xf], _stream);
1110
fputc(xtab[s[2] >> 4], _stream);
1111
fputc(xtab[s[2] & 0xf], _stream);
1114
fputs("\n", _stream);
1118
fprintf(_stream, "grestore\n");
1125
PrintPDF::PSFontName(SPStyle const *style)
1127
font_instance *tf = (font_factory::Default())->Face(style->text->font_family.value, font_style_to_pos(*style));
1133
tf->PSName(name_buf, sizeof(name_buf));
1137
// this system does not have this font, so just use the name from SVG in the hope that PS interpreter will make sense of it
1138
bool i = (style->font_style.value == SP_CSS_FONT_STYLE_ITALIC);
1139
bool o = (style->font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);
1140
bool b = (style->font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) ||
1141
(style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900);
1143
n = g_strdup_printf("%s%s%s%s",
1144
g_strdelimit(style->text->font_family.value, " ", '-'),
1145
(b || i || o) ? "-" : "",
1147
(i) ? "Italic" : ((o) ? "Oblique" : "") );
1155
PrintPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,
1156
SPStyle const *const style)
1158
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
1159
if (_bitmap) return 0;
1161
Inkscape::SVGOStringStream os;
1162
os.setf(std::ios::fixed);
1167
Inkscape::SVGOStringStream escaped_text;
1168
escaped_text.setf(std::ios::fixed);
1170
escaped_text << std::oct;
1171
for (gchar const *p_text = text ; *p_text ; p_text = g_utf8_next_char(p_text)) {
1172
gunichar const c = g_utf8_get_char(p_text);
1173
if (c == '\\' || c == ')' || c == '(')
1174
escaped_text << '\\' << static_cast<char>(c);
1176
escaped_text << '\\' << c;
1178
escaped_text << static_cast<char>(c);
1184
char const *fn = PSFontName(style);
1185
if (_latin1_encoded_fonts.find(fn) == _latin1_encoded_fonts.end()) {
1186
if (!_newlatin1font_proc_defined) {
1187
// input: newfontname, existingfontname
1188
// output: new font object, also defined to newfontname
1189
os << "/newlatin1font " // name of the proc
1190
"{findfont dup length dict copy " // load the font and create a copy of it
1191
"dup /Encoding ISOLatin1Encoding put " // change the encoding in the copy
1192
"definefont} def\n"; // create the new font and leave it on the stack, define the proc
1193
_newlatin1font_proc_defined = true;
1195
os << "/" << fn << "-ISOLatin1 /" << fn << " newlatin1font\n";
1196
_latin1_encoded_fonts.insert(fn);
1198
os << "/" << fn << "-ISOLatin1 findfont\n";
1199
os << style->font_size.computed << " scalefont\n";
1201
g_free((void *) fn);
1203
if ( style->fill.type == SP_PAINT_TYPE_COLOR
1204
|| ( style->fill.type == SP_PAINT_TYPE_PAINTSERVER
1205
&& SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) ) )
1208
print_fill_style(os, style, NULL);
1209
// FIXME: we don't know the pbox of text, so have to pass NULL. This means gradients with
1210
// bbox units won't work with text. However userspace gradients don't work with text either
1211
// (text is black) for some reason.
1214
os << p[NR::X] << " " << p[NR::Y] << " moveto\n";
1215
os << "(" << escaped_text.str() << ") show\n";
1218
if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
1221
print_stroke_style(os, style);
1225
os << p[NR::X] << " " << p[NR::Y] << " moveto\n";
1226
os << "(" << escaped_text.str() << ") false charpath stroke\n";
1231
fprintf(_stream, "%s", os.str().c_str());
1241
PrintPDF::print_bpath(SVGOStringStream &os, NArtBpath const *bp)
1243
bool closed = false;
1244
while (bp->code != NR_END) {
1248
*page_stream << "h\n";
1251
*page_stream << bp->x3 << " " << bp->y3 << " m\n";
1253
case NR_MOVETO_OPEN:
1255
*page_stream << "h\n";
1258
*page_stream << bp->x3 << " " << bp->y3 << " m\n";
1261
*page_stream << bp->x3 << " " << bp->y3 << " l\n";
1264
*page_stream << bp->x1 << " " << bp->y1 << " "
1265
<< bp->x2 << " " << bp->y2 << " "
1266
<< bp->x3 << " " << bp->y3 << " c\n";
1274
*page_stream << "h\n";
1278
/* The following code is licensed under GNU GPL.
1279
** The packbits, ascii85 and imaging printing code
1280
** is from the gimp's postscript.c.
1284
* \param nin Number of bytes of source data.
1285
* \param src Source data.
1286
* \param nout Number of output bytes.
1287
* \param dst Buffer for output.
1290
PrintPDF::compress_packbits(int nin,
1297
int nrepeat, nliteral;
1299
guchar *start_dst = dst;
1300
guchar *last_literal = NULL;
1303
if (nin <= 0) break;
1308
/* Search repeat bytes */
1309
if ((nin > 1) && (c == src[1])) {
1313
while ((nin > 0) && (c == *src)) {
1317
if (nrepeat == 127) break; /* Maximum repeat */
1320
/* Add two-byte repeat to last literal run ? */
1322
&& (last_literal != NULL) && (((*last_literal)+1)+2 <= 128) )
1330
/* Add repeat run */
1331
*(dst++) = (guchar)((-nrepeat) & 0xff);
1333
last_literal = NULL;
1336
/* Search literal bytes */
1342
if (nin <= 0) break;
1344
if ((nin >= 2) && (src[0] == src[1])) /* A two byte repeat ? */
1350
if (nliteral == 128) break; /* Maximum literal run */
1353
/* Could be added to last literal run ? */
1354
if ((last_literal != NULL) && (((*last_literal)+1)+nliteral <= 128)) {
1355
*last_literal += nliteral;
1358
*(dst++) = (guchar)(nliteral-1);
1360
while (nliteral-- > 0) *(dst++) = *(run_start++);
1362
*nout = dst - start_dst;
1366
PrintPDF::ascii85_init(void)
1369
ascii85_linewidth = 0;
1373
PrintPDF::ascii85_flush(SVGOStringStream &os)
1376
bool const zero_case = (ascii85_buf == 0);
1377
static int const max_linewidth = 75;
1379
for (int i = 4; i >= 0; i--) {
1380
c[i] = (ascii85_buf % 85) + '!';
1383
/* check for special case: "!!!!!" becomes "z", but only if not
1384
* at end of data. */
1385
if (zero_case && (ascii85_len == 4)) {
1386
if (ascii85_linewidth >= max_linewidth) {
1388
ascii85_linewidth = 0;
1391
ascii85_linewidth++;
1393
for (int i = 0; i < ascii85_len+1; i++) {
1394
if ((ascii85_linewidth >= max_linewidth) && (c[i] != '%')) {
1396
ascii85_linewidth = 0;
1399
ascii85_linewidth++;
1408
PrintPDF::ascii85_out(guchar byte, SVGOStringStream &os)
1410
if (ascii85_len == 4)
1414
ascii85_buf |= byte;
1419
PrintPDF::ascii85_nout(int n, guchar *uptr, SVGOStringStream &os)
1422
ascii85_out(*uptr, os);
1428
PrintPDF::ascii85_done(SVGOStringStream &os)
1431
/* zero any unfilled buffer portion, then flush */
1432
ascii85_buf <<= (8 * (4-ascii85_len));
1440
PrintPDF::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs,
1441
NRMatrix const *transform)
1443
Inkscape::SVGOStringStream os;
1444
os.setf(std::ios::fixed);
1449
os << "[" << transform->c[0] << " "
1450
<< transform->c[1] << " "
1451
<< transform->c[2] << " "
1452
<< transform->c[3] << " "
1453
<< transform->c[4] << " "
1454
<< transform->c[5] << "] concat\n";
1455
os << width << " " << height << " 8 ["
1456
<< width << " 0 0 -" << height << " 0 " << height << "]\n";
1459
/* Write read image procedure */
1460
os << "% Strings to hold RGB-samples per scanline\n";
1461
os << "/rstr " << width << " string def\n";
1462
os << "/gstr " << width << " string def\n";
1463
os << "/bstr " << width << " string def\n";
1464
os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop}\n";
1465
os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop}\n";
1466
os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop}\n";
1469
/* Allocate buffer for packbits data. Worst case: Less than 1% increase */
1470
guchar *const packb = (guchar *)g_malloc((width * 105)/100+2);
1471
guchar *const plane = (guchar *)g_malloc(width);
1473
/* ps_begin_data(ofp); */
1474
os << "colorimage\n";
1476
/*#define GET_RGB_TILE(begin) \
1477
* {int scan_lines; \
1478
* scan_lines = (i+tile_height-1 < height) ? tile_height : (height-i); \
1479
* gimp_pixel_rgn_get_rect(&pixel_rgn, begin, 0, i, width, scan_lines); \
1483
for (unsigned i = 0; i < height; i++) {
1484
/* if ((i % tile_height) == 0) GET_RGB_TILE(data); */ /* Get more data */
1485
guchar const *const src = px + i * rs;
1487
/* Iterate over RGB */
1488
for (int rgb = 0; rgb < 3; rgb++) {
1489
guchar const *src_ptr = src + rgb;
1490
guchar *plane_ptr = plane;
1491
for (unsigned j = 0; j < width; j++) {
1492
*(plane_ptr++) = *src_ptr;
1497
compress_packbits(width, plane, &nout, packb);
1500
ascii85_nout(nout, packb, os);
1501
ascii85_out(128, os); /* Write EOD of RunLengthDecode filter */
1505
/* ps_end_data(ofp); */
1508
fprintf(ofp, "showpage\n");
1517
g_message(_("write error occurred"));
1524
fprintf(ofp, "%s", os.str().c_str());
1527
//#undef GET_RGB_TILE
1531
PrintPDF::textToPath(Inkscape::Extension::Print * ext)
1533
return ext->get_param_bool("textToPath");
1536
#include "clear-n_.h"
1539
PrintPDF::init(void)
1542
(void) Inkscape::Extension::build_from_mem(
1543
"<inkscape-extension>\n"
1544
"<name>" N_("PDF Print") "</name>\n"
1545
"<id>" SP_MODULE_KEY_PRINT_PDF "</id>\n"
1546
"<param name=\"bitmap\" type=\"boolean\">FALSE</param>\n"
1547
"<param name=\"resolution\" type=\"string\">72</param>\n"
1548
"<param name=\"destination\" type=\"string\">| lp</param>\n"
1549
"<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"
1550
"<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"
1552
"</inkscape-extension>", new PrintPDF());
1556
} /* namespace Internal */
1557
} /* namespace Extension */
1558
} /* namespace Inkscape */
1560
/* End of GNU GPL code */
1566
c-file-style:"stroustrup"
1567
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1568
indent-tabs-mode:nil
1572
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :