| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 m_descent(0), | 39 m_descent(0), |
| 40 m_lineGap(0), | 40 m_lineGap(0), |
| 41 m_lineSpacing(0), | 41 m_lineSpacing(0), |
| 42 m_xHeight(0), | 42 m_xHeight(0), |
| 43 m_zeroWidth(0), | 43 m_zeroWidth(0), |
| 44 m_underlinethickness(0), | 44 m_underlinethickness(0), |
| 45 m_underlinePosition(0), | 45 m_underlinePosition(0), |
| 46 m_ascentInt(0), | 46 m_ascentInt(0), |
| 47 m_descentInt(0), | 47 m_descentInt(0), |
| 48 m_hasXHeight(false), | 48 m_hasXHeight(false), |
| 49 m_hasZeroWidth(false), | 49 m_hasZeroWidth(false) {} |
| 50 m_visualOverflowInflationForAscent(0), | |
| 51 m_visualOverflowInflationForDescent(0) {} | |
| 52 | 50 |
| 53 unsigned unitsPerEm() const { return m_unitsPerEm; } | 51 unsigned unitsPerEm() const { return m_unitsPerEm; } |
| 54 void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; } | 52 void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; } |
| 55 | 53 |
| 56 float floatAscent(FontBaseline baselineType = AlphabeticBaseline) const { | 54 float floatAscent(FontBaseline baselineType = AlphabeticBaseline) const { |
| 57 if (baselineType == AlphabeticBaseline) | 55 if (baselineType == AlphabeticBaseline) |
| 58 return m_ascent; | 56 return m_ascent; |
| 59 return floatHeight() / 2; | 57 return floatHeight() / 2; |
| 60 } | 58 } |
| 61 | 59 |
| 62 void setAscent(float ascent) { | 60 void setAscent(float ascent) { |
| 63 m_ascent = ascent; | 61 m_ascent = ascent; |
| 64 m_ascentInt = lroundf(ascent); | 62 m_ascentInt = lroundf(ascent); |
| 65 if (m_ascentInt < ascent) | |
| 66 m_visualOverflowInflationForAscent++; | |
| 67 } | 63 } |
| 68 | 64 |
| 69 float floatDescent(FontBaseline baselineType = AlphabeticBaseline) const { | 65 float floatDescent(FontBaseline baselineType = AlphabeticBaseline) const { |
| 70 if (baselineType == AlphabeticBaseline) | 66 if (baselineType == AlphabeticBaseline) |
| 71 return m_descent; | 67 return m_descent; |
| 72 return floatHeight() / 2; | 68 return floatHeight() / 2; |
| 73 } | 69 } |
| 74 | 70 |
| 75 void setDescent(float descent) { | 71 void setDescent(float descent) { |
| 76 m_descent = descent; | 72 m_descent = descent; |
| 77 m_descentInt = lroundf(descent); | 73 m_descentInt = lroundf(descent); |
| 78 if (m_descentInt < descent) | |
| 79 m_visualOverflowInflationForDescent++; | |
| 80 } | |
| 81 | |
| 82 void setVisualOverflowInflations(int forAscent, int forDescent) { | |
| 83 m_visualOverflowInflationForAscent = forAscent; | |
| 84 m_visualOverflowInflationForDescent = forDescent; | |
| 85 } | |
| 86 int visualOverflowInflationForAscent() const { | |
| 87 return m_visualOverflowInflationForAscent; | |
| 88 } | |
| 89 int visualOverflowInflationForDescent() const { | |
| 90 return m_visualOverflowInflationForDescent; | |
| 91 } | 74 } |
| 92 | 75 |
| 93 float floatHeight(FontBaseline baselineType = AlphabeticBaseline) const { | 76 float floatHeight(FontBaseline baselineType = AlphabeticBaseline) const { |
| 94 return floatAscent() + floatDescent(); | 77 return floatAscent() + floatDescent(); |
| 95 } | 78 } |
| 96 | 79 |
| 97 float floatLineGap() const { return m_lineGap; } | 80 float floatLineGap() const { return m_lineGap; } |
| 98 void setLineGap(float lineGap) { m_lineGap = lineGap; } | 81 void setLineGap(float lineGap) { m_lineGap = lineGap; } |
| 99 | 82 |
| 100 float floatLineSpacing() const { return m_lineSpacing; } | 83 float floatLineSpacing() const { return m_lineSpacing; } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 m_ascent = 0; | 160 m_ascent = 0; |
| 178 m_descent = 0; | 161 m_descent = 0; |
| 179 m_ascentInt = 0; | 162 m_ascentInt = 0; |
| 180 m_descentInt = 0; | 163 m_descentInt = 0; |
| 181 m_lineGap = 0; | 164 m_lineGap = 0; |
| 182 m_lineSpacing = 0; | 165 m_lineSpacing = 0; |
| 183 m_xHeight = 0; | 166 m_xHeight = 0; |
| 184 m_hasXHeight = false; | 167 m_hasXHeight = false; |
| 185 m_underlinethickness = 0; | 168 m_underlinethickness = 0; |
| 186 m_underlinePosition = 0; | 169 m_underlinePosition = 0; |
| 187 m_visualOverflowInflationForAscent = 0; | |
| 188 m_visualOverflowInflationForDescent = 0; | |
| 189 } | 170 } |
| 190 | 171 |
| 191 unsigned m_unitsPerEm; | 172 unsigned m_unitsPerEm; |
| 192 float m_ascent; | 173 float m_ascent; |
| 193 float m_descent; | 174 float m_descent; |
| 194 float m_lineGap; | 175 float m_lineGap; |
| 195 float m_lineSpacing; | 176 float m_lineSpacing; |
| 196 float m_xHeight; | 177 float m_xHeight; |
| 197 float m_zeroWidth; | 178 float m_zeroWidth; |
| 198 float m_underlinethickness; | 179 float m_underlinethickness; |
| 199 float m_underlinePosition; | 180 float m_underlinePosition; |
| 200 int m_ascentInt; | 181 int m_ascentInt; |
| 201 int m_descentInt; | 182 int m_descentInt; |
| 202 bool m_hasXHeight; | 183 bool m_hasXHeight; |
| 203 bool m_hasZeroWidth; | 184 bool m_hasZeroWidth; |
| 204 | |
| 205 // These are set to non-zero when ascent or descent is rounded or shifted | |
| 206 // to be smaller than the actual ascent or descent. When calculating visual | |
| 207 // overflows, we should add the inflations. | |
| 208 int m_visualOverflowInflationForAscent; | |
| 209 int m_visualOverflowInflationForDescent; | |
| 210 }; | 185 }; |
| 211 | 186 |
| 212 } // namespace blink | 187 } // namespace blink |
| 213 | 188 |
| 214 #endif // FontMetrics_h | 189 #endif // FontMetrics_h |
| OLD | NEW |