Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: experimental/PdfViewer/SkPdfRenderer.cpp

Issue 20662003: pdfviewer: fix a few warnings (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 matrix.postConcat(mirror); 405 matrix.postConcat(mirror);
406 406
407 canvas->setMatrix(matrix); 407 canvas->setMatrix(matrix);
408 408
409 SkTraceMatrix(matrix, "mirrored"); 409 SkTraceMatrix(matrix, "mirrored");
410 #endif 410 #endif
411 411
412 skfont->drawText(decoded, &paint, pdfContext, canvas); 412 skfont->drawText(decoded, &paint, pdfContext, canvas);
413 canvas->restore(); 413 canvas->restore();
414 414
415 return kPartial_PdfResult; 415 return kOK_PdfResult;
416 } 416 }
417 417
418 // TODO(edisonn): create header files with declarations! 418 // TODO(edisonn): create header files with declarations!
419 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per); 419 PdfResult PdfOp_q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per);
420 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per); 420 PdfResult PdfOp_Q(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** loo per);
421 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper); 421 PdfResult PdfOp_Tw(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper);
422 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper); 422 PdfResult PdfOp_Tc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLooper** lo oper);
423 423
424 // TODO(edisonn): perf!!! 424 // TODO(edisonn): perf!!!
425 425
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 // obj.GetDictionary().GetKey(PdfNa me("Filter"))); 555 // obj.GetDictionary().GetKey(PdfNa me("Filter")));
556 // if (value && value->IsArray() && value->GetArray().GetSize() == 1) { 556 // if (value && value->IsArray() && value->GetArray().GetSize() == 1) {
557 // value = resolveReferenceObject(pdfContext->fPdfDoc, 557 // value = resolveReferenceObject(pdfContext->fPdfDoc,
558 // &value->GetArray()[0]); 558 // &value->GetArray()[0]);
559 // } 559 // }
560 // if (value && value->IsName() && value->GetName().GetName() == "DCTDecode") { 560 // if (value && value->IsName() && value->GetName().GetName() == "DCTDecode") {
561 // SkStream stream = SkStream:: 561 // SkStream stream = SkStream::
562 // SkImageDecoder::Factory() 562 // SkImageDecoder::Factory()
563 // } 563 // }
564 564
565 int bytesPerLine = uncompressedStreamLength / height; 565 int bytesPerLine = (int)(uncompressedStreamLength / height);
566 #ifdef PDF_TRACE 566 #ifdef PDF_TRACE
567 if (uncompressedStreamLength % height != 0) { 567 if (uncompressedStreamLength % height != 0) {
568 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n"); 568 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n");
569 } 569 }
570 #endif 570 #endif
571 571
572 SkBitmap bitmap = transferImageStreamToBitmap( 572 SkBitmap bitmap = transferImageStreamToBitmap(
573 (unsigned char*)uncompressedStream, uncompressedStreamLength, 573 (unsigned char*)uncompressedStream, uncompressedStreamLength,
574 (int)width, (int)height, bytesPerLine, 574 (int)width, (int)height, bytesPerLine,
575 (int)bpc, colorSpace, 575 (int)bpc, colorSpace,
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 1083
1084 if (pdfContext->fGraphicsState.fHasClipPathToApply) { 1084 if (pdfContext->fGraphicsState.fHasClipPathToApply) {
1085 #ifndef PDF_DEBUG_NO_CLIPING 1085 #ifndef PDF_DEBUG_NO_CLIPING
1086 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters ect_Op, true); 1086 canvas->clipPath(pdfContext->fGraphicsState.fClipPath, SkRegion::kInters ect_Op, true);
1087 #endif 1087 #endif
1088 } 1088 }
1089 1089
1090 //pdfContext->fGraphicsState.fClipPath.reset(); 1090 //pdfContext->fGraphicsState.fClipPath.reset();
1091 pdfContext->fGraphicsState.fHasClipPathToApply = false; 1091 pdfContext->fGraphicsState.fHasClipPathToApply = false;
1092 1092
1093 return kPartial_PdfResult; 1093 return kOK_PdfResult;
1094 1094
1095 } 1095 }
1096 1096
1097 static PdfResult PdfOp_S(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1097 static PdfResult PdfOp_S(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1098 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, false, false); 1098 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, false, false);
1099 } 1099 }
1100 1100
1101 static PdfResult PdfOp_s(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1101 static PdfResult PdfOp_s(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1102 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, true, false); 1102 return PdfOp_fillAndStroke(pdfContext, canvas, false, true, true, false);
1103 } 1103 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM; 1152 pdfContext->fGraphicsState.fMatrixTlm = pdfContext->fGraphicsState.fCTM;
1153 1153
1154 return kPartial_PdfResult; 1154 return kPartial_PdfResult;
1155 } 1155 }
1156 1156
1157 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1157 static PdfResult PdfOp_ET(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1158 if (!pdfContext->fGraphicsState.fTextBlock) { 1158 if (!pdfContext->fGraphicsState.fTextBlock) {
1159 return kIgnoreError_PdfResult; 1159 return kIgnoreError_PdfResult;
1160 } 1160 }
1161 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack? 1161 // TODO(edisonn): anything else to be done once we are done with draw text? Like restore stack?
1162 return kPartial_PdfResult; 1162 return kOK_PdfResult;
1163 } 1163 }
1164 1164
1165 PdfResult skpdfGraphicsStateApplyFontCore(PdfContext* pdfContext, const SkPdfObj ect* fontName, double fontSize) { 1165 PdfResult skpdfGraphicsStateApplyFontCore(PdfContext* pdfContext, const SkPdfObj ect* fontName, double fontSize) {
1166 #ifdef PDF_TRACE 1166 #ifdef PDF_TRACE
1167 printf("font name: %s\n", fontName->nameValue2().c_str()); 1167 printf("font name: %s\n", fontName->nameValue2().c_str());
1168 #endif 1168 #endif
1169 1169
1170 if (pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) { 1170 if (!pdfContext->fGraphicsState.fResources->Font(pdfContext->fPdfDoc)) {
1171 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfCo ntext->fPdfDoc)->get(fontName); 1171 // TODO(edisonn): try to recover and draw it any way?
1172 objFont = pdfContext->fPdfDoc->resolveReference(objFont); 1172 return kIgnoreError_PdfResult;
1173 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDicti onary(objFont)) { 1173 }
1174 // TODO(edisonn): try to recover and draw it any way?
1175 return kIgnoreError_PdfResult;
1176 }
1177 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont;
1178 1174
1179 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc , fd); 1175 SkPdfObject* objFont = pdfContext->fGraphicsState.fResources->Font(pdfContex t->fPdfDoc)->get(fontName);
1176 objFont = pdfContext->fPdfDoc->resolveReference(objFont);
1177 if (kNone_SkPdfObjectType == pdfContext->fPdfDoc->mapper()->mapFontDictionar y(objFont)) {
1178 // TODO(edisonn): try to recover and draw it any way?
1179 return kIgnoreError_PdfResult;
1180 }
1180 1181
1181 if (skfont) { 1182 SkPdfFontDictionary* fd = (SkPdfFontDictionary*)objFont;
1182 pdfContext->fGraphicsState.fSkFont = skfont; 1183
1183 } 1184 SkPdfFont* skfont = SkPdfFont::fontFromPdfDictionary(pdfContext->fPdfDoc, fd );
1185
1186 if (skfont) {
1187 pdfContext->fGraphicsState.fSkFont = skfont;
1184 } 1188 }
1185 pdfContext->fGraphicsState.fCurFontSize = fontSize; 1189 pdfContext->fGraphicsState.fCurFontSize = fontSize;
1186 return kIgnoreError_PdfResult; 1190 return kOK_PdfResult;
1187 } 1191 }
1188 1192
1189 //font size Tf Set the text font, Tf 1193 //font size Tf Set the text font, Tf
1190 //, to font and the text font size, Tfs, to size. font is the name of a 1194 //, to font and the text font size, Tfs, to size. font is the name of a
1191 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is 1195 //font resource in the Fontsubdictionary of the current resource dictionary; siz e is
1192 //a number representing a scale factor. There is no initial value for either fon t or 1196 //a number representing a scale factor. There is no initial value for either fon t or
1193 //size; they must be specified explicitly using Tf before any text is shown. 1197 //size; they must be specified explicitly using Tf before any text is shown.
1194 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1198 static PdfResult PdfOp_Tf(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1195 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop(); 1199 double fontSize = pdfContext->fObjectStack.top()->numberValue(); pdfCont ext->fObjectStack.pop();
1196 SkPdfObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop(); 1200 SkPdfObject* fontName = pdfContext->fObjectStack.top(); pdfContext->fObjectStack.pop();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop(); 1321 c[i] = pdfContext->fObjectStack.top()->numberValue(); pdfCon text->fObjectStack.pop();
1318 // } else { 1322 // } else {
1319 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop(); 1323 // v[i] = pdfContext->fObjectStack.top()->intValue(); pdfConte xt->fObjectStack.pop();
1320 } 1324 }
1321 } 1325 }
1322 1326
1323 // TODO(edisonn): Now, set that color. Only DeviceRGB supported. 1327 // TODO(edisonn): Now, set that color. Only DeviceRGB supported.
1324 // TODO(edisonn): do possible field values to enum at parsing time! 1328 // TODO(edisonn): do possible field values to enum at parsing time!
1325 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB 1329 // TODO(edisonn): support also abreviations /DeviceRGB == /RGB
1326 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS pace.equals("RGB")) { 1330 if (colorOperator->fColorSpace.equals("DeviceRGB") || colorOperator->fColorS pace.equals("RGB")) {
1327 colorOperator->setRGBColor(SkColorSetRGB(255*c[0], 255*c[1], 255*c[2])); 1331 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*c[0]), (U8CPU)(255* c[1]), (U8CPU)(255*c[2])));
1328 } 1332 }
1329 return kPartial_PdfResult; 1333 return kPartial_PdfResult;
1330 } 1334 }
1331 1335
1332 static PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1336 static PdfResult PdfOp_SC(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1333 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1337 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1334 } 1338 }
1335 1339
1336 static PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1340 static PdfResult PdfOp_sc(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1337 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1341 return PdfOp_SC_sc(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 static PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1374 static PdfResult PdfOp_g(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1371 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g); 1375 return PdfOp_G_g(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrokin g);
1372 } 1376 }
1373 1377
1374 static PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) { 1378 static PdfResult PdfOp_RG_rg(PdfContext* pdfContext, SkCanvas* canvas, SkPdfColo rOperator* colorOperator) {
1375 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1379 double b = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1376 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1380 double g = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1377 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop(); 1381 double r = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO bjectStack.pop();
1378 1382
1379 colorOperator->fColorSpace = strings_DeviceRGB; 1383 colorOperator->fColorSpace = strings_DeviceRGB;
1380 colorOperator->setRGBColor(SkColorSetRGB(255*r, 255*g, 255*b)); 1384 colorOperator->setRGBColor(SkColorSetRGB((U8CPU)(255*r), (U8CPU)(255*g), (U8 CPU)(255*b)));
1381 return kOK_PdfResult; 1385 return kOK_PdfResult;
1382 } 1386 }
1383 1387
1384 static PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1388 static PdfResult PdfOp_RG(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1385 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking ); 1389 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fStroking );
1386 } 1390 }
1387 1391
1388 static PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1392 static PdfResult PdfOp_rg(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1389 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing); 1393 return PdfOp_RG_rg(pdfContext, canvas, &pdfContext->fGraphicsState.fNonStrok ing);
1390 } 1394 }
(...skipping 21 matching lines...) Expand all
1412 static PdfResult PdfOp_W(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) { 1416 static PdfResult PdfOp_W(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope r** looper) {
1413 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; 1417 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath;
1414 pdfContext->fGraphicsState.fHasClipPathToApply = true; 1418 pdfContext->fGraphicsState.fHasClipPathToApply = true;
1415 1419
1416 return kOK_PdfResult; 1420 return kOK_PdfResult;
1417 } 1421 }
1418 1422
1419 static PdfResult PdfOp_W_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) { 1423 static PdfResult PdfOp_W_star(PdfContext* pdfContext, SkCanvas* canvas, PdfToken Looper** looper) {
1420 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath; 1424 pdfContext->fGraphicsState.fClipPath = pdfContext->fGraphicsState.fPath;
1421 1425
1422 #ifdef PDF_TRACE
1423 if (pdfContext->fGraphicsState.fClipPath.isRect(NULL)) {
1424 printf("CLIP IS RECT\n");
1425 }
1426 #endif
1427
1428 // TODO(edisonn): there seem to be a bug with clipPath of a rect with even o dd.
1429 pdfContext->fGraphicsState.fClipPath.setFillType(SkPath::kEvenOdd_FillType); 1426 pdfContext->fGraphicsState.fClipPath.setFillType(SkPath::kEvenOdd_FillType);
1430 pdfContext->fGraphicsState.fHasClipPathToApply = true; 1427 pdfContext->fGraphicsState.fHasClipPathToApply = true;
1431 1428
1432 return kPartial_PdfResult; 1429 return kOK_PdfResult;
1433 } 1430 }
1434 1431
1435 static PdfResult PdfOp_BX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1432 static PdfResult PdfOp_BX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1436 *looper = new PdfCompatibilitySectionLooper(); 1433 *looper = new PdfCompatibilitySectionLooper();
1437 return kOK_PdfResult; 1434 return kOK_PdfResult;
1438 } 1435 }
1439 1436
1440 static PdfResult PdfOp_EX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) { 1437 static PdfResult PdfOp_EX(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop er** looper) {
1441 #ifdef ASSERT_BAD_PDF_OPS 1438 #ifdef ASSERT_BAD_PDF_OPS
1442 SkASSERT(false); // EX must be consumed by PdfCompatibilitySectionLooper, b ut let's 1439 SkASSERT(false); // EX must be consumed by PdfCompatibilitySectionLooper, b ut let's
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 2209
2213 rect = SkRect::MakeWH(width, height); 2210 rect = SkRect::MakeWH(width, height);
2214 2211
2215 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2212 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2216 2213
2217 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2214 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2218 SkCanvas canvas(device); 2215 SkCanvas canvas(device);
2219 2216
2220 return renderer.renderPage(page, &canvas, rect); 2217 return renderer.renderPage(page, &canvas, rect);
2221 } 2218 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698