1 /*
2 * Copyright (c) 2000, 2013, 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
66 * for (int j = 0; j < glyphh; j++) {
67 * for (int i = 0; i < glyphw; i++) {
68 * int dx = glyphx + i;
69 * int dy = glyphy + j;
70 * int alpha = bits[off++];
71 * drawPixel(alpha, dx, dy);
72 * }
73 * }
74 * }
75 * } finally {
76 * gl.dispose();
77 * }
78 * }
79 */
80 public final class GlyphList {
81 private static final int MINGRAYLENGTH = 1024;
82 private static final int MAXGRAYLENGTH = 8192;
83 private static final int DEFAULT_LENGTH = 32;
84
85 int glyphindex;
86 int metrics[];
87 byte graybits[];
88
89 /* A reference to the strike is needed for the case when the GlyphList
90 * may be added to a queue for batch processing, (e.g. OpenGL) and we need
91 * to be completely certain that the strike is still valid when the glyphs
92 * images are later referenced. This does mean that if such code discards
93 * GlyphList and places only the data it contains on the queue, that the
94 * strike needs to be part of that data held by a strong reference.
95 * In the cases of drawString() and drawChars(), this is a single strike,
96 * although it may be a composite strike. In the case of
97 * drawGlyphVector() it may be a single strike, or a list of strikes.
98 */
99 Object strikelist; // hold multiple strikes during rendering of complex gv
100
101 /* In normal usage, the same GlyphList will get recycled, so
102 * it makes sense to allocate arrays that will get reused along with
103 * it, rather than generating garbage. Garbage will be generated only
104 * in MP envts where multiple threads are executing. Throughput should
105 * still be higher in those cases.
106 */
107 int len = 0;
108 int maxLen = 0;
109 int maxPosLen = 0;
110 int glyphData[];
111 char chData[];
112 long images[];
113 float positions[];
114 float x, y;
115 float gposx, gposy;
116 boolean usePositions;
117
118 /* lcdRGBOrder is used only by LCD text rendering. Its here because
119 * the Graphics may have a different hint value than the one used
120 * by a GlyphVector, so it has to be stored here - and is obtained
121 * from the right FontInfo. Another approach would have been to have
122 * install a separate pipe for that case but that's a lot of extra
123 * code when a simple boolean will suffice. The overhead to non-LCD
124 * text is a redundant boolean assign per call.
125 */
126 boolean lcdRGBOrder;
127
128 /*
129 * lcdSubPixPos is used only by LCD text rendering. Its here because
130 * the Graphics may have a different hint value than the one used
131 * by a GlyphVector, so it has to be stored here - and is obtained
132 * from the right FontInfo. Its also needed by the code which
133 * calculates glyph positions which already needs to access this
|
1 /*
2 * Copyright (c) 2000, 2018, 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
66 * for (int j = 0; j < glyphh; j++) {
67 * for (int i = 0; i < glyphw; i++) {
68 * int dx = glyphx + i;
69 * int dy = glyphy + j;
70 * int alpha = bits[off++];
71 * drawPixel(alpha, dx, dy);
72 * }
73 * }
74 * }
75 * } finally {
76 * gl.dispose();
77 * }
78 * }
79 */
80 public final class GlyphList {
81 private static final int MINGRAYLENGTH = 1024;
82 private static final int MAXGRAYLENGTH = 8192;
83 private static final int DEFAULT_LENGTH = 32;
84
85 int glyphindex;
86 int[] metrics;
87 byte[] graybits;
88
89 /* A reference to the strike is needed for the case when the GlyphList
90 * may be added to a queue for batch processing, (e.g. OpenGL) and we need
91 * to be completely certain that the strike is still valid when the glyphs
92 * images are later referenced. This does mean that if such code discards
93 * GlyphList and places only the data it contains on the queue, that the
94 * strike needs to be part of that data held by a strong reference.
95 * In the cases of drawString() and drawChars(), this is a single strike,
96 * although it may be a composite strike. In the case of
97 * drawGlyphVector() it may be a single strike, or a list of strikes.
98 */
99 Object strikelist; // hold multiple strikes during rendering of complex gv
100
101 /* In normal usage, the same GlyphList will get recycled, so
102 * it makes sense to allocate arrays that will get reused along with
103 * it, rather than generating garbage. Garbage will be generated only
104 * in MP envts where multiple threads are executing. Throughput should
105 * still be higher in those cases.
106 */
107 int len = 0;
108 int maxLen = 0;
109 int maxPosLen = 0;
110 int[] glyphData;
111 char[] chData;
112 long[] images;
113 float[] positions;
114 float x, y;
115 float gposx, gposy;
116 boolean usePositions;
117
118 /* lcdRGBOrder is used only by LCD text rendering. Its here because
119 * the Graphics may have a different hint value than the one used
120 * by a GlyphVector, so it has to be stored here - and is obtained
121 * from the right FontInfo. Another approach would have been to have
122 * install a separate pipe for that case but that's a lot of extra
123 * code when a simple boolean will suffice. The overhead to non-LCD
124 * text is a redundant boolean assign per call.
125 */
126 boolean lcdRGBOrder;
127
128 /*
129 * lcdSubPixPos is used only by LCD text rendering. Its here because
130 * the Graphics may have a different hint value than the one used
131 * by a GlyphVector, so it has to be stored here - and is obtained
132 * from the right FontInfo. Its also needed by the code which
133 * calculates glyph positions which already needs to access this
|