ps.cpp revision 840c7e40984a84ece8179242a97caa01b52810d9
#define __SP_PS_C__
/** \file
* PostScript printing.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Basic printing code, EXCEPT image and
* ascii85 filter is in public domain
*
* Image printing and Ascii85 filter:
*
* Copyright (C) 2006 Johan Engelen
* Copyright (C) 1997-98 Peter Kirchgessner
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
* George White <aa056@chebucto.ns.ca>
* Austin Donnelly <austin@gimp.org>
*
* Licensed under GNU GPL
*/
/* Plain Print */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <signal.h>
#include <errno.h>
#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-fns.h>
#include <glib/gstrfuncs.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtkcombo.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtktooltips.h>
#include "display/nr-arena-item.h"
#include "display/canvas-bpath.h"
#include "sp-item.h"
#include "style.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
#include "libnrtype/font-instance.h"
#include "libnrtype/font-style-to-pos.h"
#include <unit-constants.h>
#include "ps.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_XFREE86_H
#include <pango/pangoft2.h>
#include <string>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
/*
using std::atof;
using std::ceil;
using std::fclose;
using std::ferror;
using std::fflush;
using std::fgetc;
using std::fprintf; --> this line will result 'std::libintl_fprintf' has not been declared
using std::fputc;
using std::fseek;
using std::ifstream;
using std::ios;
using std::memset;
using std::strchr;
using std::strcmp;
using std::strerror;
using std::tmpfile;
*/
using namespace std;
namespace Inkscape {
namespace Extension {
namespace Internal {
_dpi(72),
_bitmap(false)
{
//map font types
//TODO: support other font types (cf. embed_font())
}
{
/* fixme: should really use pclose for popen'd streams */
/* restore default signal handling for SIGPIPE */
#endif
return;
}
unsigned int
{
static gchar const *const pdr[] = {"72", "75", "100", "144", "150", "200", "300", "360", "600", "1200", "2400", NULL};
#ifdef TED
#endif
/* Create dialog */
// SP_DT_WIDGET(SP_ACTIVE_DESKTOP)->window,
NULL,
NULL);
/* Print properties frame */
/* Print type */
_("Use PostScript vector operators. The resulting image is usually smaller "
"in file size and can be arbitrarily scaled, but alpha transparency "
"and patterns will be lost."), NULL);
rb = gtk_radio_button_new_with_label(gtk_radio_button_get_group((GtkRadioButton *) rb), _("Print as bitmap"));
_("Print everything as bitmap. The resulting image is usually larger "
"in file size and cannot be arbitrarily scaled without quality loss, "
"but all objects will be rendered exactly as displayed."), NULL);
/* Resolution */
_("Preferred resolution (dots per inch) of bitmap"), NULL);
/* Setup strings */
}
if (1) {
}
/* if the destination isn't already set, we must prompt for it */
if (!destination) {
/* Print destination frame */
f = gtk_frame_new(_("Print destination"));
l = gtk_label_new(_("Printer name (as given by lpstat -p);\n"
"leave empty to use the system default printer.\n"
"Use '> filename' to print to file.\n"
"Use '| prog arg...' to pipe to a program."));
e = gtk_entry_new();
: "" ));
// pressing enter in the destination field is the same as clicking Print:
}
if (response == GTK_RESPONSE_OK) {
char const *sstr;
/* if the destination was prompted for, record the new value */
if (e) {
/* Arrgh, have to do something */
/* skip leading whitespace, bug #1068483 */
/* g_print("Printing to %s\n", fn); */
}
}
return ret;
}
unsigned int
{
_newlatin1font_proc_defined = false;
gsize bytesWritten = 0;
//check whether fonts have to be embedded in the (EPS only) output
/* TODO: Replace the below fprintf's with something that does the right thing whether in
* gui or batch mode (e.g. --print=blah). Consider throwing an exception: currently one of
* the callers (sp_print_document_to_file, "ret = mod->begin(doc)") wrongly ignores the
* return code.
*/
if (*fn == '|') {
fn += 1;
#ifndef WIN32
#else
#endif
if (!osp) {
return 0;
}
} else if (*fn == '>') {
fn += 1;
if (!osf) {
return 0;
}
_begin_stream = osf;
/* if font embedding is requested for EPS export...
* TODO:could be extended to PS export if texttopath=FALSE possible
*/
if(font_embedded && epsexport)
{
/**
* Create temporary file where to print the main "script" part of the EPS document.
* Use an extra stream (_begin_stream) to print the prolog and document setup sections.
* Thus, once all the (main) script part printed, all the fonts used are known and can be embedded
* just after the prolog section, in a Begin(End)Setup section (document setup),
* one Begin(End)Resource (DSC comment) section for each font embedded.
* Then, append the final script part from the temporary file (_stream in this case).
* Reference: Adobe Technical note 5001, "PostScript Document Struturing Conventions Specifications"
* page 19
*/
if(!osf_tmp)
{
g_warning("Could not create a temporary file for font embedding. Font embedding canceled.");
font_embedded = false;
} else {
/* put cwd stuff in here */
: g_strdup("lpr") );
#ifndef WIN32
#else
#endif
if (!osp) {
return 0;
}
}
}
if (_stream) {
/* fixme: this is kinda icky */
#endif
}
? "%%!PS-Adobe-3.0 EPSF-3.0\n"
: "%%!PS-Adobe-3.0\n" ));
/* flush this to test output stream as early as possible */
if (fflush(_begin_stream)) {
/*g_print("caught error in sp_module_print_plain_begin\n");*/
if (ferror(_begin_stream)) {
g_strerror(errno));
}
g_print("Printing failed\n");
/* fixme: should use pclose() for pipes */
return 0;
}
//TODO: do this same test on _stream
// width and height in pt
NRRect d;
bool pageBoundingBox;
bool pageLandscape;
// printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE");
if (pageBoundingBox) {
} else {
// convert from px to pt
}
if (res >= 0) {
// This will become problematic if inkscape gains the
// ability to handle multi paged documents. If this is
// the case the %%Orientation: comments should be
// renamed to %%PageOrientation: and moved to the
// respective pages.
os << "%%Pages: 1\n";
// 2004 Dec 10, BFC:
// The point of the following code is (1) to do the thing that's expected by users
// who have done File>New>A4_landscape or ...letter_landscape (i.e., rotate
// the output), while (2) not messing up users who simply want their output wider
// than it is tall (e.g., small figures for inclusion in LaTeX).
// The original patch by WQ only had the w>h condition.
{
pageLandscape = (
(w > 0. && h > 0.) // empty documents fail this sanity check, have w<0, h<0
&& (w > h) // implies, but does not prove, the user wanted landscape
&& (w > 600) // approximate maximum printable width of an A4
&& (!epsexport) // eps should always be portrait
)
? true : false;
}
if (pageLandscape) {
os << "%%Orientation: Landscape\n";
<< (int) d.x0 << " "
// According to Mike Sweet (the author of CUPS)
// HiResBoundingBox is only appropriate
// for EPS files. This means that we should
// distinguish if we export to ps or eps here.
// FIXME: I couldn't find HiResBoundingBox in the PS
// reference manual, so I guess we should skip
// it.
<< d.x0 << " "
<< d.x1 << "\n";
if (!epsexport) {
os << "%%DocumentMedia: plain "
<< "0 () ()\n";
}
} else {
os << "%%Orientation: Portrait\n";
<< (int) d.y0 << " "
<< d.y0 << " "
<< d.x1 << " "
<< d.y1 << "\n";
if (!epsexport) {
os << "%%DocumentMedia: plain "
<< "0 () ()\n";
}
}
os << "%%EndComments\n";
/* If font embedding requested, begin document setup section where to include font resources */
if(font_embedded) os << "%%BeginSetup\n";/* Resume it later with Begin(End)Resource sections for font embedding. So, for now, we are done with the prolog/setup part. */
/* Main Script part (after document setup) begins */
/* Empty os from all previous printing */
// This will become problematic if we print multi paged documents:
os << "%%Page: 1 1\n";
if (pageLandscape) {
os << "90 rotate\n";
if (_bitmap) {
}
} else {
if (!_bitmap) {
}
}
if (!_bitmap) {
// from now on we can output px, but they will be treated as pt
}
/* As a new PS document is created, _fontlist has to be reinitialized (unref fonts from possible former PS docs) */
_fonts = g_tree_new_full((GCompareDataFunc)strcmp, NULL, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
}
os << "0 0 0 setrgbcolor\n"
<< "[] 0 setdash\n"
<< "1 setlinewidth\n"
<< "0 setlinejoin\n"
<< "0 setlinecap\n";
/* FIXME: This function is declared to return unsigned, whereas fprintf returns a signed int *
* that can be zero if the first fprintf failed (os is empty) or "negative" (i.e. very positive
* in unsigned int interpretation) if the first fprintf failed but this one succeeds, or
* positive if both succeed. */
}
unsigned int
{
if (!_stream) return 0;
if (_bitmap) {
double const x0 = 0.0;
double const y0 = 0.0;
for (int y = 0; y < height; y += 64) {
/* Set area of interest. */
/* Update to renderable state. */
nr_arena_item_invoke_update(mod->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
/* Render */
/* This should take guchar* instead of unsigned char*) */
/* Blitter goes here */
}
}
/* Flush stream to be sure. */
char c;
/* If font embedding... */
{
/* Close the document setup section that had been started (because all the needed resources are supposed to be included now) */
/* If font embedding requested, the following PS script part was printed to a different file from the prolog/setup, so script part (current _stream) needs to be copied to prolog/setup file to get the complete (E)PS document */
{
}
}
/* fixme: should really use pclose for popen'd streams */
return res;
}
unsigned int
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
}
unsigned int
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
}
unsigned int
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
}
void
{
float rgb[3];
} else {
// convert to userspace
}
os << "<<\n/ShadingType 2\n/ColorSpace /DeviceRGB\n";
os << "/Extend [true true]\n";
os << "/Domain [0 1]\n";
os << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
float rgb[3];
os << "<<\n/FunctionType 2\n/Domain [0 1]\n";
os << "/N 1\n>>\n";
}
os << "/Bounds [ ";
}
os << "]\n";
os << "/Encode [ ";
os << "0 1 ";
}
os << "]\n";
os << ">>\n>>\n";
// convert to userspace
c *= bbox2user;
f *= bbox2user;
}
os << "<<\n/ShadingType 3\n/ColorSpace /DeviceRGB\n";
os << "/Coords ["<< f[NR::X] <<" "<< f[NR::Y] <<" 0 "<< c[NR::X] <<" "<< c[NR::Y] <<" "<< r <<"]\n";
os << "/Extend [true true]\n";
os << "/Domain [0 1]\n";
os << "/Function <<\n/FunctionType 3\n/Functions\n[\n";
float rgb[3];
os << "<<\n/FunctionType 2\n/Domain [0 1]\n";
os << "/N 1\n>>\n";
}
os << "/Bounds [ ";
}
os << "]\n";
os << "/Encode [ ";
os << "0 1 ";
}
os << "]\n";
os << ">>\n>>\n";
}
}
}
void
{
float rgb[3];
// There are rare cases in which for a solid line stroke_dasharray_set is true. To avoid
// 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;
{
int i = 0;
LineSolid = false;
i++;
}
if (!LineSolid) {
os << "[";
if (i > 0) {
os << " ";
}
}
} else {
os << "[] 0 setdash\n";
}
} else {
os << "[] 0 setdash\n";
}
}
unsigned int
PrintPS::fill(Inkscape::Extension::Print *mod, NRBPath const *bpath, NR::Matrix const *ctm, SPStyle const *const style,
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
{
os << "gsave\n";
os << "eofill\n";
} else {
os << "eoclip\n";
if (g->gradientTransform_set) {
}
os << "shfill\n";
if (g->gradientTransform_set) {
os << "grestore\n";
}
}
} else {
os << "fill\n";
} else {
os << "clip\n";
if (g->gradientTransform_set) {
}
os << "shfill\n";
if (g->gradientTransform_set) {
os << "grestore\n";
}
}
}
os << "grestore\n";
}
return 0;
}
unsigned int
PrintPS::stroke(Inkscape::Extension::Print *mod, NRBPath const *bpath, NR::Matrix const *ctm, SPStyle const *style,
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
os << "stroke\n";
}
return 0;
}
unsigned int
PrintPS::image(Inkscape::Extension::Print *mod, guchar *px, unsigned int w, unsigned int h, unsigned int rs,
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
}
/* PSFontName is now useless (cf. text() method code) */
char const *
{
char const *n;
char name_buf[256];
// PS does not like spaces in fontnames, replace them with the usual dashes.
if (tf) {
} else {
// 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
(style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900);
n = g_strdup_printf("%s%s%s%s",
(b || i || o) ? "-" : "",
(b) ? "Bold" : "",
(i) ? "Italic" : ((o) ? "Oblique" : "") );
}
return g_strdup(n);
}
//LSB = Least Significant Byte
//converts 4-byte array to "LSB first" to "LSB last"
/**
* (Used by PrintPS::embed_t1 (from libgnomeprint/gnome-font-face.c),
* to get the length of data segment (bytes 3-6 in IBM PC (PostScript) font file format.
* Reference: Adobe technical note 5040, "Supporting Downloadable PostScript
* Language Fonts", page 9)
*/
/**
* \brief For "Type 1" font only, print font data in output stream, to embed font data in PS output.
* \param os Stream of output.
* \param font Font whose data to embed.
* \return FALSE if font embedding canceled (due to error or not supported font type), TRUE otherwise
* TODO: enable font embedding for True Type
*/
//adapted more/less from libgnomeprint/gnome_font_face_ps_embed_t1()
bool
{
//check font type
//get font filename, stream to font file and size
//first detect if font file is in IBM PC format
/**
* if first byte is 0x80, font file is pfb, do the same as a pfb to pfa converter
* Reference: Adobe technical note 5040, "Supporting Downloadable PostScript
* Language Fonts", page 9
* else: include all the ASCII data in the font pfa file
**/
char* buf = new char[7];
unsigned char* buffer = new unsigned char[7];//for the 6 header bytes (data segment length is unknown at this point) and final '\0'
//read the 6 header bytes
//for debug: g_warning("Reading from font file %s...", font_filename);
return false;
}
//If font file is pfb, do the same as pfb to pfa converter
//check byte 1
if (buffer[0] == 0x80) {
unsigned long offset = 0;
while (offset < font_stream_size) {
if (buffer[0] != 0x80) {
//TODO: print some default font data anyway like libgnomeprint/gnome_font_face_ps_embed_empty
return false;
}
switch (buffer[1]) {
case 1:
//get data segment length from bytes 3-6
//(Note: byte 1 is first byte in comments to match Adobe technical note 5040, but index 0 in code)
offset += 6;
//resize the buffer to fit the data segment length
delete [] buf;
//read and print all the data segment length
/**
* Assigning a part from the buffer of length "length" ensures
* that no incorrect extra character will be printed and make the PS output invalid
* That was the case with the code:
* os << buffer;
* (A substring method could have been used as well.)
*/
os << ascii_data;
//read next 6 header bytes
break;
case 2:
offset += 6;
//resize the buffer to fit the data segment length
delete [] buf;
//read and print all the data segment length
for (i = 0; i < length; i++) {
offset += 1;
os << "\n";
}
//read next 6 header bytes
break;
case 3:
/* Finished */
os << "\n";
break;
default:
//TODO: print some default font data anyway like libgnomeprint/gnome_font_face_ps_embed_empty
return false;
}
}
}
//else: font file is pfa, include all directly
else {
//font is not in IBM PC format, all the file content can be directly printed
//resize buffer
delete [] buf;
delete [] buffer;
/**
* Assigning a part from the buffer of length "length" ensures
* that no incorrect extra character will be printed and make the PS output invalid
* That was the case with the code:
* os << buffer;
* (A substring method could have been used as well.)
*/
os << ascii_data;
}
delete [] buf;
char font_psname[256];
if (font_num_glyphs < 256) {
/* 8-bit vector */
os << "{1 index /FID ne {def} {pop pop} ifelse} forall\n";
os << "/Encoding [\n";
guint g;
gchar c[256];
}
}
os << "] def currentdict end\n";
//TODO: manage several font instances for same ps name like in libgnomeprint/gnome_print_ps2_set_font_real()
//gf_pso_sprintf (pso, "(%s) cvn exch definefont pop\n", pso->encodedname);
} else {
/* 16-bit vector */
os << "32 dict begin\n";
/* Common entries */
os << "/FontType 0 def\n";
os << "/FontMatrix [1 0 0 1 0 0] def\n";
os << "/LanguageLevel 2 def\n";
/* Type 0 entries */
os << "/FMapType 2 def\n";
/* Bitch 'o' bitches */
os << "/FDepVector [\n";
for (i = 0; i < nfonts; i++) {
os << "{1 index /FID ne {def} {pop pop} ifelse} forall\n";
os << "/Encoding [\n";
for (j = 0; j < 256; j++) {
gchar c[256];
glyph = 256 * i + j;
if (glyph >= font_num_glyphs)
glyph = 0;
g_warning ("file %s: line %d: Glyph %d has no name in %s", __FILE__, __LINE__, glyph, font_filename);
}
}
os << "] def\n";
os << ") cvn exch definefont\n";
}
os << "] def\n";
os << "/Encoding [\n";
for (i = 0; i < 256; i++) {
}
os << "] def\n";
os << "currentdict end\n";
//TODO: manage several font instances for same ps name like in libgnomeprint/gnome_print_ps2_set_font_real()
//gf_pso_sprintf (pso, "(%s) cvn exch definefont pop\n", pso->encodedname);
}
//font embedding completed
return true;
}
/**
* \brief Print font data in output stream, to embed font data in PS output.
* \param os Stream of output.
* \param font Font whose data to embed.
* \return FALSE if font embedding canceled (due to error or not supported font type), TRUE otherwise
*/
//adapted from libgnomeprint/gnome_font_face_ps_embed()
{
//Hinted at by a comment in libgnomeprint/fcpattern_to_gp_font_entry()
//Determining the font type in the "Pango way"
/**
* Possible values of "font_type": Type 1, TrueType, etc.
* Embedding available only for Type 1 fonts so far.
*/
//TODO: provide support for other font types (TrueType is a priority)
switch(_fontTypesMap[font_type])
{
case FONT_TYPE1:
//TODO: implement TT font embedding
/*case FONT_TRUETYPE:
embed_tt (os, font);
break;*/
default:
//TODO: embed something like in libgnomeprint/gnome_font_face_ps_embed_empty();
return false;
}
}
/**
* \brief Converts UTF-8 string to sequence of glyph numbers for PostScript string (cf. "show" commands.).
* \param os Stream of output.
* \param font Font used for unicode->glyph mapping.
* \param unistring UTF-8 encoded string to convert.
*/
{
//iterate through unicode chars in unistring
//whether font has more than one glyph pages (16-bit encoding)
{
//get unicode char
//get matching glyph index in current font for unicode char
//default glyph index is 0 for undefined font character (glyph unavailable)
//TODO: if glyph unavailable for current font, use a default font among the most Unicode-compliant - e.g. Bitstream Cyberbit - I guess
//if more than one glyph pages for current font (16-bit encoding),
{
//add glyph page before glyph index.
os << "\\";
//convert in octal code before printing
}
//(If one page - 8-bit encoding -, nothing to add.)
//TODO: explain the following line inspired from libgnomeprint/gnome_print_ps2_glyphlist()
//TODO: mark glyph as used for current font, if Inkscape has to embed minimal font data in PS
os << "\\";
//convert in octal code before printing
}
}
unsigned int
{
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
if (_bitmap) return 0;
//check whether fonts have to be embedded in the PS output
//if not, use the former way of Inkscape to print text
//find font
/**
* A font_instance object is necessary for the next steps,
* that's why using PSFontName() method just to get the PS fontname
* is not enough and not appropriate
*/
char name_buf[256];
//check whether font was found
/**
* This check is not strictly reliable
* since Inkscape returns a default font if font not found.
* This is just to be consistent with the method PSFontName().
*/
if (tf) {
//get font PS name
} else {
// this system does not have this font, so cancel font embedding...
//this case seems to never happen since Inkscape uses a default font instead (like BitstreamVeraSans on Windows)
//...and just use the name from SVG in the hope that PS interpreter will make sense of it
(style->font_weight.value >= SP_CSS_FONT_WEIGHT_500 && style->font_weight.value <= SP_CSS_FONT_WEIGHT_900);
(b || i || o) ? "-" : "",
(b) ? "Bold" : "",
(i) ? "Italic" : ((o) ? "Oblique" : "") );
}
/**
* If font embedding is requested, tempt to embed the font the first time it is used, once and for all.
* There is no selection of the glyph descriptions to embed, based on the characters used effectively in the document.
* (TODO?)
* Else, back to the former way of printing.
*/
//if not first time the font is used and if font embedding requested, check whether the font has been embedded (successfully the first time).
if(g_tree_lookup_extended(_fonts, fn, NULL, &is_embedded)) font_embedded = font_embedded && (strcmp((char *)is_embedded, "TRUE") == 0);
else
{
//first time the font is used
if(font_embedded)
{
//embed font in PS output
//adapted from libgnomeprint/gnome_print_ps2_close()
//empty os before resume printing to the script stream
}
//add to the list
}
// Escape chars
//if font embedding, all characters will be converted to glyph indices (cf. PrintPS::print_glyphlist()),
//so no need to escape characters
//else back to the old way, i.e. escape chars: '\',')','(' and UTF-8 ones
if(font_embedded) s = text;
else {
if (c == '\\' || c == ')' || c == '(')
else if (c >= 0x80)
escaped_text << '\\' << c;
else
escaped_text << static_cast<char>(c);
}
}
os << "gsave\n";
// set font
else {
if (!_newlatin1font_proc_defined) {
// input: newfontname, existingfontname
// output: new font object, also defined to newfontname
"{findfont dup length dict copy " // load the font and create a copy of it
"dup /Encoding ISOLatin1Encoding put " // change the encoding in the copy
"definefont} def\n"; // create the new font and leave it on the stack, define the proc
_newlatin1font_proc_defined = true;
}
else
} else
else
}
os << "setfont\n";
//The commented line beneath causes Inkscape to crash under Linux but not under Windows
//g_free((void*) fn);
{
// set fill style
// FIXME: we don't know the pbox of text, so have to pass NULL. This means gradients with
// bbox units won't work with text. However userspace gradients don't work with text either
// (text is black) for some reason.
os << "newpath\n";
os << "(";
os << ") show\n";
}
// set stroke style
// paint stroke
os << "newpath\n";
os << "(";
os << ") false charpath stroke\n";
}
os << "grestore\n";
return 0;
}
/* PostScript helpers */
void
{
os << "newpath\n";
bool closed = false;
case NR_MOVETO:
if (closed) {
os << "closepath\n";
}
closed = true;
break;
case NR_MOVETO_OPEN:
if (closed) {
os << "closepath\n";
}
closed = false;
break;
case NR_LINETO:
break;
case NR_CURVETO:
break;
default:
break;
}
bp += 1;
}
if (closed) {
os << "closepath\n";
}
}
/* The following code is licensed under GNU GPL.
** The packbits, ascii85 and imaging printing code
** is from the gimp's postscript.c.
*/
/**
* \param nin Number of bytes of source data.
* \param src Source data.
* \param nout Number of output bytes.
* \param dst Buffer for output.
*/
void
int *nout,
{
register guchar c;
for (;;) {
if (nin <= 0) break;
c = *run_start;
/* Search repeat bytes */
nrepeat = 1;
nin -= 2;
src += 2;
nrepeat++;
src++;
nin--;
}
/* Add two-byte repeat to last literal run ? */
if ( (nrepeat == 1)
{
*last_literal += 2;
*(dst++) = c;
*(dst++) = c;
continue;
}
/* Add repeat run */
*(dst++) = c;
last_literal = NULL;
continue;
}
/* Search literal bytes */
nliteral = 1;
nin--;
src++;
for (;;) {
if (nin <= 0) break;
break;
nliteral++;
nin--;
src++;
}
/* Could be added to last literal run ? */
*last_literal += nliteral;
} else {
last_literal = dst;
}
}
}
void
PrintPS::ascii85_init(void)
{
ascii85_len = 0;
ascii85_linewidth = 0;
}
void
{
char c[5];
bool const zero_case = (ascii85_buf == 0);
static int const max_linewidth = 75;
for (int i = 4; i >= 0; i--) {
ascii85_buf /= 85;
}
/* check for special case: "!!!!!" becomes "z", but only if not
* at end of data. */
if (ascii85_linewidth >= max_linewidth) {
os << '\n';
ascii85_linewidth = 0;
}
os << 'z';
} else {
for (int i = 0; i < ascii85_len+1; i++) {
os << '\n';
ascii85_linewidth = 0;
}
os << c[i];
}
}
ascii85_len = 0;
ascii85_buf = 0;
}
inline void
{
if (ascii85_len == 4)
ascii85_buf <<= 8;
ascii85_buf |= byte;
ascii85_len++;
}
void
{
while (n-- > 0) {
uptr++;
}
}
void
{
if (ascii85_len) {
/* zero any unfilled buffer portion, then flush */
}
os << "~>\n";
}
unsigned int
PrintPS::print_image(FILE *ofp, guchar *px, unsigned int width, unsigned int height, unsigned int rs,
{
os << "gsave\n";
/* Write read image procedure */
os << "<<\n";
os << " /ImageType 3\n";
os << " /InterleaveType 1\n";
os << " /MaskDict\n";
os << " <<\n";
os << " /ImageType 1\n";
os << " /ImageMatrix "
<< 0 << " "
<< 0 << " "
<< -((long) height) << " "
<< 0 << " "
<< height << "]\n";
os << " /BitsPerComponent 8\n";
os << " /Decode [1 0]\n";
os << " >>\n";
os << " /DataDict\n";
os << " <<\n";
os << " /ImageType 1\n";
os << " /ImageMatrix "
<< 0 << " "
<< 0 << " "
<< -((long )height) << " "
<< 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 */
os << "image\n";
ascii85_init();
for (unsigned i = 0; i < height; i++) {
for (unsigned j = 0; j < width; j++) {
src_ptr += 4;
}
}
os << "grestore\n";
return 0;
}
bool
{
}
/**
* \brief Get "fontEmbedded" param
* \retval TRUE Fonts have to be embedded in the output so that the user might not need to install fonts to have the interpreter read the document correctly
* \retval FALSE No font embedding
*
* Only available for Adobe Type 1 fonts in EPS output till now
*/
bool
{
}
#include "clear-n_.h"
void
{
/* SVG in */
"<param name=\"bitmap\" type=\"boolean\">false</param>\n"
"<param name=\"resolution\" type=\"string\">72</param>\n"
"<param name=\"destination\" type=\"string\">| lp</param>\n"
"<param name=\"pageBoundingBox\" type=\"boolean\">true</param>\n"
"<param name=\"textToPath\" type=\"boolean\">true</param>\n"
"<param name=\"fontEmbedded\" type=\"boolean\">false</param>\n"
"<print/>\n"
"</inkscape-extension>", new PrintPS());
}
} /* namespace Internal */
} /* namespace Extension */
} /* namespace Inkscape */
/* End of GNU GPL code */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :