Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: Source/platform/exported/linux/WebFontInfo.cpp

Issue 323963002: Remove old functions in the process of renaming WebFontFamily to WebFallbackFont (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@ren_step1
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/platform/fonts/linux/FontCacheLinux.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 40
41 namespace blink { 41 namespace blink {
42 42
43 static bool useSubpixelPositioning = false; 43 static bool useSubpixelPositioning = false;
44 44
45 void WebFontInfo::setSubpixelPositioning(bool subpixelPositioning) 45 void WebFontInfo::setSubpixelPositioning(bool subpixelPositioning)
46 { 46 {
47 useSubpixelPositioning = subpixelPositioning; 47 useSubpixelPositioning = subpixelPositioning;
48 } 48 }
49 49
50 // TODO(dro): Remove this legacy version, kept until renames on the Chromium sid e are done. crbug.com/382411
51 void WebFontInfo::familyForChar(WebUChar32 c, const char* preferredLocale, WebFo ntFamily* family)
52 {
53 FcCharSet* cset = FcCharSetCreate();
54 FcCharSetAddChar(cset, c);
55 FcPattern* pattern = FcPatternCreate();
56
57 FcValue fcvalue;
58 fcvalue.type = FcTypeCharSet;
59 fcvalue.u.c = cset;
60 FcPatternAdd(pattern, FC_CHARSET, fcvalue, FcFalse);
61
62 fcvalue.type = FcTypeBool;
63 fcvalue.u.b = FcTrue;
64 FcPatternAdd(pattern, FC_SCALABLE, fcvalue, FcFalse);
65
66 if (preferredLocale) {
67 FcLangSet* langset = FcLangSetCreate();
68 FcLangSetAdd(langset, reinterpret_cast<const FcChar8 *>(preferredLocale) );
69 FcPatternAddLangSet(pattern, FC_LANG, langset);
70 FcLangSetDestroy(langset);
71 }
72
73 FcConfigSubstitute(0, pattern, FcMatchPattern);
74 FcDefaultSubstitute(pattern);
75
76 FcResult result;
77 FcFontSet* fontSet = FcFontSort(0, pattern, 0, 0, &result);
78 FcPatternDestroy(pattern);
79 FcCharSetDestroy(cset);
80
81 if (!fontSet) {
82 family->name = WebCString();
83 family->isBold = false;
84 family->isItalic = false;
85 return;
86 }
87 // Older versions of fontconfig have a bug where they cannot select
88 // only scalable fonts so we have to manually filter the results.
89 for (int i = 0; i < fontSet->nfont; ++i) {
90 FcPattern* current = fontSet->fonts[i];
91 FcBool isScalable;
92
93 if (FcPatternGetBool(current, FC_SCALABLE, 0, &isScalable) != FcResultMa tch
94 || !isScalable)
95 continue;
96
97 // fontconfig can also return fonts which are unreadable
98 FcChar8* cFilename;
99 if (FcPatternGetString(current, FC_FILE, 0, &cFilename) != FcResultMatch )
100 continue;
101
102 if (access(reinterpret_cast<char*>(cFilename), R_OK))
103 continue;
104
105 FcChar8* familyName;
106 if (FcPatternGetString(current, FC_FAMILY, 0, &familyName) == FcResultMa tch) {
107 const char* charFamily = reinterpret_cast<char*>(familyName);
108 family->name = WebCString(charFamily, strlen(charFamily));
109 }
110 int weight;
111 if (FcPatternGetInteger(current, FC_WEIGHT, 0, &weight) == FcResultMatch )
112 family->isBold = weight >= FC_WEIGHT_BOLD;
113 else
114 family->isBold = false;
115 int slant;
116 if (FcPatternGetInteger(current, FC_SLANT, 0, &slant) == FcResultMatch)
117 family->isItalic = slant != FC_SLANT_ROMAN;
118 else
119 family->isItalic = false;
120 FcFontSetDestroy(fontSet);
121 return;
122 }
123
124 FcFontSetDestroy(fontSet);
125 }
126
127 void WebFontInfo::fallbackFontForChar(WebUChar32 c, const char* preferredLocale, WebFallbackFont* fallbackFont) 50 void WebFontInfo::fallbackFontForChar(WebUChar32 c, const char* preferredLocale, WebFallbackFont* fallbackFont)
128 { 51 {
129 FcCharSet* cset = FcCharSetCreate(); 52 FcCharSet* cset = FcCharSetCreate();
130 FcCharSetAddChar(cset, c); 53 FcCharSetAddChar(cset, c);
131 FcPattern* pattern = FcPatternCreate(); 54 FcPattern* pattern = FcPatternCreate();
132 55
133 FcValue fcvalue; 56 FcValue fcvalue;
134 fcvalue.type = FcTypeCharSet; 57 fcvalue.type = FcTypeCharSet;
135 fcvalue.u.c = cset; 58 fcvalue.u.c = cset;
136 FcPatternAdd(pattern, FC_CHARSET, fcvalue, FcFalse); 59 FcPatternAdd(pattern, FC_CHARSET, fcvalue, FcFalse);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 209 }
287 210
288 // FontConfig doesn't provide parameters to configure whether subpixel 211 // FontConfig doesn't provide parameters to configure whether subpixel
289 // positioning should be used or not, so we just use a global setting. 212 // positioning should be used or not, so we just use a global setting.
290 out->useSubpixelPositioning = useSubpixelPositioning; 213 out->useSubpixelPositioning = useSubpixelPositioning;
291 214
292 FcPatternDestroy(match); 215 FcPatternDestroy(match);
293 } 216 }
294 217
295 } // namespace blink 218 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/fonts/linux/FontCacheLinux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698