Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "SimpleFontData.h" | 6 #include "SimpleFontData.h" |
| 7 | 7 |
| 8 #include "Font.h" | 8 #include "Font.h" |
| 9 #include "FontCache.h" | 9 #include "FontCache.h" |
| 10 #include "FloatRect.h" | 10 #include "FloatRect.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 | 45 |
| 46 // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is | 46 // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is |
| 47 // calculated for us, but we need to calculate m_maxCharWidth and | 47 // calculated for us, but we need to calculate m_maxCharWidth and |
| 48 // m_avgCharWidth in order for text entry widgets to be sized correctly. | 48 // m_avgCharWidth in order for text entry widgets to be sized correctly. |
| 49 // Skia doesn't expose either of these so we calculate them ourselves | 49 // Skia doesn't expose either of these so we calculate them ourselves |
| 50 | 50 |
| 51 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); | 51 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); |
| 52 if (!glyphPageZero) | 52 if (!glyphPageZero) |
| 53 return; | 53 return; |
| 54 | 54 |
| 55 static const UChar32 e_char = 'e'; | |
| 56 static const UChar32 M_char = 'M'; | 55 static const UChar32 M_char = 'M'; |
| 57 m_avgCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(e_char). glyph); | |
| 58 m_maxCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(M_char). glyph); | 56 m_maxCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(M_char). glyph); |
| 57 | |
| 58 if (metrics.fAvgCharWidth) { | |
| 59 m_avgCharWidth = SkScalarRound(metrics.fAvgCharWidth); | |
| 60 } else { | |
| 61 static const UChar32 x_char = 'x'; | |
|
ojan
2008/11/26 00:17:45
Why "x" as the fallback? This is what Firefox uses
agl
2008/11/26 00:22:19
Microsoft documents suggest using the 'x' width an
| |
| 62 m_avgCharWidth = widthForGlyph(glyphPageZero->glyphDataForCharacter(x_ch ar).glyph); | |
| 63 } | |
| 59 } | 64 } |
| 60 | 65 |
| 61 void SimpleFontData::platformDestroy() | 66 void SimpleFontData::platformDestroy() |
| 62 { | 67 { |
| 63 delete m_smallCapsFontData; | 68 delete m_smallCapsFontData; |
| 64 } | 69 } |
| 65 | 70 |
| 66 SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDes cription) const | 71 SimpleFontData* SimpleFontData::smallCapsFontData(const FontDescription& fontDes cription) const |
| 67 { | 72 { |
| 68 if (!m_smallCapsFontData) { | 73 if (!m_smallCapsFontData) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 116 |
| 112 m_font.setupPaint(&paint); | 117 m_font.setupPaint(&paint); |
| 113 | 118 |
| 114 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 119 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 115 SkScalar width = paint.measureText(&glyph, 2); | 120 SkScalar width = paint.measureText(&glyph, 2); |
| 116 | 121 |
| 117 return SkScalarToFloat(width); | 122 return SkScalarToFloat(width); |
| 118 } | 123 } |
| 119 | 124 |
| 120 } // namespace WebCore | 125 } // namespace WebCore |
| OLD | NEW |