aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-04-15 16:38:12 +0200
committerThomas White <taw@bitwiz.me.uk>2018-04-15 16:38:12 +0200
commita4d11cfb752cb039aa382e18ba2b28601880d497 (patch)
treea5c7a9531791d87802856a6c7a653fda3a1f4d96
parent424f5e382900d48669690188bf153760ba7d390d (diff)
Rationalise interpretation of paragraph spacing
paragraph->height: Just the height of the contents, no spacing paragraph_height(para): The total height including all spacing
-rw-r--r--src/frame.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/frame.c b/src/frame.c
index 037e600..2ff8f16 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -85,9 +85,10 @@ PangoLayout *paragraph_layout(Paragraph *para)
}
+/* Returns the height of the paragraph including all spacing, padding etc */
double paragraph_height(Paragraph *para)
{
- return para->height;
+ return para->height + para->space[2] + para->space[3];
}
@@ -380,7 +381,6 @@ void wrap_paragraph(Paragraph *para, PangoContext *pc, double w,
pango_layout_get_extents(para->layout, NULL, &rect);
para->height = pango_units_to_double(rect.height);
- para->height += para->space[2] + para->space[3];
}
SCBlock *get_newline_at_end(Paragraph *para)
@@ -562,7 +562,7 @@ double total_height(struct frame *fr)
int i;
double t = 0.0;
for ( i=0; i<fr->n_paras; i++ ) {
- t += fr->paras[i]->height;
+ t += paragraph_height(fr->paras[i]);
}
return t;
}
@@ -763,7 +763,7 @@ int find_cursor(struct frame *fr, double x, double y, struct edit_pos *pos)
}
for ( i=0; i<fr->n_paras; i++ ) {
- double npos = pad + fr->paras[i]->height;
+ double npos = pad + paragraph_height(fr->paras[i]);
if ( npos > y ) {
pos->para = i;
if ( fr->paras[i]->type == PARA_TYPE_TEXT ) {
@@ -812,13 +812,13 @@ int get_para_highlight(struct frame *fr, int cursor_para,
para = fr->paras[cursor_para];
for ( i=0; i<cursor_para; i++ ) {
- py += fr->paras[i]->height;
+ py += paragraph_height(fr->paras[i]);
}
- *cx = fr->pad_l + para->space[0];
- *cy = fr->pad_t + py + para->space[2];
- *cw = fr->w - fr->pad_l - fr->pad_r - para->space[0] - para->space[1];
- *ch = para->height - para->space[2] - para->space[3];
+ *cx = fr->pad_l;
+ *cy = fr->pad_t + py;
+ *cw = fr->w - fr->pad_l - fr->pad_r;
+ *ch = paragraph_height(para);
return 0;
}
@@ -843,7 +843,7 @@ int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos,
para = fr->paras[cursor_para];
for ( i=0; i<cursor_para; i++ ) {
- py += fr->paras[i]->height;
+ py += paragraph_height(fr->paras[i]);
}
if ( para->type != PARA_TYPE_TEXT ) {