From: ellson Date: Wed, 29 Dec 2004 20:01:11 +0000 (+0000) Subject: handle dpi and margins in emit_init X-Git-Tag: LAST_LIBGRAPH~32^2~8183 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8aac3919e05acbf442ed723f986c49d05bb025a2;p=graphviz handle dpi and margins in emit_init --- diff --git a/lib/common/emit.c b/lib/common/emit.c index 2fb10c151..f4848b3b4 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -137,7 +137,6 @@ static void emit_defaults(GVC_t * gvc) static void setup_page(GVC_t * gvc, point page) { point offset; - double scale; int rot; graph_t *g = gvc->g; @@ -156,9 +155,8 @@ static void setup_page(GVC_t * gvc, point page) offset.x = (page.y + 1) * GP.y; offset.y = -page.x * GP.x; } - scale = GD_drawing(g)->scale; rot = GD_drawing(g)->landscape ? 90 : 0; - gvrender_begin_page(gvc, page, scale, rot, offset); + gvrender_begin_page(gvc, page, gvc->zoom, rot, offset); emit_background(gvc, CB.LL, CB.UR); emit_defaults(gvc); } @@ -306,8 +304,8 @@ static void setup_pagination(GVC_t * gvc, graph_t * g) GP.y = PFCLM.y; /* convert to double */ if (GD_drawing(g)->landscape) GP = exch_xyf(GP); - GP.x = GP.x / GD_drawing(g)->scale; - GP.y = GP.y / GD_drawing(g)->scale; + GP.x = GP.x / gvc->zoom; + GP.y = GP.y / gvc->zoom; /* we don't want graph page to exceed its bounding box */ GP.x = MIN(GP.x, GD_bb(g).UR.x); GP.y = MIN(GP.y, GD_bb(g).UR.y); @@ -316,7 +314,7 @@ static void setup_pagination(GVC_t * gvc, graph_t * g) N_pages = Pages.x * Pages.y; /* find the drawable size in device coords */ - tp = GD_drawing(g)->size; + tp = gvc->size; if (GD_drawing(g)->landscape) tp = exch_xy(tp); DS.x = MIN(tp.x, PFCLM.x); @@ -330,7 +328,7 @@ static void setup_pagination(GVC_t * gvc, graph_t * g) PFC.y = DEFAULT_PAGEHT; PFCLM.x = PFC.x - 2 * PB.LL.x; PFCLM.y = PFC.y - 2 * PB.LL.y; - DS = GD_drawing(g)->size; + DS = gvc->size; if (GD_drawing(g)->landscape) DS = exch_xy(DS); Pages.x = Pages.y = N_pages = 1; @@ -631,60 +629,39 @@ void emit_edge(GVC_t * gvc, edge_t * e) gvrender_end_edge(gvc); } -static void setup_size_scale(graph_t * g) +/* emit_init + * - called just once per output device + * (where emit_graph can be called many times for refresh callbacks) + */ +void emit_init(GVC_t * gvc, graph_t * g) { - double xscale, yscale, scale = 1.0; + char *str; + double X, Y, Z = 1.0, x, y; + point size = GD_drawing(g)->size; + point UR = GD_bb(g).UR; assert((GD_bb(g).LL.x == 0) && (GD_bb(g).LL.y == 0)); /* determine final drawing size and scale to apply. */ /* N.B. size given by user is not rotated by landscape mode */ /* start with "natural" size of layout */ - if (GD_drawing(g)->size.x > 0) { /* was given by user... */ - if ((GD_drawing(g)->size.x < GD_bb(g).UR.x) /* drawing is too big... */ - ||(GD_drawing(g)->size.y < GD_bb(g).UR.y)) { - xscale = ((double) GD_drawing(g)->size.x) / GD_bb(g).UR.x; - yscale = ((double) GD_drawing(g)->size.y) / GD_bb(g).UR.y; - scale = MIN(xscale, yscale); - } - else if (GD_drawing(g)->filled) { - if ((GD_drawing(g)->size.x > GD_bb(g).UR.x) /* drawing is too small... */ - &&(GD_drawing(g)->size.y > GD_bb(g).UR.y)) { - xscale = ((double) GD_drawing(g)->size.x) / GD_bb(g).UR.x; - yscale = ((double) GD_drawing(g)->size.y) / GD_bb(g).UR.y; - scale = MIN(xscale, yscale); - } - } + if (size.x > 0) { /* was given by user... */ + if ((size.x < UR.x) || (size.y < UR.y) /* drawing is too big... */ + || ((GD_drawing(g)->filled) /* or ratio=filled requested and ... */ + && (size.x > UR.x) && (size.y > UR.y))) /* drawing is too small... */ + Z = MIN(((double)size.x)/UR.x, ((double)size.y)/UR.y); } - GD_drawing(g)->scale = scale; - GD_drawing(g)->size.x = scale * GD_bb(g).UR.x; - GD_drawing(g)->size.y = scale * GD_bb(g).UR.y; -} - -void emit_init(GVC_t * gvc, graph_t * g) -{ - char *str; - double X, Y, Z, x, y; - - setup_size_scale(g); - X = (double)(GD_drawing(g)->size.x); - Y = (double)(GD_drawing(g)->size.y); - Z = GD_drawing(g)->scale; + X = Z * (double)(GD_bb(g).UR.x + 2 * GD_drawing(g)->margin.x + 2); + Y = Z * (double)(GD_bb(g).UR.y + 2 * GD_drawing(g)->margin.y + 2); x = (double)(GD_bb(g).UR.x) / 2.; y = (double)(GD_bb(g).UR.y) / 2.; if ((str = agget(g, "viewport"))) sscanf(str, "%lf,%lf,%lf,%lf,%lf", &X, &Y, &Z, &x, &y); - gvc->size.x = ROUND(X); - gvc->size.y = ROUND(Y); - gvc->zoom = Z; /* scaling factor */ - gvc->zoom = Z; /* scaling factor */ - gvc->focus.x = x; /* graph coord of focus - points */ - gvc->focus.y = y; G_peripheries = agfindattr(g, "peripheries"); setup_graph(gvc, g); - gvrender_begin_job(gvc, Lib, Pages); + gvrender_begin_job(gvc, Lib, Pages, X, Y, Z, x, y, GD_drawing(g)->dpi); } void emit_deinit(GVC_t * gvc, graph_t * g) diff --git a/lib/common/output.c b/lib/common/output.c index c8e6e5e32..51626b3e9 100644 --- a/lib/common/output.c +++ b/lib/common/output.c @@ -496,8 +496,7 @@ void _write_plain(GVC_t * gvc, FILE * f, boolean extend) setup_graph(gvc, g); setYInvert(g); pt = GD_bb(g).UR; - fprintf(f, "graph %.3f %.3f %.3f\n", - GD_drawing(g)->scale, PS2INCH(pt.x), PS2INCH(pt.y)); + fprintf(f, "graph %.3f %.3f %.3f\n", gvc->zoom, PS2INCH(pt.x), PS2INCH(pt.y)); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; diff --git a/lib/common/types.h b/lib/common/types.h index 70f102bee..a03a8f578 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -271,7 +271,7 @@ extern "C" { 0, R_VALUE, R_FILL, R_COMPRESS, R_AUTO, R_EXPAND } ratio_t; typedef struct layout_t { - double quantum, scale; + double quantum; double ratio; /* set only if ratio_kind == R_VALUE */ double dpi; point margin, page, size; diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 2d06fd253..63659e137 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -121,15 +121,26 @@ void gvrender_reset(GVC_t * gvc) #endif } -void gvrender_begin_job(GVC_t * gvc, char **lib, point pages) +void gvrender_begin_job(GVC_t * gvc, char **lib, point pages, double X, double Y, double Z, double x, double y, int dpi) { gvrender_engine_t *gvre = gvc->render_engine; gvc->lib = lib; gvc->pages = pages; - if (gvre && gvre->begin_job) -// gvre->begin_job(gvc, agget(g, "stylesheet")); - gvre->begin_job(gvc); + if (gvre) { + /* establish viewport and scaling */ + if (dpi < 1.0) + dpi = gvc->render_features->default_dpi; + gvc->dpi = dpi; + gvc->size.x = ROUND(X * dpi / POINTS_PER_INCH); + gvc->size.y = ROUND(Y * dpi / POINTS_PER_INCH); + gvc->zoom = Z; /* scaling factor */ + gvc->zoom = Z; /* scaling factor */ + gvc->focus.x = x; /* graph coord of focus - points */ + gvc->focus.y = y; + if (gvre->begin_job) + gvre->begin_job(gvc); + } #ifndef DISABLE_CODEGENS else { codegen_t *cg = gvc->codegen; @@ -223,33 +234,14 @@ static void gvrender_resolve_color(gvrender_features_t * features, void gvrender_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) { gvrender_engine_t *gvre = gvc->render_engine; - double dpi; char *str; gvc->g = g; gvc->bb = bb; gvc->pb = pb; - dpi = gvc->dpi = GD_drawing(g)->dpi; - gvc->margin = GD_drawing(g)->margin; if (gvre) { - /* establish viewport and scaling */ - if (dpi < 1.0) - dpi = gvc->render_features->default_dpi; -#if 0 - if (gvc->size.x == 0) { - gvc->size.x = - (gvc->bb.UR.x - gvc->bb.LL.x + - 2 * gvc->margin.x) * dpi / POINTS_PER_INCH + 2; - gvc->size.y = - (gvc->bb.UR.y - gvc->bb.LL.y + - 2 * gvc->margin.y) * dpi / POINTS_PER_INCH + 2; - gvc->focus.x = (GD_bb(gvc->g).UR.x - GD_bb(gvc->g).LL.x) / 2.; - gvc->focus.y = (GD_bb(gvc->g).UR.y - GD_bb(gvc->g).LL.y) / 2.; - gvc->zoom = 1.0; - } -#endif - gvc->compscale.x = gvc->zoom * dpi / POINTS_PER_INCH; + gvc->compscale.x = gvc->zoom * gvc->dpi / POINTS_PER_INCH; gvc->compscale.y = gvc->compscale.x * ((gvc->render_features->flags & GVRENDER_Y_GOES_DOWN) ? -1.0 : 1.0); diff --git a/lib/gvc/gvrender.h b/lib/gvc/gvrender.h index 3c9887c86..f5587355f 100644 --- a/lib/gvc/gvrender.h +++ b/lib/gvc/gvrender.h @@ -61,7 +61,7 @@ extern "C" { extern int gvrender_select(GVC_t * gvc, char *lang); extern int gvrender_features(GVC_t * gvc); extern void gvrender_reset(GVC_t * gvc); - extern void gvrender_begin_job(GVC_t * gvc, char **lib, point pages); + extern void gvrender_begin_job(GVC_t * gvc, char **lib, point pages, double X, double Y, double Z, double x, double y, int dpi); extern void gvrender_end_job(GVC_t * gvc); extern void gvrender_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb);