diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-05-21 15:08:52 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-05-21 15:08:52 +0200 |
commit | 59212d86abd5f60b8f4d0baf6f133980e142e62e (patch) | |
tree | bdfa95db61474e5d6dbeeb58d5d1ac230f332262 /src/wrap.c | |
parent | a08d89c334bcdda3fbcecbf2bc739ec8769ef47c (diff) |
Image scaling stuff
Diffstat (limited to 'src/wrap.c')
-rw-r--r-- | src/wrap.c | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -483,6 +483,34 @@ static void pop_font(struct sc_font *stack, int *n_fonts, int *max_fonts) } +static int get_size(const char *a, int *wp, int *hp) +{ + char *x; + char *ws; + char *hs; + + x = index(a, 'x'); + if ( x == NULL ) goto invalid; + + if ( rindex(a, 'x') != x ) goto invalid; + + ws = strndup(a, x-a); + hs = strdup(x+1); + + *wp = strtoul(ws, NULL, 10); + *hp = strtoul(hs, NULL, 10); + + free(ws); + free(hs); + + return 0; + +invalid: + fprintf(stderr, "Invalid dimensions '%s'\n", a); + return 1; +} + + static void run_sc(const char *sc, struct sc_font *fonts, int *n_fonts, int *max_fonts, PangoContext *pc, struct wrap_line *boxes, PangoLanguage *lang) @@ -518,10 +546,12 @@ static void run_sc(const char *sc, struct sc_font *fonts, int *n_fonts, boxes, lang); pop_font(fonts, n_fonts, max_fonts); } else if ( (strcmp(b->name, "image")==0) - && (b->contents != NULL) ) { - /* FIXME: Proper w/h from SC */ - add_image_box(boxes, b->contents, b->offset, - 100.0, 100.0); + && (b->contents != NULL) && (b->options != NULL) ) { + int w, h; + if ( get_size(b->options, &w, &h) == 0 ) { + add_image_box(boxes, b->contents, b->offset, + w, h); + } } } |