aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-03-16 22:30:34 +0100
committerThomas White <taw@bitwiz.org.uk>2016-03-16 22:30:34 +0100
commit620b7da4f4b002ac0fdb6e5663c6db392e7a59dd (patch)
treecd410c7085ff3feddfd8aa042e48dbf622679978 /src
parent8d69fd3d476179768d9e13d79261c5a1a7cacda4 (diff)
Final fixes for text in empty frame
Diffstat (limited to 'src')
-rw-r--r--src/frame.h1
-rw-r--r--src/sc_editor.c115
-rw-r--r--src/sc_interp.c6
3 files changed, 62 insertions, 60 deletions
diff --git a/src/frame.h b/src/frame.h
index cd1bfa4..8b1a645 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -68,6 +68,7 @@ struct frame
/* The font which will be used by default for this frame */
PangoFontDescription *fontdesc;
+ double col[4];
/* The rectangle allocated to this frame, determined by the renderer */
double x;
diff --git a/src/sc_editor.c b/src/sc_editor.c
index c2942f9..42a0b08 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -813,8 +813,6 @@ static void update_local(SCEditor *e, struct frame *fr, int line, int bn)
{
struct wrap_box *box = bv_box(fr->lines[line].boxes, bn);
- /* Shape the box again
- * FIXME: Number of segments could change, need to PangoAnalyse again */
shape_box(box);
/* Wrap the paragraph again */
@@ -845,72 +843,25 @@ static void shift_box_offsets(struct frame *fr, struct wrap_box *box, int n)
}
-static void insert_text(char *t, SCEditor *e)
+static void fixup_line_breaks(struct wrap_box *sbox, struct wrap_line *line,
+ int sbx, int cursor_pos, PangoLanguage *lang)
{
- int sln, sbx, sps, sseg;
- struct wrap_box *sbox;
- struct frame *fr = e->cursor_frame;
const char *text;
size_t len_bytes;
int len_chars;
PangoLogAttr *log_attrs;
int offs;
- int err = 0;
-
- printf("insert! --------------------------------------------------------\n");
-
- if ( fr == NULL ) return;
-
- /* If this is, say, the top level frame, do nothing */
- if ( fr->boxes == NULL ) return;
-
- sln = e->cursor_line;
- sbx = e->cursor_box;
- sps = e->cursor_pos;
- sbox = bv_box(e->cursor_frame->lines[sln].boxes, sbx);
-
- if ( sbox->type == WRAP_BOX_NOTHING ) {
- printf("Upgrading nothing box %p to Pango box\n", sbox);
- sbox->type = WRAP_BOX_PANGO;
- sbox->col[0] = 0.0;
- sbox->col[1] = 0.0;
- sbox->col[2] = 0.0;
- sbox->col[3] = 0.0;
- sbox->fontdesc = fr->fontdesc;
- sbox->n_segs = 1;
- sbox->segs = malloc(sizeof(struct text_seg));
- sbox->len_chars = 0;
- sbox->segs[0].glyphs = NULL;
- sbox->segs[0].offs_char = sbox->offs_char;
- sbox->segs[0].len_chars = 0;
- }
-
- sseg = which_segment(sbox, sps, &err);
- if ( err ) return;
-
- cur_box_diag(e);
- printf("sps=%i, offs_char=%i\n", sps, sbox->offs_char);
- if ( sbox->type == WRAP_BOX_NOTHING ) {
- printf("Editing a nothing box!\n");
- return;
- }
-
- sc_insert_text(sbox->scblock, sps+sbox->offs_char, t);
-
- /* The box must be analysed by Pango again, because the segments
- * might have changed */
- itemize_and_shape(sbox, e->pc);
+ return; /* FIXME ! */
text = sc_block_contents(sbox->scblock);
len_bytes = strlen(text);
len_chars = g_utf8_strlen(text, -1);
-
log_attrs = malloc((len_chars+1)*sizeof(PangoLogAttr));
if ( log_attrs == NULL ) return;
- pango_get_log_attrs(text, len_bytes, -1, e->lang,
+ pango_get_log_attrs(text, len_bytes, -1, lang,
log_attrs, len_chars+1);
- offs = sbox->offs_char + e->cursor_pos;
+ offs = sbox->offs_char + cursor_pos;
if ( (len_chars > 1) && log_attrs[offs+1].is_line_break ) {
@@ -919,14 +870,14 @@ static void insert_text(char *t, SCEditor *e)
printf("Adding line break (new box)\n");
/* Add a new box containing the text after the break */
- insert_box(&e->cursor_frame->lines[sln], sbx);
- nbox = bv_box(e->cursor_frame->lines[sln].boxes, sbx);
+ insert_box(line, sbx);
+ nbox = bv_box(line->boxes, sbx);
nbox->type = WRAP_BOX_PANGO;
nbox->space = WRAP_SPACE_INTERWORD;
- nbox->len_chars = e->cursor_pos;
+ nbox->len_chars = cursor_pos;
/* Shorten the text in the first box */
- sbox->len_chars -= e->cursor_pos;
+ sbox->len_chars -= cursor_pos;
shape_box(sbox);
//shape_box(nbox);
@@ -934,13 +885,59 @@ static void insert_text(char *t, SCEditor *e)
}
free(log_attrs);
+}
+
+
+static void insert_text(char *t, SCEditor *e)
+{
+ int sln, sbx, sps;
+ struct wrap_box *sbox;
+ struct frame *fr = e->cursor_frame;
+ int err = 0;
+
+ printf("insert! --------------------------------------------------------\n");
+
+ if ( fr == NULL ) return;
+
+ /* If this is, say, the top level frame, do nothing */
+ if ( fr->boxes == NULL ) return;
- sbox->segs[sseg].len_chars += 1;
+ sln = e->cursor_line;
+ sbx = e->cursor_box;
+ sps = e->cursor_pos;
+ sbox = bv_box(e->cursor_frame->lines[sln].boxes, sbx);
+
+ if ( sbox->type == WRAP_BOX_NOTHING ) {
+ printf("Upgrading nothing box %p to Pango box\n", sbox);
+ sbox->type = WRAP_BOX_PANGO;
+ sbox->col[0] = fr->col[0];
+ sbox->col[1] = fr->col[1];
+ sbox->col[2] = fr->col[2];
+ sbox->col[3] = fr->col[3];
+ sbox->fontdesc = pango_font_description_copy(fr->fontdesc);
+ sbox->segs = NULL;
+ }
+
+ cur_box_diag(e);
+ printf("sps=%i, offs_char=%i\n", sps, sbox->offs_char);
+ if ( sbox->type == WRAP_BOX_NOTHING ) {
+ printf("Editing a nothing box!\n");
+ return;
+ }
+
+ sc_insert_text(sbox->scblock, sps+sbox->offs_char, t);
sbox->len_chars += 1;
/* Tweak the offsets of all the subsequent boxes */
shift_box_offsets(fr, sbox, 1);
+ /* The box must be analysed by Pango again, because the segments
+ * might have changed */
+ itemize_and_shape(sbox, e->pc);
+
+ fixup_line_breaks(sbox, &e->cursor_frame->lines[sln], sbx,
+ e->cursor_pos, e->lang);
+
fr->empty = 0;
update_local(e, fr, sln, sbx);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 9226c76..70317a6 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -834,7 +834,11 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin)
return 1;
}
- fr->fontdesc = sc_interp_get_fontdesc(scin);
+ fr->fontdesc = pango_font_description_copy(sc_interp_get_fontdesc(scin));
+ fr->col[0] = sc_interp_get_fgcol(scin)[0];
+ fr->col[1] = sc_interp_get_fgcol(scin)[1];
+ fr->col[2] = sc_interp_get_fgcol(scin)[2];
+ fr->col[3] = sc_interp_get_fgcol(scin)[3];
parse_frame_options(fr, sc_interp_get_frame(scin),
options);