Path: blob/master/src/java.desktop/macosx/classes/sun/font/CCompositeGlyphMapper.java
41153 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627public final class CCompositeGlyphMapper extends CompositeGlyphMapper {2829private CompositeFont font;30private CharToGlyphMapper[] slotMappers;3132public CCompositeGlyphMapper(CompositeFont compFont) {33super(compFont);34font = compFont;35slotMappers = new CharToGlyphMapper[font.numSlots];36missingGlyph = 0;37}3839private CharToGlyphMapper getSlotMapper(int slot) {40CharToGlyphMapper mapper = slotMappers[slot];41if (mapper == null) {42mapper = font.getSlotFont(slot).getMapper();43slotMappers[slot] = mapper;44}45return mapper;46}4748public boolean canDisplay(char ch) {49int glyph = charToGlyph(ch);50return glyph != missingGlyph;51}5253private int convertToGlyph(int unicode) {54for (int slot = 0; slot < font.numSlots; slot++) {55CharToGlyphMapper mapper = getSlotMapper(slot);56int glyphCode = mapper.charToGlyph(unicode);57// The CFont Mappers will return a negative code58// for fonts that will fill the glyph from fallbacks59// - cascading font in OSX-speak. But we need to be60// know here that only the codes > 0 are really present.61if (glyphCode > 0) {62glyphCode = compositeGlyphCode(slot, glyphCode);63return glyphCode;64}65}66return missingGlyph;67}6869public int getNumGlyphs() {70int numGlyphs = 0;71for (int slot=0; slot<1 /*font.numSlots*/; slot++) {72CharToGlyphMapper mapper = slotMappers[slot];73if (mapper == null) {74mapper = font.getSlotFont(slot).getMapper();75slotMappers[slot] = mapper;76}77numGlyphs += mapper.getNumGlyphs();78}79return numGlyphs;80}8182public int charToGlyph(int unicode) {83return convertToGlyph(unicode);84}8586public int charToGlyph(char unicode) {87return convertToGlyph(unicode);88}8990public boolean charsToGlyphsNS(int count, char[] unicodes, int[] glyphs) {9192for (int i=0; i<count; i++) {93int code = unicodes[i]; // char is unsigned.9495if (code >= HI_SURROGATE_START &&96code <= HI_SURROGATE_END && i < count - 1) {97char low = unicodes[i + 1];9899if (low >= LO_SURROGATE_START &&100low <= LO_SURROGATE_END) {101code = (code - HI_SURROGATE_START) *1020x400 + low - LO_SURROGATE_START + 0x10000;103glyphs[i + 1] = INVISIBLE_GLYPH_ID;104}105}106107glyphs[i] = convertToGlyph(code);108109if (code < FontUtilities.MIN_LAYOUT_CHARCODE) {110continue;111}112else if (FontUtilities.isComplexCharCode(code)) {113return true;114}115else if (code >= 0x10000) {116i += 1; // Empty glyph slot after surrogate117continue;118}119}120121return false;122}123124public void charsToGlyphs(int count, char[] unicodes, int[] glyphs) {125for (int i=0; i<count; i++) {126int code = unicodes[i]; // char is unsigned.127128if (code >= HI_SURROGATE_START &&129code <= HI_SURROGATE_END && i < count - 1) {130char low = unicodes[i + 1];131132if (low >= LO_SURROGATE_START &&133low <= LO_SURROGATE_END) {134code = (code - HI_SURROGATE_START) *1350x400 + low - LO_SURROGATE_START + 0x10000;136137glyphs[i] = convertToGlyph(code);138i += 1; // Empty glyph slot after surrogate139glyphs[i] = INVISIBLE_GLYPH_ID;140continue;141}142}143144glyphs[i] = convertToGlyph(code);145}146}147148public void charsToGlyphs(int count, int[] unicodes, int[] glyphs) {149for (int i=0; i<count; i++) {150glyphs[i] = convertToGlyph(unicodes[i]);151}152}153154}155156157