OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. 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 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/rendering/RenderCombineText.h" | 22 #include "core/layout/LayoutTextCombine.h" |
23 | 23 |
24 #include "core/layout/TextRunConstructor.h" | 24 #include "core/layout/TextRunConstructor.h" |
25 #include "platform/graphics/GraphicsContext.h" | 25 #include "platform/graphics/GraphicsContext.h" |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 | 28 |
29 const float textCombineMargin = 1.1f; // Allow em + 10% margin | 29 const float textCombineMargin = 1.1f; // Allow em + 10% margin |
30 | 30 |
31 RenderCombineText::RenderCombineText(Node* node, PassRefPtr<StringImpl> string) | 31 LayoutTextCombine::LayoutTextCombine(Node* node, PassRefPtr<StringImpl> string) |
32 : RenderText(node, string) | 32 : LayoutText(node, string) |
33 , m_combinedTextWidth(0) | 33 , m_combinedTextWidth(0) |
34 , m_scaleX(1.0f) | 34 , m_scaleX(1.0f) |
35 , m_isCombined(false) | 35 , m_isCombined(false) |
36 , m_needsFontUpdate(false) | 36 , m_needsFontUpdate(false) |
37 { | 37 { |
38 } | 38 } |
39 | 39 |
40 void RenderCombineText::styleDidChange(StyleDifference diff, const LayoutStyle*
oldStyle) | 40 void LayoutTextCombine::styleDidChange(StyleDifference diff, const LayoutStyle*
oldStyle) |
41 { | 41 { |
42 setStyleInternal(LayoutStyle::clone(styleRef())); | 42 setStyleInternal(LayoutStyle::clone(styleRef())); |
43 RenderText::styleDidChange(diff, oldStyle); | 43 LayoutText::styleDidChange(diff, oldStyle); |
44 | 44 |
45 updateIsCombined(); | 45 updateIsCombined(); |
46 } | 46 } |
47 | 47 |
48 void RenderCombineText::setTextInternal(PassRefPtr<StringImpl> text) | 48 void LayoutTextCombine::setTextInternal(PassRefPtr<StringImpl> text) |
49 { | 49 { |
50 RenderText::setTextInternal(text); | 50 LayoutText::setTextInternal(text); |
51 | 51 |
52 updateIsCombined(); | 52 updateIsCombined(); |
53 } | 53 } |
54 | 54 |
55 float RenderCombineText::width(unsigned from, unsigned length, const Font& font,
float xPosition, TextDirection direction, HashSet<const SimpleFontData*>* fallb
ackFonts, GlyphOverflow* glyphOverflow) const | 55 float LayoutTextCombine::width(unsigned from, unsigned length, const Font& font,
float xPosition, TextDirection direction, HashSet<const SimpleFontData*>* fallb
ackFonts, GlyphOverflow* glyphOverflow) const |
56 { | 56 { |
57 if (!length) | 57 if (!length) |
58 return 0; | 58 return 0; |
59 | 59 |
60 if (hasEmptyText()) | 60 if (hasEmptyText()) |
61 return 0; | 61 return 0; |
62 | 62 |
63 if (m_isCombined) | 63 if (m_isCombined) |
64 return font.fontDescription().computedSize(); | 64 return font.fontDescription().computedSize(); |
65 | 65 |
66 return RenderText::width(from, length, font, xPosition, direction, fallbackF
onts, glyphOverflow); | 66 return LayoutText::width(from, length, font, xPosition, direction, fallbackF
onts, glyphOverflow); |
67 } | 67 } |
68 | 68 |
69 void scaleHorizontallyAndTranslate(GraphicsContext& context, float scaleX, float
centerX, float offsetX, float offsetY) | 69 void scaleHorizontallyAndTranslate(GraphicsContext& context, float scaleX, float
centerX, float offsetX, float offsetY) |
70 { | 70 { |
71 context.concatCTM(AffineTransform(scaleX, 0, 0, 1, centerX * (1.0f - scaleX)
+ offsetX * scaleX, offsetY)); | 71 context.concatCTM(AffineTransform(scaleX, 0, 0, 1, centerX * (1.0f - scaleX)
+ offsetX * scaleX, offsetY)); |
72 } | 72 } |
73 | 73 |
74 void RenderCombineText::transformToInlineCoordinates(GraphicsContext& context, c
onst FloatRect& boxRect) const | 74 void LayoutTextCombine::transformToInlineCoordinates(GraphicsContext& context, c
onst FloatRect& boxRect) const |
75 { | 75 { |
76 ASSERT(!m_needsFontUpdate); | 76 ASSERT(!m_needsFontUpdate); |
77 ASSERT(m_isCombined); | 77 ASSERT(m_isCombined); |
78 if (m_scaleX >= 1.0f) { | 78 if (m_scaleX >= 1.0f) { |
79 // Fast path, more than 90% of cases | 79 // Fast path, more than 90% of cases |
80 ASSERT(m_scaleX == 1.0f); | 80 ASSERT(m_scaleX == 1.0f); |
81 context.concatCTM(AffineTransform::translation(offsetXNoScale(boxRect),
offsetY())); | 81 context.concatCTM(AffineTransform::translation(offsetXNoScale(boxRect),
offsetY())); |
82 return; | 82 return; |
83 } | 83 } |
84 ASSERT(m_scaleX > 0.0f); | 84 ASSERT(m_scaleX > 0.0f); |
85 const float centerX = boxRect.x() + boxRect.width() / 2; | 85 const float centerX = boxRect.x() + boxRect.width() / 2; |
86 scaleHorizontallyAndTranslate(context, m_scaleX, centerX, offsetX(boxRect),
offsetY()); | 86 scaleHorizontallyAndTranslate(context, m_scaleX, centerX, offsetX(boxRect),
offsetY()); |
87 } | 87 } |
88 | 88 |
89 void RenderCombineText::transformLayoutRect(FloatRect& boxRect) const | 89 void LayoutTextCombine::transformLayoutRect(FloatRect& boxRect) const |
90 { | 90 { |
91 ASSERT(!m_needsFontUpdate); | 91 ASSERT(!m_needsFontUpdate); |
92 ASSERT(m_isCombined); | 92 ASSERT(m_isCombined); |
93 boxRect.move(offsetXNoScale(boxRect), offsetY()); | 93 boxRect.move(offsetXNoScale(boxRect), offsetY()); |
94 } | 94 } |
95 | 95 |
96 void RenderCombineText::updateIsCombined() | 96 void LayoutTextCombine::updateIsCombined() |
97 { | 97 { |
98 // CSS3 spec says text-combine works only in vertical writing mode. | 98 // CSS3 spec says text-combine works only in vertical writing mode. |
99 m_isCombined = !style()->isHorizontalWritingMode() | 99 m_isCombined = !style()->isHorizontalWritingMode() |
100 // Nothing to combine. | 100 // Nothing to combine. |
101 && !hasEmptyText(); | 101 && !hasEmptyText(); |
102 | 102 |
103 if (m_isCombined) | 103 if (m_isCombined) |
104 m_needsFontUpdate = true; | 104 m_needsFontUpdate = true; |
105 } | 105 } |
106 | 106 |
107 void RenderCombineText::updateFont() | 107 void LayoutTextCombine::updateFont() |
108 { | 108 { |
109 if (!m_needsFontUpdate) | 109 if (!m_needsFontUpdate) |
110 return; | 110 return; |
111 | 111 |
112 m_needsFontUpdate = false; | 112 m_needsFontUpdate = false; |
113 | 113 |
114 if (!m_isCombined) | 114 if (!m_isCombined) |
115 return; | 115 return; |
116 | 116 |
117 TextRun run = constructTextRun(this, originalFont(), this, styleRef(), style
()->direction()); | 117 TextRun run = constructTextRun(this, originalFont(), this, styleRef(), style
()->direction()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } else { | 154 } else { |
155 m_scaleX = 1.0f; | 155 m_scaleX = 1.0f; |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 if (shouldUpdateFont) | 159 if (shouldUpdateFont) |
160 style()->font().update(fontSelector); | 160 style()->font().update(fontSelector); |
161 } | 161 } |
162 | 162 |
163 } // namespace blink | 163 } // namespace blink |
OLD | NEW |