author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58632 | fbab568169c4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53793
9bb638b282bc
8216592: Removal of the class sun.awt.AWTSecurityManager
serb
parents:
52248
diff
changeset
|
2 |
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt; |
|
27 |
||
28 |
import java.awt.font.FontRenderContext; |
|
29 |
import java.awt.font.GlyphVector; |
|
30 |
import java.awt.font.LineMetrics; |
|
31 |
import java.awt.font.TextAttribute; |
|
32 |
import java.awt.font.TextLayout; |
|
33 |
import java.awt.geom.AffineTransform; |
|
34 |
import java.awt.geom.Point2D; |
|
35 |
import java.awt.geom.Rectangle2D; |
|
36 |
import java.awt.peer.FontPeer; |
|
37 |
import java.io.*; |
|
38 |
import java.lang.ref.SoftReference; |
|
13041
8477cb6992be
7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents:
11270
diff
changeset
|
39 |
import java.nio.file.Files; |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
40 |
import java.security.AccessController; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
41 |
import java.security.PrivilegedExceptionAction; |
2 | 42 |
import java.text.AttributedCharacterIterator.Attribute; |
43 |
import java.text.CharacterIterator; |
|
44655
06871a50a4b5
8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents:
41791
diff
changeset
|
44 |
import java.util.EventListener; |
2 | 45 |
import java.util.Hashtable; |
46 |
import java.util.Locale; |
|
47 |
import java.util.Map; |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
30469
diff
changeset
|
48 |
|
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
30469
diff
changeset
|
49 |
import sun.awt.ComponentFactory; |
2 | 50 |
import sun.font.StandardGlyphVector; |
51 |
||
52 |
import sun.font.AttributeMap; |
|
53 |
import sun.font.AttributeValues; |
|
54 |
import sun.font.CompositeFont; |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
55 |
import sun.font.CreatedFontTracker; |
2 | 56 |
import sun.font.Font2D; |
57 |
import sun.font.Font2DHandle; |
|
3928 | 58 |
import sun.font.FontAccess; |
48285
7e8a0c4ee95e
8189809: Large performance regression in Swing text layout
prr
parents:
47216
diff
changeset
|
59 |
import sun.font.FontDesignMetrics; |
2 | 60 |
import sun.font.FontManager; |
3928 | 61 |
import sun.font.FontManagerFactory; |
62 |
import sun.font.FontUtilities; |
|
2 | 63 |
import sun.font.GlyphLayout; |
64 |
import sun.font.FontLineMetrics; |
|
65 |
import sun.font.CoreMetrics; |
|
66 |
||
67 |
import static sun.font.EAttribute.*; |
|
68 |
||
69 |
/** |
|
35667 | 70 |
* The {@code Font} class represents fonts, which are used to |
2 | 71 |
* render text in a visible way. |
72 |
* A font provides the information needed to map sequences of |
|
73 |
* <em>characters</em> to sequences of <em>glyphs</em> |
|
35667 | 74 |
* and to render sequences of glyphs on {@code Graphics} and |
75 |
* {@code Component} objects. |
|
2 | 76 |
* |
54397 | 77 |
* <h2>Characters and Glyphs</h2> |
2 | 78 |
* |
79 |
* A <em>character</em> is a symbol that represents an item such as a letter, |
|
35667 | 80 |
* a digit, or punctuation in an abstract way. For example, {@code 'g'}, |
21957 | 81 |
* LATIN SMALL LETTER G, is a character. |
2 | 82 |
* <p> |
83 |
* A <em>glyph</em> is a shape used to render a character or a sequence of |
|
84 |
* characters. In simple writing systems, such as Latin, typically one glyph |
|
85 |
* represents one character. In general, however, characters and glyphs do not |
|
86 |
* have one-to-one correspondence. For example, the character 'á' |
|
21957 | 87 |
* LATIN SMALL LETTER A WITH ACUTE, can be represented by |
2 | 88 |
* two glyphs: one for 'a' and one for '´'. On the other hand, the |
89 |
* two-character string "fi" can be represented by a single glyph, an |
|
90 |
* "fi" ligature. In complex writing systems, such as Arabic or the South |
|
91 |
* and South-East Asian writing systems, the relationship between characters |
|
92 |
* and glyphs can be more complicated and involve context-dependent selection |
|
93 |
* of glyphs as well as glyph reordering. |
|
94 |
* |
|
95 |
* A font encapsulates the collection of glyphs needed to render a selected set |
|
96 |
* of characters as well as the tables needed to map sequences of characters to |
|
97 |
* corresponding sequences of glyphs. |
|
98 |
* |
|
54397 | 99 |
* <h2>Physical and Logical Fonts</h2> |
2 | 100 |
* |
101 |
* The Java Platform distinguishes between two kinds of fonts: |
|
102 |
* <em>physical</em> fonts and <em>logical</em> fonts. |
|
103 |
* <p> |
|
104 |
* <em>Physical</em> fonts are the actual font libraries containing glyph data |
|
105 |
* and tables to map from character sequences to glyph sequences, using a font |
|
106 |
* technology such as TrueType or PostScript Type 1. |
|
107 |
* All implementations of the Java Platform must support TrueType fonts; |
|
108 |
* support for other font technologies is implementation dependent. |
|
109 |
* Physical fonts may use names such as Helvetica, Palatino, HonMincho, or |
|
110 |
* any number of other font names. |
|
111 |
* Typically, each physical font supports only a limited set of writing |
|
112 |
* systems, for example, only Latin characters or only Japanese and Basic |
|
113 |
* Latin. |
|
114 |
* The set of available physical fonts varies between configurations. |
|
115 |
* Applications that require specific fonts can bundle them and instantiate |
|
116 |
* them using the {@link #createFont createFont} method. |
|
117 |
* <p> |
|
118 |
* <em>Logical</em> fonts are the five font families defined by the Java |
|
119 |
* platform which must be supported by any Java runtime environment: |
|
120 |
* Serif, SansSerif, Monospaced, Dialog, and DialogInput. |
|
121 |
* These logical fonts are not actual font libraries. Instead, the logical |
|
122 |
* font names are mapped to physical fonts by the Java runtime environment. |
|
123 |
* The mapping is implementation and usually locale dependent, so the look |
|
124 |
* and the metrics provided by them vary. |
|
125 |
* Typically, each logical font name maps to several physical fonts in order to |
|
126 |
* cover a large range of characters. |
|
127 |
* <p> |
|
128 |
* Peered AWT components, such as {@link Label Label} and |
|
129 |
* {@link TextField TextField}, can only use logical fonts. |
|
130 |
* <p> |
|
131 |
* For a discussion of the relative advantages and disadvantages of using |
|
132 |
* physical or logical fonts, see the |
|
32665
f6ce2c519881
8134476: Broken Hyperlink in JDK 8 java.awt.Font javadocs
psadhukhan
parents:
30471
diff
changeset
|
133 |
* <a href="https://docs.oracle.com/javase/tutorial/2d/text/fonts.html#advantages-and-disadvantages"> |
f6ce2c519881
8134476: Broken Hyperlink in JDK 8 java.awt.Font javadocs
psadhukhan
parents:
30471
diff
changeset
|
134 |
* Physical and Logical Fonts</a> |
f6ce2c519881
8134476: Broken Hyperlink in JDK 8 java.awt.Font javadocs
psadhukhan
parents:
30471
diff
changeset
|
135 |
* in <a href="https://docs.oracle.com/javase/tutorial/index.html">The Java Tutorials</a> |
2 | 136 |
* document. |
137 |
* |
|
54397 | 138 |
* <h2>Font Faces and Names</h2> |
2 | 139 |
* |
35667 | 140 |
* A {@code Font} |
2 | 141 |
* can have many faces, such as heavy, medium, oblique, gothic and |
142 |
* regular. All of these faces have similar typographic design. |
|
143 |
* <p> |
|
144 |
* There are three different names that you can get from a |
|
35667 | 145 |
* {@code Font} object. The <em>logical font name</em> is simply the |
2 | 146 |
* name that was used to construct the font. |
147 |
* The <em>font face name</em>, or just <em>font name</em> for |
|
148 |
* short, is the name of a particular font face, like Helvetica Bold. The |
|
149 |
* <em>family name</em> is the name of the font family that determines the |
|
150 |
* typographic design across several faces, like Helvetica. |
|
151 |
* <p> |
|
35667 | 152 |
* The {@code Font} class represents an instance of a font face from |
2 | 153 |
* a collection of font faces that are present in the system resources |
154 |
* of the host system. As examples, Arial Bold and Courier Bold Italic |
|
35667 | 155 |
* are font faces. There can be several {@code Font} objects |
2 | 156 |
* associated with a font face, each differing in size, style, transform |
157 |
* and font features. |
|
158 |
* <p> |
|
41791
a0b95c408d42
8166034: [macosx] Non-AA Serif font always displays as regular - no bold
prr
parents:
39866
diff
changeset
|
159 |
* Glyphs may not always be rendered with the requested properties (e.g, font |
a0b95c408d42
8166034: [macosx] Non-AA Serif font always displays as regular - no bold
prr
parents:
39866
diff
changeset
|
160 |
* and style) due to platform limitations such as the absence of suitable |
a0b95c408d42
8166034: [macosx] Non-AA Serif font always displays as regular - no bold
prr
parents:
39866
diff
changeset
|
161 |
* platform fonts to implement a logical font. |
a0b95c408d42
8166034: [macosx] Non-AA Serif font always displays as regular - no bold
prr
parents:
39866
diff
changeset
|
162 |
* <p> |
2 | 163 |
* The {@link GraphicsEnvironment#getAllFonts() getAllFonts} method |
35667 | 164 |
* of the {@code GraphicsEnvironment} class returns an |
2 | 165 |
* array of all font faces available in the system. These font faces are |
35667 | 166 |
* returned as {@code Font} objects with a size of 1, identity |
2 | 167 |
* transform and default font features. These |
35667 | 168 |
* base fonts can then be used to derive new {@code Font} objects |
2 | 169 |
* with varying sizes, styles, transforms and font features via the |
35667 | 170 |
* {@code deriveFont} methods in this class. |
2 | 171 |
* |
54397 | 172 |
* <h2>Font and TextAttribute</h2> |
2 | 173 |
* |
35667 | 174 |
* <p>{@code Font} supports most |
175 |
* {@code TextAttribute}s. This makes some operations, such as |
|
2 | 176 |
* rendering underlined text, convenient since it is not |
35667 | 177 |
* necessary to explicitly construct a {@code TextLayout} object. |
2 | 178 |
* Attributes can be set on a Font by constructing or deriving it |
35667 | 179 |
* using a {@code Map} of {@code TextAttribute} values. |
2 | 180 |
* |
35667 | 181 |
* <p>The values of some {@code TextAttributes} are not |
2 | 182 |
* serializable, and therefore attempting to serialize an instance of |
35667 | 183 |
* {@code Font} that has such values will not serialize them. |
2 | 184 |
* This means a Font deserialized from such a stream will not compare |
185 |
* equal to the original Font that contained the non-serializable |
|
186 |
* attributes. This should very rarely pose a problem |
|
187 |
* since these attributes are typically used only in special |
|
188 |
* circumstances and are unlikely to be serialized. |
|
189 |
* |
|
190 |
* <ul> |
|
35667 | 191 |
* <li>{@code FOREGROUND} and {@code BACKGROUND} use |
192 |
* {@code Paint} values. The subclass {@code Color} is |
|
193 |
* serializable, while {@code GradientPaint} and |
|
194 |
* {@code TexturePaint} are not.</li> |
|
195 |
* <li>{@code CHAR_REPLACEMENT} uses |
|
196 |
* {@code GraphicAttribute} values. The subclasses |
|
197 |
* {@code ShapeGraphicAttribute} and |
|
198 |
* {@code ImageGraphicAttribute} are not serializable.</li> |
|
199 |
* <li>{@code INPUT_METHOD_HIGHLIGHT} uses |
|
200 |
* {@code InputMethodHighlight} values, which are |
|
2 | 201 |
* not serializable. See {@link java.awt.im.InputMethodHighlight}.</li> |
202 |
* </ul> |
|
203 |
* |
|
35667 | 204 |
* <p>Clients who create custom subclasses of {@code Paint} and |
205 |
* {@code GraphicAttribute} can make them serializable and |
|
2 | 206 |
* avoid this problem. Clients who use input method highlights can |
207 |
* convert these to the platform-specific attributes for that |
|
208 |
* highlight on the current platform and set them on the Font as |
|
21957 | 209 |
* a workaround. |
2 | 210 |
* |
35667 | 211 |
* <p>The {@code Map}-based constructor and |
212 |
* {@code deriveFont} APIs ignore the FONT attribute, and it is |
|
2 | 213 |
* not retained by the Font; the static {@link #getFont} method should |
214 |
* be used if the FONT attribute might be present. See {@link |
|
215 |
* java.awt.font.TextAttribute#FONT} for more information.</p> |
|
216 |
* |
|
217 |
* <p>Several attributes will cause additional rendering overhead |
|
35667 | 218 |
* and potentially invoke layout. If a {@code Font} has such |
2 | 219 |
* attributes, the <code>{@link #hasLayoutAttributes()}</code> method |
220 |
* will return true.</p> |
|
221 |
* |
|
222 |
* <p>Note: Font rotations can cause text baselines to be rotated. In |
|
223 |
* order to account for this (rare) possibility, font APIs are |
|
224 |
* specified to return metrics and take parameters 'in |
|
225 |
* baseline-relative coordinates'. This maps the 'x' coordinate to |
|
226 |
* the advance along the baseline, (positive x is forward along the |
|
227 |
* baseline), and the 'y' coordinate to a distance along the |
|
228 |
* perpendicular to the baseline at 'x' (positive y is 90 degrees |
|
229 |
* clockwise from the baseline vector). APIs for which this is |
|
230 |
* especially important are called out as having 'baseline-relative |
|
231 |
* coordinates.' |
|
232 |
*/ |
|
233 |
public class Font implements java.io.Serializable |
|
234 |
{ |
|
3928 | 235 |
private static class FontAccessImpl extends FontAccess { |
236 |
public Font2D getFont2D(Font font) { |
|
237 |
return font.getFont2D(); |
|
238 |
} |
|
239 |
||
240 |
public void setFont2D(Font font, Font2DHandle handle) { |
|
241 |
font.font2DHandle = handle; |
|
242 |
} |
|
243 |
||
244 |
public void setCreatedFont(Font font) { |
|
245 |
font.createdFont = true; |
|
246 |
} |
|
247 |
||
248 |
public boolean isCreatedFont(Font font) { |
|
249 |
return font.createdFont; |
|
250 |
} |
|
30469 | 251 |
|
252 |
@Override |
|
253 |
public FontPeer getFontPeer(final Font font) { |
|
254 |
return font.getFontPeer(); |
|
255 |
} |
|
3928 | 256 |
} |
257 |
||
2 | 258 |
static { |
259 |
/* ensure that the necessary native libraries are loaded */ |
|
260 |
Toolkit.loadLibraries(); |
|
261 |
initIDs(); |
|
3928 | 262 |
FontAccess.setFontAccess(new FontAccessImpl()); |
2 | 263 |
} |
264 |
||
265 |
/** |
|
266 |
* This is now only used during serialization. Typically |
|
267 |
* it is null. |
|
268 |
* |
|
269 |
* @serial |
|
270 |
* @see #getAttributes() |
|
271 |
*/ |
|
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
272 |
private Hashtable<Object, Object> fRequestedAttributes; |
2 | 273 |
|
274 |
/* |
|
275 |
* Constants to be used for logical font family names. |
|
276 |
*/ |
|
277 |
||
278 |
/** |
|
279 |
* A String constant for the canonical family name of the |
|
280 |
* logical font "Dialog". It is useful in Font construction |
|
281 |
* to provide compile-time verification of the name. |
|
282 |
* @since 1.6 |
|
283 |
*/ |
|
284 |
public static final String DIALOG = "Dialog"; |
|
285 |
||
286 |
/** |
|
287 |
* A String constant for the canonical family name of the |
|
288 |
* logical font "DialogInput". It is useful in Font construction |
|
289 |
* to provide compile-time verification of the name. |
|
290 |
* @since 1.6 |
|
291 |
*/ |
|
292 |
public static final String DIALOG_INPUT = "DialogInput"; |
|
293 |
||
294 |
/** |
|
295 |
* A String constant for the canonical family name of the |
|
296 |
* logical font "SansSerif". It is useful in Font construction |
|
297 |
* to provide compile-time verification of the name. |
|
298 |
* @since 1.6 |
|
299 |
*/ |
|
300 |
public static final String SANS_SERIF = "SansSerif"; |
|
301 |
||
302 |
/** |
|
303 |
* A String constant for the canonical family name of the |
|
304 |
* logical font "Serif". It is useful in Font construction |
|
305 |
* to provide compile-time verification of the name. |
|
306 |
* @since 1.6 |
|
307 |
*/ |
|
308 |
public static final String SERIF = "Serif"; |
|
309 |
||
310 |
/** |
|
311 |
* A String constant for the canonical family name of the |
|
312 |
* logical font "Monospaced". It is useful in Font construction |
|
313 |
* to provide compile-time verification of the name. |
|
314 |
* @since 1.6 |
|
315 |
*/ |
|
316 |
public static final String MONOSPACED = "Monospaced"; |
|
317 |
||
318 |
/* |
|
319 |
* Constants to be used for styles. Can be combined to mix |
|
320 |
* styles. |
|
321 |
*/ |
|
322 |
||
323 |
/** |
|
324 |
* The plain style constant. |
|
325 |
*/ |
|
326 |
public static final int PLAIN = 0; |
|
327 |
||
328 |
/** |
|
329 |
* The bold style constant. This can be combined with the other style |
|
330 |
* constants (except PLAIN) for mixed styles. |
|
331 |
*/ |
|
332 |
public static final int BOLD = 1; |
|
333 |
||
334 |
/** |
|
335 |
* The italicized style constant. This can be combined with the other |
|
336 |
* style constants (except PLAIN) for mixed styles. |
|
337 |
*/ |
|
338 |
public static final int ITALIC = 2; |
|
339 |
||
340 |
/** |
|
341 |
* The baseline used in most Roman scripts when laying out text. |
|
342 |
*/ |
|
343 |
public static final int ROMAN_BASELINE = 0; |
|
344 |
||
345 |
/** |
|
346 |
* The baseline used in ideographic scripts like Chinese, Japanese, |
|
347 |
* and Korean when laying out text. |
|
348 |
*/ |
|
349 |
public static final int CENTER_BASELINE = 1; |
|
350 |
||
351 |
/** |
|
26749 | 352 |
* The baseline used in Devanagari and similar scripts when laying |
2 | 353 |
* out text. |
354 |
*/ |
|
355 |
public static final int HANGING_BASELINE = 2; |
|
356 |
||
357 |
/** |
|
358 |
* Identify a font resource of type TRUETYPE. |
|
359 |
* Used to specify a TrueType font resource to the |
|
360 |
* {@link #createFont} method. |
|
5578 | 361 |
* The TrueType format was extended to become the OpenType |
362 |
* format, which adds support for fonts with Postscript outlines, |
|
363 |
* this tag therefore references these fonts, as well as those |
|
364 |
* with TrueType outlines. |
|
2 | 365 |
* @since 1.3 |
366 |
*/ |
|
367 |
||
368 |
public static final int TRUETYPE_FONT = 0; |
|
369 |
||
370 |
/** |
|
371 |
* Identify a font resource of type TYPE1. |
|
372 |
* Used to specify a Type1 font resource to the |
|
373 |
* {@link #createFont} method. |
|
374 |
* @since 1.5 |
|
375 |
*/ |
|
376 |
public static final int TYPE1_FONT = 1; |
|
377 |
||
378 |
/** |
|
35667 | 379 |
* The logical name of this {@code Font}, as passed to the |
2 | 380 |
* constructor. |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
381 |
* @since 1.0 |
2 | 382 |
* |
383 |
* @serial |
|
384 |
* @see #getName |
|
385 |
*/ |
|
386 |
protected String name; |
|
387 |
||
388 |
/** |
|
35667 | 389 |
* The style of this {@code Font}, as passed to the constructor. |
2 | 390 |
* This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC. |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
391 |
* @since 1.0 |
2 | 392 |
* |
393 |
* @serial |
|
394 |
* @see #getStyle() |
|
395 |
*/ |
|
396 |
protected int style; |
|
397 |
||
398 |
/** |
|
35667 | 399 |
* The point size of this {@code Font}, rounded to integer. |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
400 |
* @since 1.0 |
2 | 401 |
* |
402 |
* @serial |
|
403 |
* @see #getSize() |
|
404 |
*/ |
|
405 |
protected int size; |
|
406 |
||
407 |
/** |
|
35667 | 408 |
* The point size of this {@code Font} in {@code float}. |
2 | 409 |
* |
410 |
* @serial |
|
411 |
* @see #getSize() |
|
412 |
* @see #getSize2D() |
|
413 |
*/ |
|
414 |
protected float pointSize; |
|
415 |
||
416 |
/** |
|
417 |
* The platform specific font information. |
|
418 |
*/ |
|
419 |
private transient FontPeer peer; |
|
420 |
private transient long pData; // native JDK1.1 font pointer |
|
421 |
private transient Font2DHandle font2DHandle; |
|
422 |
||
423 |
private transient AttributeValues values; |
|
424 |
private transient boolean hasLayoutAttributes; |
|
425 |
||
426 |
/* |
|
427 |
* If the origin of a Font is a created font then this attribute |
|
428 |
* must be set on all derived fonts too. |
|
429 |
*/ |
|
430 |
private transient boolean createdFont = false; |
|
431 |
||
432 |
/* |
|
433 |
* This is true if the font transform is not identity. It |
|
434 |
* is used to avoid unnecessary instantiation of an AffineTransform. |
|
435 |
*/ |
|
436 |
private transient boolean nonIdentityTx; |
|
437 |
||
438 |
/* |
|
439 |
* A cached value used when a transform is required for internal |
|
440 |
* use. This must not be exposed to callers since AffineTransform |
|
441 |
* is mutable. |
|
442 |
*/ |
|
443 |
private static final AffineTransform identityTx = new AffineTransform(); |
|
444 |
||
445 |
/* |
|
446 |
* JDK 1.1 serialVersionUID |
|
447 |
*/ |
|
448 |
private static final long serialVersionUID = -4206021311591459213L; |
|
449 |
||
450 |
/** |
|
30469 | 451 |
* Gets the peer of this {@code Font}. |
452 |
* |
|
453 |
* @return the peer of the {@code Font}. |
|
2 | 454 |
*/ |
30469 | 455 |
private FontPeer getFontPeer() { |
2 | 456 |
if(peer == null) { |
457 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
30471
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
30469
diff
changeset
|
458 |
if (tk instanceof ComponentFactory) { |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
30469
diff
changeset
|
459 |
peer = ((ComponentFactory) tk).getFontPeer(name, style); |
c1568a2416a8
8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents:
30469
diff
changeset
|
460 |
} |
2 | 461 |
} |
462 |
return peer; |
|
463 |
} |
|
464 |
||
465 |
/** |
|
466 |
* Return the AttributeValues object associated with this |
|
467 |
* font. Most of the time, the internal object is null. |
|
468 |
* If required, it will be created from the 'standard' |
|
469 |
* state on the font. Only non-default values will be |
|
470 |
* set in the AttributeValues object. |
|
471 |
* |
|
472 |
* <p>Since the AttributeValues object is mutable, and it |
|
473 |
* is cached in the font, care must be taken to ensure that |
|
474 |
* it is not mutated. |
|
475 |
*/ |
|
476 |
private AttributeValues getAttributeValues() { |
|
477 |
if (values == null) { |
|
3017
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
478 |
AttributeValues valuesTmp = new AttributeValues(); |
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
479 |
valuesTmp.setFamily(name); |
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
480 |
valuesTmp.setSize(pointSize); // expects the float value. |
2 | 481 |
|
482 |
if ((style & BOLD) != 0) { |
|
3017
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
483 |
valuesTmp.setWeight(2); // WEIGHT_BOLD |
2 | 484 |
} |
485 |
||
486 |
if ((style & ITALIC) != 0) { |
|
3017
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
487 |
valuesTmp.setPosture(.2f); // POSTURE_OBLIQUE |
2 | 488 |
} |
3017
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
489 |
valuesTmp.defineAll(PRIMARY_MASK); // for streaming compatibility |
217bf37bb0ea
6853617: race condition in java.awt.Font.getAttributes() (private method)
prr
parents:
2624
diff
changeset
|
490 |
values = valuesTmp; |
2 | 491 |
} |
492 |
||
493 |
return values; |
|
494 |
} |
|
495 |
||
496 |
private Font2D getFont2D() { |
|
3928 | 497 |
FontManager fm = FontManagerFactory.getInstance(); |
53793
9bb638b282bc
8216592: Removal of the class sun.awt.AWTSecurityManager
serb
parents:
52248
diff
changeset
|
498 |
if (font2DHandle == null) { |
2 | 499 |
font2DHandle = |
3928 | 500 |
fm.findFont2D(name, style, |
501 |
FontManager.LOGICAL_FALLBACK).handle; |
|
2 | 502 |
} |
503 |
/* Do not cache the de-referenced font2D. It must be explicitly |
|
504 |
* de-referenced to pick up a valid font in the event that the |
|
505 |
* original one is marked invalid |
|
506 |
*/ |
|
507 |
return font2DHandle.font2D; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
35667 | 511 |
* Creates a new {@code Font} from the specified name, style and |
2 | 512 |
* point size. |
513 |
* <p> |
|
514 |
* The font name can be a font face name or a font family name. |
|
515 |
* It is used together with the style to find an appropriate font face. |
|
516 |
* When a font family name is specified, the style argument is used to |
|
517 |
* select the most appropriate face from the family. When a font face |
|
518 |
* name is specified, the face's style and the style argument are |
|
519 |
* merged to locate the best matching font from the same family. |
|
520 |
* For example if face name "Arial Bold" is specified with style |
|
35667 | 521 |
* {@code Font.ITALIC}, the font system looks for a face in the |
2 | 522 |
* "Arial" family that is bold and italic, and may associate the font |
523 |
* instance with the physical font face "Arial Bold Italic". |
|
524 |
* The style argument is merged with the specified face's style, not |
|
525 |
* added or subtracted. |
|
526 |
* This means, specifying a bold face and a bold style does not |
|
527 |
* double-embolden the font, and specifying a bold face and a plain |
|
528 |
* style does not lighten the font. |
|
529 |
* <p> |
|
530 |
* If no face for the requested style can be found, the font system |
|
531 |
* may apply algorithmic styling to achieve the desired style. |
|
35667 | 532 |
* For example, if {@code ITALIC} is requested, but no italic |
2 | 533 |
* face is available, glyphs from the plain face may be algorithmically |
534 |
* obliqued (slanted). |
|
535 |
* <p> |
|
536 |
* Font name lookup is case insensitive, using the case folding |
|
537 |
* rules of the US locale. |
|
538 |
* <p> |
|
35667 | 539 |
* If the {@code name} parameter represents something other than a |
2 | 540 |
* logical font, i.e. is interpreted as a physical font face or family, and |
541 |
* this cannot be mapped by the implementation to a physical font or a |
|
542 |
* compatible alternative, then the font system will map the Font |
|
543 |
* instance to "Dialog", such that for example, the family as reported |
|
544 |
* by {@link #getFamily() getFamily} will be "Dialog". |
|
545 |
* |
|
546 |
* @param name the font name. This can be a font face name or a font |
|
547 |
* family name, and may represent either a logical font or a physical |
|
548 |
* font found in this {@code GraphicsEnvironment}. |
|
549 |
* The family names for logical fonts are: Dialog, DialogInput, |
|
550 |
* Monospaced, Serif, or SansSerif. Pre-defined String constants exist |
|
551 |
* for all of these names, for example, {@code DIALOG}. If {@code name} is |
|
552 |
* {@code null}, the <em>logical font name</em> of the new |
|
553 |
* {@code Font} as returned by {@code getName()} is set to |
|
554 |
* the name "Default". |
|
555 |
* @param style the style constant for the {@code Font} |
|
556 |
* The style argument is an integer bitmask that may |
|
557 |
* be {@code PLAIN}, or a bitwise union of {@code BOLD} and/or |
|
558 |
* {@code ITALIC} (for example, {@code ITALIC} or {@code BOLD|ITALIC}). |
|
559 |
* If the style argument does not conform to one of the expected |
|
560 |
* integer bitmasks then the style is set to {@code PLAIN}. |
|
561 |
* @param size the point size of the {@code Font} |
|
562 |
* @see GraphicsEnvironment#getAllFonts |
|
563 |
* @see GraphicsEnvironment#getAvailableFontFamilyNames |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
564 |
* @since 1.0 |
2 | 565 |
*/ |
566 |
public Font(String name, int style, int size) { |
|
567 |
this.name = (name != null) ? name : "Default"; |
|
568 |
this.style = (style & ~0x03) == 0 ? style : 0; |
|
569 |
this.size = size; |
|
570 |
this.pointSize = size; |
|
571 |
} |
|
572 |
||
573 |
private Font(String name, int style, float sizePts) { |
|
574 |
this.name = (name != null) ? name : "Default"; |
|
575 |
this.style = (style & ~0x03) == 0 ? style : 0; |
|
576 |
this.size = (int)(sizePts + 0.5); |
|
577 |
this.pointSize = sizePts; |
|
578 |
} |
|
579 |
||
580 |
/* This constructor is used by deriveFont when attributes is null */ |
|
581 |
private Font(String name, int style, float sizePts, |
|
582 |
boolean created, Font2DHandle handle) { |
|
583 |
this(name, style, sizePts); |
|
584 |
this.createdFont = created; |
|
585 |
/* Fonts created from a stream will use the same font2D instance |
|
586 |
* as the parent. |
|
587 |
* One exception is that if the derived font is requested to be |
|
588 |
* in a different style, then also check if its a CompositeFont |
|
589 |
* and if so build a new CompositeFont from components of that style. |
|
590 |
* CompositeFonts can only be marked as "created" if they are used |
|
591 |
* to add fall backs to a physical font. And non-composites are |
|
592 |
* always from "Font.createFont()" and shouldn't get this treatment. |
|
593 |
*/ |
|
594 |
if (created) { |
|
595 |
if (handle.font2D instanceof CompositeFont && |
|
596 |
handle.font2D.getStyle() != style) { |
|
3928 | 597 |
FontManager fm = FontManagerFactory.getInstance(); |
598 |
this.font2DHandle = fm.getNewComposite(null, style, handle); |
|
2 | 599 |
} else { |
600 |
this.font2DHandle = handle; |
|
601 |
} |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
/* used to implement Font.createFont */ |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
606 |
private Font(File fontFile, int fontFormat, |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
607 |
boolean isCopy, CreatedFontTracker tracker) |
2 | 608 |
throws FontFormatException { |
609 |
this.createdFont = true; |
|
610 |
/* Font2D instances created by this method track their font file |
|
611 |
* so that when the Font2D is GC'd it can also remove the file. |
|
612 |
*/ |
|
3928 | 613 |
FontManager fm = FontManagerFactory.getInstance(); |
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
614 |
Font2D[] fonts = |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
615 |
fm.createFont2D(fontFile, fontFormat, false, isCopy, tracker); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
616 |
this.font2DHandle = fonts[0].handle; |
2 | 617 |
this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault()); |
618 |
this.style = Font.PLAIN; |
|
619 |
this.size = 1; |
|
620 |
this.pointSize = 1f; |
|
621 |
} |
|
622 |
||
623 |
/* This constructor is used when one font is derived from another. |
|
624 |
* Fonts created from a stream will use the same font2D instance as the |
|
625 |
* parent. They can be distinguished because the "created" argument |
|
626 |
* will be "true". Since there is no way to recreate these fonts they |
|
627 |
* need to have the handle to the underlying font2D passed in. |
|
628 |
* "created" is also true when a special composite is referenced by the |
|
629 |
* handle for essentially the same reasons. |
|
630 |
* But when deriving a font in these cases two particular attributes |
|
631 |
* need special attention: family/face and style. |
|
632 |
* The "composites" in these cases need to be recreated with optimal |
|
633 |
* fonts for the new values of family and style. |
|
634 |
* For fonts created with createFont() these are treated differently. |
|
635 |
* JDK can often synthesise a different style (bold from plain |
|
636 |
* for example). For fonts created with "createFont" this is a reasonable |
|
637 |
* solution but its also possible (although rare) to derive a font with a |
|
638 |
* different family attribute. In this case JDK needs |
|
639 |
* to break the tie with the original Font2D and find a new Font. |
|
640 |
* The oldName and oldStyle are supplied so they can be compared with |
|
641 |
* what the Font2D and the values. To speed things along : |
|
642 |
* oldName == null will be interpreted as the name is unchanged. |
|
643 |
* oldStyle = -1 will be interpreted as the style is unchanged. |
|
644 |
* In these cases there is no need to interrogate "values". |
|
645 |
*/ |
|
646 |
private Font(AttributeValues values, String oldName, int oldStyle, |
|
647 |
boolean created, Font2DHandle handle) { |
|
648 |
||
649 |
this.createdFont = created; |
|
650 |
if (created) { |
|
651 |
this.font2DHandle = handle; |
|
652 |
||
653 |
String newName = null; |
|
654 |
if (oldName != null) { |
|
655 |
newName = values.getFamily(); |
|
656 |
if (oldName.equals(newName)) newName = null; |
|
657 |
} |
|
658 |
int newStyle = 0; |
|
659 |
if (oldStyle == -1) { |
|
660 |
newStyle = -1; |
|
661 |
} else { |
|
662 |
if (values.getWeight() >= 2f) newStyle = BOLD; |
|
663 |
if (values.getPosture() >= .2f) newStyle |= ITALIC; |
|
664 |
if (oldStyle == newStyle) newStyle = -1; |
|
665 |
} |
|
666 |
if (handle.font2D instanceof CompositeFont) { |
|
667 |
if (newStyle != -1 || newName != null) { |
|
3928 | 668 |
FontManager fm = FontManagerFactory.getInstance(); |
2 | 669 |
this.font2DHandle = |
3928 | 670 |
fm.getNewComposite(newName, newStyle, handle); |
2 | 671 |
} |
672 |
} else if (newName != null) { |
|
673 |
this.createdFont = false; |
|
674 |
this.font2DHandle = null; |
|
675 |
} |
|
676 |
} |
|
677 |
initFromValues(values); |
|
678 |
} |
|
679 |
||
680 |
/** |
|
35667 | 681 |
* Creates a new {@code Font} with the specified attributes. |
2 | 682 |
* Only keys defined in {@link java.awt.font.TextAttribute TextAttribute} |
683 |
* are recognized. In addition the FONT attribute is |
|
684 |
* not recognized by this constructor |
|
685 |
* (see {@link #getAvailableAttributes}). Only attributes that have |
|
35667 | 686 |
* values of valid types will affect the new {@code Font}. |
2 | 687 |
* <p> |
35667 | 688 |
* If {@code attributes} is {@code null}, a new |
689 |
* {@code Font} is initialized with default values. |
|
2 | 690 |
* @see java.awt.font.TextAttribute |
691 |
* @param attributes the attributes to assign to the new |
|
35667 | 692 |
* {@code Font}, or {@code null} |
2 | 693 |
*/ |
694 |
public Font(Map<? extends Attribute, ?> attributes) { |
|
695 |
initFromValues(AttributeValues.fromMap(attributes, RECOGNIZED_MASK)); |
|
696 |
} |
|
697 |
||
698 |
/** |
|
35667 | 699 |
* Creates a new {@code Font} from the specified {@code font}. |
2 | 700 |
* This constructor is intended for use by subclasses. |
35667 | 701 |
* @param font from which to create this {@code Font}. |
702 |
* @throws NullPointerException if {@code font} is null |
|
2 | 703 |
* @since 1.6 |
704 |
*/ |
|
705 |
protected Font(Font font) { |
|
706 |
if (font.values != null) { |
|
707 |
initFromValues(font.getAttributeValues().clone()); |
|
708 |
} else { |
|
709 |
this.name = font.name; |
|
710 |
this.style = font.style; |
|
711 |
this.size = font.size; |
|
712 |
this.pointSize = font.pointSize; |
|
713 |
} |
|
714 |
this.font2DHandle = font.font2DHandle; |
|
715 |
this.createdFont = font.createdFont; |
|
716 |
} |
|
717 |
||
718 |
/** |
|
719 |
* Font recognizes all attributes except FONT. |
|
720 |
*/ |
|
721 |
private static final int RECOGNIZED_MASK = AttributeValues.MASK_ALL |
|
722 |
& ~AttributeValues.getMask(EFONT); |
|
723 |
||
724 |
/** |
|
725 |
* These attributes are considered primary by the FONT attribute. |
|
726 |
*/ |
|
727 |
private static final int PRIMARY_MASK = |
|
728 |
AttributeValues.getMask(EFAMILY, EWEIGHT, EWIDTH, EPOSTURE, ESIZE, |
|
729 |
ETRANSFORM, ESUPERSCRIPT, ETRACKING); |
|
730 |
||
731 |
/** |
|
732 |
* These attributes are considered secondary by the FONT attribute. |
|
733 |
*/ |
|
734 |
private static final int SECONDARY_MASK = |
|
735 |
RECOGNIZED_MASK & ~PRIMARY_MASK; |
|
736 |
||
737 |
/** |
|
738 |
* These attributes are handled by layout. |
|
739 |
*/ |
|
740 |
private static final int LAYOUT_MASK = |
|
741 |
AttributeValues.getMask(ECHAR_REPLACEMENT, EFOREGROUND, EBACKGROUND, |
|
742 |
EUNDERLINE, ESTRIKETHROUGH, ERUN_DIRECTION, |
|
743 |
EBIDI_EMBEDDING, EJUSTIFICATION, |
|
744 |
EINPUT_METHOD_HIGHLIGHT, EINPUT_METHOD_UNDERLINE, |
|
745 |
ESWAP_COLORS, ENUMERIC_SHAPING, EKERNING, |
|
534
be8500bc69b2
6684056: SUPERSCRIPT TextAttribute on font needs to trigger layout.
prr
parents:
2
diff
changeset
|
746 |
ELIGATURES, ETRACKING, ESUPERSCRIPT); |
2 | 747 |
|
748 |
private static final int EXTRA_MASK = |
|
749 |
AttributeValues.getMask(ETRANSFORM, ESUPERSCRIPT, EWIDTH); |
|
750 |
||
751 |
/** |
|
752 |
* Initialize the standard Font fields from the values object. |
|
753 |
*/ |
|
754 |
private void initFromValues(AttributeValues values) { |
|
755 |
this.values = values; |
|
756 |
values.defineAll(PRIMARY_MASK); // for 1.5 streaming compatibility |
|
757 |
||
758 |
this.name = values.getFamily(); |
|
759 |
this.pointSize = values.getSize(); |
|
760 |
this.size = (int)(values.getSize() + 0.5); |
|
761 |
if (values.getWeight() >= 2f) this.style |= BOLD; // not == 2f |
|
762 |
if (values.getPosture() >= .2f) this.style |= ITALIC; // not == .2f |
|
763 |
||
764 |
this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK); |
|
765 |
this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK); |
|
766 |
} |
|
767 |
||
768 |
/** |
|
37562
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
769 |
* Returns true if any part of the specified text is from a |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
770 |
* complex script for which the implementation will need to invoke |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
771 |
* layout processing in order to render correctly when using |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
772 |
* {@link Graphics#drawString(String,int,int) drawString(String,int,int)} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
773 |
* and other text rendering methods. Measurement of the text |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
774 |
* may similarly need the same extra processing. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
775 |
* The {@code start} and {@code end} indices are provided so that |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
776 |
* the application can request only a subset of the text be considered. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
777 |
* The last char index examined is at {@code "end-1"}, |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
778 |
* i.e a request to examine the entire array would be |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
779 |
* <pre> |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
780 |
* {@code Font.textRequiresLayout(chars, 0, chars.length);} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
781 |
* </pre> |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
782 |
* An application may find this information helpful in |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
783 |
* performance sensitive code. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
784 |
* <p> |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
785 |
* Note that even if this method returns {@code false}, layout processing |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
786 |
* may still be invoked when used with any {@code Font} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
787 |
* for which {@link #hasLayoutAttributes()} returns {@code true}, |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
788 |
* so that method will need to be consulted for the specific font, |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
789 |
* in order to obtain an answer which accounts for such font attributes. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
790 |
* |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
791 |
* @param chars the text. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
792 |
* @param start the index of the first char to examine. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
793 |
* @param end the ending index, exclusive. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
794 |
* @return {@code true} if the specified text will need special layout. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
795 |
* @throws NullPointerException if {@code chars} is null. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
796 |
* @throws ArrayIndexOutOfBoundsException if {@code start} is negative or |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
797 |
* {@code end} is greater than the length of the {@code chars} array. |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
798 |
* @since 9 |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
799 |
*/ |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
800 |
public static boolean textRequiresLayout(char[] chars, |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
801 |
int start, int end) { |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
802 |
if (chars == null) { |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
803 |
throw new NullPointerException("null char array"); |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
804 |
} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
805 |
if (start < 0 || end > chars.length) { |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
806 |
throw new ArrayIndexOutOfBoundsException("start < 0 or end > len"); |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
807 |
} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
808 |
return FontUtilities.isComplexScript(chars, start, end); |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
809 |
} |
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
810 |
|
5b36d70170d6
8146324: Add sun.font.FontUtilities.isComplexCharCode or related method
prr
parents:
36899
diff
changeset
|
811 |
/** |
35667 | 812 |
* Returns a {@code Font} appropriate to the attributes. |
813 |
* If {@code attributes} contains a {@code FONT} attribute |
|
814 |
* with a valid {@code Font} as its value, it will be |
|
2 | 815 |
* merged with any remaining attributes. See |
816 |
* {@link java.awt.font.TextAttribute#FONT} for more |
|
817 |
* information. |
|
818 |
* |
|
819 |
* @param attributes the attributes to assign to the new |
|
35667 | 820 |
* {@code Font} |
821 |
* @return a new {@code Font} created with the specified |
|
2 | 822 |
* attributes |
35667 | 823 |
* @throws NullPointerException if {@code attributes} is null. |
2 | 824 |
* @since 1.2 |
825 |
* @see java.awt.font.TextAttribute |
|
826 |
*/ |
|
827 |
public static Font getFont(Map<? extends Attribute, ?> attributes) { |
|
828 |
// optimize for two cases: |
|
829 |
// 1) FONT attribute, and nothing else |
|
830 |
// 2) attributes, but no FONT |
|
831 |
||
832 |
// avoid turning the attributemap into a regular map for no reason |
|
833 |
if (attributes instanceof AttributeMap && |
|
834 |
((AttributeMap)attributes).getValues() != null) { |
|
835 |
AttributeValues values = ((AttributeMap)attributes).getValues(); |
|
836 |
if (values.isNonDefault(EFONT)) { |
|
837 |
Font font = values.getFont(); |
|
838 |
if (!values.anyDefined(SECONDARY_MASK)) { |
|
839 |
return font; |
|
840 |
} |
|
841 |
// merge |
|
842 |
values = font.getAttributeValues().clone(); |
|
843 |
values.merge(attributes, SECONDARY_MASK); |
|
844 |
return new Font(values, font.name, font.style, |
|
845 |
font.createdFont, font.font2DHandle); |
|
846 |
} |
|
847 |
return new Font(attributes); |
|
848 |
} |
|
849 |
||
850 |
Font font = (Font)attributes.get(TextAttribute.FONT); |
|
851 |
if (font != null) { |
|
852 |
if (attributes.size() > 1) { // oh well, check for anything else |
|
853 |
AttributeValues values = font.getAttributeValues().clone(); |
|
854 |
values.merge(attributes, SECONDARY_MASK); |
|
855 |
return new Font(values, font.name, font.style, |
|
856 |
font.createdFont, font.font2DHandle); |
|
857 |
} |
|
858 |
||
859 |
return font; |
|
860 |
} |
|
861 |
||
862 |
return new Font(attributes); |
|
863 |
} |
|
864 |
||
865 |
/** |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
866 |
* Used with the byte count tracker for fonts created from streams. |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
867 |
* If a thread can create temp files anyway, no point in counting |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
868 |
* font bytes. |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
869 |
*/ |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
870 |
private static boolean hasTempPermission() { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
871 |
|
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
872 |
if (System.getSecurityManager() == null) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
873 |
return true; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
874 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
875 |
File f = null; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
876 |
boolean hasPerm = false; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
877 |
try { |
13041
8477cb6992be
7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents:
11270
diff
changeset
|
878 |
f = Files.createTempFile("+~JT", ".tmp").toFile(); |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
879 |
f.delete(); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
880 |
f = null; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
881 |
hasPerm = true; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
882 |
} catch (Throwable t) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
883 |
/* inc. any kind of SecurityException */ |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
884 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
885 |
return hasPerm; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
886 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
887 |
|
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
888 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
889 |
/** |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
890 |
* Returns a new array of {@code Font} decoded from the specified stream. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
891 |
* The returned {@code Font[]} will have at least one element. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
892 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
893 |
* The explicit purpose of this variation on the |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
894 |
* {@code createFont(int, InputStream)} method is to support font |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
895 |
* sources which represent a TrueType/OpenType font collection and |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
896 |
* be able to return all individual fonts in that collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
897 |
* Consequently this method will throw {@code FontFormatException} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
898 |
* if the data source does not contain at least one TrueType/OpenType |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
899 |
* font. The same exception will also be thrown if any of the fonts in |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
900 |
* the collection does not contain the required font tables. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
901 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
902 |
* The condition "at least one", allows for the stream to represent |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
903 |
* a single OpenType/TrueType font. That is, it does not have to be |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
904 |
* a collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
905 |
* Each {@code Font} element of the returned array is |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
906 |
* created with a point size of 1 and style {@link #PLAIN PLAIN}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
907 |
* This base font can then be used with the {@code deriveFont} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
908 |
* methods in this class to derive new {@code Font} objects with |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
909 |
* varying sizes, styles, transforms and font features. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
910 |
* <p>This method does not close the {@link InputStream}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
911 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
912 |
* To make each {@code Font} available to Font constructors it |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
913 |
* must be registered in the {@code GraphicsEnvironment} by calling |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
914 |
* {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
915 |
* @param fontStream an {@code InputStream} object representing the |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
916 |
* input data for the font or font collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
917 |
* @return a new {@code Font[]}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
918 |
* @throws FontFormatException if the {@code fontStream} data does |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
919 |
* not contain the required font tables for any of the elements of |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
920 |
* the collection, or if it contains no fonts at all. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
921 |
* @throws IOException if the {@code fontStream} cannot be completely read. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
922 |
* @see GraphicsEnvironment#registerFont(Font) |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
923 |
* @since 9 |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
924 |
*/ |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
925 |
public static Font[] createFonts(InputStream fontStream) |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
926 |
throws FontFormatException, IOException { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
927 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
928 |
final int fontFormat = Font.TRUETYPE_FONT; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
929 |
if (hasTempPermission()) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
930 |
return createFont0(fontFormat, fontStream, true, null); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
931 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
932 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
933 |
// Otherwise, be extra conscious of pending temp file creation and |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
934 |
// resourcefully handle the temp file resources, among other things. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
935 |
CreatedFontTracker tracker = CreatedFontTracker.getTracker(); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
936 |
boolean acquired = false; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
937 |
try { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
938 |
acquired = tracker.acquirePermit(); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
939 |
if (!acquired) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
940 |
throw new IOException("Timed out waiting for resources."); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
941 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
942 |
return createFont0(fontFormat, fontStream, true, tracker); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
943 |
} catch (InterruptedException e) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
944 |
throw new IOException("Problem reading font data."); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
945 |
} finally { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
946 |
if (acquired) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
947 |
tracker.releasePermit(); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
948 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
949 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
950 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
951 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
952 |
/* used to implement Font.createFont */ |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
953 |
private Font(Font2D font2D) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
954 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
955 |
this.createdFont = true; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
956 |
this.font2DHandle = font2D.handle; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
957 |
this.name = font2D.getFontName(Locale.getDefault()); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
958 |
this.style = Font.PLAIN; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
959 |
this.size = 1; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
960 |
this.pointSize = 1f; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
961 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
962 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
963 |
/** |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
964 |
* Returns a new array of {@code Font} decoded from the specified file. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
965 |
* The returned {@code Font[]} will have at least one element. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
966 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
967 |
* The explicit purpose of this variation on the |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
968 |
* {@code createFont(int, File)} method is to support font |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
969 |
* sources which represent a TrueType/OpenType font collection and |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
970 |
* be able to return all individual fonts in that collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
971 |
* Consequently this method will throw {@code FontFormatException} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
972 |
* if the data source does not contain at least one TrueType/OpenType |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
973 |
* font. The same exception will also be thrown if any of the fonts in |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
974 |
* the collection does not contain the required font tables. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
975 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
976 |
* The condition "at least one", allows for the stream to represent |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
977 |
* a single OpenType/TrueType font. That is, it does not have to be |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
978 |
* a collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
979 |
* Each {@code Font} element of the returned array is |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
980 |
* created with a point size of 1 and style {@link #PLAIN PLAIN}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
981 |
* This base font can then be used with the {@code deriveFont} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
982 |
* methods in this class to derive new {@code Font} objects with |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
983 |
* varying sizes, styles, transforms and font features. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
984 |
* <p> |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
985 |
* To make each {@code Font} available to Font constructors it |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
986 |
* must be registered in the {@code GraphicsEnvironment} by calling |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
987 |
* {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
988 |
* @param fontFile a {@code File} object containing the |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
989 |
* input data for the font or font collection. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
990 |
* @return a new {@code Font[]}. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
991 |
* @throws FontFormatException if the {@code File} does |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
992 |
* not contain the required font tables for any of the elements of |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
993 |
* the collection, or if it contains no fonts at all. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
994 |
* @throws IOException if the {@code fontFile} cannot be read. |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
995 |
* @see GraphicsEnvironment#registerFont(Font) |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
996 |
* @since 9 |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
997 |
*/ |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
998 |
public static Font[] createFonts(File fontFile) |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
999 |
throws FontFormatException, IOException |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1000 |
{ |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1001 |
int fontFormat = Font.TRUETYPE_FONT; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1002 |
fontFile = checkFontFile(fontFormat, fontFile); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1003 |
FontManager fm = FontManagerFactory.getInstance(); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1004 |
Font2D[] font2DArr = |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1005 |
fm.createFont2D(fontFile, fontFormat, true, false, null); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1006 |
int num = font2DArr.length; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1007 |
Font[] fonts = new Font[num]; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1008 |
for (int i = 0; i < num; i++) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1009 |
fonts[i] = new Font(font2DArr[i]); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1010 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1011 |
return fonts; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1012 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1013 |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1014 |
/** |
35667 | 1015 |
* Returns a new {@code Font} using the specified font type |
1016 |
* and input data. The new {@code Font} is |
|
2 | 1017 |
* created with a point size of 1 and style {@link #PLAIN PLAIN}. |
35667 | 1018 |
* This base font can then be used with the {@code deriveFont} |
1019 |
* methods in this class to derive new {@code Font} objects with |
|
2 | 1020 |
* varying sizes, styles, transforms and font features. This |
1021 |
* method does not close the {@link InputStream}. |
|
1022 |
* <p> |
|
35667 | 1023 |
* To make the {@code Font} available to Font constructors the |
1024 |
* returned {@code Font} must be registered in the |
|
1025 |
* {@code GraphicsEnvironment} by calling |
|
2 | 1026 |
* {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}. |
35667 | 1027 |
* @param fontFormat the type of the {@code Font}, which is |
2 | 1028 |
* {@link #TRUETYPE_FONT TRUETYPE_FONT} if a TrueType resource is specified. |
1029 |
* or {@link #TYPE1_FONT TYPE1_FONT} if a Type 1 resource is specified. |
|
35667 | 1030 |
* @param fontStream an {@code InputStream} object representing the |
2 | 1031 |
* input data for the font. |
35667 | 1032 |
* @return a new {@code Font} created with the specified font type. |
1033 |
* @throws IllegalArgumentException if {@code fontFormat} is not |
|
1034 |
* {@code TRUETYPE_FONT} or {@code TYPE1_FONT}. |
|
1035 |
* @throws FontFormatException if the {@code fontStream} data does |
|
2 | 1036 |
* not contain the required font tables for the specified format. |
35667 | 1037 |
* @throws IOException if the {@code fontStream} |
2 | 1038 |
* cannot be completely read. |
1039 |
* @see GraphicsEnvironment#registerFont(Font) |
|
1040 |
* @since 1.3 |
|
1041 |
*/ |
|
1042 |
public static Font createFont(int fontFormat, InputStream fontStream) |
|
1043 |
throws java.awt.FontFormatException, java.io.IOException { |
|
1044 |
||
18214 | 1045 |
if (hasTempPermission()) { |
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1046 |
return createFont0(fontFormat, fontStream, false, null)[0]; |
18214 | 1047 |
} |
1048 |
||
1049 |
// Otherwise, be extra conscious of pending temp file creation and |
|
1050 |
// resourcefully handle the temp file resources, among other things. |
|
1051 |
CreatedFontTracker tracker = CreatedFontTracker.getTracker(); |
|
1052 |
boolean acquired = false; |
|
1053 |
try { |
|
1054 |
acquired = tracker.acquirePermit(); |
|
1055 |
if (!acquired) { |
|
1056 |
throw new IOException("Timed out waiting for resources."); |
|
1057 |
} |
|
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1058 |
return createFont0(fontFormat, fontStream, false, tracker)[0]; |
18214 | 1059 |
} catch (InterruptedException e) { |
1060 |
throw new IOException("Problem reading font data."); |
|
1061 |
} finally { |
|
1062 |
if (acquired) { |
|
1063 |
tracker.releasePermit(); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1068 |
private static Font[] createFont0(int fontFormat, InputStream fontStream, |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1069 |
boolean allFonts, |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1070 |
CreatedFontTracker tracker) |
18214 | 1071 |
throws java.awt.FontFormatException, java.io.IOException { |
1072 |
||
2 | 1073 |
if (fontFormat != Font.TRUETYPE_FONT && |
1074 |
fontFormat != Font.TYPE1_FONT) { |
|
1075 |
throw new IllegalArgumentException ("font format not recognized"); |
|
1076 |
} |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1077 |
boolean copiedFontData = false; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1078 |
try { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1079 |
final File tFile = AccessController.doPrivileged( |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1080 |
new PrivilegedExceptionAction<File>() { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1081 |
public File run() throws IOException { |
13041
8477cb6992be
7143606: File.createTempFile should be improved for temporary files created by the platform.
robm
parents:
11270
diff
changeset
|
1082 |
return Files.createTempFile("+~JF", ".tmp").toFile(); |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1083 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1084 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1085 |
); |
18214 | 1086 |
if (tracker != null) { |
1087 |
tracker.add(tFile); |
|
1088 |
} |
|
2 | 1089 |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1090 |
int totalSize = 0; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1091 |
try { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1092 |
final OutputStream outStream = |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1093 |
AccessController.doPrivileged( |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1094 |
new PrivilegedExceptionAction<OutputStream>() { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1095 |
public OutputStream run() throws IOException { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1096 |
return new FileOutputStream(tFile); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1097 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1098 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1099 |
); |
18214 | 1100 |
if (tracker != null) { |
1101 |
tracker.set(tFile, outStream); |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1102 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1103 |
try { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1104 |
byte[] buf = new byte[8192]; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1105 |
for (;;) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1106 |
int bytesRead = fontStream.read(buf); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1107 |
if (bytesRead < 0) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1108 |
break; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1109 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1110 |
if (tracker != null) { |
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
1111 |
if (totalSize+bytesRead > CreatedFontTracker.MAX_FILE_SIZE) { |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1112 |
throw new IOException("File too big."); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1113 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1114 |
if (totalSize+tracker.getNumBytes() > |
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
1115 |
CreatedFontTracker.MAX_TOTAL_BYTES) |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1116 |
{ |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1117 |
throw new IOException("Total files too big."); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1118 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1119 |
totalSize += bytesRead; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1120 |
tracker.addBytes(bytesRead); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1121 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1122 |
outStream.write(buf, 0, bytesRead); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1123 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1124 |
/* don't close the input stream */ |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1125 |
} finally { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1126 |
outStream.close(); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1127 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1128 |
/* After all references to a Font2D are dropped, the file |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1129 |
* will be removed. To support long-lived AppContexts, |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1130 |
* we need to then decrement the byte count by the size |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1131 |
* of the file. |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1132 |
* If the data isn't a valid font, the implementation will |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1133 |
* delete the tmp file and decrement the byte count |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1134 |
* in the tracker object before returning from the |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1135 |
* constructor, so we can set 'copiedFontData' to true here |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1136 |
* without waiting for the results of that constructor. |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1137 |
*/ |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1138 |
copiedFontData = true; |
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1139 |
FontManager fm = FontManagerFactory.getInstance(); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1140 |
Font2D[] font2DArr = |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1141 |
fm.createFont2D(tFile, fontFormat, allFonts, true, tracker); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1142 |
int num = font2DArr.length; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1143 |
Font[] fonts = new Font[num]; |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1144 |
for (int i = 0; i < num; i++) { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1145 |
fonts[i] = new Font(font2DArr[i]); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1146 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1147 |
return fonts; |
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1148 |
} finally { |
18214 | 1149 |
if (tracker != null) { |
1150 |
tracker.remove(tFile); |
|
1151 |
} |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1152 |
if (!copiedFontData) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1153 |
if (tracker != null) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1154 |
tracker.subBytes(totalSize); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1155 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1156 |
AccessController.doPrivileged( |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1157 |
new PrivilegedExceptionAction<Void>() { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1158 |
public Void run() { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1159 |
tFile.delete(); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1160 |
return null; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1161 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1162 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1163 |
); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1164 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1165 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1166 |
} catch (Throwable t) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1167 |
if (t instanceof FontFormatException) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1168 |
throw (FontFormatException)t; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1169 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1170 |
if (t instanceof IOException) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1171 |
throw (IOException)t; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1172 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1173 |
Throwable cause = t.getCause(); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1174 |
if (cause instanceof FontFormatException) { |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1175 |
throw (FontFormatException)cause; |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1176 |
} |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1177 |
throw new IOException("Problem reading font data."); |
2 | 1178 |
} |
1179 |
} |
|
1180 |
||
1181 |
/** |
|
35667 | 1182 |
* Returns a new {@code Font} using the specified font type |
1183 |
* and the specified font file. The new {@code Font} is |
|
2 | 1184 |
* created with a point size of 1 and style {@link #PLAIN PLAIN}. |
35667 | 1185 |
* This base font can then be used with the {@code deriveFont} |
1186 |
* methods in this class to derive new {@code Font} objects with |
|
2 | 1187 |
* varying sizes, styles, transforms and font features. |
35667 | 1188 |
* @param fontFormat the type of the {@code Font}, which is |
2 | 1189 |
* {@link #TRUETYPE_FONT TRUETYPE_FONT} if a TrueType resource is |
1190 |
* specified or {@link #TYPE1_FONT TYPE1_FONT} if a Type 1 resource is |
|
1191 |
* specified. |
|
1192 |
* So long as the returned font, or its derived fonts are referenced |
|
35667 | 1193 |
* the implementation may continue to access {@code fontFile} |
2 | 1194 |
* to retrieve font data. Thus the results are undefined if the file |
1195 |
* is changed, or becomes inaccessible. |
|
1196 |
* <p> |
|
35667 | 1197 |
* To make the {@code Font} available to Font constructors the |
1198 |
* returned {@code Font} must be registered in the |
|
1199 |
* {@code GraphicsEnvironment} by calling |
|
2 | 1200 |
* {@link GraphicsEnvironment#registerFont(Font) registerFont(Font)}. |
35667 | 1201 |
* @param fontFile a {@code File} object representing the |
2 | 1202 |
* input data for the font. |
35667 | 1203 |
* @return a new {@code Font} created with the specified font type. |
1204 |
* @throws IllegalArgumentException if {@code fontFormat} is not |
|
1205 |
* {@code TRUETYPE_FONT} or {@code TYPE1_FONT}. |
|
1206 |
* @throws NullPointerException if {@code fontFile} is null. |
|
1207 |
* @throws IOException if the {@code fontFile} cannot be read. |
|
1208 |
* @throws FontFormatException if {@code fontFile} does |
|
2 | 1209 |
* not contain the required font tables for the specified format. |
1210 |
* @throws SecurityException if the executing code does not have |
|
1211 |
* permission to read from the file. |
|
1212 |
* @see GraphicsEnvironment#registerFont(Font) |
|
1213 |
* @since 1.5 |
|
1214 |
*/ |
|
1215 |
public static Font createFont(int fontFormat, File fontFile) |
|
1216 |
throws java.awt.FontFormatException, java.io.IOException { |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1217 |
|
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1218 |
fontFile = checkFontFile(fontFormat, fontFile); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1219 |
return new Font(fontFile, fontFormat, false, null); |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1220 |
} |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1221 |
|
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1222 |
private static File checkFontFile(int fontFormat, File fontFile) |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1223 |
throws FontFormatException, IOException { |
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1224 |
|
2606
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1225 |
fontFile = new File(fontFile.getPath()); |
09ad5edb5330
6632886: Font.createFont can be persuaded to leak temporary files
prr
parents:
547
diff
changeset
|
1226 |
|
2 | 1227 |
if (fontFormat != Font.TRUETYPE_FONT && |
1228 |
fontFormat != Font.TYPE1_FONT) { |
|
1229 |
throw new IllegalArgumentException ("font format not recognized"); |
|
1230 |
} |
|
1231 |
SecurityManager sm = System.getSecurityManager(); |
|
1232 |
if (sm != null) { |
|
1233 |
FilePermission filePermission = |
|
1234 |
new FilePermission(fontFile.getPath(), "read"); |
|
1235 |
sm.checkPermission(filePermission); |
|
1236 |
} |
|
1237 |
if (!fontFile.canRead()) { |
|
1238 |
throw new IOException("Can't read " + fontFile); |
|
1239 |
} |
|
36899
e766024a0873
8055463: Need public API allowing full access to font collections in Font.createFont()
prr
parents:
35667
diff
changeset
|
1240 |
return fontFile; |
2 | 1241 |
} |
1242 |
||
1243 |
/** |
|
1244 |
* Returns a copy of the transform associated with this |
|
35667 | 1245 |
* {@code Font}. This transform is not necessarily the one |
2 | 1246 |
* used to construct the font. If the font has algorithmic |
1247 |
* superscripting or width adjustment, this will be incorporated |
|
35667 | 1248 |
* into the returned {@code AffineTransform}. |
2 | 1249 |
* <p> |
1250 |
* Typically, fonts will not be transformed. Clients generally |
|
1251 |
* should call {@link #isTransformed} first, and only call this |
|
35667 | 1252 |
* method if {@code isTransformed} returns true. |
2 | 1253 |
* |
1254 |
* @return an {@link AffineTransform} object representing the |
|
35667 | 1255 |
* transform attribute of this {@code Font} object. |
2 | 1256 |
*/ |
1257 |
public AffineTransform getTransform() { |
|
1258 |
/* The most common case is the identity transform. Most callers |
|
1259 |
* should call isTransformed() first, to decide if they need to |
|
1260 |
* get the transform, but some may not. Here we check to see |
|
1261 |
* if we have a nonidentity transform, and only do the work to |
|
1262 |
* fetch and/or compute it if so, otherwise we return a new |
|
1263 |
* identity transform. |
|
1264 |
* |
|
1265 |
* Note that the transform is _not_ necessarily the same as |
|
1266 |
* the transform passed in as an Attribute in a Map, as the |
|
1267 |
* transform returned will also reflect the effects of WIDTH and |
|
1268 |
* SUPERSCRIPT attributes. Clients who want the actual transform |
|
1269 |
* need to call getRequestedAttributes. |
|
1270 |
*/ |
|
1271 |
if (nonIdentityTx) { |
|
1272 |
AttributeValues values = getAttributeValues(); |
|
1273 |
||
1274 |
AffineTransform at = values.isNonDefault(ETRANSFORM) |
|
1275 |
? new AffineTransform(values.getTransform()) |
|
1276 |
: new AffineTransform(); |
|
1277 |
||
1278 |
if (values.getSuperscript() != 0) { |
|
1279 |
// can't get ascent and descent here, recursive call to this fn, |
|
1280 |
// so use pointsize |
|
1281 |
// let users combine super- and sub-scripting |
|
1282 |
||
1283 |
int superscript = values.getSuperscript(); |
|
1284 |
||
1285 |
double trans = 0; |
|
1286 |
int n = 0; |
|
1287 |
boolean up = superscript > 0; |
|
1288 |
int sign = up ? -1 : 1; |
|
1289 |
int ss = up ? superscript : -superscript; |
|
1290 |
||
1291 |
while ((ss & 7) > n) { |
|
1292 |
int newn = ss & 7; |
|
1293 |
trans += sign * (ssinfo[newn] - ssinfo[n]); |
|
1294 |
ss >>= 3; |
|
1295 |
sign = -sign; |
|
1296 |
n = newn; |
|
1297 |
} |
|
1298 |
trans *= pointSize; |
|
1299 |
double scale = Math.pow(2./3., n); |
|
1300 |
||
1301 |
at.preConcatenate(AffineTransform.getTranslateInstance(0, trans)); |
|
1302 |
at.scale(scale, scale); |
|
1303 |
||
1304 |
// note on placement and italics |
|
1305 |
// We preconcatenate the transform because we don't want to translate along |
|
1306 |
// the italic angle, but purely perpendicular to the baseline. While this |
|
1307 |
// looks ok for superscripts, it can lead subscripts to stack on each other |
|
1308 |
// and bring the following text too close. The way we deal with potential |
|
1309 |
// collisions that can occur in the case of italics is by adjusting the |
|
1310 |
// horizontal spacing of the adjacent glyphvectors. Examine the italic |
|
1311 |
// angle of both vectors, if one is non-zero, compute the minimum ascent |
|
1312 |
// and descent, and then the x position at each for each vector along its |
|
1313 |
// italic angle starting from its (offset) baseline. Compute the difference |
|
1314 |
// between the x positions and use the maximum difference to adjust the |
|
1315 |
// position of the right gv. |
|
1316 |
} |
|
1317 |
||
1318 |
if (values.isNonDefault(EWIDTH)) { |
|
1319 |
at.scale(values.getWidth(), 1f); |
|
1320 |
} |
|
1321 |
||
1322 |
return at; |
|
1323 |
} |
|
1324 |
||
1325 |
return new AffineTransform(); |
|
1326 |
} |
|
1327 |
||
1328 |
// x = r^0 + r^1 + r^2... r^n |
|
1329 |
// rx = r^1 + r^2 + r^3... r^(n+1) |
|
1330 |
// x - rx = r^0 - r^(n+1) |
|
1331 |
// x (1 - r) = r^0 - r^(n+1) |
|
1332 |
// x = (r^0 - r^(n+1)) / (1 - r) |
|
1333 |
// x = (1 - r^(n+1)) / (1 - r) |
|
1334 |
||
1335 |
// scale ratio is 2/3 |
|
1336 |
// trans = 1/2 of ascent * x |
|
1337 |
// assume ascent is 3/4 of point size |
|
1338 |
||
1339 |
private static final float[] ssinfo = { |
|
1340 |
0.0f, |
|
1341 |
0.375f, |
|
1342 |
0.625f, |
|
1343 |
0.7916667f, |
|
1344 |
0.9027778f, |
|
1345 |
0.9768519f, |
|
1346 |
1.0262346f, |
|
1347 |
1.0591564f, |
|
1348 |
}; |
|
1349 |
||
1350 |
/** |
|
35667 | 1351 |
* Returns the family name of this {@code Font}. |
2 | 1352 |
* |
1353 |
* <p>The family name of a font is font specific. Two fonts such as |
|
1354 |
* Helvetica Italic and Helvetica Bold have the same family name, |
|
1355 |
* <i>Helvetica</i>, whereas their font face names are |
|
1356 |
* <i>Helvetica Bold</i> and <i>Helvetica Italic</i>. The list of |
|
1357 |
* available family names may be obtained by using the |
|
1358 |
* {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method. |
|
1359 |
* |
|
35667 | 1360 |
* <p>Use {@code getName} to get the logical name of the font. |
1361 |
* Use {@code getFontName} to get the font face name of the font. |
|
1362 |
* @return a {@code String} that is the family name of this |
|
1363 |
* {@code Font}. |
|
2 | 1364 |
* |
1365 |
* @see #getName |
|
1366 |
* @see #getFontName |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1367 |
* @since 1.1 |
2 | 1368 |
*/ |
1369 |
public String getFamily() { |
|
1370 |
return getFamily_NoClientCode(); |
|
1371 |
} |
|
1372 |
// NOTE: This method is called by privileged threads. |
|
1373 |
// We implement this functionality in a package-private |
|
1374 |
// method to insure that it cannot be overridden by client |
|
1375 |
// subclasses. |
|
1376 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
1377 |
final String getFamily_NoClientCode() { |
|
1378 |
return getFamily(Locale.getDefault()); |
|
1379 |
} |
|
1380 |
||
1381 |
/** |
|
35667 | 1382 |
* Returns the family name of this {@code Font}, localized for |
2 | 1383 |
* the specified locale. |
1384 |
* |
|
1385 |
* <p>The family name of a font is font specific. Two fonts such as |
|
1386 |
* Helvetica Italic and Helvetica Bold have the same family name, |
|
1387 |
* <i>Helvetica</i>, whereas their font face names are |
|
1388 |
* <i>Helvetica Bold</i> and <i>Helvetica Italic</i>. The list of |
|
1389 |
* available family names may be obtained by using the |
|
1390 |
* {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method. |
|
1391 |
* |
|
35667 | 1392 |
* <p>Use {@code getFontName} to get the font face name of the font. |
2 | 1393 |
* @param l locale for which to get the family name |
35667 | 1394 |
* @return a {@code String} representing the family name of the |
2 | 1395 |
* font, localized for the specified locale. |
1396 |
* @see #getFontName |
|
1397 |
* @see java.util.Locale |
|
1398 |
* @since 1.2 |
|
1399 |
*/ |
|
1400 |
public String getFamily(Locale l) { |
|
1401 |
if (l == null) { |
|
1402 |
throw new NullPointerException("null locale doesn't mean default"); |
|
1403 |
} |
|
1404 |
return getFont2D().getFamilyName(l); |
|
1405 |
} |
|
1406 |
||
1407 |
/** |
|
35667 | 1408 |
* Returns the postscript name of this {@code Font}. |
1409 |
* Use {@code getFamily} to get the family name of the font. |
|
1410 |
* Use {@code getFontName} to get the font face name of the font. |
|
1411 |
* @return a {@code String} representing the postscript name of |
|
1412 |
* this {@code Font}. |
|
2 | 1413 |
* @since 1.2 |
1414 |
*/ |
|
1415 |
public String getPSName() { |
|
1416 |
return getFont2D().getPostscriptName(); |
|
1417 |
} |
|
1418 |
||
1419 |
/** |
|
35667 | 1420 |
* Returns the logical name of this {@code Font}. |
1421 |
* Use {@code getFamily} to get the family name of the font. |
|
1422 |
* Use {@code getFontName} to get the font face name of the font. |
|
1423 |
* @return a {@code String} representing the logical name of |
|
1424 |
* this {@code Font}. |
|
2 | 1425 |
* @see #getFamily |
1426 |
* @see #getFontName |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1427 |
* @since 1.0 |
2 | 1428 |
*/ |
1429 |
public String getName() { |
|
1430 |
return name; |
|
1431 |
} |
|
1432 |
||
1433 |
/** |
|
35667 | 1434 |
* Returns the font face name of this {@code Font}. For example, |
2 | 1435 |
* Helvetica Bold could be returned as a font face name. |
35667 | 1436 |
* Use {@code getFamily} to get the family name of the font. |
1437 |
* Use {@code getName} to get the logical name of the font. |
|
1438 |
* @return a {@code String} representing the font face name of |
|
1439 |
* this {@code Font}. |
|
2 | 1440 |
* @see #getFamily |
1441 |
* @see #getName |
|
1442 |
* @since 1.2 |
|
1443 |
*/ |
|
1444 |
public String getFontName() { |
|
1445 |
return getFontName(Locale.getDefault()); |
|
1446 |
} |
|
1447 |
||
1448 |
/** |
|
35667 | 1449 |
* Returns the font face name of the {@code Font}, localized |
2 | 1450 |
* for the specified locale. For example, Helvetica Fett could be |
1451 |
* returned as the font face name. |
|
35667 | 1452 |
* Use {@code getFamily} to get the family name of the font. |
2 | 1453 |
* @param l a locale for which to get the font face name |
35667 | 1454 |
* @return a {@code String} representing the font face name, |
2 | 1455 |
* localized for the specified locale. |
1456 |
* @see #getFamily |
|
1457 |
* @see java.util.Locale |
|
1458 |
*/ |
|
1459 |
public String getFontName(Locale l) { |
|
1460 |
if (l == null) { |
|
1461 |
throw new NullPointerException("null locale doesn't mean default"); |
|
1462 |
} |
|
1463 |
return getFont2D().getFontName(l); |
|
1464 |
} |
|
1465 |
||
1466 |
/** |
|
35667 | 1467 |
* Returns the style of this {@code Font}. The style can be |
2 | 1468 |
* PLAIN, BOLD, ITALIC, or BOLD+ITALIC. |
35667 | 1469 |
* @return the style of this {@code Font} |
2 | 1470 |
* @see #isPlain |
1471 |
* @see #isBold |
|
1472 |
* @see #isItalic |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1473 |
* @since 1.0 |
2 | 1474 |
*/ |
1475 |
public int getStyle() { |
|
1476 |
return style; |
|
1477 |
} |
|
1478 |
||
1479 |
/** |
|
35667 | 1480 |
* Returns the point size of this {@code Font}, rounded to |
2 | 1481 |
* an integer. |
1482 |
* Most users are familiar with the idea of using <i>point size</i> to |
|
1483 |
* specify the size of glyphs in a font. This point size defines a |
|
1484 |
* measurement between the baseline of one line to the baseline of the |
|
1485 |
* following line in a single spaced text document. The point size is |
|
1486 |
* based on <i>typographic points</i>, approximately 1/72 of an inch. |
|
1487 |
* <p> |
|
1488 |
* The Java(tm)2D API adopts the convention that one point is |
|
1489 |
* equivalent to one unit in user coordinates. When using a |
|
1490 |
* normalized transform for converting user space coordinates to |
|
1491 |
* device space coordinates 72 user |
|
1492 |
* space units equal 1 inch in device space. In this case one point |
|
1493 |
* is 1/72 of an inch. |
|
35667 | 1494 |
* @return the point size of this {@code Font} in 1/72 of an |
2 | 1495 |
* inch units. |
1496 |
* @see #getSize2D |
|
1497 |
* @see GraphicsConfiguration#getDefaultTransform |
|
1498 |
* @see GraphicsConfiguration#getNormalizingTransform |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1499 |
* @since 1.0 |
2 | 1500 |
*/ |
1501 |
public int getSize() { |
|
1502 |
return size; |
|
1503 |
} |
|
1504 |
||
1505 |
/** |
|
35667 | 1506 |
* Returns the point size of this {@code Font} in |
1507 |
* {@code float} value. |
|
1508 |
* @return the point size of this {@code Font} as a |
|
1509 |
* {@code float} value. |
|
2 | 1510 |
* @see #getSize |
1511 |
* @since 1.2 |
|
1512 |
*/ |
|
1513 |
public float getSize2D() { |
|
1514 |
return pointSize; |
|
1515 |
} |
|
1516 |
||
1517 |
/** |
|
35667 | 1518 |
* Indicates whether or not this {@code Font} object's style is |
2 | 1519 |
* PLAIN. |
35667 | 1520 |
* @return {@code true} if this {@code Font} has a |
21278 | 1521 |
* PLAIN style; |
35667 | 1522 |
* {@code false} otherwise. |
2 | 1523 |
* @see java.awt.Font#getStyle |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1524 |
* @since 1.0 |
2 | 1525 |
*/ |
1526 |
public boolean isPlain() { |
|
1527 |
return style == 0; |
|
1528 |
} |
|
1529 |
||
1530 |
/** |
|
35667 | 1531 |
* Indicates whether or not this {@code Font} object's style is |
2 | 1532 |
* BOLD. |
35667 | 1533 |
* @return {@code true} if this {@code Font} object's |
2 | 1534 |
* style is BOLD; |
35667 | 1535 |
* {@code false} otherwise. |
2 | 1536 |
* @see java.awt.Font#getStyle |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1537 |
* @since 1.0 |
2 | 1538 |
*/ |
1539 |
public boolean isBold() { |
|
1540 |
return (style & BOLD) != 0; |
|
1541 |
} |
|
1542 |
||
1543 |
/** |
|
35667 | 1544 |
* Indicates whether or not this {@code Font} object's style is |
2 | 1545 |
* ITALIC. |
35667 | 1546 |
* @return {@code true} if this {@code Font} object's |
2 | 1547 |
* style is ITALIC; |
35667 | 1548 |
* {@code false} otherwise. |
2 | 1549 |
* @see java.awt.Font#getStyle |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1550 |
* @since 1.0 |
2 | 1551 |
*/ |
1552 |
public boolean isItalic() { |
|
1553 |
return (style & ITALIC) != 0; |
|
1554 |
} |
|
1555 |
||
1556 |
/** |
|
35667 | 1557 |
* Indicates whether or not this {@code Font} object has a |
2 | 1558 |
* transform that affects its size in addition to the Size |
1559 |
* attribute. |
|
35667 | 1560 |
* @return {@code true} if this {@code Font} object |
2 | 1561 |
* has a non-identity AffineTransform attribute. |
35667 | 1562 |
* {@code false} otherwise. |
2 | 1563 |
* @see java.awt.Font#getTransform |
1564 |
* @since 1.4 |
|
1565 |
*/ |
|
1566 |
public boolean isTransformed() { |
|
1567 |
return nonIdentityTx; |
|
1568 |
} |
|
1569 |
||
1570 |
/** |
|
1571 |
* Return true if this Font contains attributes that require extra |
|
1572 |
* layout processing. |
|
1573 |
* @return true if the font has layout attributes |
|
1574 |
* @since 1.6 |
|
1575 |
*/ |
|
1576 |
public boolean hasLayoutAttributes() { |
|
1577 |
return hasLayoutAttributes; |
|
1578 |
} |
|
1579 |
||
1580 |
/** |
|
35667 | 1581 |
* Returns a {@code Font} object from the system properties list. |
1582 |
* {@code nm} is treated as the name of a system property to be |
|
1583 |
* obtained. The {@code String} value of this property is then |
|
1584 |
* interpreted as a {@code Font} object according to the |
|
1585 |
* specification of {@code Font.decode(String)} |
|
2 | 1586 |
* If the specified property is not found, or the executing code does |
1587 |
* not have permission to read the property, null is returned instead. |
|
1588 |
* |
|
1589 |
* @param nm the property name |
|
35667 | 1590 |
* @return a {@code Font} object that the property name |
2 | 1591 |
* describes, or null if no such property exists. |
1592 |
* @throws NullPointerException if nm is null. |
|
1593 |
* @since 1.2 |
|
1594 |
* @see #decode(String) |
|
1595 |
*/ |
|
1596 |
public static Font getFont(String nm) { |
|
1597 |
return getFont(nm, null); |
|
1598 |
} |
|
1599 |
||
1600 |
/** |
|
35667 | 1601 |
* Returns the {@code Font} that the {@code str} |
2 | 1602 |
* argument describes. |
1603 |
* To ensure that this method returns the desired Font, |
|
35667 | 1604 |
* format the {@code str} parameter in |
2 | 1605 |
* one of these ways |
21957 | 1606 |
* |
2 | 1607 |
* <ul> |
1608 |
* <li><em>fontname-style-pointsize</em> |
|
1609 |
* <li><em>fontname-pointsize</em> |
|
1610 |
* <li><em>fontname-style</em> |
|
1611 |
* <li><em>fontname</em> |
|
1612 |
* <li><em>fontname style pointsize</em> |
|
1613 |
* <li><em>fontname pointsize</em> |
|
1614 |
* <li><em>fontname style</em> |
|
1615 |
* <li><em>fontname</em> |
|
1616 |
* </ul> |
|
1617 |
* in which <i>style</i> is one of the four |
|
1618 |
* case-insensitive strings: |
|
35667 | 1619 |
* {@code "PLAIN"}, {@code "BOLD"}, {@code "BOLDITALIC"}, or |
1620 |
* {@code "ITALIC"}, and pointsize is a positive decimal integer |
|
2 | 1621 |
* representation of the point size. |
1622 |
* For example, if you want a font that is Arial, bold, with |
|
1623 |
* a point size of 18, you would call this method with: |
|
1624 |
* "Arial-BOLD-18". |
|
1625 |
* This is equivalent to calling the Font constructor : |
|
35667 | 1626 |
* {@code new Font("Arial", Font.BOLD, 18);} |
2 | 1627 |
* and the values are interpreted as specified by that constructor. |
1628 |
* <p> |
|
1629 |
* A valid trailing decimal field is always interpreted as the pointsize. |
|
1630 |
* Therefore a fontname containing a trailing decimal value should not |
|
1631 |
* be used in the fontname only form. |
|
1632 |
* <p> |
|
1633 |
* If a style name field is not one of the valid style strings, it is |
|
1634 |
* interpreted as part of the font name, and the default style is used. |
|
1635 |
* <p> |
|
1636 |
* Only one of ' ' or '-' may be used to separate fields in the input. |
|
1637 |
* The identified separator is the one closest to the end of the string |
|
1638 |
* which separates a valid pointsize, or a valid style name from |
|
1639 |
* the rest of the string. |
|
1640 |
* Null (empty) pointsize and style fields are treated |
|
1641 |
* as valid fields with the default value for that field. |
|
1642 |
*<p> |
|
1643 |
* Some font names may include the separator characters ' ' or '-'. |
|
35667 | 1644 |
* If {@code str} is not formed with 3 components, e.g. such that |
1645 |
* {@code style} or {@code pointsize} fields are not present in |
|
1646 |
* {@code str}, and {@code fontname} also contains a |
|
2 | 1647 |
* character determined to be the separator character |
1648 |
* then these characters where they appear as intended to be part of |
|
35667 | 1649 |
* {@code fontname} may instead be interpreted as separators |
2 | 1650 |
* so the font name may not be properly recognised. |
1651 |
* |
|
1652 |
* <p> |
|
1653 |
* The default size is 12 and the default style is PLAIN. |
|
35667 | 1654 |
* If {@code str} does not specify a valid size, the returned |
1655 |
* {@code Font} has a size of 12. If {@code str} does not |
|
2 | 1656 |
* specify a valid style, the returned Font has a style of PLAIN. |
1657 |
* If you do not specify a valid font name in |
|
35667 | 1658 |
* the {@code str} argument, this method will return |
2 | 1659 |
* a font with the family name "Dialog". |
1660 |
* To determine what font family names are available on |
|
1661 |
* your system, use the |
|
1662 |
* {@link GraphicsEnvironment#getAvailableFontFamilyNames()} method. |
|
35667 | 1663 |
* If {@code str} is {@code null}, a new {@code Font} |
2 | 1664 |
* is returned with the family name "Dialog", a size of 12 and a |
1665 |
* PLAIN style. |
|
35667 | 1666 |
* @param str the name of the font, or {@code null} |
1667 |
* @return the {@code Font} object that {@code str} |
|
1668 |
* describes, or a new default {@code Font} if |
|
1669 |
* {@code str} is {@code null}. |
|
2 | 1670 |
* @see #getFamily |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1671 |
* @since 1.1 |
2 | 1672 |
*/ |
1673 |
public static Font decode(String str) { |
|
1674 |
String fontName = str; |
|
1675 |
String styleName = ""; |
|
1676 |
int fontSize = 12; |
|
1677 |
int fontStyle = Font.PLAIN; |
|
1678 |
||
1679 |
if (str == null) { |
|
1680 |
return new Font(DIALOG, fontStyle, fontSize); |
|
1681 |
} |
|
1682 |
||
1683 |
int lastHyphen = str.lastIndexOf('-'); |
|
1684 |
int lastSpace = str.lastIndexOf(' '); |
|
1685 |
char sepChar = (lastHyphen > lastSpace) ? '-' : ' '; |
|
1686 |
int sizeIndex = str.lastIndexOf(sepChar); |
|
1687 |
int styleIndex = str.lastIndexOf(sepChar, sizeIndex-1); |
|
1688 |
int strlen = str.length(); |
|
1689 |
||
1690 |
if (sizeIndex > 0 && sizeIndex+1 < strlen) { |
|
1691 |
try { |
|
1692 |
fontSize = |
|
1693 |
Integer.valueOf(str.substring(sizeIndex+1)).intValue(); |
|
1694 |
if (fontSize <= 0) { |
|
1695 |
fontSize = 12; |
|
1696 |
} |
|
1697 |
} catch (NumberFormatException e) { |
|
1698 |
/* It wasn't a valid size, if we didn't also find the |
|
1699 |
* start of the style string perhaps this is the style */ |
|
1700 |
styleIndex = sizeIndex; |
|
1701 |
sizeIndex = strlen; |
|
1702 |
if (str.charAt(sizeIndex-1) == sepChar) { |
|
1703 |
sizeIndex--; |
|
1704 |
} |
|
1705 |
} |
|
1706 |
} |
|
1707 |
||
1708 |
if (styleIndex >= 0 && styleIndex+1 < strlen) { |
|
1709 |
styleName = str.substring(styleIndex+1, sizeIndex); |
|
1710 |
styleName = styleName.toLowerCase(Locale.ENGLISH); |
|
1711 |
if (styleName.equals("bolditalic")) { |
|
1712 |
fontStyle = Font.BOLD | Font.ITALIC; |
|
1713 |
} else if (styleName.equals("italic")) { |
|
1714 |
fontStyle = Font.ITALIC; |
|
1715 |
} else if (styleName.equals("bold")) { |
|
1716 |
fontStyle = Font.BOLD; |
|
1717 |
} else if (styleName.equals("plain")) { |
|
1718 |
fontStyle = Font.PLAIN; |
|
1719 |
} else { |
|
1720 |
/* this string isn't any of the expected styles, so |
|
1721 |
* assume its part of the font name |
|
1722 |
*/ |
|
1723 |
styleIndex = sizeIndex; |
|
1724 |
if (str.charAt(styleIndex-1) == sepChar) { |
|
1725 |
styleIndex--; |
|
1726 |
} |
|
1727 |
} |
|
1728 |
fontName = str.substring(0, styleIndex); |
|
1729 |
||
1730 |
} else { |
|
1731 |
int fontEnd = strlen; |
|
1732 |
if (styleIndex > 0) { |
|
1733 |
fontEnd = styleIndex; |
|
1734 |
} else if (sizeIndex > 0) { |
|
1735 |
fontEnd = sizeIndex; |
|
1736 |
} |
|
1737 |
if (fontEnd > 0 && str.charAt(fontEnd-1) == sepChar) { |
|
1738 |
fontEnd--; |
|
1739 |
} |
|
1740 |
fontName = str.substring(0, fontEnd); |
|
1741 |
} |
|
1742 |
||
1743 |
return new Font(fontName, fontStyle, fontSize); |
|
1744 |
} |
|
1745 |
||
1746 |
/** |
|
35667 | 1747 |
* Gets the specified {@code Font} from the system properties |
1748 |
* list. As in the {@code getProperty} method of |
|
1749 |
* {@code System}, the first |
|
2 | 1750 |
* argument is treated as the name of a system property to be |
35667 | 1751 |
* obtained. The {@code String} value of this property is then |
1752 |
* interpreted as a {@code Font} object. |
|
2 | 1753 |
* <p> |
1754 |
* The property value should be one of the forms accepted by |
|
35667 | 1755 |
* {@code Font.decode(String)} |
2 | 1756 |
* If the specified property is not found, or the executing code does not |
35667 | 1757 |
* have permission to read the property, the {@code font} |
2 | 1758 |
* argument is returned instead. |
1759 |
* @param nm the case-insensitive property name |
|
35667 | 1760 |
* @param font a default {@code Font} to return if property |
1761 |
* {@code nm} is not defined |
|
1762 |
* @return the {@code Font} value of the property. |
|
2 | 1763 |
* @throws NullPointerException if nm is null. |
1764 |
* @see #decode(String) |
|
1765 |
*/ |
|
1766 |
public static Font getFont(String nm, Font font) { |
|
1767 |
String str = null; |
|
1768 |
try { |
|
1769 |
str =System.getProperty(nm); |
|
1770 |
} catch(SecurityException e) { |
|
1771 |
} |
|
1772 |
if (str == null) { |
|
1773 |
return font; |
|
1774 |
} |
|
1775 |
return decode ( str ); |
|
1776 |
} |
|
1777 |
||
1778 |
transient int hash; |
|
1779 |
/** |
|
35667 | 1780 |
* Returns a hashcode for this {@code Font}. |
1781 |
* @return a hashcode value for this {@code Font}. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1782 |
* @since 1.0 |
2 | 1783 |
*/ |
1784 |
public int hashCode() { |
|
1785 |
if (hash == 0) { |
|
1786 |
hash = name.hashCode() ^ style ^ size; |
|
1787 |
/* It is possible many fonts differ only in transform. |
|
1788 |
* So include the transform in the hash calculation. |
|
1789 |
* nonIdentityTx is set whenever there is a transform in |
|
1790 |
* 'values'. The tests for null are required because it can |
|
1791 |
* also be set for other reasons. |
|
1792 |
*/ |
|
1793 |
if (nonIdentityTx && |
|
1794 |
values != null && values.getTransform() != null) { |
|
1795 |
hash ^= values.getTransform().hashCode(); |
|
1796 |
} |
|
1797 |
} |
|
1798 |
return hash; |
|
1799 |
} |
|
1800 |
||
1801 |
/** |
|
35667 | 1802 |
* Compares this {@code Font} object to the specified |
1803 |
* {@code Object}. |
|
1804 |
* @param obj the {@code Object} to compare |
|
1805 |
* @return {@code true} if the objects are the same |
|
1806 |
* or if the argument is a {@code Font} object |
|
2 | 1807 |
* describing the same font as this object; |
35667 | 1808 |
* {@code false} otherwise. |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1809 |
* @since 1.0 |
2 | 1810 |
*/ |
1811 |
public boolean equals(Object obj) { |
|
1812 |
if (obj == this) { |
|
1813 |
return true; |
|
1814 |
} |
|
1815 |
||
39866 | 1816 |
if (obj instanceof Font) { |
1817 |
Font font = (Font)obj; |
|
1818 |
if (size == font.size && |
|
1819 |
style == font.style && |
|
1820 |
nonIdentityTx == font.nonIdentityTx && |
|
1821 |
hasLayoutAttributes == font.hasLayoutAttributes && |
|
1822 |
pointSize == font.pointSize && |
|
1823 |
name.equals(font.name)) { |
|
2 | 1824 |
|
39866 | 1825 |
/* 'values' is usually initialized lazily, except when |
1826 |
* the font is constructed from a Map, or derived using |
|
1827 |
* a Map or other values. So if only one font has |
|
1828 |
* the field initialized we need to initialize it in |
|
1829 |
* the other instance and compare. |
|
1830 |
*/ |
|
1831 |
if (values == null) { |
|
1832 |
if (font.values == null) { |
|
1833 |
return true; |
|
2 | 1834 |
} else { |
39866 | 1835 |
return getAttributeValues().equals(font.values); |
2 | 1836 |
} |
39866 | 1837 |
} else { |
1838 |
return values.equals(font.getAttributeValues()); |
|
2 | 1839 |
} |
1840 |
} |
|
1841 |
} |
|
1842 |
return false; |
|
1843 |
} |
|
1844 |
||
1845 |
/** |
|
35667 | 1846 |
* Converts this {@code Font} object to a {@code String} |
2 | 1847 |
* representation. |
35667 | 1848 |
* @return a {@code String} representation of this |
1849 |
* {@code Font} object. |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
23010
diff
changeset
|
1850 |
* @since 1.0 |
2 | 1851 |
*/ |
1852 |
// NOTE: This method may be called by privileged threads. |
|
1853 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
1854 |
public String toString() { |
|
1855 |
String strStyle; |
|
1856 |
||
1857 |
if (isBold()) { |
|
1858 |
strStyle = isItalic() ? "bolditalic" : "bold"; |
|
1859 |
} else { |
|
1860 |
strStyle = isItalic() ? "italic" : "plain"; |
|
1861 |
} |
|
1862 |
||
1863 |
return getClass().getName() + "[family=" + getFamily() + ",name=" + name + ",style=" + |
|
1864 |
strStyle + ",size=" + size + "]"; |
|
1865 |
} // toString() |
|
1866 |
||
1867 |
||
35667 | 1868 |
/** Serialization support. A {@code readObject} |
26749 | 1869 |
* method is necessary because the constructor creates |
2 | 1870 |
* the font's peer, and we can't serialize the peer. |
1871 |
* Similarly the computed font "family" may be different |
|
35667 | 1872 |
* at {@code readObject} time than at |
1873 |
* {@code writeObject} time. An integer version is |
|
2 | 1874 |
* written so that future versions of this class will be |
1875 |
* able to recognize serialized output from this one. |
|
1876 |
*/ |
|
1877 |
/** |
|
35667 | 1878 |
* The {@code Font} Serializable Data Form. |
2 | 1879 |
* |
1880 |
* @serial |
|
1881 |
*/ |
|
1882 |
private int fontSerializedDataVersion = 1; |
|
1883 |
||
1884 |
/** |
|
1885 |
* Writes default serializable fields to a stream. |
|
1886 |
* |
|
35667 | 1887 |
* @param s the {@code ObjectOutputStream} to write |
2 | 1888 |
* @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener) |
1889 |
* @see #readObject(java.io.ObjectInputStream) |
|
1890 |
*/ |
|
1891 |
private void writeObject(java.io.ObjectOutputStream s) |
|
51116
7e34f3da2293
8203263: Remove unnecessary throws clauses from serialization-related methods
darcy
parents:
48285
diff
changeset
|
1892 |
throws java.io.IOException |
2 | 1893 |
{ |
1894 |
if (values != null) { |
|
1895 |
synchronized(values) { |
|
1896 |
// transient |
|
1897 |
fRequestedAttributes = values.toSerializableHashtable(); |
|
1898 |
s.defaultWriteObject(); |
|
1899 |
fRequestedAttributes = null; |
|
1900 |
} |
|
1901 |
} else { |
|
1902 |
s.defaultWriteObject(); |
|
1903 |
} |
|
1904 |
} |
|
1905 |
||
1906 |
/** |
|
35667 | 1907 |
* Reads the {@code ObjectInputStream}. |
2 | 1908 |
* Unrecognized keys or values will be ignored. |
1909 |
* |
|
35667 | 1910 |
* @param s the {@code ObjectInputStream} to read |
2 | 1911 |
* @serial |
1912 |
* @see #writeObject(java.io.ObjectOutputStream) |
|
1913 |
*/ |
|
1914 |
private void readObject(java.io.ObjectInputStream s) |
|
1915 |
throws java.lang.ClassNotFoundException, |
|
1916 |
java.io.IOException |
|
1917 |
{ |
|
1918 |
s.defaultReadObject(); |
|
1919 |
if (pointSize == 0) { |
|
1920 |
pointSize = (float)size; |
|
1921 |
} |
|
1922 |
||
1923 |
// Handle fRequestedAttributes. |
|
1924 |
// in 1.5, we always streamed out the font values plus |
|
1925 |
// TRANSFORM, SUPERSCRIPT, and WIDTH, regardless of whether the |
|
1926 |
// values were default or not. In 1.6 we only stream out |
|
1927 |
// defined values. So, 1.6 streams in from a 1.5 stream, |
|
1928 |
// it check each of these values and 'undefines' it if the |
|
1929 |
// value is the default. |
|
1930 |
||
1931 |
if (fRequestedAttributes != null) { |
|
58632 | 1932 |
try { |
2 | 1933 |
values = getAttributeValues(); // init |
1934 |
AttributeValues extras = |
|
1935 |
AttributeValues.fromSerializableHashtable(fRequestedAttributes); |
|
1936 |
if (!AttributeValues.is16Hashtable(fRequestedAttributes)) { |
|
1937 |
extras.unsetDefault(); // if legacy stream, undefine these |
|
1938 |
} |
|
1939 |
values = getAttributeValues().merge(extras); |
|
1940 |
this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK); |
|
1941 |
this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK); |
|
58632 | 1942 |
} catch (Throwable t) { |
1943 |
throw new IOException(t); |
|
1944 |
} finally { |
|
2 | 1945 |
fRequestedAttributes = null; // don't need it any more |
1946 |
} |
|
1947 |
} |
|
58632 | 1948 |
} |
2 | 1949 |
|
1950 |
/** |
|
35667 | 1951 |
* Returns the number of glyphs in this {@code Font}. Glyph codes |
1952 |
* for this {@code Font} range from 0 to |
|
1953 |
* {@code getNumGlyphs()} - 1. |
|
1954 |
* @return the number of glyphs in this {@code Font}. |
|
2 | 1955 |
* @since 1.2 |
1956 |
*/ |
|
1957 |
public int getNumGlyphs() { |
|
1958 |
return getFont2D().getNumGlyphs(); |
|
1959 |
} |
|
1960 |
||
1961 |
/** |
|
35667 | 1962 |
* Returns the glyphCode which is used when this {@code Font} |
2 | 1963 |
* does not have a glyph for a specified unicode code point. |
35667 | 1964 |
* @return the glyphCode of this {@code Font}. |
2 | 1965 |
* @since 1.2 |
1966 |
*/ |
|
1967 |
public int getMissingGlyphCode() { |
|
1968 |
return getFont2D().getMissingGlyphCode(); |
|
1969 |
} |
|
1970 |
||
1971 |
/** |
|
1972 |
* Returns the baseline appropriate for displaying this character. |
|
1973 |
* <p> |
|
1974 |
* Large fonts can support different writing systems, and each system can |
|
1975 |
* use a different baseline. |
|
1976 |
* The character argument determines the writing system to use. Clients |
|
1977 |
* should not assume all characters use the same baseline. |
|
1978 |
* |
|
1979 |
* @param c a character used to identify the writing system |
|
1980 |
* @return the baseline appropriate for the specified character. |
|
1981 |
* @see LineMetrics#getBaselineOffsets |
|
1982 |
* @see #ROMAN_BASELINE |
|
1983 |
* @see #CENTER_BASELINE |
|
1984 |
* @see #HANGING_BASELINE |
|
1985 |
* @since 1.2 |
|
1986 |
*/ |
|
1987 |
public byte getBaselineFor(char c) { |
|
1988 |
return getFont2D().getBaselineFor(c); |
|
1989 |
} |
|
1990 |
||
1991 |
/** |
|
1992 |
* Returns a map of font attributes available in this |
|
35667 | 1993 |
* {@code Font}. Attributes include things like ligatures and |
2 | 1994 |
* glyph substitution. |
35667 | 1995 |
* @return the attributes map of this {@code Font}. |
2 | 1996 |
*/ |
1997 |
public Map<TextAttribute,?> getAttributes(){ |
|
1998 |
return new AttributeMap(getAttributeValues()); |
|
1999 |
} |
|
2000 |
||
2001 |
/** |
|
2002 |
* Returns the keys of all the attributes supported by this |
|
35667 | 2003 |
* {@code Font}. These attributes can be used to derive other |
2 | 2004 |
* fonts. |
2005 |
* @return an array containing the keys of all the attributes |
|
35667 | 2006 |
* supported by this {@code Font}. |
2 | 2007 |
* @since 1.2 |
2008 |
*/ |
|
2009 |
public Attribute[] getAvailableAttributes() { |
|
2010 |
// FONT is not supported by Font |
|
2011 |
||
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
51116
diff
changeset
|
2012 |
Attribute[] attributes = { |
2 | 2013 |
TextAttribute.FAMILY, |
2014 |
TextAttribute.WEIGHT, |
|
2015 |
TextAttribute.WIDTH, |
|
2016 |
TextAttribute.POSTURE, |
|
2017 |
TextAttribute.SIZE, |
|
2018 |
TextAttribute.TRANSFORM, |
|
2019 |
TextAttribute.SUPERSCRIPT, |
|
2020 |
TextAttribute.CHAR_REPLACEMENT, |
|
2021 |
TextAttribute.FOREGROUND, |
|
2022 |
TextAttribute.BACKGROUND, |
|
2023 |
TextAttribute.UNDERLINE, |
|
2024 |
TextAttribute.STRIKETHROUGH, |
|
2025 |
TextAttribute.RUN_DIRECTION, |
|
2026 |
TextAttribute.BIDI_EMBEDDING, |
|
2027 |
TextAttribute.JUSTIFICATION, |
|
2028 |
TextAttribute.INPUT_METHOD_HIGHLIGHT, |
|
2029 |
TextAttribute.INPUT_METHOD_UNDERLINE, |
|
2030 |
TextAttribute.SWAP_COLORS, |
|
2031 |
TextAttribute.NUMERIC_SHAPING, |
|
2032 |
TextAttribute.KERNING, |
|
2033 |
TextAttribute.LIGATURES, |
|
2034 |
TextAttribute.TRACKING, |
|
2035 |
}; |
|
2036 |
||
2037 |
return attributes; |
|
2038 |
} |
|
2039 |
||
2040 |
/** |
|
35667 | 2041 |
* Creates a new {@code Font} object by replicating this |
2042 |
* {@code Font} object and applying a new style and size. |
|
2043 |
* @param style the style for the new {@code Font} |
|
2044 |
* @param size the size for the new {@code Font} |
|
2045 |
* @return a new {@code Font} object. |
|
2 | 2046 |
* @since 1.2 |
2047 |
*/ |
|
2048 |
public Font deriveFont(int style, float size){ |
|
2049 |
if (values == null) { |
|
2050 |
return new Font(name, style, size, createdFont, font2DHandle); |
|
2051 |
} |
|
2052 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2053 |
int oldStyle = (this.style != style) ? this.style : -1; |
|
2054 |
applyStyle(style, newValues); |
|
2055 |
newValues.setSize(size); |
|
2056 |
return new Font(newValues, null, oldStyle, createdFont, font2DHandle); |
|
2057 |
} |
|
2058 |
||
2059 |
/** |
|
35667 | 2060 |
* Creates a new {@code Font} object by replicating this |
2061 |
* {@code Font} object and applying a new style and transform. |
|
2062 |
* @param style the style for the new {@code Font} |
|
2063 |
* @param trans the {@code AffineTransform} associated with the |
|
2064 |
* new {@code Font} |
|
2065 |
* @return a new {@code Font} object. |
|
2066 |
* @throws IllegalArgumentException if {@code trans} is |
|
2067 |
* {@code null} |
|
2 | 2068 |
* @since 1.2 |
2069 |
*/ |
|
2070 |
public Font deriveFont(int style, AffineTransform trans){ |
|
2071 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2072 |
int oldStyle = (this.style != style) ? this.style : -1; |
|
2073 |
applyStyle(style, newValues); |
|
2074 |
applyTransform(trans, newValues); |
|
2075 |
return new Font(newValues, null, oldStyle, createdFont, font2DHandle); |
|
2076 |
} |
|
2077 |
||
2078 |
/** |
|
35667 | 2079 |
* Creates a new {@code Font} object by replicating the current |
2080 |
* {@code Font} object and applying a new size to it. |
|
2081 |
* @param size the size for the new {@code Font}. |
|
2082 |
* @return a new {@code Font} object. |
|
2 | 2083 |
* @since 1.2 |
2084 |
*/ |
|
2085 |
public Font deriveFont(float size){ |
|
2086 |
if (values == null) { |
|
2087 |
return new Font(name, style, size, createdFont, font2DHandle); |
|
2088 |
} |
|
2089 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2090 |
newValues.setSize(size); |
|
2091 |
return new Font(newValues, null, -1, createdFont, font2DHandle); |
|
2092 |
} |
|
2093 |
||
2094 |
/** |
|
35667 | 2095 |
* Creates a new {@code Font} object by replicating the current |
2096 |
* {@code Font} object and applying a new transform to it. |
|
2097 |
* @param trans the {@code AffineTransform} associated with the |
|
2098 |
* new {@code Font} |
|
2099 |
* @return a new {@code Font} object. |
|
2100 |
* @throws IllegalArgumentException if {@code trans} is |
|
2101 |
* {@code null} |
|
2 | 2102 |
* @since 1.2 |
2103 |
*/ |
|
2104 |
public Font deriveFont(AffineTransform trans){ |
|
2105 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2106 |
applyTransform(trans, newValues); |
|
2107 |
return new Font(newValues, null, -1, createdFont, font2DHandle); |
|
2108 |
} |
|
2109 |
||
2110 |
/** |
|
35667 | 2111 |
* Creates a new {@code Font} object by replicating the current |
2112 |
* {@code Font} object and applying a new style to it. |
|
2113 |
* @param style the style for the new {@code Font} |
|
2114 |
* @return a new {@code Font} object. |
|
2 | 2115 |
* @since 1.2 |
2116 |
*/ |
|
2117 |
public Font deriveFont(int style){ |
|
2118 |
if (values == null) { |
|
2119 |
return new Font(name, style, size, createdFont, font2DHandle); |
|
2120 |
} |
|
2121 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2122 |
int oldStyle = (this.style != style) ? this.style : -1; |
|
2123 |
applyStyle(style, newValues); |
|
2124 |
return new Font(newValues, null, oldStyle, createdFont, font2DHandle); |
|
2125 |
} |
|
2126 |
||
2127 |
/** |
|
35667 | 2128 |
* Creates a new {@code Font} object by replicating the current |
2129 |
* {@code Font} object and applying a new set of font attributes |
|
2 | 2130 |
* to it. |
2131 |
* |
|
2132 |
* @param attributes a map of attributes enabled for the new |
|
35667 | 2133 |
* {@code Font} |
2134 |
* @return a new {@code Font} object. |
|
2 | 2135 |
* @since 1.2 |
2136 |
*/ |
|
2137 |
public Font deriveFont(Map<? extends Attribute, ?> attributes) { |
|
2138 |
if (attributes == null) { |
|
2139 |
return this; |
|
2140 |
} |
|
2141 |
AttributeValues newValues = getAttributeValues().clone(); |
|
2142 |
newValues.merge(attributes, RECOGNIZED_MASK); |
|
2143 |
||
2144 |
return new Font(newValues, name, style, createdFont, font2DHandle); |
|
2145 |
} |
|
2146 |
||
2147 |
/** |
|
35667 | 2148 |
* Checks if this {@code Font} has a glyph for the specified |
2 | 2149 |
* character. |
2150 |
* |
|
55366 | 2151 |
* <p> <b>Note:</b> This method cannot handle |
2152 |
* <a href="../../../java.base/java/lang/Character.html#supplementary"> |
|
2153 |
* supplementary characters</a>. |
|
2154 |
* To support all Unicode characters, including |
|
2 | 2155 |
* supplementary characters, use the {@link #canDisplay(int)} |
35667 | 2156 |
* method or {@code canDisplayUpTo} methods. |
2 | 2157 |
* |
2158 |
* @param c the character for which a glyph is needed |
|
35667 | 2159 |
* @return {@code true} if this {@code Font} has a glyph for this |
2160 |
* character; {@code false} otherwise. |
|
2 | 2161 |
* @since 1.2 |
2162 |
*/ |
|
2163 |
public boolean canDisplay(char c){ |
|
2164 |
return getFont2D().canDisplay(c); |
|
2165 |
} |
|
2166 |
||
2167 |
/** |
|
35667 | 2168 |
* Checks if this {@code Font} has a glyph for the specified |
2 | 2169 |
* character. |
2170 |
* |
|
2171 |
* @param codePoint the character (Unicode code point) for which a glyph |
|
2172 |
* is needed. |
|
35667 | 2173 |
* @return {@code true} if this {@code Font} has a glyph for the |
2174 |
* character; {@code false} otherwise. |
|
2 | 2175 |
* @throws IllegalArgumentException if the code point is not a valid Unicode |
2176 |
* code point. |
|
2177 |
* @see Character#isValidCodePoint(int) |
|
2178 |
* @since 1.5 |
|
2179 |
*/ |
|
2180 |
public boolean canDisplay(int codePoint) { |
|
2181 |
if (!Character.isValidCodePoint(codePoint)) { |
|
2182 |
throw new IllegalArgumentException("invalid code point: " + |
|
2183 |
Integer.toHexString(codePoint)); |
|
2184 |
} |
|
2185 |
return getFont2D().canDisplay(codePoint); |
|
2186 |
} |
|
2187 |
||
2188 |
/** |
|
35667 | 2189 |
* Indicates whether or not this {@code Font} can display a |
2190 |
* specified {@code String}. For strings with Unicode encoding, |
|
2 | 2191 |
* it is important to know if a particular font can display the |
35667 | 2192 |
* string. This method returns an offset into the {@code String} |
2193 |
* {@code str} which is the first character this |
|
2194 |
* {@code Font} cannot display without using the missing glyph |
|
2195 |
* code. If the {@code Font} can display all characters, -1 is |
|
2 | 2196 |
* returned. |
35667 | 2197 |
* @param str a {@code String} object |
2198 |
* @return an offset into {@code str} that points |
|
2199 |
* to the first character in {@code str} that this |
|
2200 |
* {@code Font} cannot display; or {@code -1} if |
|
2201 |
* this {@code Font} can display all characters in |
|
2202 |
* {@code str}. |
|
2 | 2203 |
* @since 1.2 |
2204 |
*/ |
|
2205 |
public int canDisplayUpTo(String str) { |
|
8520
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2206 |
Font2D font2d = getFont2D(); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2207 |
int len = str.length(); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2208 |
for (int i = 0; i < len; i++) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2209 |
char c = str.charAt(i); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2210 |
if (font2d.canDisplay(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2211 |
continue; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2212 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2213 |
if (!Character.isHighSurrogate(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2214 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2215 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2216 |
if (!font2d.canDisplay(str.codePointAt(i))) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2217 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2218 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2219 |
i++; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2220 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2221 |
return -1; |
2 | 2222 |
} |
2223 |
||
2224 |
/** |
|
35667 | 2225 |
* Indicates whether or not this {@code Font} can display |
2226 |
* the characters in the specified {@code text} |
|
2227 |
* starting at {@code start} and ending at |
|
2228 |
* {@code limit}. This method is a convenience overload. |
|
2229 |
* @param text the specified array of {@code char} values |
|
2 | 2230 |
* @param start the specified starting offset (in |
35667 | 2231 |
* {@code char}s) into the specified array of |
2232 |
* {@code char} values |
|
2 | 2233 |
* @param limit the specified ending offset (in |
35667 | 2234 |
* {@code char}s) into the specified array of |
2235 |
* {@code char} values |
|
2236 |
* @return an offset into {@code text} that points |
|
2237 |
* to the first character in {@code text} that this |
|
2238 |
* {@code Font} cannot display; or {@code -1} if |
|
2239 |
* this {@code Font} can display all characters in |
|
2240 |
* {@code text}. |
|
2 | 2241 |
* @since 1.2 |
2242 |
*/ |
|
2243 |
public int canDisplayUpTo(char[] text, int start, int limit) { |
|
8520
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2244 |
Font2D font2d = getFont2D(); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2245 |
for (int i = start; i < limit; i++) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2246 |
char c = text[i]; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2247 |
if (font2d.canDisplay(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2248 |
continue; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2249 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2250 |
if (!Character.isHighSurrogate(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2251 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2252 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2253 |
if (!font2d.canDisplay(Character.codePointAt(text, i, limit))) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2254 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2255 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2256 |
i++; |
2 | 2257 |
} |
8520
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2258 |
return -1; |
2 | 2259 |
} |
2260 |
||
2261 |
/** |
|
35667 | 2262 |
* Indicates whether or not this {@code Font} can display the |
2263 |
* text specified by the {@code iter} starting at |
|
2264 |
* {@code start} and ending at {@code limit}. |
|
2 | 2265 |
* |
2266 |
* @param iter a {@link CharacterIterator} object |
|
2267 |
* @param start the specified starting offset into the specified |
|
35667 | 2268 |
* {@code CharacterIterator}. |
2 | 2269 |
* @param limit the specified ending offset into the specified |
35667 | 2270 |
* {@code CharacterIterator}. |
2271 |
* @return an offset into {@code iter} that points |
|
2272 |
* to the first character in {@code iter} that this |
|
2273 |
* {@code Font} cannot display; or {@code -1} if |
|
2274 |
* this {@code Font} can display all characters in |
|
2275 |
* {@code iter}. |
|
2 | 2276 |
* @since 1.2 |
2277 |
*/ |
|
2278 |
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) { |
|
8520
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2279 |
Font2D font2d = getFont2D(); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2280 |
char c = iter.setIndex(start); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2281 |
for (int i = start; i < limit; i++, c = iter.next()) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2282 |
if (font2d.canDisplay(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2283 |
continue; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2284 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2285 |
if (!Character.isHighSurrogate(c)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2286 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2287 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2288 |
char c2 = iter.next(); |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2289 |
// c2 could be CharacterIterator.DONE which is not a low surrogate. |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2290 |
if (!Character.isLowSurrogate(c2)) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2291 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2292 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2293 |
if (!font2d.canDisplay(Character.toCodePoint(c, c2))) { |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2294 |
return i; |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2295 |
} |
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2296 |
i++; |
2 | 2297 |
} |
8520
a9e798f494cb
6623219: Font.canDisplayUpTo does not work with supplementary characters
okutsu
parents:
7668
diff
changeset
|
2298 |
return -1; |
2 | 2299 |
} |
2300 |
||
2301 |
/** |
|
35667 | 2302 |
* Returns the italic angle of this {@code Font}. The italic angle |
2 | 2303 |
* is the inverse slope of the caret which best matches the posture of this |
35667 | 2304 |
* {@code Font}. |
2 | 2305 |
* @see TextAttribute#POSTURE |
35667 | 2306 |
* @return the angle of the ITALIC style of this {@code Font}. |
2 | 2307 |
*/ |
2308 |
public float getItalicAngle() { |
|
2309 |
return getItalicAngle(null); |
|
2310 |
} |
|
2311 |
||
2312 |
/* The FRC hints don't affect the value of the italic angle but |
|
2313 |
* we need to pass them in to look up a strike. |
|
2314 |
* If we can pass in ones already being used it can prevent an extra |
|
2315 |
* strike from being allocated. Note that since italic angle is |
|
2316 |
* a property of the font, the font transform is needed not the |
|
2317 |
* device transform. Finally, this is private but the only caller of this |
|
2318 |
* in the JDK - and the only likely caller - is in this same class. |
|
2319 |
*/ |
|
2320 |
private float getItalicAngle(FontRenderContext frc) { |
|
2321 |
Object aa, fm; |
|
2322 |
if (frc == null) { |
|
2323 |
aa = RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; |
|
2324 |
fm = RenderingHints.VALUE_FRACTIONALMETRICS_OFF; |
|
2325 |
} else { |
|
2326 |
aa = frc.getAntiAliasingHint(); |
|
2327 |
fm = frc.getFractionalMetricsHint(); |
|
2328 |
} |
|
547
ff9562f275ab
6694480: Two small inefficiencies in getting font strikes for transformed fonts
prr
parents:
534
diff
changeset
|
2329 |
return getFont2D().getItalicAngle(this, identityTx, aa, fm); |
2 | 2330 |
} |
2331 |
||
2332 |
/** |
|
35667 | 2333 |
* Checks whether or not this {@code Font} has uniform |
2334 |
* line metrics. A logical {@code Font} might be a |
|
2 | 2335 |
* composite font, which means that it is composed of different |
2336 |
* physical fonts to cover different code ranges. Each of these |
|
35667 | 2337 |
* fonts might have different {@code LineMetrics}. If the |
2338 |
* logical {@code Font} is a single |
|
2 | 2339 |
* font then the metrics would be uniform. |
35667 | 2340 |
* @return {@code true} if this {@code Font} has |
2341 |
* uniform line metrics; {@code false} otherwise. |
|
2 | 2342 |
*/ |
2343 |
public boolean hasUniformLineMetrics() { |
|
2344 |
return false; // REMIND always safe, but prevents caller optimize |
|
2345 |
} |
|
2346 |
||
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
2347 |
private transient SoftReference<FontLineMetrics> flmref; |
2 | 2348 |
private FontLineMetrics defaultLineMetrics(FontRenderContext frc) { |
2349 |
FontLineMetrics flm = null; |
|
2350 |
if (flmref == null |
|
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
2351 |
|| (flm = flmref.get()) == null |
2 | 2352 |
|| !flm.frc.equals(frc)) { |
2353 |
||
2354 |
/* The device transform in the frc is not used in obtaining line |
|
2355 |
* metrics, although it probably should be: REMIND find why not? |
|
2356 |
* The font transform is used but its applied in getFontMetrics, so |
|
2357 |
* just pass identity here |
|
2358 |
*/ |
|
2359 |
float [] metrics = new float[8]; |
|
2360 |
getFont2D().getFontMetrics(this, identityTx, |
|
2361 |
frc.getAntiAliasingHint(), |
|
2362 |
frc.getFractionalMetricsHint(), |
|
2363 |
metrics); |
|
2364 |
float ascent = metrics[0]; |
|
2365 |
float descent = metrics[1]; |
|
2366 |
float leading = metrics[2]; |
|
2367 |
float ssOffset = 0; |
|
2368 |
if (values != null && values.getSuperscript() != 0) { |
|
2369 |
ssOffset = (float)getTransform().getTranslateY(); |
|
2370 |
ascent -= ssOffset; |
|
2371 |
descent += ssOffset; |
|
2372 |
} |
|
2373 |
float height = ascent + descent + leading; |
|
2374 |
||
2375 |
int baselineIndex = 0; // need real index, assumes roman for everything |
|
2376 |
// need real baselines eventually |
|
2377 |
float[] baselineOffsets = { 0, (descent/2f - ascent) / 2f, -ascent }; |
|
2378 |
||
2379 |
float strikethroughOffset = metrics[4]; |
|
2380 |
float strikethroughThickness = metrics[5]; |
|
2381 |
||
2382 |
float underlineOffset = metrics[6]; |
|
2383 |
float underlineThickness = metrics[7]; |
|
2384 |
||
2385 |
float italicAngle = getItalicAngle(frc); |
|
2386 |
||
2387 |
if (isTransformed()) { |
|
2388 |
AffineTransform ctx = values.getCharTransform(); // extract rotation |
|
2389 |
if (ctx != null) { |
|
2390 |
Point2D.Float pt = new Point2D.Float(); |
|
2391 |
pt.setLocation(0, strikethroughOffset); |
|
2392 |
ctx.deltaTransform(pt, pt); |
|
2393 |
strikethroughOffset = pt.y; |
|
2394 |
pt.setLocation(0, strikethroughThickness); |
|
2395 |
ctx.deltaTransform(pt, pt); |
|
2396 |
strikethroughThickness = pt.y; |
|
2397 |
pt.setLocation(0, underlineOffset); |
|
2398 |
ctx.deltaTransform(pt, pt); |
|
2399 |
underlineOffset = pt.y; |
|
2400 |
pt.setLocation(0, underlineThickness); |
|
2401 |
ctx.deltaTransform(pt, pt); |
|
2402 |
underlineThickness = pt.y; |
|
2403 |
} |
|
2404 |
} |
|
2405 |
strikethroughOffset += ssOffset; |
|
2406 |
underlineOffset += ssOffset; |
|
2407 |
||
2408 |
CoreMetrics cm = new CoreMetrics(ascent, descent, leading, height, |
|
2409 |
baselineIndex, baselineOffsets, |
|
2410 |
strikethroughOffset, strikethroughThickness, |
|
2411 |
underlineOffset, underlineThickness, |
|
2412 |
ssOffset, italicAngle); |
|
2413 |
||
2414 |
flm = new FontLineMetrics(0, cm, frc); |
|
11270
d7b0b63bd082
7117334: Warnings cleanup day: reduce number of javac warnings in the java.awt package
bagiras
parents:
9035
diff
changeset
|
2415 |
flmref = new SoftReference<FontLineMetrics>(flm); |
2 | 2416 |
} |
2417 |
||
2418 |
return (FontLineMetrics)flm.clone(); |
|
2419 |
} |
|
2420 |
||
2421 |
/** |
|
2422 |
* Returns a {@link LineMetrics} object created with the specified |
|
35667 | 2423 |
* {@code String} and {@link FontRenderContext}. |
2424 |
* @param str the specified {@code String} |
|
2425 |
* @param frc the specified {@code FontRenderContext} |
|
2426 |
* @return a {@code LineMetrics} object created with the |
|
2427 |
* specified {@code String} and {@link FontRenderContext}. |
|
2 | 2428 |
*/ |
2429 |
public LineMetrics getLineMetrics( String str, FontRenderContext frc) { |
|
2430 |
FontLineMetrics flm = defaultLineMetrics(frc); |
|
2431 |
flm.numchars = str.length(); |
|
2432 |
return flm; |
|
2433 |
} |
|
2434 |
||
2435 |
/** |
|
35667 | 2436 |
* Returns a {@code LineMetrics} object created with the |
2 | 2437 |
* specified arguments. |
35667 | 2438 |
* @param str the specified {@code String} |
2439 |
* @param beginIndex the initial offset of {@code str} |
|
2440 |
* @param limit the end offset of {@code str} |
|
2441 |
* @param frc the specified {@code FontRenderContext} |
|
2442 |
* @return a {@code LineMetrics} object created with the |
|
2 | 2443 |
* specified arguments. |
2444 |
*/ |
|
2445 |
public LineMetrics getLineMetrics( String str, |
|
2446 |
int beginIndex, int limit, |
|
2447 |
FontRenderContext frc) { |
|
2448 |
FontLineMetrics flm = defaultLineMetrics(frc); |
|
2449 |
int numChars = limit - beginIndex; |
|
2450 |
flm.numchars = (numChars < 0)? 0: numChars; |
|
2451 |
return flm; |
|
2452 |
} |
|
2453 |
||
2454 |
/** |
|
35667 | 2455 |
* Returns a {@code LineMetrics} object created with the |
2 | 2456 |
* specified arguments. |
2457 |
* @param chars an array of characters |
|
35667 | 2458 |
* @param beginIndex the initial offset of {@code chars} |
2459 |
* @param limit the end offset of {@code chars} |
|
2460 |
* @param frc the specified {@code FontRenderContext} |
|
2461 |
* @return a {@code LineMetrics} object created with the |
|
2 | 2462 |
* specified arguments. |
2463 |
*/ |
|
2464 |
public LineMetrics getLineMetrics(char [] chars, |
|
2465 |
int beginIndex, int limit, |
|
2466 |
FontRenderContext frc) { |
|
2467 |
FontLineMetrics flm = defaultLineMetrics(frc); |
|
2468 |
int numChars = limit - beginIndex; |
|
2469 |
flm.numchars = (numChars < 0)? 0: numChars; |
|
2470 |
return flm; |
|
2471 |
} |
|
2472 |
||
2473 |
/** |
|
35667 | 2474 |
* Returns a {@code LineMetrics} object created with the |
2 | 2475 |
* specified arguments. |
35667 | 2476 |
* @param ci the specified {@code CharacterIterator} |
2477 |
* @param beginIndex the initial offset in {@code ci} |
|
2478 |
* @param limit the end offset of {@code ci} |
|
2479 |
* @param frc the specified {@code FontRenderContext} |
|
2480 |
* @return a {@code LineMetrics} object created with the |
|
2 | 2481 |
* specified arguments. |
2482 |
*/ |
|
2483 |
public LineMetrics getLineMetrics(CharacterIterator ci, |
|
2484 |
int beginIndex, int limit, |
|
2485 |
FontRenderContext frc) { |
|
2486 |
FontLineMetrics flm = defaultLineMetrics(frc); |
|
2487 |
int numChars = limit - beginIndex; |
|
2488 |
flm.numchars = (numChars < 0)? 0: numChars; |
|
2489 |
return flm; |
|
2490 |
} |
|
2491 |
||
2492 |
/** |
|
35667 | 2493 |
* Returns the logical bounds of the specified {@code String} in |
2494 |
* the specified {@code FontRenderContext}. The logical bounds |
|
2 | 2495 |
* contains the origin, ascent, advance, and height, which includes |
2496 |
* the leading. The logical bounds does not always enclose all the |
|
2497 |
* text. For example, in some languages and in some fonts, accent |
|
2498 |
* marks can be positioned above the ascent or below the descent. |
|
2499 |
* To obtain a visual bounding box, which encloses all the text, |
|
2500 |
* use the {@link TextLayout#getBounds() getBounds} method of |
|
35667 | 2501 |
* {@code TextLayout}. |
2 | 2502 |
* <p>Note: The returned bounds is in baseline-relative coordinates |
2503 |
* (see {@link java.awt.Font class notes}). |
|
35667 | 2504 |
* @param str the specified {@code String} |
2505 |
* @param frc the specified {@code FontRenderContext} |
|
2 | 2506 |
* @return a {@link Rectangle2D} that is the bounding box of the |
35667 | 2507 |
* specified {@code String} in the specified |
2508 |
* {@code FontRenderContext}. |
|
2 | 2509 |
* @see FontRenderContext |
2510 |
* @see Font#createGlyphVector |
|
2511 |
* @since 1.2 |
|
2512 |
*/ |
|
2513 |
public Rectangle2D getStringBounds( String str, FontRenderContext frc) { |
|
2514 |
char[] array = str.toCharArray(); |
|
2515 |
return getStringBounds(array, 0, array.length, frc); |
|
2516 |
} |
|
2517 |
||
2518 |
/** |
|
35667 | 2519 |
* Returns the logical bounds of the specified {@code String} in |
2520 |
* the specified {@code FontRenderContext}. The logical bounds |
|
2 | 2521 |
* contains the origin, ascent, advance, and height, which includes |
2522 |
* the leading. The logical bounds does not always enclose all the |
|
2523 |
* text. For example, in some languages and in some fonts, accent |
|
2524 |
* marks can be positioned above the ascent or below the descent. |
|
2525 |
* To obtain a visual bounding box, which encloses all the text, |
|
2526 |
* use the {@link TextLayout#getBounds() getBounds} method of |
|
35667 | 2527 |
* {@code TextLayout}. |
2 | 2528 |
* <p>Note: The returned bounds is in baseline-relative coordinates |
2529 |
* (see {@link java.awt.Font class notes}). |
|
35667 | 2530 |
* @param str the specified {@code String} |
2531 |
* @param beginIndex the initial offset of {@code str} |
|
2532 |
* @param limit the end offset of {@code str} |
|
2533 |
* @param frc the specified {@code FontRenderContext} |
|
2534 |
* @return a {@code Rectangle2D} that is the bounding box of the |
|
2535 |
* specified {@code String} in the specified |
|
2536 |
* {@code FontRenderContext}. |
|
2537 |
* @throws IndexOutOfBoundsException if {@code beginIndex} is |
|
2538 |
* less than zero, or {@code limit} is greater than the |
|
2539 |
* length of {@code str}, or {@code beginIndex} |
|
2540 |
* is greater than {@code limit}. |
|
2 | 2541 |
* @see FontRenderContext |
2542 |
* @see Font#createGlyphVector |
|
2543 |
* @since 1.2 |
|
2544 |
*/ |
|
2545 |
public Rectangle2D getStringBounds( String str, |
|
2546 |
int beginIndex, int limit, |
|
2547 |
FontRenderContext frc) { |
|
2548 |
String substr = str.substring(beginIndex, limit); |
|
2549 |
return getStringBounds(substr, frc); |
|
2550 |
} |
|
2551 |
||
2552 |
/** |
|
2553 |
* Returns the logical bounds of the specified array of characters |
|
35667 | 2554 |
* in the specified {@code FontRenderContext}. The logical |
2 | 2555 |
* bounds contains the origin, ascent, advance, and height, which |
2556 |
* includes the leading. The logical bounds does not always enclose |
|
2557 |
* all the text. For example, in some languages and in some fonts, |
|
2558 |
* accent marks can be positioned above the ascent or below the |
|
2559 |
* descent. To obtain a visual bounding box, which encloses all the |
|
2560 |
* text, use the {@link TextLayout#getBounds() getBounds} method of |
|
35667 | 2561 |
* {@code TextLayout}. |
2 | 2562 |
* <p>Note: The returned bounds is in baseline-relative coordinates |
2563 |
* (see {@link java.awt.Font class notes}). |
|
2564 |
* @param chars an array of characters |
|
2565 |
* @param beginIndex the initial offset in the array of |
|
2566 |
* characters |
|
2567 |
* @param limit the end offset in the array of characters |
|
35667 | 2568 |
* @param frc the specified {@code FontRenderContext} |
2569 |
* @return a {@code Rectangle2D} that is the bounding box of the |
|
2 | 2570 |
* specified array of characters in the specified |
35667 | 2571 |
* {@code FontRenderContext}. |
2572 |
* @throws IndexOutOfBoundsException if {@code beginIndex} is |
|
2573 |
* less than zero, or {@code limit} is greater than the |
|
2574 |
* length of {@code chars}, or {@code beginIndex} |
|
2575 |
* is greater than {@code limit}. |
|
2 | 2576 |
* @see FontRenderContext |
2577 |
* @see Font#createGlyphVector |
|
2578 |
* @since 1.2 |
|
2579 |
*/ |
|
2580 |
public Rectangle2D getStringBounds(char [] chars, |
|
2581 |
int beginIndex, int limit, |
|
2582 |
FontRenderContext frc) { |
|
2583 |
if (beginIndex < 0) { |
|
2584 |
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex); |
|
2585 |
} |
|
2586 |
if (limit > chars.length) { |
|
2587 |
throw new IndexOutOfBoundsException("limit: " + limit); |
|
2588 |
} |
|
2589 |
if (beginIndex > limit) { |
|
2590 |
throw new IndexOutOfBoundsException("range length: " + |
|
2591 |
(limit - beginIndex)); |
|
2592 |
} |
|
2593 |
||
2594 |
// this code should be in textlayout |
|
2595 |
// quick check for simple text, assume GV ok to use if simple |
|
2596 |
||
2597 |
boolean simple = values == null || |
|
2598 |
(values.getKerning() == 0 && values.getLigatures() == 0 && |
|
2599 |
values.getBaselineTransform() == null); |
|
2600 |
if (simple) { |
|
3928 | 2601 |
simple = ! FontUtilities.isComplexText(chars, beginIndex, limit); |
2 | 2602 |
} |
2603 |
||
2604 |
if (simple) { |
|
48285
7e8a0c4ee95e
8189809: Large performance regression in Swing text layout
prr
parents:
47216
diff
changeset
|
2605 |
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc); |
7e8a0c4ee95e
8189809: Large performance regression in Swing text layout
prr
parents:
47216
diff
changeset
|
2606 |
return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex); |
2 | 2607 |
} else { |
2608 |
// need char array constructor on textlayout |
|
2609 |
String str = new String(chars, beginIndex, limit - beginIndex); |
|
2610 |
TextLayout tl = new TextLayout(str, this, frc); |
|
2611 |
return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(), |
|
2612 |
tl.getAscent() + tl.getDescent() + |
|
2613 |
tl.getLeading()); |
|
2614 |
} |
|
2615 |
} |
|
2616 |
||
2617 |
/** |
|
2618 |
* Returns the logical bounds of the characters indexed in the |
|
2619 |
* specified {@link CharacterIterator} in the |
|
35667 | 2620 |
* specified {@code FontRenderContext}. The logical bounds |
2 | 2621 |
* contains the origin, ascent, advance, and height, which includes |
2622 |
* the leading. The logical bounds does not always enclose all the |
|
2623 |
* text. For example, in some languages and in some fonts, accent |
|
2624 |
* marks can be positioned above the ascent or below the descent. |
|
2625 |
* To obtain a visual bounding box, which encloses all the text, |
|
2626 |
* use the {@link TextLayout#getBounds() getBounds} method of |
|
35667 | 2627 |
* {@code TextLayout}. |
2 | 2628 |
* <p>Note: The returned bounds is in baseline-relative coordinates |
2629 |
* (see {@link java.awt.Font class notes}). |
|
35667 | 2630 |
* @param ci the specified {@code CharacterIterator} |
2631 |
* @param beginIndex the initial offset in {@code ci} |
|
2632 |
* @param limit the end offset in {@code ci} |
|
2633 |
* @param frc the specified {@code FontRenderContext} |
|
2634 |
* @return a {@code Rectangle2D} that is the bounding box of the |
|
2635 |
* characters indexed in the specified {@code CharacterIterator} |
|
2636 |
* in the specified {@code FontRenderContext}. |
|
2 | 2637 |
* @see FontRenderContext |
2638 |
* @see Font#createGlyphVector |
|
2639 |
* @since 1.2 |
|
35667 | 2640 |
* @throws IndexOutOfBoundsException if {@code beginIndex} is |
2641 |
* less than the start index of {@code ci}, or |
|
2642 |
* {@code limit} is greater than the end index of |
|
2643 |
* {@code ci}, or {@code beginIndex} is greater |
|
2644 |
* than {@code limit} |
|
2 | 2645 |
*/ |
2646 |
public Rectangle2D getStringBounds(CharacterIterator ci, |
|
2647 |
int beginIndex, int limit, |
|
2648 |
FontRenderContext frc) { |
|
2649 |
int start = ci.getBeginIndex(); |
|
2650 |
int end = ci.getEndIndex(); |
|
2651 |
||
2652 |
if (beginIndex < start) { |
|
2653 |
throw new IndexOutOfBoundsException("beginIndex: " + beginIndex); |
|
2654 |
} |
|
2655 |
if (limit > end) { |
|
2656 |
throw new IndexOutOfBoundsException("limit: " + limit); |
|
2657 |
} |
|
2658 |
if (beginIndex > limit) { |
|
2659 |
throw new IndexOutOfBoundsException("range length: " + |
|
2660 |
(limit - beginIndex)); |
|
2661 |
} |
|
2662 |
||
2663 |
char[] arr = new char[limit - beginIndex]; |
|
2664 |
||
2665 |
ci.setIndex(beginIndex); |
|
2666 |
for(int idx = 0; idx < arr.length; idx++) { |
|
2667 |
arr[idx] = ci.current(); |
|
2668 |
ci.next(); |
|
2669 |
} |
|
2670 |
||
2671 |
return getStringBounds(arr,0,arr.length,frc); |
|
2672 |
} |
|
2673 |
||
2674 |
/** |
|
2675 |
* Returns the bounds for the character with the maximum |
|
35667 | 2676 |
* bounds as defined in the specified {@code FontRenderContext}. |
2 | 2677 |
* <p>Note: The returned bounds is in baseline-relative coordinates |
2678 |
* (see {@link java.awt.Font class notes}). |
|
35667 | 2679 |
* @param frc the specified {@code FontRenderContext} |
2680 |
* @return a {@code Rectangle2D} that is the bounding box |
|
2 | 2681 |
* for the character with the maximum bounds. |
2682 |
*/ |
|
2683 |
public Rectangle2D getMaxCharBounds(FontRenderContext frc) { |
|
2684 |
float [] metrics = new float[4]; |
|
2685 |
||
2686 |
getFont2D().getFontMetrics(this, frc, metrics); |
|
2687 |
||
2688 |
return new Rectangle2D.Float(0, -metrics[0], |
|
2689 |
metrics[3], |
|
2690 |
metrics[0] + metrics[1] + metrics[2]); |
|
2691 |
} |
|
2692 |
||
2693 |
/** |
|
2694 |
* Creates a {@link java.awt.font.GlyphVector GlyphVector} by |
|
2695 |
* mapping characters to glyphs one-to-one based on the |
|
35667 | 2696 |
* Unicode cmap in this {@code Font}. This method does no other |
2 | 2697 |
* processing besides the mapping of glyphs to characters. This |
2698 |
* means that this method is not useful for some scripts, such |
|
2699 |
* as Arabic, Hebrew, Thai, and Indic, that require reordering, |
|
2700 |
* shaping, or ligature substitution. |
|
35667 | 2701 |
* @param frc the specified {@code FontRenderContext} |
2702 |
* @param str the specified {@code String} |
|
2703 |
* @return a new {@code GlyphVector} created with the |
|
2704 |
* specified {@code String} and the specified |
|
2705 |
* {@code FontRenderContext}. |
|
2 | 2706 |
*/ |
2707 |
public GlyphVector createGlyphVector(FontRenderContext frc, String str) |
|
2708 |
{ |
|
2709 |
return (GlyphVector)new StandardGlyphVector(this, str, frc); |
|
2710 |
} |
|
2711 |
||
2712 |
/** |
|
2713 |
* Creates a {@link java.awt.font.GlyphVector GlyphVector} by |
|
2714 |
* mapping characters to glyphs one-to-one based on the |
|
35667 | 2715 |
* Unicode cmap in this {@code Font}. This method does no other |
2 | 2716 |
* processing besides the mapping of glyphs to characters. This |
2717 |
* means that this method is not useful for some scripts, such |
|
2718 |
* as Arabic, Hebrew, Thai, and Indic, that require reordering, |
|
2719 |
* shaping, or ligature substitution. |
|
35667 | 2720 |
* @param frc the specified {@code FontRenderContext} |
2 | 2721 |
* @param chars the specified array of characters |
35667 | 2722 |
* @return a new {@code GlyphVector} created with the |
2 | 2723 |
* specified array of characters and the specified |
35667 | 2724 |
* {@code FontRenderContext}. |
2 | 2725 |
*/ |
2726 |
public GlyphVector createGlyphVector(FontRenderContext frc, char[] chars) |
|
2727 |
{ |
|
2728 |
return (GlyphVector)new StandardGlyphVector(this, chars, frc); |
|
2729 |
} |
|
2730 |
||
2731 |
/** |
|
2732 |
* Creates a {@link java.awt.font.GlyphVector GlyphVector} by |
|
2733 |
* mapping the specified characters to glyphs one-to-one based on the |
|
35667 | 2734 |
* Unicode cmap in this {@code Font}. This method does no other |
2 | 2735 |
* processing besides the mapping of glyphs to characters. This |
2736 |
* means that this method is not useful for some scripts, such |
|
2737 |
* as Arabic, Hebrew, Thai, and Indic, that require reordering, |
|
2738 |
* shaping, or ligature substitution. |
|
35667 | 2739 |
* @param frc the specified {@code FontRenderContext} |
2740 |
* @param ci the specified {@code CharacterIterator} |
|
2741 |
* @return a new {@code GlyphVector} created with the |
|
2742 |
* specified {@code CharacterIterator} and the specified |
|
2743 |
* {@code FontRenderContext}. |
|
2 | 2744 |
*/ |
2745 |
public GlyphVector createGlyphVector( FontRenderContext frc, |
|
2746 |
CharacterIterator ci) |
|
2747 |
{ |
|
2748 |
return (GlyphVector)new StandardGlyphVector(this, ci, frc); |
|
2749 |
} |
|
2750 |
||
2751 |
/** |
|
2752 |
* Creates a {@link java.awt.font.GlyphVector GlyphVector} by |
|
2753 |
* mapping characters to glyphs one-to-one based on the |
|
35667 | 2754 |
* Unicode cmap in this {@code Font}. This method does no other |
2 | 2755 |
* processing besides the mapping of glyphs to characters. This |
2756 |
* means that this method is not useful for some scripts, such |
|
2757 |
* as Arabic, Hebrew, Thai, and Indic, that require reordering, |
|
2758 |
* shaping, or ligature substitution. |
|
35667 | 2759 |
* @param frc the specified {@code FontRenderContext} |
2 | 2760 |
* @param glyphCodes the specified integer array |
35667 | 2761 |
* @return a new {@code GlyphVector} created with the |
2 | 2762 |
* specified integer array and the specified |
35667 | 2763 |
* {@code FontRenderContext}. |
2 | 2764 |
*/ |
2765 |
public GlyphVector createGlyphVector( FontRenderContext frc, |
|
2766 |
int [] glyphCodes) |
|
2767 |
{ |
|
2768 |
return (GlyphVector)new StandardGlyphVector(this, glyphCodes, frc); |
|
2769 |
} |
|
2770 |
||
2771 |
/** |
|
35667 | 2772 |
* Returns a new {@code GlyphVector} object, performing full |
2 | 2773 |
* layout of the text if possible. Full layout is required for |
2774 |
* complex text, such as Arabic or Hindi. Support for different |
|
2775 |
* scripts depends on the font and implementation. |
|
2776 |
* <p> |
|
2777 |
* Layout requires bidi analysis, as performed by |
|
35667 | 2778 |
* {@code Bidi}, and should only be performed on text that |
2 | 2779 |
* has a uniform direction. The direction is indicated in the |
2780 |
* flags parameter,by using LAYOUT_RIGHT_TO_LEFT to indicate a |
|
2781 |
* right-to-left (Arabic and Hebrew) run direction, or |
|
2782 |
* LAYOUT_LEFT_TO_RIGHT to indicate a left-to-right (English) |
|
2783 |
* run direction. |
|
2784 |
* <p> |
|
2785 |
* In addition, some operations, such as Arabic shaping, require |
|
2786 |
* context, so that the characters at the start and limit can have |
|
2787 |
* the proper shapes. Sometimes the data in the buffer outside |
|
2788 |
* the provided range does not have valid data. The values |
|
2789 |
* LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be |
|
2790 |
* added to the flags parameter to indicate that the text before |
|
2791 |
* start, or after limit, respectively, should not be examined |
|
2792 |
* for context. |
|
2793 |
* <p> |
|
2794 |
* All other values for the flags parameter are reserved. |
|
2795 |
* |
|
35667 | 2796 |
* @param frc the specified {@code FontRenderContext} |
2 | 2797 |
* @param text the text to layout |
35667 | 2798 |
* @param start the start of the text to use for the {@code GlyphVector} |
2799 |
* @param limit the limit of the text to use for the {@code GlyphVector} |
|
2 | 2800 |
* @param flags control flags as described above |
35667 | 2801 |
* @return a new {@code GlyphVector} representing the text between |
2 | 2802 |
* start and limit, with glyphs chosen and positioned so as to best represent |
2803 |
* the text |
|
2804 |
* @throws ArrayIndexOutOfBoundsException if start or limit is |
|
2805 |
* out of bounds |
|
2806 |
* @see java.text.Bidi |
|
2807 |
* @see #LAYOUT_LEFT_TO_RIGHT |
|
2808 |
* @see #LAYOUT_RIGHT_TO_LEFT |
|
2809 |
* @see #LAYOUT_NO_START_CONTEXT |
|
2810 |
* @see #LAYOUT_NO_LIMIT_CONTEXT |
|
2811 |
* @since 1.4 |
|
2812 |
*/ |
|
2813 |
public GlyphVector layoutGlyphVector(FontRenderContext frc, |
|
2814 |
char[] text, |
|
2815 |
int start, |
|
2816 |
int limit, |
|
2817 |
int flags) { |
|
2818 |
||
2819 |
GlyphLayout gl = GlyphLayout.get(null); // !!! no custom layout engines |
|
2820 |
StandardGlyphVector gv = gl.layout(this, frc, text, |
|
2821 |
start, limit-start, flags, null); |
|
2822 |
GlyphLayout.done(gl); |
|
2823 |
return gv; |
|
2824 |
} |
|
2825 |
||
2826 |
/** |
|
2827 |
* A flag to layoutGlyphVector indicating that text is left-to-right as |
|
2828 |
* determined by Bidi analysis. |
|
2829 |
*/ |
|
2830 |
public static final int LAYOUT_LEFT_TO_RIGHT = 0; |
|
2831 |
||
2832 |
/** |
|
2833 |
* A flag to layoutGlyphVector indicating that text is right-to-left as |
|
2834 |
* determined by Bidi analysis. |
|
2835 |
*/ |
|
2836 |
public static final int LAYOUT_RIGHT_TO_LEFT = 1; |
|
2837 |
||
2838 |
/** |
|
2839 |
* A flag to layoutGlyphVector indicating that text in the char array |
|
2840 |
* before the indicated start should not be examined. |
|
2841 |
*/ |
|
2842 |
public static final int LAYOUT_NO_START_CONTEXT = 2; |
|
2843 |
||
2844 |
/** |
|
2845 |
* A flag to layoutGlyphVector indicating that text in the char array |
|
2846 |
* after the indicated limit should not be examined. |
|
2847 |
*/ |
|
2848 |
public static final int LAYOUT_NO_LIMIT_CONTEXT = 4; |
|
2849 |
||
2850 |
||
2851 |
private static void applyTransform(AffineTransform trans, AttributeValues values) { |
|
2852 |
if (trans == null) { |
|
2853 |
throw new IllegalArgumentException("transform must not be null"); |
|
2854 |
} |
|
2855 |
values.setTransform(trans); |
|
2856 |
} |
|
2857 |
||
2858 |
private static void applyStyle(int style, AttributeValues values) { |
|
2859 |
// WEIGHT_BOLD, WEIGHT_REGULAR |
|
2860 |
values.setWeight((style & BOLD) != 0 ? 2f : 1f); |
|
2861 |
// POSTURE_OBLIQUE, POSTURE_REGULAR |
|
2862 |
values.setPosture((style & ITALIC) != 0 ? .2f : 0f); |
|
2863 |
} |
|
2864 |
||
2865 |
/* |
|
2866 |
* Initialize JNI field and method IDs |
|
2867 |
*/ |
|
2868 |
private static native void initIDs(); |
|
2869 |
} |