OLD | NEW |
---|---|
1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp | 1 /* libs/graphics/ports/SkFontHost_fontconfig_direct.cpp |
2 ** | 2 ** |
3 ** Copyright 2009, Google Inc. | 3 ** Copyright 2009, Google Inc. |
4 ** | 4 ** |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
6 ** you may not use this file except in compliance with the License. | 6 ** you may not use this file except in compliance with the License. |
7 ** You may obtain a copy of the License at | 7 ** You may obtain a copy of the License at |
8 ** | 8 ** |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
10 ** | 10 ** |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Equivalence classes, used to match the Liberation and Ascender fonts | 29 // Equivalence classes, used to match the Liberation and Ascender fonts |
30 // with their metric-compatible replacements. See the discussion in | 30 // with their metric-compatible replacements. See the discussion in |
31 // GetFontEquivClass(). | 31 // GetFontEquivClass(). |
32 enum FontEquivClass | 32 enum FontEquivClass |
33 { | 33 { |
34 OTHER, | 34 OTHER, |
35 SANS, | 35 SANS, |
36 SERIF | 36 SERIF, |
37 MONO | |
37 }; | 38 }; |
38 | 39 |
39 // Match the font name against a whilelist of fonts, returning the equivalence | 40 // Match the font name against a whilelist of fonts, returning the equivalence |
40 // class. | 41 // class. |
41 FontEquivClass GetFontEquivClass(const char* fontname) | 42 FontEquivClass GetFontEquivClass(const char* fontname) |
42 { | 43 { |
43 // It would be nice for fontconfig to tell us whether a given suggested | 44 // It would be nice for fontconfig to tell us whether a given suggested |
44 // replacement is a "strong" match (that is, an equivalent font) or | 45 // replacement is a "strong" match (that is, an equivalent font) or |
45 // a "weak" match (that is, fontconfig's next-best attempt at finding a | 46 // a "weak" match (that is, fontconfig's next-best attempt at finding a |
46 // substitute). However, I played around with the fontconfig API for | 47 // substitute). However, I played around with the fontconfig API for |
47 // a good few hours and could not make it reveal this information. | 48 // a good few hours and could not make it reveal this information. |
48 // | 49 // |
49 // So instead, we hardcode. Initially this function emulated | 50 // So instead, we hardcode. Initially this function emulated |
50 // /etc/fonts/conf.d/30-metric-aliases.conf | 51 // /etc/fonts/conf.d/30-metric-aliases.conf |
51 // from my Ubuntu system, but we're better off being very conservative. | 52 // from my Ubuntu system, but we're better off being very conservative. |
52 | 53 |
53 // "Ascender Sans" and "Ascender Serif" are the tentative names of | 54 // "Ascender Sans", "Ascender Serif" and "Ascender Sans Mono" are the |
54 // another set of fonts metric-compatible with Arial and Times New Roman | 55 // tentative names of another set of fonts metric-compatible with |
55 // with a character repertoire much larger than Liberation. | 56 // Arial, Times New Roman and Courier New with a character repertoire |
Evan Martin
2010/06/14 23:08:55
nit: you have an extra space before "with"
| |
57 // much larger than Liberation. Note that Ascender Sans Mono/Liberation | |
58 // Sans Mono are metrically compatible with Courier New, but the former | |
59 // is sans-serif while ther latter is serif. | |
56 if (strcasecmp(fontname, "Arial") == 0 || | 60 if (strcasecmp(fontname, "Arial") == 0 || |
57 strcasecmp(fontname, "Liberation Sans") == 0 || | 61 strcasecmp(fontname, "Liberation Sans") == 0 || |
58 strcasecmp(fontname, "Ascender Sans") == 0) { | 62 strcasecmp(fontname, "Ascender Sans") == 0) { |
59 return SANS; | 63 return SANS; |
60 } else if (strcasecmp(fontname, "Times New Roman") == 0 || | 64 } else if (strcasecmp(fontname, "Times New Roman") == 0 || |
61 strcasecmp(fontname, "Liberation Serif") == 0 || | 65 strcasecmp(fontname, "Liberation Serif") == 0 || |
62 strcasecmp(fontname, "Ascender Serif") == 0) { | 66 strcasecmp(fontname, "Ascender Serif") == 0) { |
63 return SERIF; | 67 return SERIF; |
68 } else if (strcasecmp(fontname, "Courier New") == 0 || | |
69 strcasecmp(fontname, "Liberation Sans Mono") == 0 || | |
Evan Martin
2010/06/14 23:08:55
I don't think we want to do this.
If you have:
| |
70 strcasecmp(fontname, "Ascender Sans Mono") == 0) { | |
71 return MONO; | |
64 } | 72 } |
65 return OTHER; | 73 return OTHER; |
66 } | 74 } |
67 | 75 |
68 | 76 |
69 // Return true if |font_a| and |font_b| are visually and at the metrics | 77 // Return true if |font_a| and |font_b| are visually and at the metrics |
70 // level interchangeable. | 78 // level interchangeable. |
71 bool IsMetricCompatibleReplacement(const char* font_a, const char* font_b) | 79 bool IsMetricCompatibleReplacement(const char* font_a, const char* font_b) |
72 { | 80 { |
73 FontEquivClass class_a = GetFontEquivClass(font_a); | 81 FontEquivClass class_a = GetFontEquivClass(font_a); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 330 |
323 int FontConfigDirect::Open(unsigned fileid) { | 331 int FontConfigDirect::Open(unsigned fileid) { |
324 SkAutoMutexAcquire ac(mutex_); | 332 SkAutoMutexAcquire ac(mutex_); |
325 const std::map<unsigned, std::string>::const_iterator | 333 const std::map<unsigned, std::string>::const_iterator |
326 i = fileid_to_filename_.find(fileid); | 334 i = fileid_to_filename_.find(fileid); |
327 if (i == fileid_to_filename_.end()) | 335 if (i == fileid_to_filename_.end()) |
328 return -1; | 336 return -1; |
329 | 337 |
330 return open(i->second.c_str(), O_RDONLY); | 338 return open(i->second.c_str(), O_RDONLY); |
331 } | 339 } |
OLD | NEW |