101 * script/font combinations will be small, so a flat hashtable should |
101 * script/font combinations will be small, so a flat hashtable should |
102 * suffice. |
102 * suffice. |
103 * */ |
103 * */ |
104 public final class SunLayoutEngine implements LayoutEngine, LayoutEngineFactory { |
104 public final class SunLayoutEngine implements LayoutEngine, LayoutEngineFactory { |
105 private static native void initGVIDs(); |
105 private static native void initGVIDs(); |
|
106 private static final boolean useICU; |
106 static { |
107 static { |
107 FontManagerNativeLibrary.load(); |
108 FontManagerNativeLibrary.load(); |
108 initGVIDs(); |
109 initGVIDs(); |
|
110 String le = java.security.AccessController.doPrivileged( |
|
111 new sun.security.action. |
|
112 GetPropertyAction("sun.font.layoutengine", "")); |
|
113 useICU = le.equals("icu"); |
|
114 String verbose = java.security.AccessController.doPrivileged( |
|
115 new sun.security.action. |
|
116 GetPropertyAction("sun.font.layoutengine.verbose", "")); |
|
117 if ("true".equalsIgnoreCase(verbose)) { |
|
118 System.out.println("Using " + (useICU ? "icu." : "harfbuzz.")); |
|
119 } |
109 } |
120 } |
110 |
121 |
111 private LayoutEngineKey key; |
122 private LayoutEngineKey key; |
112 |
123 |
113 private static LayoutEngineFactory instance; |
124 private static LayoutEngineFactory instance; |
148 |
159 |
149 private SunLayoutEngine(LayoutEngineKey key) { |
160 private SunLayoutEngine(LayoutEngineKey key) { |
150 this.key = key; |
161 this.key = key; |
151 } |
162 } |
152 |
163 |
153 public void layout(FontStrikeDesc desc, float[] mat, int gmask, |
164 private boolean isAAT(Font2D font) { |
|
165 if (font instanceof TrueTypeFont) { |
|
166 TrueTypeFont ttf = (TrueTypeFont)font; |
|
167 return ttf.getDirectoryEntry(TrueTypeFont.morxTag) != null || |
|
168 ttf.getDirectoryEntry(TrueTypeFont.mortTag) != null; |
|
169 } else if (font instanceof PhysicalFont) { |
|
170 PhysicalFont pf = (PhysicalFont)font; |
|
171 return pf.getTableBytes(TrueTypeFont.morxTag) != null || |
|
172 pf.getTableBytes(TrueTypeFont.mortTag) != null; |
|
173 } |
|
174 return false; |
|
175 } |
|
176 |
|
177 public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask, |
154 int baseIndex, TextRecord tr, int typo_flags, |
178 int baseIndex, TextRecord tr, int typo_flags, |
155 Point2D.Float pt, GVData data) { |
179 Point2D.Float pt, GVData data) { |
156 Font2D font = key.font(); |
180 Font2D font = key.font(); |
157 FontStrike strike = font.getStrike(desc); |
181 FontStrike strike = font.getStrike(desc); |
158 long layoutTables = font.getLayoutTableCache(); |
182 long layoutTables = font.getLayoutTableCache(); |
|
183 if (useICU) { |
159 nativeLayout(font, strike, mat, gmask, baseIndex, |
184 nativeLayout(font, strike, mat, gmask, baseIndex, |
160 tr.text, tr.start, tr.limit, tr.min, tr.max, |
185 tr.text, tr.start, tr.limit, tr.min, tr.max, |
161 key.script(), key.lang(), typo_flags, pt, data, |
186 key.script(), key.lang(), typo_flags, pt, data, |
162 font.getUnitsPerEm(), layoutTables); |
187 font.getUnitsPerEm(), layoutTables); |
163 } |
188 } else { |
164 |
189 long pNativeFont = font.getPlatformNativeFontPtr(); // used on OSX |
|
190 // pScaler probably not needed long term. |
|
191 long pScaler = 0L; |
|
192 if (font instanceof FileFont) { |
|
193 pScaler = ((FileFont)font).getScaler().nativeScaler; |
|
194 } |
|
195 shape(font, strike, ptSize, mat, pScaler, pNativeFont, isAAT(font), |
|
196 tr.text, data, key.script(), |
|
197 tr.start, tr.limit, baseIndex, pt, |
|
198 typo_flags, gmask); |
|
199 } |
|
200 } |
|
201 |
|
202 /* Native method to invoke ICU layout engine */ |
165 private static native void |
203 private static native void |
166 nativeLayout(Font2D font, FontStrike strike, float[] mat, int gmask, |
204 nativeLayout(Font2D font, FontStrike strike, float[] mat, int gmask, |
167 int baseIndex, char[] chars, int offset, int limit, |
205 int baseIndex, char[] chars, int offset, int limit, |
168 int min, int max, int script, int lang, int typo_flags, |
206 int min, int max, int script, int lang, int typo_flags, |
169 Point2D.Float pt, GVData data, long upem, long layoutTables); |
207 Point2D.Float pt, GVData data, long upem, long layoutTables); |
|
208 |
|
209 |
|
210 /* Native method to invoke harfbuzz layout engine */ |
|
211 private static native boolean |
|
212 shape(Font2D font, FontStrike strike, float ptSize, float[] mat, |
|
213 long pscaler, long pNativeFont, boolean aat, |
|
214 char[] chars, GVData data, |
|
215 int script, int offset, int limit, |
|
216 int baseIndex, Point2D.Float pt, int typo_flags, int slot); |
170 } |
217 } |