| 1 | /* |
| 2 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 3 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include <wtf/HashMap.h> |
| 24 | #include <wtf/Vector.h> |
| 25 | |
| 26 | namespace WebCore { |
| 27 | |
| 28 | class AffineTransform; |
| 29 | class SVGInlineTextBox; |
| 30 | |
| 31 | // A SVGTextChunk describes a range of SVGTextFragments, see the SVG spec definition of a "text chunk". |
| 32 | class SVGTextChunk { |
| 33 | public: |
| 34 | enum ChunkStyle { |
| 35 | DefaultStyle = 1 << 0, |
| 36 | MiddleAnchor = 1 << 1, |
| 37 | EndAnchor = 1 << 2, |
| 38 | RightToLeftText = 1 << 3, |
| 39 | VerticalText = 1 << 4, |
| 40 | LengthAdjustSpacing = 1 << 5, |
| 41 | LengthAdjustSpacingAndGlyphs = 1 << 6 |
| 42 | }; |
| 43 | |
| 44 | SVGTextChunk(const Vector<SVGInlineTextBox*>&, unsigned first, unsigned limit); |
| 45 | |
| 46 | unsigned totalCharacters() const; |
| 47 | float totalLength() const; |
| 48 | float totalAnchorShift() const; |
| 49 | void layout(HashMap<SVGInlineTextBox*, AffineTransform>&) const; |
| 50 | |
| 51 | private: |
| 52 | void processTextAnchorCorrection() const; |
| 53 | void buildBoxTransformations(HashMap<SVGInlineTextBox*, AffineTransform>&) const; |
| 54 | void processTextLengthSpacingCorrection() const; |
| 55 | |
| 56 | bool isVerticalText() const { return m_chunkStyle & VerticalText; } |
| 57 | float desiredTextLength() const { return m_desiredTextLength; } |
| 58 | |
| 59 | bool hasDesiredTextLength() const { return m_desiredTextLength > 0 && ((m_chunkStyle & LengthAdjustSpacing) || (m_chunkStyle & LengthAdjustSpacingAndGlyphs)); } |
| 60 | bool hasTextAnchor() const { return m_chunkStyle & RightToLeftText ? !(m_chunkStyle & EndAnchor) : (m_chunkStyle & (MiddleAnchor | EndAnchor)); } |
| 61 | bool hasLengthAdjustSpacing() const { return m_chunkStyle & LengthAdjustSpacing; } |
| 62 | bool hasLengthAdjustSpacingAndGlyphs() const { return m_chunkStyle & LengthAdjustSpacingAndGlyphs; } |
| 63 | |
| 64 | bool boxSpacingAndGlyphsTransform(const SVGInlineTextBox*, AffineTransform&) const; |
| 65 | |
| 66 | private: |
| 67 | // Contains all SVGInlineTextBoxes this chunk spans. |
| 68 | Vector<SVGInlineTextBox*> m_boxes; |
| 69 | |
| 70 | unsigned m_chunkStyle { DefaultStyle }; |
| 71 | float m_desiredTextLength { 0 }; |
| 72 | }; |
| 73 | |
| 74 | } // namespace WebCore |
| 75 | |