361 * The method currently assumes that only the size and style attributes
362 * are set on the specified font. It doesn't copy the font transform or
363 * other attributes because they aren't set on a font created from
364 * the desktop. This will need to be fixed if use is broadened.
365 *
366 * Operations such as Font.deriveFont will work properly on the
367 * font returned by this method for deriving a different point size.
368 * Additionally it tries to support a different style by calling
369 * getNewComposite() below. That also supports replacing slot zero
370 * with a different physical font but that is expected to be "rare".
371 * Deriving with a different style is needed because its been shown
372 * that some applications try to do this for Swing FontUIResources.
373 * Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14);
374 * will NOT yield the same result, as the new underlying CompositeFont
375 * cannot be "looked up" in the font registry.
376 * This returns a FontUIResource as that is the Font sub-class needed
377 * by Swing.
378 * Suggested usage is something like :
379 * FontUIResource fuir;
380 * Font desktopFont = getDesktopFont(..);
381 * // NOTE even if fontSupportsDefaultEncoding returns true because
382 * // you get Tahoma and are running in an English locale, you may
383 * // still want to just call getCompositeFontUIResource() anyway
384 * // as only then will you get fallback fonts - eg for CJK.
385 * if (FontManager.fontSupportsDefaultEncoding(desktopFont)) {
386 * fuir = new FontUIResource(..);
387 * } else {
388 * fuir = FontManager.getCompositeFontUIResource(desktopFont);
389 * }
390 * return fuir;
391 */
392 private static volatile
393 SoftReference<ConcurrentHashMap<PhysicalFont, CompositeFont>>
394 compMapRef = new SoftReference<>(null);
395
396 public static FontUIResource getCompositeFontUIResource(Font font) {
397
398 FontUIResource fuir = new FontUIResource(font);
399 Font2D font2D = FontUtilities.getFont2D(font);
400
401 if (!(font2D instanceof PhysicalFont)) {
402 /* Swing should only be calling this when a font is obtained
403 * from desktop properties, so should generally be a physical font,
404 * an exception might be for names like "MS Serif" which are
405 * automatically mapped to "Serif", so there's no need to do
406 * anything special in that case. But note that suggested usage
|
361 * The method currently assumes that only the size and style attributes
362 * are set on the specified font. It doesn't copy the font transform or
363 * other attributes because they aren't set on a font created from
364 * the desktop. This will need to be fixed if use is broadened.
365 *
366 * Operations such as Font.deriveFont will work properly on the
367 * font returned by this method for deriving a different point size.
368 * Additionally it tries to support a different style by calling
369 * getNewComposite() below. That also supports replacing slot zero
370 * with a different physical font but that is expected to be "rare".
371 * Deriving with a different style is needed because its been shown
372 * that some applications try to do this for Swing FontUIResources.
373 * Also operations such as new Font(font.getFontName(..), Font.PLAIN, 14);
374 * will NOT yield the same result, as the new underlying CompositeFont
375 * cannot be "looked up" in the font registry.
376 * This returns a FontUIResource as that is the Font sub-class needed
377 * by Swing.
378 * Suggested usage is something like :
379 * FontUIResource fuir;
380 * Font desktopFont = getDesktopFont(..);
381 * if (FontManager.fontSupportsDefaultEncoding(desktopFont)) {
382 * fuir = new FontUIResource(desktopFont);
383 * } else {
384 * fuir = FontManager.getCompositeFontUIResource(desktopFont);
385 * }
386 * return fuir;
387 */
388 private static volatile
389 SoftReference<ConcurrentHashMap<PhysicalFont, CompositeFont>>
390 compMapRef = new SoftReference<>(null);
391
392 public static FontUIResource getCompositeFontUIResource(Font font) {
393
394 FontUIResource fuir = new FontUIResource(font);
395 Font2D font2D = FontUtilities.getFont2D(font);
396
397 if (!(font2D instanceof PhysicalFont)) {
398 /* Swing should only be calling this when a font is obtained
399 * from desktop properties, so should generally be a physical font,
400 * an exception might be for names like "MS Serif" which are
401 * automatically mapped to "Serif", so there's no need to do
402 * anything special in that case. But note that suggested usage
|