| 1 | /* |
| 2 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "AffineTransform.h" |
| 23 | |
| 24 | namespace WebCore { |
| 25 | |
| 26 | // A SVGTextFragment describes a text fragment of a RenderSVGInlineText which can be rendered at once. |
| 27 | struct SVGTextFragment { |
| 28 | SVGTextFragment() |
| 29 | : characterOffset(0) |
| 30 | , metricsListOffset(0) |
| 31 | , length(0) |
| 32 | , isTextOnPath(false) |
| 33 | , x(0) |
| 34 | , y(0) |
| 35 | , width(0) |
| 36 | , height(0) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | enum TransformType { |
| 41 | TransformRespectingTextLength, |
| 42 | TransformIgnoringTextLength |
| 43 | }; |
| 44 | |
| 45 | void buildFragmentTransform(AffineTransform& result, TransformType type = TransformRespectingTextLength) const |
| 46 | { |
| 47 | if (type == TransformIgnoringTextLength) { |
| 48 | result = transform; |
| 49 | transformAroundOrigin(result); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | if (isTextOnPath) |
| 54 | buildTransformForTextOnPath(result); |
| 55 | else |
| 56 | buildTransformForTextOnLine(result); |
| 57 | } |
| 58 | |
| 59 | // The first rendered character starts at RenderSVGInlineText::characters() + characterOffset. |
| 60 | unsigned characterOffset; |
| 61 | unsigned metricsListOffset; |
| 62 | unsigned length : 31; |
| 63 | bool isTextOnPath : 1; |
| 64 | |
| 65 | float x; |
| 66 | float y; |
| 67 | float width; |
| 68 | float height; |
| 69 | |
| 70 | // Includes rotation/glyph-orientation-(horizontal|vertical) transforms, as well as orientation related shifts |
| 71 | // (see SVGTextLayoutEngine, which builds this transformation). |
| 72 | AffineTransform transform; |
| 73 | |
| 74 | // Contains lengthAdjust related transformations, which are not allowd to influence the SVGTextQuery code. |
| 75 | AffineTransform lengthAdjustTransform; |
| 76 | |
| 77 | private: |
| 78 | void transformAroundOrigin(AffineTransform& result) const |
| 79 | { |
| 80 | // Returns (translate(x, y) * result) * translate(-x, -y). |
| 81 | result.setE(result.e() + x); |
| 82 | result.setF(result.f() + y); |
| 83 | result.translate(-x, -y); |
| 84 | } |
| 85 | |
| 86 | void buildTransformForTextOnPath(AffineTransform& result) const |
| 87 | { |
| 88 | // For text-on-path layout, multiply the transform with the lengthAdjustTransform before orienting the resulting transform. |
| 89 | result = lengthAdjustTransform.isIdentity() ? transform : transform * lengthAdjustTransform; |
| 90 | if (!result.isIdentity()) |
| 91 | transformAroundOrigin(result); |
| 92 | } |
| 93 | |
| 94 | void buildTransformForTextOnLine(AffineTransform& result) const |
| 95 | { |
| 96 | // For text-on-line layout, orient the transform first, then multiply the lengthAdjustTransform with the oriented transform. |
| 97 | if (transform.isIdentity()) { |
| 98 | result = lengthAdjustTransform; |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | result = transform; |
| 103 | transformAroundOrigin(result); |
| 104 | |
| 105 | if (!lengthAdjustTransform.isIdentity()) |
| 106 | result = lengthAdjustTransform * result; |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | } // namespace WebCore |
| 111 | |