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

Side by Side Diff: third_party/WebKit/Source/platform/text/Hyphenation.cpp

Issue 2161683002: Add LayoutLocale class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test stability Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/text/Hyphenation.h" 5 #include "platform/text/Hyphenation.h"
6 6
7 #include "platform/fonts/Font.h"
7 #include "wtf/text/StringView.h" 8 #include "wtf/text/StringView.h"
8 9
9 namespace blink { 10 namespace blink {
10 11
11 Hyphenation::HyphenationMap& Hyphenation::getHyphenationMap()
12 {
13 DEFINE_STATIC_LOCAL(HyphenationMap, hyphenationMap, ());
14 return hyphenationMap;
15 }
16
17 Hyphenation* Hyphenation::get(const AtomicString& locale)
18 {
19 DCHECK(!locale.isNull());
20 Hyphenation::HyphenationMap& hyphenationMap = getHyphenationMap();
21 const auto& it = hyphenationMap.find(locale);
22 if (it != hyphenationMap.end())
23 return it->value.get();
24
25 return hyphenationMap.add(locale, platformGetHyphenation(locale))
26 .storedValue->value.get();
27 }
28
29 void Hyphenation::setForTesting(const AtomicString& locale, PassRefPtr<Hyphenati on> hyphenation)
30 {
31 getHyphenationMap().set(locale, hyphenation);
32 }
33
34 void Hyphenation::clearForTesting()
35 {
36 getHyphenationMap().clear();
37 }
38
39 Vector<size_t, 8> Hyphenation::hyphenLocations(const StringView& text) const 12 Vector<size_t, 8> Hyphenation::hyphenLocations(const StringView& text) const
40 { 13 {
41 Vector<size_t, 8> hyphenLocations; 14 Vector<size_t, 8> hyphenLocations;
42 size_t hyphenLocation = text.length(); 15 size_t hyphenLocation = text.length();
43 if (hyphenLocation <= minimumSuffixLength) 16 if (hyphenLocation <= minimumSuffixLength)
44 return hyphenLocations; 17 return hyphenLocations;
45 hyphenLocation -= minimumSuffixLength; 18 hyphenLocation -= minimumSuffixLength;
46 19
47 while ((hyphenLocation = lastHyphenLocation(text, hyphenLocation)) >= minimu mPrefixLength) 20 while ((hyphenLocation = lastHyphenLocation(text, hyphenLocation)) >= minimu mPrefixLength)
48 hyphenLocations.append(hyphenLocation); 21 hyphenLocations.append(hyphenLocation);
49 22
50 return hyphenLocations; 23 return hyphenLocations;
51 } 24 }
52 25
26 int Hyphenation::minimumPrefixWidth(const Font& font)
27 {
28 // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely
29 // that an hyphenation opportunity exists, so do not bother to look for it.
30 // These are heuristic numbers for performance added in http://wkb.ug/45606
31 const int minimumPrefixWidthNumerator = 5;
32 const int minimumPrefixWidthDenominator = 4;
33 return font.getFontDescription().computedPixelSize()
34 * minimumPrefixWidthNumerator / minimumPrefixWidthDenominator;
35 }
36
53 } // namespace blink 37 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/Hyphenation.h ('k') | third_party/WebKit/Source/platform/text/HyphenationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698