summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e3cdb32)
raw | patch | inline | side by side (parent: e3cdb32)
author | ulferikson <ulferikson@users.sourceforge.net> | |
Sat, 5 Aug 2006 21:10:49 +0000 (21:10 +0000) | ||
committer | ulferikson <ulferikson@users.sourceforge.net> | |
Sat, 5 Aug 2006 21:10:49 +0000 (21:10 +0000) |
src/extension/internal/pdf.cpp | patch | blob | history |
index dde35c39192046ebcb716264e16c0a0fc4eb2e67..80a5a1304aca2dba9c873dd2a832b604e7542d69 100644 (file)
@@ -1109,48 +1109,8 @@ PrintPDF::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, uns
{\r
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.\r
if (_bitmap) return 0;\r
-\r
- return 0;\r
\r
return print_image(_stream, px, w, h, rs, transform);\r
-#if 0\r
- fprintf(_stream, "gsave\n");\r
- fprintf(_stream, "/rowdata %d string def\n", 3 * w);\r
- fprintf(_stream, "[%g %g %g %g %g %g] concat\n",\r
- transform->c[0],\r
- transform->c[1],\r
- transform->c[2],\r
- transform->c[3],\r
- transform->c[4],\r
- transform->c[5]);\r
- fprintf(_stream, "%d %d 8 [%d 0 0 -%d 0 %d]\n", w, h, w, h, h);\r
- fprintf(_stream, "{currentfile rowdata readhexstring pop}\n");\r
- fprintf(_stream, "false 3 colorimage\n");\r
-\r
- for (unsigned int r = 0; r < h; r++) {\r
- guchar *s;\r
- unsigned int c0, c1, c;\r
- s = px + r * rs;\r
- for (c0 = 0; c0 < w; c0 += 24) {\r
- c1 = MIN(w, c0 + 24);\r
- for (c = c0; c < c1; c++) {\r
- static char const xtab[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};\r
- fputc(xtab[s[0] >> 4], _stream);\r
- fputc(xtab[s[0] & 0xf], _stream);\r
- fputc(xtab[s[1] >> 4], _stream);\r
- fputc(xtab[s[1] & 0xf], _stream);\r
- fputc(xtab[s[2] >> 4], _stream);\r
- fputc(xtab[s[2] & 0xf], _stream);\r
- s += 4;\r
- }\r
- fputs("\n", _stream);\r
- }\r
- }\r
-\r
- fprintf(_stream, "grestore\n");\r
-\r
- return 0;\r
-#endif\r
}\r
\r
char const *\r
@@ -1475,88 +1435,114 @@ PrintPDF::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int he
Inkscape::SVGOStringStream os;\r
os.setf(std::ios::fixed);\r
\r
- return 0;\r
+ PdfObject *pdf_image = pdf_file->begin_resource(pdf_xobject);\r
+ PdfObject *pdf_image_len = pdf_file->begin_resource(pdf_none);\r
\r
- os << "gsave\n";\r
- os << "[" << transform->c[0] << " "\r
+ PdfObject *pdf_smask = pdf_file->begin_resource(pdf_xobject);\r
+ PdfObject *pdf_smask_len = pdf_file->begin_resource(pdf_none);\r
+\r
+\r
+ os << "q\n";\r
+ os << transform->c[0] << " "\r
<< transform->c[1] << " "\r
<< transform->c[2] << " "\r
<< transform->c[3] << " "\r
<< transform->c[4] << " "\r
- << transform->c[5] << "] concat\n";\r
- os << width << " " << height << " 8 ["\r
- << width << " 0 0 -" << height << " 0 " << height << "]\n";\r
-\r
-\r
- /* Write read image procedure */\r
- os << "% Strings to hold RGB-samples per scanline\n";\r
- os << "/rstr " << width << " string def\n";\r
- os << "/gstr " << width << " string def\n";\r
- os << "/bstr " << width << " string def\n";\r
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop}\n";\r
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop}\n";\r
- os << "{currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop}\n";\r
- os << "true 3\n";\r
-\r
- /* Allocate buffer for packbits data. Worst case: Less than 1% increase */\r
- guchar *const packb = (guchar *)g_malloc((width * 105)/100+2);\r
- guchar *const plane = (guchar *)g_malloc(width);\r
-\r
- /* ps_begin_data(ofp); */\r
- os << "colorimage\n";\r
-\r
-/*#define GET_RGB_TILE(begin) \\r
- * {int scan_lines; \\r
- * scan_lines = (i+tile_height-1 < height) ? tile_height : (height-i); \\r
- * gimp_pixel_rgn_get_rect(&pixel_rgn, begin, 0, i, width, scan_lines); \\r
- * src = begin; }\r
- */\r
+ << transform->c[5] << " cm\n";\r
+ os << pdf_image->get_name() << " Do\n";\r
+ os << "Q\n";\r
+ pdf_file->puts(os);\r
+\r
+\r
+ *pdf_image << "<< /Type /XObject\n";\r
+ *pdf_image << " /Subtype /Image\n";\r
+ *pdf_image << " /Width " << width << "\n";\r
+ *pdf_image << " /Height " << height << "\n";\r
+ *pdf_image << " /ColorSpace /DeviceRGB\n";\r
+ *pdf_image << " /BitsPerComponent 8\n";\r
+ *pdf_image << " /Length " << pdf_image_len->get_id() << " 0 R\n";\r
+ *pdf_image << " /Filter /ASCIIHexDecode\n";\r
+ *pdf_image << " /SMask " << pdf_smask->get_id() << " 0 R\n";\r
+ *pdf_image << ">>\n";\r
+\r
+ *pdf_image << "stream\n";\r
+\r
+\r
+ *pdf_smask << "<< /Type /XObject\n";\r
+ *pdf_smask << " /Subtype /Image\n";\r
+ *pdf_smask << " /Width " << width << "\n";\r
+ *pdf_smask << " /Height " << height << "\n";\r
+ *pdf_smask << " /ColorSpace /DeviceGray\n";\r
+ *pdf_smask << " /BitsPerComponent 8\n";\r
+ *pdf_smask << " /Length " << pdf_smask_len->get_id() << " 0 R\n";\r
+ *pdf_smask << " /Filter /ASCIIHexDecode\n";\r
+ *pdf_smask << ">>\n";\r
+\r
+ *pdf_smask << "stream\n";\r
+\r
+\r
+ unsigned long image_len = pdf_image->get_length();\r
+ unsigned long smask_len = pdf_smask->get_length();\r
+\r
+ int image_chars = 0;\r
+ int smask_chars = 0;\r
\r
for (unsigned i = 0; i < height; i++) {\r
- /* if ((i % tile_height) == 0) GET_RGB_TILE(data); */ /* Get more data */\r
guchar const *const src = px + i * rs;\r
\r
- /* Iterate over RGB */\r
- for (int rgb = 0; rgb < 3; rgb++) {\r
- guchar const *src_ptr = src + rgb;\r
- guchar *plane_ptr = plane;\r
- for (unsigned j = 0; j < width; j++) {\r
- *(plane_ptr++) = *src_ptr;\r
- src_ptr += 4;\r
+ for (unsigned j = 0; j < width; j++) {\r
+ char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};\r
+ guchar const *src_ptr = src + 4*j;\r
+\r
+ /* Iterate over RGB */\r
+ for (int rgb = 0; rgb < 3; rgb++) {\r
+ guchar val = *(src_ptr + rgb);\r
+\r
+ *pdf_image << hex[val / 16];\r
+ *pdf_image << hex[val % 16];\r
+\r
+ image_chars += 2;\r
+ if (image_chars >= 78) {\r
+ *pdf_image << "\n";\r
+ image_chars = 0;\r
+ }\r
}\r
\r
- int nout;\r
- compress_packbits(width, plane, &nout, packb);\r
+ guchar alpha = *(src_ptr + 3);\r
\r
- ascii85_init();\r
- ascii85_nout(nout, packb, os);\r
- ascii85_out(128, os); /* Write EOD of RunLengthDecode filter */\r
- ascii85_done(os);\r
+ *pdf_smask << hex[alpha / 16];\r
+ *pdf_smask << hex[alpha % 16];\r
+ \r
+ smask_chars += 2;\r
+ if (smask_chars >= 78) {\r
+ *pdf_smask << "\n";\r
+ smask_chars = 0;\r
+ }\r
}\r
}\r
- /* ps_end_data(ofp); */\r
\r
-#if 0\r
- fprintf(ofp, "showpage\n");\r
- g_free(data);\r
-#endif\r
\r
- g_free(packb);\r
- g_free(plane);\r
+ *pdf_image << ">\n";\r
+ image_len = pdf_image->get_length() - image_len;\r
\r
-#if 0\r
- if (ferror(ofp)) {\r
- g_message(_("write error occurred"));\r
- return (FALSE);\r
- }\r
-#endif\r
+ *pdf_image << "endstream\n";\r
+ pdf_file->end_resource(pdf_image);\r
\r
- os << "grestore\n";\r
+ *pdf_image_len << image_len << "\n";\r
+ pdf_file->end_resource(pdf_image_len);\r
+\r
+\r
+ *pdf_smask << ">\n";\r
+ smask_len = pdf_smask->get_length() - smask_len;\r
+\r
+ *pdf_smask << "endstream\n";\r
+ pdf_file->end_resource(pdf_smask);\r
+\r
+ *pdf_smask_len << smask_len << "\n";\r
+ pdf_file->end_resource(pdf_smask_len);\r
\r
- fprintf(ofp, "%s", os.str().c_str());\r
\r
return 0;\r
-//#undef GET_RGB_TILE\r
}\r
\r
bool\r