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

Side by Side Diff: content/renderer/hyphenator/hyphenator.h

Issue 9545017: Adds a hy-phen-ator. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
6 #define CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
7 #pragma once
8
9 #include <vector>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/platform_file.h"
13 #include "base/string16.h"
14 #include "content/common/content_export.h"
15
16 namespace file_util {
17 class MemoryMappedFile;
18 }
19
20 typedef struct _HyphenDict HyphenDict;
21
22 namespace content {
23
24 // A class that hyphenates a word. This class encapsulates the hyphen library
25 // and manages resources used by the library. When this class uses a huge
26 // dictionary, it takes lots of memory (~1.3MB for English). A renderer should
27 // create this object only when it renders a page that needs hyphenation and
28 // deletes it when it moves to a page that does not need hyphenation.
29 class CONTENT_EXPORT Hyphenator {
30 public:
31 explicit Hyphenator(base::PlatformFile file);
32 ~Hyphenator();
33
34 // Initializes the hyphen library and allocates resources needed for
35 // hyphenation.
36 bool Initialize();
37
38 // Returns the last hyphenation point, the position where we can insert a
39 // hyphen, before the given position. If there are not any hyphenation points,
40 // this function returns 0.
41 size_t ComputeLastHyphenLocation(const string16& word, size_t before_index);
42
43 private:
44 // The dictionary used by the hyphen library.
45 HyphenDict* dictionary_;
46
47 // The dictionary file and its memory-mapping object. (Our copy of the hyphen
48 // library uses a memory-mapped file opened by a browser so renderers can use
49 // it without opening the file.)
50 base::PlatformFile rule_file_;
51 scoped_ptr<file_util::MemoryMappedFile> rule_map_;
52
53 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same
54 // word multiple times to find the best hyphenation point when it finds a line
55 // break. On the other hand, the hyphen library returns all hyphenation points
56 // for a word. This class caches the hyphenation points returned by the hyphen
57 // library to avoid calling the library multiple times.
58 string16 word_;
59 bool result_;
60 std::vector<int> hyphen_offsets_;
61
62 DISALLOW_COPY_AND_ASSIGN(Hyphenator);
63 };
64
65 } // namespace content
66
67 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698