summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/hyphenator.cc41
-rw-r--r--dw/hyphenator.hh21
-rw-r--r--dw/textblock_linebreaking.cc6
-rw-r--r--test/liang.cc4
-rw-r--r--test/trie.cc5
5 files changed, 27 insertions, 50 deletions
diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc
index cec5a9d8..4fe9433b 100644
--- a/dw/hyphenator.cc
+++ b/dw/hyphenator.cc
@@ -19,15 +19,11 @@ using namespace lout::misc;
namespace dw {
-HashTable <TypedPair <TypedPointer <core::Platform>, ConstString>,
- Hyphenator> *Hyphenator::hyphenators =
- new HashTable <TypedPair <TypedPointer <core::Platform>, ConstString>,
- Hyphenator> (true, true);
+HashTable <String, Hyphenator> *Hyphenator::hyphenators =
+ new HashTable <String, Hyphenator> (true, true);
-Hyphenator::Hyphenator (core::Platform *platform,
- const char *patFile, const char *excFile, int pack)
+Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
{
- this->platform = platform;
trie = NULL; // As long we are not sure whether a pattern file can be read.
char buf[PATH_MAX + 1];
@@ -91,20 +87,13 @@ Hyphenator::~Hyphenator ()
delete exceptions;
}
-Hyphenator *Hyphenator::getHyphenator (core::Platform *platform,
- const char *lang)
+Hyphenator *Hyphenator::getHyphenator (const char *lang)
{
- // TODO Not very efficient. Other key than TypedPair?
- // (Keeping the parts of the pair on the stack does not help, since
- // ~TypedPair deletes them, so they have to be kept on the heap.)
- TypedPair <TypedPointer <core::Platform>, ConstString> *pair =
- new TypedPair <TypedPointer <core::Platform>,
- ConstString> (new TypedPointer <core::Platform> (platform),
- new String (lang));
-
- Hyphenator *hyphenator = hyphenators->get (pair);
+ String *langString = new String (lang);
+
+ Hyphenator *hyphenator = hyphenators->get (langString);
if (hyphenator)
- delete pair;
+ delete langString;
else {
char patFile [PATH_MAX];
snprintf (patFile, sizeof (patFile), "%s/hyphenation/%s.pat",
@@ -116,8 +105,8 @@ Hyphenator *Hyphenator::getHyphenator (core::Platform *platform,
//printf ("Loading hyphenation patterns for language '%s' from '%s' and "
// "exceptions from '%s' ...\n", lang, patFile, excFile);
- hyphenator = new Hyphenator (platform, patFile, excFile);
- hyphenators->put (pair, hyphenator);
+ hyphenator = new Hyphenator (patFile, excFile);
+ hyphenators->put (langString, hyphenator);
}
//lout::misc::StringBuffer sb;
@@ -221,7 +210,8 @@ bool Hyphenator::isCharPartOfActualWord (char *s)
/**
* Given a word, returns a list of the possible hyphenation points.
*/
-int *Hyphenator::hyphenateWord(const char *word, int *numBreaks)
+int *Hyphenator::hyphenateWord(core::Platform *platform,
+ const char *word, int *numBreaks)
{
if ((trie == NULL && exceptions ==NULL) || !isHyphenationCandidate (word)) {
*numBreaks = 0;
@@ -261,7 +251,7 @@ int *Hyphenator::hyphenateWord(const char *word, int *numBreaks)
} else
nextStart = end;
- hyphenateSingleWord (wordLc + start, start, &breakPos);
+ hyphenateSingleWord (platform, wordLc + start, start, &breakPos);
start = nextStart;
}
@@ -279,8 +269,9 @@ int *Hyphenator::hyphenateWord(const char *word, int *numBreaks)
* Hyphenate a single word, which only consists of lowercase
* characters. Store break positions + "offset" in "breakPos".
*/
-void Hyphenator::hyphenateSingleWord(char *wordLc, int offset,
- SimpleVector <int> *breakPos)
+void Hyphenator::hyphenateSingleWord(core::Platform *platform,
+ char *wordLc, int offset,
+ SimpleVector <int> *breakPos)
{
// If the word is an exception, get the stored points.
Vector <Integer> *exceptionalBreaks;
diff --git a/dw/hyphenator.hh b/dw/hyphenator.hh
index b02265ec..7716b857 100644
--- a/dw/hyphenator.hh
+++ b/dw/hyphenator.hh
@@ -86,16 +86,7 @@ class TrieBuilder {
class Hyphenator: public lout::object::Object
{
static lout::container::typed::HashTable
- <lout::object::TypedPair <lout::object::TypedPointer <core::Platform>,
- lout::object::ConstString>,
- Hyphenator> *hyphenators;
-
- /*
- * Actually, only one method in Platform is needed:
- * textToLower(). And, IMO, this method is actually not platform
- * independent, but based on UTF-8. Clarify? Change?
- */
- core::Platform *platform;
+ <lout::object::String, Hyphenator> *hyphenators;
Trie *trie;
lout::container::typed::HashTable <lout::object::ConstString,
@@ -105,19 +96,17 @@ class Hyphenator: public lout::object::Object
void insertPattern (TrieBuilder *trieBuilder, char *s);
void insertException (char *s);
- void hyphenateSingleWord(char *wordLc, int offset,
+ void hyphenateSingleWord(core::Platform *platform, char *wordLc, int offset,
lout::misc::SimpleVector <int> *breakPos);
bool isCharPartOfActualWord (char *s);
public:
- Hyphenator (core::Platform *platform,
- const char *patFile, const char *excFile, int pack = 256);
+ Hyphenator (const char *patFile, const char *excFile, int pack = 256);
~Hyphenator();
- static Hyphenator *getHyphenator (core::Platform *platform,
- const char *language);
+ static Hyphenator *getHyphenator (const char *language);
static bool isHyphenationCandidate (const char *word);
- int *hyphenateWord(const char *word, int *numBreaks);
+ int *hyphenateWord(core::Platform *platform, const char *word, int *numBreaks);
void saveTrie (FILE *fp) { trie->save (fp); };
};
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 4900a9a2..28c2999b 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -736,13 +736,13 @@ int Textblock::hyphenateWord (int wordIndex)
Word *hyphenatedWord = words->getRef(wordIndex);
char lang[3] = { hyphenatedWord->style->x_lang[0],
hyphenatedWord->style->x_lang[1], 0 };
- Hyphenator *hyphenator =
- Hyphenator::getHyphenator (layout->getPlatform (), lang);
+ Hyphenator *hyphenator = Hyphenator::getHyphenator (lang);
PRINTF ("[%p] considering to hyphenate word %d, '%s', in language '%s'\n",
this, wordIndex, words->getRef(wordIndex)->content.text, lang);
int numBreaks;
int *breakPos =
- hyphenator->hyphenateWord (hyphenatedWord->content.text, &numBreaks);
+ hyphenator->hyphenateWord (layout->getPlatform (),
+ hyphenatedWord->content.text, &numBreaks);
if (numBreaks > 0) {
Word origWord = *hyphenatedWord;
diff --git a/test/liang.cc b/test/liang.cc
index b1161d9f..a1bc2442 100644
--- a/test/liang.cc
+++ b/test/liang.cc
@@ -4,10 +4,10 @@
void hyphenateWord (dw::core::Platform *p, const char *word)
{
- dw::Hyphenator *h = dw::Hyphenator::getHyphenator (p, "de");
+ dw::Hyphenator *h = dw::Hyphenator::getHyphenator ("de");
int numBreaks;
- int *breakPos = h->hyphenateWord (word, &numBreaks);
+ int *breakPos = h->hyphenateWord (p, word, &numBreaks);
for (int i = 0; i < numBreaks + 1; i++) {
if (i != 0)
printf (" \xc2\xad ");
diff --git a/test/trie.cc b/test/trie.cc
index 628daabf..41b56c70 100644
--- a/test/trie.cc
+++ b/test/trie.cc
@@ -1,10 +1,7 @@
-#include "../dw/fltkcore.hh"
#include "../dw/hyphenator.hh"
int main (int argc, char *argv[])
{
- dw::fltk::FltkPlatform p;
-
if (argc < 2) {
fprintf(stderr, "Usage: trie <pattern file>\n");
exit (1);
@@ -12,6 +9,6 @@ int main (int argc, char *argv[])
/* Use pack = 1024 to create a really small trie - can take a while.
*/
- dw::Hyphenator hyphenator (&p, argv[1], NULL, 1024);
+ dw::Hyphenator hyphenator (argv[1], NULL, 1024);
hyphenator.saveTrie (stdout);
}