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

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
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/hyphenator/hyphenator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
8 #include <vector>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/platform_file.h"
12 #include "base/string16.h"
13 #include "content/common/content_export.h"
14
15 namespace file_util {
16 class MemoryMappedFile;
17 }
18
19 typedef struct _HyphenDict HyphenDict;
20
21 namespace content {
22
23 // A class that hyphenates a word. This class encapsulates the hyphen library
24 // and manages resources used by the library. When this class uses a huge
25 // dictionary, it takes lots of memory (~1.3MB for English). A renderer should
26 // create this object only when it renders a page that needs hyphenation and
27 // deletes it when it moves to a page that does not need hyphenation.
28 class CONTENT_EXPORT Hyphenator {
29 public:
30 explicit Hyphenator(base::PlatformFile file);
31 ~Hyphenator();
32
33 // Initializes the hyphen library and allocates resources needed for
34 // hyphenation.
35 bool Initialize();
36
37 // Returns the last hyphenation point, the position where we can insert a
38 // hyphen, before the given position. If there are not any hyphenation points,
39 // this function returns 0.
40 size_t ComputeLastHyphenLocation(const string16& word, size_t before_index);
41
42 private:
43 // The dictionary used by the hyphen library.
44 HyphenDict* dictionary_;
45
46 // The dictionary file and its memory-mapping object. (Our copy of the hyphen
47 // library uses a memory-mapped file opened by a browser so renderers can use
48 // it without opening the file.)
49 base::PlatformFile rule_file_;
50 scoped_ptr<file_util::MemoryMappedFile> rule_map_;
51
52 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same
53 // word multiple times to find the best hyphenation point when it finds a line
54 // break. On the other hand, the hyphen library returns all hyphenation points
55 // for a word. This class caches the hyphenation points returned by the hyphen
56 // library to avoid calling the library multiple times.
57 string16 word_;
58 bool result_;
59 std::vector<int> hyphen_offsets_;
60
61 DISALLOW_COPY_AND_ASSIGN(Hyphenator);
62 };
63
64 } // namespace content
65
66 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/hyphenator/hyphenator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698