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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 | |
22 #include "core/layout/svg/SVGTextChunk.h" | 21 #include "core/layout/svg/SVGTextChunk.h" |
23 | 22 |
24 #include "core/layout/svg/SVGTextFragment.h" | |
25 #include "core/layout/svg/line/SVGInlineTextBox.h" | |
26 | |
27 namespace blink { | 23 namespace blink { |
28 | 24 |
29 SVGTextChunk::SVGTextChunk(unsigned chunkStyle, float desiredTextLength) | |
30 : m_chunkStyle(chunkStyle) | |
31 , m_desiredTextLength(desiredTextLength) | |
32 { | |
33 } | |
34 | |
35 void SVGTextChunk::calculateLength(float& length, unsigned& characters) const | |
36 { | |
37 SVGTextFragment* lastFragment = 0; | |
38 | |
39 unsigned boxCount = m_boxes.size(); | |
40 for (unsigned boxPosition = 0; boxPosition < boxCount; ++boxPosition) { | |
41 SVGInlineTextBox* textBox = m_boxes.at(boxPosition); | |
42 Vector<SVGTextFragment>& fragments = textBox->textFragments(); | |
43 | |
44 unsigned size = fragments.size(); | |
45 if (!size) | |
46 continue; | |
47 | |
48 for (unsigned i = 0; i < size; ++i) { | |
49 SVGTextFragment& fragment = fragments.at(i); | |
50 characters += fragment.length; | |
51 | |
52 if (m_chunkStyle & VerticalText) | |
53 length += fragment.height; | |
54 else | |
55 length += fragment.width; | |
56 | |
57 if (!lastFragment) { | |
58 lastFragment = &fragment; | |
59 continue; | |
60 } | |
61 | |
62 // Resepect gap between chunks. | |
63 if (m_chunkStyle & VerticalText) | |
64 length += fragment.y - (lastFragment->y + lastFragment->height); | |
65 else | |
66 length += fragment.x - (lastFragment->x + lastFragment->width); | |
67 | |
68 lastFragment = &fragment; | |
69 } | |
70 } | |
71 } | |
72 | |
73 float SVGTextChunk::calculateTextAnchorShift(float length) const | 25 float SVGTextChunk::calculateTextAnchorShift(float length) const |
74 { | 26 { |
75 if (m_chunkStyle & MiddleAnchor) | 27 if (m_chunkStyle & MiddleAnchor) |
76 return -length / 2; | 28 return -length / 2; |
77 if (m_chunkStyle & EndAnchor) | 29 if (m_chunkStyle & EndAnchor) |
78 return m_chunkStyle & RightToLeftText ? 0 : -length; | 30 return m_chunkStyle & RightToLeftText ? 0 : -length; |
79 return m_chunkStyle & RightToLeftText ? -length : 0; | 31 return m_chunkStyle & RightToLeftText ? -length : 0; |
80 } | 32 } |
81 | 33 |
82 } // namespace blink | 34 } // namespace blink |
OLD | NEW |