vandebo@chromium.org | 04c643b | 2011-08-08 22:33:05 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2010 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | #include "Test.h" |
| 13 | #include "SkData.h" |
| 14 | #include "SkPDFTypes.h" |
| 15 | #include "SkPDFFont.h" |
| 16 | #include "SkStream.h" |
| 17 | |
| 18 | static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, |
| 19 | const void* buffer, size_t len) { |
| 20 | SkAutoDataUnref data(stream.copyToData()); |
| 21 | if (offset + len > data.size()) { |
| 22 | return false; |
| 23 | } |
| 24 | return memcmp(data.bytes() + offset, buffer, len) == 0; |
| 25 | } |
| 26 | |
| 27 | void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode, |
| 28 | const SkPDFGlyphSet* subset, |
| 29 | SkDynamicMemoryWStream* cmap); |
| 30 | static void TestToUnicode(skiatest::Reporter* reporter) { |
| 31 | SkTDArray<SkUnichar> glyphToUnicode; |
| 32 | SkTDArray<uint16_t> glyphsInSubset; |
| 33 | SkPDFGlyphSet subset; |
| 34 | |
| 35 | glyphToUnicode.push(0); // 0 |
| 36 | glyphToUnicode.push(0); // 1 |
| 37 | glyphToUnicode.push(0); // 2 |
| 38 | glyphsInSubset.push(3); |
| 39 | glyphToUnicode.push(0x20); // 3 |
| 40 | glyphsInSubset.push(4); |
| 41 | glyphToUnicode.push(0x25); // 4 |
| 42 | glyphsInSubset.push(5); |
| 43 | glyphToUnicode.push(0x27); // 5 |
| 44 | glyphsInSubset.push(6); |
| 45 | glyphToUnicode.push(0x28); // 6 |
| 46 | glyphsInSubset.push(7); |
| 47 | glyphToUnicode.push(0x29); // 7 |
| 48 | glyphsInSubset.push(8); |
| 49 | glyphToUnicode.push(0x2F); // 8 |
| 50 | glyphsInSubset.push(9); |
| 51 | glyphToUnicode.push(0x33); // 9 |
| 52 | glyphToUnicode.push(0); // 10 |
| 53 | glyphsInSubset.push(11); |
| 54 | glyphToUnicode.push(0x35); // 11 |
| 55 | glyphsInSubset.push(12); |
| 56 | glyphToUnicode.push(0x36); // 12 |
| 57 | for (uint16_t i = 13; i < 0xFE; ++i) { |
| 58 | glyphToUnicode.push(0); // Zero from index 0x9 to 0xFD |
| 59 | } |
| 60 | glyphsInSubset.push(0xFE); |
| 61 | glyphToUnicode.push(0x1010); |
| 62 | glyphsInSubset.push(0xFF); |
| 63 | glyphToUnicode.push(0x1011); |
| 64 | glyphsInSubset.push(0x100); |
| 65 | glyphToUnicode.push(0x1012); |
| 66 | glyphsInSubset.push(0x101); |
| 67 | glyphToUnicode.push(0x1013); |
| 68 | |
| 69 | SkDynamicMemoryWStream buffer; |
| 70 | subset.set(glyphsInSubset.begin(), glyphsInSubset.count()); |
| 71 | append_cmap_sections(glyphToUnicode, &subset, &buffer); |
| 72 | |
| 73 | char expectedResult[] = |
| 74 | "4 beginbfchar\n\ |
| 75 | <0003> <0020>\n\ |
| 76 | <0004> <0025>\n\ |
| 77 | <0008> <002F>\n\ |
| 78 | <0009> <0033>\n\ |
| 79 | endbfchar\n\ |
| 80 | 4 beginbfrange\n\ |
| 81 | <0005> <0007> <0027>\n\ |
| 82 | <000B> <000C> <0035>\n\ |
| 83 | <00FE> <00FF> <1010>\n\ |
| 84 | <0100> <0101> <1012>\n\ |
| 85 | endbfrange\n"; |
| 86 | |
| 87 | REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult, |
| 88 | buffer.getOffset())); |
| 89 | } |
| 90 | |
| 91 | #include "TestClassDef.h" |
| 92 | DEFINE_TESTCLASS("ToUnicode", ToUnicodeTestClass, TestToUnicode) |