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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 canvas->restore(); | 1078 canvas->restore(); |
1079 PdfOp_Q(pdfContext, canvas, NULL); | 1079 PdfOp_Q(pdfContext, canvas, NULL); |
1080 return kPartial_SkPdfResult; | 1080 return kPartial_SkPdfResult; |
1081 } | 1081 } |
1082 | 1082 |
1083 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { | 1083 SkPdfResult PdfOp_q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { |
1084 // TODO(edisonn): create a new stack of parameters, so once we start a q, | 1084 // TODO(edisonn): create a new stack of parameters, so once we start a q, |
1085 // it is not possible to see under the previous q? | 1085 // it is not possible to see under the previous q? |
1086 pdfContext->fStateStack.push(pdfContext->fGraphicsState); | 1086 pdfContext->fStateStack.push(pdfContext->fGraphicsState); |
1087 canvas->save(); | 1087 canvas->save(); |
| 1088 pdfContext->fObjectStack.nest(); |
1088 return kOK_SkPdfResult; | 1089 return kOK_SkPdfResult; |
1089 } | 1090 } |
1090 | 1091 |
1091 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { | 1092 SkPdfResult PdfOp_Q(SkPdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper**
looper) { |
1092 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); | 1093 if (pdfContext->fStateStack.count() > 0) { |
1093 pdfContext->fStateStack.pop(); | 1094 pdfContext->fGraphicsState = pdfContext->fStateStack.top(); |
1094 canvas->restore(); | 1095 pdfContext->fStateStack.pop(); |
| 1096 canvas->restore(); |
| 1097 |
| 1098 if (pdfContext->fObjectStack.nests() <= 0) { |
| 1099 return kIgnoreError_SkPdfResult; |
| 1100 } else { |
| 1101 pdfContext->fObjectStack.unnest(); |
| 1102 } |
| 1103 } else { |
| 1104 return kIgnoreError_SkPdfResult; |
| 1105 } |
| 1106 |
1095 return kOK_SkPdfResult; | 1107 return kOK_SkPdfResult; |
1096 } | 1108 } |
1097 | 1109 |
1098 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { | 1110 static SkPdfResult PdfOp_cm(SkPdfContext* pdfContext, SkCanvas* canvas, PdfToken
Looper** looper) { |
1099 EXPECT_OPERANDS(pdfContext, 6); | 1111 EXPECT_OPERANDS(pdfContext, 6); |
1100 POP_NUMBER(pdfContext, f); | 1112 POP_NUMBER(pdfContext, f); |
1101 POP_NUMBER(pdfContext, e); | 1113 POP_NUMBER(pdfContext, e); |
1102 POP_NUMBER(pdfContext, d); | 1114 POP_NUMBER(pdfContext, d); |
1103 POP_NUMBER(pdfContext, c); | 1115 POP_NUMBER(pdfContext, c); |
1104 POP_NUMBER(pdfContext, b); | 1116 POP_NUMBER(pdfContext, b); |
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2768 pdfContext.fOriginalMatrix = SkMatrix::I(); | 2780 pdfContext.fOriginalMatrix = SkMatrix::I(); |
2769 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); | 2781 pdfContext.fGraphicsState.fResources = fPdfDoc->pageResources(page); |
2770 | 2782 |
2771 gPdfContext = &pdfContext; | 2783 gPdfContext = &pdfContext; |
2772 | 2784 |
2773 // TODO(edisonn): get matrix stuff right. | 2785 // TODO(edisonn): get matrix stuff right. |
2774 SkScalar z = SkIntToScalar(0); | 2786 SkScalar z = SkIntToScalar(0); |
2775 SkScalar w = dst.width(); | 2787 SkScalar w = dst.width(); |
2776 SkScalar h = dst.height(); | 2788 SkScalar h = dst.height(); |
2777 | 2789 |
| 2790 if (SkScalarTruncToInt(w) <= 0 || SkScalarTruncToInt(h) <= 0) { |
| 2791 return true; |
| 2792 } |
| 2793 |
2778 SkScalar wp = fPdfDoc->MediaBox(page).width(); | 2794 SkScalar wp = fPdfDoc->MediaBox(page).width(); |
2779 SkScalar hp = fPdfDoc->MediaBox(page).height(); | 2795 SkScalar hp = fPdfDoc->MediaBox(page).height(); |
2780 | 2796 |
2781 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(wp, z), SkPoint::M
ake(wp, hp), SkPoint::Make(z, hp)}; | 2797 SkPoint pdfSpace[4] = {SkPoint::Make(z, z), SkPoint::Make(wp, z), SkPoint::M
ake(wp, hp), SkPoint::Make(z, hp)}; |
2782 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w,
h), SkPoint::Make(w, z), SkPoint::Make(z, z)}; | 2798 // SkPoint skiaSpace[4] = {SkPoint::Make(z, h), SkPoint::Make(w,
h), SkPoint::Make(w, z), SkPoint::Make(z, z)}; |
2783 | 2799 |
2784 // TODO(edisonn): add flag for this app to create sourunding buffer zone | 2800 // TODO(edisonn): add flag for this app to create sourunding buffer zone |
2785 // TODO(edisonn): add flagg for no clipping. | 2801 // TODO(edisonn): add flagg for no clipping. |
2786 // Use larger image to make sure we do not draw anything outside of page | 2802 // Use larger image to make sure we do not draw anything outside of page |
2787 // could be used in tests. | 2803 // could be used in tests. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 | 2906 |
2891 rect = SkRect::MakeWH(width, height); | 2907 rect = SkRect::MakeWH(width, height); |
2892 | 2908 |
2893 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2909 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2894 | 2910 |
2895 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2911 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2896 SkCanvas canvas(device); | 2912 SkCanvas canvas(device); |
2897 | 2913 |
2898 return renderer.renderPage(page, &canvas, rect); | 2914 return renderer.renderPage(page, &canvas, rect); |
2899 } | 2915 } |
OLD | NEW |