Chromium Code Reviews| 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) {} | |
| 50 | 52 |
| 51 unsigned unitsPerEm() const { return m_unitsPerEm; } | 53 unsigned unitsPerEm() const { return m_unitsPerEm; } |
| 52 void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; } | 54 void setUnitsPerEm(unsigned unitsPerEm) { m_unitsPerEm = unitsPerEm; } |
| 53 | 55 |
| 54 float floatAscent(FontBaseline baselineType = AlphabeticBaseline) const { | 56 float floatAscent(FontBaseline baselineType = AlphabeticBaseline) const { |
| 55 if (baselineType == AlphabeticBaseline) | 57 if (baselineType == AlphabeticBaseline) |
| 56 return m_ascent; | 58 return m_ascent; |
| 57 return floatHeight() / 2; | 59 return floatHeight() / 2; |
| 58 } | 60 } |
| 59 | 61 |
| 60 void setAscent(float ascent) { | 62 void setAscent(float ascent) { |
| 61 m_ascent = ascent; | 63 m_ascent = ascent; |
| 62 m_ascentInt = lroundf(ascent); | 64 m_ascentInt = lroundf(ascent); |
| 65 if (m_ascentInt < ascent) | |
| 66 m_visualOverflowInflationForAscent++; | |
|
eae
2017/04/07 17:41:57
FontMetrics already stores the rounded and unround
Xianzhu
2017/04/07 18:02:53
FontMetrics doesn't store the unrounded values in
| |
| 63 } | 67 } |
| 64 | 68 |
| 65 float floatDescent(FontBaseline baselineType = AlphabeticBaseline) const { | 69 float floatDescent(FontBaseline baselineType = AlphabeticBaseline) const { |
| 66 if (baselineType == AlphabeticBaseline) | 70 if (baselineType == AlphabeticBaseline) |
| 67 return m_descent; | 71 return m_descent; |
| 68 return floatHeight() / 2; | 72 return floatHeight() / 2; |
| 69 } | 73 } |
| 70 | 74 |
| 71 void setDescent(float descent) { | 75 void setDescent(float descent) { |
| 72 m_descent = descent; | 76 m_descent = descent; |
| 73 m_descentInt = lroundf(descent); | 77 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; | |
| 74 } | 91 } |
| 75 | 92 |
| 76 float floatHeight(FontBaseline baselineType = AlphabeticBaseline) const { | 93 float floatHeight(FontBaseline baselineType = AlphabeticBaseline) const { |
| 77 return floatAscent() + floatDescent(); | 94 return floatAscent() + floatDescent(); |
| 78 } | 95 } |
| 79 | 96 |
| 80 float floatLineGap() const { return m_lineGap; } | 97 float floatLineGap() const { return m_lineGap; } |
| 81 void setLineGap(float lineGap) { m_lineGap = lineGap; } | 98 void setLineGap(float lineGap) { m_lineGap = lineGap; } |
| 82 | 99 |
| 83 float floatLineSpacing() const { return m_lineSpacing; } | 100 float floatLineSpacing() const { return m_lineSpacing; } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 m_ascent = 0; | 177 m_ascent = 0; |
| 161 m_descent = 0; | 178 m_descent = 0; |
| 162 m_ascentInt = 0; | 179 m_ascentInt = 0; |
| 163 m_descentInt = 0; | 180 m_descentInt = 0; |
| 164 m_lineGap = 0; | 181 m_lineGap = 0; |
| 165 m_lineSpacing = 0; | 182 m_lineSpacing = 0; |
| 166 m_xHeight = 0; | 183 m_xHeight = 0; |
| 167 m_hasXHeight = false; | 184 m_hasXHeight = false; |
| 168 m_underlinethickness = 0; | 185 m_underlinethickness = 0; |
| 169 m_underlinePosition = 0; | 186 m_underlinePosition = 0; |
| 187 m_visualOverflowInflationForAscent = 0; | |
| 188 m_visualOverflowInflationForDescent = 0; | |
| 170 } | 189 } |
| 171 | 190 |
| 172 unsigned m_unitsPerEm; | 191 unsigned m_unitsPerEm; |
| 173 float m_ascent; | 192 float m_ascent; |
| 174 float m_descent; | 193 float m_descent; |
| 175 float m_lineGap; | 194 float m_lineGap; |
| 176 float m_lineSpacing; | 195 float m_lineSpacing; |
| 177 float m_xHeight; | 196 float m_xHeight; |
| 178 float m_zeroWidth; | 197 float m_zeroWidth; |
| 179 float m_underlinethickness; | 198 float m_underlinethickness; |
| 180 float m_underlinePosition; | 199 float m_underlinePosition; |
| 181 int m_ascentInt; | 200 int m_ascentInt; |
| 182 int m_descentInt; | 201 int m_descentInt; |
| 183 bool m_hasXHeight; | 202 bool m_hasXHeight; |
| 184 bool m_hasZeroWidth; | 203 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; | |
| 185 }; | 210 }; |
| 186 | 211 |
| 187 } // namespace blink | 212 } // namespace blink |
| 188 | 213 |
| 189 #endif // FontMetrics_h | 214 #endif // FontMetrics_h |
| OLD | NEW |