|
1 | 1 | /* |
2 | | - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -81,17 +81,89 @@ public void drawString(final SunGraphics2D sg2d, final String s, final double x, |
81 | 81 | } |
82 | 82 | } |
83 | 83 |
|
84 | | - public void drawGlyphVector(final SunGraphics2D sg2d, final GlyphVector gV, final float x, final float y) { |
85 | | - final Font prevFont = sg2d.getFont(); |
86 | | - sg2d.setFont(gV.getFont()); |
| 84 | + private boolean hasSlotData(GlyphVector gv) { |
| 85 | + final int length = gv.getNumGlyphs(); |
| 86 | + for (int i = 0; i < length; i++) { |
| 87 | + if ((gv.getGlyphCode(i) & CompositeGlyphMapper.SLOTMASK) != 0) { |
| 88 | + return true; |
| 89 | + } |
| 90 | + } |
| 91 | + return false; |
| 92 | + } |
| 93 | + |
| 94 | + private Font getSlotFont(Font font, int slot) { |
| 95 | + Font2D f2d = FontUtilities.getFont2D(font); |
| 96 | + if (f2d instanceof CFont) { |
| 97 | + CompositeFont cf = ((CFont)f2d).getCompositeFont2D(); |
| 98 | + PhysicalFont pf = cf.getSlotFont(slot); |
| 99 | + Font f = new Font(pf.getFontName(null), |
| 100 | + font.getStyle(), font.getSize()); |
| 101 | + return f; |
| 102 | + } |
| 103 | + return null; |
| 104 | + } |
| 105 | + |
| 106 | + private GlyphVector getGlyphVectorWithRange(final Font font, final GlyphVector gV, int start, int count) { |
| 107 | + int[] glyphs = new int[count]; |
| 108 | + for (int i = 0; i < count; i++) { |
| 109 | + glyphs[i] = gV.getGlyphCode(start+i) & CompositeGlyphMapper.GLYPHMASK; |
| 110 | + } |
| 111 | + // Positions should be null to recalculate by native methods, |
| 112 | + // if GV was segmented. |
| 113 | + StandardGlyphVector sgv = new StandardGlyphVector(font, |
| 114 | + gV.getFontRenderContext(), |
| 115 | + glyphs, |
| 116 | + null, // positions |
| 117 | + null, // indices |
| 118 | + gV.getLayoutFlags()); |
| 119 | + return sgv; |
| 120 | + } |
| 121 | + |
| 122 | + private int getLengthOfSameSlot(final GlyphVector gV, final int targetSlot, final int start, final int length) { |
| 123 | + int count = 1; |
| 124 | + for (; start + count < length; count++) { |
| 125 | + int slot = (gV.getGlyphCode(start + count) & |
| 126 | + CompositeGlyphMapper.SLOTMASK) >> 24; |
| 127 | + if (targetSlot != slot) { |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + return count; |
| 132 | + } |
87 | 133 |
|
| 134 | + private void drawGlyphVectorImpl(final SunGraphics2D sg2d, final GlyphVector gV, final float x, final float y) { |
88 | 135 | final long nativeStrikePtr = getNativeStrikePtr(sg2d); |
89 | 136 | if (OSXSurfaceData.IsSimpleColor(sg2d.paint) && nativeStrikePtr != 0) { |
90 | 137 | final OSXSurfaceData surfaceData = (OSXSurfaceData)sg2d.getSurfaceData(); |
91 | 138 | surfaceData.drawGlyphs(this, sg2d, nativeStrikePtr, gV, x, y); |
92 | 139 | } else { |
93 | 140 | drawGlyphVectorAsShape(sg2d, gV, x, y); |
94 | 141 | } |
| 142 | + } |
| 143 | + |
| 144 | + public void drawGlyphVector(final SunGraphics2D sg2d, final GlyphVector gV, final float x, final float y) { |
| 145 | + final Font prevFont = sg2d.getFont(); |
| 146 | + sg2d.setFont(gV.getFont()); |
| 147 | + |
| 148 | + if (hasSlotData(gV)) { |
| 149 | + final int length = gV.getNumGlyphs(); |
| 150 | + float[] positions = gV.getGlyphPositions(0, length, null); |
| 151 | + int start = 0; |
| 152 | + while (start < length) { |
| 153 | + int slot = (gV.getGlyphCode(start) & |
| 154 | + CompositeGlyphMapper.SLOTMASK) >> 24; |
| 155 | + sg2d.setFont(getSlotFont(gV.getFont(), slot)); |
| 156 | + int count = getLengthOfSameSlot(gV, slot, start, length); |
| 157 | + GlyphVector rangeGV = getGlyphVectorWithRange(sg2d.getFont(), |
| 158 | + gV, start, count); |
| 159 | + drawGlyphVectorImpl(sg2d, rangeGV, |
| 160 | + x + positions[start * 2], |
| 161 | + y + positions[start * 2 + 1]); |
| 162 | + start += count; |
| 163 | + } |
| 164 | + } else { |
| 165 | + drawGlyphVectorImpl(sg2d, gV, x, y); |
| 166 | + } |
95 | 167 | sg2d.setFont(prevFont); |
96 | 168 | } |
97 | 169 |
|
|
0 commit comments