Rev 19095 | Rev 19250 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18228 | fschmid | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | |||
8 | #include <QByteArray> |
||
9 | #include <QCursor> |
||
10 | #include <QDrag> |
||
11 | #include <QFile> |
||
12 | #include <QList> |
||
13 | #include <QMimeData> |
||
14 | #include <QRegExp> |
||
15 | #include <QStack> |
||
18549 | fschmid | 16 | #include <QTextDocument> |
18228 | fschmid | 17 | #include <QDebug> |
18 | |||
19 | #include <cstdlib> |
||
20 | |||
19095 | craig | 21 | #include "importpub.h" |
22 | |||
18228 | fschmid | 23 | #include "color.h" |
24 | #include "commonstrings.h" |
||
18251 | fschmid | 25 | #include "fileloader.h" |
18228 | fschmid | 26 | #include "loadsaveplugin.h" |
27 | #include "pagesize.h" |
||
28 | #include "prefscontext.h" |
||
29 | #include "prefsfile.h" |
||
30 | #include "prefsmanager.h" |
||
31 | #include "prefstable.h" |
||
32 | #include "rawimage.h" |
||
33 | #include "scclocale.h" |
||
34 | #include "sccolorengine.h" |
||
35 | #include "scconfig.h" |
||
36 | #include "scmimedata.h" |
||
37 | #include "scpaths.h" |
||
38 | #include "scpattern.h" |
||
39 | #include "scribus.h" |
||
40 | #include "scribusXml.h" |
||
41 | #include "scribuscore.h" |
||
19095 | craig | 42 | #include "scribusdoc.h" |
43 | #include "scribusview.h" |
||
18228 | fschmid | 44 | #include "sctextstream.h" |
45 | #include "selection.h" |
||
19095 | craig | 46 | #include "ui/customfdialog.h" |
47 | #include "ui/missing.h" |
||
48 | #include "ui/multiprogressdialog.h" |
||
49 | #include "ui/propertiespalette.h" |
||
18228 | fschmid | 50 | #include "undomanager.h" |
51 | #include "util.h" |
||
52 | #include "util_formats.h" |
||
53 | #include "util_icon.h" |
||
54 | #include "util_math.h" |
||
55 | |||
19095 | craig | 56 | |
18228 | fschmid | 57 | extern SCRIBUS_API ScribusQApp * ScQApp; |
58 | |||
19222 | fschmid | 59 | #if HAVE_REVENGE |
60 | |||
61 | struct RawPainterPrivate |
||
18228 | fschmid | 62 | { |
19222 | fschmid | 63 | RawPainterPrivate(); |
64 | }; |
||
65 | |||
66 | RawPainterPrivate::RawPainterPrivate() |
||
67 | { |
||
68 | } |
||
69 | |||
70 | RawPainter::RawPainter(ScribusDoc* Doc, double x, double y, double w, double h, int iflags, QList<PageItem*> *Elem, QStringList *iColors, QStringList *iPatterns, Selection* tSel) : m_pImpl(new RawPainterPrivate()) |
||
71 | { |
||
72 | m_Doc = Doc; |
||
73 | baseX = x; |
||
74 | baseY = y; |
||
75 | docWidth = w; |
||
76 | docHeight = h; |
||
77 | importerFlags = iflags; |
||
78 | Elements = Elem; |
||
79 | importedColors = iColors; |
||
80 | importedPatterns = iPatterns; |
||
81 | tmpSel = tSel; |
||
82 | doProcessing = true; |
||
18228 | fschmid | 83 | CurrColorFill = "Black"; |
84 | CurrFillShade = 100.0; |
||
85 | CurrColorStroke = "Black"; |
||
86 | CurrStrokeShade = 100.0; |
||
87 | CurrStrokeTrans = 0.0; |
||
88 | CurrFillTrans = 0.0; |
||
89 | Coords.resize(0); |
||
90 | Coords.svgInit(); |
||
91 | LineW = 1.0; |
||
92 | lineJoin = Qt::MiterJoin; |
||
93 | lineEnd = Qt::FlatCap; |
||
94 | fillrule = true; |
||
95 | gradientAngle = 0.0; |
||
96 | isGradient = false; |
||
97 | lineSpSet = false; |
||
98 | currentGradient = VGradient(VGradient::linear); |
||
99 | currentGradient.clearStops(); |
||
100 | currentGradient.setRepeatMethod( VGradient::none ); |
||
101 | dashArray.clear(); |
||
102 | firstPage = true; |
||
103 | actPage = 0; |
||
104 | actTextItem = NULL; |
||
19222 | fschmid | 105 | } |
106 | |||
107 | RawPainter::~RawPainter() |
||
108 | { |
||
109 | delete m_pImpl; |
||
110 | } |
||
111 | |||
112 | void RawPainter::startDocument(const librevenge::RVNGPropertyList &propList) |
||
113 | { |
||
114 | } |
||
115 | |||
116 | void RawPainter::endDocument() |
||
117 | { |
||
118 | } |
||
119 | |||
120 | void RawPainter::setDocumentMetaData(const librevenge::RVNGPropertyList &propList) |
||
121 | { |
||
122 | if (!doProcessing) |
||
123 | return; |
||
124 | qDebug() << "setDocumentMetaData"; |
||
125 | } |
||
126 | |||
127 | void RawPainter::defineEmbeddedFont(const librevenge::RVNGPropertyList &propList) |
||
128 | { |
||
129 | if (!doProcessing) |
||
130 | return; |
||
131 | qDebug() << "defineEmbeddedFont"; |
||
132 | } |
||
133 | |||
134 | void RawPainter::startPage(const librevenge::RVNGPropertyList &propList) |
||
135 | { |
||
136 | if (propList["svg:width"]) |
||
137 | docWidth = valueAsPoint(propList["svg:width"]); |
||
138 | if (propList["svg:height"]) |
||
139 | docHeight = valueAsPoint(propList["svg:height"]); |
||
140 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
||
141 | { |
||
142 | if (!firstPage) |
||
143 | { |
||
144 | m_Doc->addPage(actPage); |
||
145 | m_Doc->setActiveLayer(baseLayer); |
||
146 | } |
||
147 | else |
||
148 | baseLayer = m_Doc->activeLayerName(); |
||
149 | m_Doc->setPageSize("Custom"); |
||
150 | m_Doc->currentPage()->setInitialWidth(docWidth); |
||
151 | m_Doc->currentPage()->setInitialHeight(docHeight); |
||
152 | m_Doc->currentPage()->setWidth(docWidth); |
||
153 | m_Doc->currentPage()->setHeight(docHeight); |
||
154 | m_Doc->currentPage()->MPageNam = CommonStrings::trMasterPageNormal; |
||
155 | m_Doc->currentPage()->m_pageSize = "Custom"; |
||
156 | m_Doc->reformPages(true); |
||
157 | baseX = m_Doc->currentPage()->xOffset(); |
||
158 | baseY = m_Doc->currentPage()->yOffset(); |
||
159 | } |
||
160 | firstPage = false; |
||
161 | actPage++; |
||
162 | } |
||
163 | |||
164 | void RawPainter::endPage() |
||
165 | { |
||
166 | if (importerFlags & LoadSavePlugin::lfCreateThumbnail) |
||
167 | doProcessing = false; |
||
168 | } |
||
169 | |||
170 | void RawPainter::startMasterPage(const librevenge::RVNGPropertyList &propList) |
||
171 | { |
||
172 | if (!doProcessing) |
||
173 | return; |
||
174 | qDebug() << "startMasterPage"; |
||
175 | } |
||
176 | |||
177 | void RawPainter::endMasterPage() |
||
178 | { |
||
179 | if (!doProcessing) |
||
180 | return; |
||
181 | qDebug() << "endMasterPage"; |
||
182 | } |
||
183 | |||
184 | void RawPainter::startLayer(const librevenge::RVNGPropertyList &propList) |
||
185 | { |
||
186 | if (!doProcessing) |
||
187 | return; |
||
188 | FPointArray clip; |
||
189 | if (propList["svg:clip-path"]) |
||
190 | { |
||
191 | QString svgString = QString(propList["svg:clip-path"]->getStr().cstr()); |
||
192 | clip.resize(0); |
||
193 | clip.svgInit(); |
||
194 | svgString.replace(",", "."); |
||
195 | clip.parseSVG(svgString); |
||
196 | QTransform m; |
||
197 | m.scale(72.0, 72.0); |
||
198 | clip.map(m); |
||
199 | } |
||
200 | QList<PageItem*> gElements; |
||
201 | groupEntry gr; |
||
202 | gr.clip = clip.copy(); |
||
203 | gr.Items = gElements; |
||
204 | groupStack.push(gr); |
||
205 | } |
||
206 | |||
207 | void RawPainter::endLayer() |
||
208 | { |
||
209 | if (!doProcessing) |
||
210 | return; |
||
211 | if (groupStack.count() != 0) |
||
212 | { |
||
213 | PageItem *ite; |
||
214 | groupEntry gr = groupStack.pop(); |
||
215 | QList<PageItem*> gElements = gr.Items; |
||
216 | tmpSel->clear(); |
||
217 | if (gElements.count() > 0) |
||
218 | { |
||
219 | bool groupClip = true; |
||
220 | for (int dre = 0; dre < gElements.count(); ++dre) |
||
221 | { |
||
222 | tmpSel->addItem(gElements.at(dre), true); |
||
223 | Elements->removeAll(gElements.at(dre)); |
||
224 | if (gElements.at(dre)->hasSoftShadow()) |
||
225 | groupClip = false; |
||
226 | } |
||
227 | ite = m_Doc->groupObjectsSelection(tmpSel); |
||
228 | ite->setGroupClipping(groupClip); |
||
229 | ite->setTextFlowMode(PageItem::TextFlowUsesBoundingBox); |
||
230 | if (!gr.clip.isEmpty()) |
||
231 | { |
||
232 | double oldX = ite->xPos(); |
||
233 | double oldY = ite->yPos(); |
||
234 | double oldW = ite->width(); |
||
235 | double oldH = ite->height(); |
||
236 | double oldgW = ite->groupWidth; |
||
237 | double oldgH = ite->groupHeight; |
||
238 | ite->PoLine = gr.clip.copy(); |
||
239 | ite->PoLine.translate(baseX, baseY); |
||
240 | FPoint xy = getMinClipF(&ite->PoLine); |
||
241 | ite->setXYPos(xy.x(), xy.y(), true); |
||
242 | ite->PoLine.translate(-xy.x(), -xy.y()); |
||
243 | FPoint wh = getMaxClipF(&ite->PoLine); |
||
244 | ite->setWidthHeight(wh.x(),wh.y()); |
||
245 | ite->groupWidth = oldgW * (ite->width() / oldW); |
||
246 | ite->groupHeight = oldgH * (ite->height() / oldH); |
||
247 | double dx = (ite->xPos() - oldX) / (ite->width() / ite->groupWidth); |
||
248 | double dy = (ite->yPos() - oldY) / (ite->height() / ite->groupHeight); |
||
249 | for (int em = 0; em < ite->groupItemList.count(); ++em) |
||
250 | { |
||
251 | PageItem* embedded = ite->groupItemList.at(em); |
||
252 | embedded->moveBy(-dx, -dy, true); |
||
253 | m_Doc->setRedrawBounding(embedded); |
||
254 | embedded->OwnPage = m_Doc->OnPage(embedded); |
||
255 | } |
||
256 | ite->ClipEdited = true; |
||
257 | ite->OldB2 = ite->width(); |
||
258 | ite->OldH2 = ite->height(); |
||
259 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
||
260 | ite->updateGradientVectors(); |
||
261 | } |
||
262 | Elements->append(ite); |
||
263 | if (groupStack.count() != 0) |
||
264 | groupStack.top().Items.append(ite); |
||
265 | } |
||
266 | tmpSel->clear(); |
||
267 | } |
||
268 | } |
||
269 | |||
270 | void RawPainter::startEmbeddedGraphics(const librevenge::RVNGPropertyList &propList) |
||
271 | { |
||
272 | if (!doProcessing) |
||
273 | return; |
||
274 | qDebug() << "startEmbeddedGraphics"; |
||
275 | } |
||
276 | |||
277 | void RawPainter::endEmbeddedGraphics() |
||
278 | { |
||
279 | if (!doProcessing) |
||
280 | return; |
||
281 | qDebug() << "endEmbeddedGraphics"; |
||
282 | } |
||
283 | |||
284 | void RawPainter::openGroup(const librevenge::RVNGPropertyList &propList) |
||
285 | { |
||
286 | if (!doProcessing) |
||
287 | return; |
||
288 | qDebug() << "openGroup"; |
||
289 | } |
||
290 | |||
291 | void RawPainter::closeGroup() |
||
292 | { |
||
293 | if (!doProcessing) |
||
294 | return; |
||
295 | qDebug() << "closeGroup"; |
||
296 | } |
||
297 | |||
298 | void RawPainter::setStyle(const librevenge::RVNGPropertyList &propList) |
||
299 | { |
||
300 | if (!doProcessing) |
||
301 | return; |
||
302 | m_style.clear(); |
||
303 | m_style = propList; |
||
304 | isGradient = false; |
||
305 | if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "none") |
||
306 | CurrColorFill = CommonStrings::None; |
||
307 | else if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "solid") |
||
308 | { |
||
309 | if (propList["draw:fill-color"]) |
||
310 | { |
||
311 | CurrColorFill = parseColor(QString(propList["draw:fill-color"]->getStr().cstr())); |
||
312 | if(propList["draw:opacity"]) |
||
313 | CurrFillTrans = 1.0 - qMin(1.0, qMax(fromPercentage(QString(propList["draw:opacity"]->getStr().cstr())), 0.0)); |
||
314 | } |
||
315 | } |
||
316 | if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "gradient") |
||
317 | { |
||
318 | double angle = 0; |
||
319 | if (propList["draw:angle"]) |
||
320 | angle = propList["draw:angle"]->getDouble(); |
||
321 | double opacity = 1.0; |
||
322 | librevenge::RVNGPropertyListVector gradient; |
||
323 | if (propList.child("svg:linearGradient")) |
||
324 | { |
||
325 | currentGradient = VGradient(VGradient::linear); |
||
326 | gradient = *propList.child("svg:linearGradient"); |
||
327 | } |
||
328 | else if (propList.child("svg:radialGradient")) |
||
329 | { |
||
330 | currentGradient = VGradient(VGradient::radial); |
||
331 | gradient = *propList.child("svg:radialGradient"); |
||
332 | } |
||
333 | if (gradient.count() > 1) |
||
334 | { |
||
335 | currentGradient.clearStops(); |
||
336 | currentGradient.setRepeatMethod( VGradient::pad ); |
||
337 | double dr = 1.0 / static_cast<double>(gradient.count()); |
||
338 | for (unsigned c = 0; c < gradient.count(); c++) |
||
339 | { |
||
340 | librevenge::RVNGPropertyList grad = gradient[c]; |
||
341 | if (grad["svg:stop-color"]) |
||
342 | { |
||
343 | QString stopName = parseColor(QString(grad["svg:stop-color"]->getStr().cstr())); |
||
344 | double rampPoint = dr * c; |
||
345 | if(grad["svg:offset"]) |
||
346 | rampPoint = fromPercentage(QString(grad["svg:offset"]->getStr().cstr())); |
||
347 | const ScColor& gradC = m_Doc->PageColors[stopName]; |
||
348 | if(grad["svg:stop-opacity"]) |
||
349 | opacity = qMin(1.0, qMax(fromPercentage(QString(grad["svg:stop-opacity"]->getStr().cstr())), 0.0)); |
||
350 | currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), rampPoint, 0.5, opacity, stopName, 100 ); |
||
351 | if (c == 0) |
||
352 | { |
||
353 | gradColor1Str = stopName; |
||
354 | gradColor1 = ScColorEngine::getRGBColor(gradC, m_Doc); |
||
355 | gradColor1Trans = opacity; |
||
356 | } |
||
357 | else |
||
358 | { |
||
359 | gradColor2Str = stopName; |
||
360 | gradColor2 = ScColorEngine::getRGBColor(gradC, m_Doc); |
||
361 | gradColor2Trans = opacity; |
||
362 | } |
||
363 | } |
||
364 | } |
||
365 | if (currentGradient.Stops() > 1) |
||
366 | isGradient = true; |
||
367 | } |
||
368 | } |
||
369 | if(propList["svg:fill-rule"]) |
||
370 | { |
||
371 | if (QString(propList["svg:fill-rule"]->getStr().cstr()) == "nonzero") |
||
372 | fillrule = false; |
||
373 | else |
||
374 | fillrule = true; |
||
375 | } |
||
376 | if (propList["svg:stroke-width"]) |
||
377 | LineW = valueAsPoint(propList["svg:stroke-width"]); |
||
378 | if (propList["draw:stroke"]) |
||
379 | { |
||
380 | if (propList["draw:stroke"]->getStr() == "none") |
||
381 | CurrColorStroke = CommonStrings::None; |
||
382 | else if ((propList["draw:stroke"]->getStr() == "solid") || (propList["draw:stroke"]->getStr() == "dash")) |
||
383 | { |
||
384 | if (propList["svg:stroke-color"]) |
||
385 | { |
||
386 | CurrColorStroke = parseColor(QString(propList["svg:stroke-color"]->getStr().cstr())); |
||
387 | if(propList["svg:stroke-opacity"]) |
||
388 | CurrStrokeTrans = 1.0 - qMin(1.0, qMax(fromPercentage(QString(propList["svg:stroke-opacity"]->getStr().cstr())), 0.0)); |
||
389 | } |
||
390 | if (propList["draw:stroke"]->getStr() == "dash") |
||
391 | { |
||
392 | dashArray.clear(); |
||
393 | double gap = LineW; |
||
394 | if (propList["draw:distance"]) |
||
395 | gap = valueAsPoint(propList["draw:distance"]); |
||
396 | int dots1 = 0; |
||
397 | if (propList["draw:dots1"]) |
||
398 | dots1 = propList["draw:dots1"]->getInt(); |
||
399 | double dots1len = LineW; |
||
400 | if (propList["draw:dots1-length"]) |
||
401 | dots1len = valueAsPoint(propList["draw:dots1-length"]); |
||
402 | int dots2 = 0; |
||
403 | if (propList["draw:dots2"]) |
||
404 | dots2 = propList["draw:dots2"]->getInt(); |
||
405 | double dots2len = LineW; |
||
406 | if (propList["draw:dots2-length"]) |
||
407 | dots2len = valueAsPoint(propList["draw:dots2-length"]); |
||
408 | for (int i = 0; i < dots1; i++) |
||
409 | { |
||
410 | dashArray << qMax(dots1len, 0.1) << qMax(gap, 0.1); |
||
411 | } |
||
412 | for (int j = 0; j < dots2; j++) |
||
413 | { |
||
414 | dashArray << qMax(dots2len, 0.1) << qMax(gap, 0.1); |
||
415 | } |
||
416 | } |
||
417 | else |
||
418 | dashArray.clear(); |
||
419 | } |
||
420 | } |
||
421 | if (propList["svg:stroke-linecap"]) |
||
422 | { |
||
423 | QString params = QString(propList["svg:stroke-linecap"]->getStr().cstr()); |
||
424 | if( params == "butt" ) |
||
425 | lineEnd = Qt::FlatCap; |
||
426 | else if( params == "round" ) |
||
427 | lineEnd = Qt::RoundCap; |
||
428 | else if( params == "square" ) |
||
429 | lineEnd = Qt::SquareCap; |
||
430 | else |
||
431 | lineEnd = Qt::FlatCap; |
||
432 | } |
||
433 | if (propList["svg:stroke-linejoin"]) |
||
434 | { |
||
435 | QString params = QString(propList["svg:stroke-linejoin"]->getStr().cstr()); |
||
436 | if( params == "miter" ) |
||
437 | lineJoin = Qt::MiterJoin; |
||
438 | else if( params == "round" ) |
||
439 | lineJoin = Qt::RoundJoin; |
||
440 | else if( params == "bevel" ) |
||
441 | lineJoin = Qt::BevelJoin; |
||
442 | else |
||
443 | lineJoin = Qt::MiterJoin; |
||
444 | } |
||
445 | } |
||
446 | |||
447 | void RawPainter::drawRectangle(const librevenge::RVNGPropertyList &propList) |
||
448 | { |
||
449 | if (!doProcessing) |
||
450 | return; |
||
451 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
452 | { |
||
453 | double x = valueAsPoint(propList["svg:x"]); |
||
454 | double y = valueAsPoint(propList["svg:y"]); |
||
455 | double w = valueAsPoint(propList["svg:width"]); |
||
456 | double h = valueAsPoint(propList["svg:height"]); |
||
457 | int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true); |
||
458 | PageItem *ite = m_Doc->Items->at(z); |
||
459 | finishItem(ite); |
||
460 | applyFill(ite); |
||
461 | if (CurrColorFill != CommonStrings::None) |
||
462 | applyShadow(ite); |
||
463 | } |
||
464 | } |
||
465 | |||
466 | void RawPainter::drawEllipse(const librevenge::RVNGPropertyList &propList) |
||
467 | { |
||
468 | if (!doProcessing) |
||
469 | return; |
||
470 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
471 | { |
||
472 | double x = valueAsPoint(propList["svg:x"]); |
||
473 | double y = valueAsPoint(propList["svg:y"]); |
||
474 | double w = valueAsPoint(propList["svg:width"]); |
||
475 | double h = valueAsPoint(propList["svg:height"]); |
||
476 | int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true); |
||
477 | PageItem *ite = m_Doc->Items->at(z); |
||
478 | finishItem(ite); |
||
479 | applyFill(ite); |
||
480 | if (CurrColorFill != CommonStrings::None) |
||
481 | applyShadow(ite); |
||
482 | } |
||
483 | } |
||
484 | |||
485 | void RawPainter::drawPolyline(const librevenge::RVNGPropertyList &propList) |
||
486 | { |
||
487 | if (!doProcessing) |
||
488 | return; |
||
489 | librevenge::RVNGPropertyListVector vertices = *propList.child("svg:points"); |
||
490 | if(vertices.count() < 2) |
||
491 | return; |
||
492 | Coords.resize(0); |
||
493 | Coords.svgInit(); |
||
494 | PageItem *ite; |
||
495 | Coords.svgMoveTo(valueAsPoint(vertices[0]["svg:x"]), valueAsPoint(vertices[0]["svg:y"])); |
||
496 | for(unsigned i = 1; i < vertices.count(); i++) |
||
497 | { |
||
498 | Coords.svgLineTo(valueAsPoint(vertices[i]["svg:x"]), valueAsPoint(vertices[i]["svg:y"])); |
||
499 | } |
||
500 | if (Coords.size() > 0) |
||
501 | { |
||
502 | int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true); |
||
503 | ite = m_Doc->Items->at(z); |
||
504 | ite->PoLine = Coords.copy(); |
||
505 | finishItem(ite); |
||
506 | } |
||
507 | } |
||
508 | |||
509 | void RawPainter::drawPolygon(const librevenge::RVNGPropertyList &propList) |
||
510 | { |
||
511 | if (!doProcessing) |
||
512 | return; |
||
513 | librevenge::RVNGPropertyListVector vertices = *propList.child("svg:points"); |
||
514 | if(vertices.count() < 2) |
||
515 | return; |
||
516 | Coords.resize(0); |
||
517 | Coords.svgInit(); |
||
518 | PageItem *ite; |
||
519 | int z; |
||
520 | Coords.svgMoveTo(valueAsPoint(vertices[0]["svg:x"]), valueAsPoint(vertices[0]["svg:y"])); |
||
521 | for(unsigned i = 1; i < vertices.count(); i++) |
||
522 | { |
||
523 | Coords.svgLineTo(valueAsPoint(vertices[i]["svg:x"]), valueAsPoint(vertices[i]["svg:y"])); |
||
524 | } |
||
525 | Coords.svgClosePath(); |
||
526 | if (Coords.size() > 0) |
||
527 | { |
||
528 | if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap" && m_style["style:repeat"] && m_style["style:repeat"]->getStr() == "stretch") |
||
529 | { |
||
530 | if (m_style["draw:fill-image"] && m_style["librevenge:mime-type"]) |
||
531 | { |
||
532 | QByteArray ba(m_style["draw:fill-image"]->getStr().cstr()); |
||
533 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
534 | QString imgExt = ""; |
||
535 | if (m_style["librevenge:mime-type"]->getStr() == "image/png") |
||
536 | imgExt = "png"; |
||
537 | else if (m_style["librevenge:mime-type"]->getStr() == "image/jpeg") |
||
538 | imgExt = "jpg"; |
||
539 | else if (m_style["librevenge:mime-type"]->getStr() == "image/bmp") |
||
540 | imgExt = "bmp"; |
||
541 | else if (m_style["librevenge:mime-type"]->getStr() == "image/pict") |
||
542 | imgExt = "pict"; |
||
543 | else if (m_style["librevenge:mime-type"]->getStr() == "image/tiff") |
||
544 | imgExt = "tif"; |
||
545 | if (!imgExt.isEmpty()) |
||
546 | { |
||
547 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
548 | ite = m_Doc->Items->at(z); |
||
549 | ite->PoLine = Coords.copy(); |
||
550 | finishItem(ite); |
||
551 | insertImage(ite, imgExt, imageData); |
||
552 | } |
||
553 | else if (m_style["librevenge:mime-type"]->getStr() == "image/wmf") |
||
554 | { |
||
555 | imgExt = "wmf"; |
||
556 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
557 | if (tempFile->open()) |
||
558 | { |
||
559 | tempFile->write(imageData); |
||
560 | QString fileName = getLongPathName(tempFile->fileName()); |
||
561 | tempFile->close(); |
||
562 | FileLoader *fileLoader = new FileLoader(fileName); |
||
563 | int testResult = fileLoader->testFile(); |
||
564 | delete fileLoader; |
||
565 | if (testResult != -1) |
||
566 | { |
||
567 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
568 | if( fmt ) |
||
569 | { |
||
570 | fmt->setupTargets(m_Doc, 0, 0, 0, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts)); |
||
571 | fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted); |
||
572 | if (m_Doc->m_Selection->count() > 0) |
||
573 | { |
||
574 | ite = m_Doc->groupObjectsSelection(); |
||
575 | double rot = 0; |
||
576 | if (m_style["librevenge:rotate"]) |
||
577 | rot = m_style["librevenge:rotate"]->getDouble(); |
||
578 | QPainterPath ba = Coords.toQPainterPath(true); |
||
579 | QRectF baR = ba.boundingRect(); |
||
580 | if (rot != 0) |
||
581 | { |
||
582 | QTransform mm; |
||
583 | mm.translate(baR.x(), baR.y()); |
||
584 | mm.translate(baR.width() / 2.0, baR.height() / 2.0); |
||
585 | mm.rotate(rot); |
||
586 | mm.translate(-baR.width() / 2.0, -baR.height() / 2.0); |
||
587 | mm.translate(-baR.x(), -baR.y()); |
||
588 | ba = mm.map(ba); |
||
589 | baR = ba.boundingRect(); |
||
590 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
591 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
592 | Coords.fromQPainterPath(ba, true); |
||
593 | FPoint tp2(getMinClipF(&Coords)); |
||
594 | Coords.translate(-tp2.x(), -tp2.y()); |
||
595 | ite->PoLine = Coords.copy(); |
||
596 | int rm = m_Doc->RotMode(); |
||
597 | m_Doc->RotMode(2); |
||
598 | m_Doc->RotateItem(-rot, ite); |
||
599 | m_Doc->RotMode(rm); |
||
600 | } |
||
601 | else |
||
602 | { |
||
603 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
604 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
605 | FPoint tp2(getMinClipF(&Coords)); |
||
606 | Coords.translate(-tp2.x(), -tp2.y()); |
||
607 | ite->PoLine = Coords.copy(); |
||
608 | } |
||
609 | finishItem(ite); |
||
610 | if (m_style["draw:red"] && m_style["draw:green"] && m_style["draw:blue"]) |
||
611 | { |
||
612 | int r = qRound(m_style["draw:red"]->getDouble() * 255); |
||
613 | int g = qRound(m_style["draw:green"]->getDouble() * 255); |
||
614 | int b = qRound(m_style["draw:blue"]->getDouble() * 255); |
||
615 | QString colVal = QString("#%1%2%3").arg(r, 2, 16, QLatin1Char('0')).arg(g, 2, 16, QLatin1Char('0')).arg(b, 2, 16, QLatin1Char('0')); |
||
616 | QString efVal = parseColor(colVal); |
||
617 | recolorItem(ite, efVal); |
||
618 | } |
||
619 | } |
||
620 | } |
||
621 | } |
||
622 | } |
||
623 | delete tempFile; |
||
624 | } |
||
625 | } |
||
626 | } |
||
627 | else |
||
628 | { |
||
629 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
630 | ite = m_Doc->Items->at(z); |
||
631 | ite->PoLine = Coords.copy(); |
||
632 | finishItem(ite); |
||
633 | applyFill(ite); |
||
634 | } |
||
635 | applyFlip(ite); |
||
636 | if (CurrColorFill != CommonStrings::None) |
||
637 | applyShadow(ite); |
||
638 | } |
||
639 | } |
||
640 | |||
641 | void RawPainter::drawPath(const librevenge::RVNGPropertyList &propList) |
||
642 | { |
||
643 | if (!doProcessing) |
||
644 | return; |
||
645 | librevenge::RVNGPropertyListVector path = *propList.child("svg:d"); |
||
646 | bool isClosed = false; |
||
647 | QString svgString = ""; |
||
648 | for(unsigned i=0; i < path.count(); i++) |
||
649 | { |
||
650 | librevenge::RVNGPropertyList pList = path[i]; |
||
651 | if (pList["librevenge:path-action"] && pList["librevenge:path-action"]->getStr() == "M") |
||
652 | svgString += QString("M %1 %2 ").arg(valueAsPoint(pList["svg:x"])).arg(valueAsPoint(pList["svg:y"])); |
||
653 | else if (pList["librevenge:path-action"] && pList["librevenge:path-action"]->getStr() == "L") |
||
654 | svgString += QString("L %1 %2 ").arg(valueAsPoint(pList["svg:x"])).arg(valueAsPoint(pList["svg:y"])); |
||
655 | else if (pList["librevenge:path-action"] && pList["librevenge:path-action"]->getStr() == "C") |
||
656 | svgString += QString("C %1 %2 %3 %4 %5 %6 ").arg(valueAsPoint(pList["svg:x1"])).arg(valueAsPoint(pList["svg:y1"])).arg(valueAsPoint(pList["svg:x2"])).arg(valueAsPoint(pList["svg:y2"])).arg(valueAsPoint(pList["svg:x"])).arg(valueAsPoint(pList["svg:y"])); |
||
657 | else if (propList["librevenge:path-action"] && propList["librevenge:path-action"]->getStr() == "Q") |
||
658 | svgString += QString("Q %1 %2 %3 %4 ").arg(valueAsPoint(pList["svg:x1"])).arg(valueAsPoint(pList["svg:y1"])).arg(valueAsPoint(pList["svg:x"])).arg(valueAsPoint(pList["svg:y"])); |
||
659 | else if (pList["librevenge:path-action"] && pList["librevenge:path-action"]->getStr() == "A") |
||
660 | svgString += QString("A %1 %2 %3 %4 %5 %6 %7") .arg(valueAsPoint(pList["svg:rx"])) .arg(valueAsPoint(pList["svg:ry"])).arg(pList["librevenge:rotate"] ? pList["librevenge:rotate"]->getDouble() : 0).arg(pList["librevenge:large-arc"] ? pList["librevenge:large-arc"]->getInt() : 1).arg(pList["librevenge:sweep"] ? pList["librevenge:sweep"]->getInt() : 1).arg(valueAsPoint(pList["svg:x"])).arg(valueAsPoint(pList["svg:y"])); |
||
661 | else if ((i >= path.count()-1 && i > 2) && pList["librevenge:path-action"] && pList["librevenge:path-action"]->getStr() == "Z" ) |
||
662 | { |
||
663 | isClosed = true; |
||
664 | svgString += "Z"; |
||
665 | } |
||
666 | } |
||
667 | Coords.resize(0); |
||
668 | Coords.svgInit(); |
||
669 | Coords.parseSVG(svgString); |
||
670 | PageItem *ite; |
||
671 | int z; |
||
672 | if (isClosed) |
||
673 | { |
||
674 | if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap" && m_style["style:repeat"] && m_style["style:repeat"]->getStr() == "stretch") |
||
675 | { |
||
676 | if (m_style["draw:fill-image"] && m_style["librevenge:mime-type"]) |
||
677 | { |
||
678 | QByteArray ba(m_style["draw:fill-image"]->getStr().cstr()); |
||
679 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
680 | QString imgExt = ""; |
||
681 | if (m_style["librevenge:mime-type"]->getStr() == "image/png") |
||
682 | imgExt = "png"; |
||
683 | else if (m_style["librevenge:mime-type"]->getStr() == "image/jpeg") |
||
684 | imgExt = "jpg"; |
||
685 | else if (m_style["librevenge:mime-type"]->getStr() == "image/bmp") |
||
686 | imgExt = "bmp"; |
||
687 | else if (m_style["librevenge:mime-type"]->getStr() == "image/pict") |
||
688 | imgExt = "pict"; |
||
689 | else if (m_style["librevenge:mime-type"]->getStr() == "image/tiff") |
||
690 | imgExt = "tif"; |
||
691 | if (!imgExt.isEmpty()) |
||
692 | { |
||
693 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
694 | ite = m_Doc->Items->at(z); |
||
695 | ite->PoLine = Coords.copy(); |
||
696 | finishItem(ite); |
||
697 | insertImage(ite, imgExt, imageData); |
||
698 | } |
||
699 | else if (m_style["librevenge:mime-type"]->getStr() == "image/wmf") |
||
700 | { |
||
701 | imgExt = "wmf"; |
||
702 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
703 | if (tempFile->open()) |
||
704 | { |
||
705 | tempFile->write(imageData); |
||
706 | QString fileName = getLongPathName(tempFile->fileName()); |
||
707 | tempFile->close(); |
||
708 | FileLoader *fileLoader = new FileLoader(fileName); |
||
709 | int testResult = fileLoader->testFile(); |
||
710 | delete fileLoader; |
||
711 | if (testResult != -1) |
||
712 | { |
||
713 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
714 | if( fmt ) |
||
715 | { |
||
716 | fmt->setupTargets(m_Doc, 0, 0, 0, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts)); |
||
717 | fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted); |
||
718 | if (m_Doc->m_Selection->count() > 0) |
||
719 | { |
||
720 | ite = m_Doc->groupObjectsSelection(); |
||
721 | double rot = 0; |
||
722 | if (m_style["librevenge:rotate"]) |
||
723 | rot = m_style["librevenge:rotate"]->getDouble(); |
||
724 | QPainterPath ba = Coords.toQPainterPath(true); |
||
725 | QRectF baR = ba.boundingRect(); |
||
726 | if (rot != 0) |
||
727 | { |
||
728 | QTransform mm; |
||
729 | mm.translate(baR.x(), baR.y()); |
||
730 | mm.translate(baR.width() / 2.0, baR.height() / 2.0); |
||
731 | mm.rotate(rot); |
||
732 | mm.translate(-baR.width() / 2.0, -baR.height() / 2.0); |
||
733 | mm.translate(-baR.x(), -baR.y()); |
||
734 | ba = mm.map(ba); |
||
735 | baR = ba.boundingRect(); |
||
736 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
737 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
738 | Coords.fromQPainterPath(ba, true); |
||
739 | FPoint tp2(getMinClipF(&Coords)); |
||
740 | Coords.translate(-tp2.x(), -tp2.y()); |
||
741 | ite->PoLine = Coords.copy(); |
||
742 | int rm = m_Doc->RotMode(); |
||
743 | m_Doc->RotMode(2); |
||
744 | m_Doc->RotateItem(-rot, ite); |
||
745 | m_Doc->RotMode(rm); |
||
746 | } |
||
747 | else |
||
748 | { |
||
749 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
750 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
751 | FPoint tp2(getMinClipF(&Coords)); |
||
752 | Coords.translate(-tp2.x(), -tp2.y()); |
||
753 | ite->PoLine = Coords.copy(); |
||
754 | } |
||
755 | finishItem(ite); |
||
756 | if (m_style["draw:red"] && m_style["draw:green"] && m_style["draw:blue"]) |
||
757 | { |
||
758 | int r = qRound(m_style["draw:red"]->getDouble() * 255); |
||
759 | int g = qRound(m_style["draw:green"]->getDouble() * 255); |
||
760 | int b = qRound(m_style["draw:blue"]->getDouble() * 255); |
||
761 | QString colVal = QString("#%1%2%3").arg(r, 2, 16, QLatin1Char('0')).arg(g, 2, 16, QLatin1Char('0')).arg(b, 2, 16, QLatin1Char('0')); |
||
762 | QString efVal = parseColor(colVal); |
||
763 | recolorItem(ite, efVal); |
||
764 | } |
||
765 | } |
||
766 | } |
||
767 | } |
||
768 | } |
||
769 | delete tempFile; |
||
770 | } |
||
771 | } |
||
772 | } |
||
773 | else |
||
774 | { |
||
775 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
776 | ite = m_Doc->Items->at(z); |
||
777 | ite->PoLine = Coords.copy(); |
||
778 | finishItem(ite); |
||
779 | applyFill(ite); |
||
780 | } |
||
781 | applyFlip(ite); |
||
782 | if (CurrColorFill != CommonStrings::None) |
||
783 | applyShadow(ite); |
||
784 | } |
||
785 | else |
||
786 | { |
||
787 | z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true); |
||
788 | ite = m_Doc->Items->at(z); |
||
789 | ite->PoLine = Coords.copy(); |
||
790 | finishItem(ite); |
||
791 | } |
||
792 | } |
||
793 | |||
794 | void RawPainter::drawGraphicObject(const librevenge::RVNGPropertyList &propList) |
||
795 | { |
||
796 | if (!doProcessing) |
||
797 | return; |
||
798 | if (!propList["librevenge:mime-type"] || propList["librevenge:mime-type"]->getStr().len() <= 0) |
||
799 | return; |
||
800 | if (!propList["office:binary-data"]) |
||
801 | return; |
||
802 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
803 | { |
||
804 | PageItem *ite; |
||
805 | double x = valueAsPoint(propList["svg:x"]); |
||
806 | double y = valueAsPoint(propList["svg:y"]); |
||
807 | double w = valueAsPoint(propList["svg:width"]); |
||
808 | double h = valueAsPoint(propList["svg:height"]); |
||
809 | QByteArray ba(propList["office:binary-data"]->getStr().cstr()); |
||
810 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
811 | QString imgExt = ""; |
||
812 | if (propList["librevenge:mime-type"]->getStr() == "image/png") |
||
813 | imgExt = "png"; |
||
814 | else if (propList["librevenge:mime-type"]->getStr() == "image/jpeg") |
||
815 | imgExt = "jpg"; |
||
816 | else if (propList["librevenge:mime-type"]->getStr() == "image/bmp") |
||
817 | imgExt = "bmp"; |
||
818 | else if (propList["librevenge:mime-type"]->getStr() == "image/pict") |
||
819 | imgExt = "pict"; |
||
820 | else if (propList["librevenge:mime-type"]->getStr() == "image/tiff") |
||
821 | imgExt = "tif"; |
||
822 | if (!imgExt.isEmpty()) |
||
823 | { |
||
824 | int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Rectangle, baseX + x, baseY + y, w, h, 0, CurrColorFill, CurrColorStroke, true); |
||
825 | ite = m_Doc->Items->at(z); |
||
826 | finishItem(ite); |
||
827 | insertImage(ite, imgExt, imageData); |
||
828 | } |
||
829 | else |
||
830 | { |
||
831 | if (propList["librevenge:mime-type"]->getStr() == "image/wmf") |
||
832 | { |
||
833 | imgExt = "wmf"; |
||
834 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
835 | if (tempFile->open()) |
||
836 | { |
||
837 | tempFile->write(imageData); |
||
838 | QString fileName = getLongPathName(tempFile->fileName()); |
||
839 | tempFile->close(); |
||
840 | FileLoader *fileLoader = new FileLoader(fileName); |
||
841 | int testResult = fileLoader->testFile(); |
||
842 | delete fileLoader; |
||
843 | if (testResult != -1) |
||
844 | { |
||
845 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
846 | if( fmt ) |
||
847 | { |
||
848 | fmt->setupTargets(m_Doc, 0, 0, 0, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts)); |
||
849 | fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted); |
||
850 | if (m_Doc->m_Selection->count() > 0) |
||
851 | { |
||
852 | ite = m_Doc->groupObjectsSelection(); |
||
853 | double rot = 0; |
||
854 | if (m_style["librevenge:rotate"]) |
||
855 | rot = m_style["librevenge:rotate"]->getDouble(); |
||
856 | QPainterPath ba; |
||
857 | ba.addRect(QRectF(x, y, w, h)); |
||
858 | QRectF baR = QRectF(x, y, w, h); |
||
859 | if (rot != 0) |
||
860 | { |
||
861 | QTransform mm; |
||
862 | mm.translate(baR.x(), baR.y()); |
||
863 | mm.translate(baR.width() / 2.0, baR.height() / 2.0); |
||
864 | mm.rotate(rot); |
||
865 | mm.translate(-baR.width() / 2.0, -baR.height() / 2.0); |
||
866 | mm.translate(-baR.x(), -baR.y()); |
||
867 | ba = mm.map(ba); |
||
868 | baR = ba.boundingRect(); |
||
869 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
870 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
871 | ite->updateClip(); |
||
872 | int rm = m_Doc->RotMode(); |
||
873 | m_Doc->RotMode(2); |
||
874 | m_Doc->RotateItem(-rot, ite); |
||
875 | m_Doc->RotMode(rm); |
||
876 | } |
||
877 | else |
||
878 | { |
||
879 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
880 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
881 | ite->updateClip(); |
||
882 | } |
||
883 | finishItem(ite); |
||
884 | if (m_style["draw:red"] && m_style["draw:green"] && m_style["draw:blue"]) |
||
885 | { |
||
886 | int r = qRound(m_style["draw:red"]->getDouble() * 255); |
||
887 | int g = qRound(m_style["draw:green"]->getDouble() * 255); |
||
888 | int b = qRound(m_style["draw:blue"]->getDouble() * 255); |
||
889 | QString colVal = QString("#%1%2%3").arg(r, 2, 16, QLatin1Char('0')).arg(g, 2, 16, QLatin1Char('0')).arg(b, 2, 16, QLatin1Char('0')); |
||
890 | QString efVal = parseColor(colVal); |
||
891 | recolorItem(ite, efVal); |
||
892 | } |
||
893 | } |
||
894 | } |
||
895 | } |
||
896 | } |
||
897 | delete tempFile; |
||
898 | } |
||
899 | } |
||
900 | applyFlip(ite); |
||
901 | if (CurrColorFill != CommonStrings::None) |
||
902 | applyShadow(ite); |
||
903 | } |
||
904 | } |
||
905 | |||
906 | void RawPainter::drawConnector(const librevenge::RVNGPropertyList &propList) |
||
907 | { |
||
908 | if (!doProcessing) |
||
909 | return; |
||
910 | qDebug() << "drawConnector"; |
||
911 | } |
||
912 | |||
913 | void RawPainter::startTextObject(const librevenge::RVNGPropertyList &propList) |
||
914 | { |
||
915 | if (!doProcessing) |
||
916 | return; |
||
917 | if (!doProcessing) |
||
918 | return; |
||
919 | actTextItem = NULL; |
||
920 | lineSpSet = false; |
||
921 | lineSpIsPT = false; |
||
922 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
923 | { |
||
924 | double x = valueAsPoint(propList["svg:x"]); |
||
925 | double y = valueAsPoint(propList["svg:y"]); |
||
926 | double w = valueAsPoint(propList["svg:width"]); |
||
927 | double h = valueAsPoint(propList["svg:height"]); |
||
928 | double rot = 0; |
||
929 | if (propList["librevenge:rotate"]) |
||
930 | rot = propList["librevenge:rotate"]->getDouble(); |
||
931 | int z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, baseX + x, baseY + y, w, h, 0, CurrColorFill, CurrColorStroke, true); |
||
932 | PageItem *ite = m_Doc->Items->at(z); |
||
933 | finishItem(ite); |
||
934 | applyShadow(ite); |
||
935 | if (rot != 0) |
||
936 | { |
||
937 | int rm = m_Doc->RotMode(); |
||
938 | m_Doc->RotMode(2); |
||
939 | m_Doc->RotateItem(rot, ite); |
||
940 | m_Doc->RotMode(rm); |
||
941 | } |
||
942 | if (propList["draw-mirror-horizontal"]) |
||
943 | ite->flipImageH(); |
||
944 | if (propList["draw-mirror-vertical"]) |
||
945 | ite->flipImageV(); |
||
946 | if (propList["fo:padding-left"]) |
||
947 | ite->setTextToFrameDistLeft(valueAsPoint(propList["fo:padding-left"])); |
||
948 | if (propList["fo:padding-right"]) |
||
949 | ite->setTextToFrameDistRight(valueAsPoint(propList["fo:padding-right"])); |
||
950 | if (propList["fo:padding-top"]) |
||
951 | ite->setTextToFrameDistTop(valueAsPoint(propList["fo:padding-top"])); |
||
952 | if (propList["fo:padding-bottom"]) |
||
953 | ite->setTextToFrameDistBottom(valueAsPoint(propList["fo:padding-bottom"])); |
||
954 | if (propList["fo:column-count"]) |
||
955 | ite->setColumns(propList["fo:column-count"]->getInt()); |
||
956 | if (propList["fo:column-gap"]) |
||
957 | ite->setColumnGap(valueAsPoint(propList["fo:column-gap"])); |
||
958 | ite->setFirstLineOffset(FLOPFontAscent); |
||
959 | actTextItem = ite; |
||
960 | QString pStyle = CommonStrings::DefaultParagraphStyle; |
||
961 | ParagraphStyle newStyle; |
||
962 | newStyle.setParent(pStyle); |
||
963 | textStyle = newStyle; |
||
964 | } |
||
965 | } |
||
966 | |||
967 | void RawPainter::endTextObject() |
||
968 | { |
||
969 | if (!doProcessing) |
||
970 | return; |
||
971 | if (actTextItem) |
||
972 | actTextItem->itemText.trim(); |
||
973 | actTextItem = NULL; |
||
974 | lineSpSet = false; |
||
975 | lineSpIsPT = false; |
||
976 | } |
||
977 | |||
978 | void RawPainter::startTableObject(const librevenge::RVNGPropertyList &propList) |
||
979 | { |
||
980 | if (!doProcessing) |
||
981 | return; |
||
982 | qDebug() << "startTableObject"; |
||
983 | } |
||
984 | |||
985 | void RawPainter::openTableRow(const librevenge::RVNGPropertyList &propList) |
||
986 | { |
||
987 | if (!doProcessing) |
||
988 | return; |
||
989 | qDebug() << "openTableRow"; |
||
990 | } |
||
991 | |||
992 | void RawPainter::closeTableRow() |
||
993 | { |
||
994 | if (!doProcessing) |
||
995 | return; |
||
996 | qDebug() << "closeTableRow"; |
||
997 | } |
||
998 | |||
999 | void RawPainter::openTableCell(const librevenge::RVNGPropertyList &propList) |
||
1000 | { |
||
1001 | if (!doProcessing) |
||
1002 | return; |
||
1003 | qDebug() << "openTableCell"; |
||
1004 | } |
||
1005 | |||
1006 | void RawPainter::closeTableCell() |
||
1007 | { |
||
1008 | if (!doProcessing) |
||
1009 | return; |
||
1010 | qDebug() << "closeTableCell"; |
||
1011 | } |
||
1012 | |||
1013 | void RawPainter::insertCoveredTableCell(const librevenge::RVNGPropertyList &propList) |
||
1014 | { |
||
1015 | if (!doProcessing) |
||
1016 | return; |
||
1017 | qDebug() << "insertCoveredTableCell"; |
||
1018 | } |
||
1019 | |||
1020 | void RawPainter::endTableObject() |
||
1021 | { |
||
1022 | if (!doProcessing) |
||
1023 | return; |
||
1024 | qDebug() << "endTableObject"; |
||
1025 | } |
||
1026 | |||
1027 | void RawPainter::openOrderedListLevel(const librevenge::RVNGPropertyList &propList) |
||
1028 | { |
||
1029 | if (!doProcessing) |
||
1030 | return; |
||
1031 | qDebug() << "openOrderedListLevel"; |
||
1032 | } |
||
1033 | |||
1034 | void RawPainter::closeOrderedListLevel() |
||
1035 | { |
||
1036 | if (!doProcessing) |
||
1037 | return; |
||
1038 | qDebug() << "closeOrderedListLevel"; |
||
1039 | } |
||
1040 | |||
1041 | void RawPainter::openUnorderedListLevel(const librevenge::RVNGPropertyList &propList) |
||
1042 | { |
||
1043 | if (!doProcessing) |
||
1044 | return; |
||
1045 | qDebug() << "openUnorderedListLevel"; |
||
1046 | } |
||
1047 | |||
1048 | void RawPainter::closeUnorderedListLevel() |
||
1049 | { |
||
1050 | if (!doProcessing) |
||
1051 | return; |
||
1052 | qDebug() << "closeUnorderedListLevel"; |
||
1053 | } |
||
1054 | |||
1055 | void RawPainter::openListElement(const librevenge::RVNGPropertyList &propList) |
||
1056 | { |
||
1057 | if (!doProcessing) |
||
1058 | return; |
||
1059 | qDebug() << "openListElement"; |
||
1060 | } |
||
1061 | |||
1062 | void RawPainter::closeListElement() |
||
1063 | { |
||
1064 | if (!doProcessing) |
||
1065 | return; |
||
1066 | qDebug() << "closeListElement"; |
||
1067 | } |
||
1068 | |||
1069 | void RawPainter::defineParagraphStyle(const librevenge::RVNGPropertyList &propList) |
||
1070 | { |
||
1071 | if (!doProcessing) |
||
1072 | return; |
||
1073 | qDebug() << "defineParagraphStyle"; |
||
1074 | } |
||
1075 | |||
1076 | void RawPainter::openParagraph(const librevenge::RVNGPropertyList &propList) |
||
1077 | { |
||
1078 | if (!doProcessing) |
||
1079 | return; |
||
1080 | QString pStyle = CommonStrings::DefaultParagraphStyle; |
||
1081 | ParagraphStyle newStyle; |
||
1082 | newStyle.setParent(pStyle); |
||
1083 | textStyle = newStyle; |
||
1084 | if (propList["fo:text-align"]) |
||
1085 | { |
||
1086 | QString align = QString(propList["fo:text-align"]->getStr().cstr()); |
||
1087 | if (align == "left") |
||
1088 | textStyle.setAlignment(ParagraphStyle::Leftaligned); |
||
1089 | else if (align == "center") |
||
1090 | textStyle.setAlignment(ParagraphStyle::Centered); |
||
1091 | else if (align == "right") |
||
1092 | textStyle.setAlignment(ParagraphStyle::Rightaligned); |
||
1093 | else if (align == "justify") |
||
1094 | textStyle.setAlignment(ParagraphStyle::Justified); |
||
1095 | } |
||
1096 | if (propList["fo:margin-left"]) |
||
1097 | textStyle.setLeftMargin(valueAsPoint(propList["fo:margin-left"])); |
||
1098 | if (propList["fo:margin-right"]) |
||
1099 | textStyle.setRightMargin(valueAsPoint(propList["fo:margin-right"])); |
||
1100 | if (propList["fo:text-indent"]) |
||
1101 | textStyle.setFirstIndent(valueAsPoint(propList["fo:text-indent"])); |
||
1102 | if (propList["style:drop-cap"]) |
||
1103 | { |
||
1104 | textStyle.setDropCapLines(propList["style:drop-cap"]->getInt()); |
||
1105 | textStyle.setHasDropCap(true); |
||
1106 | } |
||
1107 | if (propList["fo:margin-bottom"]) |
||
1108 | textStyle.setGapAfter(valueAsPoint(propList["fo:margin-bottom"])); |
||
1109 | if (propList["fo:margin-top"]) |
||
1110 | textStyle.setGapBefore(valueAsPoint(propList["fo:margin-top"])); |
||
1111 | // m_maxFontSize = textStyle.charStyle().fontSize() / 10.0; |
||
1112 | m_maxFontSize = 1.0; |
||
1113 | if (propList["fo:line-height"]) |
||
1114 | { |
||
1115 | m_linespace = propList["fo:line-height"]->getDouble(); |
||
1116 | QString lsp = QString(propList["fo:line-height"]->getStr().cstr()); |
||
1117 | lineSpIsPT = lsp.endsWith("pt"); |
||
1118 | lineSpSet = true; |
||
1119 | } |
||
1120 | } |
||
1121 | |||
1122 | void RawPainter::closeParagraph() |
||
1123 | { |
||
1124 | if (!doProcessing) |
||
1125 | return; |
||
1126 | int posT = actTextItem->itemText.length(); |
||
1127 | if (posT > 0) |
||
1128 | { |
||
1129 | if ((actTextItem->itemText.text(posT - 1) != SpecialChars::PARSEP)) |
||
1130 | { |
||
1131 | actTextItem->itemText.insertChars(posT, SpecialChars::PARSEP); |
||
1132 | actTextItem->itemText.applyStyle(posT, textStyle); |
||
1133 | } |
||
1134 | } |
||
1135 | } |
||
1136 | |||
1137 | void RawPainter::defineCharacterStyle(const librevenge::RVNGPropertyList &propList) |
||
1138 | { |
||
1139 | if (!doProcessing) |
||
1140 | return; |
||
1141 | qDebug() << "defineCharacterStyle"; |
||
1142 | } |
||
1143 | |||
1144 | void RawPainter::openSpan(const librevenge::RVNGPropertyList &propList) |
||
1145 | { |
||
1146 | if (!doProcessing) |
||
1147 | return; |
||
1148 | textCharStyle = textStyle.charStyle(); |
||
1149 | if (propList["fo:font-size"]) |
||
1150 | { |
||
1151 | textCharStyle.setFontSize(valueAsPoint(propList["fo:font-size"]) * 10.0); |
||
1152 | m_maxFontSize = qMax(m_maxFontSize, valueAsPoint(propList["fo:font-size"])); |
||
1153 | } |
||
1154 | if (propList["fo:color"]) |
||
1155 | textCharStyle.setFillColor(parseColor(QString(propList["fo:color"]->getStr().cstr()))); |
||
1156 | if (propList["style:font-name"]) |
||
1157 | { |
||
1158 | QString fontVari = ""; |
||
1159 | if (propList["fo:font-weight"]) |
||
1160 | fontVari = QString(propList["fo:font-weight"]->getStr().cstr()); |
||
1161 | QString fontName = QString(propList["style:font-name"]->getStr().cstr()); |
||
1162 | QString realFontName = constructFontName(fontName, fontVari); |
||
1163 | textCharStyle.setFont((*m_Doc->AllFonts)[realFontName]); |
||
1164 | } |
||
1165 | StyleFlag styleEffects = textCharStyle.effects(); |
||
1166 | if (propList["style:text-underline-type"]) |
||
1167 | styleEffects |= ScStyle_Underline; |
||
1168 | if (propList["style:text-position"]) |
||
1169 | { |
||
1170 | if (propList["style:text-position"]->getStr() == "50% 67%") |
||
1171 | styleEffects |= ScStyle_Superscript; |
||
1172 | else |
||
1173 | styleEffects |= ScStyle_Subscript; |
||
1174 | } |
||
1175 | textCharStyle.setFeatures(styleEffects.featureList()); |
||
1176 | } |
||
1177 | |||
1178 | void RawPainter::closeSpan() |
||
1179 | { |
||
1180 | } |
||
1181 | |||
1182 | void RawPainter::openLink(const librevenge::RVNGPropertyList &propList) |
||
1183 | { |
||
1184 | if (!doProcessing) |
||
1185 | return; |
||
1186 | qDebug() << "openLink"; |
||
1187 | } |
||
1188 | |||
1189 | void RawPainter::closeLink() |
||
1190 | { |
||
1191 | if (!doProcessing) |
||
1192 | return; |
||
1193 | qDebug() << "closeLink"; |
||
1194 | } |
||
1195 | |||
1196 | void RawPainter::insertTab() |
||
1197 | { |
||
1198 | if (!doProcessing) |
||
1199 | return; |
||
1200 | int posT = actTextItem->itemText.length(); |
||
1201 | actTextItem->itemText.insertChars(posT, SpecialChars::TAB); |
||
1202 | actTextItem->itemText.applyStyle(posT, textStyle); |
||
1203 | } |
||
1204 | |||
1205 | void RawPainter::insertSpace() |
||
1206 | { |
||
1207 | if (!doProcessing) |
||
1208 | return; |
||
1209 | int posT = actTextItem->itemText.length(); |
||
1210 | actTextItem->itemText.insertChars(posT, SpecialChars::BLANK); |
||
1211 | actTextItem->itemText.applyStyle(posT, textStyle); |
||
1212 | } |
||
1213 | |||
1214 | void RawPainter::insertText(const librevenge::RVNGString &text) |
||
1215 | { |
||
1216 | if (!doProcessing) |
||
1217 | return; |
||
1218 | if (lineSpSet) |
||
1219 | { |
||
1220 | textStyle.setLineSpacingMode(ParagraphStyle::FixedLineSpacing); |
||
1221 | if (lineSpIsPT) |
||
1222 | textStyle.setLineSpacing(m_linespace); |
||
1223 | else |
||
1224 | textStyle.setLineSpacing(m_maxFontSize * m_linespace); |
||
1225 | } |
||
1226 | else |
||
1227 | textStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing); |
||
1228 | librevenge::RVNGString tempUTF8(text); |
||
1229 | QString actText = QString(tempUTF8.cstr()); |
||
1230 | if (actTextItem) |
||
1231 | { |
||
1232 | int posC = actTextItem->itemText.length(); |
||
1233 | if (actText.count() > 0) |
||
1234 | { |
||
1235 | actText.replace(QChar(10), SpecialChars::LINEBREAK); |
||
1236 | actText.replace(QChar(12), SpecialChars::FRAMEBREAK); |
||
1237 | actText.replace(QChar(30), SpecialChars::NBHYPHEN); |
||
1238 | actText.replace(QChar(160), SpecialChars::NBSPACE); |
||
1239 | QTextDocument texDoc; |
||
1240 | texDoc.setHtml(actText); |
||
1241 | actText = texDoc.toPlainText(); |
||
1242 | actText = actText.trimmed(); |
||
1243 | actTextItem->itemText.insertChars(posC, actText); |
||
1244 | actTextItem->itemText.applyStyle(posC, textStyle); |
||
1245 | actTextItem->itemText.applyCharStyle(posC, actText.length(), textCharStyle); |
||
1246 | } |
||
1247 | } |
||
1248 | } |
||
1249 | |||
1250 | void RawPainter::insertLineBreak() |
||
1251 | { |
||
1252 | if (!doProcessing) |
||
1253 | return; |
||
1254 | int posT = actTextItem->itemText.length(); |
||
1255 | actTextItem->itemText.insertChars(posT, SpecialChars::LINEBREAK); |
||
1256 | actTextItem->itemText.applyStyle(posT, textStyle); |
||
1257 | } |
||
1258 | |||
1259 | void RawPainter::insertField(const librevenge::RVNGPropertyList &propList) |
||
1260 | { |
||
1261 | if (!doProcessing) |
||
1262 | return; |
||
1263 | qDebug() << "insertField"; |
||
1264 | } |
||
1265 | |||
1266 | double RawPainter::valueAsPoint(const librevenge::RVNGProperty *prop) |
||
1267 | { |
||
1268 | double value = 0.0; |
||
1269 | QString str = QString(prop->getStr().cstr()).toLower(); |
||
1270 | if (str.endsWith("in")) |
||
1271 | value = prop->getDouble() * 72.0; |
||
1272 | else |
||
1273 | value = prop->getDouble(); |
||
1274 | return value; |
||
1275 | } |
||
1276 | |||
1277 | void RawPainter::applyFill(PageItem* ite) |
||
1278 | { |
||
1279 | if(isGradient) |
||
1280 | { |
||
1281 | QString gradMode = "normal"; |
||
1282 | if (m_style["libmspub:shade"]) |
||
1283 | gradMode = QString(m_style["libmspub:shade"]->getStr().cstr()); |
||
1284 | else if (m_style["draw:style"]) |
||
1285 | gradMode = QString(m_style["draw:style"]->getStr().cstr()); |
||
1286 | if ((gradMode == "normal") || (gradMode == "linear")) |
||
1287 | { |
||
1288 | int angle = 0; |
||
1289 | if (m_style["draw:angle"]) |
||
1290 | angle = qRound(m_style["draw:angle"]->getDouble()); |
||
1291 | double h = ite->height(); |
||
1292 | double w = ite->width(); |
||
1293 | if (angle == 0) |
||
1294 | ite->setGradientVector(w / 2.0, h, w / 2.0, 0, 0, 0, 1, 0); |
||
1295 | else if (angle == -225) |
||
1296 | ite->setGradientVector(w, 0, 0, h, 0, 0, 1, 0); |
||
1297 | else if (angle == 45) |
||
1298 | ite->setGradientVector(w, h, 0, 0, 0, 0, 1, 0); |
||
1299 | else if (angle == 90) |
||
1300 | ite->setGradientVector(w, h / 2.0, 0, h / 2.0, 0, 0, 1, 0); |
||
1301 | else if (angle == 180) |
||
1302 | ite->setGradientVector(w / 2.0, 0, w / 2.0, h, 0, 0, 1, 0); |
||
1303 | else if (angle == 270) |
||
1304 | ite->setGradientVector(0, h / 2.0, w, h / 2.0, 0, 0, 1, 0); |
||
1305 | ite->fill_gradient = currentGradient; |
||
1306 | ite->GrType = 6; |
||
1307 | } |
||
1308 | else if (gradMode == "radial") |
||
1309 | { |
||
1310 | double h = ite->height(); |
||
1311 | double w = ite->width(); |
||
1312 | double cx = 0.0; |
||
1313 | double cy = 0.0; |
||
1314 | if (m_style["svg:cx"]) |
||
1315 | cx = m_style["svg:cx"]->getDouble(); |
||
1316 | if (m_style["svg:cy"]) |
||
1317 | cy = m_style["svg:cy"]->getDouble(); |
||
1318 | ite->setGradientVector(cx, cy, w, h / 2.0, cx, cy, 1, 0); |
||
1319 | ite->fill_gradient = currentGradient; |
||
1320 | ite->GrType = 7; |
||
1321 | } |
||
1322 | else if (gradMode == "square") |
||
1323 | { |
||
1324 | double cx = 0.0; |
||
1325 | double cy = 0.0; |
||
1326 | if (m_style["svg:cx"]) |
||
1327 | cx = m_style["svg:cx"]->getDouble(); |
||
1328 | if (m_style["svg:cy"]) |
||
1329 | cy = m_style["svg:cy"]->getDouble(); |
||
1330 | FPoint cp = FPoint(cx, cy); |
||
1331 | ite->setDiamondGeometry(FPoint(0, 0), FPoint(ite->width(), 0), FPoint(ite->width(), ite->height()), FPoint(0, ite->height()), cp); |
||
1332 | ite->fill_gradient.clearStops(); |
||
1333 | QList<VColorStop*> colorStops = currentGradient.colorStops(); |
||
1334 | for( int a = 0; a < colorStops.count() ; a++ ) |
||
1335 | { |
||
1336 | ite->fill_gradient.addStop(colorStops[a]->color, 1.0 - colorStops[a]->rampPoint, colorStops[a]->midPoint, colorStops[a]->opacity, colorStops[a]->name, colorStops[a]->shade); |
||
1337 | } |
||
1338 | ite->GrType = 10; |
||
1339 | } |
||
1340 | else if (gradMode == "center") |
||
1341 | { |
||
1342 | QString center = "top-left"; |
||
1343 | FPoint cp = FPoint(0, 0); |
||
1344 | if (m_style["libmspub:shade-ref-point"]) |
||
1345 | center = QString(m_style["libmspub:shade-ref-point"]->getStr().cstr()); |
||
1346 | if (center == "top-left") |
||
1347 | cp = FPoint(0, 0); |
||
1348 | else if (center == "top-right") |
||
1349 | cp = FPoint(ite->width(), 0); |
||
1350 | else if (center == "bottom-left") |
||
1351 | cp = FPoint(0, ite->height()); |
||
1352 | else if (center == "bottom-right") |
||
1353 | cp = FPoint(ite->width(), ite->height()); |
||
1354 | ite->setDiamondGeometry(FPoint(0, 0), FPoint(ite->width(), 0), FPoint(ite->width(), ite->height()), FPoint(0, ite->height()), cp); |
||
1355 | ite->fill_gradient.clearStops(); |
||
1356 | QList<VColorStop*> colorStops = currentGradient.colorStops(); |
||
1357 | for( int a = 0; a < colorStops.count() ; a++ ) |
||
1358 | { |
||
1359 | ite->fill_gradient.addStop(colorStops[a]->color, 1.0 - colorStops[a]->rampPoint, colorStops[a]->midPoint, colorStops[a]->opacity, colorStops[a]->name, colorStops[a]->shade); |
||
1360 | } |
||
1361 | ite->GrType = 10; |
||
1362 | } |
||
1363 | else if (gradMode == "shape") |
||
1364 | { |
||
1365 | ite->meshGradientPatches.clear(); |
||
1366 | FPoint center = FPoint(ite->width() / 2.0, ite->height() / 2.0); |
||
1367 | meshPoint cP; |
||
1368 | cP.resetTo(center); |
||
1369 | cP.transparency = gradColor2Trans; |
||
1370 | cP.shade = 100; |
||
1371 | cP.colorName = gradColor2Str; |
||
1372 | cP.color = gradColor2; |
||
1373 | for (int poi = 0; poi < ite->PoLine.size()-3; poi += 4) |
||
1374 | { |
||
1375 | meshGradientPatch patch; |
||
1376 | patch.BL = cP; |
||
1377 | patch.BR = cP; |
||
1378 | if (ite->PoLine.isMarker(poi)) |
||
1379 | continue; |
||
1380 | meshPoint tL; |
||
1381 | tL.resetTo(ite->PoLine.point(poi)); |
||
1382 | tL.controlRight = ite->PoLine.point(poi + 1); |
||
1383 | tL.transparency = gradColor1Trans; |
||
1384 | tL.shade = 100; |
||
1385 | tL.colorName = gradColor1Str; |
||
1386 | tL.color = gradColor1; |
||
1387 | meshPoint tR; |
||
1388 | tR.resetTo(ite->PoLine.point(poi + 2)); |
||
1389 | tR.controlLeft = ite->PoLine.point(poi + 3); |
||
1390 | tR.transparency = gradColor1Trans; |
||
1391 | tR.shade = 100; |
||
1392 | tR.colorName = gradColor1Str; |
||
1393 | tR.color = gradColor1; |
||
1394 | patch.TL = tL; |
||
1395 | patch.TR = tR; |
||
1396 | ite->meshGradientPatches.append(patch); |
||
1397 | } |
||
1398 | ite->GrType = 12; |
||
1399 | } |
||
1400 | } |
||
1401 | if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap") |
||
1402 | { |
||
1403 | QByteArray ba(m_style["draw:fill-image"]->getStr().cstr()); |
||
1404 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
1405 | QString imgExt = ""; |
||
1406 | if (m_style["librevenge:mime-type"]->getStr() == "image/png") |
||
1407 | imgExt = "png"; |
||
1408 | else if (m_style["librevenge:mime-type"]->getStr() == "image/jpeg") |
||
1409 | imgExt = "jpg"; |
||
1410 | else if (m_style["librevenge:mime-type"]->getStr() == "image/bmp") |
||
1411 | imgExt = "bmp"; |
||
1412 | else if (m_style["librevenge:mime-type"]->getStr() == "image/pict") |
||
1413 | imgExt = "pict"; |
||
1414 | else if (m_style["librevenge:mime-type"]->getStr() == "image/tiff") |
||
1415 | imgExt = "tif"; |
||
1416 | if (!imgExt.isEmpty()) |
||
1417 | { |
||
1418 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
1419 | tempFile->setAutoRemove(false); |
||
1420 | if (tempFile->open()) |
||
1421 | { |
||
1422 | tempFile->write(imageData); |
||
1423 | QString fileName = getLongPathName(tempFile->fileName()); |
||
1424 | tempFile->close(); |
||
1425 | ScPattern pat = ScPattern(); |
||
1426 | pat.setDoc(m_Doc); |
||
1427 | int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, 0, 0, 1, 1, 0, CommonStrings::None, CommonStrings::None, true); |
||
1428 | PageItem* newItem = m_Doc->Items->at(z); |
||
1429 | if (m_style["draw:red"] && m_style["draw:green"] && m_style["draw:blue"]) |
||
1430 | { |
||
1431 | int r = qRound(m_style["draw:red"]->getDouble() * 255); |
||
1432 | int g = qRound(m_style["draw:green"]->getDouble() * 255); |
||
1433 | int b = qRound(m_style["draw:blue"]->getDouble() * 255); |
||
1434 | QString colVal = QString("#%1%2%3").arg(r, 2, 16, QLatin1Char('0')).arg(g, 2, 16, QLatin1Char('0')).arg(b, 2, 16, QLatin1Char('0')); |
||
1435 | QString efVal = parseColor(colVal); |
||
1436 | efVal += "\n"; |
||
1437 | struct ImageEffect ef; |
||
1438 | efVal += "100"; |
||
1439 | ef.effectCode = ScImage::EF_COLORIZE; |
||
1440 | ef.effectParameters = efVal; |
||
1441 | ite->effectsInUse.append(ef); |
||
1442 | } |
||
1443 | m_Doc->loadPict(fileName, newItem); |
||
1444 | m_Doc->Items->takeAt(z); |
||
1445 | newItem->isInlineImage = true; |
||
1446 | newItem->isTempFile = true; |
||
1447 | pat.width = newItem->pixm.qImage().width(); |
||
1448 | pat.height = newItem->pixm.qImage().height(); |
||
1449 | pat.scaleX = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale; |
||
1450 | pat.scaleY = (72.0 / newItem->pixm.imgInfo.xres) * newItem->pixm.imgInfo.lowResScale; |
||
1451 | pat.pattern = newItem->pixm.qImage().copy(); |
||
1452 | newItem->setWidth(pat.pattern.width()); |
||
1453 | newItem->setHeight(pat.pattern.height()); |
||
1454 | newItem->SetRectFrame(); |
||
1455 | newItem->gXpos = 0.0; |
||
1456 | newItem->gYpos = 0.0; |
||
1457 | newItem->gWidth = pat.pattern.width(); |
||
1458 | newItem->gHeight = pat.pattern.height(); |
||
1459 | pat.items.append(newItem); |
||
1460 | QString patternName = "Pattern_"+ite->itemName(); |
||
1461 | patternName = patternName.trimmed().simplified().replace(" ", "_"); |
||
1462 | m_Doc->addPattern(patternName, pat); |
||
1463 | importedPatterns->append(patternName); |
||
1464 | ite->setPattern(patternName); |
||
1465 | ite->GrType = 8; |
||
1466 | } |
||
1467 | delete tempFile; |
||
1468 | } |
||
1469 | } |
||
1470 | } |
||
1471 | |||
1472 | #else |
||
1473 | RawPainter::RawPainter(ScribusDoc* Doc, double x, double y, double w, double h, int iflags, QList<PageItem*> *Elem, QStringList *iColors, QStringList *iPatterns, Selection* tSel): libwpg::WPGPaintInterface() |
||
1474 | { |
||
1475 | m_Doc = Doc; |
||
1476 | baseX = x; |
||
1477 | baseY = y; |
||
1478 | docWidth = w; |
||
1479 | docHeight = h; |
||
1480 | importerFlags = iflags; |
||
1481 | Elements = Elem; |
||
1482 | importedColors = iColors; |
||
1483 | importedPatterns = iPatterns; |
||
1484 | tmpSel = tSel; |
||
1485 | CurrColorFill = "Black"; |
||
1486 | CurrFillShade = 100.0; |
||
1487 | CurrColorStroke = "Black"; |
||
1488 | CurrStrokeShade = 100.0; |
||
1489 | CurrStrokeTrans = 0.0; |
||
1490 | CurrFillTrans = 0.0; |
||
1491 | Coords.resize(0); |
||
1492 | Coords.svgInit(); |
||
1493 | LineW = 1.0; |
||
1494 | lineJoin = Qt::MiterJoin; |
||
1495 | lineEnd = Qt::FlatCap; |
||
1496 | fillrule = true; |
||
1497 | gradientAngle = 0.0; |
||
1498 | isGradient = false; |
||
1499 | lineSpSet = false; |
||
1500 | currentGradient = VGradient(VGradient::linear); |
||
1501 | currentGradient.clearStops(); |
||
1502 | currentGradient.setRepeatMethod( VGradient::none ); |
||
1503 | dashArray.clear(); |
||
1504 | firstPage = true; |
||
1505 | actPage = 0; |
||
1506 | actTextItem = NULL; |
||
18271 | fschmid | 1507 | doProcessing = true; |
18228 | fschmid | 1508 | } |
1509 | |||
1510 | void RawPainter::startGraphics(const ::WPXPropertyList &propList) |
||
1511 | { |
||
1512 | if (propList["svg:width"]) |
||
18297 | fschmid | 1513 | docWidth = valueAsPoint(propList["svg:width"]); |
18228 | fschmid | 1514 | if (propList["svg:height"]) |
18297 | fschmid | 1515 | docHeight = valueAsPoint(propList["svg:height"]); |
18228 | fschmid | 1516 | if (importerFlags & LoadSavePlugin::lfCreateDoc) |
1517 | { |
||
1518 | if (!firstPage) |
||
1519 | { |
||
1520 | m_Doc->addPage(actPage); |
||
1521 | m_Doc->setActiveLayer(baseLayer); |
||
1522 | } |
||
1523 | else |
||
1524 | baseLayer = m_Doc->activeLayerName(); |
||
1525 | m_Doc->setPageSize("Custom"); |
||
1526 | m_Doc->currentPage()->setInitialWidth(docWidth); |
||
1527 | m_Doc->currentPage()->setInitialHeight(docHeight); |
||
1528 | m_Doc->currentPage()->setWidth(docWidth); |
||
1529 | m_Doc->currentPage()->setHeight(docHeight); |
||
1530 | m_Doc->currentPage()->MPageNam = CommonStrings::trMasterPageNormal; |
||
1531 | m_Doc->currentPage()->m_pageSize = "Custom"; |
||
1532 | m_Doc->reformPages(true); |
||
1533 | baseX = m_Doc->currentPage()->xOffset(); |
||
1534 | baseY = m_Doc->currentPage()->yOffset(); |
||
1535 | } |
||
1536 | firstPage = false; |
||
1537 | actPage++; |
||
1538 | } |
||
1539 | |||
1540 | void RawPainter::endGraphics() |
||
1541 | { |
||
18271 | fschmid | 1542 | if (importerFlags & LoadSavePlugin::lfCreateThumbnail) |
1543 | doProcessing = false; |
||
18228 | fschmid | 1544 | // qDebug() << "endGraphics"; |
1545 | // printf("RawPainter::endGraphics\n"); |
||
1546 | } |
||
1547 | |||
1548 | void RawPainter::startLayer(const ::WPXPropertyList &propList) |
||
1549 | { |
||
18271 | fschmid | 1550 | if (!doProcessing) |
1551 | return; |
||
18251 | fschmid | 1552 | FPointArray clip; |
1553 | if (propList["svg:clip-path"]) |
||
1554 | { |
||
1555 | QString svgString = QString(propList["svg:clip-path"]->getStr().cstr()); |
||
1556 | clip.resize(0); |
||
1557 | clip.svgInit(); |
||
1558 | svgString.replace(",", "."); |
||
1559 | clip.parseSVG(svgString); |
||
1560 | QTransform m; |
||
1561 | m.scale(72.0, 72.0); |
||
1562 | clip.map(m); |
||
1563 | } |
||
18228 | fschmid | 1564 | QList<PageItem*> gElements; |
18251 | fschmid | 1565 | groupEntry gr; |
1566 | gr.clip = clip.copy(); |
||
1567 | gr.Items = gElements; |
||
1568 | groupStack.push(gr); |
||
18228 | fschmid | 1569 | } |
1570 | |||
1571 | void RawPainter::endLayer() |
||
1572 | { |
||
18271 | fschmid | 1573 | if (!doProcessing) |
1574 | return; |
||
18228 | fschmid | 1575 | if (groupStack.count() != 0) |
1576 | { |
||
1577 | PageItem *ite; |
||
18251 | fschmid | 1578 | groupEntry gr = groupStack.pop(); |
1579 | QList<PageItem*> gElements = gr.Items; |
||
18228 | fschmid | 1580 | tmpSel->clear(); |
1581 | if (gElements.count() > 0) |
||
1582 | { |
||
18777 | fschmid | 1583 | bool groupClip = true; |
18228 | fschmid | 1584 | for (int dre = 0; dre < gElements.count(); ++dre) |
1585 | { |
||
1586 | tmpSel->addItem(gElements.at(dre), true); |
||
1587 | Elements->removeAll(gElements.at(dre)); |
||
18777 | fschmid | 1588 | if (gElements.at(dre)->hasSoftShadow()) |
1589 | groupClip = false; |
||
18228 | fschmid | 1590 | } |
1591 | ite = m_Doc->groupObjectsSelection(tmpSel); |
||
18777 | fschmid | 1592 | ite->setGroupClipping(groupClip); |
18228 | fschmid | 1593 | ite->setTextFlowMode(PageItem::TextFlowUsesBoundingBox); |
18251 | fschmid | 1594 | if (!gr.clip.isEmpty()) |
1595 | { |
||
1596 | double oldX = ite->xPos(); |
||
1597 | double oldY = ite->yPos(); |
||
1598 | double oldW = ite->width(); |
||
1599 | double oldH = ite->height(); |
||
1600 | double oldgW = ite->groupWidth; |
||
1601 | double oldgH = ite->groupHeight; |
||
1602 | ite->PoLine = gr.clip.copy(); |
||
1603 | ite->PoLine.translate(baseX, baseY); |
||
1604 | FPoint xy = getMinClipF(&ite->PoLine); |
||
1605 | ite->setXYPos(xy.x(), xy.y(), true); |
||
1606 | ite->PoLine.translate(-xy.x(), -xy.y()); |
||
1607 | FPoint wh = getMaxClipF(&ite->PoLine); |
||
1608 | ite->setWidthHeight(wh.x(),wh.y()); |
||
1609 | ite->groupWidth = oldgW * (ite->width() / oldW); |
||
1610 | ite->groupHeight = oldgH * (ite->height() / oldH); |
||
1611 | double dx = (ite->xPos() - oldX) / (ite->width() / ite->groupWidth); |
||
1612 | double dy = (ite->yPos() - oldY) / (ite->height() / ite->groupHeight); |
||
1613 | for (int em = 0; em < ite->groupItemList.count(); ++em) |
||
1614 | { |
||
1615 | PageItem* embedded = ite->groupItemList.at(em); |
||
1616 | embedded->moveBy(-dx, -dy, true); |
||
1617 | m_Doc->setRedrawBounding(embedded); |
||
1618 | embedded->OwnPage = m_Doc->OnPage(embedded); |
||
1619 | } |
||
1620 | ite->ClipEdited = true; |
||
1621 | ite->OldB2 = ite->width(); |
||
1622 | ite->OldH2 = ite->height(); |
||
1623 | ite->Clip = FlattenPath(ite->PoLine, ite->Segments); |
||
1624 | ite->updateGradientVectors(); |
||
1625 | } |
||
18228 | fschmid | 1626 | Elements->append(ite); |
18284 | fschmid | 1627 | if (groupStack.count() != 0) |
1628 | groupStack.top().Items.append(ite); |
||
18228 | fschmid | 1629 | } |
1630 | tmpSel->clear(); |
||
1631 | } |
||
1632 | } |
||
1633 | |||
1634 | void RawPainter::startEmbeddedGraphics(const ::WPXPropertyList &propList) |
||
1635 | { |
||
18271 | fschmid | 1636 | if (!doProcessing) |
1637 | return; |
||
18228 | fschmid | 1638 | qDebug() << "startEmbeddedGraphics"; |
1639 | // printf("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr()); |
||
1640 | } |
||
1641 | |||
1642 | void RawPainter::endEmbeddedGraphics() |
||
1643 | { |
||
18271 | fschmid | 1644 | if (!doProcessing) |
1645 | return; |
||
18228 | fschmid | 1646 | // qDebug() << "endEmbeddedGraphics"; |
1647 | // printf("RawPainter::endEmbeddedGraphics \n"); |
||
1648 | } |
||
1649 | |||
1650 | void RawPainter::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) |
||
1651 | { |
||
18271 | fschmid | 1652 | if (!doProcessing) |
1653 | return; |
||
18228 | fschmid | 1654 | m_style.clear(); |
1655 | m_style = propList; |
||
1656 | isGradient = false; |
||
1657 | if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "none") |
||
1658 | CurrColorFill = CommonStrings::None; |
||
1659 | else if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "solid") |
||
1660 | { |
||
1661 | if (propList["draw:fill-color"]) |
||
1662 | { |
||
1663 | CurrColorFill = parseColor(QString(propList["draw:fill-color"]->getStr().cstr())); |
||
1664 | if(propList["draw:opacity"]) |
||
1665 | CurrFillTrans = 1.0 - qMin(1.0, qMax(fromPercentage(QString(propList["draw:opacity"]->getStr().cstr())), 0.0)); |
||
1666 | } |
||
1667 | } |
||
1668 | if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "gradient") |
||
1669 | { |
||
1670 | double angle = 0; |
||
1671 | if (propList["draw:angle"]) |
||
1672 | angle = propList["draw:angle"]->getDouble(); |
||
1673 | if (gradient.count() > 1) |
||
1674 | { |
||
1675 | double opacity = 1.0; |
||
1676 | currentGradient = VGradient(VGradient::linear); |
||
1677 | currentGradient.clearStops(); |
||
1678 | currentGradient.setRepeatMethod( VGradient::none ); |
||
18251 | fschmid | 1679 | double dr = 1.0 / static_cast<double>(gradient.count()); |
1680 | for (unsigned c = 0; c < gradient.count(); c++) |
||
18228 | fschmid | 1681 | { |
18251 | fschmid | 1682 | WPXPropertyList grad = gradient[c]; |
1683 | if (grad["svg:stop-color"]) |
||
1684 | { |
||
1685 | QString stopName = parseColor(QString(grad["svg:stop-color"]->getStr().cstr())); |
||
1686 | double rampPoint = dr * c; |
||
1687 | if(grad["svg:offset"]) |
||
1688 | rampPoint = fromPercentage(QString(grad["svg:offset"]->getStr().cstr())); |
||
1689 | const ScColor& gradC = m_Doc->PageColors[stopName]; |
||
1690 | if(grad["svg:stop-opacity"]) |
||
1691 | opacity = qMin(1.0, qMax(fromPercentage(QString(grad["svg:stop-opacity"]->getStr().cstr())), 0.0)); |
||
1692 | currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), rampPoint, 0.5, opacity, stopName, 100 ); |
||
1693 | if (c == 0) |
||
1694 | { |
||
1695 | gradColor1Str = stopName; |
||
1696 | gradColor1 = ScColorEngine::getRGBColor(gradC, m_Doc); |
||
1697 | gradColor1Trans = opacity; |
||
1698 | } |
||
1699 | else |
||
1700 | { |
||
1701 | gradColor2Str = stopName; |
||
1702 | gradColor2 = ScColorEngine::getRGBColor(gradC, m_Doc); |
||
1703 | gradColor2Trans = opacity; |
||
1704 | } |
||
1705 | } |
||
18228 | fschmid | 1706 | } |
1707 | if (currentGradient.Stops() > 1) |
||
1708 | isGradient = true; |
||
1709 | } |
||
1710 | } |
||
1711 | if(propList["svg:fill-rule"]) |
||
1712 | { |
||
1713 | if (QString(propList["svg:fill-rule"]->getStr().cstr()) == "nonzero") |
||
1714 | fillrule = false; |
||
1715 | else |
||
1716 | fillrule = true; |
||
1717 | } |
||
1718 | if (propList["svg:stroke-width"]) |
||
18297 | fschmid | 1719 | LineW = valueAsPoint(propList["svg:stroke-width"]); |
18251 | fschmid | 1720 | if (propList["draw:stroke"]) |
18228 | fschmid | 1721 | { |
18251 | fschmid | 1722 | if (propList["draw:stroke"]->getStr() == "none") |
1723 | CurrColorStroke = CommonStrings::None; |
||
1724 | else if ((propList["draw:stroke"]->getStr() == "solid") || (propList["draw:stroke"]->getStr() == "dash")) |
||
18228 | fschmid | 1725 | { |
18251 | fschmid | 1726 | if (propList["svg:stroke-color"]) |
1727 | { |
||
1728 | CurrColorStroke = parseColor(QString(propList["svg:stroke-color"]->getStr().cstr())); |
||
1729 | if(propList["svg:stroke-opacity"]) |
||
1730 | CurrStrokeTrans = 1.0 - qMin(1.0, qMax(fromPercentage(QString(propList["svg:stroke-opacity"]->getStr().cstr())), 0.0)); |
||
1731 | } |
||
1732 | if (propList["draw:stroke"]->getStr() == "dash") |
||
1733 | { |
||
1734 | dashArray.clear(); |
||
18253 | fschmid | 1735 | double gap = LineW; |
1736 | if (propList["draw:distance"]) |
||
18297 | fschmid | 1737 | gap = valueAsPoint(propList["draw:distance"]); |
18253 | fschmid | 1738 | int dots1 = 0; |
1739 | if (propList["draw:dots1"]) |
||
1740 | dots1 = propList["draw:dots1"]->getInt(); |
||
1741 | double dots1len = LineW; |
||
1742 | if (propList["draw:dots1-length"]) |
||
18297 | fschmid | 1743 | dots1len = valueAsPoint(propList["draw:dots1-length"]); |
18253 | fschmid | 1744 | int dots2 = 0; |
1745 | if (propList["draw:dots2"]) |
||
1746 | dots2 = propList["draw:dots2"]->getInt(); |
||
1747 | double dots2len = LineW; |
||
1748 | if (propList["draw:dots2-length"]) |
||
18297 | fschmid | 1749 | dots2len = valueAsPoint(propList["draw:dots2-length"]); |
18253 | fschmid | 1750 | for (int i = 0; i < dots1; i++) |
1751 | { |
||
1752 | dashArray << qMax(dots1len, 0.1) << qMax(gap, 0.1); |
||
1753 | } |
||
1754 | for (int j = 0; j < dots2; j++) |
||
1755 | { |
||
1756 | dashArray << qMax(dots2len, 0.1) << qMax(gap, 0.1); |
||
1757 | } |
||
18251 | fschmid | 1758 | } |
1759 | else |
||
1760 | dashArray.clear(); |
||
18228 | fschmid | 1761 | } |
1762 | } |
||
1763 | if (propList["svg:stroke-linecap"]) |
||
1764 | { |
||
1765 | QString params = QString(propList["svg:stroke-linecap"]->getStr().cstr()); |
||
1766 | if( params == "butt" ) |
||
1767 | lineEnd = Qt::FlatCap; |
||
1768 | else if( params == "round" ) |
||
1769 | lineEnd = Qt::RoundCap; |
||
1770 | else if( params == "square" ) |
||
1771 | lineEnd = Qt::SquareCap; |
||
1772 | else |
||
1773 | lineEnd = Qt::FlatCap; |
||
1774 | } |
||
1775 | if (propList["svg:stroke-linejoin"]) |
||
1776 | { |
||
1777 | QString params = QString(propList["svg:stroke-linejoin"]->getStr().cstr()); |
||
1778 | if( params == "miter" ) |
||
1779 | lineJoin = Qt::MiterJoin; |
||
1780 | else if( params == "round" ) |
||
1781 | lineJoin = Qt::RoundJoin; |
||
1782 | else if( params == "bevel" ) |
||
1783 | lineJoin = Qt::BevelJoin; |
||
1784 | else |
||
1785 | lineJoin = Qt::MiterJoin; |
||
1786 | } |
||
1787 | // qDebug() << "setStyle"; |
||
1788 | // printf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr()); |
||
1789 | } |
||
1790 | |||
1791 | void RawPainter::drawRectangle(const ::WPXPropertyList &propList) |
||
1792 | { |
||
18271 | fschmid | 1793 | if (!doProcessing) |
1794 | return; |
||
1795 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
1796 | { |
||
18297 | fschmid | 1797 | double x = valueAsPoint(propList["svg:x"]); |
1798 | double y = valueAsPoint(propList["svg:y"]); |
||
1799 | double w = valueAsPoint(propList["svg:width"]); |
||
1800 | double h = valueAsPoint(propList["svg:height"]); |
||
18271 | fschmid | 1801 | int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true); |
1802 | PageItem *ite = m_Doc->Items->at(z); |
||
1803 | finishItem(ite); |
||
1804 | applyFill(ite); |
||
18730 | fschmid | 1805 | if (CurrColorFill != CommonStrings::None) |
1806 | applyShadow(ite); |
||
18271 | fschmid | 1807 | } |
1808 | // qDebug() << "drawRectangle"; |
||
18228 | fschmid | 1809 | // printf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr()); |
1810 | } |
||
1811 | |||
1812 | void RawPainter::drawEllipse(const ::WPXPropertyList &propList) |
||
1813 | { |
||
18271 | fschmid | 1814 | if (!doProcessing) |
1815 | return; |
||
1816 | if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) |
||
1817 | { |
||
18297 | fschmid | 1818 | double x = valueAsPoint(propList["svg:x"]); |
1819 | double y = valueAsPoint(propList["svg:y"]); |
||
1820 | double w = valueAsPoint(propList["svg:width"]); |
||
1821 | double h = valueAsPoint(propList["svg:height"]); |
||
18271 | fschmid | 1822 | int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true); |
1823 | PageItem *ite = m_Doc->Items->at(z); |
||
1824 | finishItem(ite); |
||
1825 | applyFill(ite); |
||
18730 | fschmid | 1826 | if (CurrColorFill != CommonStrings::None) |
1827 | applyShadow(ite); |
||
18271 | fschmid | 1828 | } |
1829 | // qDebug() << "drawEllipse"; |
||
18228 | fschmid | 1830 | // printf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr()); |
1831 | } |
||
1832 | |||
1833 | void RawPainter::drawPolyline(const ::WPXPropertyListVector &vertices) |
||
1834 | { |
||
18271 | fschmid | 1835 | if (!doProcessing) |
1836 | return; |
||
18228 | fschmid | 1837 | Coords.resize(0); |
1838 | Coords.svgInit(); |
||
1839 | PageItem *ite; |
||
18297 | fschmid | 1840 | Coords.svgMoveTo(valueAsPoint(vertices[0]["svg:x"]), valueAsPoint(vertices[0]["svg:y"])); |
18228 | fschmid | 1841 | for(unsigned i = 1; i < vertices.count(); i++) |
1842 | { |
||
18297 | fschmid | 1843 | Coords.svgLineTo(valueAsPoint(vertices[i]["svg:x"]), valueAsPoint(vertices[i]["svg:y"])); |
18228 | fschmid | 1844 | } |
1845 | if (Coords.size() > 0) |
||
1846 | { |
||
1847 | int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true); |
||
1848 | ite = m_Doc->Items->at(z); |
||
1849 | ite->PoLine = Coords.copy(); |
||
1850 | finishItem(ite); |
||
1851 | } |
||
1852 | } |
||
1853 | |||
1854 | void RawPainter::drawPolygon(const ::WPXPropertyListVector &vertices) |
||
1855 | { |
||
18271 | fschmid | 1856 | if (!doProcessing) |
1857 | return; |
||
18228 | fschmid | 1858 | if(vertices.count() < 2) |
1859 | return; |
||
1860 | Coords.resize(0); |
||
1861 | Coords.svgInit(); |
||
1862 | PageItem *ite; |
||
1863 | int z; |
||
18297 | fschmid | 1864 | Coords.svgMoveTo(valueAsPoint(vertices[0]["svg:x"]), valueAsPoint(vertices[0]["svg:y"])); |
18228 | fschmid | 1865 | for(unsigned i = 1; i < vertices.count(); i++) |
1866 | { |
||
18297 | fschmid | 1867 | Coords.svgLineTo(valueAsPoint(vertices[i]["svg:x"]), valueAsPoint(vertices[i]["svg:y"])); |
18228 | fschmid | 1868 | } |
1869 | Coords.svgClosePath(); |
||
1870 | if (Coords.size() > 0) |
||
1871 | { |
||
1872 | if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap" && m_style["style:repeat"] && m_style["style:repeat"]->getStr() == "stretch") |
||
1873 | { |
||
1874 | if (m_style["draw:fill-image"] && m_style["libwpg:mime-type"]) |
||
1875 | { |
||
1876 | QByteArray ba(m_style["draw:fill-image"]->getStr().cstr()); |
||
1877 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
1878 | QString imgExt = ""; |
||
1879 | if (m_style["libwpg:mime-type"]->getStr() == "image/png") |
||
1880 | imgExt = "png"; |
||
1881 | else if (m_style["libwpg:mime-type"]->getStr() == "image/jpeg") |
||
1882 | imgExt = "jpg"; |
||
1883 | else if (m_style["libwpg:mime-type"]->getStr() == "image/bmp") |
||
1884 | imgExt = "bmp"; |
||
1885 | else if (m_style["libwpg:mime-type"]->getStr() == "image/pict") |
||
1886 | imgExt = "pict"; |
||
1887 | else if (m_style["libwpg:mime-type"]->getStr() == "image/tiff") |
||
1888 | imgExt = "tif"; |
||
1889 | if (!imgExt.isEmpty()) |
||
1890 | { |
||
1891 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
1892 | ite = m_Doc->Items->at(z); |
||
1893 | ite->PoLine = Coords.copy(); |
||
1894 | finishItem(ite); |
||
18283 | fschmid | 1895 | insertImage(ite, imgExt, imageData); |
18228 | fschmid | 1896 | } |
18251 | fschmid | 1897 | else if (m_style["libwpg:mime-type"]->getStr() == "image/wmf") |
1898 | { |
||
1899 | imgExt = "wmf"; |
||
1900 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
1901 | if (tempFile->open()) |
||
1902 | { |
||
1903 | tempFile->write(imageData); |
||
1904 | QString fileName = getLongPathName(tempFile->fileName()); |
||
1905 | tempFile->close(); |
||
1906 | FileLoader *fileLoader = new FileLoader(fileName); |
||
1907 | int testResult = fileLoader->testFile(); |
||
1908 | delete fileLoader; |
||
1909 | if (testResult != -1) |
||
1910 | { |
||
1911 | const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult); |
||
1912 | if( fmt ) |
||
1913 | { |
||
18750 | fschmid | 1914 | fmt->setupTargets(m_Doc, 0, 0, 0, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts)); |
1915 | fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted); |
||
1916 | if (m_Doc->m_Selection->count() > 0) |
||
1917 | { |
||
1918 | ite = m_Doc->groupObjectsSelection(); |
||
1919 | double rot = 0; |
||
1920 | if (m_style["libwpg:rotate"]) |
||
1921 | rot = m_style["libwpg:rotate"]->getDouble(); |
||
1922 | QPainterPath ba = Coords.toQPainterPath(true); |
||
1923 | QRectF baR = ba.boundingRect(); |
||
1924 | if (rot != 0) |
||
1925 | { |
||
1926 | QTransform mm; |
||
1927 | mm.translate(baR.x(), baR.y()); |
||
1928 | mm.translate(baR.width() / 2.0, baR.height() / 2.0); |
||
1929 | mm.rotate(rot); |
||
1930 | mm.translate(-baR.width() / 2.0, -baR.height() / 2.0); |
||
1931 | mm.translate(-baR.x(), -baR.y()); |
||
1932 | ba = mm.map(ba); |
||
1933 | baR = ba.boundingRect(); |
||
1934 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
1935 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
1936 | Coords.fromQPainterPath(ba, true); |
||
1937 | FPoint tp2(getMinClipF(&Coords)); |
||
1938 | Coords.translate(-tp2.x(), -tp2.y()); |
||
1939 | ite->PoLine = Coords.copy(); |
||
1940 | int rm = m_Doc->RotMode(); |
||
1941 | m_Doc->RotMode(2); |
||
1942 | m_Doc->RotateItem(-rot, ite); |
||
1943 | m_Doc->RotMode(rm); |
||
1944 | } |
||
1945 | else |
||
1946 | { |
||
1947 | ite->setXYPos(baseX + baR.x(), baseY + baR.y(), true); |
||
1948 | ite->setWidthHeight(baR.width(), baR.height(), true); |
||
1949 | FPoint tp2(getMinClipF(&Coords)); |
||
1950 | Coords.translate(-tp2.x(), -tp2.y()); |
||
1951 | ite->PoLine = Coords.copy(); |
||
1952 | } |
||
1953 | finishItem(ite); |
||
1954 | if (m_style["draw:red"] && m_style["draw:green"] && m_style["draw:blue"]) |
||
1955 | { |
||
1956 | int r = qRound(m_style["draw:red"]->getDouble() * 255); |
||
1957 | int g = qRound(m_style["draw:green"]->getDouble() * 255); |
||
1958 | int b = qRound(m_style["draw:blue"]->getDouble() * 255); |
||
1959 | QString colVal = QString("#%1%2%3").arg(r, 2, 16, QLatin1Char('0')).arg(g, 2, 16, QLatin1Char('0')).arg(b, 2, 16, QLatin1Char('0')); |
||
1960 | QString efVal = parseColor(colVal); |
||
1961 | recolorItem(ite, efVal); |
||
1962 | } |
||
1963 | } |
||
18251 | fschmid | 1964 | } |
1965 | } |
||
1966 | } |
||
1967 | delete tempFile; |
||
1968 | } |
||
18228 | fschmid | 1969 | } |
1970 | } |
||
1971 | else |
||
1972 | { |
||
1973 | z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
1974 | ite = m_Doc->Items->at(z); |
||
1975 | ite->PoLine = Coords.copy(); |
||
1976 | finishItem(ite); |
||
1977 | applyFill(ite); |
||
1978 | } |
||
18515 | fschmid | 1979 | applyFlip(ite); |
18730 | fschmid | 1980 | if (CurrColorFill != CommonStrings::None) |
1981 | applyShadow(ite); |
||
18228 | fschmid | 1982 | } |
1983 | } |
||
1984 | |||
1985 | void RawPainter::drawPath(const ::WPXPropertyListVector &path) |
||
1986 | { |
||
18271 | fschmid | 1987 | if (!doProcessing) |
1988 | return; |
||
18228 | fschmid | 1989 | bool isClosed = false; |
1990 | QString svgString = ""; |
||
1991 | for(unsigned i=0; i < path.count(); i++) |
||
1992 | { |
||
1993 | WPXPropertyList propList = path[i]; |
||
1994 | if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "M") |
||
18297 | fschmid | 1995 | svgString += QString("M %1 %2 ").arg(valueAsPoint(propList["svg:x"])).arg(valueAsPoint(propList["svg:y"])); |
18228 | fschmid | 1996 | else if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "L") |
18297 | fschmid | 1997 | svgString += QString("L %1 %2 ").arg(valueAsPoint(propList["svg:x"])).arg(valueAsPoint(propList["svg:y"])); |
18228 | fschmid | 1998 | else if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "C") |
18297 | fschmid | 1999 | svgString += QString("C %1 %2 %3 %4 %5 %6 ").arg(valueAsPoint(propList["svg:x1"])).arg(valueAsPoint(propList["svg:y1"])).arg(valueAsPoint(propList["svg:x2"])).arg(valueAsPoint(propList["svg:y2"])).arg(valueAsPoint(propList["svg:x"])).arg(valueAsPoint(propList["svg:y"])); |
18228 | fschmid | 2000 | else if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "Q") |
18297 | fschmid | 2001 | svgString += QString("Q %1 %2 %3 %4 ").arg(valueAsPoint(propList["svg:x1"])).arg(valueAsPoint(propList["svg:y1"])).arg(valueAsPoint(propList["svg:x"])).arg(valueAsPoint(propList["svg:y"])); |
18228 | fschmid | 2002 | else if (propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "A") |
18297 | fschmid | 2003 | svgString += QString("A %1 %2 %3 %4 %5 %6 %7") .arg(valueAsPoint(propList["svg:rx"])) .arg(valueAsPoint(propList["svg:ry"])).arg(propList["libwpg:rotate"] ? propList["libwpg:rotate"]->getDouble() : 0).arg(propList["libwpg:large-arc"] ? propList["libwpg:large-arc"]->getInt() : 1).arg(propList["libwpg:sweep"] ? propList["libwpg:sweep"]->getInt() : 1).arg(valueAsPoint(propList["svg:x"])).arg(valueAsPoint(propList["svg:y"])); |
18228 | fschmid | 2004 | else if ((i >= path.count()-1 && i > 2) && propList["libwpg:path-action"] && propList["libwpg:path-action"]->getStr() == "Z" ) |
2005 | { |
||
2006 | isClosed = true; |
||
2007 | svgString += "Z"; |
||
2008 | } |
||
2009 | } |
||
2010 | Coords.resize(0); |
||
2011 | Coords.svgInit(); |
||
2012 | Coords.parseSVG(svgString); |
||
2013 | PageItem *ite; |
||
2014 | int z; |
||
2015 | if (isClosed) |
||
2016 | { |
||
2017 | if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "bitmap" && m_style["style:repeat"] && m_style["style:repeat"]->getStr() == "stretch") |
||
2018 | { |
||
2019 | if (m_style["draw:fill-image"] && m_style["libwpg:mime-type"]) |
||
2020 | { |
||
2021 | QByteArray ba(m_style["draw:fill-image"]->getStr().cstr()); |
||
2022 | QByteArray imageData = QByteArray::fromBase64(ba); |
||
2023 | QString imgExt = ""; |
||
2024 | if (m_style["libwpg:mime-type"]->getStr() == "image/png") |
||
2025 | imgExt = "png"; |
||
2026 | else if (m_style["libwpg:mime-type"]->getStr() == "image/jpeg") |
||
2027 | imgExt = "jpg"; |
||
2028 | else if (m_style["libwpg:mime-type"]->getStr() == "image/bmp") |
||
2029 | imgExt = "bmp"; |
||
2030 | else if (m_style["libwpg:mime-type"]->getStr() == "image/pict") |
||
2031 | imgExt = "pict"; |
||
2032 | else if (m_style["libwpg:mime-type"]->getStr() == "image/tiff") |
||
2033 | imgExt = "tif"; |
||
2034 | if (!imgExt.isEmpty()) |
||
2035 | { |
||
2036 | z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true); |
||
2037 | ite = m_Doc->Items->at(z); |
||
2038 | ite->PoLine = Coords.copy(); |
||
2039 | finishItem(ite); |
||
18283 | fschmid | 2040 | insertImage(ite, imgExt, imageData); |
18228 | fschmid | 2041 | } |
18251 | fschmid | 2042 | else if (m_style["libwpg:mime-type"]->getStr() == "image/wmf") |
2043 | { |
||
2044 | imgExt = "wmf"; |
||
2045 | QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pub_XXXXXX." + imgExt); |
||
2046 | if (tempFile->open()) |
||
2047 | { |
||
2048 | tempFile->write(imageData); |
||
2049 | QString fileName = getLongPathName(tempFile->fileName()); |
||
2050 | tempFile->close() |