1 package com
.intellij
.openapi
.editor
.impl
;
3 import gnu
.trove
.TIntHashSet
;
11 public class FontInfo
{
12 private final String myFamilyName
;
13 private final Font myFont
;
14 private final int mySize
;
15 private final int myStyle
;
16 private final TIntHashSet mySafeCharacters
= new TIntHashSet();
17 private FontMetrics myFontMetrics
= null;
18 private final int[] charWidth
= new int[128];
20 public FontInfo(final String familyName
, final int size
, final int style
) {
21 myFamilyName
= familyName
;
24 myFont
= new Font(familyName
, style
, size
);
27 public boolean canDisplay(char c
) {
29 if (c
< 128) return true;
30 if (mySafeCharacters
.contains(c
)) return true;
31 if (myFont
.canDisplay(c
)) {
32 mySafeCharacters
.add(c
);
38 // JRE has problems working with the font. Just skip.
43 public Font
getFont() {
47 public int charWidth(char c
, JComponent anyComponent
) {
48 final FontMetrics metrics
= fontMetrics(anyComponent
);
49 if (c
< 128) return charWidth
[c
];
50 return metrics
.charWidth(c
);
53 private FontMetrics
fontMetrics(JComponent anyComponent
) {
54 if (myFontMetrics
== null) {
55 myFontMetrics
= anyComponent
.getFontMetrics(myFont
);
56 for (int i
= 0; i
< 128; i
++) {
57 charWidth
[i
] = myFontMetrics
.charWidth(i
);
63 public int getSize() {
67 public int getStyle() {