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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/hyphenator/hyphenator.h
===================================================================
--- content/renderer/hyphenator/hyphenator.h (revision 0)
+++ content/renderer/hyphenator/hyphenator.h (revision 0)
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
+#define CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
+#pragma once
+
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/platform_file.h"
+#include "base/string16.h"
+#include "content/common/content_export.h"
+
+namespace file_util {
+class MemoryMappedFile;
+}
+
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
+typedef struct _HyphenDict HyphenDict;
+
+// A class that hyphenates a word. This class encapsulates the hyphen library
+// and manages resources used by the library. When this class uses a huge
+// 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
+// only when it renders a page that needs hyphenation and deletes it when it
+// moves to a page that does not need hyphenation as listed in the following
+// snippet.
+//
+// base::PlatformFile file("hyphen.us");
+// scoped_ptr<Hyphenator> hyphenator(new Hyphenator(file));
+// size_t pos = hyphenator->ComputeLastHyphenLocation("organize", 8);
+// ...
+// hyphenator.reset();
+//
+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
+ public:
+ explicit Hyphenator(base::PlatformFile file);
+ ~Hyphenator();
+
+ // Initializes the hyphen library and allocates resources needed for
+ // hyphenation.
+ bool Initialize();
+
+ // Returns the last hyphenation point, the position where we can insert a
+ // hyphen, before the given position. If there are not any hyphenation points,
+ // this function returns 0.
+ size_t ComputeLastHyphenLocation(const string16& word, size_t before_index);
+
+ private:
+ // The dictionary used by the hyphen library.
+ HyphenDict* dictionary_;
+
+ // The dictionary file and its memory-mapping object. (Our copy of the hyphen
+ // library uses a memory-mapped file opened by a browser so renderers can use
+ // it without opening the file.)
+ base::PlatformFile rule_file_;
+ scoped_ptr<file_util::MemoryMappedFile> rule_map_;
+
+ // A cached result. WebKit often calls ComputeLastHyphenLocation with the same
+ // word multiple times to find the best hyphenation point when it finds a line
+ // break. On the other hand, the hyphen library returns all hyphenation points
+ // for a word. This class caches the hyphenation points returned by the hyphen
+ // library to avoid calling the library multiple times.
+ string16 word_;
+ bool result_;
+ std::vector<int> hyphen_offsets_;
+};
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.
+
+#endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_
Property changes on: content\renderer\hyphenator\hyphenator.h
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698