19
19
#include <signal.h>
23
#include "libnr/nr-matrix.h"
24
#include "libnr/nr-matrix-ops.h"
25
#include "libnr/nr-matrix-scale-ops.h"
26
#include "libnr/nr-matrix-translate-ops.h"
27
#include "libnr/nr-scale-translate-ops.h"
28
#include "libnr/nr-translate-scale-ops.h"
29
#include <libnr/nr-matrix-fns.h>
22
32
#include "libnr/n-art-bpath.h"
23
33
#include "sp-item.h"
127
137
_width = sp_document_width(doc) * PT_PER_PX;
128
138
_height = sp_document_height(doc) * PT_PER_PX;
132
// printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE");
133
/* if (pageBoundingBox) {
136
d.y1 = ceil(_height);
137
} else */{ // no bounding boxes for now
138
SPItem* doc_item = SP_ITEM(sp_document_root(doc));
139
sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
140
// convert from px to pt
150
142
os << "%%Creator: " << PACKAGE_STRING << "\n";
151
143
os << "%%Please note this file requires PSTricks extensions\n";
154
// The point of the following code is (1) to do the thing that's expected by users
155
// who have done File>New>A4_landscape or ...letter_landscape (i.e., rotate
156
// the output), while (2) not messing up users who simply want their output wider
157
// than it is tall (e.g., small figures for inclusion in LaTeX).
158
// The original patch by WQ only had the w>h condition.
160
double w = (d.x1 - d.x0); // width and height of bounding box, in pt
161
double h = (d.y1 - d.y0);
163
(w > 0. && h > 0.) // empty documents fail this sanity check, have w<0, h<0
164
&& (w > h) // implies, but does not prove, the user wanted landscape
165
&& (w > 600) // approximate maximum printable width of an A4
171
os << "\\rotate{90}\n";
174
145
os << "\\psset{xunit=.5pt,yunit=.5pt,runit=.5pt}\n";
175
146
// from now on we can output px, but they will be treated as pt
177
148
os << "\\begin{pspicture}(" << sp_document_width(doc) << "," << sp_document_height(doc) << ")\n";
151
m_tr_stack.push( NR::scale(1, -1) * NR::translate(0, sp_document_height(doc)));
180
153
return fprintf(_stream, "%s", os.str().c_str());
174
PrintLatex::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity)
176
NR::Matrix tr = *transform;
178
if(m_tr_stack.size()){
179
NR::Matrix tr_top = m_tr_stack.top();
180
m_tr_stack.push(tr * tr_top);
188
PrintLatex::release(Inkscape::Extension::Print *mod)
200
194
unsigned int PrintLatex::comment (Inkscape::Extension::Print * module,
201
195
const char * comment)
213
207
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
215
if (style->fill.type == SP_PAINT_TYPE_COLOR) {
209
if (style->fill.isColor()) {
216
210
Inkscape::SVGOStringStream os;
221
215
sp_color_get_rgb_floatv(&style->fill.value.color, rgb);
222
216
os << "{\n\\newrgbcolor{curcolor}{" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "}\n";
224
os << "\\pscustom[fillstyle=solid,fillcolor=curcolor]\n{\n";
218
os << "\\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]\n{\n";
226
220
print_bpath(os, bpath->path, transform);
240
234
if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
242
if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
236
if (style->stroke.isColor()) {
243
237
Inkscape::SVGOStringStream os;
239
NR::Matrix tr_stack = m_tr_stack.top();
240
double const scale = expansion(tr_stack);
246
241
os.setf(std::ios::fixed);
248
243
sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);
249
244
os << "{\n\\newrgbcolor{curcolor}{" << rgb[0] << " " << rgb[1] << " " << rgb[2] << "}\n";
251
os << "\\pscustom[linewidth=" << style->stroke_width.computed<< ",linecolor=curcolor";
246
os << "\\pscustom[linewidth=" << style->stroke_width.computed*scale<< ",linecolor=curcolor";
253
248
if (style->stroke_dasharray_set &&
254
249
style->stroke_dash.n_dash &&
281
276
unsigned int closed;
282
277
NR::Matrix tf=*transform;
278
NR::Matrix tf_stack=m_tr_stack.top();
285
280
os << "\\newpath\n";
287
282
while (bp->code != NR_END) {
290
NR::Point const p1(bp->c(1) * tf);
291
NR::Point const p2(bp->c(2) * tf);
292
NR::Point const p3(bp->c(3) * tf);
286
// NR::Point const p1(bp->c(1) * tf);
287
// NR::Point const p2(bp->c(2) * tf);
288
// NR::Point const p3(bp->c(3) * tf);
290
NR::Point const p1(bp->c(1) * tf_stack);
291
NR::Point const p2(bp->c(2) * tf_stack);
292
NR::Point const p3(bp->c(3) * tf_stack);
293
294
double const x1 = p1[X], y1 = p1[Y];
294
295
double const x2 = p2[X], y2 = p2[Y];
295
296
double const x3 = p3[X], y3 = p3[Y];