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 11 matching lines...) Expand all Loading... |
22 static const float kSmallCapsFraction = 0.7f; | 22 static const float kSmallCapsFraction = 0.7f; |
23 | 23 |
24 void SimpleFontData::platformInit() | 24 void SimpleFontData::platformInit() |
25 { | 25 { |
26 SkPaint paint; | 26 SkPaint paint; |
27 SkPaint::FontMetrics metrics; | 27 SkPaint::FontMetrics metrics; |
28 | 28 |
29 m_font.setupPaint(&paint); | 29 m_font.setupPaint(&paint); |
30 paint.getFontMetrics(&metrics); | 30 paint.getFontMetrics(&metrics); |
31 | 31 |
32 // use ceil instead of round to favor descent, given a lot of accidental | 32 // Beware those who step here: This code is designed to match Win32 font |
33 // clipping of descenders (e.g. 14pt 'g') in textedit fields | 33 // metrics *exactly*. |
34 const int descent = SkScalarCeil(metrics.fDescent); | 34 m_ascent = SkScalarCeil(-metrics.fAscent); |
35 const int span = SkScalarRound(metrics.fDescent - metrics.fAscent); | 35 m_descent = SkScalarCeil(metrics.fDescent); |
36 const int ascent = span - descent; | |
37 | |
38 m_ascent = ascent; | |
39 m_descent = descent; | |
40 m_xHeight = SkScalarToFloat(-metrics.fAscent) * 0.56f; // hack I stole fro
m the Windows port | 36 m_xHeight = SkScalarToFloat(-metrics.fAscent) * 0.56f; // hack I stole fro
m the Windows port |
41 m_lineSpacing = ascent + descent; | 37 m_lineGap = SkScalarCeil(metrics.fLeading); |
42 m_lineGap = SkScalarRound(metrics.fLeading); | 38 m_lineSpacing = m_ascent + m_descent + m_lineGap; |
43 | 39 |
44 // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is | 40 // In WebKit/WebCore/platform/graphics/SimpleFontData.cpp, m_spaceWidth is |
45 // calculated for us, but we need to calculate m_maxCharWidth and | 41 // calculated for us, but we need to calculate m_maxCharWidth and |
46 // m_avgCharWidth in order for text entry widgets to be sized correctly. | 42 // m_avgCharWidth in order for text entry widgets to be sized correctly. |
47 // Skia doesn't expose either of these so we calculate them ourselves | 43 // Skia doesn't expose either of these so we calculate them ourselves |
48 | 44 |
49 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); | 45 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); |
50 if (!glyphPageZero) | 46 if (!glyphPageZero) |
51 return; | 47 return; |
52 | 48 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 105 |
110 m_font.setupPaint(&paint); | 106 m_font.setupPaint(&paint); |
111 | 107 |
112 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 108 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
113 SkScalar width = paint.measureText(&glyph, 2); | 109 SkScalar width = paint.measureText(&glyph, 2); |
114 | 110 |
115 return SkScalarToFloat(width); | 111 return SkScalarToFloat(width); |
116 } | 112 } |
117 | 113 |
118 } // namespace WebCore | 114 } // namespace WebCore |
OLD | NEW |