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 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 SkAnnotationKeys::Define_Named_Dest_Key()); | 1457 SkAnnotationKeys::Define_Named_Dest_Key()); |
1458 if (nameData) { | 1458 if (nameData) { |
1459 for (size_t i = 0; i < count; i++) { | 1459 for (size_t i = 0; i < count; i++) { |
1460 defineNamedDestination(nameData, points[i], matrix); | 1460 defineNamedDestination(nameData, points[i], matrix); |
1461 } | 1461 } |
1462 return paint.getAnnotation() != NULL; | 1462 return paint.getAnnotation() != NULL; |
1463 } | 1463 } |
1464 return false; | 1464 return false; |
1465 } | 1465 } |
1466 | 1466 |
1467 SkPDFDict* SkPDFDevice::createLinkAnnotation(const SkRect& r, | 1467 void SkPDFDevice::addAnnotation(SkPDFDict* annotation) { |
1468 const SkMatrix& matrix) { | 1468 if (NULL == fAnnotations) { |
| 1469 fAnnotations = SkNEW(SkPDFArray); |
| 1470 } |
| 1471 fAnnotations->appendObject(annotation); |
| 1472 } |
| 1473 |
| 1474 static SkPDFDict* create_link_annotation(const SkRect& r, |
| 1475 const SkMatrix& initialTransform, |
| 1476 const SkMatrix& matrix) { |
1469 SkMatrix transform = matrix; | 1477 SkMatrix transform = matrix; |
1470 transform.postConcat(fInitialTransform); | 1478 transform.postConcat(initialTransform); |
1471 SkRect translatedRect; | 1479 SkRect translatedRect; |
1472 transform.mapRect(&translatedRect, r); | 1480 transform.mapRect(&translatedRect, r); |
1473 | 1481 |
1474 if (NULL == fAnnotations) { | 1482 SkAutoTUnref<SkPDFDict> annotation(SkNEW_ARGS(SkPDFDict, ("Annot"))); |
1475 fAnnotations = SkNEW(SkPDFArray); | |
1476 } | |
1477 SkPDFDict* annotation(SkNEW_ARGS(SkPDFDict, ("Annot"))); | |
1478 annotation->insertName("Subtype", "Link"); | 1483 annotation->insertName("Subtype", "Link"); |
1479 fAnnotations->append(annotation); | |
1480 | 1484 |
1481 SkAutoTUnref<SkPDFArray> border(SkNEW(SkPDFArray)); | 1485 SkAutoTUnref<SkPDFArray> border(SkNEW(SkPDFArray)); |
1482 border->reserve(3); | 1486 border->reserve(3); |
1483 border->appendInt(0); // Horizontal corner radius. | 1487 border->appendInt(0); // Horizontal corner radius. |
1484 border->appendInt(0); // Vertical corner radius. | 1488 border->appendInt(0); // Vertical corner radius. |
1485 border->appendInt(0); // Width, 0 = no border. | 1489 border->appendInt(0); // Width, 0 = no border. |
1486 annotation->insert("Border", border.get()); | 1490 annotation->insertObject("Border", border.detach()); |
1487 | 1491 |
1488 SkAutoTUnref<SkPDFArray> rect(SkNEW(SkPDFArray)); | 1492 SkAutoTUnref<SkPDFArray> rect(SkNEW(SkPDFArray)); |
1489 rect->reserve(4); | 1493 rect->reserve(4); |
1490 rect->appendScalar(translatedRect.fLeft); | 1494 rect->appendScalar(translatedRect.fLeft); |
1491 rect->appendScalar(translatedRect.fTop); | 1495 rect->appendScalar(translatedRect.fTop); |
1492 rect->appendScalar(translatedRect.fRight); | 1496 rect->appendScalar(translatedRect.fRight); |
1493 rect->appendScalar(translatedRect.fBottom); | 1497 rect->appendScalar(translatedRect.fBottom); |
1494 annotation->insert("Rect", rect.get()); | 1498 annotation->insertObject("Rect", rect.detach()); |
1495 | 1499 |
1496 return annotation; | 1500 return annotation.detach(); |
1497 } | 1501 } |
1498 | 1502 |
1499 void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r, | 1503 void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r, |
1500 const SkMatrix& matrix) { | 1504 const SkMatrix& matrix) { |
1501 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); | 1505 SkAutoTUnref<SkPDFDict> annotation( |
| 1506 create_link_annotation(r, fInitialTransform, matrix)); |
1502 | 1507 |
1503 SkString url(static_cast<const char *>(urlData->data()), | 1508 SkString url(static_cast<const char *>(urlData->data()), |
1504 urlData->size() - 1); | 1509 urlData->size() - 1); |
1505 SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action"))); | 1510 SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action"))); |
1506 action->insertName("S", "URI"); | 1511 action->insertName("S", "URI"); |
1507 action->insertString("URI", url); | 1512 action->insertString("URI", url); |
1508 annotation->insert("A", action.get()); | 1513 annotation->insertObject("A", action.detach()); |
| 1514 this->addAnnotation(annotation.detach()); |
1509 } | 1515 } |
1510 | 1516 |
1511 void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r, | 1517 void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r, |
1512 const SkMatrix& matrix) { | 1518 const SkMatrix& matrix) { |
1513 SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); | 1519 SkAutoTUnref<SkPDFDict> annotation( |
| 1520 create_link_annotation(r, fInitialTransform, matrix)); |
1514 SkString name(static_cast<const char *>(nameData->data()), | 1521 SkString name(static_cast<const char *>(nameData->data()), |
1515 nameData->size() - 1); | 1522 nameData->size() - 1); |
1516 annotation->insertName("Dest", name); | 1523 annotation->insertName("Dest", name); |
| 1524 this->addAnnotation(annotation.detach()); |
1517 } | 1525 } |
1518 | 1526 |
1519 struct NamedDestination { | 1527 struct NamedDestination { |
1520 const SkData* nameData; | 1528 const SkData* nameData; |
1521 SkPoint point; | 1529 SkPoint point; |
1522 | 1530 |
1523 NamedDestination(const SkData* nameData, const SkPoint& point) | 1531 NamedDestination(const SkData* nameData, const SkPoint& point) |
1524 : nameData(SkRef(nameData)), point(point) {} | 1532 : nameData(SkRef(nameData)), point(point) {} |
1525 | 1533 |
1526 ~NamedDestination() { | 1534 ~NamedDestination() { |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2137 return; | 2145 return; |
2138 } | 2146 } |
2139 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); | 2147 SkAutoTUnref<SkPDFObject> image(SkPDFBitmap::Create(fCanon, subsetBitmap)); |
2140 if (!image) { | 2148 if (!image) { |
2141 return; | 2149 return; |
2142 } | 2150 } |
2143 | 2151 |
2144 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), | 2152 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), |
2145 &content.entry()->fContent); | 2153 &content.entry()->fContent); |
2146 } | 2154 } |
OLD | NEW |