Skip to content

Commit 1704d94

Browse files
committed
back-art: FTFontInfo: convert FreeType static variables into and instance variables. Initialize them in -initWithFontName:matrix:screenFont:. Should fix issue #448.
1 parent 69da92a commit 1704d94

File tree

2 files changed

+78
-71
lines changed

2 files changed

+78
-71
lines changed

Libraries/gnustep/back-art/Source/art/FTFontInfo.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@
103103

104104
@interface FTFontInfo : GSFontInfo <FTFontInfo>
105105
{
106-
@public
106+
FT_Library ft_library;
107+
FTC_Manager ftc_manager;
108+
FTC_ImageCache ftc_imagecache;
109+
FTC_SBitCache ftc_sbitcache;
110+
FTC_CMapCache ftc_cmapcache;
111+
112+
@public
107113
int pix_width, pix_height;
108114

109115
FTC_FaceID faceId;

Libraries/gnustep/back-art/Source/art/FTFontInfo.m

+71-70
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@
7171
@interface FTFontInfo_subpixel : FTFontInfo
7272
@end
7373

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-
8074
/*
8175
* Helper method used inside of FTC_Manager to create an FT_FACE.
8276
*/
@@ -110,6 +104,74 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
110104

111105
@implementation FTFontInfo
112106

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+
113175
- (id)initWithFontName:(NSString *)name
114176
matrix:(const CGFloat *)fmatrix
115177
screenFont:(BOOL)p_screenFont
@@ -127,6 +189,9 @@ - (id)initWithFontName:(NSString *)name
127189
if (!self)
128190
return nil;
129191

192+
[self _initFontCaches];
193+
[self _initFontFilters];
194+
130195
screenFont = p_screenFont;
131196

132197
NSDebugLLog(@"ftfont", @"[%@ -initWithFontName: %@ matrix: (%g %g %g %g %g %g)] %i", self, name,
@@ -1884,70 +1949,6 @@ - (void)appendBezierPathWithGlyphs:(NSGlyph *)glyphs
18841949
}
18851950
}
18861951

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-
19511952
- (NSGlyph)glyphForCharacter:(unichar)ch
19521953
{
19531954
NSGlyph g;

0 commit comments

Comments
 (0)