summaryrefslogtreecommitdiffstats
path: root/src/extension
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-07-01 20:57:59 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-07-01 20:57:59 +0000
commit9f4a2c1950d81d583a14244338122b57004397ef (patch)
tree6479b86494a300cca8912d6ff6a54ac321a5f97a /src/extension
parentTypo fixed, thanks Luciano Montanaro (diff)
downloadinkscape-9f4a2c1950d81d583a14244338122b57004397ef.tar.gz
inkscape-9f4a2c1950d81d583a14244338122b57004397ef.zip
patch to fix multiple ps and pdf problems by Ulf Erikson
(bzr r1331)
Diffstat (limited to 'src/extension')
-rw-r--r--src/extension/internal/pdf-out.cpp7
-rw-r--r--src/extension/internal/pdf.cpp80
-rw-r--r--src/extension/internal/pdf.h3
-rw-r--r--src/extension/internal/ps.cpp157
4 files changed, 122 insertions, 125 deletions
diff --git a/src/extension/internal/pdf-out.cpp b/src/extension/internal/pdf-out.cpp
index 370855fe6..5cf859161 100644
--- a/src/extension/internal/pdf-out.cpp
+++ b/src/extension/internal/pdf-out.cpp
@@ -101,17 +101,11 @@ PdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar
if (ext == NULL)
return;
- bool old_textToPath = ext->get_param_bool("textToPath");
- bool new_val = mod->get_param_bool("textToPath");
- ext->set_param_bool("textToPath", new_val);
-
gchar * final_name;
final_name = g_strdup_printf("> %s", uri);
pdf_print_document_to_file(doc, final_name);
g_free(final_name);
- ext->set_param_bool("textToPath", old_textToPath);
-
return;
}
@@ -129,7 +123,6 @@ PdfOutput::init (void)
"<inkscape-extension>\n"
"<name>PDF Output</name>\n"
"<id>org.inkscape.output.pdf</id>\n"
- "<param name=\"textToPath\" gui-text=\"Text to Path\" type=\"boolean\">true</param>\n"
"<output>\n"
"<extension>.pdf</extension>\n"
"<mimetype>application/pdf</mimetype>\n"
diff --git a/src/extension/internal/pdf.cpp b/src/extension/internal/pdf.cpp
index c85be3b56..0951d97f2 100644
--- a/src/extension/internal/pdf.cpp
+++ b/src/extension/internal/pdf.cpp
@@ -74,10 +74,14 @@ PrintPDF::PrintPDF() :
_dpi(72),
_bitmap(false)
{
+ _num_alphas = 10;
+ _pushed_alphas = (float*) malloc(_num_alphas*sizeof(float));
}
PrintPDF::~PrintPDF(void)
{
+ free(_pushed_alphas);
+
/* fixme: should really use pclose for popen'd streams */
if (_stream) fclose(_stream);
@@ -233,6 +237,9 @@ PrintPDF::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
FILE *osf = NULL;
FILE *osp = NULL;
+ _curr_alpha = 0;
+ _pushed_alphas[_curr_alpha] = 1.0;
+
gsize bytesRead = 0;
gsize bytesWritten = 0;
GError *error = NULL;
@@ -473,6 +480,31 @@ PrintPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float
<< transform->c[4] << " "
<< transform->c[5] << " cm\n";
+ if (opacity!=1.0) {
+ float alpha = opacity * _pushed_alphas[_curr_alpha];
+
+ fprintf(stderr, "bind: opacity=%f, pushed=%f, alpha=%f\n",
+ opacity, _pushed_alphas[_curr_alpha], alpha);
+
+ _curr_alpha++;
+ if (_curr_alpha >= _num_alphas) {
+ _num_alphas = _num_alphas*2;
+ _pushed_alphas = (float *) realloc(_pushed_alphas, _num_alphas*sizeof(float));
+ }
+ _pushed_alphas[_curr_alpha] = alpha;
+
+ PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);
+ *pdf_alpha << "<< /Type /ExtGState\n";
+ *pdf_alpha << " /ca " << alpha << "\n";
+ *pdf_alpha << " /AIS false\n";
+ *pdf_alpha << ">>\n";
+
+ *page_stream << pdf_alpha->get_name()
+ << " gs\n";
+
+ pdf_file->end_resource(pdf_alpha);
+ }
+
return 1;
}
@@ -482,6 +514,8 @@ PrintPDF::release(Inkscape::Extension::Print *mod)
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
+ _curr_alpha--;
+
*page_stream << "Q\n";
return 1;
@@ -507,23 +541,25 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style,
if (style->fill.type == SP_PAINT_TYPE_COLOR) {
float alpha = 1.0;
-
- if (style->opacity.set)
- alpha *= SP_SCALE24_TO_FLOAT(style->opacity.value);
-
- if (style->fill_opacity.set)
- alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value);
+ alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value);
if (alpha != 1.0) {
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);
*pdf_alpha << "<< /Type /ExtGState\n";
- *pdf_alpha << " /ca " << alpha << "\n";
+ *pdf_alpha << " /ca " << alpha*_pushed_alphas[_curr_alpha] << "\n";
*pdf_alpha << " /AIS false\n";
*pdf_alpha << ">>\n";
*page_stream << pdf_alpha->get_name()
<< " gs\n";
+
+ fprintf(stderr, "print_fill_alpha: opacity=%f, fill-opacity=%f, pushed_alphas=%f ==> %f\n",
+ SP_SCALE24_TO_FLOAT(style->opacity.value),
+ SP_SCALE24_TO_FLOAT(style->fill_opacity.value),
+ _pushed_alphas[_curr_alpha],
+ alpha*_pushed_alphas[_curr_alpha]);
+
pdf_file->end_resource(pdf_alpha);
}
} else {
@@ -550,12 +586,12 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style,
alpha *= lg->vector.stops[i].opacity;
}
- if (alpha != 1.0 || style->opacity.set) {
+ if (alpha != 1.0) {
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);
*pdf_gstate << "<< /Type /ExtGState\n";
- if (style->opacity.set) {
- *pdf_gstate << " /ca " << SP_SCALE24_TO_FLOAT(style->opacity.value) << "\n";
+ if (_pushed_alphas[_curr_alpha] != 1.0) {
+ *pdf_gstate << " /ca " << _pushed_alphas[_curr_alpha] << "\n";
*pdf_gstate << " /AIS false\n";
}
@@ -679,12 +715,12 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style,
alpha *= rg->vector.stops[i].opacity;
}
- if (alpha != 1.0 || style->opacity.set) {
+ if (alpha != 1.0) {
PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate);
*pdf_gstate << "<< /Type /ExtGState\n";
- if (style->opacity.set) {
- *pdf_gstate << " /ca " << SP_SCALE24_TO_FLOAT(style->opacity.value) << "\n";
+ if (_pushed_alphas[_curr_alpha] != 1.0) {
+ *pdf_gstate << " /ca " << _pushed_alphas[_curr_alpha] << "\n";
*pdf_gstate << " /AIS false\n";
}
@@ -914,17 +950,12 @@ PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style)
*page_stream << rgb[0] << " " << rgb[1] << " " << rgb[2] << " RG\n";
float alpha = 1.0;
-
- if (style->opacity.set)
- alpha *= SP_SCALE24_TO_FLOAT(style->opacity.value);
-
- if (style->stroke_opacity.set)
- alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);
+ alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value);
if (alpha != 1.0) {
PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate);
*pdf_alpha << "<< /Type /ExtGState\n";
- *pdf_alpha << " /CA " << alpha << "\n";
+ *pdf_alpha << " /CA " << alpha*_pushed_alphas[_curr_alpha] << "\n";
*pdf_alpha << " /AIS false\n";
*pdf_alpha << ">>\n";
@@ -937,8 +968,7 @@ PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style)
// invalid PS-lines such as "[0.0000000 0.0000000] 0.0000000 setdash", which should be "[] 0 setdash",
// we first check if all components of stroke_dash.dash are 0.
bool LineSolid = true;
- if (style->stroke_dasharray_set &&
- style->stroke_dash.n_dash &&
+ if (style->stroke_dash.n_dash &&
style->stroke_dash.dash )
{
int i = 0;
@@ -966,9 +996,9 @@ PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style)
*page_stream << style->stroke_width.computed << " w\n";
*page_stream << style->stroke_linejoin.computed << " j\n";
*page_stream << style->stroke_linecap.computed << " J\n";
- if (style->stroke_miterlimit.set) {
- *page_stream << style->stroke_miterlimit.value << " M\n";
- }
+ *page_stream <<
+ ( style->stroke_miterlimit.value > 1 ?
+ style->stroke_miterlimit.value : 1 ) << " M\n";
}
diff --git a/src/extension/internal/pdf.h b/src/extension/internal/pdf.h
index 0273f9835..0ceda7caf 100644
--- a/src/extension/internal/pdf.h
+++ b/src/extension/internal/pdf.h
@@ -35,6 +35,9 @@ class PrintPDF : public Inkscape::Extension::Implementation::Implementation {
PdfFile *pdf_file;
PdfObject *doc_info;
PdfObject *page_stream;
+ float *_pushed_alphas;
+ int _num_alphas;
+ int _curr_alpha;
unsigned short _dpi;
bool _bitmap;
std::set<std::string> _latin1_encoded_fonts;
diff --git a/src/extension/internal/ps.cpp b/src/extension/internal/ps.cpp
index a72b88461..c3289ccd6 100644
--- a/src/extension/internal/ps.cpp
+++ b/src/extension/internal/ps.cpp
@@ -385,6 +385,10 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
<< d.x0 << " "
<< (_height - d.y0) << " "
<< d.x1 << "\n";
+ os << "%%DocumentMedia: plain "
+ << (int) ceil(_height) << " "
+ << (int) ceil(_width) << " "
+ << "0 () ()\n";
} else {
os << "%%Orientation: Portrait\n";
os << "%%BoundingBox: " << (int) d.x0 << " "
@@ -395,6 +399,10 @@ PrintPS::begin(Inkscape::Extension::Print *mod, SPDocument *doc)
<< d.y0 << " "
<< d.x1 << " "
<< d.y1 << "\n";
+ os << "%%DocumentMedia: plain "
+ << (int) ceil(_width) << " "
+ << (int) ceil(_height) << " "
+ << "0 () ()\n";
}
os << "%%EndComments\n";
@@ -656,8 +664,7 @@ PrintPS::print_stroke_style(SVGOStringStream &os, SPStyle const *style)
// invalid PS-lines such as "[0.0000000 0.0000000] 0.0000000 setdash", which should be "[] 0 setdash",
// we first check if all components of stroke_dash.dash are 0.
bool LineSolid = true;
- if (style->stroke_dasharray_set &&
- style->stroke_dash.n_dash &&
+ if (style->stroke_dash.n_dash &&
style->stroke_dash.dash )
{
int i = 0;
@@ -784,44 +791,6 @@ PrintPS::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsi
if (_bitmap) return 0;
return print_image(_stream, px, w, h, rs, transform);
-#if 0
- fprintf(_stream, "gsave\n");
- fprintf(_stream, "/rowdata %d string def\n", 3 * w);
- fprintf(_stream, "[%g %g %g %g %g %g] concat\n",
- transform->c[0],
- transform->c[1],
- transform->c[2],
- transform->c[3],
- transform->c[4],
- transform->c[5]);
- fprintf(_stream, "%d %d 8 [%d 0 0 -%d 0 %d]\n", w, h, w, h, h);
- fprintf(_stream, "{currentfile rowdata readhexstring pop}\n");
- fprintf(_stream, "false 3 colorimage\n");
-
- for (unsigned int r = 0; r < h; r++) {
- guchar *s;
- unsigned int c0, c1, c;
- s = px + r * rs;
- for (c0 = 0; c0 < w; c0 += 24) {
- c1 = MIN(w, c0 + 24);
- for (c = c0; c < c1; c++) {
- static char const xtab[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- fputc(xtab[s[0] >> 4], _stream);
- fputc(xtab[s[0] & 0xf], _stream);
- fputc(xtab[s[1] >> 4], _stream);
- fputc(xtab[s[1] & 0xf], _stream);
- fputc(xtab[s[2] >> 4], _stream);
- fputc(xtab[s[2] & 0xf], _stream);
- s += 4;
- }
- fputs("\n", _stream);
- }
- }
-
- fprintf(_stream, "grestore\n");
-
- return 0;
-#endif
}
char const *
@@ -1142,85 +1111,87 @@ PrintPS::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int hei
Inkscape::SVGOStringStream os;
os << "gsave\n";
+
os << "[" << transform->c[0] << " "
<< transform->c[1] << " "
<< transform->c[2] << " "
<< transform->c[3] << " "
<< transform->c[4] << " "
<< transform->c[5] << "] concat\n";
- os << width << " " << height << " 8 ["
- << width << " 0 0 -" << height << " 0 " << height << "]\n";
-
/* Write read image procedure */
- os << "% Strings to hold RGB-samples per scanline\n";
- os << "/rstr " << width << " string def\n";
- os << "/gstr " << width << " string def\n";
- os << "/bstr " << width << " string def\n";
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop}\n";
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop}\n";
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop}\n";
- os << "true 3\n";
+ os << "<<\n";
+ os << " /ImageType 3\n";
+ os << " /InterleaveType 1\n";
+
+ os << " /MaskDict\n";
+ os << " <<\n";
+ os << " /ImageType 1\n";
+ os << " /Width " << width << "\n";
+ os << " /Height " << height << "\n";
+ os << " /ImageMatrix "
+ << "[" << transform->c[0] << " "
+ << transform->c[1] << " "
+ << transform->c[2] << " "
+ << transform->c[3] << " "
+ << 0 << " "
+ << height << "]\n";
+ os << " /BitsPerComponent 8\n";
+ os << " /Decode [1 0]\n";
+ os << " >>\n";
+
+ os << " /DataDict\n";
+ os << " <<\n";
+ os << " /ImageType 1\n";
+ os << " /Width " << width << "\n";
+ os << " /Height " << height << "\n";
+ os << " /ImageMatrix "
+ << "[" << transform->c[0] << " "
+ << transform->c[1] << " "
+ << transform->c[2] << " "
+ << transform->c[3] << " "
+ << 0 << " "
+ << height << "]\n";
+ os << " /DataSource currentfile /ASCII85Decode filter\n";
+ os << " /BitsPerComponent 8\n";
+ os << " /Decode [0 1 0 1 0 1]\n";
+ os << " >>\n";
+
+ os << ">>\n";
/* Allocate buffer for packbits data. Worst case: Less than 1% increase */
- guchar *const packb = (guchar *)g_malloc((width * 105)/100+2);
- guchar *const plane = (guchar *)g_malloc(width);
+ guchar *const packb = (guchar *)g_malloc((4*width * 105)/100+2);
+ guchar *const plane = (guchar *)g_malloc(4*width);
- /* ps_begin_data(ofp); */
- os << "colorimage\n";
-
-/*#define GET_RGB_TILE(begin) \
- * {int scan_lines; \
- * scan_lines = (i+tile_height-1 < height) ? tile_height : (height-i); \
- * gimp_pixel_rgn_get_rect(&pixel_rgn, begin, 0, i, width, scan_lines); \
- * src = begin; }
- */
+ os << "image\n";
+ ascii85_init();
+
for (unsigned i = 0; i < height; i++) {
- /* if ((i % tile_height) == 0) GET_RGB_TILE(data); */ /* Get more data */
guchar const *const src = px + i * rs;
- /* Iterate over RGB */
- for (int rgb = 0; rgb < 3; rgb++) {
- guchar const *src_ptr = src + rgb;
- guchar *plane_ptr = plane;
- for (unsigned j = 0; j < width; j++) {
- *(plane_ptr++) = *src_ptr;
- src_ptr += 4;
- }
-
- int nout;
- compress_packbits(width, plane, &nout, packb);
-
- ascii85_init();
- ascii85_nout(nout, packb, os);
- ascii85_out(128, os); /* Write EOD of RunLengthDecode filter */
- ascii85_done(os);
+ guchar const *src_ptr = src;
+ guchar *plane_ptr = plane;
+ for (unsigned j = 0; j < width; j++) {
+ *(plane_ptr++) = *(src_ptr+3);
+ *(plane_ptr++) = *(src_ptr+0);
+ *(plane_ptr++) = *(src_ptr+1);
+ *(plane_ptr++) = *(src_ptr+2);
+ src_ptr += 4;
}
+
+ ascii85_nout(4*width, plane, os);
}
- /* ps_end_data(ofp); */
-
-#if 0
- fprintf(ofp, "showpage\n");
- g_free(data);
-#endif
+ ascii85_done(os);
g_free(packb);
g_free(plane);
-#if 0
- if (ferror(ofp)) {
- g_message(_("write error occurred"));
- return (FALSE);
- }
-#endif
-
os << "grestore\n";
fprintf(ofp, "%s", os.str().c_str());
return 0;
-//#undef GET_RGB_TILE
}
bool