summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2010-05-21 07:52:45 +0000
committertavmjong-free <tavmjong@free.fr>2010-05-21 07:52:45 +0000
commit9f10079c170c5903e3ea8dd56fedb6e98fef5c8b (patch)
tree498a00e881ee44ed12f4592f0d403ef6d71a3369 /src
parentAbout Screen for 0.48 - this way it gets in the alpha too (diff)
downloadinkscape-9f10079c170c5903e3ea8dd56fedb6e98fef5c8b.tar.gz
inkscape-9f10079c170c5903e3ea8dd56fedb6e98fef5c8b.zip
Subtract letter_spacing from width at end of line so center
alignment works as expected. (bzr r9436)
Diffstat (limited to 'src')
-rw-r--r--src/libnrtype/Layout-TNG-Compute.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libnrtype/Layout-TNG-Compute.cpp b/src/libnrtype/Layout-TNG-Compute.cpp
index f6b9688bb..518df152f 100644
--- a/src/libnrtype/Layout-TNG-Compute.cpp
+++ b/src/libnrtype/Layout-TNG-Compute.cpp
@@ -153,6 +153,8 @@ class Layout::Calculator
unsigned whitespace_count;
bool ends_with_whitespace;
double each_whitespace_width;
+ double letter_spacing; // Save so we can subtract from width at end of line (for center justification)
+ double word_spacing;
void setZero();
};
@@ -340,12 +342,21 @@ class Layout::Calculator
span->end.increment();
- if (span->width > maximum_width && !char_attributes.is_white) { // whitespaces don't matter, we can put as many as we want at eol
+ // Width should not include letter_spacing (or word_spacing) after last letter at end of line.
+ // word_spacing is attached to white space that is already removed from line end (?)
+ double test_width = span->width - text_source->style->letter_spacing.computed;
+
+ // Save letter_spacing and word_spacing for subtraction later if span is last span in line.
+ span->letter_spacing = text_source->style->letter_spacing.computed;
+ span->word_spacing = text_source->style->word_spacing.computed;
+
+ if (test_width > maximum_width && !char_attributes.is_white) { // whitespaces don't matter, we can put as many as we want at eol
TRACE(("span %d exceeded scanrun; width = %f chars = %d\n", span->start.iter_span - para.unbroken_spans.begin(), span->width, char_count));
return false;
}
} while (span->end.char_byte != 0); // while we haven't wrapped to the next span
+
TRACE(("fitted span %d width = %f chars = %d\n", span->start.iter_span - para.unbroken_spans.begin(), span->width, char_count));
return true;
}
@@ -369,7 +380,7 @@ class Layout::Calculator
case RIGHT:
return it_chunk->x - it_chunk->text_width;
case CENTER:
- return it_chunk->x - it_chunk->text_width / 2;
+ return it_chunk->x - it_chunk->text_width/ 2;
}
}
@@ -1337,6 +1348,13 @@ bool Layout::Calculator::_buildChunksInScanRun(ParagraphInfo const &para,
chunk_info->back().whitespace_count--;
}
+ if (!chunk_info->empty() && !chunk_info->back().broken_spans.empty() ) {
+ // for justification we need to discard line-spacing and word-spacing at end of the chunk
+ chunk_info->back().broken_spans.back().width -= chunk_info->back().broken_spans.back().letter_spacing;
+ chunk_info->back().text_width -= chunk_info->back().broken_spans.back().letter_spacing;
+ TRACE(("width after subtracting last letter_spacing: %f\n", chunk_info->back().broken_spans.back().width));
+ }
+
return true;
}