2929import java .awt .geom .Point2D ;
3030import java .awt .geom .Rectangle2D ;
3131import java .lang .ref .WeakReference ;
32- import java .lang .reflect .Constructor ;
3332
3433import sun .java2d .Disposer ;
3534import sun .java2d .DisposerRecord ;
8281public abstract class FontScaler implements DisposerRecord {
8382
8483 private static FontScaler nullScaler = null ;
85- private static Constructor <? extends FontScaler > scalerConstructor = null ;
8684
8785 //Find preferred font scaler
8886 //
8987 //NB: we can allow property based preferences
9088 // (theoretically logic can be font type specific)
91- static {
92- Class <? extends FontScaler > scalerClass = null ;
93- Class <?>[] arglst = new Class <?>[] {Font2D .class , int .class ,
94- boolean .class , int .class };
95-
96- try {
97- @ SuppressWarnings ("unchecked" )
98- Class <? extends FontScaler > tmp = (Class <? extends FontScaler >)
99- ((!FontUtilities .useT2K && !FontUtilities .useLegacy ) ?
100- Class .forName ("sun.font.FreetypeFontScaler" ) :
101- Class .forName ("sun.font.T2KFontScaler" ));
102- scalerClass = tmp ;
103- } catch (ClassNotFoundException e ) {
104- try {
105- @ SuppressWarnings ("unchecked" )
106- Class <? extends FontScaler > tmp = (Class <? extends FontScaler >)
107- Class .forName ("sun.font.FreetypeFontScaler" );
108- scalerClass = tmp ;
109- } catch (ClassNotFoundException e1 ) {
110- scalerClass = NullFontScaler .class ;
111- }
112- } finally {
113- if (FontUtilities .debugFonts ()) {
114- System .out .println ("Scaler class=" +scalerClass );
115- }
116- }
117-
118- //NB: rewrite using factory? constructor is ugly way
119- try {
120- scalerConstructor = scalerClass .getConstructor (arglst );
121- } catch (NoSuchMethodException e ) {
122- //should not happen
123- }
124- }
12589
12690 /* This is the only place to instantiate new FontScaler.
12791 * Therefore this is very convinient place to register
128- * scaler with Disposer as well as trigger deregistring bad font
129- * in case when scaler reports this.
92+ * scaler with Disposer as well as trigger deregistering a bad font
93+ * when the scaler reports this.
13094 */
13195 public static FontScaler getScaler (Font2D font ,
13296 int indexInCollection ,
@@ -135,14 +99,13 @@ public static FontScaler getScaler(Font2D font,
13599 FontScaler scaler = null ;
136100
137101 try {
138- Object args [] = new Object [] {font , indexInCollection ,
139- supportsCJK , filesize };
140- scaler = scalerConstructor .newInstance (args );
102+ scaler = new FreetypeFontScaler (font , indexInCollection ,
103+ supportsCJK , filesize );
141104 Disposer .addObjectRecord (font , scaler );
142105 } catch (Throwable e ) {
143- scaler = nullScaler ;
106+ scaler = getNullScaler () ;
144107
145- //if we can not instantiate scaler assume bad font
108+ //if we can not instantiate scaler assume a bad font
146109 //NB: technically it could be also because of internal scaler
147110 // error but here we are assuming scaler is ok.
148111 FontManager fm = FontManagerFactory .getInstance ();
0 commit comments