aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-12 22:35:43 +0100
committerThomas White <taw@physics.org>2018-03-12 22:35:43 +0100
commitcc5038a7a2be909dd845e0e5e635cc6f0697e98f (patch)
tree5e23038dfb91ad43185340f5a720052986b7b9ac /src
parent6f95a69666891323f594f01c9eac918665968b54 (diff)
Get rid of Paragraph->open
Diffstat (limited to 'src')
-rw-r--r--src/frame.c96
-rw-r--r--src/frame.h7
-rw-r--r--src/sc_editor.c2
-rw-r--r--src/sc_interp.c25
4 files changed, 37 insertions, 93 deletions
diff --git a/src/frame.c b/src/frame.c
index 51e7e66..221952f 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -53,7 +53,6 @@ struct _paragraph
/* For PARA_TYPE_TEXT */
int n_runs;
struct text_run *runs;
- int open;
PangoLayout *layout;
/* For anything other than PARA_TYPE_TEXT
@@ -399,11 +398,6 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock,
{
struct text_run *runs_new;
- if ( !para->open ) {
- fprintf(stderr, "Adding a run to a closed paragraph!\n");
- //return;
- }
-
runs_new = realloc(para->runs,
(para->n_runs+1)*sizeof(struct text_run));
if ( runs_new == NULL ) {
@@ -423,7 +417,7 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock,
}
-static Paragraph *create_paragraph(struct frame *fr)
+Paragraph *create_paragraph(struct frame *fr)
{
Paragraph **paras_new;
Paragraph *pnew;
@@ -437,6 +431,14 @@ static Paragraph *create_paragraph(struct frame *fr)
fr->paras = paras_new;
fr->paras[fr->n_paras++] = pnew;
+ /* For now, assume the paragraph is going to be for text.
+ * However, this can easily be changed */
+ pnew->type = PARA_TYPE_TEXT;
+ pnew->n_runs = 0;
+ pnew->runs = NULL;
+ pnew->layout = NULL;
+ pnew->height = 0.0;
+
return pnew;
}
@@ -459,8 +461,6 @@ Paragraph *insert_paragraph(struct frame *fr, int pos)
pnew = calloc(1, sizeof(struct _paragraph));
if ( pnew == NULL ) return NULL;
- pnew->open = 1;
-
fr->paras = paras_new;
fr->n_paras++;
@@ -497,7 +497,6 @@ void add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl,
pnew->bvp = bvp;
pnew->vp = vp;
pnew->height = h;
- pnew->open = 0;
}
@@ -534,7 +533,6 @@ void add_image_para(struct frame *fr, SCBlock *scblock, SCBlock *rscblock,
pnew->image_real_w = wi;
pnew->image_real_h = hi;
pnew->height = h;
- pnew->open = 0;
pnew->space[0] = 0.0;
pnew->space[1] = 0.0;
pnew->space[2] = 0.0;
@@ -553,62 +551,10 @@ double total_height(struct frame *fr)
}
-Paragraph *last_open_para(struct frame *fr)
-{
- Paragraph *pnew;
-
- if ( (fr->paras != NULL) && (fr->paras[fr->n_paras-1]->open) ) {
- return fr->paras[fr->n_paras-1];
- }
-
- /* No open paragraph found, create a new one */
- pnew = create_paragraph(fr);
- if ( pnew == NULL ) return NULL;
-
- pnew->type = PARA_TYPE_TEXT;
- pnew->open = 1;
- pnew->n_runs = 0;
- pnew->runs = NULL;
- pnew->layout = NULL;
- pnew->height = 0.0;
-
- return pnew;
-}
-
-
-void add_newpara(struct frame *fr, SCBlock *bl)
+Paragraph *last_para(struct frame *fr)
{
- Paragraph *last_para;
-
- if ( fr->paras == NULL ) return;
- last_para = fr->paras[fr->n_paras-1];
-
- if ( last_para->open ) {
- set_newline_at_end(last_para, bl);
- close_last_paragraph(fr);
- } /* else do nothing */
-}
-
-
-void close_last_paragraph(struct frame *fr)
-{
- if ( fr->paras == NULL ) return;
- if ( fr->paras[fr->n_paras-1]->type != PARA_TYPE_TEXT ) {
- printf("Closing a non-text paragraph!\n");
- }
- fr->paras[fr->n_paras-1]->open = 0;
-}
-
-
-int last_para_available_for_text(struct frame *fr)
-{
- Paragraph *last_para;
- if ( fr->paras == NULL ) return 0;
- last_para = fr->paras[fr->n_paras-1];
- if ( last_para->type == PARA_TYPE_TEXT ) {
- if ( last_para->open ) return 1;
- }
- return 0;
+ if ( fr->paras == NULL ) return NULL;
+ return fr->paras[fr->n_paras-1];
}
@@ -1671,9 +1617,6 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos,
pnew->n_runs = 0;
add_run(pnew, end, end, fr->fontdesc, fr->col);
- pnew->open = para->open;
- para->open = 0;
-
wrap_paragraph(pnew, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0);
return end;
@@ -1744,9 +1687,6 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos,
nnp = sc_block_append(rr->rscblock, strdup("newpara"), NULL, NULL, NULL);
set_newline_at_end(para, nnp);
- pnew->open = para->open;
- para->open = 0;
-
wrap_paragraph(para, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0);
wrap_paragraph(pnew, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0);
@@ -1808,18 +1748,6 @@ void set_para_spacing(Paragraph *para, float space[4])
}
-Paragraph *current_para(struct frame *fr)
-{
- if ( fr == NULL ) return NULL;
-
- if ( (fr->paras != NULL) && (fr->paras[fr->n_paras-1]->open) ) {
- return fr->paras[fr->n_paras-1];
- }
-
- return NULL;
-}
-
-
void *get_para_bvp(Paragraph *para)
{
if ( para->type != PARA_TYPE_CALLBACK ) return NULL;
diff --git a/src/frame.h b/src/frame.h
index af2e9fd..606fabf 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -121,11 +121,7 @@ extern struct frame *find_frame_with_scblocks(struct frame *top,
extern double total_height(struct frame *fr);
-extern void add_newpara(struct frame *fr, SCBlock *bl);
-extern Paragraph *last_open_para(struct frame *fr);
-extern Paragraph *current_para(struct frame *fr);
-extern void close_last_paragraph(struct frame *fr);
-extern int last_para_available_for_text(struct frame *fr);
+extern Paragraph *last_para(struct frame *fr);
extern void show_para(Paragraph *p);
extern void set_para_spacing(Paragraph *para, float space[4]);
@@ -202,6 +198,7 @@ extern int get_sc_pos(struct frame *fr, int pn, size_t pos,
extern void *get_para_bvp(Paragraph *para);
extern void merge_paragraphs(struct frame *fr, int para);
+extern Paragraph *create_paragraph(struct frame *fr);
extern enum para_type para_type(Paragraph *para);
extern SCBlock *para_scblock(Paragraph *para);
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 00c626d..0cd810c 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -1061,7 +1061,7 @@ static void check_paragraph(struct frame *fr, PangoContext *pc,
SCBlock *scblocks)
{
if ( fr->n_paras > 0 ) return;
- Paragraph *para = last_open_para(fr);
+ Paragraph *para = last_para(fr);
if ( scblocks == NULL ) {
/* We have no SCBlocks at all! Better create one... */
diff --git a/src/sc_interp.c b/src/sc_interp.c
index c9f3d76..d827326 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -695,7 +695,7 @@ static void set_paraspace(SCInterpreter *scin, const char *opts)
st->paraspace[2] = p[2];
st->paraspace[3] = p[3];
- set_para_spacing(current_para(sc_interp_get_frame(scin)), p);
+ set_para_spacing(last_para(sc_interp_get_frame(scin)), p);
}
@@ -943,6 +943,19 @@ static int in_macro(SCInterpreter *scin)
}
+static void add_newpara(struct frame *fr, SCBlock *bl)
+{
+ Paragraph *last_para;
+
+ if ( fr->paras == NULL ) return;
+ last_para = fr->paras[fr->n_paras-1];
+
+ set_newline_at_end(last_para, bl);
+
+ create_paragraph(fr);
+}
+
+
/* Add the SCBlock to the text in 'frame', at the end */
static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
PangoLanguage *lang, int editable, SCInterpreter *scin)
@@ -952,6 +965,7 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
double *col;
struct sc_state *st = &scin->state[scin->j];
SCBlock *rbl;
+ Paragraph *para;
/* Empty block? */
if ( text == NULL ) return 1;
@@ -959,13 +973,18 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
fontdesc = sc_interp_get_fontdesc(scin);
col = sc_interp_get_fgcol(scin);
- Paragraph *para = last_open_para(fr);
+ para = last_para(fr);
+ if ( (para == NULL) || (para_type(para) != PARA_TYPE_TEXT) ) {
+ /* Last paragraph is not text.
+ * or: no paragraphs yet.
+ * Either way: Create the first one */
+ para = create_paragraph(fr);
+ }
rbl = bl;
if ( st->macro_real_block != NULL ) {
bl = st->macro_real_block;
}
-
add_run(para, bl, rbl, fontdesc, col);
set_para_spacing(para, st->paraspace);