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 15 matching lines...) Expand all Loading... |
26 namespace blink { | 26 namespace blink { |
27 | 27 |
28 // A SVGTextFragment describes a text fragment of a LayoutSVGInlineText which ca
n be laid out at once. | 28 // A SVGTextFragment describes a text fragment of a LayoutSVGInlineText which ca
n be laid out at once. |
29 struct SVGTextFragment { | 29 struct SVGTextFragment { |
30 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 30 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
31 SVGTextFragment() | 31 SVGTextFragment() |
32 : characterOffset(0) | 32 : characterOffset(0) |
33 , metricsListOffset(0) | 33 , metricsListOffset(0) |
34 , length(0) | 34 , length(0) |
35 , isTextOnPath(false) | 35 , isTextOnPath(false) |
| 36 , isVertical(false) |
36 , x(0) | 37 , x(0) |
37 , y(0) | 38 , y(0) |
38 , width(0) | 39 , width(0) |
39 , height(0) | 40 , height(0) |
| 41 , lengthAdjustScale(1) |
| 42 , lengthAdjustBias(0) |
40 { | 43 { |
41 } | 44 } |
42 | 45 |
43 enum TransformType { | 46 enum TransformType { |
44 TransformRespectingTextLength, | 47 TransformRespectingTextLength, |
45 TransformIgnoringTextLength | 48 TransformIgnoringTextLength |
46 }; | 49 }; |
47 | 50 |
48 FloatRect boundingBox(float baseline) const | 51 FloatRect boundingBox(float baseline) const |
49 { | 52 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return result; | 84 return result; |
82 } | 85 } |
83 return buildNormalFragmentTransform(); | 86 return buildNormalFragmentTransform(); |
84 } | 87 } |
85 | 88 |
86 bool isTransformed() const { return affectedByTextLength() || !transform.isI
dentity(); } | 89 bool isTransformed() const { return affectedByTextLength() || !transform.isI
dentity(); } |
87 | 90 |
88 // The first laid out character starts at LayoutSVGInlineText::characters()
+ characterOffset. | 91 // The first laid out character starts at LayoutSVGInlineText::characters()
+ characterOffset. |
89 unsigned characterOffset; | 92 unsigned characterOffset; |
90 unsigned metricsListOffset; | 93 unsigned metricsListOffset; |
91 unsigned length : 31; | 94 unsigned length : 30; |
92 unsigned isTextOnPath : 1; | 95 unsigned isTextOnPath : 1; |
| 96 unsigned isVertical : 1; |
93 | 97 |
94 float x; | 98 float x; |
95 float y; | 99 float y; |
96 float width; | 100 float width; |
97 float height; | 101 float height; |
98 | 102 |
99 // Top and bottom are the amounts of glyph overflows exceeding the font metr
ics' ascent and descent, respectively. | 103 // Top and bottom are the amounts of glyph overflows exceeding the font metr
ics' ascent and descent, respectively. |
100 float glyphOverflowTop; | 104 float glyphOverflowTop; |
101 float glyphOverflowBottom; | 105 float glyphOverflowBottom; |
102 // Left and right are the amounts of glyph overflows exceeding the left and
right edge of normal layout boundary, respectively. | 106 // Left and right are the amounts of glyph overflows exceeding the left and
right edge of normal layout boundary, respectively. |
103 float glyphOverflowLeft; | 107 float glyphOverflowLeft; |
104 float glyphOverflowRight; | 108 float glyphOverflowRight; |
105 | 109 |
106 // Includes rotation/glyph-orientation-(horizontal|vertical) transforms, as
well as orientation related shifts | 110 // Includes rotation/glyph-orientation-(horizontal|vertical) transforms, as
well as orientation related shifts |
107 // (see SVGTextLayoutEngine, which builds this transformation). | 111 // (see SVGTextLayoutEngine, which builds this transformation). |
108 AffineTransform transform; | 112 AffineTransform transform; |
109 | 113 |
110 // Contains lengthAdjust related transformations, which are not allowd to in
fluence the SVGTextQuery code. | 114 // Contains lengthAdjust related transformations, which are not allowd to in
fluence the SVGTextQuery code. |
111 AffineTransform lengthAdjustTransform; | 115 float lengthAdjustScale; |
| 116 float lengthAdjustBias; |
112 | 117 |
113 private: | 118 private: |
114 AffineTransform buildNormalFragmentTransform() const | 119 AffineTransform buildNormalFragmentTransform() const |
115 { | 120 { |
116 if (isTextOnPath) | 121 if (isTextOnPath) |
117 return buildTransformForTextOnPath(); | 122 return buildTransformForTextOnPath(); |
118 return buildTransformForTextOnLine(); | 123 return buildTransformForTextOnLine(); |
119 } | 124 } |
120 | 125 |
121 bool affectedByTextLength() const { return lengthAdjustTransform.a() != 1 ||
lengthAdjustTransform.d() != 1; } | 126 bool affectedByTextLength() const { return lengthAdjustScale != 1; } |
122 | 127 |
123 void transformAroundOrigin(AffineTransform& result) const | 128 void transformAroundOrigin(AffineTransform& result) const |
124 { | 129 { |
125 // Returns (translate(x, y) * result) * translate(-x, -y). | 130 // Returns (translate(x, y) * result) * translate(-x, -y). |
126 result.setE(result.e() + x); | 131 result.setE(result.e() + x); |
127 result.setF(result.f() + y); | 132 result.setF(result.f() + y); |
128 result.translate(-x, -y); | 133 result.translate(-x, -y); |
129 } | 134 } |
130 | 135 |
131 AffineTransform buildTransformForTextOnPath() const | 136 AffineTransform buildTransformForTextOnPath() const |
132 { | 137 { |
133 // For text-on-path layout, multiply the transform with the lengthAdjust
Transform before orienting the resulting transform. | 138 // For text-on-path layout, multiply the transform with the |
134 AffineTransform result = !affectedByTextLength() ? transform : transform
* lengthAdjustTransform; | 139 // lengthAdjustTransform before orienting the resulting transform. |
| 140 // T(x,y) * M(transform) * M(lengthAdjust) * T(-x,-y) |
| 141 AffineTransform result = !affectedByTextLength() ? transform : transform
* lengthAdjustTransform(); |
135 if (!result.isIdentity()) | 142 if (!result.isIdentity()) |
136 transformAroundOrigin(result); | 143 transformAroundOrigin(result); |
137 return result; | 144 return result; |
138 } | 145 } |
139 | 146 |
| 147 AffineTransform lengthAdjustTransform() const |
| 148 { |
| 149 AffineTransform result; |
| 150 if (!affectedByTextLength()) |
| 151 return result; |
| 152 // Load a transform assuming horizontal direction, then swap if vertical
. |
| 153 result.setMatrix(lengthAdjustScale, 0, 0, 1, lengthAdjustBias, 0); |
| 154 if (isVertical) { |
| 155 result.setD(result.a()); |
| 156 result.setA(1); |
| 157 result.setF(result.e()); |
| 158 result.setE(0); |
| 159 } |
| 160 return result; |
| 161 } |
| 162 |
140 AffineTransform buildTransformForTextOnLine() const | 163 AffineTransform buildTransformForTextOnLine() const |
141 { | 164 { |
142 // For text-on-line layout, orient the transform first, then multiply th
e lengthAdjustTransform with the oriented transform. | 165 // For text-on-line layout, orient the transform first, then multiply |
| 166 // the lengthAdjustTransform with the oriented transform. |
| 167 // M(lengthAdjust) * T(x,y) * M(transform) * T(-x,-y) |
143 if (transform.isIdentity()) | 168 if (transform.isIdentity()) |
144 return lengthAdjustTransform; | 169 return lengthAdjustTransform(); |
145 | 170 |
146 AffineTransform result = transform; | 171 AffineTransform result = transform; |
147 transformAroundOrigin(result); | 172 transformAroundOrigin(result); |
148 result.preMultiply(lengthAdjustTransform); | 173 result.preMultiply(lengthAdjustTransform()); |
149 return result; | 174 return result; |
150 } | 175 } |
151 }; | 176 }; |
152 | 177 |
153 } // namespace blink | 178 } // namespace blink |
154 | 179 |
155 #endif | 180 #endif |
OLD | NEW |