From 3cbb8d0124e839136795ae8dcf475a5fbe86c093 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Nov 2015 09:55:46 +0100 Subject: WIP --- src/render.c | 2 +- src/sc_editor.c | 60 +++++++++++++++++++++++++++++++++--------------------- src/slide_window.c | 2 +- src/wrap.c | 21 +++++++++++++++++++ src/wrap.h | 2 ++ 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/render.c b/src/render.c index ae8094a..a605ad2 100644 --- a/src/render.c +++ b/src/render.c @@ -201,7 +201,7 @@ static void render_boxes(struct wrap_line *line, cairo_t *cr, ImageStore *is, box = &line->boxes[j]; cairo_translate(cr, x_pos, 0.0); - //draw_outline(cr, box); + draw_outline(cr, box); switch ( line->boxes[j].type ) { diff --git a/src/sc_editor.c b/src/sc_editor.c index bdfc842..ed554c4 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -779,29 +779,6 @@ void insert_scblock(SCBlock *scblock, SCEditor *e) static void update_local(SCEditor *e, struct frame *fr, int line, int bn) { struct wrap_box *box = &fr->lines[line].boxes[bn]; - const char *text; - size_t len_bytes; - int len_chars; - PangoLogAttr *log_attrs; - int offs; - - text = sc_block_contents(box->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, - log_attrs, len_chars+1); - - offs = box->offs_char + e->cursor_pos; - - if ( log_attrs[offs].is_line_break ) { - printf("Just typed a break!\n"); - } - - free(log_attrs); - /* Shape the box again */ shape_box(box->cf->cf); box->glyphs = box->cf->cf->glyphs; @@ -840,6 +817,11 @@ static void insert_text(char *t, SCEditor *e) int sln, sbx, sps; 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; if ( fr == NULL ) return; @@ -855,6 +837,38 @@ static void insert_text(char *t, SCEditor *e) printf("sps=%i, offs_char=%i\n", sps, sbox->offs_char); sc_insert_text(sbox->scblock, sps+sbox->offs_char, t); + 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, + log_attrs, len_chars+1); + + offs = sbox->offs_char + e->cursor_pos; + + if ( log_attrs[offs+1].is_line_break ) { + + struct wrap_box *nbox; + + /* Add a new box containing the text after the break */ + insert_box(&e->cursor_frame->lines[sln], sbx); + nbox = &e->cursor_frame->lines[sln].boxes[sbx]; + nbox->type = WRAP_BOX_PANGO; + nbox->space = WRAP_SPACE_INTERWORD; + nbox->len_chars = e->cursor_pos; + + /* Shorten the text in the first box */ + sbox->len_chars -= e->cursor_pos; + + shape_box(sbox); + //shape_box(nbox); + + } + + free(log_attrs); + /* Update the length of the box in the unwrapped and un-paragraph-split * string of wrap boxes */ sbox->cf->cf->len_chars += 1; diff --git a/src/slide_window.c b/src/slide_window.c index eb8ecaa..3e167d7 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -575,7 +575,7 @@ SlideWindow *slide_window_open(struct presentation *p, GApplication *app) toolbar = gtk_toolbar_new(); gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); - gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(toolbar), FALSE, FALSE, 0); + //gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(toolbar), FALSE, FALSE, 0); /* Fullscreen */ image = gtk_image_new_from_icon_name("view-fullscreen", diff --git a/src/wrap.c b/src/wrap.c index 5d5847a..f06babc 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -1038,3 +1038,24 @@ double total_height(struct frame *fr) return pango_units_to_double(tot); } + + +/* Insert a new box, which will be at position 'pos' */ +int insert_box(struct wrap_line *l, int pos) +{ + int i; + + if ( l->n_boxes == l->max_boxes ) { + l->max_boxes += 32; + if ( alloc_boxes(l) ) return 1; + } + + /* Shuffle the boxes along */ + for ( i=l->n_boxes; i>pos+1; i-- ) { + l->boxes[i] = l->boxes[i-1]; + } + + l->n_boxes++; + + return 0; +} diff --git a/src/wrap.h b/src/wrap.h index a6503e1..bf091ee 100644 --- a/src/wrap.h +++ b/src/wrap.h @@ -123,4 +123,6 @@ extern void wrap_line_free(struct wrap_line *l); extern void show_boxes(struct wrap_line *boxes); extern double total_height(struct frame *fr); +extern int insert_box(struct wrap_line *l, int pos); + #endif /* WRAP_H */ -- cgit v1.2.3