71
71
@interface FTFontInfo_subpixel : FTFontInfo
72
72
@end
73
73
74
- static FT_Library ft_library;
75
- static FTC_Manager ftc_manager;
76
- static FTC_ImageCache ftc_imagecache;
77
- static FTC_SBitCache ftc_sbitcache;
78
- static FTC_CMapCache ftc_cmapcache;
79
-
80
74
/*
81
75
* Helper method used inside of FTC_Manager to create an FT_FACE.
82
76
*/
@@ -110,6 +104,74 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
110
104
111
105
@implementation FTFontInfo
112
106
107
+ static int filters[3 ][7 ] = {{0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
108
+ 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 },
109
+ {0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
110
+ 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 },
111
+ {0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
112
+ 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 }};
113
+
114
+ + (void )initializeBackend
115
+ {
116
+ [GSFontEnumerator setDefaultClass: [FTFontEnumerator class ]];
117
+ [GSFontInfo setDefaultClass: [FTFontInfo class ]];
118
+ }
119
+
120
+ - (void )_initFontCaches
121
+ {
122
+ if (FT_Init_FreeType (&ft_library))
123
+ NSLog (@" FT_Init_FreeType failed" );
124
+ if (FTC_Manager_New (ft_library, 0 , 0 , 4096 * 24 , ft_get_face, 0 , &ftc_manager))
125
+ NSLog (@" FTC_Manager_New failed" );
126
+ if (FTC_SBitCache_New (ftc_manager, &ftc_sbitcache))
127
+ NSLog (@" FTC_SBitCache_New failed" );
128
+ if (FTC_ImageCache_New (ftc_manager, &ftc_imagecache))
129
+ NSLog (@" FTC_ImageCache_New failed" );
130
+ if (FTC_CMapCache_New (ftc_manager, &ftc_cmapcache))
131
+ NSLog (@" FTC_CMapCache_New failed" );
132
+ }
133
+
134
+ - (void )_initFontFilters
135
+ {
136
+ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults ];
137
+ NSString *s;
138
+ NSArray *a;
139
+ int i;
140
+
141
+ subpixel_text = [ud integerForKey: @" back-art-subpixel-text" ];
142
+
143
+ /* To make it easier to find an optimal (or at least good) filter,
144
+ the filters are configurable (for now). */
145
+ for (i = 0 ; i < 3 ; i++) {
146
+ s = [ud stringForKey: [NSString stringWithFormat: @" back-art-subpixel-filter-%i " , i]];
147
+ if (s) {
148
+ int j, c, sum, v;
149
+ a = [s componentsSeparatedByString: @" " ];
150
+ c = [a count ];
151
+ if (!c)
152
+ continue ;
153
+ if (!(c & 1 ) || c > 7 ) {
154
+ NSLog (@" invalid number of components in filter (must be odd number, 1<=n<=7)" );
155
+ continue ;
156
+ }
157
+ memset (filters[i], 0 , sizeof (filters[0 ]));
158
+ sum = 0 ;
159
+ for (j = 0 ; j < c; j++) {
160
+ v = [[a objectAtIndex: j] intValue ];
161
+ sum += v;
162
+ filters[i][j + (7 - c) / 2 ] = v * 65536 ;
163
+ }
164
+ if (sum) {
165
+ for (j = 0 ; j < 7 ; j++) {
166
+ filters[i][j] /= sum;
167
+ }
168
+ }
169
+ NSLog (@" filter %i : %04x %04x %04x %04x %04x %04x %04x " , i, filters[i][0 ], filters[i][1 ],
170
+ filters[i][2 ], filters[i][3 ], filters[i][4 ], filters[i][5 ], filters[i][6 ]);
171
+ }
172
+ }
173
+ }
174
+
113
175
- (id )initWithFontName : (NSString *)name
114
176
matrix : (const CGFloat *)fmatrix
115
177
screenFont : (BOOL )p_screenFont
@@ -127,6 +189,9 @@ - (id)initWithFontName:(NSString *)name
127
189
if (!self)
128
190
return nil ;
129
191
192
+ [self _initFontCaches ];
193
+ [self _initFontFilters ];
194
+
130
195
screenFont = p_screenFont;
131
196
132
197
NSDebugLLog (@" ftfont" , @" [%@ -initWithFontName: %@ matrix: (%g %g %g %g %g %g )] %i " , self, name,
@@ -1884,70 +1949,6 @@ - (void)appendBezierPathWithGlyphs:(NSGlyph *)glyphs
1884
1949
}
1885
1950
}
1886
1951
1887
- static int filters[3 ][7 ] = {{0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
1888
- 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 },
1889
- {0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
1890
- 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 },
1891
- {0 * 65536 / 9 , 1 * 65536 / 9 , 2 * 65536 / 9 , 3 * 65536 / 9 ,
1892
- 2 * 65536 / 9 , 1 * 65536 / 9 , 0 * 65536 / 9 }};
1893
-
1894
- + (void )initializeBackend
1895
- {
1896
- [GSFontEnumerator setDefaultClass: [FTFontEnumerator class ]];
1897
- [GSFontInfo setDefaultClass: [FTFontInfo class ]];
1898
-
1899
- if (FT_Init_FreeType (&ft_library))
1900
- NSLog (@" FT_Init_FreeType failed" );
1901
- if (FTC_Manager_New (ft_library, 0 , 0 , 4096 * 24 , ft_get_face, 0 , &ftc_manager))
1902
- NSLog (@" FTC_Manager_New failed" );
1903
- if (FTC_SBitCache_New (ftc_manager, &ftc_sbitcache))
1904
- NSLog (@" FTC_SBitCache_New failed" );
1905
- if (FTC_ImageCache_New (ftc_manager, &ftc_imagecache))
1906
- NSLog (@" FTC_ImageCache_New failed" );
1907
- if (FTC_CMapCache_New (ftc_manager, &ftc_cmapcache))
1908
- NSLog (@" FTC_CMapCache_New failed" );
1909
-
1910
- {
1911
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults ];
1912
- NSString *s;
1913
- NSArray *a;
1914
- int i;
1915
-
1916
- subpixel_text = [ud integerForKey: @" back-art-subpixel-text" ];
1917
-
1918
- /* To make it easier to find an optimal (or at least good) filter,
1919
- the filters are configurable (for now). */
1920
- for (i = 0 ; i < 3 ; i++) {
1921
- s = [ud stringForKey: [NSString stringWithFormat: @" back-art-subpixel-filter-%i " , i]];
1922
- if (s) {
1923
- int j, c, sum, v;
1924
- a = [s componentsSeparatedByString: @" " ];
1925
- c = [a count ];
1926
- if (!c)
1927
- continue ;
1928
- if (!(c & 1 ) || c > 7 ) {
1929
- NSLog (@" invalid number of components in filter (must be odd number, 1<=n<=7)" );
1930
- continue ;
1931
- }
1932
- memset (filters[i], 0 , sizeof (filters[0 ]));
1933
- sum = 0 ;
1934
- for (j = 0 ; j < c; j++) {
1935
- v = [[a objectAtIndex: j] intValue ];
1936
- sum += v;
1937
- filters[i][j + (7 - c) / 2 ] = v * 65536 ;
1938
- }
1939
- if (sum) {
1940
- for (j = 0 ; j < 7 ; j++) {
1941
- filters[i][j] /= sum;
1942
- }
1943
- }
1944
- NSLog (@" filter %i : %04x %04x %04x %04x %04x %04x %04x " , i, filters[i][0 ], filters[i][1 ],
1945
- filters[i][2 ], filters[i][3 ], filters[i][4 ], filters[i][5 ], filters[i][6 ]);
1946
- }
1947
- }
1948
- }
1949
- }
1950
-
1951
1952
- (NSGlyph )glyphForCharacter : (unichar )ch
1952
1953
{
1953
1954
NSGlyph g;
0 commit comments