Skip to content

Commit 6313d54

Browse files
committed
Apply the provided cmap for CIDFont
Also move FontAsian resources handling logic out of FontCache. DEVSIX-3555, DEVSIX-3938
1 parent 10cc267 commit 6313d54

File tree

22 files changed

+755
-246
lines changed

22 files changed

+755
-246
lines changed

font-asian/src/main/resources/com/itextpdf/io/font/cmap/cjk_registry.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Adobe_Japan1=78-EUC-H 78-EUC-V 78-H 78-RKSJ-H 78-RKSJ-V 78-V 78ms-RKSJ-H 78ms-RK
22
Adobe_Korea1=Adobe-Korea1-0 Adobe-Korea1-1 Adobe-Korea1-2 KSC-EUC-H KSC-EUC-V KSC-H KSC-Johab-H KSC-Johab-V KSC-V KSCms-UHC-H KSCms-UHC-HW-H KSCms-UHC-HW-V KSCms-UHC-V KSCpc-EUC-H KSCpc-EUC-V UniKS-UCS2-H UniKS-UCS2-V UniKS-UTF16-H UniKS-UTF16-V UniKS-UTF32-H UniKS-UTF32-V UniKS-UTF8-H UniKS-UTF8-V
33
Adobe_GB1=Adobe-GB1-0 Adobe-GB1-1 Adobe-GB1-2 Adobe-GB1-3 Adobe-GB1-4 Adobe-GB1-5 GB-EUC-H GB-EUC-V GB-H GB-V GBK-EUC-H GBK-EUC-V GBK2K-H GBK2K-V GBKp-EUC-H GBKp-EUC-V GBpc-EUC-H GBpc-EUC-V GBT-EUC-H GBT-EUC-V GBT-H GBT-V GBTpc-EUC-H GBTpc-EUC-V UniGB-UCS2-H UniGB-UCS2-V UniGB-UTF16-H UniGB-UTF16-V UniGB-UTF32-H UniGB-UTF32-V UniGB-UTF8-H UniGB-UTF8-V
44
Adobe_CNS1=Adobe-CNS1-0 Adobe-CNS1-1 Adobe-CNS1-2 Adobe-CNS1-3 Adobe-CNS1-4 Adobe-CNS1-5 Adobe-CNS1-6 B5-H B5-V B5pc-H B5pc-V CNS-EUC-H CNS-EUC-V CNS1-H CNS1-V CNS2-H CNS2-V ETen-B5-H ETen-B5-V ETenms-B5-H ETenms-B5-V ETHK-B5-H ETHK-B5-V HKdla-B5-H HKdla-B5-V HKdlb-B5-H HKdlb-B5-V HKgccs-B5-H HKgccs-B5-V HKm314-B5-H HKm314-B5-V HKm471-B5-H HKm471-B5-V HKscs-B5-H HKscs-B5-V UniCNS-UCS2-H UniCNS-UCS2-V UniCNS-UTF16-H UniCNS-UTF16-V UniCNS-UTF32-H UniCNS-UTF32-V UniCNS-UTF8-H UniCNS-UTF8-V
5-
Adobe_Japan1_Uni=UniJIS-UTF16-H UniJIS-UTF16-V
5+
Adobe_Japan1_Uni=UniJIS-UTF16-H UniJIS-UTF16-V UniJIS-UCS2-H UniJIS-UCS2-HW-H UniJIS2004-UTF16-H
66
Adobe_Korea1_Uni=UniKS-UTF16-H UniKS-UTF16-V
77
Adobe_GB1_Uni=UniGB-UTF16-H UniGB-UTF16-V
88
Adobe_CNS1_Uni=UniCNS-UTF16-H UniCNS-UTF16-V

io/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<artifactId>commons</artifactId>
1616
<version>${project.version}</version>
1717
</dependency>
18+
<dependency>
19+
<groupId>com.itextpdf</groupId>
20+
<artifactId>font-asian</artifactId>
21+
<version>${project.version}</version>
22+
<scope>test</scope>
23+
</dependency>
1824
<dependency>
1925
<groupId>com.itextpdf</groupId>
2026
<artifactId>pdftest</artifactId>

io/src/main/java/com/itextpdf/io/font/CMapEncoding.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public CMapEncoding(String cmap, String uniMap) {
7777
isDirect = true;
7878
this.codeSpaceRanges = IDENTITY_H_V_CODESPACE_RANGES;
7979
} else {
80-
cid2Code = FontCache.getCidToCodepointCmap(cmap);
80+
cid2Code = CjkResourceLoader.getCidToCodepointCmap(cmap);
8181
code2Cid = CMapEncoding.getCodeToCidCmap(cmap, cid2Code);
8282
this.codeSpaceRanges = cid2Code.getCodeSpaceRanges();
8383
}
@@ -197,7 +197,7 @@ public List<byte[]> getCodeSpaceRanges() {
197197

198198
private static CMapCodepointToCid getCodeToCidCmap(String cmap, CMapCidToCodepoint cid2Code) {
199199
try {
200-
return FontCache.getCodepointToCidCmap(cmap);
200+
return CjkResourceLoader.getCodepointToCidCmap(cmap);
201201
} catch (com.itextpdf.io.exceptions.IOException ex) {
202202
// if not found, fall back to reversing
203203
return new CMapCodepointToCid(cid2Code);

io/src/main/java/com/itextpdf/io/font/CidFont.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.io.font;
2424

2525
import com.itextpdf.io.exceptions.IOException;
26-
import com.itextpdf.io.font.cmap.CMapCidUni;
2726
import com.itextpdf.io.font.cmap.CMapUniCid;
2827
import com.itextpdf.io.font.otf.Glyph;
2928
import com.itextpdf.io.util.IntHashtable;
@@ -35,27 +34,20 @@ This file is part of the iText (R) project.
3534

3635
public class CidFont extends FontProgram {
3736

38-
3937
private String fontName;
4038
private int pdfFontFlags;
4139
private Set<String> compatibleCmaps;
4240

43-
CidFont(String fontName, Set<String> cmaps) {
41+
CidFont(String fontName, String cmap, Set<String> compatibleCmaps) {
4442
this.fontName = fontName;
45-
compatibleCmaps = cmaps;
43+
this.compatibleCmaps = compatibleCmaps;
4644
fontNames = new FontNames();
4745
initializeCidFontNameAndStyle(fontName);
4846
Map<String, Object> fontDesc = CidFontProperties.getAllFonts().get(fontNames.getFontName());
4947
if (fontDesc == null) {
5048
throw new IOException("There is no such predefined font: {0}").setMessageParams(fontName);
5149
}
52-
initializeCidFontProperties(fontDesc);
53-
}
54-
55-
CidFont(String fontName, Set<String> cmaps, Map<String, Object> fontDescription) {
56-
initializeCidFontNameAndStyle(fontName);
57-
initializeCidFontProperties(fontDescription);
58-
compatibleCmaps = cmaps;
50+
initializeCidFontProperties(fontDesc, cmap);
5951
}
6052

6153
public boolean compatibleWith(String cmap) {
@@ -97,7 +89,7 @@ private void initializeCidFontNameAndStyle(String fontName) {
9789
fontNames.setFullName(new String[][]{new String[]{"", "", "", fontNames.getFontName()}});
9890
}
9991

100-
private void initializeCidFontProperties(Map<String, Object> fontDesc) {
92+
private void initializeCidFontProperties(Map<String, Object> fontDesc, String cmap) {
10193
fontIdentification.setPanose((String) fontDesc.get("Panose"));
10294
fontMetrics.setItalicAngle(Integer.parseInt((String) fontDesc.get("ItalicAngle")));
10395
fontMetrics.setCapHeight(Integer.parseInt((String) fontDesc.get("CapHeight")));
@@ -113,10 +105,10 @@ private void initializeCidFontProperties(Map<String, Object> fontDesc) {
113105
int ury = Integer.parseInt(tk.nextToken());
114106
fontMetrics.updateBbox(llx, lly, urx, ury);
115107
registry = (String) fontDesc.get("Registry");
116-
String uniMap = getCompatibleUniMap(registry);
108+
String uniMap = getCompatibleUniMap(registry, cmap);
117109
if (uniMap != null) {
118110
IntHashtable metrics = (IntHashtable) fontDesc.get("W");
119-
CMapUniCid uni2cid = FontCache.getUni2CidCmap(uniMap);
111+
CMapUniCid uni2cid = CjkResourceLoader.getUni2CidCmap(uniMap);
120112
avgWidth = 0;
121113
for (int cp: uni2cid.getCodePoints()) {
122114
int cid = uni2cid.lookup(cp);
@@ -133,14 +125,22 @@ private void initializeCidFontProperties(Map<String, Object> fontDesc) {
133125
}
134126
}
135127

136-
private static String getCompatibleUniMap(String registry) {
128+
private static String getCompatibleUniMap(String registry, String cmap) {
129+
Set<String> compatibleUniMaps = CidFontProperties.getRegistryNames().get(registry + "_Uni");
130+
// 'cmap != null &&' part here is for autoport
131+
if (cmap != null && compatibleUniMaps.contains(cmap)) {
132+
return cmap;
133+
}
134+
137135
String uniMap = "";
138-
for (String name : CidFontProperties.getRegistryNames().get(registry + "_Uni")) {
136+
for (String name : compatibleUniMaps) {
139137
uniMap = name;
140138
if (name.endsWith("H")) {
139+
uniMap = name;
141140
break;
142141
}
143142
}
143+
144144
return uniMap;
145145
}
146146
}

io/src/main/java/com/itextpdf/io/font/CidFontProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This file is part of the iText (R) project.
2828

2929
import java.io.InputStream;
3030
import java.util.HashMap;
31-
import java.util.HashSet;
31+
import java.util.LinkedHashSet;
3232
import java.util.Map;
3333
import java.util.Properties;
3434
import java.util.Set;
@@ -94,7 +94,7 @@ private static void loadRegistry() throws java.io.IOException {
9494
for (Object key : p.keySet()) {
9595
String value = p.getProperty((String)key);
9696
String[] sp = value.split(" ");
97-
Set<String> hs = new HashSet<String>();
97+
Set<String> hs = new LinkedHashSet<String>();
9898
for (String s : sp) {
9999
if (s.length() > 0)
100100
hs.add(s);

0 commit comments

Comments
 (0)