commit 288e467a6083a547a3996e69b6ba0ea1d430e70b
parent 8db8f0b44f5f1c727be32114a22863bf72355a76
Author: lumidify <nobody@lumidify.org>
Date: Tue, 26 May 2020 11:23:50 +0200
Fix wrapping again
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/text_buffer.c b/text_buffer.c
@@ -77,7 +77,6 @@ ltk_text_line_cleanup_soft_lines(struct ltk_array_line *soft_lines, int old_len)
ltk_array_resize_line(soft_lines, soft_lines->len);
}
-/* FIXME: this is a few pixels off! */
void
ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
struct timeval t1, t2;
@@ -126,6 +125,10 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
if (cur->dir == HB_DIRECTION_RTL) {
cur_start = cur->glyphs[cur->num_glyphs - 1].x_abs + cur->glyphs[cur->num_glyphs - 1].x_advance;
int i = cur->num_glyphs - 1;
+ /* This is needed to properly break a run over multiple lines.
+ We can't just reuse sl->glyph_index because that might be
+ located in another run */
+ int cur_start_index = cur->num_glyphs - 1;
while (i >= 0) {
glyph = &cur->glyphs[i];
int cur_w = sl->w + cur_start - glyph->x_abs;
@@ -135,8 +138,8 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
if (char_break == -1 && cur->glyphs[j].cluster != glyph->cluster)
char_break = j;
if ((j != i && tl->log_buf->buf[cur->glyphs[j].cluster] == 0x20) ||
- j == cur->num_glyphs - 1 || sl->len == 0) {
- if (j == cur->num_glyphs - 1 &&
+ j == cur_start_index || sl->len == 0) {
+ if (j == cur_start_index &&
tl->log_buf->buf[cur->glyphs[j].cluster] != 0x20) {
if (sl->len == 0) {
char_break = char_break == -1 ? j : char_break;
@@ -159,6 +162,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
tl->soft_lines->buf[cur_index] :
ltk_soft_line_create();
sl->glyph_index = i;
+ cur_start_index = i;
sl->run = cur;
sl->len = 0;
sl->w = 0;
@@ -180,6 +184,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
} else {
cur_start = cur->glyphs[0].x_abs;
int i = 0;
+ int cur_start_index = 0;
while (i < cur->num_glyphs) {
glyph = &cur->glyphs[i];
/* FIXME: This uses x_advance instead of glyph width so it works correctly
@@ -192,8 +197,8 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
if (char_break == -1 && cur->glyphs[j].cluster != glyph->cluster)
char_break = j;
if ((j != i && tl->log_buf->buf[cur->glyphs[j].cluster] == 0x20) ||
- j == 0 || sl->len == 0) {
- if (j == 0 &&
+ j == cur_start_index || sl->len == 0) {
+ if (j == cur_start_index &&
tl->log_buf->buf[cur->glyphs[j].cluster] != 0x20) {
if (sl->len == 0) {
char_break = char_break == -1 ? j : char_break;
@@ -216,6 +221,7 @@ ltk_text_line_wrap(struct ltk_text_line *tl, int max_width) {
tl->soft_lines->buf[cur_index] :
ltk_soft_line_create();
sl->glyph_index = i;
+ cur_start_index = i;
sl->run = cur;
sl->len = 0;
sl->w = 0;
diff --git a/text_edit.c b/text_edit.c
@@ -61,6 +61,7 @@ ltk_text_edit_draw(LtkTextEdit *te) {
);
}
+/* FIXME: only recalculate if largest line is too wide */
void
ltk_text_edit_resize(LtkTextEdit *te, int orig_w, int orig_h) {
if (te->tl->soft_lines->len == 1 &&