~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/extension/internal/latex-pstricks.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <signal.h>
20
20
#include <errno.h>
21
21
 
 
22
 
 
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>
 
30
 
 
31
 
22
32
#include "libnr/n-art-bpath.h"
23
33
#include "sp-item.h"
24
34
 
127
137
    _width = sp_document_width(doc) * PT_PER_PX;
128
138
    _height = sp_document_height(doc) * PT_PER_PX;
129
139
 
130
 
    NRRect d;
131
 
    bool   pageLandscape;
132
 
    // printf("Page Bounding Box: %s\n", pageBoundingBox ? "TRUE" : "FALSE");
133
 
/*    if (pageBoundingBox) {
134
 
       d.x0 = d.y0 = 0;
135
 
        d.x1 = ceil(_width);
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
141
 
        d.x0 *= PT_PER_PX;
142
 
        d.x1 *= PT_PER_PX;
143
 
        d.y0 *= PT_PER_PX;
144
 
        d.y1 *= PT_PER_PX;
145
 
    }
146
 
 
147
 
 
148
140
    if (res >= 0) {
149
141
 
150
142
        os << "%%Creator: " << PACKAGE_STRING << "\n";
151
143
        os << "%%Please note this file requires PSTricks extensions\n";
152
144
 
153
 
        // 2004 Dec 10, BFC:
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.
159
 
        {
160
 
             double w = (d.x1 - d.x0); // width and height of bounding box, in pt
161
 
             double h = (d.y1 - d.y0);
162
 
             pageLandscape = (
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
166
 
             )
167
 
             ? true : false;
168
 
        }
169
 
 
170
 
        if (pageLandscape) {
171
 
            os << "\\rotate{90}\n";
172
 
        }
173
 
 
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
176
147
    
177
148
        os << "\\begin{pspicture}(" << sp_document_width(doc) << "," << sp_document_height(doc) << ")\n";
178
149
    }
179
150
 
 
151
    m_tr_stack.push( NR::scale(1, -1) * NR::translate(0, sp_document_height(doc)));
 
152
 
180
153
    return fprintf(_stream, "%s", os.str().c_str());
181
154
}
182
155
 
197
170
    return 0;
198
171
}
199
172
 
 
173
unsigned int
 
174
PrintLatex::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float opacity)
 
175
{
 
176
    NR::Matrix tr = *transform;
 
177
    
 
178
    if(m_tr_stack.size()){
 
179
        NR::Matrix tr_top = m_tr_stack.top();
 
180
        m_tr_stack.push(tr * tr_top);
 
181
    }else
 
182
        m_tr_stack.push(tr);
 
183
 
 
184
    return 1;
 
185
}
 
186
 
 
187
unsigned int
 
188
PrintLatex::release(Inkscape::Extension::Print *mod)
 
189
{
 
190
    m_tr_stack.pop();
 
191
    return 1;
 
192
}
 
193
 
200
194
unsigned int PrintLatex::comment (Inkscape::Extension::Print * module,
201
195
                                  const char * comment)
202
196
{
212
206
{
213
207
    if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
214
208
 
215
 
    if (style->fill.type == SP_PAINT_TYPE_COLOR) {
 
209
    if (style->fill.isColor()) {
216
210
        Inkscape::SVGOStringStream os;
217
211
        float rgb[3];
218
212
 
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";
223
217
 
224
 
        os << "\\pscustom[fillstyle=solid,fillcolor=curcolor]\n{\n";
 
218
        os << "\\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]\n{\n";
225
219
 
226
220
        print_bpath(os, bpath->path, transform);
227
221
 
239
233
{
240
234
    if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned.
241
235
 
242
 
    if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
 
236
    if (style->stroke.isColor()) {
243
237
        Inkscape::SVGOStringStream os;
244
238
        float rgb[3];
245
 
 
 
239
        NR::Matrix tr_stack = m_tr_stack.top();
 
240
        double const scale = expansion(tr_stack);
246
241
        os.setf(std::ios::fixed);
247
242
 
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";
250
245
 
251
 
        os << "\\pscustom[linewidth=" << style->stroke_width.computed<< ",linecolor=curcolor";
 
246
        os << "\\pscustom[linewidth=" << style->stroke_width.computed*scale<< ",linecolor=curcolor";
252
247
 
253
248
        if (style->stroke_dasharray_set &&
254
249
                style->stroke_dash.n_dash &&
280
275
{
281
276
    unsigned int closed;
282
277
    NR::Matrix tf=*transform;
283
 
 
 
278
    NR::Matrix tf_stack=m_tr_stack.top();
284
279
 
285
280
    os << "\\newpath\n";
286
281
    closed = FALSE;
287
282
    while (bp->code != NR_END) {
288
283
        using NR::X;
289
284
        using NR::Y;
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);
 
285
 
 
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);
 
289
 
 
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
 
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];