OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 #endif // PDF_TRACE_DIFF_IN_PNG | 230 #endif // PDF_TRACE_DIFF_IN_PNG |
231 | 231 |
232 | 232 |
233 | 233 |
234 // TODO(edisonn): Pass PdfContext and SkCanvasd only with the define for instrum
entation. | 234 // TODO(edisonn): Pass PdfContext and SkCanvasd only with the define for instrum
entation. |
235 static bool readToken(SkPdfNativeTokenizer* fTokenizer, PdfToken* token) { | 235 static bool readToken(SkPdfNativeTokenizer* fTokenizer, PdfToken* token) { |
236 bool ret = fTokenizer->readToken(token); | 236 bool ret = fTokenizer->readToken(token); |
237 | 237 |
238 gReadOp++; | 238 gReadOp++; |
239 | 239 gLastOpKeyword++; |
240 #ifdef PDF_TRACE_DIFF_IN_PNG | 240 #ifdef PDF_TRACE_DIFF_IN_PNG |
241 // TODO(edisonn): compare with old bitmap, and save only new bits are availa
ble, and save | 241 // TODO(edisonn): compare with old bitmap, and save only new bits are availa
ble, and save |
242 // the numbar and name of last operation, so the file name will reflect op t
hat changed. | 242 // the numbar and name of last operation, so the file name will reflect op t
hat changed. |
243 if (hasVisualEffect(gLastKeyword)) { // TODO(edisonn): and has dirty bits. | 243 if (gLastKeyword[0] && hasVisualEffect(gLastKeyword)) { // TODO(edisonn): a
nd has dirty bits. |
244 gDumpCanvas->flush(); | 244 gDumpCanvas->flush(); |
245 | 245 |
246 SkBitmap bitmap; | 246 SkBitmap bitmap; |
247 setup_bitmap(&bitmap, gDumpBitmap->width(), gDumpBitmap->height()); | 247 setup_bitmap(&bitmap, gDumpBitmap->width(), gDumpBitmap->height()); |
248 | 248 |
249 memcpy(bitmap.getPixels(), gDumpBitmap->getPixels(), gDumpBitmap->getSiz
e()); | 249 memcpy(bitmap.getPixels(), gDumpBitmap->getPixels(), gDumpBitmap->getSiz
e()); |
250 | 250 |
251 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); | 251 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); |
252 SkCanvas canvas(device); | 252 SkCanvas canvas(device); |
253 | 253 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 canvas.flush(); | 304 canvas.flush(); |
305 | 305 |
306 SkString out; | 306 SkString out; |
307 | 307 |
308 // TODO(edisonn): get the image, and overlay on top of it, the clip , gr
afic state, teh stack, | 308 // TODO(edisonn): get the image, and overlay on top of it, the clip , gr
afic state, teh stack, |
309 // ... and other properties, to be able to debug th code easily | 309 // ... and other properties, to be able to debug th code easily |
310 | 310 |
311 out.appendf("/usr/local/google/home/edisonn/log_view2/step-%i-%s.png", g
LastOpKeyword, gLastKeyword); | 311 out.appendf("/usr/local/google/home/edisonn/log_view2/step-%i-%s.png", g
LastOpKeyword, gLastKeyword); |
312 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder::kPNG_Typ
e, 100); | 312 SkImageEncoder::EncodeFile(out.c_str(), bitmap, SkImageEncoder::kPNG_Typ
e, 100); |
313 } | 313 } |
| 314 |
| 315 if (ret && token->fType == kKeyword_TokenType && token->fKeyword && token->f
KeywordLength > 0 && token->fKeywordLength < 100) { |
| 316 strncpy(gLastKeyword, token->fKeyword, token->fKeywordLength); |
| 317 gLastKeyword[token->fKeywordLength] = '\0'; |
| 318 } else { |
| 319 gLastKeyword[0] = '\0'; |
| 320 } |
| 321 |
314 #endif | 322 #endif |
315 | 323 |
316 return ret; | 324 return ret; |
317 } | 325 } |
318 | 326 |
319 | 327 |
320 | 328 |
321 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper*
*); | 329 typedef PdfResult (*PdfOperatorRenderer)(PdfContext*, SkCanvas*, PdfTokenLooper*
*); |
322 | 330 |
323 SkTDict<PdfOperatorRenderer> gPdfOps(100); | 331 SkTDict<PdfOperatorRenderer> gPdfOps(100); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 if (skpdfimage == NULL) { | 643 if (skpdfimage == NULL) { |
636 return kIgnoreError_PdfResult; | 644 return kIgnoreError_PdfResult; |
637 } | 645 } |
638 | 646 |
639 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); | 647 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false); |
640 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); | 648 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage); |
641 | 649 |
642 canvas->save(); | 650 canvas->save(); |
643 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 651 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
644 | 652 |
645 #if 1 | |
646 SkScalar z = SkIntToScalar(0); | 653 SkScalar z = SkIntToScalar(0); |
647 SkScalar one = SkIntToScalar(1); | 654 SkScalar one = SkIntToScalar(1); |
648 | 655 |
649 SkPoint from[4] = {SkPoint::Make(z, z), SkPoint::Make(one, z), SkPoint::Make
(one, one), SkPoint::Make(z, one)}; | 656 SkPoint from[4] = {SkPoint::Make(z, z), SkPoint::Make(one, z), SkPoint::Make
(one, one), SkPoint::Make(z, one)}; |
650 SkPoint to[4] = {SkPoint::Make(z, one), SkPoint::Make(one, one), SkPoint::Ma
ke(one, z), SkPoint::Make(z, z)}; | 657 SkPoint to[4] = {SkPoint::Make(z, one), SkPoint::Make(one, one), SkPoint::Ma
ke(one, z), SkPoint::Make(z, z)}; |
651 SkMatrix flip; | 658 SkMatrix flip; |
652 SkAssertResult(flip.setPolyToPoly(from, to, 4)); | 659 SkAssertResult(flip.setPolyToPoly(from, to, 4)); |
653 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fCTM; | 660 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fCTM; |
654 solveImageFlip.preConcat(flip); | 661 solveImageFlip.preConcat(flip); |
655 canvas->setMatrix(solveImageFlip); | 662 canvas->setMatrix(solveImageFlip); |
656 #endif | 663 |
| 664 #ifdef PDF_TRACE |
| 665 SkPoint final[4] = {SkPoint::Make(z, z), SkPoint::Make(one, z), SkPoint::Mak
e(one, one), SkPoint::Make(z, one)}; |
| 666 solveImageFlip.mapPoints(final, 4); |
| 667 printf("IMAGE rect = "); |
| 668 for (int i = 0; i < 4; i++) { |
| 669 printf("(%f %f) ", SkScalarToDouble(final[i].x()), SkScalarToDouble(fina
l[i].y())); |
| 670 } |
| 671 printf("\n"); |
| 672 #endif // PDF_TRACE |
657 | 673 |
658 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); | 674 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0),
SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); |
659 | 675 |
660 // TODO(edisonn): soft mask type? alpha/luminosity. | 676 // TODO(edisonn): soft mask type? alpha/luminosity. |
661 SkPaint paint; | 677 SkPaint paint; |
662 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); | 678 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); |
663 | 679 |
664 if (!sMask || sMask->empty()) { | 680 if (!sMask || sMask->empty()) { |
665 canvas->drawBitmapRect(*image, dst, &paint); | 681 canvas->drawBitmapRect(*image, dst, &paint); |
666 } else { | 682 } else { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); | 755 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); |
740 | 756 |
741 if (skobj->has_Matrix()) { | 757 if (skobj->has_Matrix()) { |
742 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf
Doc)); | 758 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf
Doc)); |
743 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM; | 759 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM; |
744 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; | 760 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; |
745 // TODO(edisonn) reset matrixTm and matricTlm also? | 761 // TODO(edisonn) reset matrixTm and matricTlm also? |
746 } | 762 } |
747 | 763 |
748 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); | 764 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); |
| 765 pdfContext->fGraphicsState.fContentStreamMatrix = pdfContext->fGraphicsState
.fCTM; |
749 | 766 |
750 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 767 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
751 | 768 |
752 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); | 769 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); |
753 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. | 770 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. |
754 | 771 |
755 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. | 772 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. |
756 // For this PdfContentsTokenizer needs to be extended. | 773 // For this PdfContentsTokenizer needs to be extended. |
757 | 774 |
758 // This is a group? | 775 // This is a group? |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 | 813 |
797 PdfOp_q(pdfContext, canvas, NULL); | 814 PdfOp_q(pdfContext, canvas, NULL); |
798 | 815 |
799 canvas->save(); | 816 canvas->save(); |
800 | 817 |
801 | 818 |
802 if (skobj->Resources(pdfContext->fPdfDoc)) { | 819 if (skobj->Resources(pdfContext->fPdfDoc)) { |
803 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 820 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
804 } | 821 } |
805 | 822 |
806 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); | 823 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Current Cont
ent stream matrix"); |
807 | 824 |
808 if (skobj->has_Matrix()) { | 825 if (skobj->has_Matrix()) { |
809 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf
Doc)); | 826 pdfContext->fGraphicsState.fContentStreamMatrix.preConcat(skobj->Matrix(
pdfContext->fPdfDoc)); |
810 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM; | |
811 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; | |
812 // TODO(edisonn) reset matrixTm and matricTlm also? | |
813 } | 827 } |
814 | 828 |
815 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); | 829 SkTraceMatrix(pdfContext->fGraphicsState.fContentStreamMatrix, "Total Conten
t stream matrix"); |
816 | 830 |
817 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 831 canvas->setMatrix(pdfContext->fGraphicsState.fContentStreamMatrix); |
| 832 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fContentStreamM
atrix; |
818 | 833 |
819 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); | 834 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); |
820 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. | 835 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. |
821 | 836 |
822 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. | 837 // TODO(edisonn): iterate smart on the stream even if it is compressed, toke
nize it as we go. |
823 // For this PdfContentsTokenizer needs to be extended. | 838 // For this PdfContentsTokenizer needs to be extended. |
824 | 839 |
825 SkPdfStream* stream = (SkPdfStream*)skobj; | 840 SkPdfStream* stream = (SkPdfStream*)skobj; |
826 | 841 |
827 SkPdfNativeTokenizer* tokenizer = | 842 SkPdfNativeTokenizer* tokenizer = |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 y = bounds.top(); | 1331 y = bounds.top(); |
1317 int totalx = 0; | 1332 int totalx = 0; |
1318 int totaly = 0; | 1333 int totaly = 0; |
1319 while (y < bounds.bottom()) { | 1334 while (y < bounds.bottom()) { |
1320 x = bounds.left(); | 1335 x = bounds.left(); |
1321 totalx = 0; | 1336 totalx = 0; |
1322 | 1337 |
1323 while (x < bounds.right()) { | 1338 while (x < bounds.right()) { |
1324 doXObject(pdfContext, canvas, pattern); | 1339 doXObject(pdfContext, canvas, pattern); |
1325 | 1340 |
1326 pdfContext->fGraphicsState.fCTM.preTranslate(SkI
ntToScalar(xStep), SkIntToScalar(0)); | 1341 pdfContext->fGraphicsState.fContentStreamMatrix.
preTranslate(SkIntToScalar(xStep), SkIntToScalar(0)); |
1327 totalx += xStep; | 1342 totalx += xStep; |
1328 x += SkIntToScalar(xStep); | 1343 x += SkIntToScalar(xStep); |
1329 } | 1344 } |
1330 pdfContext->fGraphicsState.fCTM.preTranslate(SkIntTo
Scalar(-totalx), SkIntToScalar(0)); | 1345 pdfContext->fGraphicsState.fContentStreamMatrix.preT
ranslate(SkIntToScalar(-totalx), SkIntToScalar(0)); |
1331 | 1346 |
1332 pdfContext->fGraphicsState.fCTM.preTranslate(SkIntTo
Scalar(0), SkIntToScalar(-yStep)); | 1347 pdfContext->fGraphicsState.fContentStreamMatrix.preT
ranslate(SkIntToScalar(0), SkIntToScalar(-yStep)); |
1333 totaly += yStep; | 1348 totaly += yStep; |
1334 y += SkIntToScalar(yStep); | 1349 y += SkIntToScalar(yStep); |
1335 } | 1350 } |
1336 pdfContext->fGraphicsState.fCTM.preTranslate(SkIntToScal
ar(0), SkIntToScalar(totaly)); | 1351 pdfContext->fGraphicsState.fContentStreamMatrix.preTrans
late(SkIntToScalar(0), SkIntToScalar(totaly)); |
1337 } | 1352 } |
1338 } | 1353 } |
1339 | 1354 |
1340 // apply matrix | 1355 // apply matrix |
1341 // get xstep, y step, bbox ... for cliping, and bos of the path | 1356 // get xstep, y step, bbox ... for cliping, and bos of the path |
1342 | 1357 |
1343 PdfOp_Q(pdfContext, canvas, NULL); | 1358 PdfOp_Q(pdfContext, canvas, NULL); |
1344 canvas->restore(); | 1359 canvas->restore(); |
1345 } else { | 1360 } else { |
1346 paint.setStyle(SkPaint::kFill_Style); | 1361 paint.setStyle(SkPaint::kFill_Style); |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 | 2542 |
2528 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)}; | 2543 //SkPoint pdfSpace[2] = {SkPoint::Make(z, z), SkPoint::Make(z, h)}; |
2529 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)}; | 2544 //SkPoint skiaSpace[2] = {SkPoint::Make(z, h), SkPoint::Make(z, z)}; |
2530 | 2545 |
2531 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint::
Make(w, h)}; | 2546 //SkPoint pdfSpace[3] = {SkPoint::Make(z, z), SkPoint::Make(z, h), SkPoint::
Make(w, h)}; |
2532 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint:
:Make(w, 0)}; | 2547 //SkPoint skiaSpace[3] = {SkPoint::Make(z, h), SkPoint::Make(z, z), SkPoint:
:Make(w, 0)}; |
2533 | 2548 |
2534 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace,
4)); | 2549 SkAssertResult(pdfContext.fOriginalMatrix.setPolyToPoly(pdfSpace, skiaSpace,
4)); |
2535 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix"); | 2550 SkTraceMatrix(pdfContext.fOriginalMatrix, "Original matrix"); |
2536 | 2551 |
2537 | |
2538 pdfContext.fGraphicsState.fCTM = pdfContext.fOriginalMatrix; | 2552 pdfContext.fGraphicsState.fCTM = pdfContext.fOriginalMatrix; |
| 2553 pdfContext.fGraphicsState.fContentStreamMatrix = pdfContext.fOriginalMatrix; |
2539 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fCTM; | 2554 pdfContext.fGraphicsState.fMatrixTm = pdfContext.fGraphicsState.fCTM; |
2540 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fCTM; | 2555 pdfContext.fGraphicsState.fMatrixTlm = pdfContext.fGraphicsState.fCTM; |
2541 | 2556 |
2542 #ifndef PDF_DEBUG_NO_PAGE_CLIPING | 2557 #ifndef PDF_DEBUG_NO_PAGE_CLIPING |
2543 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); | 2558 canvas->clipRect(dst, SkRegion::kIntersect_Op, true); |
2544 #endif | 2559 #endif |
2545 | 2560 |
2546 canvas->setMatrix(pdfContext.fOriginalMatrix); | 2561 canvas->setMatrix(pdfContext.fOriginalMatrix); |
2547 | 2562 |
2548 doPage(&pdfContext, canvas, fPdfDoc->page(page)); | 2563 doPage(&pdfContext, canvas, fPdfDoc->page(page)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2621 | 2636 |
2622 rect = SkRect::MakeWH(width, height); | 2637 rect = SkRect::MakeWH(width, height); |
2623 | 2638 |
2624 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2639 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2625 | 2640 |
2626 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2641 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2627 SkCanvas canvas(device); | 2642 SkCanvas canvas(device); |
2628 | 2643 |
2629 return renderer.renderPage(page, &canvas, rect); | 2644 return renderer.renderPage(page, &canvas, rect); |
2630 } | 2645 } |
OLD | NEW |