aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-11-21 22:32:42 +0100
committerThomas White <taw@physics.org>2017-11-21 22:32:42 +0100
commit55c566558b168b434e955dbefca4745c3a4932a2 (patch)
tree77ade1ecfa8de1bfc1e1081146d79691b78a7273 /src
parentcad7675852e8f2fd556b38b8e376913daca2f10a (diff)
Calculate image sizes to fill frames horizontally
Diffstat (limited to 'src')
-rw-r--r--src/frame.c21
-rw-r--r--src/sc_interp.c27
2 files changed, 39 insertions, 9 deletions
diff --git a/src/frame.c b/src/frame.c
index 4a64e35..cc47208 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "sc_parse.h"
#include "frame.h"
@@ -69,6 +70,8 @@ struct _paragraph
char *filename;
double image_w;
double image_h;
+ int image_real_w;
+ int image_real_h;
/* For PARA_TYPE_CALLBACK */
double cb_w;
@@ -283,6 +286,15 @@ void wrap_paragraph(Paragraph *para, PangoContext *pc, double w,
w -= para->space[0] + para->space[1];
+ if ( para->type == PARA_TYPE_IMAGE ) {
+ if ( para->image_w < 0.0 ) {
+ para->image_w = w;
+ para->image_h = w*((float)para->image_real_h/para->image_real_w);
+ }
+ para->height = para->image_h;
+ return;
+ }
+
if ( para->type != PARA_TYPE_TEXT ) return;
for ( i=0; i<para->n_runs; i++ ) {
@@ -478,6 +490,7 @@ void add_image_para(struct frame *fr, SCBlock *scblock, const char *filename,
double w, double h, int editable)
{
Paragraph *pnew;
+ int wi, hi;
pnew = create_paragraph(fr);
if ( pnew == NULL ) {
@@ -485,11 +498,19 @@ void add_image_para(struct frame *fr, SCBlock *scblock, const char *filename,
return;
}
+ if ( gdk_pixbuf_get_file_info(filename, &wi, &hi) == NULL ) {
+ fprintf(stderr, "Couldn't get size for %s\n", filename);
+ wi = 100;
+ hi = 100;
+ }
+
pnew->type = PARA_TYPE_IMAGE;
pnew->scblock = scblock;
pnew->filename = strdup(filename);
pnew->image_w = w;
pnew->image_h = h;
+ pnew->image_real_w = wi;
+ pnew->image_real_h = hi;
pnew->height = h;
pnew->open = 0;
pnew->space[0] = 0.0;
diff --git a/src/sc_interp.c b/src/sc_interp.c
index b4ec7cd..b530941 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -723,20 +723,29 @@ static int parse_dims(const char *opt, struct frame *parent,
if ( check == w ) goto invalid;
w_units = get_units(w);
if ( w_units == UNITS_FRAC ) {
- double pw = parent->w;
- pw -= parent->pad_l;
- pw -= parent->pad_r;
- *wp = pw * *wp;
+ if ( parent != NULL ) {
+ double pw = parent->w;
+ pw -= parent->pad_l;
+ pw -= parent->pad_r;
+ *wp = pw * *wp;
+ } else {
+ *wp = -1.0;
+ }
+
}
*hp = strtod(h, &check);
if ( check == h ) goto invalid;
h_units = get_units(h);
if ( h_units == UNITS_FRAC ) {
- double ph = parent->h;
- ph -= parent->pad_t;
- ph -= parent->pad_b;
- *hp = ph * *hp;
+ if ( parent != NULL ) {
+ double ph = parent->h;
+ ph -= parent->pad_t;
+ ph -= parent->pad_b;
+ *hp = ph * *hp;
+ } else {
+ *hp = -1.0;
+ }
}
*xp= strtod(x, &check);
@@ -810,7 +819,7 @@ static int parse_image_option(const char *opt, struct frame *parent,
if ( (index(opt, 'x') != NULL) && (index(opt, '+') != NULL)
&& (index(opt, '+') != rindex(opt, '+')) ) {
double dum;
- return parse_dims(opt, parent, wp, hp, &dum, &dum);
+ return parse_dims(opt, NULL, wp, hp, &dum, &dum);
}
if ( strncmp(opt, "filename=\"", 10) == 0 ) {