| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 return ascent * 8 / 10.f; | 141 return ascent * 8 / 10.f; |
| 142 case AB_MATHEMATICAL: | 142 case AB_MATHEMATICAL: |
| 143 return ascent / 2; | 143 return ascent / 2; |
| 144 case AB_BASELINE: | 144 case AB_BASELINE: |
| 145 default: | 145 default: |
| 146 ASSERT_NOT_REACHED(); | 146 ASSERT_NOT_REACHED(); |
| 147 return 0; | 147 return 0; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica
lText, const SVGComputedStyle& style, const UChar32 character) const | |
| 152 { | |
| 153 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien
tationHorizontal()) { | |
| 154 case GO_AUTO: { | |
| 155 // Spec: Fullwidth ideographic and fullwidth Latin text will be set with
a glyph-orientation of 0-degrees. | |
| 156 // Text which is not fullwidth will be set with a glyph-orientation of 9
0-degrees. | |
| 157 if (!Character::isUprightInMixedVertical(character)) | |
| 158 return 90; | |
| 159 | |
| 160 return 0; | |
| 161 } | |
| 162 case GO_90DEG: | |
| 163 return 90; | |
| 164 case GO_180DEG: | |
| 165 return 180; | |
| 166 case GO_270DEG: | |
| 167 return 270; | |
| 168 case GO_0DEG: | |
| 169 default: | |
| 170 return 0; | |
| 171 } | |
| 172 } | 151 } |
| 173 | |
| 174 static inline bool glyphOrientationIsMultiplyOf180Degrees(float orientationAngle
) | |
| 175 { | |
| 176 return !fabsf(fmodf(orientationAngle, 180)); | |
| 177 } | |
| 178 | |
| 179 float SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation(bool isVe
rticalText, const SVGTextMetrics& metrics, float angle, float& xOrientationShift
, float& yOrientationShift) const | |
| 180 { | |
| 181 bool orientationIsMultiplyOf180Degrees = glyphOrientationIsMultiplyOf180Degr
ees(angle); | |
| 182 | |
| 183 // The function is based on spec requirements: | |
| 184 // | |
| 185 // Spec: If the 'glyph-orientation-horizontal' results in an orientation ang
le that is not a multiple of | |
| 186 // of 180 degrees, then the current text position is incremented according t
o the vertical metrics of the glyph. | |
| 187 // | |
| 188 // Spec: If if the 'glyph-orientation-vertical' results in an orientation an
gle that is not a multiple of | |
| 189 // 180 degrees, then the current text position is incremented according to t
he horizontal metrics of the glyph. | |
| 190 | |
| 191 const FontMetrics& fontMetrics = m_font.fontMetrics(); | |
| 192 | |
| 193 float ascent = fontMetrics.floatAscent() / m_effectiveZoom; | |
| 194 float descent = fontMetrics.floatDescent() / m_effectiveZoom; | |
| 195 | |
| 196 // Vertical orientation handling. | |
| 197 if (isVerticalText) { | |
| 198 float ascentMinusDescent = ascent - descent; | |
| 199 | |
| 200 if (!angle) { | |
| 201 xOrientationShift = (ascentMinusDescent - metrics.width()) / 2; | |
| 202 yOrientationShift = ascent; | |
| 203 } else if (angle == 180) { | |
| 204 xOrientationShift = (ascentMinusDescent + metrics.width()) / 2; | |
| 205 } else if (angle == 270) { | |
| 206 yOrientationShift = metrics.width(); | |
| 207 xOrientationShift = ascentMinusDescent; | |
| 208 } | |
| 209 | |
| 210 // Vertical advance calculation. | |
| 211 if (angle && !orientationIsMultiplyOf180Degrees) | |
| 212 return metrics.width(); | |
| 213 | |
| 214 return metrics.height(); | |
| 215 } | |
| 216 | |
| 217 // Horizontal orientation handling. | |
| 218 if (angle == 90) { | |
| 219 yOrientationShift = -metrics.width(); | |
| 220 } else if (angle == 180) { | |
| 221 xOrientationShift = metrics.width(); | |
| 222 yOrientationShift = -ascent; | |
| 223 } else if (angle == 270) { | |
| 224 xOrientationShift = metrics.width(); | |
| 225 } | |
| 226 | |
| 227 // Horizontal advance calculation. | |
| 228 if (angle && !orientationIsMultiplyOf180Degrees) | |
| 229 return metrics.height(); | |
| 230 | |
| 231 return metrics.width(); | |
| 232 } | |
| 233 | |
| 234 } | |
| OLD | NEW |