OLD | NEW |
---|---|
1 /** | 1 /** |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 "#HeadLineA", | 182 "#HeadLineA", |
183 "#PCMyungjo", | 183 "#PCMyungjo", |
184 "#PilGi", | 184 "#PilGi", |
185 }; | 185 }; |
186 | 186 |
187 // For font families where any of the fonts don't have a valid entry in the OS/2 table | 187 // For font families where any of the fonts don't have a valid entry in the OS/2 table |
188 // for avgCharWidth, fallback to the legacy webkit behavior of getting the avgCh arWidth | 188 // for avgCharWidth, fallback to the legacy webkit behavior of getting the avgCh arWidth |
189 // from the width of a '0'. This only seems to apply to a fixed number of Mac fo nts, | 189 // from the width of a '0'. This only seems to apply to a fixed number of Mac fo nts, |
190 // but, in order to get similar rendering across platforms, we do this check for | 190 // but, in order to get similar rendering across platforms, we do this check for |
191 // all platforms. | 191 // all platforms. |
192 bool LayoutTextControl::hasValidAvgCharWidth(const AtomicString& family) | 192 bool LayoutTextControl::hasValidAvgCharWidth(const SimpleFontData* font, const A tomicString& family) |
kochi
2016/07/13 09:36:12
Can't this be "const SimpleFontData& font"?
(that
kojii
2016/07/13 11:20:35
Making "*" to "&" doesn't assure non-null, so it c
tkent
2016/07/13 23:14:35
In this case,
* making the argument type |const S
tkent
2016/07/14 00:07:09
eae@ just added a runtime null check. https://code
| |
193 { | 193 { |
194 // Some fonts match avgCharWidth to CJK full-width characters. | |
195 // Heuristic check to avoid such fonts. | |
196 DCHECK(font); | |
197 const FontMetrics& metrics = font->getFontMetrics(); | |
198 if (metrics.hasZeroWidth() && font->avgCharWidth() > metrics.zeroWidth() * 1 .7) | |
199 return false; | |
200 | |
194 static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = nullptr; | 201 static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = nullptr; |
195 | 202 |
196 if (family.isEmpty()) | 203 if (family.isEmpty()) |
197 return false; | 204 return false; |
198 | 205 |
199 if (!fontFamiliesWithInvalidCharWidthMap) { | 206 if (!fontFamiliesWithInvalidCharWidthMap) { |
200 fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>; | 207 fontFamiliesWithInvalidCharWidthMap = new HashSet<AtomicString>; |
201 | 208 |
202 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth ); ++i) | 209 for (size_t i = 0; i < WTF_ARRAY_LENGTH(fontFamiliesWithInvalidCharWidth ); ++i) |
203 fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWi thInvalidCharWidth[i])); | 210 fontFamiliesWithInvalidCharWidthMap->add(AtomicString(fontFamiliesWi thInvalidCharWidth[i])); |
204 } | 211 } |
205 | 212 |
206 return !fontFamiliesWithInvalidCharWidthMap->contains(family); | 213 return !fontFamiliesWithInvalidCharWidthMap->contains(family); |
207 } | 214 } |
208 | 215 |
209 float LayoutTextControl::getAvgCharWidth(const AtomicString& family) const | 216 float LayoutTextControl::getAvgCharWidth(const AtomicString& family) const |
210 { | 217 { |
211 const Font& font = style()->font(); | 218 const Font& font = style()->font(); |
212 if (hasValidAvgCharWidth(family)) { | 219 const SimpleFontData* primaryFont = font.primaryFont(); |
213 ASSERT(font.primaryFont()); | 220 if (hasValidAvgCharWidth(primaryFont, family)) |
214 return roundf(font.primaryFont()->avgCharWidth()); | 221 return roundf(primaryFont->avgCharWidth()); |
215 } | |
216 | 222 |
217 const UChar ch = '0'; | 223 const UChar ch = '0'; |
218 const String str = String(&ch, 1); | 224 const String str = String(&ch, 1); |
219 TextRun textRun = constructTextRun(font, str, styleRef(), TextRun::AllowTrai lingExpansion); | 225 TextRun textRun = constructTextRun(font, str, styleRef(), TextRun::AllowTrai lingExpansion); |
220 return font.width(textRun); | 226 return font.width(textRun); |
221 } | 227 } |
222 | 228 |
223 float LayoutTextControl::scaleEmToUnits(int x) const | 229 float LayoutTextControl::scaleEmToUnits(int x) const |
224 { | 230 { |
225 // This matches the unitsPerEm value for MS Shell Dlg and Courier New from t he "head" font table. | 231 // This matches the unitsPerEm value for MS Shell Dlg and Courier New from t he "head" font table. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element(); | 285 HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholder Element(); |
280 LayoutObject* placeholderLayoutObject = placeholder ? placeholder->layoutObj ect() : nullptr; | 286 LayoutObject* placeholderLayoutObject = placeholder ? placeholder->layoutObj ect() : nullptr; |
281 if (!placeholderLayoutObject) | 287 if (!placeholderLayoutObject) |
282 return nullptr; | 288 return nullptr; |
283 if (relayoutChildren) | 289 if (relayoutChildren) |
284 layoutScope.setChildNeedsLayout(placeholderLayoutObject); | 290 layoutScope.setChildNeedsLayout(placeholderLayoutObject); |
285 return placeholderLayoutObject; | 291 return placeholderLayoutObject; |
286 } | 292 } |
287 | 293 |
288 } // namespace blink | 294 } // namespace blink |
OLD | NEW |