OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2012. 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 "core/layout/svg/SVGTextMetrics.h" | 20 #include "core/layout/svg/SVGTextMetrics.h" |
21 | 21 |
22 #include "core/layout/api/LineLayoutSVGInlineText.h" | 22 #include "core/layout/api/LineLayoutSVGInlineText.h" |
23 #include "core/layout/svg/LayoutSVGInlineText.h" | |
24 #include "platform/fonts/FontOrientation.h" | 23 #include "platform/fonts/FontOrientation.h" |
25 | 24 |
26 namespace blink { | 25 namespace blink { |
27 | 26 |
28 SVGTextMetrics::SVGTextMetrics() | 27 SVGTextMetrics::SVGTextMetrics() |
29 : m_width(0) | 28 : m_width(0) |
30 , m_height(0) | 29 , m_height(0) |
31 , m_length(0) | 30 , m_length(0) |
32 { | 31 { |
33 } | 32 } |
34 | 33 |
35 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) | 34 SVGTextMetrics::SVGTextMetrics(SVGTextMetrics::MetricsType) |
36 : m_width(0) | 35 : m_width(0) |
37 , m_height(0) | 36 , m_height(0) |
38 , m_length(1) | 37 , m_length(1) |
39 { | 38 { |
40 } | 39 } |
41 | 40 |
42 TextRun SVGTextMetrics::constructTextRun(LineLayoutSVGInlineText textLayoutItem,
unsigned position, unsigned length, TextDirection textDirection) | |
43 { | |
44 const ComputedStyle& style = textLayoutItem.styleRef(); | |
45 | |
46 TextRun run(static_cast<const LChar*>(nullptr) // characters, will be set be
low if non-zero. | |
47 , 0 // length, will be set below if non-zero. | |
48 , 0 // xPos, only relevant with allowTabs=true | |
49 , 0 // padding, only relevant for justified text, not relevant for SVG | |
50 , TextRun::AllowTrailingExpansion | |
51 , textDirection | |
52 , isOverride(style.unicodeBidi()) /* directionalOverride */); | |
53 | |
54 if (length) { | |
55 if (textLayoutItem.is8Bit()) | |
56 run.setText(textLayoutItem.characters8() + position, length); | |
57 else | |
58 run.setText(textLayoutItem.characters16() + position, length); | |
59 } | |
60 | |
61 // We handle letter & word spacing ourselves. | |
62 run.disableSpacing(); | |
63 | |
64 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. | |
65 run.setCharactersLength(textLayoutItem.textLength() - position); | |
66 ASSERT(run.charactersLength() >= run.length()); | |
67 return run; | |
68 } | |
69 | |
70 SVGTextMetrics::SVGTextMetrics(LineLayoutSVGInlineText textLayoutItem, unsigned
length, float width) | 41 SVGTextMetrics::SVGTextMetrics(LineLayoutSVGInlineText textLayoutItem, unsigned
length, float width) |
71 { | 42 { |
72 ASSERT(textLayoutItem); | 43 ASSERT(textLayoutItem); |
73 | 44 |
74 float scalingFactor = textLayoutItem.scalingFactor(); | 45 float scalingFactor = textLayoutItem.scalingFactor(); |
75 ASSERT(scalingFactor); | 46 ASSERT(scalingFactor); |
76 | 47 |
77 m_width = width / scalingFactor; | 48 m_width = width / scalingFactor; |
78 m_height = textLayoutItem.scaledFont().getFontMetrics().floatHeight() / scal
ingFactor; | 49 m_height = textLayoutItem.scaledFont().getFontMetrics().floatHeight() / scal
ingFactor; |
79 | 50 |
80 m_length = length; | 51 m_length = length; |
81 } | 52 } |
82 | 53 |
83 float SVGTextMetrics::advance(FontOrientation orientation) const | 54 float SVGTextMetrics::advance(FontOrientation orientation) const |
84 { | 55 { |
85 switch (orientation) { | 56 switch (orientation) { |
86 case FontOrientation::Horizontal: | 57 case FontOrientation::Horizontal: |
87 case FontOrientation::VerticalRotated: | 58 case FontOrientation::VerticalRotated: |
88 return width(); | 59 return width(); |
89 case FontOrientation::VerticalUpright: | 60 case FontOrientation::VerticalUpright: |
90 return height(); | 61 return height(); |
91 default: | 62 default: |
92 ASSERT_NOT_REACHED(); | 63 ASSERT_NOT_REACHED(); |
93 return width(); | 64 return width(); |
94 } | 65 } |
95 } | 66 } |
96 | 67 |
97 } // namespace blink | 68 } // namespace blink |
OLD | NEW |