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