epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | f66025d | 2010-10-01 23:26:55 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | f66025d | 2010-10-01 23:26:55 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | f66025d | 2010-10-01 23:26:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 10 | #include "Test.h" |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 12 | #include "SkData.h" |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 13 | #include "SkFlate.h" |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 14 | #include "SkPDFCatalog.h" |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 15 | #include "SkPDFDevice.h" |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 16 | #include "SkPDFStream.h" |
| 17 | #include "SkPDFTypes.h" |
| 18 | #include "SkScalar.h" |
| 19 | #include "SkStream.h" |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 20 | #include "SkTypes.h" |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 21 | |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 22 | class SkPDFTestDict : public SkPDFDict { |
| 23 | public: |
| 24 | void getResources(SkTDArray<SkPDFObject*>* resourceList) { |
| 25 | resourceList->setReserve(resourceList->count() + fResources.count()); |
| 26 | for (int i = 0; i < fResources.count(); i++) { |
| 27 | resourceList->push(fResources[i]); |
| 28 | fResources[i]->ref(); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void addResource(SkPDFObject* object) { |
| 33 | fResources.append(1, &object); |
| 34 | } |
| 35 | |
| 36 | private: |
| 37 | SkTDArray<SkPDFObject*> fResources; |
| 38 | }; |
| 39 | |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 40 | static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, |
| 41 | const void* buffer, size_t len) { |
| 42 | SkAutoDataUnref data(stream.copyToData()); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 43 | if (offset + len > data->size()) { |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 44 | return false; |
| 45 | } |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 46 | return memcmp(data->bytes() + offset, buffer, len) == 0; |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 47 | } |
| 48 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 49 | static void CheckObjectOutput(skiatest::Reporter* reporter, SkPDFObject* obj, |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 50 | const char* expectedData, size_t expectedSize, |
| 51 | bool indirect, bool compression) { |
| 52 | SkPDFDocument::Flags docFlags = (SkPDFDocument::Flags) 0; |
| 53 | if (!compression) { |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 54 | docFlags = SkTBitOr(docFlags, SkPDFDocument::kNoCompression_Flags); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 55 | } |
| 56 | SkPDFCatalog catalog(docFlags); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 57 | size_t directSize = obj->getOutputSize(&catalog, false); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, directSize == expectedSize); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 59 | |
| 60 | SkDynamicMemoryWStream buffer; |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 61 | obj->emit(&buffer, &catalog, false); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 62 | REPORTER_ASSERT(reporter, directSize == buffer.getOffset()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedData, |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 64 | directSize)); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 65 | |
| 66 | if (indirect) { |
| 67 | // Indirect output. |
| 68 | static char header[] = "1 0 obj\n"; |
| 69 | static size_t headerLen = strlen(header); |
| 70 | static char footer[] = "\nendobj\n"; |
| 71 | static size_t footerLen = strlen(footer); |
| 72 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 73 | catalog.addObject(obj, false); |
| 74 | |
| 75 | size_t indirectSize = obj->getOutputSize(&catalog, true); |
| 76 | REPORTER_ASSERT(reporter, |
| 77 | indirectSize == directSize + headerLen + footerLen); |
| 78 | |
| 79 | buffer.reset(); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 80 | obj->emit(&buffer, &catalog, true); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 81 | REPORTER_ASSERT(reporter, indirectSize == buffer.getOffset()); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 82 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, header, headerLen)); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 83 | REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen, expectedData, |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 84 | directSize)); |
| 85 | REPORTER_ASSERT(reporter, stream_equals(buffer, headerLen + directSize, |
| 86 | footer, footerLen)); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 90 | static void SimpleCheckObjectOutput(skiatest::Reporter* reporter, |
| 91 | SkPDFObject* obj, |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 92 | const char* expectedResult) { |
| 93 | CheckObjectOutput(reporter, obj, expectedResult, |
| 94 | strlen(expectedResult), true, false); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static void TestPDFStream(skiatest::Reporter* reporter) { |
| 98 | char streamBytes[] = "Test\nFoo\tBar"; |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 99 | SkAutoTUnref<SkMemoryStream> streamData(new SkMemoryStream( |
| 100 | streamBytes, strlen(streamBytes), true)); |
| 101 | SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 102 | SimpleCheckObjectOutput( |
| 103 | reporter, stream.get(), |
| 104 | "<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream"); |
| 105 | stream->insert("Attribute", new SkPDFInt(42))->unref(); |
| 106 | SimpleCheckObjectOutput(reporter, stream.get(), |
| 107 | "<</Length 12\n/Attribute 42\n>> stream\n" |
| 108 | "Test\nFoo\tBar\nendstream"); |
| 109 | |
| 110 | if (SkFlate::HaveFlate()) { |
| 111 | char streamBytes2[] = "This is a longer string, so that compression " |
| 112 | "can do something with it. With shorter strings, " |
| 113 | "the short circuit logic cuts in and we end up " |
| 114 | "with an uncompressed string."; |
| 115 | SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, |
| 116 | strlen(streamBytes2))); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 117 | SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 118 | |
| 119 | SkDynamicMemoryWStream compressedByteStream; |
| 120 | SkFlate::Deflate(streamData2.get(), &compressedByteStream); |
| 121 | SkAutoDataUnref compressedData(compressedByteStream.copyToData()); |
| 122 | |
| 123 | // Check first without compression. |
| 124 | SkDynamicMemoryWStream expectedResult1; |
| 125 | expectedResult1.writeText("<</Length 167\n>> stream\n"); |
| 126 | expectedResult1.writeText(streamBytes2); |
| 127 | expectedResult1.writeText("\nendstream"); |
| 128 | SkAutoDataUnref expectedResultData1(expectedResult1.copyToData()); |
| 129 | CheckObjectOutput(reporter, stream.get(), |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 130 | (const char*) expectedResultData1->data(), |
| 131 | expectedResultData1->size(), true, false); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 132 | |
| 133 | // Then again with compression. |
| 134 | SkDynamicMemoryWStream expectedResult2; |
| 135 | expectedResult2.writeText("<</Filter /FlateDecode\n/Length 116\n" |
| 136 | ">> stream\n"); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 137 | expectedResult2.write(compressedData->data(), compressedData->size()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 138 | expectedResult2.writeText("\nendstream"); |
| 139 | SkAutoDataUnref expectedResultData2(expectedResult2.copyToData()); |
| 140 | CheckObjectOutput(reporter, stream.get(), |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 141 | (const char*) expectedResultData2->data(), |
| 142 | expectedResultData2->size(), true, true); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 146 | static void TestCatalog(skiatest::Reporter* reporter) { |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 147 | SkPDFCatalog catalog((SkPDFDocument::Flags)0); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 148 | SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
| 149 | SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); |
| 150 | SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3)); |
| 151 | int1.get()->ref(); |
| 152 | SkAutoTUnref<SkPDFInt> int1Again(int1.get()); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 153 | |
| 154 | catalog.addObject(int1.get(), false); |
| 155 | catalog.addObject(int2.get(), false); |
| 156 | catalog.addObject(int3.get(), false); |
| 157 | |
| 158 | REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int1.get()) == 3); |
| 159 | REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int2.get()) == 3); |
| 160 | REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int3.get()) == 3); |
| 161 | |
| 162 | SkDynamicMemoryWStream buffer; |
| 163 | catalog.emitObjectNumber(&buffer, int1.get()); |
| 164 | catalog.emitObjectNumber(&buffer, int2.get()); |
| 165 | catalog.emitObjectNumber(&buffer, int3.get()); |
| 166 | catalog.emitObjectNumber(&buffer, int1Again.get()); |
| 167 | char expectedResult[] = "1 02 03 01 0"; |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
| 169 | strlen(expectedResult))); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void TestObjectRef(skiatest::Reporter* reporter) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 173 | SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
| 174 | SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2)); |
| 175 | SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get())); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 176 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 177 | SkPDFCatalog catalog((SkPDFDocument::Flags)0); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 178 | catalog.addObject(int1.get(), false); |
| 179 | catalog.addObject(int2.get(), false); |
| 180 | REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int1.get()) == 3); |
| 181 | REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int2.get()) == 3); |
| 182 | |
| 183 | char expectedResult[] = "2 0 R"; |
| 184 | SkDynamicMemoryWStream buffer; |
| 185 | int2ref->emitObject(&buffer, &catalog, false); |
| 186 | REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 187 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
| 188 | buffer.getOffset())); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 189 | } |
| 190 | |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 191 | static void TestSubstitute(skiatest::Reporter* reporter) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 192 | SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict()); |
| 193 | SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict()); |
| 194 | SkAutoTUnref<SkPDFInt> int33(new SkPDFInt(33)); |
| 195 | SkAutoTUnref<SkPDFDict> stubResource(new SkPDFDict()); |
| 196 | SkAutoTUnref<SkPDFInt> int44(new SkPDFInt(44)); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 197 | |
| 198 | stub->insert("Value", int33.get()); |
| 199 | stubResource->insert("InnerValue", int44.get()); |
| 200 | stub->addResource(stubResource.get()); |
| 201 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 202 | SkPDFCatalog catalog((SkPDFDocument::Flags)0); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 203 | catalog.addObject(proxy.get(), false); |
| 204 | catalog.setSubstitute(proxy.get(), stub.get()); |
| 205 | |
| 206 | SkDynamicMemoryWStream buffer; |
| 207 | proxy->emit(&buffer, &catalog, false); |
| 208 | catalog.emitSubstituteResources(&buffer, false); |
| 209 | |
vandebo@chromium.org | d3a094c | 2011-07-25 22:22:25 +0000 | [diff] [blame] | 210 | char objectResult[] = "2 0 obj\n<</Value 33\n>>\nendobj\n"; |
| 211 | REPORTER_ASSERT( |
| 212 | reporter, |
| 213 | catalog.setFileOffset(proxy.get(), 0) == strlen(objectResult)); |
| 214 | |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 215 | char expectedResult[] = |
| 216 | "<</Value 33\n>>1 0 obj\n<</InnerValue 44\n>>\nendobj\n"; |
| 217 | REPORTER_ASSERT(reporter, buffer.getOffset() == strlen(expectedResult)); |
| 218 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
| 219 | buffer.getOffset())); |
| 220 | } |
| 221 | |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 222 | // This test used to assert without the fix submitted for |
| 223 | // http://code.google.com/p/skia/issues/detail?id=1083. |
| 224 | // SKP files might have invalid glyph ids. This test ensures they are ignored, |
| 225 | // and there is no assert on input data in Debug mode. |
| 226 | static void test_issue1083(skiatest::Reporter* reporter) { |
| 227 | SkISize pageSize = SkISize::Make(100, 100); |
| 228 | SkPDFDevice* dev = new SkPDFDevice(pageSize, pageSize, SkMatrix::I()); |
| 229 | |
| 230 | SkCanvas c(dev); |
| 231 | SkPaint paint; |
| 232 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 233 | |
| 234 | uint16_t glyphID = 65000; |
| 235 | c.drawText(&glyphID, 2, 0, 0, paint); |
| 236 | |
| 237 | SkPDFDocument doc; |
| 238 | doc.appendPage(dev); |
| 239 | |
| 240 | SkDynamicMemoryWStream stream; |
| 241 | doc.emitPDF(&stream); |
| 242 | } |
| 243 | |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 244 | static void TestPDFPrimitives(skiatest::Reporter* reporter) { |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 245 | SkAutoTUnref<SkPDFInt> int42(new SkPDFInt(42)); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 246 | SimpleCheckObjectOutput(reporter, int42.get(), "42"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 247 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 248 | SkAutoTUnref<SkPDFScalar> realHalf(new SkPDFScalar(SK_ScalarHalf)); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 249 | SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 250 | |
vandebo@chromium.org | 6cc26da | 2011-05-18 17:08:05 +0000 | [diff] [blame] | 251 | #if defined(SK_SCALAR_IS_FLOAT) |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 252 | SkAutoTUnref<SkPDFScalar> bigScalar(new SkPDFScalar(110999.75f)); |
vandebo@chromium.org | 6cc26da | 2011-05-18 17:08:05 +0000 | [diff] [blame] | 253 | #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 254 | SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000"); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 255 | #else |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 256 | SimpleCheckObjectOutput(reporter, bigScalar.get(), "110999.75"); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 257 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 258 | SkAutoTUnref<SkPDFScalar> biggerScalar(new SkPDFScalar(50000000.1)); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 259 | SimpleCheckObjectOutput(reporter, biggerScalar.get(), "50000000"); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 260 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 261 | SkAutoTUnref<SkPDFScalar> smallestScalar(new SkPDFScalar(1.0/65536)); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 262 | SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526"); |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 263 | #endif |
vandebo@chromium.org | 6cc26da | 2011-05-18 17:08:05 +0000 | [diff] [blame] | 264 | #endif |
vandebo@chromium.org | 094316b | 2011-03-04 03:15:13 +0000 | [diff] [blame] | 265 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 266 | SkAutoTUnref<SkPDFString> stringSimple( |
| 267 | new SkPDFString("test ) string ( foo")); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 268 | SimpleCheckObjectOutput(reporter, stringSimple.get(), |
| 269 | "(test \\) string \\( foo)"); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 270 | SkAutoTUnref<SkPDFString> stringComplex( |
| 271 | new SkPDFString("\ttest ) string ( foo")); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 272 | SimpleCheckObjectOutput(reporter, stringComplex.get(), |
| 273 | "<0974657374202920737472696E67202820666F6F>"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 274 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 275 | SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab")); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 276 | const char expectedResult[] = "/Test#20name#09with#23tab"; |
| 277 | CheckObjectOutput(reporter, name.get(), expectedResult, |
| 278 | strlen(expectedResult), false, false); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 279 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 280 | SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B")); |
vandebo@chromium.org | 251a766 | 2012-09-21 17:50:50 +0000 | [diff] [blame] | 281 | const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"; |
| 282 | CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected, |
| 283 | strlen(escapedNameExpected), false, false); |
| 284 | |
vandebo@chromium.org | c0376fe | 2012-03-05 18:44:33 +0000 | [diff] [blame] | 285 | // Test that we correctly handle characters with the high-bit set. |
bungeman@google.com | f8aa18c | 2012-03-19 21:04:52 +0000 | [diff] [blame] | 286 | const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0}; |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 287 | SkAutoTUnref<SkPDFName> highBitName( |
| 288 | new SkPDFName((const char*)highBitCString)); |
vandebo@chromium.org | c0376fe | 2012-03-05 18:44:33 +0000 | [diff] [blame] | 289 | const char highBitExpectedResult[] = "/#DE#ADbe#EF"; |
| 290 | CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult, |
| 291 | strlen(highBitExpectedResult), false, false); |
| 292 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 293 | SkAutoTUnref<SkPDFArray> array(new SkPDFArray); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 294 | SimpleCheckObjectOutput(reporter, array.get(), "[]"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 295 | array->append(int42.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 296 | SimpleCheckObjectOutput(reporter, array.get(), "[42]"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 297 | array->append(realHalf.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 298 | SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]"); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 299 | SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0)); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 300 | array->append(int0.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 301 | SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]"); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 302 | SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1)); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 303 | array->setAt(0, int1.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 304 | SimpleCheckObjectOutput(reporter, array.get(), "[1 0.5 0]"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 305 | |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 306 | SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 307 | SimpleCheckObjectOutput(reporter, dict.get(), "<<>>"); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 308 | SkAutoTUnref<SkPDFName> n1(new SkPDFName("n1")); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 309 | dict->insert(n1.get(), int42.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 310 | SimpleCheckObjectOutput(reporter, dict.get(), "<</n1 42\n>>"); |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 311 | SkAutoTUnref<SkPDFName> n2(new SkPDFName("n2")); |
| 312 | SkAutoTUnref<SkPDFName> n3(new SkPDFName("n3")); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 313 | dict->insert(n2.get(), realHalf.get()); |
| 314 | dict->insert(n3.get(), array.get()); |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 315 | SimpleCheckObjectOutput(reporter, dict.get(), |
| 316 | "<</n1 42\n/n2 0.5\n/n3 [1 0.5 0]\n>>"); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 317 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 318 | TestPDFStream(reporter); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 319 | |
| 320 | TestCatalog(reporter); |
| 321 | |
| 322 | TestObjectRef(reporter); |
vandebo@chromium.org | 2ef12d4 | 2011-07-06 23:31:24 +0000 | [diff] [blame] | 323 | |
| 324 | TestSubstitute(reporter); |
vandebo@chromium.org | 4e1cc6a | 2013-01-25 19:27:23 +0000 | [diff] [blame] | 325 | |
| 326 | test_issue1083(reporter); |
vandebo@chromium.org | 8459d4e | 2010-09-24 22:25:30 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | #include "TestClassDef.h" |
| 330 | DEFINE_TESTCLASS("PDFPrimitives", PDFPrimitivesTestClass, TestPDFPrimitives) |