diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2022-08-02 15:41:46 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2022-08-22 11:52:15 +0100 |
commit | b7b1df089d446e17750d0abfa525c1789b0d7080 (patch) | |
tree | f93acde5f2ecfefa62b8fa5a93537a27f60c0558 | |
parent | 75c431d66c9a627be9bc4eded903052c67819649 (diff) |
Avoid breaking lines repeatedly if they start with space.
The current code, faced with:
"bibble"
" foo"
would result in:
<span>bibble</span>
<span> </span><span> </span><span> </span><span>foo</span>
When considering whether a given char should be added onto the
end of an existing span or not, we were looking for the previous
non-whitespace char as the place to extend from.
Sadly, in the case where we've already encountered a leading space,
that meant we'd create another span needlessly.
Instead, modify the code to accept leading whitespace in spans.
-rw-r--r-- | src/extract.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/extract.c b/src/extract.c index 8e4a801..05bed29 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1118,8 +1118,12 @@ split_to_new_span(extract_alloc_t *alloc, content_t *content, span_t *span0) return span; } +/* +This routine returns the previous non-space-char, UNLESS the span +starts with a space, in which case we accept that one. +*/ static span_t * -find_previous_non_space_char(content_t *content, int *char_num, int *intervening_space) +find_previous_non_space_char_ish(content_t *content, int *char_num, int *intervening_space) { content_t *s; int i; @@ -1134,7 +1138,7 @@ find_previous_non_space_char(content_t *content, int *char_num, int *intervening for (i = span->chars_num-1; i >= 0; i--) { - if (span->chars[i].ucs != 32) + if (span->chars[i].ucs != 32 || i == 0) { *char_num = i; return span; @@ -1204,7 +1208,7 @@ int extract_add_char(extract_t *extract, outf("(%f %f) ucs=% 5i=%c adv=%f", x, y, ucs, (ucs >=32 && ucs< 127) ? ucs : ' ', adv); /* Now, check whether we need to break to a new line, or add (or subtract) a space. */ - span0 = find_previous_non_space_char(&subpage->content, &char_num0, &intervening_space); + span0 = find_previous_non_space_char_ish(&subpage->content, &char_num0, &intervening_space); if (span0 == NULL) { |