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

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

Issue 21738005: pdfviewer: add indexed rbg image support, enhanche caching(setData) for SkPdfObject (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
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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (grayColortable == NULL) { 428 if (grayColortable == NULL) {
429 SkPMColor* colors = new SkPMColor[256]; 429 SkPMColor* colors = new SkPMColor[256];
430 for (int i = 0 ; i < 256; i++) { 430 for (int i = 0 ; i < 256; i++) {
431 colors[i] = SkPreMultiplyARGB(255, i, i, i); 431 colors[i] = SkPreMultiplyARGB(255, i, i, i);
432 } 432 }
433 grayColortable = new SkColorTable(colors, 256); 433 grayColortable = new SkColorTable(colors, 256);
434 } 434 }
435 return grayColortable; 435 return grayColortable;
436 } 436 }
437 437
438 static SkBitmap transferImageStreamToBitmap(const unsigned char* uncompressedStr eam, size_t uncompressedStreamLength, 438 static SkBitmap* transferImageStreamToBitmap(const unsigned char* uncompressedSt ream, size_t uncompressedStreamLength,
439 int width, int height, int bytesPerLine, 439 int width, int height, int bytesPerLine,
440 int bpc, const std::string& colorSpace, 440 int bpc, const std::string& colorSpace,
441 bool transparencyMask) { 441 bool transparencyMask) {
442 SkBitmap bitmap; 442 SkBitmap* bitmap = new SkBitmap();
443 443
444 //int components = GetColorSpaceComponents(colorSpace); 444 //int components = GetColorSpaceComponents(colorSpace);
445 //#define MAX_COMPONENTS 10 445 //#define MAX_COMPONENTS 10
446 446
447 // TODO(edisonn): assume start of lines are aligned at 32 bits? 447 // TODO(edisonn): assume start of lines are aligned at 32 bits?
448 // Is there a faster way to load the uncompressed stream into a bitmap? 448 // Is there a faster way to load the uncompressed stream into a bitmap?
449 449
450 // minimal support for now 450 // minimal support for now
451 if ((colorSpace == "DeviceRGB" || colorSpace == "RGB") && bpc == 8) { 451 if ((colorSpace == "DeviceRGB" || colorSpace == "RGB") && bpc == 8) {
452 SkColor* uncompressedStreamArgb = (SkColor*)malloc(width * height * size of(SkColor)); 452 SkColor* uncompressedStreamArgb = (SkColor*)malloc(width * height * size of(SkColor));
453 453
454 for (int h = 0 ; h < height; h++) { 454 for (int h = 0 ; h < height; h++) {
455 long i = width * (h); 455 long i = width * (h);
456 for (int w = 0 ; w < width; w++) { 456 for (int w = 0 ; w < width; w++) {
457 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 * w], 457 uncompressedStreamArgb[i] = SkColorSetRGB(uncompressedStream[3 * w],
458 uncompressedStream[3 * w + 1], 458 uncompressedStream[3 * w + 1],
459 uncompressedStream[3 * w + 2]); 459 uncompressedStream[3 * w + 2]);
460 i++; 460 i++;
461 } 461 }
462 uncompressedStream += bytesPerLine; 462 uncompressedStream += bytesPerLine;
463 } 463 }
464 464
465 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 465 bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
466 bitmap.setPixels(uncompressedStreamArgb); 466 bitmap->setPixels(uncompressedStreamArgb);
467 } 467 }
468 else if ((colorSpace == "DeviceGray" || colorSpace == "Gray") && bpc == 8) { 468 else if ((colorSpace == "DeviceGray" || colorSpace == "Gray") && bpc == 8) {
469 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei ght); 469 unsigned char* uncompressedStreamA8 = (unsigned char*)malloc(width * hei ght);
470 470
471 for (int h = 0 ; h < height; h++) { 471 for (int h = 0 ; h < height; h++) {
472 long i = width * (h); 472 long i = width * (h);
473 for (int w = 0 ; w < width; w++) { 473 for (int w = 0 ; w < width; w++) {
474 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS tream[w] : 474 uncompressedStreamA8[i] = transparencyMask ? 255 - uncompressedS tream[w] :
475 uncompressedStream[ w]; 475 uncompressedStream[ w];
476 i++; 476 i++;
477 } 477 }
478 uncompressedStream += bytesPerLine; 478 uncompressedStream += bytesPerLine;
479 } 479 }
480 480
481 bitmap.setConfig(transparencyMask ? SkBitmap::kA8_Config : SkBitmap::kIn dex8_Config, 481 bitmap->setConfig(transparencyMask ? SkBitmap::kA8_Config : SkBitmap::kI ndex8_Config,
482 width, height); 482 width, height);
483 bitmap.setPixels(uncompressedStreamA8, transparencyMask ? NULL : getGray Colortable()); 483 bitmap->setPixels(uncompressedStreamA8, transparencyMask ? NULL : getGra yColortable());
484 } 484 }
485 485
486 // TODO(edisonn): Report Warning, NYI, or error 486 // TODO(edisonn): Report Warning, NYI, or error
487 return bitmap; 487 return bitmap;
488 } 488 }
489 489
490 // utils 490 // utils
491 491
492 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec t 492 // TODO(edisonn): add cache, or put the bitmap property directly on the PdfObjec t
493 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config 493 // TODO(edisonn): deal with colorSpaces, we could add them to SkBitmap::Config
494 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2 22, 444 to closest 494 // TODO(edisonn): preserve A1 format that skia knows, + fast convert from 111, 2 22, 444 to closest
495 // skia format, through a table 495 // skia format, through a table
496 496
497 // this functions returns the image, it does not look at the smask. 497 // this functions returns the image, it does not look at the smask.
498 498
499 static SkBitmap getImageFromObject(PdfContext* pdfContext, SkPdfImageDictionary* image, bool transparencyMask) { 499 static SkBitmap* getImageFromObjectCore(PdfContext* pdfContext, SkPdfImageDictio nary* image, bool transparencyMask) {
500 if (image == NULL || !image->hasStream()) { 500 if (image == NULL || !image->hasStream()) {
501 // TODO(edisonn): report warning to be used in testing. 501 // TODO(edisonn): report warning to be used in testing.
502 return SkBitmap(); 502 return NULL;
503 } 503 }
504 504
505 int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc); 505 int64_t bpc = image->BitsPerComponent(pdfContext->fPdfDoc);
506 int64_t width = image->Width(pdfContext->fPdfDoc); 506 int64_t width = image->Width(pdfContext->fPdfDoc);
507 int64_t height = image->Height(pdfContext->fPdfDoc); 507 int64_t height = image->Height(pdfContext->fPdfDoc);
508 std::string colorSpace = "DeviceRGB"; 508 std::string colorSpace = "DeviceRGB";
509 509
510 bool indexed = false;
511 SkPMColor colors[256];
512 int cnt = 0;
513
510 // TODO(edisonn): color space can be an array too! 514 // TODO(edisonn): color space can be an array too!
511 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) { 515 if (image->isColorSpaceAName(pdfContext->fPdfDoc)) {
512 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc); 516 colorSpace = image->getColorSpaceAsName(pdfContext->fPdfDoc);
517 } else if (image->isColorSpaceAArray(pdfContext->fPdfDoc)) {
518 SkPdfArray* array = image->getColorSpaceAsArray(pdfContext->fPdfDoc);
519 if (array && array->size() == 4 && array->objAtAIndex(0)->isName("Indexe d") &&
520 (array->objAtAIndex(1)->isName("Devic eRGB") || array->objAtAIndex(1)->isName("RGB")) &&
521 array->objAtAIndex(2)->isInteger() &&
522 array->objAtAIndex(3)->isHexString()
523 ) {
524 // TODO(edisonn): suport only DeviceRGB for now.
525 indexed = true;
526 cnt = array->objAtAIndex(2)->intValue() + 1;
527 if (cnt > 256) {
528 // TODO(edionn): report NYIs
529 return NULL;
530 }
531 SkColorTable colorTable(cnt);
532 NotOwnedString data = array->objAtAIndex(3)->strRef();
533 if (data.fBytes != (unsigned int)cnt * 3) {
534 // TODO(edionn): report error/warning
535 return NULL;
536 }
537 for (int i = 0 ; i < cnt; i++) {
538 colors[i] = SkPreMultiplyARGB(0xff, data.fBuffer[3 * i], data.fB uffer[3 * i + 1], data.fBuffer[3 * i + 2]);
539 }
540 }
513 } 541 }
514 542
515 /* 543 /*
516 bool imageMask = image->imageMask(); 544 bool imageMask = image->imageMask();
517 545
518 if (imageMask) { 546 if (imageMask) {
519 if (bpc != 0 && bpc != 1) { 547 if (bpc != 0 && bpc != 1) {
520 // TODO(edisonn): report warning to be used in testing. 548 // TODO(edisonn): report warning to be used in testing.
521 return SkBitmap(); 549 return SkBitmap();
522 } 550 }
523 bpc = 1; 551 bpc = 1;
524 } 552 }
525 */ 553 */
526 554
527 const unsigned char* uncompressedStream = NULL; 555 const unsigned char* uncompressedStream = NULL;
528 size_t uncompressedStreamLength = 0; 556 size_t uncompressedStreamLength = 0;
529 557
530 SkPdfStream* stream = (SkPdfStream*)image; 558 SkPdfStream* stream = (SkPdfStream*)image;
531 559
532 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres sedStreamLength) || 560 if (!stream || !stream->GetFilteredStreamRef(&uncompressedStream, &uncompres sedStreamLength) ||
533 uncompressedStream == NULL || uncompressedStreamLength == 0) { 561 uncompressedStream == NULL || uncompressedStreamLength == 0) {
534 // TODO(edisonn): report warning to be used in testing. 562 // TODO(edisonn): report warning to be used in testing.
535 return SkBitmap(); 563 return NULL;
536 } 564 }
537 565
538 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre am; 566 SkPdfStreamCommonDictionary* streamDict = (SkPdfStreamCommonDictionary*)stre am;
539 567
540 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) && 568 if (streamDict->has_Filter() && ((streamDict->isFilterAName(NULL) &&
541 streamDict->getFilterAsName(NULL) == " DCTDecode") || 569 streamDict->getFilterAsName(NULL) == " DCTDecode") ||
542 (streamDict->isFilterAArray(NULL) && 570 (streamDict->isFilterAArray(NULL) &&
543 streamDict->getFilterAsArray(NULL)->si ze() > 0 && 571 streamDict->getFilterAsArray(NULL)->si ze() > 0 &&
544 streamDict->getFilterAsArray(NULL)->ob jAtAIndex(0)->isName() && 572 streamDict->getFilterAsArray(NULL)->ob jAtAIndex(0)->isName() &&
545 streamDict->getFilterAsArray(NULL)->ob jAtAIndex(0)->nameValue2() == "DCTDecode"))) { 573 streamDict->getFilterAsArray(NULL)->ob jAtAIndex(0)->nameValue2() == "DCTDecode"))) {
546 SkBitmap bitmap; 574 SkBitmap* bitmap = new SkBitmap();
547 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt h, &bitmap); 575 SkImageDecoder::DecodeMemory(uncompressedStream, uncompressedStreamLengt h, bitmap);
548 return bitmap; 576 return bitmap;
549 } 577 }
550 578
551 579
552 580
553 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw ... 581 // TODO (edisonn): Fast Jpeg(DCTDecode) draw, or fast PNG(FlateDecode) draw ...
554 // PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc, 582 // PdfObject* value = resolveReferenceObject(pdfContext->fPdfDoc,
555 // obj.GetDictionary().GetKey(PdfNa me("Filter"))); 583 // obj.GetDictionary().GetKey(PdfNa me("Filter")));
556 // if (value && value->IsArray() && value->GetArray().GetSize() == 1) { 584 // if (value && value->IsArray() && value->GetArray().GetSize() == 1) {
557 // value = resolveReferenceObject(pdfContext->fPdfDoc, 585 // value = resolveReferenceObject(pdfContext->fPdfDoc,
558 // &value->GetArray()[0]); 586 // &value->GetArray()[0]);
559 // } 587 // }
560 // if (value && value->IsName() && value->GetName().GetName() == "DCTDecode") { 588 // if (value && value->IsName() && value->GetName().GetName() == "DCTDecode") {
561 // SkStream stream = SkStream:: 589 // SkStream stream = SkStream::
562 // SkImageDecoder::Factory() 590 // SkImageDecoder::Factory()
563 // } 591 // }
564 592
593 // TODO(edisonn): assumes RGB for now, since it is the only onwe implemented
594 if (indexed) {
595 SkBitmap* bitmap = new SkBitmap();
596 bitmap->setConfig(SkBitmap::kIndex8_Config, width, height);
597 SkColorTable* colorTable = new SkColorTable(colors, cnt);
598 bitmap->setPixels((void*)uncompressedStream, colorTable);
599 return bitmap;
600 }
601
565 int bytesPerLine = (int)(uncompressedStreamLength / height); 602 int bytesPerLine = (int)(uncompressedStreamLength / height);
566 #ifdef PDF_TRACE 603 #ifdef PDF_TRACE
567 if (uncompressedStreamLength % height != 0) { 604 if (uncompressedStreamLength % height != 0) {
568 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n"); 605 printf("Warning uncompressedStreamLength modulo height != 0 !!!\n");
569 } 606 }
570 #endif 607 #endif
571 608
572 SkBitmap bitmap = transferImageStreamToBitmap( 609 SkBitmap* bitmap = transferImageStreamToBitmap(
573 (unsigned char*)uncompressedStream, uncompressedStreamLength, 610 (unsigned char*)uncompressedStream, uncompressedStreamLength,
574 (int)width, (int)height, bytesPerLine, 611 (int)width, (int)height, bytesPerLine,
575 (int)bpc, colorSpace, 612 (int)bpc, colorSpace,
576 transparencyMask); 613 transparencyMask);
577 614
578 return bitmap; 615 return bitmap;
579 } 616 }
580 617
581 static SkBitmap getSmaskFromObject(PdfContext* pdfContext, SkPdfImageDictionary* obj) { 618 static SkBitmap* getImageFromObject(PdfContext* pdfContext, SkPdfImageDictionary * image, bool transparencyMask) {
619 if (!transparencyMask) {
620 if (!image->hasData(SkPdfObject::kBitmap_Data)) {
621 SkBitmap* bitmap = getImageFromObjectCore(pdfContext, image, transpa rencyMask);
622 image->setData(bitmap, SkPdfObject::kBitmap_Data);
623 }
624 return (SkBitmap*) image->data(SkPdfObject::kBitmap_Data);
625 } else {
626 return getImageFromObjectCore(pdfContext, image, transparencyMask);
627 }
628 }
629
630 static SkBitmap* getSmaskFromObject(PdfContext* pdfContext, SkPdfImageDictionary * obj) {
582 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc); 631 SkPdfImageDictionary* sMask = obj->SMask(pdfContext->fPdfDoc);
583 632
584 if (sMask) { 633 if (sMask) {
585 return getImageFromObject(pdfContext, sMask, true); 634 return getImageFromObject(pdfContext, sMask, true);
586 } 635 }
587 636
588 // TODO(edisonn): implement GS SMask. Default to empty right now. 637 // TODO(edisonn): implement GS SMask. Default to empty right now.
589 return pdfContext->fGraphicsState.fSMask; 638 return pdfContext->fGraphicsState.fSMask;
590 } 639 }
591 640
592 static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf ImageDictionary* skpdfimage) { 641 static PdfResult doXObject_Image(PdfContext* pdfContext, SkCanvas* canvas, SkPdf ImageDictionary* skpdfimage) {
593 if (skpdfimage == NULL) { 642 if (skpdfimage == NULL) {
594 return kIgnoreError_PdfResult; 643 return kIgnoreError_PdfResult;
595 } 644 }
596 645
597 SkBitmap image = getImageFromObject(pdfContext, skpdfimage, false); 646 SkBitmap* image = getImageFromObject(pdfContext, skpdfimage, false);
598 SkBitmap sMask = getSmaskFromObject(pdfContext, skpdfimage); 647 SkBitmap* sMask = getSmaskFromObject(pdfContext, skpdfimage);
599 648
600 canvas->save(); 649 canvas->save();
601 canvas->setMatrix(pdfContext->fGraphicsState.fCTM); 650 canvas->setMatrix(pdfContext->fGraphicsState.fCTM);
602 651
603 #if 1 652 #if 1
604 SkScalar z = SkIntToScalar(0); 653 SkScalar z = SkIntToScalar(0);
605 SkScalar one = SkIntToScalar(1); 654 SkScalar one = SkIntToScalar(1);
606 655
607 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)};
608 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)};
609 SkMatrix flip; 658 SkMatrix flip;
610 SkAssertResult(flip.setPolyToPoly(from, to, 4)); 659 SkAssertResult(flip.setPolyToPoly(from, to, 4));
611 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fCTM; 660 SkMatrix solveImageFlip = pdfContext->fGraphicsState.fCTM;
612 solveImageFlip.preConcat(flip); 661 solveImageFlip.preConcat(flip);
613 canvas->setMatrix(solveImageFlip); 662 canvas->setMatrix(solveImageFlip);
614 #endif 663 #endif
615 664
616 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(1.0), SkDoubleToScalar(1.0)); 665 SkRect dst = SkRect::MakeXYWH(SkDoubleToScalar(0.0), SkDoubleToScalar(0.0), SkDoubleToScalar(1.0), SkDoubleToScalar(1.0));
617 666
618 // TODO(edisonn): soft mask type? alpha/luminosity. 667 // TODO(edisonn): soft mask type? alpha/luminosity.
619 if (sMask.empty()) { 668 if (!sMask || sMask->empty()) {
620 canvas->drawBitmapRect(image, dst, NULL); 669 canvas->drawBitmapRect(*image, dst, NULL);
621 } else { 670 } else {
622 canvas->saveLayer(&dst, NULL); 671 canvas->saveLayer(&dst, NULL);
623 canvas->drawBitmapRect(image, dst, NULL); 672 canvas->drawBitmapRect(*image, dst, NULL);
624 SkPaint xfer; 673 SkPaint xfer;
625 pdfContext->fGraphicsState.applyGraphicsState(&xfer, false); 674 pdfContext->fGraphicsState.applyGraphicsState(&xfer, false);
626 // TODO(edisonn): is the blend mode specified already implicitly/explici tly in pdf? 675 // TODO(edisonn): is the blend mode specified already implicitly/explici tly in pdf?
627 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M ode 676 xfer.setXfermodeMode(SkXfermode::kSrcOut_Mode); // SkXfermode::kSdtOut_M ode
628 canvas->drawBitmapRect(sMask, dst, &xfer); 677 canvas->drawBitmapRect(*sMask, dst, &xfer);
629 canvas->restore(); 678 canvas->restore();
630 } 679 }
631 680
632 canvas->restore(); 681 canvas->restore();
633 682
634 return kPartial_PdfResult; 683 return kPartial_PdfResult;
635 } 684 }
636 685
637 //TODO(edisonn): options for implementing isolation and knockout 686 //TODO(edisonn): options for implementing isolation and knockout
638 // 1) emulate them (current solution) 687 // 1) emulate them (current solution)
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 path.setFillType(SkPath::kEvenOdd_FillType); 1297 path.setFillType(SkPath::kEvenOdd_FillType);
1249 } 1298 }
1250 canvas->clipPath(path); 1299 canvas->clipPath(path);
1251 1300
1252 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfObjectType) { 1301 if (pdfContext->fPdfDoc->mapper()->mapType1PatternDictionary(pdf Context->fGraphicsState.fNonStroking.fPattern) != kNone_SkPdfObjectType) {
1253 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern; 1302 SkPdfType1PatternDictionary* pattern = (SkPdfType1PatternDic tionary*)pdfContext->fGraphicsState.fNonStroking.fPattern;
1254 1303
1255 // TODO(edisonn): constants 1304 // TODO(edisonn): constants
1256 // TODO(edisonn): colored 1305 // TODO(edisonn): colored
1257 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) { 1306 if (pattern->PaintType(pdfContext->fPdfDoc) == 1) {
1258 int xStep = (int)pattern->XStep(pdfContext->fPdfDoc); 1307 // TODO(edisonn): don't use abs, iterate as asked, if th e cells intersect
1259 int yStep = (int)pattern->YStep(pdfContext->fPdfDoc); 1308 // it will change the result iterating in reverse
1309 int xStep = abs((int)pattern->XStep(pdfContext->fPdfDoc) );
1310 int yStep = abs((int)pattern->YStep(pdfContext->fPdfDoc) );
1260 1311
1261 SkRect bounds = path.getBounds(); 1312 SkRect bounds = path.getBounds();
1313
1314 // TODO(edisonn): xstep and ystep can be negative, and w e need to iterate in reverse
1315 // TODO(edisonn): don't do that!
1316 bounds.sort();
1317
1262 SkScalar x; 1318 SkScalar x;
1263 SkScalar y; 1319 SkScalar y;
1264 1320
1265 // TODO(edisonn): xstep and ystep can be negative, and w e need to iterate in reverse
1266
1267 y = bounds.top(); 1321 y = bounds.top();
1268 int totalx = 0; 1322 int totalx = 0;
1269 int totaly = 0; 1323 int totaly = 0;
1270 while (y < bounds.bottom()) { 1324 while (y < bounds.bottom()) {
1271 x = bounds.left(); 1325 x = bounds.left();
1272 totalx = 0; 1326 totalx = 0;
1273 1327
1274 while (x < bounds.right()) { 1328 while (x < bounds.right()) {
1275 doXObject(pdfContext, canvas, pattern); 1329 doXObject(pdfContext, canvas, pattern);
1276 1330
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas k; 2008 SkPdfSoftMaskImageDictionary* smid = (SkPdfSoftMaskImageDictionary*)sMas k;
1955 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid, true); 2009 pdfContext->fGraphicsState.fSMask = getImageFromObject(pdfContext, smid, true);
1956 } else { 2010 } else {
1957 // TODO (edisonn): report error/warning 2011 // TODO (edisonn): report error/warning
1958 } 2012 }
1959 } 2013 }
1960 2014
1961 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string & sMask) { 2015 void skpdfGraphicsStateApplySMask_name(PdfContext* pdfContext, const std::string & sMask) {
1962 if (sMask == "None") { 2016 if (sMask == "None") {
1963 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; 2017 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL;
1964 pdfContext->fGraphicsState.fSMask = SkBitmap(); 2018 pdfContext->fGraphicsState.fSMask = NULL;
1965 return; 2019 return;
1966 } 2020 }
1967 2021
1968 //Next, get the ExtGState Dictionary from the Resource Dictionary: 2022 //Next, get the ExtGState Dictionary from the Resource Dictionary:
1969 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc); 2023 SkPdfDictionary* extGStateDictionary = pdfContext->fGraphicsState.fResources ->ExtGState(pdfContext->fPdfDoc);
1970 2024
1971 if (extGStateDictionary == NULL) { 2025 if (extGStateDictionary == NULL) {
1972 #ifdef PDF_TRACE 2026 #ifdef PDF_TRACE
1973 printf("ExtGState is NULL!\n"); 2027 printf("ExtGState is NULL!\n");
1974 #endif 2028 #endif
1975 // TODO (edisonn): report error/warning 2029 // TODO (edisonn): report error/warning
1976 return; 2030 return;
1977 } 2031 }
1978 2032
1979 SkPdfObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDictionary ->get(sMask.c_str())); 2033 SkPdfObject* obj = pdfContext->fPdfDoc->resolveReference(extGStateDictionary ->get(sMask.c_str()));
1980 if (!obj || !obj->isDictionary()) { 2034 if (!obj || !obj->isDictionary()) {
1981 // TODO (edisonn): report error/warning 2035 // TODO (edisonn): report error/warning
1982 return; 2036 return;
1983 } 2037 }
1984 2038
1985 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL; 2039 pdfContext->fGraphicsState.fSoftMaskDictionary = NULL;
1986 pdfContext->fGraphicsState.fSMask = SkBitmap(); 2040 pdfContext->fGraphicsState.fSMask = NULL;
1987 2041
1988 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary()); 2042 skpdfGraphicsStateApplySMask_dict(pdfContext, obj->asDictionary());
1989 } 2043 }
1990 2044
1991 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) { 2045 void skpdfGraphicsStateApplyAIS(PdfContext* pdfContext, bool alphaSource) {
1992 pdfContext->fGraphicsState.fAlphaSource = alphaSource; 2046 pdfContext->fGraphicsState.fAlphaSource = alphaSource;
1993 } 2047 }
1994 2048
1995 2049
1996 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is 2050 //dictName gs (PDF 1.2) Set the specified parameters in the graphics state. dictN ame is
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 2626
2573 rect = SkRect::MakeWH(width, height); 2627 rect = SkRect::MakeWH(width, height);
2574 2628
2575 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2629 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2576 2630
2577 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2631 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2578 SkCanvas canvas(device); 2632 SkCanvas canvas(device);
2579 2633
2580 return renderer.renderPage(page, &canvas, rect); 2634 return renderer.renderPage(page, &canvas, rect);
2581 } 2635 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698