OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/platform/graphics/mac/ComplexTextController.h" | 26 #include "core/platform/graphics/mac/ComplexTextController.h" |
27 | 27 |
28 #include <ApplicationServices/ApplicationServices.h> | 28 #include <ApplicationServices/ApplicationServices.h> |
29 #include "core/platform/graphics/Font.h" | 29 #include "core/platform/graphics/Font.h" |
30 #include "core/rendering/RenderBlockFlow.h" | |
31 #include "core/rendering/RenderText.h" | |
32 #include "platform/geometry/FloatSize.h" | 30 #include "platform/geometry/FloatSize.h" |
33 #include "platform/graphics/TextRun.h" | 31 #include "platform/graphics/TextRun.h" |
34 #include "platform/text/TextBreakIterator.h" | 32 #include "platform/text/TextBreakIterator.h" |
35 #include "wtf/StdLibExtras.h" | 33 #include "wtf/StdLibExtras.h" |
36 #include "wtf/unicode/CharacterNames.h" | 34 #include "wtf/unicode/CharacterNames.h" |
37 | 35 |
38 using namespace std; | 36 using namespace std; |
39 | 37 |
40 namespace WebCore { | 38 namespace WebCore { |
41 | 39 |
42 class TextLayout { | 40 class TextLayout { |
43 public: | 41 public: |
44 static bool isNeeded(RenderText* text, const Font& font) | 42 static bool isNeeded(const TextRun& run, const Font& font) |
45 { | 43 { |
46 TextRun run = RenderBlockFlow::constructTextRun(text, font, text, text->
style()); | |
47 return font.codePath(run) == Font::Complex; | 44 return font.codePath(run) == Font::Complex; |
48 } | 45 } |
49 | 46 |
50 TextLayout(RenderText* text, const Font& font, float xPos) | 47 TextLayout(const TextRun& run, unsigned textLength, const Font& font, float
xPos) |
51 : m_font(font) | 48 : m_font(font) |
52 , m_run(constructTextRun(text, font, xPos)) | 49 , m_run(constructTextRun(run, textLength, font, xPos)) |
53 , m_controller(adoptPtr(new ComplexTextController(&m_font, m_run, true))
) | 50 , m_controller(adoptPtr(new ComplexTextController(&m_font, m_run, true))
) |
54 { | 51 { |
55 } | 52 } |
56 | 53 |
57 float width(unsigned from, unsigned len, HashSet<const SimpleFontData*>* fal
lbackFonts) | 54 float width(unsigned from, unsigned len, HashSet<const SimpleFontData*>* fal
lbackFonts) |
58 { | 55 { |
59 m_controller->advance(from, 0, ByWholeGlyphs, fallbackFonts); | 56 m_controller->advance(from, 0, ByWholeGlyphs, fallbackFonts); |
60 float beforeWidth = m_controller->runWidthSoFar(); | 57 float beforeWidth = m_controller->runWidthSoFar(); |
61 if (m_font.wordSpacing() && from && Font::treatAsSpace(m_run[from])) | 58 if (m_font.wordSpacing() && from && Font::treatAsSpace(m_run[from])) |
62 beforeWidth += m_font.wordSpacing(); | 59 beforeWidth += m_font.wordSpacing(); |
63 m_controller->advance(from + len, 0, ByWholeGlyphs, fallbackFonts); | 60 m_controller->advance(from + len, 0, ByWholeGlyphs, fallbackFonts); |
64 float afterWidth = m_controller->runWidthSoFar(); | 61 float afterWidth = m_controller->runWidthSoFar(); |
65 return afterWidth - beforeWidth; | 62 return afterWidth - beforeWidth; |
66 } | 63 } |
67 | 64 |
68 private: | 65 private: |
69 static TextRun constructTextRun(RenderText* text, const Font& font, float xP
os) | 66 static TextRun constructTextRun(const TextRun& textRun, unsigned textLength,
const Font& font, float xPos) |
70 { | 67 { |
71 TextRun run = RenderBlockFlow::constructTextRun(text, font, text, text->
style()); | 68 TextRun run = textRun; |
72 run.setCharactersLength(text->textLength()); | 69 run.setCharactersLength(textLength); |
73 ASSERT(run.charactersLength() >= run.length()); | 70 ASSERT(run.charactersLength() >= run.length()); |
74 | 71 |
75 run.setXPos(xPos); | 72 run.setXPos(xPos); |
76 return run; | 73 return run; |
77 } | 74 } |
78 | 75 |
79 // ComplexTextController has only references to its Font and TextRun so they
must be kept alive here. | 76 // ComplexTextController has only references to its Font and TextRun so they
must be kept alive here. |
80 Font m_font; | 77 Font m_font; |
81 TextRun m_run; | 78 TextRun m_run; |
82 OwnPtr<ComplexTextController> m_controller; | 79 OwnPtr<ComplexTextController> m_controller; |
83 }; | 80 }; |
84 | 81 |
85 PassOwnPtr<TextLayout> Font::createLayout(RenderText* text, float xPos, bool col
lapseWhiteSpace) const | 82 PassOwnPtr<TextLayout> Font::createLayoutForMacComplexText(const TextRun& run, u
nsigned textLength, float xPos, bool collapseWhiteSpace) const |
86 { | 83 { |
87 if (!collapseWhiteSpace || !TextLayout::isNeeded(text, *this)) | 84 if (!collapseWhiteSpace || !TextLayout::isNeeded(run, *this)) |
88 return nullptr; | 85 return nullptr; |
89 return adoptPtr(new TextLayout(text, *this, xPos)); | 86 return adoptPtr(new TextLayout(run, textLength, *this, xPos)); |
90 } | 87 } |
91 | 88 |
92 void Font::deleteLayout(TextLayout* layout) | 89 void Font::deleteLayout(TextLayout* layout) |
93 { | 90 { |
94 delete layout; | 91 delete layout; |
95 } | 92 } |
96 | 93 |
97 float Font::width(TextLayout& layout, unsigned from, unsigned len, HashSet<const
SimpleFontData*>* fallbackFonts) | 94 float Font::width(TextLayout& layout, unsigned from, unsigned len, HashSet<const
SimpleFontData*>* fallbackFonts) |
98 { | 95 { |
99 return layout.width(from, len, fallbackFonts); | 96 return layout.width(from, len, fallbackFonts); |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 | 718 |
722 lastCharacterIndex = characterIndex; | 719 lastCharacterIndex = characterIndex; |
723 } | 720 } |
724 if (!isMonotonic) | 721 if (!isMonotonic) |
725 complexTextRun.setIsNonMonotonic(); | 722 complexTextRun.setIsNonMonotonic(); |
726 } | 723 } |
727 m_totalWidth += widthSinceLastCommit; | 724 m_totalWidth += widthSinceLastCommit; |
728 } | 725 } |
729 | 726 |
730 } // namespace WebCore | 727 } // namespace WebCore |
OLD | NEW |