2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include <wtf/MathExtras.h>
27 const unsigned gDefaultUnitsPerEm = 1000;
32 : m_unitsPerEm(gDefaultUnitsPerEm)
41 unsigned unitsPerEm() const { return m_unitsPerEm; }
42 void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; }
44 float floatAscent(FontBaseline baselineType = AlphabeticBaseline) const
46 if (baselineType == AlphabeticBaseline)
48 return floatHeight() / 2;
51 void setAscent(float ascent) { m_ascent = ascent; }
53 float floatDescent(FontBaseline baselineType = AlphabeticBaseline) const
55 if (baselineType == AlphabeticBaseline)
57 return floatHeight() / 2;
60 void setDescent(float descent) { m_descent = descent; }
62 float floatHeight(FontBaseline baselineType = AlphabeticBaseline) const
64 return floatAscent(baselineType) + floatDescent(baselineType);
67 float floatLineGap() const { return m_lineGap; }
68 void setLineGap(float lineGap) { m_lineGap = lineGap; }
70 float floatLineSpacing() const { return m_lineSpacing; }
71 void setLineSpacing(float lineSpacing) { m_lineSpacing = lineSpacing; }
73 float xHeight() const { return m_xHeight; }
74 void setXHeight(float xHeight) { m_xHeight = xHeight; }
76 // Integer variants of certain metrics, used for HTML rendering.
77 int ascent(FontBaseline baselineType = AlphabeticBaseline) const
79 if (baselineType == AlphabeticBaseline)
80 return lroundf(m_ascent);
81 return height() - height() / 2;
84 int descent(FontBaseline baselineType = AlphabeticBaseline) const
86 if (baselineType == AlphabeticBaseline)
87 return lroundf(m_descent);
91 int height(FontBaseline baselineType = AlphabeticBaseline) const
93 return ascent(baselineType) + descent(baselineType);
96 int lineGap() const { return lroundf(m_lineGap); }
97 int lineSpacing() const { return lroundf(m_lineSpacing); }
99 bool hasIdenticalAscentDescentAndLineGap(const FontMetrics& other) const
101 return ascent() == other.ascent() && descent() == other.descent() && lineGap() == other.lineGap();
105 friend class SimpleFontData;
109 m_unitsPerEm = gDefaultUnitsPerEm;
117 unsigned m_unitsPerEm;
125 static inline float scaleEmToUnits(float x, unsigned unitsPerEm)
127 return unitsPerEm ? x / unitsPerEm : x;
130 } // namespace WebCore
132 #endif // FontMetrics_h