OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 418 |
419 push(); | 419 push(); |
420 SkPDFUtils::AppendTransform(matrix, fContentStream); | 420 SkPDFUtils::AppendTransform(matrix, fContentStream); |
421 currentEntry()->fMatrix = matrix; | 421 currentEntry()->fMatrix = matrix; |
422 } | 422 } |
423 | 423 |
424 void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) { | 424 void GraphicStackState::updateDrawingState(const GraphicStateEntry& state) { |
425 // PDF treats a shader as a color, so we only set one or the other. | 425 // PDF treats a shader as a color, so we only set one or the other. |
426 if (state.fShaderIndex >= 0) { | 426 if (state.fShaderIndex >= 0) { |
427 if (state.fShaderIndex != currentEntry()->fShaderIndex) { | 427 if (state.fShaderIndex != currentEntry()->fShaderIndex) { |
428 SkString resourceName = SkPDFResourceDict::getResourceName( | 428 SkPDFUtils::ApplyPattern(state.fShaderIndex, fContentStream); |
429 SkPDFResourceDict::kPattern_ResourceType, | |
430 state.fShaderIndex); | |
431 fContentStream->writeText("/Pattern CS /Pattern cs /"); | |
432 fContentStream->writeText(resourceName.c_str()); | |
433 fContentStream->writeText(" SCN /"); | |
434 fContentStream->writeText(resourceName.c_str()); | |
435 fContentStream->writeText(" scn\n"); | |
436 currentEntry()->fShaderIndex = state.fShaderIndex; | 429 currentEntry()->fShaderIndex = state.fShaderIndex; |
437 } | 430 } |
438 } else { | 431 } else { |
439 if (state.fColor != currentEntry()->fColor || | 432 if (state.fColor != currentEntry()->fColor || |
440 currentEntry()->fShaderIndex >= 0) { | 433 currentEntry()->fShaderIndex >= 0) { |
441 emit_pdf_color(state.fColor, fContentStream); | 434 emit_pdf_color(state.fColor, fContentStream); |
442 fContentStream->writeText("RG "); | 435 fContentStream->writeText("RG "); |
443 emit_pdf_color(state.fColor, fContentStream); | 436 emit_pdf_color(state.fColor, fContentStream); |
444 fContentStream->writeText("rg\n"); | 437 fContentStream->writeText("rg\n"); |
445 currentEntry()->fColor = state.fColor; | 438 currentEntry()->fColor = state.fColor; |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 SkMatrix identity; | 1393 SkMatrix identity; |
1401 identity.reset(); | 1394 identity.reset(); |
1402 SkDraw draw; | 1395 SkDraw draw; |
1403 draw.fMatrix = &identity; | 1396 draw.fMatrix = &identity; |
1404 draw.fClip = &clipRegion; | 1397 draw.fClip = &clipRegion; |
1405 draw.fClipStack = clipStack; | 1398 draw.fClipStack = clipStack; |
1406 SkPaint stockPaint; | 1399 SkPaint stockPaint; |
1407 this->drawPaint(draw, stockPaint); | 1400 this->drawPaint(draw, stockPaint); |
1408 SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice()
); | 1401 SkAutoTUnref<SkPDFFormXObject> maskFormXObject(createFormXObjectFromDevice()
); |
1409 SkAutoTUnref<SkPDFGraphicState> sMaskGS( | 1402 SkAutoTUnref<SkPDFGraphicState> sMaskGS( |
1410 SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip)); | 1403 SkPDFGraphicState::GetSMaskGraphicState(maskFormXObject, invertClip, |
| 1404 SkPDFGraphicState::kAlpha_SMaskM
ode)); |
1411 | 1405 |
1412 // Draw the xobject with the clip as a mask. | 1406 // Draw the xobject with the clip as a mask. |
1413 ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, | 1407 ScopedContentEntry content(this, &fExistingClipStack, fExistingClipRegion, |
1414 identity, stockPaint); | 1408 identity, stockPaint); |
1415 if (!content.entry()) { | 1409 if (!content.entry()) { |
1416 return; | 1410 return; |
1417 } | 1411 } |
1418 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1412 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
1419 &content.entry()->fContent); | 1413 &content.entry()->fContent); |
1420 SkPDFUtils::DrawFormXObject(fXObjectResources.count(), | 1414 SkPDFUtils::DrawFormXObject(fXObjectResources.count(), |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 fExistingClipRegion, identity, | 1550 fExistingClipRegion, identity, |
1557 stockPaint); | 1551 stockPaint); |
1558 if (!inClipContentEntry.entry()) { | 1552 if (!inClipContentEntry.entry()) { |
1559 return; | 1553 return; |
1560 } | 1554 } |
1561 | 1555 |
1562 SkAutoTUnref<SkPDFGraphicState> sMaskGS; | 1556 SkAutoTUnref<SkPDFGraphicState> sMaskGS; |
1563 if (xfermode == SkXfermode::kSrcIn_Mode || | 1557 if (xfermode == SkXfermode::kSrcIn_Mode || |
1564 xfermode == SkXfermode::kSrcOut_Mode) { | 1558 xfermode == SkXfermode::kSrcOut_Mode) { |
1565 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( | 1559 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
1566 dst, xfermode == SkXfermode::kSrcOut_Mode)); | 1560 dst, |
| 1561 xfermode == SkXfermode::kSrcOut_Mode, |
| 1562 SkPDFGraphicState::kAlpha_SMaskMode)); |
1567 fXObjectResources.push(srcFormXObject.get()); | 1563 fXObjectResources.push(srcFormXObject.get()); |
1568 srcFormXObject.get()->ref(); | 1564 srcFormXObject.get()->ref(); |
1569 } else { | 1565 } else { |
1570 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( | 1566 sMaskGS.reset(SkPDFGraphicState::GetSMaskGraphicState( |
1571 srcFormXObject.get(), xfermode == SkXfermode::kDstOut_Mode)); | 1567 srcFormXObject.get(), |
| 1568 xfermode == SkXfermode::kDstOut_Mode, |
| 1569 SkPDFGraphicState::kAlpha_SMaskMode)); |
1572 // dst already added to fXObjectResources in drawFormXObjectWithClip. | 1570 // dst already added to fXObjectResources in drawFormXObjectWithClip. |
1573 } | 1571 } |
1574 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1572 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
1575 &inClipContentEntry.entry()->fContent); | 1573 &inClipContentEntry.entry()->fContent); |
1576 | 1574 |
1577 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, | 1575 SkPDFUtils::DrawFormXObject(fXObjectResources.count() - 1, |
1578 &inClipContentEntry.entry()->fContent); | 1576 &inClipContentEntry.entry()->fContent); |
1579 | 1577 |
1580 sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); | 1578 sMaskGS.reset(SkPDFGraphicState::GetNoSMaskGraphicState()); |
1581 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), | 1579 SkPDFUtils::ApplyGraphicState(addGraphicStateResource(sMaskGS.get()), |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 } | 1753 } |
1756 | 1754 |
1757 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, | 1755 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
1758 SkCanvas::Config8888) { | 1756 SkCanvas::Config8888) { |
1759 return false; | 1757 return false; |
1760 } | 1758 } |
1761 | 1759 |
1762 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { | 1760 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
1763 return false; | 1761 return false; |
1764 } | 1762 } |
OLD | NEW |