aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2013-09-06 23:01:15 +0200
committerThomas White <taw@bitwiz.org.uk>2013-09-06 23:01:15 +0200
commita4fc5fe56ad4861c9345f003bdd1d7822f756b08 (patch)
treec8ed0195d1d43adbd5aa520692fb2c9a03dc8b46 /src
parentca730b236f848f22a138435c4a645c15e0c5e6ea (diff)
Allow "fit" as a size parameter for images
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.c2
-rw-r--r--src/wrap.c31
2 files changed, 21 insertions, 12 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 0830b02..8783acc 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -1828,7 +1828,7 @@ static void dnd_receive(GtkWidget *widget, GdkDragContext *drag_context,
fprintf(stderr, "Failed to allocate SC\n");
return;
}
- snprintf(sc, len, "\\image[%ix%i]{%s}", w, h, filename);
+ snprintf(sc, len, "\\image[fitxfit]{%s}", filename);
fr = create_frame(p, p->start_corner_x,
p->start_corner_y, w, h);
diff --git a/src/wrap.c b/src/wrap.c
index 01b9484..ee53424 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -609,7 +609,7 @@ static void pop_font_or_colour(struct sc_font_stack *stack)
}
-static int get_size(const char *a, int *wp, int *hp)
+static int get_size(const char *a, struct frame *fr, int *wp, int *hp)
{
char *x;
char *ws;
@@ -623,8 +623,16 @@ static int get_size(const char *a, int *wp, int *hp)
ws = strndup(a, x-a);
hs = strdup(x+1);
- *wp = strtoul(ws, NULL, 10);
- *hp = strtoul(hs, NULL, 10);
+ if ( strcmp(ws, "fit") == 0 ) {
+ *wp = fr->w;
+ } else {
+ *wp = strtoul(ws, NULL, 10);
+ }
+ if ( strcmp(ws, "fit") == 0 ) {
+ *hp = fr->h;
+ } else {
+ *hp = strtoul(hs, NULL, 10);
+ }
free(ws);
free(hs);
@@ -639,7 +647,8 @@ invalid:
static void run_sc(const char *sc, struct sc_font_stack *fonts,
PangoContext *pc, struct wrap_line *boxes,
- PangoLanguage *lang, size_t g_offset, int editable)
+ PangoLanguage *lang, size_t g_offset, int editable,
+ struct frame *fr)
{
SCBlockList *bl;
SCBlockListIterator *iter;
@@ -671,7 +680,7 @@ static void run_sc(const char *sc, struct sc_font_stack *fonts,
&& (b->contents != NULL) ) {
push_font(fonts, b->options, pc);
run_sc(b->contents, fonts, pc, boxes, lang, offset,
- editable);
+ editable, fr);
pop_font_or_colour(fonts);
} else if ( (strcmp(b->name, "fgcol")==0)
@@ -682,13 +691,13 @@ static void run_sc(const char *sc, struct sc_font_stack *fonts,
&& (b->contents != NULL) ) {
push_colour(fonts, b->options);
run_sc(b->contents, fonts, pc, boxes, lang, offset,
- editable);
+ editable, fr);
pop_font_or_colour(fonts);
} else if ( (strcmp(b->name, "image")==0)
&& (b->contents != NULL) && (b->options != NULL) ) {
int w, h;
- if ( get_size(b->options, &w, &h) == 0 ) {
+ if ( get_size(b->options, fr, &w, &h) == 0 ) {
add_image_box(boxes, b->contents, offset, w, h,
editable);
}
@@ -700,7 +709,7 @@ static void run_sc(const char *sc, struct sc_font_stack *fonts,
static struct wrap_line *sc_to_wrap_boxes(const char *sc, const char *prefix,
- PangoContext *pc)
+ PangoContext *pc, struct frame *fr)
{
struct wrap_line *boxes;
PangoLanguage *lang;
@@ -725,10 +734,10 @@ static struct wrap_line *sc_to_wrap_boxes(const char *sc, const char *prefix,
set_colour(&fonts, "#000000");
if ( prefix != NULL ) {
- run_sc(prefix, &fonts, pc, boxes, lang, 0, 0);
+ run_sc(prefix, &fonts, pc, boxes, lang, 0, 0, fr);
}
if ( sc != NULL ) {
- run_sc(sc, &fonts, pc, boxes, lang, 0, 1);
+ run_sc(sc, &fonts, pc, boxes, lang, 0, 1, fr);
}
/* Empty the stack */
@@ -1233,7 +1242,7 @@ int wrap_contents(struct frame *fr, PangoContext *pc)
}
/* Turn the StoryCode into wrap boxes, all on one line */
- boxes = sc_to_wrap_boxes(fr->sc, prologue, pc);
+ boxes = sc_to_wrap_boxes(fr->sc, prologue, pc, fr);
if ( boxes == NULL ) {
fprintf(stderr, "Failed to create wrap boxes.\n");
return 1;