Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: Source/platform/fonts/shaping/CachingWordShaper.cpp

Issue 1192223002: Optimize Complex Text Shaping and Caching (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove TypesettingFeatures check Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "platform/fonts/shaping/CachingWordShaper.h"
28
29 #include "platform/fonts/SimpleFontData.h"
30 #include "platform/fonts/shaping/CachingWordShapeIterator.h"
31 #include "platform/fonts/shaping/HarfBuzzShaper.h"
32 #include "platform/fonts/shaping/ShapeCache.h"
33 #include "wtf/unicode/CharacterNames.h"
34
35 namespace blink {
36
37 CachingWordShaper::CachingWordShaper()
38 {
39 m_shapeCache = new ShapeCache();
40 }
41
42 CachingWordShaper::~CachingWordShaper()
43 {
44 delete m_shapeCache;
45 }
46
47 void CachingWordShaper::clear()
48 {
49 if (m_shapeCache)
50 m_shapeCache->clear();
51 }
52
53 float CachingWordShaper::width(const Font* font, const TextRun& run,
54 HashSet<const SimpleFontData*>* fallbackFonts,
55 FloatRect* glyphBounds)
56 {
57 float width = 0;
58 RefPtr<ShapeResult> wordResult;
59 CachingWordShapeIterator iterator(m_shapeCache, run, font, fallbackFonts);
60 while (iterator.next(&wordResult)) {
61 if (wordResult) {
62 width += wordResult->width();
63 if (glyphBounds)
64 glyphBounds->unite(wordResult->bounds());
65 }
66 }
67
68 return width;
69 }
70
71 float CachingWordShaper::fillGlyphBuffer(const Font* font, const TextRun& run,
72 HashSet<const SimpleFontData*>* fallbackFonts,
73 GlyphBuffer* glyphBuffer, unsigned from, unsigned to)
74 {
75 CachingWordShapeIterator iterator(m_shapeCache, run, font, fallbackFonts);
76 RefPtr<ShapeResult> wordResult;
77 Vector<RefPtr<ShapeResult>> results;
78 while (iterator.next(&wordResult)) {
79 if (wordResult)
80 results.append(wordResult);
81 }
82
83 return ShapeResult::fillGlyphBuffer(results, glyphBuffer, run, from, to);
84 }
85
86 float CachingWordShaper::fillGlyphBufferForTextEmphasis(const Font* font,
87 const TextRun& run, const GlyphData* emphasisData, GlyphBuffer* glyphBuffer,
88 unsigned from, unsigned to)
89 {
90 CachingWordShapeIterator iterator(m_shapeCache, run, font, nullptr);
91 RefPtr<ShapeResult> wordResult;
92 Vector<RefPtr<ShapeResult>> results;
93 while (iterator.next(&wordResult)) {
94 if (wordResult)
95 results.append(wordResult);
96 }
97
98 return ShapeResult::fillGlyphBufferForTextEmphasis(results, glyphBuffer,
99 run, emphasisData, from, to);
100 }
101
102 FloatRect CachingWordShaper::selectionRect(const Font* font, const TextRun& run,
103 const FloatPoint& point, int height, unsigned from, unsigned to)
104 {
105 CachingWordShapeIterator iterator(m_shapeCache, run, font, nullptr);
106 RefPtr<ShapeResult> wordResult;
107 Vector<RefPtr<ShapeResult>> results;
108 float totalWidth = 0;
109 while (iterator.next(&wordResult)) {
110 if (wordResult) {
111 results.append(wordResult);
112 totalWidth += wordResult->width();
113 }
114 }
115
116 return ShapeResult::selectionRect(results, run.direction(), totalWidth,
117 point, height, from, to);
118 }
119
120 }; // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698