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

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

Issue 2161683002: Add LayoutLocale class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test stability Created 4 years, 5 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 #ifndef Hyphenation_h 5 #ifndef Hyphenation_h
6 #define Hyphenation_h 6 #define Hyphenation_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/fonts/Font.h"
10 #include "wtf/Forward.h" 9 #include "wtf/Forward.h"
11 #include "wtf/HashMap.h" 10 #include "wtf/HashMap.h"
12 #include "wtf/RefCounted.h" 11 #include "wtf/RefCounted.h"
13 #include "wtf/text/AtomicStringHash.h" 12 #include "wtf/text/AtomicStringHash.h"
14 #include "wtf/text/StringHash.h" 13 #include "wtf/text/StringHash.h"
15 14
16 namespace blink { 15 namespace blink {
17 16
17 class Font;
18
18 class PLATFORM_EXPORT Hyphenation : public RefCounted<Hyphenation> { 19 class PLATFORM_EXPORT Hyphenation : public RefCounted<Hyphenation> {
19 public: 20 public:
20 virtual ~Hyphenation() {} 21 virtual ~Hyphenation() {}
21 22
22 static Hyphenation* get(const AtomicString& locale);
23
24 virtual size_t lastHyphenLocation(const StringView&, size_t beforeIndex) con st = 0; 23 virtual size_t lastHyphenLocation(const StringView&, size_t beforeIndex) con st = 0;
25 virtual Vector<size_t, 8> hyphenLocations(const StringView&) const; 24 virtual Vector<size_t, 8> hyphenLocations(const StringView&) const;
26 25
27 static const unsigned minimumPrefixLength = 2; 26 static const unsigned minimumPrefixLength = 2;
28 static const unsigned minimumSuffixLength = 2; 27 static const unsigned minimumSuffixLength = 2;
29 static int minimumPrefixWidth(const Font&); 28 static int minimumPrefixWidth(const Font&);
30 29
31 static void setForTesting(const AtomicString& locale, PassRefPtr<Hyphenation >);
32 static void clearForTesting();
33
34 private: 30 private:
35 using HyphenationMap = HashMap<AtomicString, RefPtr<Hyphenation>, CaseFoldin gHash>; 31 friend class LayoutLocale;
36
37 static HyphenationMap& getHyphenationMap();
38 static PassRefPtr<Hyphenation> platformGetHyphenation(const AtomicString& lo cale); 32 static PassRefPtr<Hyphenation> platformGetHyphenation(const AtomicString& lo cale);
39 }; 33 };
40 34
41 inline int Hyphenation::minimumPrefixWidth(const Font& font)
42 {
43 // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely
44 // that an hyphenation opportunity exists, so do not bother to look for it.
45 // These are heuristic numbers for performance added in http://wkb.ug/45606
46 const int minimumPrefixWidthNumerator = 5;
47 const int minimumPrefixWidthDenominator = 4;
48 return font.getFontDescription().computedPixelSize()
49 * minimumPrefixWidthNumerator / minimumPrefixWidthDenominator;
50 }
51
52 } // namespace blink 35 } // namespace blink
53 36
54 #endif // Hyphenation_h 37 #endif // Hyphenation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698