aboutsummaryrefslogtreecommitdiff
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
parent4253a0888d6154beecc1d64346d0d810dedf5658 (diff)
Attribute "lang" is evaluated for hyphenation; part of dw:core::style::Style.y
-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
-rw-r--r--src/css.hh1
-rw-r--r--src/html.cc8
-rw-r--r--src/styleengine.cc7
7 files changed, 38 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),
diff --git a/src/css.hh b/src/css.hh
index 532acc01..e81fde62 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -223,6 +223,7 @@ typedef enum {
CSS_PROPERTY_X_COLSPAN,
CSS_PROPERTY_X_ROWSPAN,
PROPERTY_X_LINK,
+ PROPERTY_X_LANG,
PROPERTY_X_IMG,
PROPERTY_X_TOOLTIP,
CSS_PROPERTY_LAST
diff --git a/src/html.cc b/src/html.cc
index 0cee0a8f..22952609 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -3440,6 +3440,14 @@ static void Html_parse_common_attrs(DilloHtml *html, char *tag, int tagsize)
html->styleEngine->setStyle (attrbuf);
}
+ if (tagsize >= 10) { /* TODO prefs.hyphenate? */
+ /* length of "<t lang=i>" */
+ attrbuf = Html_get_attr2(html, tag, tagsize, "lang",
+ HTML_LeftTrim | HTML_RightTrim);
+ if (attrbuf)
+ html->styleEngine->setNonCssHint(PROPERTY_X_LANG, CSS_TYPE_STRING,
+ attrbuf);
+ }
}
static void Html_display_block(DilloHtml *html)
diff --git a/src/styleengine.cc b/src/styleengine.cc
index ea251e32..e94a6d6f 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -601,6 +601,13 @@ void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props) {
case PROPERTY_X_LINK:
attrs->x_link = p->value.intVal;
break;
+ case PROPERTY_X_LANG:
+ attrs->x_lang[0] = tolower (p->value.strVal[0]);
+ if (attrs->x_lang[0])
+ attrs->x_lang[1] = tolower (p->value.strVal[1]);
+ else
+ attrs->x_lang[1] = 0;
+ break;
case PROPERTY_X_IMG:
attrs->x_img = p->value.intVal;
break;