[PDF] Add link annotations.

Review URL: https://codereview.appspot.com/6346100

git-svn-id: http://skia.googlecode.com/svn/trunk@4609 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/AnnotationTest.cpp b/tests/AnnotationTest.cpp
index fe2cd01..17da622 100644
--- a/tests/AnnotationTest.cpp
+++ b/tests/AnnotationTest.cpp
@@ -9,6 +9,8 @@
 #include "SkAnnotation.h"
 #include "SkData.h"
 #include "SkCanvas.h"
+#include "SkPDFDevice.h"
+#include "SkPDFDocument.h"
 
 static void test_nodraw(skiatest::Reporter* reporter) {
     SkBitmap bm;
@@ -26,8 +28,54 @@
     REPORTER_ASSERT(reporter, 0 == *bm.getAddr32(0, 0));
 }
 
+struct testCase {
+    SkPDFDocument::Flags flags;
+    bool expectAnnotations;
+};
+
+static void test_pdf_link_annotations(skiatest::Reporter* reporter) {
+    SkISize size = SkISize::Make(612, 792);
+    SkMatrix initialTransform;
+    initialTransform.reset();
+    SkPDFDevice device(size, size, initialTransform);
+    SkCanvas canvas(&device);
+
+    SkRect r = SkRect::MakeXYWH(SkIntToScalar(72), SkIntToScalar(72),
+                                SkIntToScalar(288), SkIntToScalar(72));
+    SkAutoDataUnref data(SkData::NewWithCString("http://www.gooogle.com"));
+    SkAnnotateRectWithURL(&canvas, r, data.get());
+
+    testCase tests[] = {{(SkPDFDocument::Flags)0, true},
+                        {SkPDFDocument::kNoLinks_Flags, false}};
+    for (size_t testNum = 0; testNum < SK_ARRAY_COUNT(tests); testNum++) {
+        SkPDFDocument doc(tests[testNum].flags);
+        doc.appendPage(&device);
+        SkDynamicMemoryWStream outStream;
+        doc.emitPDF(&outStream);
+        SkAutoDataUnref out(outStream.copyToData());
+        const char* rawOutput = (const char*)out->data();
+
+        bool found = false;
+        for (size_t i = 0; i < out->size() - 8; i++) {
+            if (rawOutput[i + 0] == '/' &&
+                rawOutput[i + 1] == 'A' &&
+                rawOutput[i + 2] == 'n' &&
+                rawOutput[i + 3] == 'n' &&
+                rawOutput[i + 4] == 'o' &&
+                rawOutput[i + 5] == 't' &&
+                rawOutput[i + 6] == 's' &&
+                rawOutput[i + 7] == ' ') {
+                found = true;
+                break;
+            }
+        }
+        REPORTER_ASSERT(reporter, found == tests[testNum].expectAnnotations);
+    }
+}
+
 static void TestAnnotation(skiatest::Reporter* reporter) {
     test_nodraw(reporter);
+    test_pdf_link_annotations(reporter);
 }
 
 #include "TestClassDef.h"
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index ea3093f..33366be 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -49,7 +49,7 @@
                               bool indirect, bool compression) {
     SkPDFDocument::Flags docFlags = (SkPDFDocument::Flags) 0;
     if (!compression) {
-        docFlags = SkTBitOr(docFlags, SkPDFDocument::kNoCompression_Flag);
+        docFlags = SkTBitOr(docFlags, SkPDFDocument::kNoCompression_Flags);
     }
     SkPDFCatalog catalog(docFlags);
     size_t directSize = obj->getOutputSize(&catalog, false);