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 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 } | 1519 } |
1520 | 1520 |
1521 static PdfResult PdfOp_EI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | 1521 static PdfResult PdfOp_EI(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
1522 #ifdef ASSERT_BAD_PDF_OPS | 1522 #ifdef ASSERT_BAD_PDF_OPS |
1523 SkASSERT(false); // must be processed in inline image looper, but let's | 1523 SkASSERT(false); // must be processed in inline image looper, but let's |
1524 // have the assert when testing good pdfs. | 1524 // have the assert when testing good pdfs. |
1525 #endif | 1525 #endif |
1526 return kIgnoreError_PdfResult; | 1526 return kIgnoreError_PdfResult; |
1527 } | 1527 } |
1528 | 1528 |
1529 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). | 1529 |
1530 static PdfResult PdfOp_w(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | 1530 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. |
1531 double lineWidth = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | 1531 PdfResult skpdfGraphicsStateApply_ca(PdfContext* pdfContext, double ca) { |
| 1532 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; |
| 1533 return kOK_PdfResult; |
| 1534 } |
| 1535 |
| 1536 PdfResult skpdfGraphicsStateApply_CA(PdfContext* pdfContext, double CA) { |
| 1537 pdfContext->fGraphicsState.fStroking.fOpacity = CA; |
| 1538 return kOK_PdfResult; |
| 1539 } |
| 1540 |
| 1541 PdfResult skpdfGraphicsStateApplyLW(PdfContext* pdfContext, double lineWidth) { |
1532 pdfContext->fGraphicsState.fLineWidth = lineWidth; | 1542 pdfContext->fGraphicsState.fLineWidth = lineWidth; |
| 1543 return kOK_PdfResult; |
| 1544 } |
| 1545 |
| 1546 PdfResult skpdfGraphicsStateApplyLC(PdfContext* pdfContext, int64_t lineCap) { |
| 1547 pdfContext->fGraphicsState.fLineCap = (int)lineCap; |
| 1548 return kOK_PdfResult; |
| 1549 } |
| 1550 |
| 1551 PdfResult skpdfGraphicsStateApplyLJ(PdfContext* pdfContext, int64_t lineJoin) { |
| 1552 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; |
| 1553 return kOK_PdfResult; |
| 1554 } |
| 1555 |
| 1556 PdfResult skpdfGraphicsStateApplyML(PdfContext* pdfContext, double miterLimit) { |
| 1557 pdfContext->fGraphicsState.fMiterLimit = miterLimit; |
| 1558 return kOK_PdfResult; |
| 1559 } |
| 1560 |
| 1561 // TODO(edisonn): implement all rules, as of now 3) and 5) and 6) do not seem su
ported by skia, but I am not sure |
| 1562 /* |
| 1563 1) [ ] 0 No dash; solid, unbroken lines |
| 1564 2) [3] 0 3 units on, 3 units off, … |
| 1565 3) [2] 1 1 on, 2 off, 2 on, 2 off, … |
| 1566 4) [2 1] 0 2 on, 1 off, 2 on, 1 off, … |
| 1567 5) [3 5] 6 2 off, 3 on, 5 off, 3 on, 5 off, … |
| 1568 6) [2 3] 11 1 on, 3 off, 2 on, 3 off, 2 on, … |
| 1569 */ |
| 1570 |
| 1571 PdfResult skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* intervals
, SkPdfObject* phase) { |
| 1572 int cnt = intervals->size(); |
| 1573 if (cnt >= 256) { |
| 1574 // TODO(edisonn): report error/warning, unsuported; |
| 1575 // TODO(edisonn): alloc memory |
| 1576 return kIgnoreError_PdfResult; |
| 1577 } |
| 1578 for (int i = 0; i < cnt; i++) { |
| 1579 if (!intervals->objAtAIndex(i)->isNumber()) { |
| 1580 // TODO(edisonn): report error/warning |
| 1581 return kIgnoreError_PdfResult; |
| 1582 } |
| 1583 } |
| 1584 |
| 1585 pdfContext->fGraphicsState.fDashArrayLength = cnt; |
| 1586 double total = 0; |
| 1587 for (int i = 0 ; i < cnt; i++) { |
| 1588 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); |
| 1589 total += pdfContext->fGraphicsState.fDashArray[i]; |
| 1590 } |
| 1591 pdfContext->fGraphicsState.fDashPhase = phase->scalarValue(); |
| 1592 if (pdfContext->fGraphicsState.fDashPhase == 0) { |
| 1593 // other rules, changes? |
| 1594 pdfContext->fGraphicsState.fDashPhase = total; |
| 1595 } |
1533 | 1596 |
1534 return kOK_PdfResult; | 1597 return kOK_PdfResult; |
1535 } | 1598 } |
1536 | 1599 |
1537 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). | 1600 PdfResult skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* dash) { |
1538 static PdfResult PdfOp_J(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | |
1539 pdfContext->fObjectStack.pop(); | |
1540 //double lineCap = pdfContext->fObjectStack.top()->numberValue(); pdfCon
text->fObjectStack.pop(); | |
1541 | |
1542 return kNYI_PdfResult; | |
1543 } | |
1544 | |
1545 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). | |
1546 static PdfResult PdfOp_j(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | |
1547 pdfContext->fObjectStack.pop(); | |
1548 //double lineJoin = pdfContext->fObjectStack.top()->numberValue(); pdfCo
ntext->fObjectStack.pop(); | |
1549 | |
1550 return kNYI_PdfResult; | |
1551 } | |
1552 | |
1553 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). | |
1554 static PdfResult PdfOp_M(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | |
1555 pdfContext->fObjectStack.pop(); | |
1556 //double miterLimit = pdfContext->fObjectStack.top()->numberValue(); pdf
Context->fObjectStack.pop(); | |
1557 | |
1558 return kNYI_PdfResult; | |
1559 } | |
1560 | |
1561 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on | |
1562 //page 155). | |
1563 static PdfResult PdfOp_d(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | |
1564 pdfContext->fObjectStack.pop(); | |
1565 pdfContext->fObjectStack.pop(); | |
1566 | |
1567 return kNYI_PdfResult; | |
1568 } | |
1569 | |
1570 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). | |
1571 static PdfResult PdfOp_ri(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { | |
1572 pdfContext->fObjectStack.pop(); | |
1573 | |
1574 return kNYI_PdfResult; | |
1575 } | |
1576 | |
1577 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness | |
1578 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- | |
1579 //fies the output device’s default flatness tolerance. | |
1580 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { | |
1581 pdfContext->fObjectStack.pop(); | |
1582 | |
1583 return kNYI_PdfResult; | |
1584 } | |
1585 | |
1586 | |
1587 // TODO(edisonn): security review here, make sure all parameters are valid, and
safe. | |
1588 void skpdfGraphicsStateApply_ca(PdfContext* pdfContext, double ca) { | |
1589 pdfContext->fGraphicsState.fNonStroking.fOpacity = ca; | |
1590 } | |
1591 | |
1592 void skpdfGraphicsStateApply_CA(PdfContext* pdfContext, double CA) { | |
1593 pdfContext->fGraphicsState.fStroking.fOpacity = CA; | |
1594 } | |
1595 | |
1596 void skpdfGraphicsStateApplyLW(PdfContext* pdfContext, double lineWidth) { | |
1597 pdfContext->fGraphicsState.fLineWidth = lineWidth; | |
1598 } | |
1599 | |
1600 void skpdfGraphicsStateApplyLC(PdfContext* pdfContext, int64_t lineCap) { | |
1601 pdfContext->fGraphicsState.fLineCap = (int)lineCap; | |
1602 } | |
1603 | |
1604 void skpdfGraphicsStateApplyLJ(PdfContext* pdfContext, int64_t lineJoin) { | |
1605 pdfContext->fGraphicsState.fLineJoin = (int)lineJoin; | |
1606 } | |
1607 | |
1608 void skpdfGraphicsStateApplyML(PdfContext* pdfContext, double miterLimit) { | |
1609 pdfContext->fGraphicsState.fMiterLimit = miterLimit; | |
1610 } | |
1611 | |
1612 void skpdfGraphicsStateApplyD(PdfContext* pdfContext, SkPdfArray* dash) { | |
1613 // TODO(edisonn): verify input | 1601 // TODO(edisonn): verify input |
1614 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { | 1602 if (!dash || dash->isArray() || dash->size() != 2 || !dash->objAtAIndex(0)->
isArray() || !dash->objAtAIndex(1)->isNumber()) { |
1615 // TODO(edisonn): report error/warning | 1603 // TODO(edisonn): report error/warning |
1616 return; | 1604 return kIgnoreError_PdfResult; |
1617 } | 1605 } |
1618 | 1606 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)dash->objAtAIndex(0
), dash->objAtAIndex(1)); |
1619 SkPdfArray* intervals = (SkPdfArray*)dash->objAtAIndex(0); | |
1620 int cnt = intervals->size(); | |
1621 if (cnt >= 256) { | |
1622 // TODO(edisonn): report error/warning, unsuported; | |
1623 // TODO(edisonn): alloc memory | |
1624 return; | |
1625 } | |
1626 for (int i = 0; i < cnt; i++) { | |
1627 if (!intervals->objAtAIndex(i)->isNumber()) { | |
1628 // TODO(edisonn): report error/warning | |
1629 return; | |
1630 } | |
1631 } | |
1632 | |
1633 pdfContext->fGraphicsState.fDashPhase = dash->objAtAIndex(1)->scalarValue(); | |
1634 pdfContext->fGraphicsState.fDashArrayLength = cnt; | |
1635 for (int i = 0 ; i < cnt; i++) { | |
1636 pdfContext->fGraphicsState.fDashArray[i] = intervals->objAtAIndex(i)->sc
alarValue(); | |
1637 } | |
1638 } | 1607 } |
1639 | 1608 |
1640 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize
) { | 1609 void skpdfGraphicsStateApplyFont(PdfContext* pdfContext, SkPdfArray* fontAndSize
) { |
1641 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { | 1610 if (!fontAndSize || fontAndSize->isArray() || fontAndSize->size() != 2 || !f
ontAndSize->objAtAIndex(0)->isName() || !fontAndSize->objAtAIndex(1)->isNumber()
) { |
1642 // TODO(edisonn): report error/warning | 1611 // TODO(edisonn): report error/warning |
1643 return; | 1612 return; |
1644 } | 1613 } |
1645 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); | 1614 skpdfGraphicsStateApplyFontCore(pdfContext, fontAndSize->objAtAIndex(0), fon
tAndSize->objAtAIndex(1)->numberValue()); |
1646 } | 1615 } |
1647 | 1616 |
| 1617 |
| 1618 //lineWidth w Set the line width in the graphics state (see “Line Width” on page
152). |
| 1619 static PdfResult PdfOp_w(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1620 double lw = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
| 1621 return skpdfGraphicsStateApplyLW(pdfContext, lw); |
| 1622 } |
| 1623 |
| 1624 //lineCap J Set the line cap style in the graphics state (see “Line Cap Style” o
n page 153). |
| 1625 static PdfResult PdfOp_J(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1626 int64_t lc = pdfContext->fObjectStack.top()->numberValue(); pdfContext->f
ObjectStack.pop(); |
| 1627 return skpdfGraphicsStateApplyLC(pdfContext, lc); |
| 1628 } |
| 1629 |
| 1630 //lineJoin j Set the line join style in the graphics state (see “Line Join Style
” on page 153). |
| 1631 static PdfResult PdfOp_j(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1632 double lj = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
| 1633 return skpdfGraphicsStateApplyLJ(pdfContext, lj); |
| 1634 } |
| 1635 |
| 1636 //miterLimit M Set the miter limit in the graphics state (see “Miter Limit” on p
age 153). |
| 1637 static PdfResult PdfOp_M(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1638 double ml = pdfContext->fObjectStack.top()->numberValue(); pdfContext->fO
bjectStack.pop(); |
| 1639 return skpdfGraphicsStateApplyML(pdfContext, ml); |
| 1640 } |
| 1641 |
| 1642 //dashArray dashPhase d Set the line dash pattern in the graphics state (see “Li
ne Dash Pattern” on |
| 1643 //page 155). |
| 1644 static PdfResult PdfOp_d(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1645 SkPdfObject* phase = pdfContext->fObjectStack.top(); pdfContext->fO
bjectStack.pop(); |
| 1646 SkPdfObject* array = pdfContext->fObjectStack.top(); pdfContext->fO
bjectStack.pop(); |
| 1647 |
| 1648 if (!array->isArray()) { |
| 1649 return kIgnoreError_PdfResult; |
| 1650 } |
| 1651 |
| 1652 return skpdfGraphicsStateApplyD(pdfContext, (SkPdfArray*)array, phase); |
| 1653 } |
| 1654 |
| 1655 //intent ri (PDF 1.1) Set the color rendering intent in the graphics state (see
“Rendering Intents” on page 197). |
| 1656 static PdfResult PdfOp_ri(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoop
er** looper) { |
| 1657 pdfContext->fObjectStack.pop(); |
| 1658 |
| 1659 return kNYI_PdfResult; |
| 1660 } |
| 1661 |
| 1662 //flatness i Set the flatness tolerance in the graphics state (see Section 6.5.1,
“Flatness |
| 1663 //Tolerance”). flatness is a number in the range 0 to 100; a value of 0 speci- |
| 1664 //fies the output device’s default flatness tolerance. |
| 1665 static PdfResult PdfOp_i(PdfContext* pdfContext, SkCanvas* canvas, PdfTokenLoope
r** looper) { |
| 1666 pdfContext->fObjectStack.pop(); |
| 1667 |
| 1668 return kNYI_PdfResult; |
| 1669 } |
| 1670 |
1648 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); | 1671 SkTDict<SkXfermode::Mode> gPdfBlendModes(20); |
1649 | 1672 |
1650 class InitBlendModes { | 1673 class InitBlendModes { |
1651 public: | 1674 public: |
1652 InitBlendModes() { | 1675 InitBlendModes() { |
1653 // TODO(edisonn): use the python code generator? | 1676 // TODO(edisonn): use the python code generator? |
1654 // TABLE 7.2 Standard separable blend modes | 1677 // TABLE 7.2 Standard separable blend modes |
1655 gPdfBlendModes.set("Normal", SkXfermode::kSrc_Mode); | 1678 gPdfBlendModes.set("Normal", SkXfermode::kSrc_Mode); |
1656 gPdfBlendModes.set("Multiply", SkXfermode::kMultiply_Mode); | 1679 gPdfBlendModes.set("Multiply", SkXfermode::kMultiply_Mode); |
1657 gPdfBlendModes.set("Screen", SkXfermode::kScreen_Mode); | 1680 gPdfBlendModes.set("Screen", SkXfermode::kScreen_Mode); |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 | 2384 |
2362 rect = SkRect::MakeWH(width, height); | 2385 rect = SkRect::MakeWH(width, height); |
2363 | 2386 |
2364 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); | 2387 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei
ght)); |
2365 | 2388 |
2366 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); | 2389 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); |
2367 SkCanvas canvas(device); | 2390 SkCanvas canvas(device); |
2368 | 2391 |
2369 return renderer.renderPage(page, &canvas, rect); | 2392 return renderer.renderPage(page, &canvas, rect); |
2370 } | 2393 } |
OLD | NEW |