2011-08-08 22:33:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-12-30 18:09:03 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#ifdef SK_SUPPORT_PDF
|
|
|
|
|
2016-08-18 21:22:52 +00:00
|
|
|
#include "SkBitSet.h"
|
2011-08-08 22:33:05 +00:00
|
|
|
#include "SkData.h"
|
2016-08-09 20:04:34 +00:00
|
|
|
#include "SkPDFMakeToUnicodeCmap.h"
|
2011-08-08 22:33:05 +00:00
|
|
|
#include "SkStream.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkTo.h"
|
2011-08-08 22:33:05 +00:00
|
|
|
|
Reland "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."
This reverts commit ab17347df32807cabd9f2a518d22c3bd420e482f.
Reason for revert: Chromium should now be ok.
Original change's description:
> Revert "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."
>
> This reverts commit e1bc7de7c07686b28b00b850e44e0722189f3592.
>
> Reason for revert: chrome used it
>
> Original change's description:
> > Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines.
> >
> > sed 's/SK_MaxSizeT/SIZE_MAX/g'
> > sed 's/SK_MaxU32/UINT32_MAX/g'
> > sed 's/SK_MaxU16/UINT16_MAX/g'
> >
> > SK_MinU32 and SK_MinU16 were unused
> >
> > Change-Id: I6b6c824df47b05bde7e73b13a58e851a5f63fe0e
> > Reviewed-on: https://skia-review.googlesource.com/134607
> > Commit-Queue: Hal Canary <halcanary@google.com>
> > Reviewed-by: Ben Wagner <bungeman@google.com>
>
> TBR=halcanary@google.com,bungeman@google.com,reed@google.com
>
> Change-Id: I1e2c440dcf9f59bf87c1fea113248cd5136f7519
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/134921
> Reviewed-by: Hal Canary <halcanary@google.com>
> Commit-Queue: Hal Canary <halcanary@google.com>
CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux-ozone-rel
TBR=halcanary@google.com,bungeman@google.com,reed@google.com
Change-Id: I7709f9715bea0463b85b5b0a89712ac1020fcddb
Reviewed-on: https://skia-review.googlesource.com/135180
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2018-06-15 15:37:57 +00:00
|
|
|
static const int kMaximumGlyphCount = UINT16_MAX + 1;
|
2016-08-18 21:22:52 +00:00
|
|
|
|
2011-08-08 22:33:05 +00:00
|
|
|
static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
|
2012-01-03 18:35:39 +00:00
|
|
|
const char* buffer, size_t len) {
|
2016-12-15 18:02:33 +00:00
|
|
|
if (len != strlen(buffer)) {
|
2011-08-08 22:33:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-15 18:02:33 +00:00
|
|
|
|
|
|
|
const size_t streamSize = stream.bytesWritten();
|
|
|
|
|
|
|
|
if (offset + len > streamSize) {
|
2012-01-03 18:35:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-15 18:02:33 +00:00
|
|
|
|
|
|
|
SkAutoTMalloc<char> data(streamSize);
|
|
|
|
stream.copyTo(data.get());
|
|
|
|
return memcmp(data.get() + offset, buffer, len) == 0;
|
2011-08-08 22:33:05 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 18:41:59 +00:00
|
|
|
DEF_TEST(SkPDF_ToUnicode, reporter) {
|
2011-08-08 22:33:05 +00:00
|
|
|
SkTDArray<SkUnichar> glyphToUnicode;
|
|
|
|
SkTDArray<uint16_t> glyphsInSubset;
|
2016-08-18 21:22:52 +00:00
|
|
|
SkBitSet subset(kMaximumGlyphCount);
|
2011-08-08 22:33:05 +00:00
|
|
|
|
2018-08-08 15:23:41 +00:00
|
|
|
glyphToUnicode.push_back(0); // 0
|
|
|
|
glyphToUnicode.push_back(0); // 1
|
|
|
|
glyphToUnicode.push_back(0); // 2
|
|
|
|
glyphsInSubset.push_back(3);
|
|
|
|
glyphToUnicode.push_back(0x20); // 3
|
|
|
|
glyphsInSubset.push_back(4);
|
|
|
|
glyphToUnicode.push_back(0x25); // 4
|
|
|
|
glyphsInSubset.push_back(5);
|
|
|
|
glyphToUnicode.push_back(0x27); // 5
|
|
|
|
glyphsInSubset.push_back(6);
|
|
|
|
glyphToUnicode.push_back(0x28); // 6
|
|
|
|
glyphsInSubset.push_back(7);
|
|
|
|
glyphToUnicode.push_back(0x29); // 7
|
|
|
|
glyphsInSubset.push_back(8);
|
|
|
|
glyphToUnicode.push_back(0x2F); // 8
|
|
|
|
glyphsInSubset.push_back(9);
|
|
|
|
glyphToUnicode.push_back(0x33); // 9
|
|
|
|
glyphToUnicode.push_back(0); // 10
|
|
|
|
glyphsInSubset.push_back(11);
|
|
|
|
glyphToUnicode.push_back(0x35); // 11
|
|
|
|
glyphsInSubset.push_back(12);
|
|
|
|
glyphToUnicode.push_back(0x36); // 12
|
|
|
|
glyphsInSubset.push_back(13);
|
|
|
|
glyphToUnicode.push_back(0x37); // 13
|
2013-09-18 19:29:08 +00:00
|
|
|
for (uint16_t i = 14; i < 0xFE; ++i) {
|
2018-08-08 15:23:41 +00:00
|
|
|
glyphToUnicode.push_back(0); // Zero from index 0x9 to 0xFD
|
2011-08-08 22:33:05 +00:00
|
|
|
}
|
2018-08-08 15:23:41 +00:00
|
|
|
glyphsInSubset.push_back(0xFE);
|
|
|
|
glyphToUnicode.push_back(0x1010);
|
|
|
|
glyphsInSubset.push_back(0xFF);
|
|
|
|
glyphToUnicode.push_back(0x1011);
|
|
|
|
glyphsInSubset.push_back(0x100);
|
|
|
|
glyphToUnicode.push_back(0x1012);
|
|
|
|
glyphsInSubset.push_back(0x101);
|
|
|
|
glyphToUnicode.push_back(0x1013);
|
2011-08-08 22:33:05 +00:00
|
|
|
|
2018-05-09 15:50:34 +00:00
|
|
|
SkGlyphID lastGlyphID = SkToU16(glyphToUnicode.count() - 1);
|
|
|
|
|
2011-08-08 22:33:05 +00:00
|
|
|
SkDynamicMemoryWStream buffer;
|
2016-08-18 21:22:52 +00:00
|
|
|
subset.setAll(glyphsInSubset.begin(), glyphsInSubset.count());
|
2018-05-09 15:50:34 +00:00
|
|
|
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset, &buffer, true, 0,
|
|
|
|
SkTMin<SkGlyphID>(0xFFFF, lastGlyphID));
|
2011-08-08 22:33:05 +00:00
|
|
|
|
|
|
|
char expectedResult[] =
|
|
|
|
"4 beginbfchar\n\
|
|
|
|
<0003> <0020>\n\
|
|
|
|
<0004> <0025>\n\
|
|
|
|
<0008> <002F>\n\
|
|
|
|
<0009> <0033>\n\
|
|
|
|
endbfchar\n\
|
|
|
|
4 beginbfrange\n\
|
|
|
|
<0005> <0007> <0027>\n\
|
2013-09-18 19:29:08 +00:00
|
|
|
<000B> <000D> <0035>\n\
|
2011-08-08 22:33:05 +00:00
|
|
|
<00FE> <00FF> <1010>\n\
|
|
|
|
<0100> <0101> <1012>\n\
|
|
|
|
endbfrange\n";
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
|
2016-12-16 16:51:41 +00:00
|
|
|
buffer.bytesWritten()));
|
2012-01-03 18:35:39 +00:00
|
|
|
|
2013-09-18 19:29:08 +00:00
|
|
|
// Remove characters and ranges.
|
|
|
|
buffer.reset();
|
|
|
|
|
2018-05-09 15:50:34 +00:00
|
|
|
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset, &buffer, true, 8,
|
|
|
|
SkTMin<SkGlyphID>(0x00FF, lastGlyphID));
|
2013-09-18 19:29:08 +00:00
|
|
|
|
|
|
|
char expectedResultChop1[] =
|
|
|
|
"2 beginbfchar\n\
|
|
|
|
<0008> <002F>\n\
|
|
|
|
<0009> <0033>\n\
|
|
|
|
endbfchar\n\
|
|
|
|
2 beginbfrange\n\
|
|
|
|
<000B> <000D> <0035>\n\
|
|
|
|
<00FE> <00FF> <1010>\n\
|
|
|
|
endbfrange\n";
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop1,
|
2016-12-16 16:51:41 +00:00
|
|
|
buffer.bytesWritten()));
|
2013-09-18 19:29:08 +00:00
|
|
|
|
|
|
|
// Remove characters from range to downdrade it to one char.
|
|
|
|
buffer.reset();
|
|
|
|
|
2018-05-09 15:50:34 +00:00
|
|
|
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset, &buffer, true, 0x00D,
|
|
|
|
SkTMin<SkGlyphID>(0x00FE, lastGlyphID));
|
2013-09-18 19:29:08 +00:00
|
|
|
|
|
|
|
char expectedResultChop2[] =
|
|
|
|
"2 beginbfchar\n\
|
|
|
|
<000D> <0037>\n\
|
|
|
|
<00FE> <1010>\n\
|
|
|
|
endbfchar\n";
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResultChop2,
|
2016-12-16 16:51:41 +00:00
|
|
|
buffer.bytesWritten()));
|
2013-09-18 19:29:08 +00:00
|
|
|
|
2013-12-11 18:47:11 +00:00
|
|
|
buffer.reset();
|
|
|
|
|
2018-05-09 15:50:34 +00:00
|
|
|
SkPDFAppendCmapSections(&glyphToUnicode[0], nullptr, &buffer, false, 0xFC,
|
|
|
|
SkTMin<SkGlyphID>(0x110, lastGlyphID));
|
2013-12-11 18:47:11 +00:00
|
|
|
|
|
|
|
char expectedResultSingleBytes[] =
|
|
|
|
"2 beginbfchar\n\
|
2016-08-31 19:52:35 +00:00
|
|
|
<01> <0000>\n\
|
|
|
|
<02> <0000>\n\
|
2013-12-11 18:47:11 +00:00
|
|
|
endbfchar\n\
|
|
|
|
1 beginbfrange\n\
|
2016-08-31 19:52:35 +00:00
|
|
|
<03> <06> <1010>\n\
|
2013-12-11 18:47:11 +00:00
|
|
|
endbfrange\n";
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stream_equals(buffer, 0,
|
|
|
|
expectedResultSingleBytes,
|
2016-12-16 16:51:41 +00:00
|
|
|
buffer.bytesWritten()));
|
2013-12-11 18:47:11 +00:00
|
|
|
|
2012-01-03 18:35:39 +00:00
|
|
|
glyphToUnicode.reset();
|
|
|
|
glyphsInSubset.reset();
|
2016-08-18 21:22:52 +00:00
|
|
|
SkBitSet subset2(kMaximumGlyphCount);
|
2012-01-03 18:35:39 +00:00
|
|
|
|
|
|
|
// Test mapping:
|
|
|
|
// I n s t a l
|
|
|
|
// Glyph id 2c 51 56 57 44 4f
|
|
|
|
// Unicode 49 6e 73 74 61 6c
|
2014-12-12 23:11:17 +00:00
|
|
|
for (SkUnichar i = 0; i < 100; ++i) {
|
2018-08-08 15:23:41 +00:00
|
|
|
glyphToUnicode.push_back(i + 29);
|
2012-01-03 18:35:39 +00:00
|
|
|
}
|
2018-05-09 15:50:34 +00:00
|
|
|
lastGlyphID = SkToU16(glyphToUnicode.count() - 1);
|
2012-01-03 18:35:39 +00:00
|
|
|
|
2018-08-08 15:23:41 +00:00
|
|
|
glyphsInSubset.push_back(0x2C);
|
|
|
|
glyphsInSubset.push_back(0x44);
|
|
|
|
glyphsInSubset.push_back(0x4F);
|
|
|
|
glyphsInSubset.push_back(0x51);
|
|
|
|
glyphsInSubset.push_back(0x56);
|
|
|
|
glyphsInSubset.push_back(0x57);
|
2012-01-03 18:35:39 +00:00
|
|
|
|
|
|
|
SkDynamicMemoryWStream buffer2;
|
2016-08-18 21:22:52 +00:00
|
|
|
subset2.setAll(glyphsInSubset.begin(), glyphsInSubset.count());
|
2018-05-09 15:50:34 +00:00
|
|
|
SkPDFAppendCmapSections(&glyphToUnicode[0], &subset2, &buffer2, true, 0,
|
|
|
|
SkTMin<SkGlyphID>(0xFFFF, lastGlyphID));
|
2012-01-03 18:35:39 +00:00
|
|
|
|
|
|
|
char expectedResult2[] =
|
|
|
|
"4 beginbfchar\n\
|
|
|
|
<002C> <0049>\n\
|
|
|
|
<0044> <0061>\n\
|
|
|
|
<004F> <006C>\n\
|
|
|
|
<0051> <006E>\n\
|
|
|
|
endbfchar\n\
|
|
|
|
1 beginbfrange\n\
|
|
|
|
<0056> <0057> <0073>\n\
|
|
|
|
endbfrange\n";
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, stream_equals(buffer2, 0, expectedResult2,
|
2016-12-16 16:51:41 +00:00
|
|
|
buffer2.bytesWritten()));
|
2011-08-08 22:33:05 +00:00
|
|
|
}
|
2016-12-30 18:09:03 +00:00
|
|
|
|
|
|
|
#endif
|