aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-23 21:28:30 +0100
committerThomas White <taw@physics.org>2018-03-23 21:28:30 +0100
commite0204fa4ae96ec9b298b67b723afe9fb6919a0d7 (patch)
treeaf8c7b75108be798483c9c33b7bb493640ca971f /src
parent476a5210dcdddcad5eab5c5bc0e3cdee9a7efad1 (diff)
Add \ralign
Diffstat (limited to 'src')
-rw-r--r--src/frame.c10
-rw-r--r--src/frame.h1
-rw-r--r--src/sc_interp.c15
3 files changed, 26 insertions, 0 deletions
diff --git a/src/frame.c b/src/frame.c
index bd66498..5d9acc0 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -54,6 +54,7 @@ struct _paragraph
int n_runs;
struct text_run *runs;
PangoLayout *layout;
+ PangoAlignment alignment;
/* For anything other than PARA_TYPE_TEXT
* (for text paragraphs, these things are in the runs) */
@@ -371,6 +372,7 @@ void wrap_paragraph(Paragraph *para, PangoContext *pc, double w,
}
pango_layout_set_width(para->layout, pango_units_from_double(w));
pango_layout_set_text(para->layout, text, total_len);
+ pango_layout_set_alignment(para->layout, para->alignment);
pango_layout_set_attributes(para->layout, attrs);
free(text);
pango_attr_list_unref(attrs);
@@ -439,6 +441,7 @@ Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl)
pnew->runs = NULL;
pnew->layout = NULL;
pnew->height = 0.0;
+ pnew->alignment = PANGO_ALIGN_LEFT;
return pnew;
}
@@ -1827,6 +1830,13 @@ void set_para_spacing(Paragraph *para, float space[4])
}
+void set_para_alignment(Paragraph *para, PangoAlignment align)
+{
+ if ( para == NULL ) return;
+ para->alignment = align;
+}
+
+
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 36cdca1..002d397 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -124,6 +124,7 @@ extern double total_height(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]);
+extern void set_para_alignment(Paragraph *para, PangoAlignment align);
extern double paragraph_height(Paragraph *para);
extern void render_paragraph(cairo_t *cr, Paragraph *para, ImageStore *is);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 55d5f34..eb09063 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -56,6 +56,7 @@ struct sc_state
{
PangoFontDescription *fontdesc;
PangoFont *font;
+ PangoAlignment alignment;
double col[4];
int ascent;
int height;
@@ -408,6 +409,13 @@ static void set_italic(SCInterpreter *scin)
}
+static void set_alignment(SCInterpreter *scin, PangoAlignment align)
+{
+ struct sc_state *st = &scin->state[scin->j];
+ st->alignment = align;
+}
+
+
/* This sets the colour for the font at the top of the stack */
static void set_colour(SCInterpreter *scin, const char *colour)
{
@@ -613,6 +621,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang,
st->paraspace[3] = 0.0;
st->fontdesc = NULL;
st->have_size = 0;
+ st->alignment = PANGO_ALIGN_LEFT;
scin->lang = lang;
@@ -991,6 +1000,7 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl,
para = create_paragraph(fr, bl, rbl);
}
+ set_para_alignment(para, st->alignment);
add_run(para, bl, rbl, fontdesc, col);
set_para_spacing(para, st->paraspace);
@@ -1181,6 +1191,11 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
set_italic(scin);
maybe_recurse_after(scin, child);
+ } else if ( strcmp(name, "ralign") == 0 ) {
+ maybe_recurse_before(scin, child);
+ set_alignment(scin, PANGO_ALIGN_RIGHT);
+ maybe_recurse_after(scin, child);
+
} else if ( strcmp(name, "fgcol") == 0 ) {
maybe_recurse_before(scin, child);
set_colour(scin, options);