• R/O
  • SSH
  • HTTPS

copper: Commit


Commit MetaInfo

Revision1601 (tree)
Time2020-04-18 12:42:26
Authormiyabe

Log Message

IVS support

Change Summary

Incremental Difference

--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/Font.java (revision 1600)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/Font.java (revision 1601)
@@ -28,17 +28,6 @@
2828 public int toGID(int c);
2929
3030 /**
31- * 文字をグリフコードに変換します(IVS対応)。
32- * IVSコードを維持する場合は−1
33- * 削除する場合は0
34- *
35- * @param c
36- * @param ivs
37- * @return
38- */
39- public int toGID(int c, int ivs);リガチャで実装できないか
40-
41- /**
4231 * グリフの進行方向の進行幅を返します。
4332 *
4433 * @param gid
@@ -66,11 +55,11 @@
6655 /**
6756 * 合字を返します。 合字が存在しない場合は0を返します。
6857 *
69- * @param sgid
7058 * @param gid
59+ * @param cid
7160 * @return
7261 */
73- public int getLigature(int sgid, int gid);
62+ public int getLigature(int gid, int cid);
7463
7564 /**
7665 * ランをグラフィックコンテキストに出力します。
--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/FontMetricsImpl.java (revision 1600)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/FontMetricsImpl.java (revision 1601)
@@ -98,8 +98,8 @@
9898 return this.size * this.getFont().getKerning(gid, sgid) / FontSource.DEFAULT_UNITS_PER_EM;
9999 }
100100
101- public int getLigature(int gid, int sgid) {
102- return this.getFont().getLigature(gid, sgid);
101+ public int getLigature(int gid, int cid) {
102+ return this.getFont().getLigature(gid, cid);
103103 }
104104
105105 public boolean canDisplay(int c) {
--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFont.java (revision 1601)
@@ -197,7 +197,7 @@
197197 return 0;
198198 }
199199
200- public int getLigature(int sgid, int gid) {
200+ public int getLigature(int gid, int cid) {
201201 return -1;
202202 }
203203 }
\ No newline at end of file
--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFontImpl.java (revision 1600)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFontImpl.java (revision 1601)
@@ -16,10 +16,6 @@
1616 this.unicodes.set(gid, (char) c);
1717 return gid;
1818 }
19-
20- public int toGID(int c, int vs) {
21- return 0;
22- }
2319
2420 protected int toChar(int gid) {
2521 return this.unicodes.get(gid);
--- copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFontSource.java (revision 1600)
+++ copper/trunk/sakae/sakae-core/src/main/java/jp/cssj/sakae/font/otf/OpenTypeFontSource.java (revision 1601)
@@ -248,7 +248,13 @@
248248 return false;
249249 }
250250 }
251- return this.cmap.mapCharCode(c) != 0;
251+ if (this.cmap.mapCharCode(c) != 0) {
252+ return true;
253+ }
254+ if (this.uvsCmap != null && this.uvsCmap.isVarSelector(c)) {
255+ return true;
256+ }
257+ return false;
252258 }
253259
254260 public Font createFont() {
--- copper/trunk/sakae/sakae-pdf/src/example/java/jp/cssj/sakae/tools/BuildEmojiIndexTool.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/example/java/jp/cssj/sakae/tools/BuildEmojiIndexTool.java (revision 1601)
@@ -4,6 +4,8 @@
44 import java.io.FileOutputStream;
55 import java.io.OutputStreamWriter;
66 import java.io.PrintWriter;
7+import java.util.HashSet;
8+import java.util.Set;
79
810 public class BuildEmojiIndexTool {
911
@@ -11,13 +13,38 @@
1113 File dir = new File("src/main/resources/jp/cssj/sakae/font/emoji");
1214 File indexFile = new File(dir, "INDEX");
1315 try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(indexFile), "ISO8859-1"))) {
14- for (String name : dir.list()) {
15- if (!name.endsWith(".svg")) {
16+ Set<String> codes = new HashSet<String>();
17+ for (String code : dir.list()) {
18+ if (!code.endsWith(".svg")) {
1619 continue;
1720 }
18- name = name.substring(7, name.length() - 4);
19- out.println(name);
21+ code = code.substring(7, code.length() - 4);
22+ for (;;) {
23+ if (!codes.contains(code)) {
24+ out.println(code);
25+ codes.add(code);
26+ }
27+ int ub = code.lastIndexOf('_');
28+ if (ub == -1) {
29+ break;
30+ }
31+ code = code.substring(0, ub);
32+ }
2033 }
34+ out.println("200d");
35+
36+ for (String code : dir.list()) {
37+ if (!code.endsWith(".svg")) {
38+ continue;
39+ }
40+ code = code.substring(7, code.length() - 4);
41+ for (String c : code.split("_")) {
42+ if (!codes.contains(c)) {
43+ System.err.println(c);
44+ codes.add(c);
45+ }
46+ }
47+ }
2148 }
2249 }
2350
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFont.java (revision 1601)
@@ -3,11 +3,9 @@
33 import java.awt.Graphics2D;
44 import java.awt.geom.AffineTransform;
55 import java.awt.geom.Dimension2D;
6-import java.io.BufferedReader;
76 import java.io.IOException;
87 import java.io.InputStream;
9-import java.io.InputStreamReader;
10-import java.util.Collections;
8+import java.net.URL;
119 import java.util.HashMap;
1210 import java.util.Map;
1311
@@ -31,60 +29,26 @@
3129 import jp.cssj.sakae.svg.GVTBuilderImpl;
3230 import jp.cssj.sakae.svg.SVGBridgeGraphics2D;
3331 import jp.cssj.sakae.svg.UserAgentImpl;
34-import jp.cssj.sakae.util.IntList;
3532
3633 class EmojiFont implements ImageFont {
3734 private static final long serialVersionUID = 2L;
35+ protected final EmojiFontSource source;
36+ protected final Map<Integer, GraphicsNode> gidToEmoji = new HashMap<Integer, GraphicsNode>();
37+ protected static final Dimension2D VIEWPORT = new Dimension2DImpl(128, 128);
3838
39- protected static final Map<String, Integer> codeToFgid;
40- static {
41- Map<String, Integer> ctog = new HashMap<String, Integer>();
42- try (BufferedReader in = new BufferedReader(
43- new InputStreamReader(EmojiFontSource.class.getResourceAsStream("INDEX"), "ISO8859-1"))) {
44- int gid = 0;
45- for (String line = in.readLine(); line != null; line = in.readLine()) {
46- ++gid;
47- ctog.put(line, gid);
48- }
49- } catch (Exception e) {
50- throw new RuntimeException(e);
51- }
52- codeToFgid = Collections.unmodifiableMap(ctog);
53- }
54- private int glyphCount = 1;
55-
56- private final EmojiFontSource source;
57-
58- private final IntList cidToGid = new IntList(-1);
59- private final Map<Integer, String> gidToCode = new HashMap<Integer, String>();
60- private final IntList fgidToGid = new IntList(-1);
61-
62- private final Map<Integer, GraphicsNode> gidToEmoji = new HashMap<Integer, GraphicsNode>();
63- private static final Dimension2D VIEWPORT = new Dimension2DImpl(128, 128);
64-
6539 public EmojiFont(EmojiFontSource source) {
6640 this.source = source;
6741 }
6842
6943 public int toGID(final int c) {
70- String code = Integer.toHexString(c).toLowerCase();
71- if (!codeToFgid.containsKey(code)) {
44+ String code = Integer.toHexString(c);
45+ Integer fgid = EmojiFontSource.codeToFgid.get(code);
46+ if (fgid == null) {
7247 return 0;
7348 }
74- int gid = this.cidToGid.get(c);
75- if (gid != -1) {
76- return gid;
77- }
78- gid = this.glyphCount++;
79- this.cidToGid.set(c, gid);
80- this.gidToCode.put(gid, code);
81- return gid;
49+ return fgid;
8250 }
8351
84- public int toGID(final int c, final int vs) {
85- return 0;
86- }
87-
8852 public short getAdvance(int gid) {
8953 return 1000;
9054 }
@@ -106,21 +70,17 @@
10670 return 0;
10771 }
10872
109- public int getLigature(int sgid, int gid) {
110- String scode = this.gidToCode.get(sgid);
111- String code = scode + "_" + this.gidToCode.get(gid);
112- Integer fgid = codeToFgid.get(code);
73+ public int getLigature(int gid, int cid) {
74+ if (gid == -1) {
75+ return -1;
76+ }
77+ String scode = EmojiFontSource.fgidToCode.get(gid);
78+ String code = scode + "_" + Integer.toHexString(cid);
79+ Integer fgid = EmojiFontSource.codeToFgid.get(code);
11380 if (fgid == null) {
11481 return -1;
11582 }
116- int lgid = this.fgidToGid.get(fgid);
117- if (lgid != -1) {
118- return lgid;
119- }
120- lgid = this.glyphCount++;
121- this.fgidToGid.set(fgid, lgid);
122- this.gidToCode.put(lgid, code);
123- return lgid;
83+ return fgid;
12484 }
12585
12686 public void drawTo(GC gc, Text text) throws IOException, GraphicsException {
@@ -130,8 +90,15 @@
13090 public void drawGlyphForGid(GC gc, int gid, AffineTransform at) {
13191 GraphicsNode gvtRoot = this.gidToEmoji.get(gid);
13292 if (gvtRoot == null) {
133- String code = this.gidToCode.get(gid);
134- try (InputStream in = EmojiFontSource.class.getResourceAsStream("emoji_u" + code + ".svg")) {
93+ String code = EmojiFontSource.fgidToCode.get(gid);
94+ if (code.endsWith("_200d")) {
95+ code = code.substring(0, code.length() - 5);
96+ }
97+ URL url = EmojiFontSource.class.getResource("emoji_u" + code + ".svg");
98+ if (url == null) {
99+ return;
100+ }
101+ try (InputStream in = url.openStream()) {
135102 SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
136103 XMLResourceDescriptor.getXMLParserClassName());
137104 SVGOMDocument doc = (SVGOMDocument) factory.createDocument(null, in);
@@ -146,9 +113,6 @@
146113 throw new RuntimeException(e);
147114 }
148115 }
149- if (gvtRoot == null) {
150- return;
151- }
152116
153117 gc.begin();
154118 if (at != null) {
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFontSource.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/font/emoji/EmojiFontSource.java (revision 1601)
@@ -1,5 +1,11 @@
11 package jp.cssj.sakae.font.emoji;
22
3+import java.io.BufferedReader;
4+import java.io.InputStreamReader;
5+import java.util.Collections;
6+import java.util.HashMap;
7+import java.util.Map;
8+
39 import jp.cssj.sakae.font.AbstractFontSource;
410 import jp.cssj.sakae.font.BBox;
511 import jp.cssj.sakae.font.Font;
@@ -16,6 +22,26 @@
1622
1723 private static final BBox BBOX = new BBox((short) 0, DEFAULT_DESCENT, (short) 1000, DEFAULT_ASCENT);
1824
25+ protected static final Map<String, Integer> codeToFgid;
26+ protected static final Map<Integer, String> fgidToCode;
27+ static {
28+ Map<String, Integer> ctog = new HashMap<String, Integer>();
29+ Map<Integer, String> gtoc = new HashMap<Integer, String>();
30+ try (BufferedReader in = new BufferedReader(
31+ new InputStreamReader(EmojiFontSource.class.getResourceAsStream("INDEX"), "ISO8859-1"))) {
32+ int gid = 0;
33+ for (String code = in.readLine(); code != null; code = in.readLine()) {
34+ ++gid;
35+ ctog.put(code, gid);
36+ gtoc.put(gid, code);
37+ }
38+ } catch (Exception e) {
39+ throw new RuntimeException(e);
40+ }
41+ codeToFgid = Collections.unmodifiableMap(ctog);
42+ fgidToCode = Collections.unmodifiableMap(gtoc);
43+ }
44+
1945 public static final EmojiFontSource INSTANCES_LTR = new EmojiFontSource(FontStyle.DIRECTION_LTR);
2046 public static final EmojiFontSource INSTANCES_TB = new EmojiFontSource(FontStyle.DIRECTION_TB);
2147
@@ -66,10 +92,7 @@
6692 }
6793
6894 public boolean canDisplay(int c) {
69- if (c == 0x200D || (c >= 0x1F3FB && c <= 0x1F3FF)) {
70- return true;
71- }
72- return EmojiFont.codeToFgid.containsKey(Integer.toHexString(c).toLowerCase());
95+ return codeToFgid.containsKey(Integer.toHexString(c));
7396 }
7497
7598 public Panose getPanose() {
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/FontManagerImpl.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/FontManagerImpl.java (revision 1601)
@@ -98,7 +98,7 @@
9898 protected class CharacterHandler implements Glypher {
9999 private GlyphHandler glyphHandler;
100100
101- private final char[] ch = new char[6];
101+ private final char[] ch = new char[12];
102102
103103 private int charOffset;
104104
@@ -110,6 +110,8 @@
110110
111111 private int fontBound = 0;
112112
113+ private boolean zwj = false; // ZWJ(u200D)およびそれに続く文字はフォントを変えない
114+
113115 private FontStyle fontStyle;
114116
115117 private FontMetricsImpl fontMetrics = null;
@@ -136,6 +138,7 @@
136138 if (!this.outOfRun) {
137139 this.glyph();
138140 this.endRun();
141+ this.zwj = false;
139142 }
140143 }
141144
@@ -161,31 +164,25 @@
161164 }
162165 }
163166
164- // IVSの処理
165- if (this.len > 0 && ((cc >= 0xFE00 && cc <= 0xFE0F) || (cc >= 0xE0100 && cc <= 0xE01EF))) {
166- int xgid = this.fontMetrics.getFont().toGID(this.ch[this.len - 1], cc);
167- if (xgid > 0) {
168- this.gid = xgid;
167+ // ランの範囲を作成
168+ if (this.fontMetrics.canDisplay(cc)) {
169+ if (cc == 0x200D) {
170+ this.zwj = true;
169171 }
170- if (xgid >= 0) {
171- continue;
172- }
173- }
174-
175- // ランの範囲を作成
176- if (!this.fontMetrics.canDisplay(cc)) {
172+ } else {
177173 this.glyphBreak();
178174 this.initFont();
179175 }
180-
181- // 利用可能な文字を検出
182- for (int j = 0; j < this.fontBound; ++j) {
183- FontMetricsImpl metrics = (FontMetricsImpl) this.fontListMetrics.getFontMetrics(j);
184- if (metrics.canDisplay(cc)) {
185- this.glyphBreak();
186- this.fontMetrics = (FontMetricsImpl) this.fontListMetrics.getFontMetrics(j);
187- this.fontBound = j;
188- break;
176+ if (!this.zwj) {
177+ // 優先順位の高いフォントに切り替える
178+ for (int j = 0; j < this.fontBound; ++j) {
179+ FontMetricsImpl metrics = (FontMetricsImpl) this.fontListMetrics.getFontMetrics(j);
180+ if (metrics.canDisplay(cc)) {
181+ this.glyphBreak();
182+ this.fontMetrics = (FontMetricsImpl) this.fontListMetrics.getFontMetrics(j);
183+ this.fontBound = j;
184+ break;
185+ }
189186 }
190187 }
191188
@@ -202,7 +199,7 @@
202199 }
203200
204201 // 連字のチェック
205- int lgid = this.fontMetrics.getLigature(this.gid, gid);
202+ int lgid = this.len >= this.ch.length ? -1 : this.fontMetrics.getLigature(this.gid, cc);
206203 if (lgid != -1) {
207204 // 連字にできる
208205 this.gid = this.pgid;
@@ -224,6 +221,7 @@
224221 this.ch[1] = ls;
225222 this.len = 2;
226223 }
224+ this.zwj = (cc == 0x200D);
227225 }
228226
229227 this.pgid = this.gid;
@@ -249,6 +247,7 @@
249247 private void initFont() {
250248 this.fontBound = this.fontListMetrics.getLength();
251249 this.fontMetrics = (FontMetricsImpl) this.fontListMetrics.getFontMetrics(this.fontBound - 1);
250+ this.zwj = false;
252251 }
253252
254253 public void flush() {
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/CIDFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/CIDFont.java (revision 1601)
@@ -27,11 +27,11 @@
2727 return this.name;
2828 }
2929
30- public short getKerning(int scid, int cid) {
30+ public short getKerning(int gid, int cid) {
3131 return 0;
3232 }
3333
34- public int getLigature(int scid, int cid) {
34+ public int getLigature(int gid, int cid) {
3535 return -1;
3636 }
3737
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/embedded/OpenTypeEmbeddedCIDFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/embedded/OpenTypeEmbeddedCIDFont.java (revision 1601)
@@ -19,6 +19,7 @@
1919 import jp.cssj.sakae.util.IntList;
2020 import jp.cssj.sakae.util.ShortList;
2121 import net.zamasoft.font.Glyph;
22+import net.zamasoft.font.table.UvsCmapFormat;
2223
2324 class OpenTypeEmbeddedCIDFont extends OpenTypeFont implements PdfEmbeddedFont {
2425 private static final long serialVersionUID = 0L;
@@ -54,13 +55,7 @@
5455 int fgid = source.getCmapFormat().mapCharCode(c);
5556 return this.addGID(c, fgid);
5657 }
57-
58- public int toGID(int c, int ivs) {
59- OpenTypeEmbeddedCIDFontSource source = (OpenTypeEmbeddedCIDFontSource) this.getFontSource();
60- int fgid = source.getUvsCmapFormat().mapCharCode(c, ivs);
61- return this.addGID(c, fgid);
62- }
63-
58+
6459 private int addGID(int c, int fgid) {
6560 if (fgid == 0) {
6661 return 0;
@@ -70,17 +65,32 @@
7065 }
7166 int gid = this.fgidToGid.get(fgid);
7267 if (gid == -1) {
73- gid = this.glyphCount;
68+ gid = this.glyphCount++;
7469 this.fgidToGid.set(fgid, gid);
7570 this.gidToFgid.set(gid, fgid);
7671 this.gidToCid.set(gid, c);
77- ++this.glyphCount;
7872 this.widths.set(gid, this.getHAdvance(fgid));
7973 this.heights.set(gid, this.getVAdvance(fgid));
8074 }
81- return gid;
75+ return gid;
8276 }
8377
78+ public int getLigature(int gid, int cid) {
79+ if (gid == -1) {
80+ return -1;
81+ }
82+ UvsCmapFormat ucf = this.source.getUvsCmapFormat();
83+ if (ucf == null || !ucf.isVarSelector(cid)) {
84+ return -1;
85+ }
86+ int c = this.gidToCid.get(gid);
87+ int fgid = ucf.mapCharCode(c, cid);
88+ if (fgid == 0) {
89+ return -1;
90+ }
91+ return this.addGID(c, fgid);
92+ }
93+
8494 protected int toChar(int gid) {
8595 return this.gidToCid.get(gid);
8696 }
@@ -170,7 +180,6 @@
170180 // return glyph.getCharString();
171181 }
172182
173-
174183 public int getSupplement() {
175184 return CIDUtils.SUPPLEMENT;
176185 }
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/embedded/SystemEmbeddedCIDFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/embedded/SystemEmbeddedCIDFont.java (revision 1601)
@@ -67,10 +67,6 @@
6767 }
6868 return gid;
6969 }
70-
71- public int toGID(int c, int ivs) {
72- return 0;
73- }
7470
7571 public short getAdvance(int gid) {
7672 return this.advances.get(gid);
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/identity/OpenTypeCIDIdentityFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/identity/OpenTypeCIDIdentityFont.java (revision 1601)
@@ -57,15 +57,6 @@
5757 return gid;
5858 }
5959
60- public int toGID(int c, int vs) {
61- OpenTypeCIDIdentityFontSource source = (OpenTypeCIDIdentityFontSource) this.getFontSource();
62- int gid = source.getUvsCmapFormat().mapCharCode(c, vs);
63- if (this.vSubst != null) {
64- gid = this.vSubst.substitute(gid);
65- }
66- return gid;
67- }
68-
6960 protected int toChar(int gid) {
7061 return this.unicodes.get(gid);
7162 }
@@ -130,7 +121,7 @@
130121 return 0;
131122 }
132123
133- public int getLigature(int scid, int cid) {
124+ public int getLigature(int gid, int cid) {
134125 return -1;
135126 }
136127 }
\ No newline at end of file
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/identity/SystemCIDIdentityFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/identity/SystemCIDIdentityFont.java (revision 1601)
@@ -31,9 +31,6 @@
3131 int gid = source.toGID(c);
3232 return gid;
3333 }
34- public int toGID(int c, int vs) {
35- return 0;
36- }
3734
3835 public short getAdvance(int cid) {
3936 SystemCIDIdentityFontSource source = (SystemCIDIdentityFontSource) this.source;
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/keyed/CIDKeyedFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/keyed/CIDKeyedFont.java (revision 1601)
@@ -231,10 +231,6 @@
231231 return gid;
232232 }
233233
234- public int toGID(int c, int vs) {
235- return 0;
236- }
237-
238234 public short getAdvance(int gid) {
239235 if (this.source.getDirection() == FontStyle.DIRECTION_TB) {
240236 return 1000;
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/missing/MissingCIDFont.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/cid/missing/MissingCIDFont.java (revision 1601)
@@ -73,10 +73,6 @@
7373 }
7474 return gid;
7575 }
76-
77- public int toGID(final int c, final int ivs) {
78- return -1;
79- }
8076
8177 public short getAdvance(int gid) {
8278 int c = this.unicodes.get(gid);
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/AbstractType1FontSource.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/AbstractType1FontSource.java (revision 1601)
@@ -12,6 +12,7 @@
1212 import jp.cssj.sakae.pdf.font.PdfFontSource;
1313 import jp.cssj.sakae.pdf.font.type1.AFMFontInfo.AFMGlyphInfo;
1414 import jp.cssj.sakae.pdf.font.util.PdfFontUtils;
15+import jp.cssj.sakae.util.IntList;
1516
1617 /**
1718 * 標準Type1フォントです。
@@ -50,6 +51,8 @@
5051
5152 protected abstract GlyphInfo[] getGidToGi();
5253
54+ protected abstract IntList getCidToGid();
55+
5356 protected synchronized Font getAwtFont() {
5457 if (this.awtFont == null) {
5558 this.awtFont = PdfFontUtils.toAwtFont(this);
@@ -85,12 +88,12 @@
8588 return gi.getKerning(pgid);
8689 }
8790
88- int getLigature(int gid, int pgid) {
91+ int getLigature(int gid, int cid) {
8992 if (!this.canDisplayGID(gid)) {
9093 return -1;
9194 }
9295 GlyphInfo gi = this.getGidToGi()[gid];
93- return gi.getLigature(pgid);
96+ return gi.getLigature(this.getCidToGid().get(cid));
9497 }
9598
9699 abstract int toGID(int c);
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/LetterType1FontSource.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/LetterType1FontSource.java (revision 1601)
@@ -122,16 +122,16 @@
122122 return pair;
123123 }
124124
125- protected GlyphInfo[] getGidToGi() {
125+ protected synchronized GlyphInfo[] getGidToGi() {
126126 return (GlyphInfo[]) this.getPair()[1];
127127 }
128128
129- protected IntList getCharToGid() {
129+ protected synchronized IntList getCidToGid() {
130130 return (IntList) this.getPair()[0];
131131 }
132132
133133 int toGID(int c) {
134- return this.getCharToGid().get(c);
134+ return this.getCidToGid().get(c);
135135 }
136136
137137 String getEncoding() {
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/SymbolicType1FontSource.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/SymbolicType1FontSource.java (revision 1601)
@@ -99,7 +99,7 @@
9999 return gidToGi;
100100 }
101101
102- private synchronized IntList getCharToGid() {
102+ protected synchronized IntList getCidToGid() {
103103 IntList charToGid = null;
104104 synchronized (this) {
105105 if (this.charToGid != null) {
@@ -138,7 +138,7 @@
138138 }
139139
140140 int toGID(int c) {
141- int gid = this.getCharToGid().get(c);
141+ int gid = this.getCidToGid().get(c);
142142 return gid;
143143 }
144144
--- copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/Type1Font.java (revision 1600)
+++ copper/trunk/sakae/sakae-pdf/src/main/java/jp/cssj/sakae/pdf/font/type1/Type1Font.java (revision 1601)
@@ -45,16 +45,12 @@
4545 return gid;
4646 }
4747
48- public int toGID(int c, int ivs) {
49- return 0;
50- }
51-
5248 public short getKerning(int scid, int cid) {
5349 return this.source.getKerning(scid, cid);
5450 }
5551
56- public int getLigature(int scid, int cid) {
57- return this.source.getLigature(scid, cid);
52+ public int getLigature(int gid, int cid) {
53+ return this.source.getLigature(gid, cid);
5854 }
5955
6056 public short getAdvance(int gid) {
--- copper/trunk/sakae/zs-font/src/main/java/net/zamasoft/font/table/UvsCmapFormat.java (revision 1600)
+++ copper/trunk/sakae/zs-font/src/main/java/net/zamasoft/font/table/UvsCmapFormat.java (revision 1601)
@@ -4,11 +4,15 @@
44 import java.io.RandomAccessFile;
55 import java.util.Collections;
66 import java.util.HashMap;
7+import java.util.HashSet;
78 import java.util.Map;
9+import java.util.Set;
810
911 public class UvsCmapFormat extends CmapFormat {
1012 protected Map<Long, Integer> codeToGlyphId;
1113
14+ protected Set<Integer> varSelectors;
15+
1216 protected UvsCmapFormat(int format, int numGlyphs, RandomAccessFile data) throws IOException {
1317 data.readInt();
1418 this.processSubtype14(data, numGlyphs);
@@ -28,19 +32,22 @@
2832 long start = data.getFilePointer() - 6;
2933 long numVarSelectorRecords = data.readInt();
3034 this.codeToGlyphId = new HashMap<Long, Integer>();
35+ this.varSelectors = new HashSet<Integer>();
3136 for (int i = 0; i < numVarSelectorRecords; ++i) {
3237 int varSelector = 0xFFFFFF & ((data.readShort() << 8) | (0xFF & data.readByte()));
38+ this.varSelectors.add(varSelector);
39+ @SuppressWarnings("unused")
3340 long defaultUVSOffset = data.readInt();
3441 long nonDefaultUVSOffset = data.readInt();
3542 long pos = data.getFilePointer();
36- if (defaultUVSOffset != 0) {
37- data.seek(start + defaultUVSOffset);
38- long numUnicodeValueRanges = data.readInt();
39- for (int j = 0; j < numUnicodeValueRanges; ++j) {
40- int startUnicodeValue = 0xFFFFFF & ((data.readShort() << 8) | (0xFF & data.readByte()));
41- int additionalCount = 0xFF & data.readByte();
42- }
43- }
43+// if (defaultUVSOffset != 0) {
44+// data.seek(start + defaultUVSOffset);
45+// long numUnicodeValueRanges = data.readInt();
46+// for (int j = 0; j < numUnicodeValueRanges; ++j) {
47+// int startUnicodeValue = 0xFFFFFF & ((data.readShort() << 8) | (0xFF & data.readByte()));
48+// int additionalCount = 0xFF & data.readByte();
49+// }
50+// }
4451 if (nonDefaultUVSOffset != 0) {
4552 data.seek(start + nonDefaultUVSOffset);
4653 long numUVSMappings = data.readInt();
@@ -53,7 +60,7 @@
5360 data.seek(pos);
5461 }
5562 this.codeToGlyphId = Collections.unmodifiableMap(this.codeToGlyphId);
56- System.out.println(codeToGlyphId.get(0x0000795E000E0100L));
63+ this.varSelectors = Collections.unmodifiableSet(this.varSelectors);
5764 }
5865
5966 public int mapCharCode(int c, int vs) {
@@ -60,4 +67,8 @@
6067 Integer glyphId = this.codeToGlyphId.get(((long)c << 32L) | (long)vs);
6168 return glyphId == null ? 0 : glyphId;
6269 }
70+
71+ public boolean isVarSelector(int c) {
72+ return this.varSelectors.contains(c);
73+ }
6374 }
Show on old repository browser