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

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
jochen (gone - plz use gerrit) 2012/07/02 15:33:01 all code in content/ should go into the namespace
Hironori Bono 2012/07/10 09:22:09 Done. Thanks for your comment. (I did not notice i
20 typedef struct _HyphenDict HyphenDict;
21
22 // A class that hyphenates a word. This class encapsulates the hyphen library
23 // and manages resources used by the library. When this class uses a huge
24 // dictionary, it takes lots of memory. A renderer should create this object
tony 2012/06/28 20:06:44 Nit: Would be nice to give actual size estimates h
25 // only when it renders a page that needs hyphenation and deletes it when it
26 // moves to a page that does not need hyphenation as listed in the following
27 // snippet.
28 //
29 // base::PlatformFile file("hyphen.us");
30 // scoped_ptr<Hyphenator> hyphenator(new Hyphenator(file));
31 // size_t pos = hyphenator->ComputeLastHyphenLocation("organize", 8);
32 // ...
33 // hyphenator.reset();
34 //
35 class CONTENT_EXPORT Hyphenator {
jochen (gone - plz use gerrit) 2012/07/02 15:33:01 why is this a CONTENT_EXPORT class if it's not in
Hironori Bono 2012/07/10 09:22:09 Even though this class is not a public one, it is
jochen (gone - plz use gerrit) 2012/07/10 09:46:06 Usually, we have different macros for this case (s
36 public:
37 explicit Hyphenator(base::PlatformFile file);
38 ~Hyphenator();
39
40 // Initializes the hyphen library and allocates resources needed for
41 // hyphenation.
42 bool Initialize();
43
44 // Returns the last hyphenation point, the position where we can insert a
45 // hyphen, before the given position. If there are not any hyphenation points,
46 // this function returns 0.
47 size_t ComputeLastHyphenLocation(const string16& word, size_t before_index);
48
49 private:
50 // The dictionary used by the hyphen library.
51 HyphenDict* dictionary_;
52
53 // The dictionary file and its memory-mapping object. (Our copy of the hyphen
54 // library uses a memory-mapped file opened by a browser so renderers can use
55 // it without opening the file.)
56 base::PlatformFile rule_file_;
57 scoped_ptr<file_util::MemoryMappedFile> rule_map_;
58
59 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same
60 // word multiple times to find the best hyphenation point when it finds a line
61 // break. On the other hand, the hyphen library returns all hyphenation points
62 // for a word. This class caches the hyphenation points returned by the hyphen
63 // library to avoid calling the library multiple times.
64 string16 word_;
65 bool result_;
66 std::vector<int> hyphen_offsets_;
67 };
jochen (gone - plz use gerrit) 2012/07/02 15:33:01 DISALLOW_COPY_AND_ASSIGN?
Hironori Bono 2012/07/10 09:22:09 Done. Thanks for noticing it.
68
69 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698