Rev 25070 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
19590 | jghali | 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 "slaoutput.h" |
||
22513 | jghali | 9 | |
24884 | jghali | 10 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 2, 0) |
11 | #include <memory> |
||
12 | #include <optional> |
||
13 | #endif |
||
14 | |||
19590 | jghali | 15 | #include <poppler/GlobalParams.h> |
16 | #include <poppler/poppler-config.h> |
||
17 | #include <poppler/FileSpec.h> |
||
18 | #include <poppler/fofi/FoFiTrueType.h> |
||
19 | #include <QApplication> |
||
20 | #include <QFile> |
||
21 | #include "commonstrings.h" |
||
22 | #include "loadsaveplugin.h" |
||
23 | #include "sccolorengine.h" |
||
24 | #include "util.h" |
||
25 | #include "util_math.h" |
||
26 | #include <tiffio.h> |
||
27 | |||
24374 | jghali | 28 | //#ifndef DEBUG_TEXT_IMPORT |
29 | // #define DEBUG_TEXT_IMPORT |
||
30 | //#endif |
||
31 | |||
23550 | jghali | 32 | namespace |
33 | { |
||
34 | // Compute the intersection of two paths while considering the fillrule of each of them. |
||
35 | // QPainterPath has the right interface to do the operation but is currently buggy. |
||
36 | // See for example https://bugreports.qt.io/browse/QTBUG-83102. Thus this function |
||
37 | // applies some heuristics to find the best result. As soon QPainterPath is fixed |
||
38 | // one can just use a.intersected(b) wherever this function is called. |
||
39 | // TODO: Find an alternative to QPainterPath that works for different fill rules. |
||
40 | QPainterPath intersection(QPainterPath const &a, QPainterPath const &b) |
||
41 | { |
||
42 | // An empty path is treated like the whole area. |
||
43 | if (a.elementCount() == 0) |
||
44 | return b; |
||
45 | if (b.elementCount() == 0) |
||
46 | return a; |
||
47 | |||
48 | QPainterPath ret_a = a.intersected(b); |
||
49 | QPainterPath ret_b = b.intersected(a); |
||
50 | // Sometimes the resulting paths are not closed even though they should. |
||
51 | // Close them now. |
||
52 | ret_a.closeSubpath(); |
||
53 | ret_b.closeSubpath(); |
||
54 | |||
55 | // Most of the time one of the two operations returns an empty path while the other |
||
56 | // gives us the desired result. Return the non-empty one. |
||
57 | if (ret_a.elementCount() == 0) |
||
58 | return ret_b; |
||
59 | if (ret_b.elementCount() == 0) |
||
60 | return ret_a; |
||
61 | |||
62 | // There are cases where both intersections are not empty but one of them is quite |
||
63 | // complicated with several subpaths, etc. We return the simpler one. |
||
64 | return (ret_a.elementCount() <= ret_b.elementCount()) ? ret_a : ret_b; |
||
65 | } |
||
23589 | jghali | 66 | |
67 | // Invert preblending matte values into the color values. Assuming that c and alpha are RGBA components |
||
68 | // between 0 and 255. |
||
69 | int unblendMatte(int c, int alpha, int matte) |
||
70 | { |
||
71 | if (alpha == 0) |
||
72 | return matte; |
||
73 | int ret = matte + ((c - matte) * 255) / alpha; |
||
74 | if (ret < 0) |
||
75 | return 0; |
||
76 | if (ret > 255) |
||
77 | return 255; |
||
78 | return ret; |
||
79 | } |
||
23550 | jghali | 80 | } |
81 | |||
19590 | jghali | 82 | LinkSubmitForm::LinkSubmitForm(Object *actionObj) |
83 | { |
||
23377 | craig | 84 | if (!actionObj->isDict()) |
85 | return; |
||
22738 | jghali | 86 | |
23377 | craig | 87 | Object obj1 = actionObj->dictLookup("F"); |
88 | if (!obj1.isNull()) |
||
19590 | jghali | 89 | { |
23377 | craig | 90 | if (obj1.isDict()) |
22154 | jghali | 91 | { |
23377 | craig | 92 | Object obj3 = obj1.dictLookup("FS"); |
93 | if (!obj3.isNull()) |
||
22154 | jghali | 94 | { |
23377 | craig | 95 | if (obj3.isName()) |
22154 | jghali | 96 | { |
23377 | craig | 97 | POPPLER_CONST char *name = obj3.getName(); |
98 | if (!strcmp(name, "URL")) |
||
22154 | jghali | 99 | { |
23377 | craig | 100 | Object obj2 = obj1.dictLookup("F"); |
101 | if (!obj2.isNull()) |
||
102 | fileName = obj2.getString()->copy(); |
||
22154 | jghali | 103 | } |
104 | } |
||
105 | } |
||
106 | } |
||
107 | } |
||
23377 | craig | 108 | obj1 = actionObj->dictLookup("Flags"); |
109 | if (!obj1.isNull()) |
||
110 | { |
||
111 | if (obj1.isNum()) |
||
112 | m_flags = obj1.getInt(); |
||
113 | } |
||
19590 | jghali | 114 | } |
115 | |||
116 | LinkSubmitForm::~LinkSubmitForm() |
||
117 | { |
||
22609 | craig | 118 | delete fileName; |
19590 | jghali | 119 | } |
120 | |||
121 | LinkImportData::LinkImportData(Object *actionObj) |
||
122 | { |
||
23377 | craig | 123 | if (!actionObj->isDict()) |
124 | return; |
||
125 | Object obj1 = actionObj->dictLookup("F"); |
||
126 | if (obj1.isNull()) |
||
127 | return; |
||
22738 | jghali | 128 | |
23377 | craig | 129 | Object obj3 = getFileSpecNameForPlatform(&obj1); |
130 | if (!obj3.isNull()) |
||
131 | fileName = obj3.getString()->copy(); |
||
19590 | jghali | 132 | } |
133 | |||
134 | LinkImportData::~LinkImportData() |
||
135 | { |
||
22609 | craig | 136 | delete fileName; |
19590 | jghali | 137 | } |
138 | |||
139 | AnoOutputDev::~AnoOutputDev() |
||
140 | { |
||
24374 | jghali | 141 | delete fontName; |
142 | delete itemText; |
||
19590 | jghali | 143 | } |
144 | |||
145 | AnoOutputDev::AnoOutputDev(ScribusDoc* doc, QStringList *importedColors) |
||
146 | { |
||
147 | m_doc = doc; |
||
148 | m_importedColors = importedColors; |
||
24374 | jghali | 149 | currColorText = "Black"; |
150 | currColorFill = CommonStrings::None; |
||
151 | currColorStroke = CommonStrings::None; |
||
19590 | jghali | 152 | } |
153 | |||
154 | void AnoOutputDev::eoFill(GfxState *state) |
||
155 | { |
||
156 | int shade = 100; |
||
24374 | jghali | 157 | currColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade); |
19590 | jghali | 158 | } |
159 | |||
160 | void AnoOutputDev::fill(GfxState *state) |
||
161 | { |
||
162 | int shade = 100; |
||
24374 | jghali | 163 | currColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade); |
19590 | jghali | 164 | } |
165 | |||
166 | void AnoOutputDev::stroke(GfxState *state) |
||
167 | { |
||
168 | int shade = 100; |
||
24374 | jghali | 169 | currColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &shade); |
19590 | jghali | 170 | } |
171 | |||
22678 | jghali | 172 | void AnoOutputDev::drawString(GfxState *state, POPPLER_CONST GooString *s) |
19590 | jghali | 173 | { |
174 | int shade = 100; |
||
24374 | jghali | 175 | currColorText = getColor(state->getFillColorSpace(), state->getFillColor(), &shade); |
176 | fontSize = state->getFontSize(); |
||
25074 | jghali | 177 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 4, 0) |
178 | if (state->getFont() && state->getFont()->getName()) |
||
179 | fontName = new GooString(state->getFont()->getName().value()); |
||
180 | #else |
||
19590 | jghali | 181 | if (state->getFont()) |
24374 | jghali | 182 | fontName = state->getFont()->getName()->copy(); |
25074 | jghali | 183 | #endif |
24374 | jghali | 184 | itemText = s->copy(); |
19590 | jghali | 185 | } |
186 | |||
22741 | jghali | 187 | QString AnoOutputDev::getColor(GfxColorSpace *color_space, POPPLER_CONST_070 GfxColor *color, int *shade) |
19590 | jghali | 188 | { |
189 | QString fNam; |
||
190 | QString namPrefix = "FromPDF"; |
||
191 | ScColor tmp; |
||
192 | tmp.setSpotColor(false); |
||
193 | tmp.setRegistrationColor(false); |
||
194 | *shade = 100; |
||
195 | if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB)) |
||
196 | { |
||
197 | GfxRGB rgb; |
||
198 | color_space->getRGB(color, &rgb); |
||
22212 | jghali | 199 | double Rc = colToDbl(rgb.r); |
200 | double Gc = colToDbl(rgb.g); |
||
201 | double Bc = colToDbl(rgb.b); |
||
202 | tmp.setRgbColorF(Rc, Gc, Bc); |
||
19590 | jghali | 203 | fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp); |
204 | } |
||
205 | else if (color_space->getMode() == csDeviceCMYK) |
||
206 | { |
||
207 | GfxCMYK cmyk; |
||
208 | color_space->getCMYK(color, &cmyk); |
||
22212 | jghali | 209 | double Cc = colToDbl(cmyk.c); |
210 | double Mc = colToDbl(cmyk.m); |
||
211 | double Yc = colToDbl(cmyk.y); |
||
212 | double Kc = colToDbl(cmyk.k); |
||
22593 | jghali | 213 | tmp.setCmykColorF(Cc, Mc, Yc, Kc); |
19590 | jghali | 214 | fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp); |
215 | } |
||
216 | else if ((color_space->getMode() == csCalGray) || (color_space->getMode() == csDeviceGray)) |
||
217 | { |
||
218 | GfxGray gray; |
||
219 | color_space->getGray(color, &gray); |
||
22212 | jghali | 220 | double Kc = 1.0 - colToDbl(gray); |
22593 | jghali | 221 | tmp.setCmykColorF(0, 0, 0, Kc); |
19590 | jghali | 222 | fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp); |
223 | } |
||
224 | else if (color_space->getMode() == csSeparation) |
||
225 | { |
||
22596 | jghali | 226 | GfxSeparationColorSpace* sepColorSpace = (GfxSeparationColorSpace*)color_space; |
227 | GfxColorSpace* altColorSpace = sepColorSpace->getAlt(); |
||
228 | QString name = QString(sepColorSpace->getName()->getCString()); |
||
229 | bool isRegistrationColor = (name == "All"); |
||
230 | if (isRegistrationColor) |
||
231 | { |
||
232 | tmp.setCmykColorF(1.0, 1.0, 1.0, 1.0); |
||
233 | tmp.setRegistrationColor(true); |
||
234 | name = "Registration"; |
||
235 | } |
||
236 | else if ((altColorSpace->getMode() == csDeviceRGB) || (altColorSpace->getMode() == csCalRGB)) |
||
237 | { |
||
238 | double x = 1.0; |
||
239 | double comps[gfxColorMaxComps]; |
||
240 | sepColorSpace->getFunc()->transform(&x, comps); |
||
241 | tmp.setRgbColorF(comps[0], comps[1], comps[2]); |
||
242 | } |
||
243 | else if ((altColorSpace->getMode() == csCalGray) || (altColorSpace->getMode() == csDeviceGray)) |
||
244 | { |
||
245 | double x = 1.0; |
||
246 | double comps[gfxColorMaxComps]; |
||
247 | sepColorSpace->getFunc()->transform(&x, comps); |
||
248 | tmp.setCmykColorF(0.0, 0.0, 0.0, 1.0 - comps[0]); |
||
249 | } |
||
250 | else if (altColorSpace->getMode() == csLab) |
||
251 | { |
||
252 | double x = 1.0; |
||
253 | double comps[gfxColorMaxComps]; |
||
254 | sepColorSpace->getFunc()->transform(&x, comps); |
||
255 | tmp.setLabColor(comps[0], comps[1], comps[2]); |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | GfxCMYK cmyk; |
||
260 | color_space->getCMYK(color, &cmyk); |
||
261 | double Cc = colToDbl(cmyk.c); |
||
262 | double Mc = colToDbl(cmyk.m); |
||
263 | double Yc = colToDbl(cmyk.y); |
||
264 | double Kc = colToDbl(cmyk.k); |
||
265 | tmp.setCmykColorF(Cc, Mc, Yc, Kc); |
||
266 | } |
||
267 | tmp.setSpotColor(true); |
||
22592 | jghali | 268 | |
22596 | jghali | 269 | fNam = m_doc->PageColors.tryAddColor(name, tmp); |
270 | *shade = qRound(colToDbl(color->c[0]) * 100); |
||
19590 | jghali | 271 | } |
272 | else |
||
273 | { |
||
274 | GfxRGB rgb; |
||
275 | color_space->getRGB(color, &rgb); |
||
22212 | jghali | 276 | double Rc = colToDbl(rgb.r); |
277 | double Gc = colToDbl(rgb.g); |
||
278 | double Bc = colToDbl(rgb.b); |
||
279 | tmp.setRgbColorF(Rc, Gc, Bc); |
||
19590 | jghali | 280 | fNam = m_doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp); |
281 | // qDebug() << "update fill color other colorspace" << color_space->getMode() << "treating as rgb" << Rc << Gc << Bc; |
||
282 | } |
||
283 | if (fNam == namPrefix+tmp.name()) |
||
284 | m_importedColors->append(fNam); |
||
285 | return fNam; |
||
286 | } |
||
287 | |||
288 | SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringList *importedColors, int flags) |
||
289 | { |
||
290 | m_doc = doc; |
||
291 | m_Elements = Elements; |
||
292 | pushGroup(); |
||
293 | m_importedColors = importedColors; |
||
24374 | jghali | 294 | m_currColorStroke = "Black"; |
295 | m_currColorFill = "Black"; |
||
19590 | jghali | 296 | tmpSel = new Selection(m_doc, false); |
297 | importerFlags = flags; |
||
298 | currentLayer = m_doc->activeLayer(); |
||
299 | layersSetByOCG = false; |
||
300 | } |
||
301 | |||
302 | SlaOutputDev::~SlaOutputDev() |
||
303 | { |
||
304 | m_groupStack.clear(); |
||
305 | tmpSel->clear(); |
||
306 | delete tmpSel; |
||
307 | delete m_fontEngine; |
||
308 | } |
||
309 | |||
310 | /* get Actions not implemented by Poppler */ |
||
311 | LinkAction* SlaOutputDev::SC_getAction(AnnotWidget *ano) |
||
312 | { |
||
22527 | craig | 313 | LinkAction *linkAction = nullptr; |
19590 | jghali | 314 | Object obj; |
315 | Ref refa = ano->getRef(); |
||
22906 | jghali | 316 | |
22154 | jghali | 317 | obj = xref->fetch(refa.num, refa.gen); |
318 | if (obj.isDict()) |
||
319 | { |
||
320 | Dict* adic = obj.getDict(); |
||
22906 | jghali | 321 | POPPLER_CONST_075 Object POPPLER_REF additionalActions = adic->lookupNF("A"); |
22154 | jghali | 322 | Object additionalActionsObject = additionalActions.fetch(pdfDoc->getXRef()); |
323 | if (additionalActionsObject.isDict()) |
||
324 | { |
||
325 | Object actionObject = additionalActionsObject.dictLookup("S"); |
||
326 | if (actionObject.isName("ImportData")) |
||
327 | { |
||
328 | linkAction = new LinkImportData(&additionalActionsObject); |
||
329 | } |
||
330 | else if (actionObject.isName("SubmitForm")) |
||
331 | { |
||
332 | linkAction = new LinkSubmitForm(&additionalActionsObject); |
||
333 | } |
||
334 | } |
||
335 | } |
||
19590 | jghali | 336 | return linkAction; |
337 | } |
||
338 | |||
339 | /* Replacement for the crippled Poppler function LinkAction* AnnotWidget::getAdditionalAction(AdditionalActionsType type) */ |
||
23478 | jghali | 340 | std::unique_ptr<LinkAction> SlaOutputDev::SC_getAdditionalAction(const char *key, AnnotWidget *ano) |
341 | { |
||
342 | std::unique_ptr<LinkAction> linkAction; |
||
19590 | jghali | 343 | Object obj; |
344 | Ref refa = ano->getRef(); |
||
22154 | jghali | 345 | |
346 | obj = xref->fetch(refa.num, refa.gen); |
||
347 | if (obj.isDict()) |
||
348 | { |
||
349 | Dict* adic = obj.getDict(); |
||
22906 | jghali | 350 | POPPLER_CONST_075 Object POPPLER_REF additionalActions = adic->lookupNF("AA"); |
22154 | jghali | 351 | Object additionalActionsObject = additionalActions.fetch(pdfDoc->getXRef()); |
352 | if (additionalActionsObject.isDict()) |
||
353 | { |
||
354 | Object actionObject = additionalActionsObject.dictLookup(key); |
||
355 | if (actionObject.isDict()) |
||
356 | linkAction = LinkAction::parseAction(&actionObject, pdfDoc->getCatalog()->getBaseURI()); |
||
357 | } |
||
358 | } |
||
19590 | jghali | 359 | return linkAction; |
360 | } |
||
361 | |||
362 | GBool SlaOutputDev::annotations_callback(Annot *annota, void *user_data) |
||
363 | { |
||
364 | SlaOutputDev *dev = (SlaOutputDev*)user_data; |
||
25074 | jghali | 365 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 4, 0) |
366 | const PDFRectangle& annotRect = annota->getRect();; |
||
367 | const PDFRectangle* box = &annotRect; |
||
368 | #else |
||
19590 | jghali | 369 | PDFRectangle *box = annota->getRect(); |
25074 | jghali | 370 | #endif |
19590 | jghali | 371 | double xCoor = dev->m_doc->currentPage()->xOffset() + box->x1 - dev->cropOffsetX; |
372 | double yCoor = dev->m_doc->currentPage()->yOffset() + dev->m_doc->currentPage()->height() - box->y2 + dev->cropOffsetY; |
||
373 | double width = box->x2 - box->x1; |
||
374 | double height = box->y2 - box->y1; |
||
375 | if (dev->rotate == 90) |
||
376 | { |
||
377 | xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + box->y2; |
||
378 | yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->x1; |
||
379 | } |
||
380 | else if (dev->rotate == 180) |
||
381 | { |
||
382 | xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->x1; |
||
383 | yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + box->y2; |
||
384 | } |
||
385 | else if (dev->rotate == 270) |
||
386 | { |
||
387 | xCoor = dev->m_doc->currentPage()->xOffset() - dev->cropOffsetX + dev->m_doc->currentPage()->width() - box->y2; |
||
388 | yCoor = dev->m_doc->currentPage()->yOffset() + dev->cropOffsetY + dev->m_doc->currentPage()->height() - box->x1; |
||
389 | } |
||
390 | bool retVal = true; |
||
391 | if (annota->getType() == Annot::typeText) |
||
392 | retVal = !dev->handleTextAnnot(annota, xCoor, yCoor, width, height); |
||
393 | else if (annota->getType() == Annot::typeLink) |
||
394 | retVal = !dev->handleLinkAnnot(annota, xCoor, yCoor, width, height); |
||
395 | else if (annota->getType() == Annot::typeWidget) |
||
396 | retVal = !dev->handleWidgetAnnot(annota, xCoor, yCoor, width, height); |
||
397 | return retVal; |
||
398 | } |
||
399 | |||
400 | bool SlaOutputDev::handleTextAnnot(Annot* annota, double xCoor, double yCoor, double width, double height) |
||
401 | { |
||
402 | AnnotText *anl = (AnnotText*)annota; |
||
20561 | jghali | 403 | int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None); |
19590 | jghali | 404 | PageItem *ite = m_doc->Items->at(z); |
405 | int flg = annota->getFlags(); |
||
406 | if (!(flg & 16)) |
||
407 | ite->setRotation(rotate, true); |
||
408 | ite->ClipEdited = true; |
||
409 | ite->FrameType = 3; |
||
410 | ite->setFillEvenOdd(false); |
||
23040 | jghali | 411 | ite->Clip = flattenPath(ite->PoLine, ite->Segments); |
19590 | jghali | 412 | ite->ContourLine = ite->PoLine.copy(); |
413 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
414 | m_Elements->append(ite); |
||
415 | if (m_groupStack.count() != 0) |
||
416 | { |
||
417 | m_groupStack.top().Items.append(ite); |
||
418 | applyMask(ite); |
||
419 | } |
||
420 | ite->setIsAnnotation(true); |
||
421 | ite->AutoName = false; |
||
422 | ite->annotation().setType(Annotation::Text); |
||
423 | ite->annotation().setActionType(Annotation::Action_None); |
||
424 | ite->annotation().setAnOpen(anl->getOpen()); |
||
425 | QString iconName = UnicodeParsedString(anl->getIcon()); |
||
426 | if (iconName == "Note") |
||
427 | ite->annotation().setIcon(Annotation::Icon_Note); |
||
428 | else if (iconName == "Comment") |
||
429 | ite->annotation().setIcon(Annotation::Icon_Comment); |
||
430 | else if (iconName == "Key") |
||
431 | ite->annotation().setIcon(Annotation::Icon_Key); |
||
432 | else if (iconName == "Help") |
||
433 | ite->annotation().setIcon(Annotation::Icon_Help); |
||
434 | else if (iconName == "NewParagraph") |
||
435 | ite->annotation().setIcon(Annotation::Icon_NewParagraph); |
||
436 | else if (iconName == "Paragraph") |
||
437 | ite->annotation().setIcon(Annotation::Icon_Paragraph); |
||
438 | else if (iconName == "Insert") |
||
439 | ite->annotation().setIcon(Annotation::Icon_Insert); |
||
440 | else if (iconName == "Cross") |
||
441 | ite->annotation().setIcon(Annotation::Icon_Cross); |
||
442 | else if (iconName == "Circle") |
||
443 | ite->annotation().setIcon(Annotation::Icon_Circle); |
||
444 | else |
||
445 | ite->annotation().setIcon(Annotation::Icon_Note); |
||
446 | ite->setItemName( CommonStrings::itemName_TextAnnotation + QString("%1").arg(m_doc->TotalItems)); |
||
447 | ite->itemText.insertChars(UnicodeParsedString(annota->getContents())); |
||
448 | ite->itemText.trim(); |
||
449 | return true; |
||
450 | } |
||
451 | |||
452 | bool SlaOutputDev::handleLinkAnnot(Annot* annota, double xCoor, double yCoor, double width, double height) |
||
453 | { |
||
454 | AnnotLink *anl = (AnnotLink*)annota; |
||
455 | LinkAction *act = anl->getAction(); |
||
456 | if (!act) |
||
457 | return false; |
||
458 | bool validLink = false; |
||
459 | int pagNum = 0; |
||
460 | int xco = 0; |
||
461 | int yco = 0; |
||
25070 | craig | 462 | QString fileName; |
19590 | jghali | 463 | if (act->getKind() == actionGoTo) |
464 | { |
||
22513 | jghali | 465 | LinkGoTo *gto = (LinkGoTo*) act; |
466 | POPPLER_CONST LinkDest *dst = gto->getDest(); |
||
19590 | jghali | 467 | if (dst) |
468 | { |
||
469 | if (dst->getKind() == destXYZ) |
||
470 | { |
||
471 | if (dst->isPageRef()) |
||
472 | { |
||
473 | Ref dstr = dst->getPageRef(); |
||
22975 | jghali | 474 | pagNum = pdfDoc->findPage(dstr); |
19590 | jghali | 475 | } |
476 | else |
||
477 | pagNum = dst->getPageNum(); |
||
478 | xco = dst->getLeft(); |
||
479 | yco = dst->getTop(); |
||
480 | validLink = true; |
||
481 | } |
||
482 | } |
||
483 | else |
||
484 | { |
||
22513 | jghali | 485 | POPPLER_CONST GooString *ndst = gto->getNamedDest(); |
19590 | jghali | 486 | if (ndst) |
487 | { |
||
23478 | jghali | 488 | std::unique_ptr<LinkDest> dstn = pdfDoc->findDest(ndst); |
19590 | jghali | 489 | if (dstn) |
490 | { |
||
491 | if (dstn->getKind() == destXYZ) |
||
492 | { |
||
493 | if (dstn->isPageRef()) |
||
494 | { |
||
495 | Ref dstr = dstn->getPageRef(); |
||
22975 | jghali | 496 | pagNum = pdfDoc->findPage(dstr); |
19590 | jghali | 497 | } |
498 | else |
||
499 | pagNum = dstn->getPageNum(); |
||
500 | xco = dstn->getLeft(); |
||
501 | yco = dstn->getTop(); |
||
502 | validLink = true; |
||
503 | } |
||
504 | } |
||
505 | } |
||
506 | } |
||
507 | } |
||
508 | else if (act->getKind() == actionGoToR) |
||
509 | { |
||
510 | LinkGoToR *gto = (LinkGoToR*)act; |
||
511 | fileName = UnicodeParsedString(gto->getFileName()); |
||
22513 | jghali | 512 | POPPLER_CONST LinkDest *dst = gto->getDest(); |
19590 | jghali | 513 | if (dst) |
514 | { |
||
515 | if (dst->getKind() == destXYZ) |
||
516 | { |
||
517 | pagNum = dst->getPageNum(); |
||
518 | xco = dst->getLeft(); |
||
519 | yco = dst->getTop(); |
||
520 | validLink = true; |
||
521 | } |
||
522 | } |
||
523 | else |
||
524 | { |
||
22513 | jghali | 525 | POPPLER_CONST GooString *ndst = gto->getNamedDest(); |
19590 | jghali | 526 | if (ndst) |
527 | { |
||
23478 | jghali | 528 | std::unique_ptr<LinkDest> dstn = pdfDoc->findDest(ndst); |
19590 | jghali | 529 | if (dstn) |
530 | { |
||
531 | if (dstn->getKind() == destXYZ) |
||
532 | { |
||
533 | pagNum = dstn->getPageNum(); |
||
534 | xco = dstn->getLeft(); |
||
535 | yco = dstn->getTop(); |
||
536 | validLink = true; |
||
537 | } |
||
538 | } |
||
539 | } |
||
540 | } |
||
541 | } |
||
542 | else if (act->getKind() == actionURI) |
||
543 | { |
||
544 | LinkURI *gto = (LinkURI*)act; |
||
545 | validLink = true; |
||
546 | fileName = UnicodeParsedString(gto->getURI()); |
||
547 | } |
||
548 | if (validLink) |
||
549 | { |
||
20561 | jghali | 550 | int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, CommonStrings::None, CommonStrings::None); |
19590 | jghali | 551 | PageItem *ite = m_doc->Items->at(z); |
552 | int flg = annota->getFlags(); |
||
553 | if (!(flg & 16)) |
||
554 | ite->setRotation(rotate, true); |
||
555 | ite->ClipEdited = true; |
||
556 | ite->FrameType = 3; |
||
557 | ite->setFillEvenOdd(false); |
||
23040 | jghali | 558 | ite->Clip = flattenPath(ite->PoLine, ite->Segments); |
19590 | jghali | 559 | ite->ContourLine = ite->PoLine.copy(); |
560 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
561 | m_Elements->append(ite); |
||
562 | if (m_groupStack.count() != 0) |
||
563 | { |
||
564 | m_groupStack.top().Items.append(ite); |
||
565 | applyMask(ite); |
||
566 | } |
||
567 | ite->setIsAnnotation(true); |
||
568 | ite->AutoName = false; |
||
569 | if (act->getKind() == actionGoTo) |
||
570 | { |
||
21458 | jghali | 571 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 572 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
573 | ite->annotation().setActionType(2); |
||
574 | } |
||
575 | else if (act->getKind() == actionGoToR) |
||
576 | { |
||
21458 | jghali | 577 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 578 | ite->annotation().setExtern(fileName); |
579 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
||
580 | ite->annotation().setActionType(9); |
||
581 | } |
||
582 | else if (act->getKind() == actionURI) |
||
583 | { |
||
584 | ite->annotation().setAction(""); |
||
585 | ite->annotation().setExtern(fileName); |
||
586 | ite->annotation().setActionType(8); |
||
587 | } |
||
588 | ite->annotation().setType(Annotation::Link); |
||
589 | ite->setItemName( CommonStrings::itemName_LinkAnnotation + QString("%1").arg(m_doc->TotalItems)); |
||
590 | } |
||
591 | return validLink; |
||
592 | } |
||
593 | |||
594 | bool SlaOutputDev::handleWidgetAnnot(Annot* annota, double xCoor, double yCoor, double width, double height) |
||
595 | { |
||
596 | bool retVal = false; |
||
597 | bool found = false; |
||
598 | |||
599 | if (!m_formWidgets) |
||
600 | return false; |
||
601 | |||
602 | int formcount = m_formWidgets->getNumWidgets(); |
||
603 | for (int i = 0; i < formcount; ++i) |
||
604 | { |
||
605 | FormWidget *fm = m_formWidgets->getWidget(i); |
||
606 | if (!fm) |
||
607 | continue; |
||
608 | AnnotWidget *ano = fm->getWidgetAnnotation(); |
||
609 | if (!ano) |
||
610 | continue; |
||
611 | if (ano != (AnnotWidget*) annota) |
||
612 | continue; |
||
613 | found = true; |
||
614 | int wtyp = -1; |
||
615 | if (fm->getType() == formButton) |
||
616 | { |
||
617 | FormWidgetButton *btn = (FormWidgetButton*)fm; |
||
618 | if (btn) |
||
619 | { |
||
620 | if (btn->getButtonType() == formButtonCheck) |
||
621 | { |
||
622 | wtyp = Annotation::Checkbox; |
||
623 | retVal = true; |
||
624 | } |
||
625 | else if (btn->getButtonType() == formButtonPush) |
||
626 | { |
||
627 | wtyp = Annotation::Button; |
||
628 | retVal = true; |
||
629 | } |
||
630 | else if (btn->getButtonType() == formButtonRadio) |
||
631 | { |
||
632 | wtyp = Annotation::RadioButton; |
||
633 | retVal = true; |
||
634 | } |
||
635 | } |
||
636 | } |
||
637 | else if (fm->getType() == formText) |
||
638 | { |
||
639 | wtyp = Annotation::Textfield; |
||
640 | retVal = true; |
||
641 | } |
||
642 | else if (fm->getType() == formChoice) |
||
643 | { |
||
644 | FormWidgetChoice *btn = (FormWidgetChoice*)fm; |
||
645 | if (btn) |
||
646 | { |
||
647 | if (btn->isCombo()) |
||
648 | { |
||
649 | wtyp = Annotation::Combobox; |
||
650 | retVal = true; |
||
651 | } |
||
652 | else if (btn->isListBox()) |
||
653 | { |
||
654 | wtyp = Annotation::Listbox; |
||
655 | retVal = true; |
||
656 | } |
||
657 | } |
||
658 | } |
||
659 | if (retVal) |
||
660 | { |
||
661 | AnnotAppearanceCharacs *achar = ano->getAppearCharacs(); |
||
662 | bool fgFound = false; |
||
663 | bool bgFound = false; |
||
664 | if (achar) |
||
665 | { |
||
22513 | jghali | 666 | POPPLER_CONST AnnotColor *bgCol = achar->getBackColor(); |
19590 | jghali | 667 | if (bgCol) |
668 | { |
||
669 | bgFound = true; |
||
24374 | jghali | 670 | m_currColorFill = getAnnotationColor(bgCol); |
19590 | jghali | 671 | } |
672 | else |
||
24374 | jghali | 673 | m_currColorFill = CommonStrings::None; |
22513 | jghali | 674 | POPPLER_CONST AnnotColor *fgCol = achar->getBorderColor(); |
19590 | jghali | 675 | if (fgCol) |
676 | { |
||
677 | fgFound = true; |
||
24374 | jghali | 678 | m_currColorStroke = getAnnotationColor(fgCol); |
19590 | jghali | 679 | } |
680 | else |
||
681 | { |
||
682 | fgCol = achar->getBackColor(); |
||
683 | if (fgCol) |
||
24374 | jghali | 684 | m_currColorStroke = getAnnotationColor(fgCol); |
19590 | jghali | 685 | else |
24374 | jghali | 686 | m_currColorStroke = CommonStrings::None; |
19590 | jghali | 687 | } |
688 | } |
||
24374 | jghali | 689 | QString m_currColorText = "Black"; |
19590 | jghali | 690 | double fontSize = 12; |
25070 | craig | 691 | QString fontName; |
692 | QString itemText; |
||
19590 | jghali | 693 | AnnotAppearance *apa = annota->getAppearStreams(); |
694 | if (apa || !achar) |
||
695 | { |
||
24374 | jghali | 696 | AnoOutputDev *annotOutDev = new AnoOutputDev(m_doc, m_importedColors); |
25074 | jghali | 697 | #if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(22, 4, 0) |
698 | const PDFRectangle& annotaRect = annota->getRect(); |
||
699 | Gfx* gfx = new Gfx(pdfDoc, annotOutDev, pdfDoc->getPage(m_actPage)->getResourceDict(), &annotaRect, nullptr); |
||
700 | #else |
||
24374 | jghali | 701 | Gfx *gfx = new Gfx(pdfDoc, annotOutDev, pdfDoc->getPage(m_actPage)->getResourceDict(), annota->getRect(), nullptr); |
25074 | jghali | 702 | #endif |
19590 | jghali | 703 | ano->draw(gfx, false); |
704 | if (!bgFound) |
||
24374 | jghali | 705 | m_currColorFill = annotOutDev->currColorFill; |
19590 | jghali | 706 | if (!fgFound) |
24374 | jghali | 707 | m_currColorStroke = annotOutDev->currColorStroke; |
708 | m_currColorText = annotOutDev->currColorText; |
||
709 | fontSize = annotOutDev->fontSize; |
||
710 | fontName = UnicodeParsedString(annotOutDev->fontName); |
||
711 | itemText = UnicodeParsedString(annotOutDev->itemText); |
||
19590 | jghali | 712 | delete gfx; |
24374 | jghali | 713 | delete annotOutDev; |
19590 | jghali | 714 | } |
24374 | jghali | 715 | int z = m_doc->itemAdd(PageItem::TextFrame, PageItem::Rectangle, xCoor, yCoor, width, height, 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 716 | PageItem *ite = m_doc->Items->at(z); |
717 | int flg = annota->getFlags(); |
||
718 | if (!(flg & 16)) |
||
719 | ite->setRotation(rotate, true); |
||
720 | ite->ClipEdited = true; |
||
721 | ite->FrameType = 3; |
||
722 | ite->setFillEvenOdd(false); |
||
23040 | jghali | 723 | ite->Clip = flattenPath(ite->PoLine, ite->Segments); |
19590 | jghali | 724 | ite->ContourLine = ite->PoLine.copy(); |
725 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
726 | m_Elements->append(ite); |
||
727 | if (m_groupStack.count() != 0) |
||
728 | { |
||
729 | m_groupStack.top().Items.append(ite); |
||
730 | applyMask(ite); |
||
731 | } |
||
732 | ite->setIsAnnotation(true); |
||
733 | ite->AutoName = false; |
||
734 | AnnotBorder *brd = annota->getBorder(); |
||
735 | if (brd) |
||
736 | { |
||
737 | int bsty = brd->getStyle(); |
||
738 | if (bsty == AnnotBorder::borderDashed) |
||
739 | bsty = 1; |
||
740 | else if (bsty == AnnotBorder::borderBeveled) |
||
741 | bsty = 3; |
||
742 | else if (bsty == AnnotBorder::borderInset) |
||
743 | bsty = 4; |
||
744 | else if (bsty == AnnotBorder::borderUnderlined) |
||
745 | bsty = 2; |
||
22748 | jghali | 746 | ite->annotation().setBorderStyle(bsty); |
24374 | jghali | 747 | ite->annotation().setBorderColor(m_currColorStroke); |
22748 | jghali | 748 | ite->annotation().setBorderWidth(qRound(brd->getWidth())); |
19590 | jghali | 749 | } |
750 | else |
||
751 | { |
||
22748 | jghali | 752 | ite->annotation().setBorderStyle(0); |
19590 | jghali | 753 | ite->annotation().setBorderColor(CommonStrings::None); |
22748 | jghali | 754 | ite->annotation().setBorderWidth(0); |
19590 | jghali | 755 | } |
25070 | craig | 756 | QString tmTxt(UnicodeParsedString(fm->getPartialName())); |
19590 | jghali | 757 | if (!tmTxt.isEmpty()) |
758 | ite->setItemName(tmTxt); |
||
25070 | craig | 759 | tmTxt.clear(); |
19590 | jghali | 760 | tmTxt = UnicodeParsedString(fm->getAlternateUiName()); |
761 | if (!tmTxt.isEmpty()) |
||
762 | ite->annotation().setToolTip(tmTxt); |
||
25070 | craig | 763 | tmTxt.clear(); |
19590 | jghali | 764 | if (achar) |
765 | { |
||
766 | tmTxt = UnicodeParsedString(achar->getRolloverCaption()); |
||
767 | if (!tmTxt.isEmpty()) |
||
768 | ite->annotation().setRollOver(tmTxt); |
||
769 | tmTxt = ""; |
||
770 | tmTxt = UnicodeParsedString(achar->getAlternateCaption()); |
||
771 | if (!tmTxt.isEmpty()) |
||
772 | ite->annotation().setDown(tmTxt); |
||
773 | } |
||
774 | ite->annotation().setType(wtyp); |
||
775 | ite->annotation().setFlag(0); |
||
776 | if (flg & 2) |
||
777 | ite->annotation().setVis(1); |
||
778 | if (flg & 32) |
||
779 | ite->annotation().setVis(3); |
||
780 | if (wtyp == Annotation::Button) |
||
781 | { |
||
24374 | jghali | 782 | ite->setFillColor(m_currColorFill); |
19590 | jghali | 783 | if (achar) |
784 | ite->itemText.insertChars(UnicodeParsedString(achar->getNormalCaption())); |
||
785 | else |
||
786 | ite->itemText.insertChars(itemText); |
||
24374 | jghali | 787 | applyTextStyle(ite, fontName, m_currColorText, fontSize); |
19590 | jghali | 788 | ite->annotation().addToFlag(Annotation::Flag_PushButton); |
789 | FormWidgetButton *btn = (FormWidgetButton*)fm; |
||
790 | if (!btn->isReadOnly()) |
||
791 | ite->annotation().addToFlag(Annotation::Flag_Edit); |
||
792 | handleActions(ite, ano); |
||
793 | } |
||
794 | else if (wtyp == Annotation::Textfield) |
||
795 | { |
||
796 | FormWidgetText *btn = (FormWidgetText*)fm; |
||
797 | if (btn) |
||
798 | { |
||
799 | ite->itemText.insertChars(UnicodeParsedString(btn->getContent())); |
||
24374 | jghali | 800 | applyTextStyle(ite, fontName, m_currColorText, fontSize); |
19590 | jghali | 801 | ite->itemText.trim(); |
802 | if (btn->isMultiline()) |
||
803 | ite->annotation().addToFlag(Annotation::Flag_Multiline); |
||
804 | if (btn->isPassword()) |
||
805 | ite->annotation().addToFlag(Annotation::Flag_Password); |
||
806 | if (btn->noSpellCheck()) |
||
807 | ite->annotation().addToFlag(Annotation::Flag_DoNotSpellCheck); |
||
808 | if (btn->noScroll()) |
||
809 | ite->annotation().addToFlag(Annotation::Flag_DoNotScroll); |
||
810 | int mxLen = btn->getMaxLen(); |
||
811 | if (mxLen > 0) |
||
812 | ite->annotation().setMaxChar(mxLen); |
||
813 | else |
||
814 | ite->annotation().setMaxChar(-1); |
||
815 | if (!btn->isReadOnly()) |
||
816 | ite->annotation().addToFlag(Annotation::Flag_Edit); |
||
817 | handleActions(ite, ano); |
||
818 | } |
||
819 | } |
||
820 | else if (wtyp == Annotation::Checkbox) |
||
821 | { |
||
822 | FormWidgetButton *btn = (FormWidgetButton*)fm; |
||
823 | if (btn) |
||
824 | { |
||
825 | ite->annotation().setIsChk(btn->getState()); |
||
826 | ite->annotation().setCheckState(ite->annotation().IsChk()); |
||
827 | handleActions(ite, ano); |
||
828 | if (itemText == "4") |
||
829 | ite->annotation().setChkStil(0); |
||
830 | else if (itemText == "5") |
||
831 | ite->annotation().setChkStil(1); |
||
832 | else if (itemText == "F") |
||
833 | ite->annotation().setChkStil(2); |
||
834 | else if (itemText == "l") |
||
835 | ite->annotation().setChkStil(3); |
||
836 | else if (itemText == "H") |
||
837 | ite->annotation().setChkStil(4); |
||
838 | else if (itemText == "n") |
||
839 | ite->annotation().setChkStil(5); |
||
840 | else |
||
841 | ite->annotation().setChkStil(0); |
||
842 | if (!btn->isReadOnly()) |
||
843 | ite->annotation().addToFlag(Annotation::Flag_Edit); |
||
844 | } |
||
845 | } |
||
846 | else if ((wtyp == Annotation::Combobox) || (wtyp == Annotation::Listbox)) |
||
847 | { |
||
848 | FormWidgetChoice *btn = (FormWidgetChoice*)fm; |
||
849 | if (btn) |
||
850 | { |
||
851 | if (wtyp == 5) |
||
852 | ite->annotation().addToFlag(Annotation::Flag_Combo); |
||
853 | int co = btn->getNumChoices(); |
||
854 | if (co > 0) |
||
855 | { |
||
856 | QString inh = UnicodeParsedString(btn->getChoice(0)); |
||
857 | for (int a = 1; a < co; a++) |
||
858 | { |
||
859 | inh += "\n" + UnicodeParsedString(btn->getChoice(a)); |
||
860 | } |
||
861 | ite->itemText.insertChars(inh); |
||
862 | } |
||
24374 | jghali | 863 | applyTextStyle(ite, fontName, m_currColorText, fontSize); |
19590 | jghali | 864 | if (!btn->isReadOnly()) |
865 | ite->annotation().addToFlag(Annotation::Flag_Edit); |
||
866 | handleActions(ite, ano); |
||
867 | } |
||
868 | } |
||
869 | else if (wtyp == Annotation::RadioButton) |
||
870 | { |
||
871 | FormWidgetButton *btn = (FormWidgetButton*)fm; |
||
872 | if (btn) |
||
873 | { |
||
874 | ite->setItemName( CommonStrings::itemName_RadioButton + QString("%1").arg(m_doc->TotalItems)); |
||
875 | ite->annotation().setIsChk(btn->getState()); |
||
876 | ite->annotation().setCheckState(ite->annotation().IsChk()); |
||
877 | handleActions(ite, ano); |
||
878 | m_radioButtons.insert(annota->getRef().num, ite); |
||
879 | } |
||
880 | } |
||
881 | } |
||
882 | break; |
||
883 | } |
||
884 | if (!found) |
||
885 | { |
||
886 | Object obj1; |
||
887 | Ref refa = annota->getRef(); |
||
22154 | jghali | 888 | obj1 = xref->fetch(refa.num, refa.gen); |
889 | if (obj1.isDict()) |
||
890 | { |
||
891 | Dict* dict = obj1.getDict(); |
||
892 | Object obj2 = dict->lookup("Kids"); |
||
893 | //childs |
||
894 | if (obj2.isArray()) |
||
895 | { |
||
896 | // Load children |
||
897 | QList<int> radList; |
||
898 | for (int i = 0; i < obj2.arrayGetLength(); i++) |
||
899 | { |
||
22906 | jghali | 900 | POPPLER_CONST_075 Object POPPLER_REF childRef = obj2.arrayGetNF(i); |
22154 | jghali | 901 | if (!childRef.isRef()) |
902 | continue; |
||
903 | Object childObj = obj2.arrayGet(i); |
||
904 | if (!childObj.isDict()) |
||
905 | continue; |
||
906 | const Ref ref = childRef.getRef(); |
||
907 | radList.append(ref.num); |
||
908 | } |
||
909 | QString tmTxt = UnicodeParsedString(annota->getName()); |
||
910 | m_radioMap.insert(tmTxt, radList); |
||
911 | } |
||
912 | } |
||
19590 | jghali | 913 | } |
914 | return retVal; |
||
915 | } |
||
916 | |||
22609 | craig | 917 | void SlaOutputDev::applyTextStyle(PageItem* ite, const QString& fontName, const QString& textColor, double fontSize) |
19590 | jghali | 918 | { |
919 | CharStyle newStyle; |
||
920 | newStyle.setFillColor(textColor); |
||
921 | newStyle.setFontSize(fontSize * 10); |
||
922 | if (!fontName.isEmpty()) |
||
923 | { |
||
924 | SCFontsIterator it(*m_doc->AllFonts); |
||
925 | for ( ; it.hasNext() ; it.next()) |
||
926 | { |
||
927 | ScFace& face(it.current()); |
||
928 | if ((face.psName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF)) |
||
929 | { |
||
930 | newStyle.setFont(face); |
||
931 | break; |
||
932 | } |
||
22609 | craig | 933 | if ((face.family() == fontName) && (face.usable()) && (face.type() == ScFace::TTF)) |
19590 | jghali | 934 | { |
935 | newStyle.setFont(face); |
||
936 | break; |
||
937 | } |
||
22609 | craig | 938 | if ((face.scName() == fontName) && (face.usable()) && (face.type() == ScFace::TTF)) |
19590 | jghali | 939 | { |
940 | newStyle.setFont(face); |
||
941 | break; |
||
942 | } |
||
943 | } |
||
944 | } |
||
945 | ParagraphStyle dstyle(ite->itemText.defaultStyle()); |
||
946 | dstyle.charStyle().applyCharStyle(newStyle); |
||
947 | ite->itemText.setDefaultStyle(dstyle); |
||
948 | ite->itemText.applyCharStyle(0, ite->itemText.length(), newStyle); |
||
949 | ite->invalid = true; |
||
950 | } |
||
951 | |||
952 | void SlaOutputDev::handleActions(PageItem* ite, AnnotWidget *ano) |
||
953 | { |
||
954 | LinkAction *Lact = ano->getAction(); |
||
955 | if (Lact) |
||
956 | { |
||
957 | if (Lact->getKind() == actionJavaScript) |
||
958 | { |
||
959 | LinkJavaScript *jsa = (LinkJavaScript*)Lact; |
||
960 | if (jsa->isOk()) |
||
961 | { |
||
962 | ite->annotation().setActionType(1); |
||
963 | ite->annotation().setAction(UnicodeParsedString(jsa->getScript())); |
||
964 | } |
||
965 | } |
||
966 | else if (Lact->getKind() == actionGoTo) |
||
967 | { |
||
968 | int pagNum = 0; |
||
969 | int xco = 0; |
||
970 | int yco = 0; |
||
971 | LinkGoTo *gto = (LinkGoTo*)Lact; |
||
22513 | jghali | 972 | POPPLER_CONST LinkDest *dst = gto->getDest(); |
19590 | jghali | 973 | if (dst) |
974 | { |
||
975 | if (dst->getKind() == destXYZ) |
||
976 | { |
||
977 | if (dst->isPageRef()) |
||
978 | { |
||
979 | Ref dstr = dst->getPageRef(); |
||
22975 | jghali | 980 | pagNum = pdfDoc->findPage(dstr); |
19590 | jghali | 981 | } |
982 | else |
||
983 | pagNum = dst->getPageNum(); |
||
984 | xco = dst->getLeft(); |
||
985 | yco = dst->getTop(); |
||
21458 | jghali | 986 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 987 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
988 | ite->annotation().setActionType(2); |
||
989 | } |
||
990 | } |
||
991 | else |
||
992 | { |
||
22513 | jghali | 993 | POPPLER_CONST GooString *ndst = gto->getNamedDest(); |
19590 | jghali | 994 | if (ndst) |
995 | { |
||
23478 | jghali | 996 | std::unique_ptr<LinkDest> dstn = pdfDoc->findDest(ndst); |
19590 | jghali | 997 | if (dstn) |
998 | { |
||
999 | if (dstn->getKind() == destXYZ) |
||
1000 | { |
||
1001 | if (dstn->isPageRef()) |
||
1002 | { |
||
1003 | Ref dstr = dstn->getPageRef(); |
||
22975 | jghali | 1004 | pagNum = pdfDoc->findPage(dstr); |
19590 | jghali | 1005 | } |
1006 | else |
||
1007 | pagNum = dstn->getPageNum(); |
||
1008 | xco = dstn->getLeft(); |
||
1009 | yco = dstn->getTop(); |
||
21458 | jghali | 1010 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 1011 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
1012 | ite->annotation().setActionType(2); |
||
1013 | } |
||
1014 | } |
||
1015 | } |
||
1016 | } |
||
1017 | } |
||
1018 | else if (Lact->getKind() == actionGoToR) |
||
1019 | { |
||
1020 | int pagNum = 0; |
||
1021 | int xco = 0; |
||
1022 | int yco = 0; |
||
1023 | LinkGoToR *gto = (LinkGoToR*)Lact; |
||
1024 | QString fileName = UnicodeParsedString(gto->getFileName()); |
||
22513 | jghali | 1025 | POPPLER_CONST LinkDest *dst = gto->getDest(); |
19590 | jghali | 1026 | if (dst) |
1027 | { |
||
1028 | if (dst->getKind() == destXYZ) |
||
1029 | { |
||
1030 | pagNum = dst->getPageNum(); |
||
1031 | xco = dst->getLeft(); |
||
1032 | yco = dst->getTop(); |
||
21458 | jghali | 1033 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 1034 | ite->annotation().setExtern(fileName); |
1035 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
||
1036 | ite->annotation().setActionType(9); |
||
1037 | } |
||
1038 | } |
||
1039 | else |
||
1040 | { |
||
22513 | jghali | 1041 | POPPLER_CONST GooString *ndst = gto->getNamedDest(); |
19590 | jghali | 1042 | if (ndst) |
1043 | { |
||
23478 | jghali | 1044 | std::unique_ptr<LinkDest> dstn = pdfDoc->findDest(ndst); |
19590 | jghali | 1045 | if (dstn) |
1046 | { |
||
1047 | if (dstn->getKind() == destXYZ) |
||
1048 | { |
||
1049 | pagNum = dstn->getPageNum(); |
||
1050 | xco = dstn->getLeft(); |
||
1051 | yco = dstn->getTop(); |
||
21458 | jghali | 1052 | ite->annotation().setZiel((pagNum > 0) ? (pagNum - 1) : (m_actPage - 1)); |
19590 | jghali | 1053 | ite->annotation().setExtern(fileName); |
1054 | ite->annotation().setAction(QString("%1 %2").arg(xco).arg(yco)); |
||
1055 | ite->annotation().setActionType(9); |
||
1056 | } |
||
1057 | } |
||
1058 | } |
||
1059 | } |
||
1060 | } |
||
1061 | else if (Lact->getKind() == actionUnknown) |
||
1062 | { |
||
1063 | LinkUnknown *uno = (LinkUnknown*)Lact; |
||
1064 | QString actString = UnicodeParsedString(uno->getAction()); |
||
1065 | if (actString == "ResetForm") |
||
1066 | { |
||
1067 | ite->annotation().setActionType(4); |
||
1068 | } |
||
1069 | else |
||
1070 | { |
||
1071 | LinkAction* scact = SC_getAction(ano); |
||
1072 | if (scact) |
||
1073 | { |
||
1074 | if (actString == "ImportData") |
||
1075 | { |
||
1076 | LinkImportData *impo = (LinkImportData*)scact; |
||
1077 | if (impo->isOk()) |
||
1078 | { |
||
1079 | ite->annotation().setActionType(5); |
||
1080 | ite->annotation().setAction(UnicodeParsedString(impo->getFileName())); |
||
1081 | } |
||
1082 | } |
||
1083 | else if (actString == "SubmitForm") |
||
1084 | { |
||
1085 | LinkSubmitForm *impo = (LinkSubmitForm*)scact; |
||
1086 | if (impo->isOk()) |
||
1087 | { |
||
1088 | ite->annotation().setActionType(3); |
||
1089 | ite->annotation().setAction(UnicodeParsedString(impo->getFileName())); |
||
1090 | int fl = impo->getFlags(); |
||
1091 | if (fl == 0) |
||
1092 | ite->annotation().setHTML(0); |
||
1093 | else if (fl == 4) |
||
1094 | ite->annotation().setHTML(1); |
||
1095 | else if (fl == 64) |
||
1096 | ite->annotation().setHTML(2); |
||
1097 | else if (fl == 512) |
||
1098 | ite->annotation().setHTML(3); |
||
1099 | } |
||
1100 | } |
||
1101 | } |
||
1102 | } |
||
1103 | } |
||
1104 | else if (Lact->getKind() == actionNamed) |
||
1105 | { |
||
1106 | LinkNamed *uno = (LinkNamed*)Lact; |
||
1107 | ite->annotation().setActionType(10); |
||
1108 | ite->annotation().setAction(UnicodeParsedString(uno->getName())); |
||
1109 | } |
||
1110 | else |
||
1111 | qDebug() << "Found unsupported Action of type" << Lact->getKind(); |
||
1112 | } |
||
23478 | jghali | 1113 | auto Aact = SC_getAdditionalAction("D", ano); |
19590 | jghali | 1114 | if (Aact) |
1115 | { |
||
1116 | if (Aact->getKind() == actionJavaScript) |
||
1117 | { |
||
23478 | jghali | 1118 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1119 | if (jsa->isOk()) |
1120 | { |
||
1121 | ite->annotation().setD_act(UnicodeParsedString(jsa->getScript())); |
||
1122 | ite->annotation().setAAact(true); |
||
1123 | } |
||
1124 | } |
||
23478 | jghali | 1125 | Aact.reset(); |
19590 | jghali | 1126 | } |
1127 | Aact = SC_getAdditionalAction("E", ano); |
||
1128 | if (Aact) |
||
1129 | { |
||
1130 | if (Aact->getKind() == actionJavaScript) |
||
1131 | { |
||
23478 | jghali | 1132 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1133 | if (jsa->isOk()) |
1134 | { |
||
1135 | ite->annotation().setE_act(UnicodeParsedString(jsa->getScript())); |
||
1136 | ite->annotation().setAAact(true); |
||
1137 | } |
||
1138 | } |
||
23478 | jghali | 1139 | Aact.reset(); |
19590 | jghali | 1140 | } |
1141 | Aact = SC_getAdditionalAction("X", ano); |
||
1142 | if (Aact) |
||
1143 | { |
||
1144 | if (Aact->getKind() == actionJavaScript) |
||
1145 | { |
||
23478 | jghali | 1146 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1147 | if (jsa->isOk()) |
1148 | { |
||
1149 | ite->annotation().setX_act(UnicodeParsedString(jsa->getScript())); |
||
1150 | ite->annotation().setAAact(true); |
||
1151 | } |
||
1152 | } |
||
23478 | jghali | 1153 | Aact.reset(); |
19590 | jghali | 1154 | } |
1155 | Aact = SC_getAdditionalAction("Fo", ano); |
||
1156 | if (Aact) |
||
1157 | { |
||
1158 | if (Aact->getKind() == actionJavaScript) |
||
1159 | { |
||
23478 | jghali | 1160 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1161 | if (jsa->isOk()) |
1162 | { |
||
1163 | ite->annotation().setFo_act(UnicodeParsedString(jsa->getScript())); |
||
1164 | ite->annotation().setAAact(true); |
||
1165 | } |
||
1166 | } |
||
23478 | jghali | 1167 | Aact.reset(); |
19590 | jghali | 1168 | } |
1169 | Aact = SC_getAdditionalAction("Bl", ano); |
||
1170 | if (Aact) |
||
1171 | { |
||
1172 | if (Aact->getKind() == actionJavaScript) |
||
1173 | { |
||
23478 | jghali | 1174 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1175 | if (jsa->isOk()) |
1176 | { |
||
1177 | ite->annotation().setBl_act(UnicodeParsedString(jsa->getScript())); |
||
1178 | ite->annotation().setAAact(true); |
||
1179 | } |
||
1180 | } |
||
23478 | jghali | 1181 | Aact.reset(); |
19590 | jghali | 1182 | } |
1183 | Aact = SC_getAdditionalAction("C", ano); |
||
1184 | if (Aact) |
||
1185 | { |
||
1186 | if (Aact->getKind() == actionJavaScript) |
||
1187 | { |
||
23478 | jghali | 1188 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1189 | if (jsa->isOk()) |
1190 | { |
||
1191 | ite->annotation().setC_act(UnicodeParsedString(jsa->getScript())); |
||
1192 | ite->annotation().setAAact(true); |
||
1193 | } |
||
1194 | } |
||
23478 | jghali | 1195 | Aact.reset(); |
19590 | jghali | 1196 | } |
1197 | Aact = SC_getAdditionalAction("F", ano); |
||
1198 | if (Aact) |
||
1199 | { |
||
1200 | if (Aact->getKind() == actionJavaScript) |
||
1201 | { |
||
23478 | jghali | 1202 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1203 | if (jsa->isOk()) |
1204 | { |
||
1205 | ite->annotation().setF_act(UnicodeParsedString(jsa->getScript())); |
||
1206 | ite->annotation().setAAact(true); |
||
1207 | ite->annotation().setFormat(5); |
||
1208 | } |
||
1209 | } |
||
23478 | jghali | 1210 | Aact.reset(); |
19590 | jghali | 1211 | } |
1212 | Aact = SC_getAdditionalAction("K", ano); |
||
1213 | if (Aact) |
||
1214 | { |
||
1215 | if (Aact->getKind() == actionJavaScript) |
||
1216 | { |
||
23478 | jghali | 1217 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1218 | if (jsa->isOk()) |
1219 | { |
||
1220 | ite->annotation().setK_act(UnicodeParsedString(jsa->getScript())); |
||
1221 | ite->annotation().setAAact(true); |
||
1222 | ite->annotation().setFormat(5); |
||
1223 | } |
||
1224 | } |
||
23478 | jghali | 1225 | Aact.reset(); |
19590 | jghali | 1226 | } |
1227 | Aact = SC_getAdditionalAction("V", ano); |
||
1228 | if (Aact) |
||
1229 | { |
||
1230 | if (Aact->getKind() == actionJavaScript) |
||
1231 | { |
||
23478 | jghali | 1232 | LinkJavaScript *jsa = (LinkJavaScript*) Aact.get(); |
19590 | jghali | 1233 | if (jsa->isOk()) |
1234 | { |
||
1235 | ite->annotation().setV_act(UnicodeParsedString(jsa->getScript())); |
||
1236 | ite->annotation().setAAact(true); |
||
1237 | } |
||
1238 | } |
||
23478 | jghali | 1239 | Aact.reset(); |
19590 | jghali | 1240 | } |
1241 | } |
||
1242 | |||
1243 | void SlaOutputDev::startDoc(PDFDoc *doc, XRef *xrefA, Catalog *catA) |
||
1244 | { |
||
1245 | xref = xrefA; |
||
1246 | catalog = catA; |
||
1247 | pdfDoc = doc; |
||
1248 | updateGUICounter = 0; |
||
23431 | jghali | 1249 | m_fontEngine = new SplashFontEngine(true, false, false, true); |
19590 | jghali | 1250 | } |
1251 | |||
19595 | jghali | 1252 | void SlaOutputDev::startPage(int pageNum, GfxState *, XRef *) |
19590 | jghali | 1253 | { |
1254 | m_formWidgets = pdfDoc->getPage(pageNum)->getFormWidgets(); |
||
1255 | m_radioMap.clear(); |
||
1256 | m_radioButtons.clear(); |
||
1257 | m_actPage = pageNum; |
||
20011 | fschmid | 1258 | m_groupStack.clear(); |
1259 | pushGroup(); |
||
23536 | jghali | 1260 | m_currentClipPath = QPainterPath(); |
20011 | fschmid | 1261 | m_clipPaths.clear(); |
19590 | jghali | 1262 | } |
1263 | |||
1264 | void SlaOutputDev::endPage() |
||
1265 | { |
||
1266 | if (!m_radioMap.isEmpty()) |
||
1267 | { |
||
22509 | jghali | 1268 | for (auto it = m_radioMap.begin(); it != m_radioMap.end(); ++it) |
19590 | jghali | 1269 | { |
1270 | tmpSel->clear(); |
||
1271 | QList<int> refList = it.value(); |
||
1272 | for (int a = 0; a < refList.count(); a++) |
||
1273 | { |
||
1274 | if (m_radioButtons.contains(refList[a])) |
||
1275 | { |
||
1276 | tmpSel->addItem(m_radioButtons[refList[a]], true); |
||
1277 | m_Elements->removeAll(m_radioButtons[refList[a]]); |
||
1278 | } |
||
1279 | } |
||
1280 | if (!tmpSel->isEmpty()) |
||
1281 | { |
||
1282 | PageItem *ite = m_doc->groupObjectsSelection(tmpSel); |
||
1283 | ite->setItemName(it.key()); |
||
1284 | m_Elements->append(ite); |
||
1285 | if (m_groupStack.count() != 0) |
||
1286 | m_groupStack.top().Items.append(ite); |
||
1287 | } |
||
1288 | } |
||
1289 | } |
||
1290 | m_radioMap.clear(); |
||
1291 | m_radioButtons.clear(); |
||
1292 | // qDebug() << "ending page"; |
||
1293 | } |
||
1294 | |||
1295 | void SlaOutputDev::saveState(GfxState *state) |
||
1296 | { |
||
20011 | fschmid | 1297 | m_clipPaths.push(m_currentClipPath); |
1298 | pushGroup(); |
||
19590 | jghali | 1299 | } |
1300 | |||
1301 | void SlaOutputDev::restoreState(GfxState *state) |
||
1302 | { |
||
1303 | if (m_groupStack.count() != 0) |
||
1304 | { |
||
20011 | fschmid | 1305 | groupEntry gElements = m_groupStack.pop(); |
1306 | if (gElements.Items.count() > 0) |
||
19590 | jghali | 1307 | { |
20625 | fschmid | 1308 | if ((gElements.Items.count() > 1) && (checkClip())) |
19590 | jghali | 1309 | { |
20011 | fschmid | 1310 | tmpSel->clear(); |
1311 | for (int dre = 0; dre < gElements.Items.count(); ++dre) |
||
19590 | jghali | 1312 | { |
20011 | fschmid | 1313 | tmpSel->addItem(gElements.Items.at(dre), true); |
1314 | m_Elements->removeAll(gElements.Items.at(dre)); |
||
19590 | jghali | 1315 | } |
20011 | fschmid | 1316 | PageItem *ite = m_doc->groupObjectsSelection(tmpSel); |
20625 | fschmid | 1317 | if (ite) |
19590 | jghali | 1318 | { |
23536 | jghali | 1319 | QPainterPath clippath = m_currentClipPath; |
1320 | clippath.translate(m_doc->currentPage()->xOffset(), m_doc->currentPage()->yOffset()); |
||
1321 | clippath.translate(-ite->xPos(), -ite->yPos()); |
||
1322 | ite->PoLine.fromQPainterPath(clippath, true); |
||
23319 | jghali | 1323 | ite->ClipEdited = true; |
1324 | ite->FrameType = 3; |
||
20625 | fschmid | 1325 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
23319 | jghali | 1326 | // Comment out temporarily, there are some bad interactions between adjustItemSize() and |
1327 | // resizeGroupToContents() since fixing resizing of multiple selections |
||
1328 | //m_doc->adjustItemSize(ite, true); |
||
20625 | fschmid | 1329 | m_doc->resizeGroupToContents(ite); |
1330 | ite->OldB2 = ite->width(); |
||
1331 | ite->OldH2 = ite->height(); |
||
1332 | m_Elements->append(ite); |
||
1333 | if (m_groupStack.count() != 0) |
||
1334 | { |
||
1335 | applyMask(ite); |
||
1336 | m_groupStack.top().Items.append(ite); |
||
1337 | } |
||
19590 | jghali | 1338 | } |
20628 | fschmid | 1339 | else |
1340 | { |
||
1341 | if (m_groupStack.count() != 0) |
||
1342 | { |
||
1343 | for (int dre = 0; dre < gElements.Items.count(); ++dre) |
||
1344 | { |
||
1345 | PageItem *ite = gElements.Items.at(dre); |
||
1346 | applyMask(ite); |
||
1347 | m_groupStack.top().Items.append(ite); |
||
1348 | } |
||
1349 | } |
||
1350 | } |
||
20011 | fschmid | 1351 | tmpSel->clear(); |
19590 | jghali | 1352 | } |
20011 | fschmid | 1353 | else |
1354 | { |
||
1355 | if (m_groupStack.count() != 0) |
||
1356 | { |
||
1357 | for (int dre = 0; dre < gElements.Items.count(); ++dre) |
||
1358 | { |
||
1359 | PageItem *ite = gElements.Items.at(dre); |
||
1360 | applyMask(ite); |
||
1361 | m_groupStack.top().Items.append(ite); |
||
1362 | } |
||
1363 | } |
||
1364 | } |
||
19590 | jghali | 1365 | } |
1366 | } |
||
20011 | fschmid | 1367 | if (m_clipPaths.count() != 0) |
1368 | m_currentClipPath = m_clipPaths.pop(); |
||
19590 | jghali | 1369 | } |
20011 | fschmid | 1370 | |
22916 | jghali | 1371 | void SlaOutputDev::beginTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool isolated, GBool knockout, GBool forSoftMask) |
19590 | jghali | 1372 | { |
23550 | jghali | 1373 | // qDebug() << "SlaOutputDev::beginTransparencyGroup isolated:" << isolated << "knockout:" << knockout << "forSoftMask:" << forSoftMask; |
20011 | fschmid | 1374 | pushGroup("", forSoftMask); |
20125 | fschmid | 1375 | m_groupStack.top().isolated = isolated; |
19590 | jghali | 1376 | } |
20011 | fschmid | 1377 | |
22916 | jghali | 1378 | void SlaOutputDev::paintTransparencyGroup(GfxState *state, POPPLER_CONST_070 double *bbox) |
19590 | jghali | 1379 | { |
23550 | jghali | 1380 | // qDebug() << "SlaOutputDev::paintTransparencyGroup"; |
20011 | fschmid | 1381 | if (m_groupStack.count() != 0) |
1382 | { |
||
1383 | if ((m_groupStack.top().Items.count() != 0) && (!m_groupStack.top().forSoftMask)) |
||
1384 | { |
||
1385 | PageItem *ite = m_groupStack.top().Items.last(); |
||
1386 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1387 | ite->setFillBlendmode(getBlendMode(state)); |
||
1388 | } |
||
1389 | } |
||
19590 | jghali | 1390 | } |
1391 | |||
1392 | void SlaOutputDev::endTransparencyGroup(GfxState *state) |
||
1393 | { |
||
23550 | jghali | 1394 | // qDebug() << "SlaOutputDev::endTransparencyGroup"; |
22991 | jghali | 1395 | if (m_groupStack.count() <= 0) |
1396 | return; |
||
1397 | |||
1398 | tmpSel->clear(); |
||
1399 | |||
1400 | groupEntry gElements = m_groupStack.pop(); |
||
1401 | if (gElements.Items.count() <= 0) |
||
1402 | return; |
||
1403 | |||
1404 | if (gElements.forSoftMask) |
||
19590 | jghali | 1405 | { |
22991 | jghali | 1406 | for (int dre = 0; dre < gElements.Items.count(); ++dre) |
19590 | jghali | 1407 | { |
22991 | jghali | 1408 | tmpSel->addItem(gElements.Items.at(dre), true); |
1409 | m_Elements->removeAll(gElements.Items.at(dre)); |
||
19590 | jghali | 1410 | } |
22991 | jghali | 1411 | PageItem *ite = m_doc->groupObjectsSelection(tmpSel); |
1412 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1413 | ite->setFillBlendmode(getBlendMode(state)); |
||
24744 | jghali | 1414 | ScPattern pat(m_doc); |
22991 | jghali | 1415 | m_doc->DoDrawing = true; |
1416 | pat.pattern = ite->DrawObj_toImage(qMin(qMax(ite->width(), ite->height()), 500.0)); |
||
1417 | pat.xoffset = 0; |
||
1418 | pat.yoffset = 0; |
||
1419 | m_doc->DoDrawing = false; |
||
1420 | pat.width = ite->width(); |
||
1421 | pat.height = ite->height(); |
||
23550 | jghali | 1422 | m_currentMaskPosition = QPointF(ite->xPos(), ite->yPos()); |
22991 | jghali | 1423 | ite->gXpos = 0; |
1424 | ite->gYpos = 0; |
||
1425 | ite->setXYPos(ite->gXpos, ite->gYpos, true); |
||
1426 | pat.items.append(ite); |
||
1427 | m_doc->Items->removeAll(ite); |
||
1428 | QString id = QString("Pattern_from_PDF_%1S").arg(m_doc->docPatterns.count() + 1); |
||
1429 | m_doc->addPattern(id, pat); |
||
1430 | m_currentMask = id; |
||
19590 | jghali | 1431 | tmpSel->clear(); |
22991 | jghali | 1432 | return; |
19590 | jghali | 1433 | } |
22991 | jghali | 1434 | PageItem *ite; |
1435 | for (int dre = 0; dre < gElements.Items.count(); ++dre) |
||
1436 | { |
||
1437 | tmpSel->addItem(gElements.Items.at(dre), true); |
||
1438 | m_Elements->removeAll(gElements.Items.at(dre)); |
||
1439 | } |
||
1440 | if ((gElements.Items.count() != 1) || (gElements.isolated)) |
||
1441 | ite = m_doc->groupObjectsSelection(tmpSel); |
||
1442 | else |
||
1443 | ite = gElements.Items.first(); |
||
1444 | if (ite->isGroup()) |
||
1445 | { |
||
1446 | ite->ClipEdited = true; |
||
1447 | ite->FrameType = 3; |
||
1448 | if (checkClip()) |
||
1449 | { |
||
23536 | jghali | 1450 | QPainterPath clippath = m_currentClipPath; |
1451 | clippath.translate(m_doc->currentPage()->xOffset(), m_doc->currentPage()->yOffset()); |
||
1452 | clippath.translate(-ite->xPos(), -ite->yPos()); |
||
1453 | ite->PoLine.fromQPainterPath(clippath, true); |
||
23319 | jghali | 1454 | ite->ClipEdited = true; |
1455 | ite->FrameType = 3; |
||
22991 | jghali | 1456 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
23319 | jghali | 1457 | // Comment out temporarily, there are some bad interactions between adjustItemSize() and |
1458 | // resizeGroupToContents() since fixing resizing of multiple selections |
||
1459 | //m_doc->adjustItemSize(ite, true); |
||
22991 | jghali | 1460 | m_doc->resizeGroupToContents(ite); |
1461 | ite->OldB2 = ite->width(); |
||
1462 | ite->OldH2 = ite->height(); |
||
1463 | } |
||
1464 | } |
||
1465 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1466 | ite->setFillBlendmode(getBlendMode(state)); |
||
1467 | m_Elements->append(ite); |
||
1468 | if (m_groupStack.count() != 0) |
||
1469 | { |
||
1470 | applyMask(ite); |
||
1471 | m_groupStack.top().Items.append(ite); |
||
1472 | } |
||
1473 | |||
1474 | tmpSel->clear(); |
||
19590 | jghali | 1475 | } |
1476 | |||
23525 | jghali | 1477 | void SlaOutputDev::setSoftMask(GfxState * /*state*/, POPPLER_CONST_070 double * bbox, GBool alpha, Function *transferFunc, GfxColor * /*backdropColor*/) |
19590 | jghali | 1478 | { |
22991 | jghali | 1479 | if (m_groupStack.count() <= 0) |
1480 | return; |
||
1481 | |||
1482 | double lum = 0; |
||
1483 | double lum2 = 0; |
||
1484 | if (transferFunc) |
||
1485 | transferFunc->transform(&lum, &lum2); |
||
1486 | else |
||
1487 | lum2 = lum; |
||
24257 | jghali | 1488 | m_groupStack.top().inverted = (lum != lum2); |
22991 | jghali | 1489 | m_groupStack.top().maskName = m_currentMask; |
23550 | jghali | 1490 | // Remember the mask's position as it might not align with the image to which the mask is later assigned. |
1491 | m_groupStack.top().maskPos = m_currentMaskPosition; |
||
22991 | jghali | 1492 | m_groupStack.top().alpha = alpha; |
1493 | if (m_groupStack.top().Items.count() != 0) |
||
1494 | applyMask(m_groupStack.top().Items.last()); |
||
19590 | jghali | 1495 | } |
1496 | |||
1497 | void SlaOutputDev::clearSoftMask(GfxState * /*state*/) |
||
1498 | { |
||
1499 | if (m_groupStack.count() != 0) |
||
1500 | m_groupStack.top().maskName = ""; |
||
1501 | } |
||
1502 | |||
1503 | void SlaOutputDev::updateFillColor(GfxState *state) |
||
1504 | { |
||
24374 | jghali | 1505 | m_currFillShade = 100; |
1506 | m_currColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &m_currFillShade); |
||
19590 | jghali | 1507 | } |
1508 | |||
1509 | void SlaOutputDev::updateStrokeColor(GfxState *state) |
||
1510 | { |
||
24374 | jghali | 1511 | m_currStrokeShade = 100; |
1512 | m_currColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &m_currStrokeShade); |
||
19590 | jghali | 1513 | } |
1514 | |||
1515 | void SlaOutputDev::clip(GfxState *state) |
||
1516 | { |
||
1517 | // qDebug() << "Clip"; |
||
23536 | jghali | 1518 | adjustClip(state, Qt::WindingFill); |
1519 | } |
||
1520 | |||
1521 | void SlaOutputDev::eoClip(GfxState *state) |
||
1522 | { |
||
1523 | // qDebug() << "EoClip"; |
||
1524 | adjustClip(state, Qt::OddEvenFill); |
||
1525 | } |
||
1526 | |||
1527 | void SlaOutputDev::adjustClip(GfxState *state, Qt::FillRule fillRule) |
||
1528 | { |
||
1529 | const double *ctm = state->getCTM(); |
||
19590 | jghali | 1530 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
1531 | QString output = convertPath(state->getPath()); |
||
22991 | jghali | 1532 | if (output.isEmpty()) |
1533 | return; |
||
19590 | jghali | 1534 | FPointArray out; |
22991 | jghali | 1535 | out.parseSVG(output); |
1536 | out.svgClosePath(); |
||
1537 | out.map(m_ctm); |
||
1538 | if (checkClip()) |
||
19590 | jghali | 1539 | { |
23536 | jghali | 1540 | // "clip" (WindingFill) and "eoClip" (OddEvenFill) only the determine |
1541 | // the fill rule of the new clipping path. The new clip should be the |
||
1542 | // intersection of the old and new area. QPainterPath determines on |
||
1543 | // its own which fill rule to use for the result. We should not loose |
||
1544 | // this information. |
||
1545 | QPainterPath pathN = out.toQPainterPath(false); |
||
1546 | pathN.setFillRule(fillRule); |
||
23550 | jghali | 1547 | m_currentClipPath = intersection(pathN, m_currentClipPath); |
19590 | jghali | 1548 | } |
22991 | jghali | 1549 | else |
23536 | jghali | 1550 | m_currentClipPath = out.toQPainterPath(false); |
19590 | jghali | 1551 | } |
1552 | |||
1553 | void SlaOutputDev::stroke(GfxState *state) |
||
1554 | { |
||
1555 | // qDebug() << "Stroke"; |
||
22741 | jghali | 1556 | const double *ctm; |
19590 | jghali | 1557 | ctm = state->getCTM(); |
1558 | double xCoor = m_doc->currentPage()->xOffset(); |
||
1559 | double yCoor = m_doc->currentPage()->yOffset(); |
||
1560 | QString output = convertPath(state->getPath()); |
||
1561 | getPenState(state); |
||
1562 | if ((m_Elements->count() != 0) && (output == Coords)) // Path is the same as in last fill |
||
1563 | { |
||
1564 | PageItem* ite = m_Elements->last(); |
||
24374 | jghali | 1565 | ite->setLineColor(m_currColorStroke); |
1566 | ite->setLineShade(m_currStrokeShade); |
||
1567 | ite->setLineEnd(m_lineEnd); |
||
1568 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1569 | ite->setLineWidth(state->getTransformedLineWidth()); |
1570 | ite->setDashes(DashValues); |
||
1571 | ite->setDashOffset(DashOffset); |
||
1572 | ite->setLineTransparency(1.0 - state->getStrokeOpacity()); |
||
1573 | } |
||
1574 | else |
||
1575 | { |
||
1576 | FPointArray out; |
||
1577 | out.parseSVG(output); |
||
1578 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
||
1579 | out.map(m_ctm); |
||
23038 | jghali | 1580 | FPoint wh = out.widthHeight(); |
19590 | jghali | 1581 | if ((out.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0))) |
1582 | { |
||
24374 | jghali | 1583 | m_currColorStroke = getColor(state->getStrokeColorSpace(), state->getStrokeColor(), &m_currStrokeShade); |
19590 | jghali | 1584 | int z; |
1585 | if (pathIsClosed) |
||
24374 | jghali | 1586 | z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, m_currColorStroke); |
19590 | jghali | 1587 | else |
24374 | jghali | 1588 | z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, state->getTransformedLineWidth(), CommonStrings::None, m_currColorStroke); |
19590 | jghali | 1589 | PageItem* ite = m_doc->Items->at(z); |
1590 | ite->PoLine = out.copy(); |
||
1591 | ite->ClipEdited = true; |
||
1592 | ite->FrameType = 3; |
||
23289 | jghali | 1593 | ite->setWidthHeight(wh.x(), wh.y()); |
20694 | craig | 1594 | m_doc->adjustItemSize(ite); |
19590 | jghali | 1595 | if (m_Elements->count() != 0) |
1596 | { |
||
1597 | PageItem* lItem = m_Elements->last(); |
||
1598 | if ((lItem->lineColor() == CommonStrings::None) && (lItem->PoLine == ite->PoLine)) |
||
1599 | { |
||
24374 | jghali | 1600 | lItem->setLineColor(m_currColorStroke); |
19590 | jghali | 1601 | lItem->setLineWidth(state->getTransformedLineWidth()); |
24374 | jghali | 1602 | lItem->setLineShade(m_currStrokeShade); |
19590 | jghali | 1603 | lItem->setLineTransparency(1.0 - state->getStrokeOpacity()); |
1604 | lItem->setLineBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1605 | lItem->setLineEnd(m_lineEnd); |
1606 | lItem->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1607 | lItem->setDashes(DashValues); |
1608 | lItem->setDashOffset(DashOffset); |
||
1609 | lItem->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1610 | m_doc->Items->removeAll(ite); |
||
1611 | } |
||
1612 | else |
||
1613 | { |
||
24374 | jghali | 1614 | ite->setLineShade(m_currStrokeShade); |
19590 | jghali | 1615 | ite->setLineTransparency(1.0 - state->getStrokeOpacity()); |
1616 | ite->setLineBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1617 | ite->setLineEnd(m_lineEnd); |
1618 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1619 | ite->setDashes(DashValues); |
1620 | ite->setDashOffset(DashOffset); |
||
1621 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1622 | m_Elements->append(ite); |
||
1623 | if (m_groupStack.count() != 0) |
||
1624 | m_groupStack.top().Items.append(ite); |
||
1625 | } |
||
1626 | } |
||
1627 | else |
||
1628 | { |
||
24374 | jghali | 1629 | ite->setLineShade(m_currStrokeShade); |
19590 | jghali | 1630 | ite->setLineTransparency(1.0 - state->getStrokeOpacity()); |
1631 | ite->setLineBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1632 | ite->setLineEnd(m_lineEnd); |
1633 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1634 | ite->setDashes(DashValues); |
1635 | ite->setDashOffset(DashOffset); |
||
1636 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
||
1637 | m_Elements->append(ite); |
||
1638 | if (m_groupStack.count() != 0) |
||
1639 | m_groupStack.top().Items.append(ite); |
||
1640 | } |
||
1641 | } |
||
1642 | } |
||
1643 | } |
||
1644 | |||
1645 | void SlaOutputDev::fill(GfxState *state) |
||
1646 | { |
||
1647 | // qDebug() << "Fill"; |
||
23536 | jghali | 1648 | createFillItem(state, Qt::WindingFill); |
19590 | jghali | 1649 | } |
1650 | |||
1651 | void SlaOutputDev::eoFill(GfxState *state) |
||
1652 | { |
||
1653 | // qDebug() << "EoFill"; |
||
23536 | jghali | 1654 | createFillItem(state, Qt::OddEvenFill); |
1655 | } |
||
1656 | |||
1657 | void SlaOutputDev::createFillItem(GfxState *state, Qt::FillRule fillRule) |
||
1658 | { |
||
22741 | jghali | 1659 | const double *ctm; |
19590 | jghali | 1660 | ctm = state->getCTM(); |
23550 | jghali | 1661 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
19590 | jghali | 1662 | double xCoor = m_doc->currentPage()->xOffset(); |
1663 | double yCoor = m_doc->currentPage()->yOffset(); |
||
1664 | FPointArray out; |
||
1665 | QString output = convertPath(state->getPath()); |
||
1666 | out.parseSVG(output); |
||
1667 | out.map(m_ctm); |
||
23536 | jghali | 1668 | |
1669 | // Clip the new path first and only add it if it is not empty. |
||
1670 | QPainterPath path = out.toQPainterPath(false); |
||
1671 | path.setFillRule(fillRule); |
||
23550 | jghali | 1672 | QPainterPath clippedPath = intersection(m_currentClipPath, path); |
23536 | jghali | 1673 | |
23550 | jghali | 1674 | // Undo the rotation of the clipping path as it is rotated together with the item. |
1675 | double angle = m_ctm.map(QLineF(0, 0, 1, 0)).angle(); |
||
1676 | QTransform mm; |
||
1677 | mm.rotate(angle); |
||
1678 | clippedPath = mm.map(clippedPath); |
||
1679 | |||
19590 | jghali | 1680 | Coords = output; |
23536 | jghali | 1681 | QRectF bbox = clippedPath.boundingRect(); |
1682 | if (!clippedPath.isEmpty() && !bbox.isNull()) |
||
19590 | jghali | 1683 | { |
24374 | jghali | 1684 | m_currColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &m_currFillShade); |
19590 | jghali | 1685 | int z; |
1686 | if (pathIsClosed) |
||
24374 | jghali | 1687 | z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 1688 | else |
24374 | jghali | 1689 | z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 1690 | PageItem* ite = m_doc->Items->at(z); |
23536 | jghali | 1691 | ite->PoLine.fromQPainterPath(clippedPath, true); |
19590 | jghali | 1692 | ite->ClipEdited = true; |
1693 | ite->FrameType = 3; |
||
24374 | jghali | 1694 | ite->setFillShade(m_currFillShade); |
19590 | jghali | 1695 | ite->setLineShade(100); |
23550 | jghali | 1696 | ite->setRotation(-angle); |
23536 | jghali | 1697 | // Only the new path has to be interpreted according to fillRule. QPainterPath |
1698 | // could decide to create a final path according to the other rule. Thus |
||
1699 | // we have to set this from the final path. |
||
1700 | ite->setFillEvenOdd(clippedPath.fillRule() == Qt::OddEvenFill); |
||
19590 | jghali | 1701 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
1702 | ite->setFillBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1703 | ite->setLineEnd(m_lineEnd); |
1704 | ite->setLineJoin(m_lineJoin); |
||
23536 | jghali | 1705 | ite->setWidthHeight(bbox.width(),bbox.height()); |
19590 | jghali | 1706 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
20694 | craig | 1707 | m_doc->adjustItemSize(ite); |
19590 | jghali | 1708 | m_Elements->append(ite); |
1709 | if (m_groupStack.count() != 0) |
||
1710 | { |
||
1711 | m_groupStack.top().Items.append(ite); |
||
1712 | applyMask(ite); |
||
1713 | } |
||
1714 | } |
||
1715 | } |
||
1716 | |||
1717 | GBool SlaOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) |
||
1718 | { |
||
23536 | jghali | 1719 | // qDebug() << "SlaOutputDev::axialShadedFill"; |
19590 | jghali | 1720 | double GrStartX; |
1721 | double GrStartY; |
||
1722 | double GrEndX; |
||
1723 | double GrEndY; |
||
1724 | int shade = 100; |
||
22741 | jghali | 1725 | POPPLER_CONST_070 Function *func = shading->getFunc(0); |
19590 | jghali | 1726 | VGradient FillGradient = VGradient(VGradient::linear); |
1727 | FillGradient.clearStops(); |
||
1728 | GfxColorSpace *color_space = shading->getColorSpace(); |
||
1729 | if (func->getType() == 3) |
||
1730 | { |
||
1731 | StitchingFunction *stitchingFunc = (StitchingFunction*)func; |
||
22741 | jghali | 1732 | const double *bounds = stitchingFunc->getBounds(); |
19590 | jghali | 1733 | int num_funcs = stitchingFunc->getNumFuncs(); |
22978 | jghali | 1734 | double domain_min = stitchingFunc->getDomainMin(0); |
1735 | double domain_max = stitchingFunc->getDomainMax(0); |
||
1736 | if (fabs(domain_max - domain_min) < 1e-6) |
||
1737 | { |
||
1738 | domain_min = 0.0; |
||
1739 | domain_max = 1.0; |
||
1740 | } |
||
19590 | jghali | 1741 | // Add stops from all the stitched functions |
22978 | jghali | 1742 | for (int i = 0 ; i <= num_funcs ; i++) |
19590 | jghali | 1743 | { |
1744 | GfxColor temp; |
||
22978 | jghali | 1745 | shading->getColor(bounds[i], &temp); |
19590 | jghali | 1746 | QString stopColor = getColor(color_space, &temp, &shade); |
22978 | jghali | 1747 | double stopPoint = (bounds[i] - domain_min) / (domain_max - domain_min); |
1748 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), stopPoint, 0.5, 1.0, stopColor, shade ); |
||
19590 | jghali | 1749 | } |
1750 | } |
||
1751 | else if ((func->getType() == 2) || (func->getType() == 0)) |
||
1752 | { |
||
1753 | GfxColor stop1; |
||
22978 | jghali | 1754 | shading->getColor(0.0, &stop1); |
19590 | jghali | 1755 | QString stopColor1 = getColor(color_space, &stop1, &shade); |
1756 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade ); |
||
1757 | GfxColor stop2; |
||
22978 | jghali | 1758 | shading->getColor(1.0, &stop2); |
19590 | jghali | 1759 | QString stopColor2 = getColor(color_space, &stop2, &shade); |
1760 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade ); |
||
1761 | } |
||
22978 | jghali | 1762 | shading->getCoords(&GrStartX, &GrStartY, &GrEndX, &GrEndY); |
19590 | jghali | 1763 | double xmin, ymin, xmax, ymax; |
1764 | // get the clip region bbox |
||
1765 | state->getClipBBox(&xmin, &ymin, &xmax, &ymax); |
||
1766 | QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)); |
||
1767 | crect = crect.normalized(); |
||
23588 | jghali | 1768 | QPainterPath out; |
1769 | out.addRect(crect); |
||
1770 | if (checkClip()) |
||
1771 | { |
||
1772 | // Apply the clip path early to adjust the gradient vector to the |
||
1773 | // smaller boundign box. |
||
1774 | out = intersection(m_currentClipPath, out); |
||
1775 | crect = out.boundingRect(); |
||
1776 | } |
||
22741 | jghali | 1777 | const double *ctm = state->getCTM(); |
19590 | jghali | 1778 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
1779 | FPointArray gr; |
||
1780 | gr.addPoint(GrStartX, GrStartY); |
||
1781 | gr.addPoint(GrEndX, GrEndY); |
||
1782 | gr.map(m_ctm); |
||
23588 | jghali | 1783 | gr.translate(-crect.x(), -crect.y()); |
1784 | |||
1785 | // Undo the rotation and translation of the gradient vector. |
||
1786 | double angle = m_ctm.map(QLineF(0, 0, 1, 0)).angle(); |
||
1787 | QTransform mm; |
||
1788 | mm.rotate(angle); |
||
1789 | out.translate(-crect.x(), -crect.y()); |
||
1790 | out = mm.map(out); |
||
1791 | QRectF bb = out.boundingRect(); |
||
1792 | gr.map(mm); |
||
1793 | gr.translate(-bb.left(), -bb.top()); |
||
1794 | GrStartX = gr.point(0).x(); |
||
1795 | GrStartY = gr.point(0).y(); |
||
1796 | GrEndX = gr.point(1).x(); |
||
1797 | GrEndY = gr.point(1).y(); |
||
1798 | |||
19590 | jghali | 1799 | double xCoor = m_doc->currentPage()->xOffset(); |
1800 | double yCoor = m_doc->currentPage()->yOffset(); |
||
1801 | QString output = QString("M %1 %2").arg(0.0).arg(0.0); |
||
1802 | output += QString("L %1 %2").arg(crect.width()).arg(0.0); |
||
1803 | output += QString("L %1 %2").arg(crect.width()).arg(crect.height()); |
||
1804 | output += QString("L %1 %2").arg(0.0).arg(crect.height()); |
||
1805 | output += QString("L %1 %2").arg(0.0).arg(0.0); |
||
1806 | output += QString("Z"); |
||
1807 | pathIsClosed = true; |
||
1808 | Coords = output; |
||
24374 | jghali | 1809 | int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), bb.width(), bb.height(), 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 1810 | PageItem* ite = m_doc->Items->at(z); |
20011 | fschmid | 1811 | if (checkClip()) |
1812 | { |
||
23536 | jghali | 1813 | ite->PoLine.fromQPainterPath(out, true); |
1814 | ite->setFillEvenOdd(out.fillRule() == Qt::OddEvenFill); |
||
20011 | fschmid | 1815 | } |
23588 | jghali | 1816 | ite->setRotation(-angle); |
19590 | jghali | 1817 | ite->ClipEdited = true; |
1818 | ite->FrameType = 3; |
||
24374 | jghali | 1819 | ite->setFillShade(m_currFillShade); |
19590 | jghali | 1820 | ite->setLineShade(100); |
1821 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1822 | ite->setFillBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1823 | ite->setLineEnd(m_lineEnd); |
1824 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1825 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
1826 | ite->GrType = 6; |
||
1827 | if (!shading->getExtend0() || !shading->getExtend1()) |
||
1828 | { |
||
1829 | FillGradient.setRepeatMethod(VGradient::none); |
||
1830 | ite->setGradientExtend(VGradient::none); |
||
1831 | } |
||
1832 | else |
||
1833 | { |
||
1834 | FillGradient.setRepeatMethod(VGradient::pad); |
||
1835 | ite->setGradientExtend(VGradient::pad); |
||
1836 | } |
||
1837 | ite->fill_gradient = FillGradient; |
||
1838 | ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, 0, 0, 1, 0); |
||
20694 | craig | 1839 | m_doc->adjustItemSize(ite); |
19590 | jghali | 1840 | m_Elements->append(ite); |
1841 | if (m_groupStack.count() != 0) |
||
1842 | { |
||
1843 | m_groupStack.top().Items.append(ite); |
||
1844 | applyMask(ite); |
||
1845 | } |
||
1846 | return gTrue; |
||
1847 | } |
||
1848 | |||
1849 | GBool SlaOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading, double sMin, double sMax) |
||
1850 | { |
||
23536 | jghali | 1851 | // qDebug() << "SlaOutputDev::radialShadedFill"; |
19590 | jghali | 1852 | double GrStartX; |
1853 | double GrStartY; |
||
1854 | double GrEndX; |
||
1855 | double GrEndY; |
||
1856 | int shade = 100; |
||
22741 | jghali | 1857 | POPPLER_CONST_070 Function *func = shading->getFunc(0); |
19590 | jghali | 1858 | VGradient FillGradient = VGradient(VGradient::linear); |
1859 | FillGradient.clearStops(); |
||
1860 | GfxColorSpace *color_space = shading->getColorSpace(); |
||
1861 | if (func->getType() == 3) |
||
1862 | { |
||
1863 | StitchingFunction *stitchingFunc = (StitchingFunction*)func; |
||
22741 | jghali | 1864 | const double *bounds = stitchingFunc->getBounds(); |
19590 | jghali | 1865 | int num_funcs = stitchingFunc->getNumFuncs(); |
22978 | jghali | 1866 | double domain_min = stitchingFunc->getDomainMin(0); |
1867 | double domain_max = stitchingFunc->getDomainMax(0); |
||
1868 | if (fabs(domain_max - domain_min) < 1e-6) |
||
1869 | { |
||
1870 | domain_min = 0.0; |
||
1871 | domain_max = 1.0; |
||
1872 | } |
||
19590 | jghali | 1873 | // Add stops from all the stitched functions |
22978 | jghali | 1874 | for (int i = 0 ; i <= num_funcs ; i++) |
19590 | jghali | 1875 | { |
1876 | GfxColor temp; |
||
22978 | jghali | 1877 | shading->getColor(bounds[i], &temp); |
19590 | jghali | 1878 | QString stopColor = getColor(color_space, &temp, &shade); |
22978 | jghali | 1879 | double stopPoint = (bounds[i] - domain_min) / (domain_max - domain_min); |
1880 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor], m_doc, shade), stopPoint, 0.5, 1.0, stopColor, shade ); |
||
19590 | jghali | 1881 | } |
1882 | } |
||
1883 | else if ((func->getType() == 2) || (func->getType() == 0)) |
||
1884 | { |
||
1885 | GfxColor stop1; |
||
22978 | jghali | 1886 | shading->getColor(0.0, &stop1); |
19590 | jghali | 1887 | QString stopColor1 = getColor(color_space, &stop1, &shade); |
1888 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor1], m_doc, shade), 0.0, 0.5, 1.0, stopColor1, shade ); |
||
1889 | GfxColor stop2; |
||
22978 | jghali | 1890 | shading->getColor(1.0, &stop2); |
19590 | jghali | 1891 | QString stopColor2 = getColor(color_space, &stop2, &shade); |
1892 | FillGradient.addStop( ScColorEngine::getShadeColor(m_doc->PageColors[stopColor2], m_doc, shade), 1.0, 0.5, 1.0, stopColor2, shade ); |
||
1893 | } |
||
1894 | double r0, x1, y1, r1; |
||
22978 | jghali | 1895 | shading->getCoords(&GrStartX, &GrStartY, &r0, &x1, &y1, &r1); |
19590 | jghali | 1896 | double xmin, ymin, xmax, ymax; |
1897 | // get the clip region bbox |
||
1898 | state->getClipBBox(&xmin, &ymin, &xmax, &ymax); |
||
1899 | QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)); |
||
1900 | crect = crect.normalized(); |
||
1901 | double GrFocalX = x1; |
||
1902 | double GrFocalY = y1; |
||
1903 | GrEndX = GrFocalX + r1; |
||
1904 | GrEndY = GrFocalY; |
||
22741 | jghali | 1905 | const double *ctm = state->getCTM(); |
19590 | jghali | 1906 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
1907 | FPointArray gr; |
||
1908 | gr.addPoint(GrStartX, GrStartY); |
||
1909 | gr.addPoint(GrEndX, GrEndY); |
||
1910 | gr.addPoint(GrFocalX, GrFocalY); |
||
1911 | gr.map(m_ctm); |
||
1912 | GrStartX = gr.point(0).x() - crect.x(); |
||
1913 | GrStartY = gr.point(0).y() - crect.y(); |
||
1914 | GrEndX = gr.point(1).x() - crect.x(); |
||
1915 | GrEndY = gr.point(1).y() - crect.y(); |
||
1916 | GrFocalX = gr.point(2).x() - crect.x(); |
||
1917 | GrFocalY = gr.point(2).y() - crect.y(); |
||
1918 | double xCoor = m_doc->currentPage()->xOffset(); |
||
1919 | double yCoor = m_doc->currentPage()->yOffset(); |
||
1920 | QString output = QString("M %1 %2").arg(0.0).arg(0.0); |
||
1921 | output += QString("L %1 %2").arg(crect.width()).arg(0.0); |
||
1922 | output += QString("L %1 %2").arg(crect.width()).arg(crect.height()); |
||
1923 | output += QString("L %1 %2").arg(0.0).arg(crect.height()); |
||
1924 | output += QString("L %1 %2").arg(0.0).arg(0.0); |
||
1925 | output += QString("Z"); |
||
1926 | pathIsClosed = true; |
||
1927 | Coords = output; |
||
24374 | jghali | 1928 | int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 1929 | PageItem* ite = m_doc->Items->at(z); |
20011 | fschmid | 1930 | if (checkClip()) |
1931 | { |
||
23536 | jghali | 1932 | QPainterPath out = m_currentClipPath; |
23319 | jghali | 1933 | out.translate(m_doc->currentPage()->xOffset(), m_doc->currentPage()->yOffset()); |
1934 | out.translate(-ite->xPos(), -ite->yPos()); |
||
23536 | jghali | 1935 | ite->PoLine.fromQPainterPath(out, true); |
1936 | ite->setFillEvenOdd(out.fillRule() == Qt::OddEvenFill); |
||
20011 | fschmid | 1937 | } |
19590 | jghali | 1938 | ite->ClipEdited = true; |
1939 | ite->FrameType = 3; |
||
24374 | jghali | 1940 | ite->setFillShade(m_currFillShade); |
19590 | jghali | 1941 | ite->setLineShade(100); |
1942 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1943 | ite->setFillBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1944 | ite->setLineEnd(m_lineEnd); |
1945 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 1946 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
1947 | ite->GrType = 7; |
||
1948 | if (!shading->getExtend0() || !shading->getExtend1()) |
||
1949 | { |
||
1950 | FillGradient.setRepeatMethod(VGradient::none); |
||
1951 | ite->setGradientExtend(VGradient::none); |
||
1952 | } |
||
1953 | else |
||
1954 | { |
||
1955 | FillGradient.setRepeatMethod(VGradient::pad); |
||
1956 | ite->setGradientExtend(VGradient::pad); |
||
1957 | } |
||
1958 | ite->fill_gradient = FillGradient; |
||
1959 | ite->setGradientVector(GrStartX, GrStartY, GrEndX, GrEndY, GrFocalX, GrFocalY, 1, 0); |
||
20694 | craig | 1960 | m_doc->adjustItemSize(ite); |
19590 | jghali | 1961 | m_Elements->append(ite); |
1962 | if (m_groupStack.count() != 0) |
||
1963 | { |
||
1964 | m_groupStack.top().Items.append(ite); |
||
1965 | applyMask(ite); |
||
1966 | } |
||
1967 | return gTrue; |
||
1968 | } |
||
1969 | |||
1970 | GBool SlaOutputDev::gouraudTriangleShadedFill(GfxState *state, GfxGouraudTriangleShading *shading) |
||
1971 | { |
||
23536 | jghali | 1972 | // qDebug() << "SlaOutputDev::gouraudTriangleShadedFill"; |
19590 | jghali | 1973 | double xCoor = m_doc->currentPage()->xOffset(); |
1974 | double yCoor = m_doc->currentPage()->yOffset(); |
||
1975 | double xmin, ymin, xmax, ymax; |
||
1976 | // get the clip region bbox |
||
1977 | state->getClipBBox(&xmin, &ymin, &xmax, &ymax); |
||
1978 | QRectF crect = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)); |
||
1979 | crect = crect.normalized(); |
||
1980 | QString output = QString("M %1 %2").arg(0.0).arg(0.0); |
||
1981 | output += QString("L %1 %2").arg(crect.width()).arg(0.0); |
||
1982 | output += QString("L %1 %2").arg(crect.width()).arg(crect.height()); |
||
1983 | output += QString("L %1 %2").arg(0.0).arg(crect.height()); |
||
1984 | output += QString("L %1 %2").arg(0.0).arg(0.0); |
||
1985 | output += QString("Z"); |
||
1986 | pathIsClosed = true; |
||
1987 | Coords = output; |
||
22741 | jghali | 1988 | const double *ctm = state->getCTM(); |
19590 | jghali | 1989 | m_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]); |
24374 | jghali | 1990 | int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + crect.x(), yCoor + crect.y(), crect.width(), crect.height(), 0, m_currColorFill, CommonStrings::None); |
19590 | jghali | 1991 | PageItem* ite = m_doc->Items->at(z); |
1992 | ite->ClipEdited = true; |
||
1993 | ite->FrameType = 3; |
||
24374 | jghali | 1994 | ite->setFillShade(m_currFillShade); |
19590 | jghali | 1995 | ite->setLineShade(100); |
1996 | ite->setFillEvenOdd(false); |
||
1997 | ite->setFillTransparency(1.0 - state->getFillOpacity()); |
||
1998 | ite->setFillBlendmode(getBlendMode(state)); |
||
24374 | jghali | 1999 | ite->setLineEnd(m_lineEnd); |
2000 | ite->setLineJoin(m_lineJoin); |
||
19590 | jghali | 2001 | ite->setTextFlowMode(PageItem::TextFlowDisabled); |
20694 | craig | 2002 | m_doc->adjustItemSize(ite); |
19590 | jghali | 2003 | m_Elements->append(ite); |
2004 | if (m_groupStack.count() != 0) |
||
2005 | { |
||
2006 | m_groupStack.top().Items.append(ite); |
||
2007 | applyMask(ite); |
||
2008 | } |
||
2009 | GfxColor color[3]; |
||
2010 | double x0, y0, x1, y1, x2, y2; |
||
2011 | for (int i = 0; i < shading->getNTriangles(); i++) |
||
2012 | { |
||
2013 | int shade = 100; |
||
2014 | meshGradientPatch patchM; |
||
2015 | shading->getTriangle(i, &x0, &y0, &color[0], &x1, &y1, &color[1], &x2, &y2, &color[2]); |
||
2016 | patchM.BL.resetTo(FPoint(x0, y0)); |
||
2017 | patchM.BL.shade = 100; |
||
2018 | patchM.BL.transparency = 1.0; |
||
2019 | patchM.BL.colorName = getColor(shading->getColorSpace(), &color[0], &shade); |
||
2020 | patchM.BL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.BL.colorName], m_doc, shade); |
||
2021 | patchM.TL.resetTo(FPoint(x1, y1)); |
||
2022 | patchM.TL.shade = 100; |
||
2023 | patchM.TL.transparency = 1.0; |
||
2024 | patchM.TL.colorName = getColor(shading->getColorSpace(), &color[1], &shade); |
||
2025 | patchM.TL.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TL.colorName], m_doc, shade); |
||
2026 | patchM.TR.resetTo(FPoint(x2, y2)); |
||
2027 | patchM.TR.shade = 100; |
||
2028 | patchM.TR.transparency = 1.0; |
||
2029 | patchM.TR.colorName = getColor(shading->getColorSpace(), &color[2], &shade); |
||
2030 | patchM.TR.color = ScColorEngine::getShadeColorProof(m_doc->PageColors[patchM.TR.colorName], m_doc, shade); |
||
2031 | patchM.BR.resetTo(FPoint |