| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "core/layout/LayoutObject.h" | 23 #include "core/layout/LayoutObject.h" |
| 24 #include "core/style/SVGComputedStyle.h" | 24 #include "core/style/SVGComputedStyle.h" |
| 25 #include "core/layout/svg/SVGTextMetrics.h" | 25 #include "core/layout/svg/SVGTextMetrics.h" |
| 26 #include "core/svg/SVGLengthContext.h" | 26 #include "core/svg/SVGLengthContext.h" |
| 27 #include "platform/fonts/Font.h" | 27 #include "platform/fonts/Font.h" |
| 28 #include "platform/text/UnicodeRange.h" | 28 #include "platform/text/UnicodeRange.h" |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 | 31 |
| 32 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font) | 32 SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font, float
effectiveZoom) |
| 33 : m_font(font) | 33 : m_font(font) |
| 34 , m_effectiveZoom(effectiveZoom) |
| 34 { | 35 { |
| 36 ASSERT(m_effectiveZoom); |
| 35 } | 37 } |
| 36 | 38 |
| 37 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s
tyle) const | 39 float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s
tyle) const |
| 38 { | 40 { |
| 39 const SVGComputedStyle& svgStyle = style.svgStyle(); | 41 const SVGComputedStyle& svgStyle = style.svgStyle(); |
| 40 | 42 |
| 41 switch (svgStyle.baselineShift()) { | 43 switch (svgStyle.baselineShift()) { |
| 42 case BS_LENGTH: | 44 case BS_LENGTH: |
| 43 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s
tyle, m_font.fontDescription().computedPixelSize()); | 45 return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), s
tyle, m_font.fontDescription().computedPixelSize() / m_effectiveZoom); |
| 44 case BS_SUB: | 46 case BS_SUB: |
| 45 return -m_font.fontMetrics().floatHeight() / 2; | 47 return -m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom; |
| 46 case BS_SUPER: | 48 case BS_SUPER: |
| 47 return m_font.fontMetrics().floatHeight() / 2; | 49 return m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom; |
| 48 default: | 50 default: |
| 49 ASSERT_NOT_REACHED(); | 51 ASSERT_NOT_REACHED(); |
| 50 return 0; | 52 return 0; |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 | 55 |
| 54 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
ine(bool isVerticalText, const LayoutObject* textRenderer) const | 56 EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
ine(bool isVerticalText, const LayoutObject* textRenderer) const |
| 55 { | 57 { |
| 56 ASSERT(textRenderer); | 58 ASSERT(textRenderer); |
| 57 ASSERT(textRenderer->style()); | 59 ASSERT(textRenderer->style()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 const LayoutObject* textRendererParent = textRenderer->parent(); | 109 const LayoutObject* textRendererParent = textRenderer->parent(); |
| 108 ASSERT(textRendererParent); | 110 ASSERT(textRendererParent); |
| 109 | 111 |
| 110 EAlignmentBaseline baseline = textRenderer->style()->svgStyle().alignmentBas
eline(); | 112 EAlignmentBaseline baseline = textRenderer->style()->svgStyle().alignmentBas
eline(); |
| 111 if (baseline == AB_AUTO || baseline == AB_BASELINE) { | 113 if (baseline == AB_AUTO || baseline == AB_BASELINE) { |
| 112 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRende
rerParent); | 114 baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textRende
rerParent); |
| 113 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); | 115 ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); |
| 114 } | 116 } |
| 115 | 117 |
| 116 const FontMetrics& fontMetrics = m_font.fontMetrics(); | 118 const FontMetrics& fontMetrics = m_font.fontMetrics(); |
| 119 float ascent = fontMetrics.floatAscent() / m_effectiveZoom; |
| 120 float descent = fontMetrics.floatDescent() / m_effectiveZoom; |
| 121 float xheight = fontMetrics.xHeight() / m_effectiveZoom; |
| 117 | 122 |
| 118 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling | 123 // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling |
| 119 switch (baseline) { | 124 switch (baseline) { |
| 120 case AB_BEFORE_EDGE: | 125 case AB_BEFORE_EDGE: |
| 121 case AB_TEXT_BEFORE_EDGE: | 126 case AB_TEXT_BEFORE_EDGE: |
| 122 return fontMetrics.floatAscent(); | 127 return ascent; |
| 123 case AB_MIDDLE: | 128 case AB_MIDDLE: |
| 124 return fontMetrics.xHeight() / 2; | 129 return xheight / 2; |
| 125 case AB_CENTRAL: | 130 case AB_CENTRAL: |
| 126 return (fontMetrics.floatAscent() - fontMetrics.floatDescent()) / 2; | 131 return (ascent - descent) / 2; |
| 127 case AB_AFTER_EDGE: | 132 case AB_AFTER_EDGE: |
| 128 case AB_TEXT_AFTER_EDGE: | 133 case AB_TEXT_AFTER_EDGE: |
| 129 case AB_IDEOGRAPHIC: | 134 case AB_IDEOGRAPHIC: |
| 130 return -fontMetrics.floatDescent(); | 135 return -descent; |
| 131 case AB_ALPHABETIC: | 136 case AB_ALPHABETIC: |
| 132 return 0; | 137 return 0; |
| 133 case AB_HANGING: | 138 case AB_HANGING: |
| 134 return fontMetrics.floatAscent() * 8 / 10.f; | 139 return ascent * 8 / 10.f; |
| 135 case AB_MATHEMATICAL: | 140 case AB_MATHEMATICAL: |
| 136 return fontMetrics.floatAscent() / 2; | 141 return ascent / 2; |
| 137 case AB_BASELINE: | 142 case AB_BASELINE: |
| 138 default: | 143 default: |
| 139 ASSERT_NOT_REACHED(); | 144 ASSERT_NOT_REACHED(); |
| 140 return 0; | 145 return 0; |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica
lText, const SVGComputedStyle& style, const UChar& character) const | 149 float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVertica
lText, const SVGComputedStyle& style, const UChar& character) const |
| 145 { | 150 { |
| 146 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien
tationHorizontal()) { | 151 switch (isVerticalText ? style.glyphOrientationVertical() : style.glyphOrien
tationHorizontal()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 177 // The function is based on spec requirements: | 182 // The function is based on spec requirements: |
| 178 // | 183 // |
| 179 // Spec: If the 'glyph-orientation-horizontal' results in an orientation ang
le that is not a multiple of | 184 // Spec: If the 'glyph-orientation-horizontal' results in an orientation ang
le that is not a multiple of |
| 180 // of 180 degrees, then the current text position is incremented according t
o the vertical metrics of the glyph. | 185 // of 180 degrees, then the current text position is incremented according t
o the vertical metrics of the glyph. |
| 181 // | 186 // |
| 182 // Spec: If if the 'glyph-orientation-vertical' results in an orientation an
gle that is not a multiple of | 187 // Spec: If if the 'glyph-orientation-vertical' results in an orientation an
gle that is not a multiple of |
| 183 // 180 degrees, then the current text position is incremented according to t
he horizontal metrics of the glyph. | 188 // 180 degrees, then the current text position is incremented according to t
he horizontal metrics of the glyph. |
| 184 | 189 |
| 185 const FontMetrics& fontMetrics = m_font.fontMetrics(); | 190 const FontMetrics& fontMetrics = m_font.fontMetrics(); |
| 186 | 191 |
| 192 float ascent = fontMetrics.floatAscent() / m_effectiveZoom; |
| 193 float descent = fontMetrics.floatDescent() / m_effectiveZoom; |
| 194 |
| 187 // Vertical orientation handling. | 195 // Vertical orientation handling. |
| 188 if (isVerticalText) { | 196 if (isVerticalText) { |
| 189 float ascentMinusDescent = fontMetrics.floatAscent() - fontMetrics.float
Descent(); | 197 float ascentMinusDescent = ascent - descent; |
| 198 |
| 190 if (!angle) { | 199 if (!angle) { |
| 191 xOrientationShift = (ascentMinusDescent - metrics.width()) / 2; | 200 xOrientationShift = (ascentMinusDescent - metrics.width()) / 2; |
| 192 yOrientationShift = fontMetrics.floatAscent(); | 201 yOrientationShift = ascent; |
| 193 } else if (angle == 180) { | 202 } else if (angle == 180) { |
| 194 xOrientationShift = (ascentMinusDescent + metrics.width()) / 2; | 203 xOrientationShift = (ascentMinusDescent + metrics.width()) / 2; |
| 195 } else if (angle == 270) { | 204 } else if (angle == 270) { |
| 196 yOrientationShift = metrics.width(); | 205 yOrientationShift = metrics.width(); |
| 197 xOrientationShift = ascentMinusDescent; | 206 xOrientationShift = ascentMinusDescent; |
| 198 } | 207 } |
| 199 | 208 |
| 200 // Vertical advance calculation. | 209 // Vertical advance calculation. |
| 201 if (angle && !orientationIsMultiplyOf180Degrees) | 210 if (angle && !orientationIsMultiplyOf180Degrees) |
| 202 return metrics.width(); | 211 return metrics.width(); |
| 203 | 212 |
| 204 return metrics.height(); | 213 return metrics.height(); |
| 205 } | 214 } |
| 206 | 215 |
| 207 // Horizontal orientation handling. | 216 // Horizontal orientation handling. |
| 208 if (angle == 90) { | 217 if (angle == 90) { |
| 209 yOrientationShift = -metrics.width(); | 218 yOrientationShift = -metrics.width(); |
| 210 } else if (angle == 180) { | 219 } else if (angle == 180) { |
| 211 xOrientationShift = metrics.width(); | 220 xOrientationShift = metrics.width(); |
| 212 yOrientationShift = -fontMetrics.floatAscent(); | 221 yOrientationShift = -ascent; |
| 213 } else if (angle == 270) { | 222 } else if (angle == 270) { |
| 214 xOrientationShift = metrics.width(); | 223 xOrientationShift = metrics.width(); |
| 215 } | 224 } |
| 216 | 225 |
| 217 // Horizontal advance calculation. | 226 // Horizontal advance calculation. |
| 218 if (angle && !orientationIsMultiplyOf180Degrees) | 227 if (angle && !orientationIsMultiplyOf180Degrees) |
| 219 return metrics.height(); | 228 return metrics.height(); |
| 220 | 229 |
| 221 return metrics.width(); | 230 return metrics.width(); |
| 222 } | 231 } |
| 223 | 232 |
| 224 } | 233 } |
| OLD | NEW |