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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 383 } |
384 | 384 |
385 // if (fCurFont && fCurFont->GetFontScale() != 0) { | 385 // if (fCurFont && fCurFont->GetFontScale() != 0) { |
386 // paint.setTextScaleX(SkFloatToScalar(fCurFont->GetFontScale() / 100.0))
; | 386 // paint.setTextScaleX(SkFloatToScalar(fCurFont->GetFontScale() / 100.0))
; |
387 // } | 387 // } |
388 | 388 |
389 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); | 389 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); |
390 | 390 |
391 canvas->save(); | 391 canvas->save(); |
392 | 392 |
393 #if 1 | |
394 SkMatrix matrix = pdfContext->fGraphicsState.fMatrixTm; | |
395 | |
396 SkPoint point1; | |
397 pdfContext->fGraphicsState.fMatrixTm.mapXY(SkIntToScalar(0), SkIntToScalar(0
), &point1); | |
398 | |
399 SkMatrix mirror; | |
400 mirror.setTranslate(0, -point1.y()); | |
401 // TODO(edisonn): fix rotated text, and skewed too | |
402 mirror.postScale(SK_Scalar1, -SK_Scalar1); | |
403 // TODO(edisonn): post rotate, skew | |
404 mirror.postTranslate(0, point1.y()); | |
405 | |
406 matrix.postConcat(mirror); | |
407 | |
408 canvas->setMatrix(matrix); | |
409 | |
410 SkTraceMatrix(matrix, "mirrored"); | |
411 #endif | |
412 | |
413 skfont->drawText(decoded, &paint, pdfContext, canvas); | 393 skfont->drawText(decoded, &paint, pdfContext, canvas); |
414 canvas->restore(); | 394 canvas->restore(); |
415 | 395 |
416 return kOK_PdfResult; | 396 return kOK_PdfResult; |
417 } | 397 } |
418 | 398 |
419 // TODO(edisonn): create header files with declarations! | 399 // TODO(edisonn): create header files with declarations! |
420 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); | 400 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); |
421 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); | 401 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo
per); |
422 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper); | 402 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo
oper); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 729 |
750 | 730 |
751 if (skobj->Resources(pdfContext->fPdfDoc)) { | 731 if (skobj->Resources(pdfContext->fPdfDoc)) { |
752 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); | 732 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd
fDoc); |
753 } | 733 } |
754 | 734 |
755 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); | 735 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); |
756 | 736 |
757 if (skobj->has_Matrix()) { | 737 if (skobj->has_Matrix()) { |
758 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf
Doc)); | 738 pdfContext->fGraphicsState.fCTM.preConcat(skobj->Matrix(pdfContext->fPdf
Doc)); |
759 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM; | 739 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; |
760 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; | 740 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
| 741 pdfContext->fGraphicsState.fMatrixTm = matrix; |
| 742 pdfContext->fGraphicsState.fMatrixTlm = matrix; |
761 // TODO(edisonn) reset matrixTm and matricTlm also? | 743 // TODO(edisonn) reset matrixTm and matricTlm also? |
762 } | 744 } |
763 | 745 |
764 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); | 746 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); |
765 pdfContext->fGraphicsState.fContentStreamMatrix = pdfContext->fGraphicsState
.fCTM; | 747 pdfContext->fGraphicsState.fContentStreamMatrix = pdfContext->fGraphicsState
.fCTM; |
766 | 748 |
767 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 749 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
768 | 750 |
769 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); | 751 SkRect bbox = skobj->BBox(pdfContext->fPdfDoc); |
770 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. | 752 canvas->clipRect(bbox, SkRegion::kIntersect_Op, true); // TODO(edisonn): AA
from settings. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec
t* skobj, SkRect bBox, SkMatrix matrix, double textSize) { | 845 PdfResult doType3Char(PdfContext* pdfContext, SkCanvas* canvas, const SkPdfObjec
t* skobj, SkRect bBox, SkMatrix matrix, double textSize) { |
864 if (!skobj || !skobj->hasStream()) { | 846 if (!skobj || !skobj->hasStream()) { |
865 return kIgnoreError_PdfResult; | 847 return kIgnoreError_PdfResult; |
866 } | 848 } |
867 | 849 |
868 PdfOp_q(pdfContext, canvas, NULL); | 850 PdfOp_q(pdfContext, canvas, NULL); |
869 canvas->save(); | 851 canvas->save(); |
870 | 852 |
871 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 853 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
872 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); | 854 pdfContext->fGraphicsState.fMatrixTm.preScale(SkDoubleToScalar(textSize), Sk
DoubleToScalar(textSize)); |
| 855 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fMatrixTm
; |
873 | 856 |
874 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; | 857 pdfContext->fGraphicsState.fCTM = pdfContext->fGraphicsState.fMatrixTm; |
875 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; | 858 pdfContext->fGraphicsState.fCTM.preScale(SkDoubleToScalar(1), SkDoubleToScal
ar(-1)); |
876 | 859 |
877 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); | 860 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Total matrix"); |
878 | 861 |
879 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); | 862 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); |
880 | 863 |
881 SkRect rm = bBox; | 864 SkRect rm = bBox; |
882 pdfContext->fGraphicsState.fCTM.mapRect(&rm); | 865 pdfContext->fGraphicsState.fCTM.mapRect(&rm); |
883 | 866 |
884 SkTraceRect(rm, "bbox mapped"); | 867 SkTraceRect(rm, "bbox mapped"); |
885 | 868 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 | 1050 |
1068 static PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1051 static PdfResult PdfOp_Td(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
1069 #ifdef PDF_TRACE | 1052 #ifdef PDF_TRACE |
1070 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); | 1053 printf("stack size = %i\n", (int)pdfContext->fObjectStack.size()); |
1071 #endif | 1054 #endif |
1072 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1055 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1073 SkPdfObject* obj = pdfContext->fObjectStack.top(); | 1056 SkPdfObject* obj = pdfContext->fObjectStack.top(); |
1074 obj = obj; | 1057 obj = obj; |
1075 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1058 double tx = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
1076 | 1059 |
1077 double array[6] = {1, 0, 0, 1, tx, ty}; | 1060 double array[6] = {1, 0, 0, 1, tx, -ty}; |
1078 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1061 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1079 | 1062 |
1080 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); | 1063 pdfContext->fGraphicsState.fMatrixTm.preConcat(matrix); |
1081 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); | 1064 pdfContext->fGraphicsState.fMatrixTlm.preConcat(matrix); |
1082 | 1065 |
1083 return kPartial_PdfResult; | 1066 return kPartial_PdfResult; |
1084 } | 1067 } |
1085 | 1068 |
1086 static PdfResult PdfOp_TD(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1069 static PdfResult PdfOp_TD(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
1087 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); | 1070 double ty = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fObje
ctStack.pop(); |
(...skipping 30 matching lines...) Expand all Loading... |
1118 double array[6]; | 1101 double array[6]; |
1119 array[0] = a; | 1102 array[0] = a; |
1120 array[1] = b; | 1103 array[1] = b; |
1121 array[2] = c; | 1104 array[2] = c; |
1122 array[3] = d; | 1105 array[3] = d; |
1123 array[4] = e; | 1106 array[4] = e; |
1124 array[5] = f; | 1107 array[5] = f; |
1125 | 1108 |
1126 SkMatrix matrix = SkMatrixFromPdfMatrix(array); | 1109 SkMatrix matrix = SkMatrixFromPdfMatrix(array); |
1127 matrix.postConcat(pdfContext->fGraphicsState.fCTM); | 1110 matrix.postConcat(pdfContext->fGraphicsState.fCTM); |
| 1111 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
1128 | 1112 |
1129 // TODO(edisonn): Text positioning. | 1113 // TODO(edisonn): Text positioning. |
1130 pdfContext->fGraphicsState.fMatrixTm = matrix; | 1114 pdfContext->fGraphicsState.fMatrixTm = matrix; |
1131 pdfContext->fGraphicsState.fMatrixTlm = matrix;; | 1115 pdfContext->fGraphicsState.fMatrixTlm = matrix;; |
1132 | 1116 |
1133 return kPartial_PdfResult; | 1117 return kPartial_PdfResult; |
1134 } | 1118 } |
1135 | 1119 |
1136 //— T* Move to the start of the next line. This operator has the same effect as
the code | 1120 //— T* Move to the start of the next line. This operator has the same effect as
the code |
1137 //0 Tl Td | 1121 //0 Tl Td |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 //pdfContext->fGraphicsState.fClipPath.reset(); | 1436 //pdfContext->fGraphicsState.fClipPath.reset(); |
1453 pdfContext->fGraphicsState.fHasClipPathToApply = false; | 1437 pdfContext->fGraphicsState.fHasClipPathToApply = false; |
1454 | 1438 |
1455 pdfContext->fGraphicsState.fPathClosed = true; | 1439 pdfContext->fGraphicsState.fPathClosed = true; |
1456 | 1440 |
1457 return kOK_PdfResult; | 1441 return kOK_PdfResult; |
1458 } | 1442 } |
1459 | 1443 |
1460 static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1444 static PdfResult PdfOp_BT(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
1461 pdfContext->fGraphicsState.fTextBlock = true; | 1445 pdfContext->fGraphicsState.fTextBlock = true; |
1462 pdfContext->fGraphicsState.fMatrixTm = pdfContext->fGraphicsState.fCTM; | 1446 SkMatrix matrix = pdfContext->fGraphicsState.fCTM; |
1463 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; | 1447 matrix.preScale(SkDoubleToScalar(1), SkDoubleToScalar(-1)); |
| 1448 pdfContext->fGraphicsState.fMatrixTm = matrix; |
| 1449 pdfContext->fGraphicsState.fMatrixTlm = matrix; |
1464 | 1450 |
1465 return kPartial_PdfResult; | 1451 return kPartial_PdfResult; |
1466 } | 1452 } |
1467 | 1453 |
1468 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1454 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
1469 if (!pdfContext->fGraphicsState.fTextBlock) { | 1455 if (!pdfContext->fGraphicsState.fTextBlock) { |
1470 return kIgnoreError_PdfResult; | 1456 return kIgnoreError_PdfResult; |
1471 } | 1457 } |
1472 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? | 1458 // TODO(edisonn): anything else to be done once we are done with draw text?
Like restore stack? |
1473 return kOK_PdfResult; | 1459 return kOK_PdfResult; |
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2636 | 2622 |
2637 rect = SkRect::MakeWH(width, height); | 2623 rect = SkRect::MakeWH(width, height); |
2638 | 2624 |
2639 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2625 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2640 | 2626 |
2641 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2627 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2642 SkCanvas canvas(device); | 2628 SkCanvas canvas(device); |
2643 | 2629 |
2644 return renderer.renderPage(page, &canvas, rect); | 2630 return renderer.renderPage(page, &canvas, rect); |
2645 } | 2631 } |
OLD | NEW |