aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorsgeerken <devnull@localhost>2012-07-06 01:28:44 +0200
committersgeerken <devnull@localhost>2012-07-06 01:28:44 +0200
commit0c3a5744d317e30bce7b6f067c5c3ed25e6fb063 (patch)
tree05860660110ed39d527c271eacb6b1f822344336 /dw
parent4253a0888d6154beecc1d64346d0d810dedf5658 (diff)
Attribute "lang" is evaluated for hyphenation; part of dw:core::style::Style.y
Diffstat (limited to 'dw')
-rw-r--r--dw/hyphenator.cc3
-rw-r--r--dw/style.cc6
-rw-r--r--dw/style.hh4
-rw-r--r--dw/textblock_linebreaking.cc19
4 files changed, 22 insertions, 10 deletions
diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc
index 861a1330..5c84fe99 100644
--- a/dw/hyphenator.cc
+++ b/dw/hyphenator.cc
@@ -65,8 +65,7 @@ Hyphenator *Hyphenator::getHyphenator (core::Platform *platform,
Hyphenator *hyphenator = hyphenators->get (pair);
if (hyphenator)
delete pair;
- else
- {
+ else {
// TODO Much hard-coded!
char filename [256];
sprintf (filename, "/usr/local/lib/dillo/hyphenation/%s.pat", language);
diff --git a/dw/style.cc b/dw/style.cc
index a2240a9e..2a1d4088 100644
--- a/dw/style.cc
+++ b/dw/style.cc
@@ -37,6 +37,7 @@ namespace style {
void StyleAttrs::initValues ()
{
x_link = -1;
+ x_lang[0] = x_lang[1] = 0;
x_img = -1;
x_tooltip = NULL;
textDecoration = TEXT_DECORATION_NONE;
@@ -144,6 +145,8 @@ bool StyleAttrs::equals (object::Object *other) {
listStyleType == otherAttrs->listStyleType &&
cursor == otherAttrs->cursor &&
x_link == otherAttrs->x_link &&
+ x_lang[0] == otherAttrs->x_lang[0] &&
+ x_lang[1] == otherAttrs->x_lang[1] &&
x_img == otherAttrs->x_img &&
x_tooltip == otherAttrs->x_tooltip);
}
@@ -182,6 +185,7 @@ int StyleAttrs::hashValue () {
listStyleType +
cursor +
x_link +
+ x_lang[0] + x_lang[1] +
x_img +
(intptr_t) x_tooltip;
}
@@ -267,6 +271,8 @@ void Style::copyAttrs (StyleAttrs *attrs)
listStyleType = attrs->listStyleType;
cursor = attrs->cursor;
x_link = attrs->x_link;
+ x_lang[0] = attrs->x_lang[0];
+ x_lang[1] = attrs->x_lang[1];
x_img = attrs->x_img;
x_tooltip = attrs->x_tooltip;
}
diff --git a/dw/style.hh b/dw/style.hh
index f69e5015..2422bfa9 100644
--- a/dw/style.hh
+++ b/dw/style.hh
@@ -468,6 +468,10 @@ public:
int x_link;
int x_img;
Tooltip *x_tooltip;
+ char x_lang[2]; /* Either x_lang[0] == x_lang[1] == 0 (no language
+ set), or x_lang contains the RFC 1766 country
+ code in lower case letters. (Only two letters
+ allowed, currently.) */
void initValues ();
void resetValues ();
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 8383a777..b6c080b1 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -463,6 +463,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
Word *word1 = words->getRef(breakPos);
if (word1->badnessAndPenalty.lineTight () &&
word1->canBeHyphenated &&
+ word1->style->x_lang[0] &&
word1->content.type == core::Content::TEXT &&
Hyphenator::isHyphenationCandidate (word1->content.text))
hyphenatedWord = breakPos;
@@ -471,6 +472,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
breakPos + 1 < words->size ()) {
Word *word2 = words->getRef(breakPos + 1);
if (word2->canBeHyphenated &&
+ word2->style->x_lang[0] &&
word2->content.type == core::Content::TEXT &&
Hyphenator::isHyphenationCandidate (word2->content.text))
hyphenatedWord = breakPos + 1;
@@ -507,18 +509,19 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
int Textblock::hyphenateWord (int wordIndex)
{
- PRINTF ("[%p] considering to hyphenate word %d: '%s'\n",
- this, wordIndex, words->getRef(wordIndex)->content.text);
-
+ 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 (), "de"); // TODO lang
-
+ Hyphenator::getHyphenator (layout->getPlatform (), lang);
+ PRINTF ("[%p] considering to hyphenate word %d, '%s', in language '%s'\n",
+ this, wordIndex, words->getRef(wordIndex)->content.text, langf);
int numBreaks;
int *breakPos =
- hyphenator->hyphenateWord (words->getRef(wordIndex)->content.text,
- &numBreaks);
+ hyphenator->hyphenateWord (hyphenatedWord->content.text, &numBreaks);
+
if (numBreaks > 0) {
- Word origWord = words->get(wordIndex);
+ Word origWord = *hyphenatedWord;
core::Requisition wordSize[numBreaks + 1];
calcTextSizes (origWord.content.text, strlen (origWord.content.text),