You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2021/02/01 07:16:51 UTC
svn commit: r1886092 - in /pdfbox/trunk/fontbox/src/test:
java/org/apache/fontbox/cmap/TestCMapParser.java
resources/cmap/Identitybfrange
Author: lehmi
Date: Mon Feb 1 07:16:51 2021
New Revision: 1886092
URL: http://svn.apache.org/viewvc?rev=1886092&view=rev
Log:
PDFBOX-5090: add a test for an identity bfrange mapping
Added:
pdfbox/trunk/fontbox/src/test/resources/cmap/Identitybfrange
Modified:
pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
Modified: pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java?rev=1886092&r1=1886091&r2=1886092&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java (original)
+++ pdfbox/trunk/fontbox/src/test/java/org/apache/fontbox/cmap/TestCMapParser.java Mon Feb 1 07:16:51 2021
@@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Asse
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
@@ -46,8 +47,7 @@ class TestCMapParser
final String resourceDir = "src/test/resources/cmap";
File inDir = new File(resourceDir);
- CMapParser parser = new CMapParser();
- CMap cMap = parser.parse(new File(inDir, "CMapTest"));
+ CMap cMap = new CMapParser().parse(new File(inDir, "CMapTest"));
// char mappings
byte[] bytes1 = {0, 1};
@@ -92,11 +92,7 @@ class TestCMapParser
@Test
void testIdentity() throws IOException
{
- final String resourceDir = "src/main/resources/org/apache/fontbox/cmap";
- File inDir = new File(resourceDir);
-
- CMapParser parser = new CMapParser();
- CMap cMap = parser.parse(new File(inDir, "Identity-H"));
+ CMap cMap = new CMapParser().parsePredefined("Identity-H");
assertEquals(65, cMap.toCID(new byte[] { 0, 65 }), "Indentity-H CID 65");
assertEquals(12345, cMap.toCID(new byte[] { 0x30, 0x39 }), "Indentity-H CID 12345");
@@ -107,11 +103,7 @@ class TestCMapParser
@Test
void testUniJIS_UTF16_H() throws IOException
{
- final String resourceDir = "src/main/resources/org/apache/fontbox/cmap";
- File inDir = new File(resourceDir);
-
- CMapParser parser = new CMapParser();
- CMap cMap = parser.parse(new File(inDir, "UniJIS-UTF16-H"));
+ CMap cMap = new CMapParser().parsePredefined("UniJIS-UTF16-H");
// the next 3 cases demonstrate the issue of possible false result values of CMap.toCID(int code)
assertEquals(694, cMap.toCID(0xb1), "UniJIS-UTF16-H CID 0xb1 -> 694");
@@ -135,11 +127,7 @@ class TestCMapParser
@Test
void testUniJIS_UCS2_H() throws IOException
{
- final String resourceDir = "src/main/resources/org/apache/fontbox/cmap";
- File inDir = new File(resourceDir);
-
- CMapParser parser = new CMapParser();
- CMap cMap = parser.parse(new File(inDir, "UniJIS-UCS2-H"));
+ CMap cMap = new CMapParser().parsePredefined("UniJIS-UCS2-H");
assertEquals(34, cMap.toCID(new byte[] { 0, 65 }), "UniJIS-UCS2-H CID 65 -> 34");
}
@@ -147,11 +135,7 @@ class TestCMapParser
@Test
void testAdobe_GB1_UCS2() throws IOException
{
- final String resourceDir = "src/main/resources/org/apache/fontbox/cmap";
- File inDir = new File(resourceDir);
-
- CMapParser parser = new CMapParser();
- CMap cMap = parser.parse(new File(inDir, "Adobe-GB1-UCS2"));
+ CMap cMap = new CMapParser().parsePredefined("Adobe-GB1-UCS2");
assertEquals("0", cMap.toUnicode(new byte[] { 0, 0x11 }),
"Adobe-GB1-UCS2 CID 0x11 -> \"0\"");
@@ -225,6 +209,33 @@ class TestCMapParser
cMap = new CMapParser().parsePredefined("Identity-V");
assertNotNull(cMap, "Failed to parse predefined CMap Identity-V");
+ }
+
+ @Test
+ void testIdentitybfrange() throws IOException
+ {
+ // use strict mode
+ CMap cMap = new CMapParser(true)
+ .parse(new File("src/test/resources/cmap", "Identitybfrange"));
+ assertEquals("Adobe-Identity-UCS", cMap.getName(), "wrong CMap name");
+
+ byte[] bytes = new byte[] { 0, 65 };
+ assertEquals(new String(bytes, StandardCharsets.UTF_16BE), cMap.toUnicode(bytes),
+ "Indentity 0x0048");
+ bytes = new byte[] { 0x30, 0x39 };
+ assertEquals(new String(bytes, StandardCharsets.UTF_16BE), cMap.toUnicode(bytes),
+ "Indentity 0x3039");
+ // check border values for strict mode
+ bytes = new byte[] { 0x30, (byte) 0xFF };
+ assertEquals(new String(bytes, StandardCharsets.UTF_16BE), cMap.toUnicode(bytes),
+ "Indentity 0x30FF");
+ // check border values for strict mode
+ bytes = new byte[] { 0x31, 0x00 };
+ assertEquals(new String(bytes, StandardCharsets.UTF_16BE), cMap.toUnicode(bytes),
+ "Indentity 0x3100");
+ bytes = new byte[] { (byte) 0xFF, (byte) 0xFF };
+ assertEquals(new String(bytes, StandardCharsets.UTF_16BE), cMap.toUnicode(bytes),
+ "Indentity 0xFFFF");
}
}
Added: pdfbox/trunk/fontbox/src/test/resources/cmap/Identitybfrange
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/test/resources/cmap/Identitybfrange?rev=1886092&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/test/resources/cmap/Identitybfrange (added)
+++ pdfbox/trunk/fontbox/src/test/resources/cmap/Identitybfrange Mon Feb 1 07:16:51 2021
@@ -0,0 +1,45 @@
+%% Licensed to the Apache Software Foundation (ASF) under one or more
+%% contributor license agreements. See the NOTICE file distributed with
+%% this work for additional information regarding copyright ownership.
+%% The ASF licenses this file to You under the Apache License, Version 2.0
+%% (the "License"); you may not use this file except in compliance with
+%% the License. You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% This CMap represents a CMap for an Identity bfrange mapping.
+%% It is included in some pdfs and was copied from one of those.
+%%
+%%EndComments
+
+/CIDInit /ProcSet findresource begin
+12 dict begin
+begincmap
+/CIDSystemInfo
+<<
+/Registry (Adobe)
+/Ordering (UCS)
+/Supplement 0
+>> def
+
+/CMapName /Adobe-Identity-UCS def
+/CMapType 2 def
+
+1 begincodespacerange
+<0000> <ffff>
+endcodespacerange
+
+1 beginbfrange
+<0000> <ffff> <0000>
+endbfrange
+
+endcmap
+CMapName currentdict /CMap defineresource pop
+end
+end