1 /*
2 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
253 FontDescriptor lastFontDescriptor = null;
254 char currentDefaultChar;
255 PlatformFontCache theChar;
256
257 // Simple bounds check
258 int end = start + len;
259 if (start < 0 || end > data.length) {
260 throw new ArrayIndexOutOfBoundsException();
261 }
262
263 if(stringIndex >= end) {
264 return null;
265 }
266
267 // coversion loop
268 while(stringIndex < end)
269 {
270 currentDefaultChar = data[stringIndex];
271
272 // Note that cache sizes must be a power of two!
273 cacheIndex = (int)(currentDefaultChar & this.FONTCACHEMASK);
274
275 theChar = (PlatformFontCache)getFontCache()[cacheIndex];
276
277 // Is the unicode char we want cached?
278 if(theChar == null || theChar.uniChar != currentDefaultChar)
279 {
280 /* find a converter that can convert the current character */
281 currentFontDescriptor = defaultFont;
282 currentDefaultChar = defaultChar;
283 char ch = (char)data[stringIndex];
284 int componentCount = componentFonts.length;
285
286 for (int j = 0; j < componentCount; j++) {
287 FontDescriptor fontDescriptor = componentFonts[j];
288
289 fontDescriptor.encoder.reset();
290 //fontDescriptor.encoder.onUnmappleCharacterAction(...);
291
292 if (fontDescriptor.isExcluded(ch)) {
293 continue;
294 }
295 if (fontDescriptor.encoder.canEncode(ch)) {
296 currentFontDescriptor = fontDescriptor;
297 currentDefaultChar = ch;
298 break;
299 }
300 }
301 try {
302 char[] input = new char[1];
303 input[0] = currentDefaultChar;
304
305 theChar = new PlatformFontCache();
306 if (currentFontDescriptor.useUnicode()) {
307 /*
308 currentFontDescriptor.unicodeEncoder.encode(CharBuffer.wrap(input),
309 theChar.bb,
310 true);
311 */
312 if (currentFontDescriptor.isLE) {
313 theChar.bb.put((byte)(input[0] & 0xff));
314 theChar.bb.put((byte)(input[0] >>8));
315 } else {
316 theChar.bb.put((byte)(input[0] >> 8));
317 theChar.bb.put((byte)(input[0] & 0xff));
318 }
319 }
320 else {
321 currentFontDescriptor.encoder.encode(CharBuffer.wrap(input),
322 theChar.bb,
323 true);
324 }
325 theChar.fontDescriptor = currentFontDescriptor;
326 theChar.uniChar = data[stringIndex];
327 getFontCache()[cacheIndex] = theChar;
328 } catch(Exception e){
329 // Should never happen!
330 System.err.println(e);
331 e.printStackTrace();
332 return null;
403 convertedData[1] = (byte)(convertedDataIndex >> 16);
404 convertedData[2] = (byte)(convertedDataIndex >> 8);
405 convertedData[3] = (byte)convertedDataIndex;
406 }
407 return result;
408 }
409
410 /*
411 * Create fontCache on demand instead of during construction to
412 * reduce overall memory consumption.
413 *
414 * This method is declared final so that its code can be inlined
415 * by the compiler.
416 */
417 protected final Object[] getFontCache() {
418 // This method is not MT-safe by design. Since this is just a
419 // cache anyways, it's okay if we occasionally allocate the array
420 // twice or return an array which will be dereferenced and gced
421 // right away.
422 if (fontCache == null) {
423 fontCache = new Object[this.FONTCACHESIZE];
424 }
425
426 return fontCache;
427 }
428
429 /**
430 * Initialize JNI field and method IDs
431 */
432 private static native void initIDs();
433
434 class PlatformFontCache
435 {
436 char uniChar;
437 FontDescriptor fontDescriptor;
438 ByteBuffer bb = ByteBuffer.allocate(4);
439 }
440 }
|
1 /*
2 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
253 FontDescriptor lastFontDescriptor = null;
254 char currentDefaultChar;
255 PlatformFontCache theChar;
256
257 // Simple bounds check
258 int end = start + len;
259 if (start < 0 || end > data.length) {
260 throw new ArrayIndexOutOfBoundsException();
261 }
262
263 if(stringIndex >= end) {
264 return null;
265 }
266
267 // coversion loop
268 while(stringIndex < end)
269 {
270 currentDefaultChar = data[stringIndex];
271
272 // Note that cache sizes must be a power of two!
273 cacheIndex = (int)(currentDefaultChar & PlatformFont.FONTCACHEMASK);
274
275 theChar = (PlatformFontCache)getFontCache()[cacheIndex];
276
277 // Is the unicode char we want cached?
278 if(theChar == null || theChar.uniChar != currentDefaultChar)
279 {
280 /* find a converter that can convert the current character */
281 currentFontDescriptor = defaultFont;
282 currentDefaultChar = defaultChar;
283 char ch = (char)data[stringIndex];
284 int componentCount = componentFonts.length;
285
286 for (int j = 0; j < componentCount; j++) {
287 FontDescriptor fontDescriptor = componentFonts[j];
288
289 fontDescriptor.encoder.reset();
290 //fontDescriptor.encoder.onUnmappleCharacterAction(...);
291
292 if (fontDescriptor.isExcluded(ch)) {
293 continue;
294 }
295 if (fontDescriptor.encoder.canEncode(ch)) {
296 currentFontDescriptor = fontDescriptor;
297 currentDefaultChar = ch;
298 break;
299 }
300 }
301 try {
302 char[] input = new char[1];
303 input[0] = currentDefaultChar;
304
305 theChar = new PlatformFontCache();
306 if (currentFontDescriptor.useUnicode()) {
307 /*
308 currentFontDescriptor.unicodeEncoder.encode(CharBuffer.wrap(input),
309 theChar.bb,
310 true);
311 */
312 if (FontDescriptor.isLE) {
313 theChar.bb.put((byte)(input[0] & 0xff));
314 theChar.bb.put((byte)(input[0] >>8));
315 } else {
316 theChar.bb.put((byte)(input[0] >> 8));
317 theChar.bb.put((byte)(input[0] & 0xff));
318 }
319 }
320 else {
321 currentFontDescriptor.encoder.encode(CharBuffer.wrap(input),
322 theChar.bb,
323 true);
324 }
325 theChar.fontDescriptor = currentFontDescriptor;
326 theChar.uniChar = data[stringIndex];
327 getFontCache()[cacheIndex] = theChar;
328 } catch(Exception e){
329 // Should never happen!
330 System.err.println(e);
331 e.printStackTrace();
332 return null;
403 convertedData[1] = (byte)(convertedDataIndex >> 16);
404 convertedData[2] = (byte)(convertedDataIndex >> 8);
405 convertedData[3] = (byte)convertedDataIndex;
406 }
407 return result;
408 }
409
410 /*
411 * Create fontCache on demand instead of during construction to
412 * reduce overall memory consumption.
413 *
414 * This method is declared final so that its code can be inlined
415 * by the compiler.
416 */
417 protected final Object[] getFontCache() {
418 // This method is not MT-safe by design. Since this is just a
419 // cache anyways, it's okay if we occasionally allocate the array
420 // twice or return an array which will be dereferenced and gced
421 // right away.
422 if (fontCache == null) {
423 fontCache = new Object[PlatformFont.FONTCACHESIZE];
424 }
425
426 return fontCache;
427 }
428
429 /**
430 * Initialize JNI field and method IDs
431 */
432 private static native void initIDs();
433
434 class PlatformFontCache
435 {
436 char uniChar;
437 FontDescriptor fontDescriptor;
438 ByteBuffer bb = ByteBuffer.allocate(4);
439 }
440 }
|