Commit 929b7e09 authored by Dom Lachowicz's avatar Dom Lachowicz

allow for independant X and Y resolutions

parent 54357112
2004-07-10 Dom Lachowicz <cinamod@hotmail.com>
* *.c: Allow for different X & Y resolutions (DPI). This needs more work;
probably need to change rsvg_parse_length().
2004-07-10 Dom Lachowicz <cinamod@hotmail.com>
* rsvg-styles.c: Fix bug #145477 - RSVG can now handle relative
......
......@@ -37,6 +37,9 @@ Core API
</para>
@dpi_x:
@dpi_y:
<!-- # Unused Parameters # -->
@dpi:
......@@ -54,6 +57,9 @@ Core API
</para>
@handle:
@dpi_x:
@dpi_y:
<!-- # Unused Parameters # -->
@dpi:
......
This diff is collapsed.
......@@ -226,25 +226,25 @@ rsvg_start_mask (RsvgHandle *ctx, RsvgPropertyBag *atts)
if ((value = rsvg_property_bag_lookup (atts, "x")))
mask->x =
rsvg_css_parse_normalized_length (value,
ctx->dpi,
ctx->dpi_x,
1,
font_size);
if ((value = rsvg_property_bag_lookup (atts, "y")))
mask->y =
rsvg_css_parse_normalized_length (value,
ctx->dpi,
ctx->dpi_y,
1,
font_size);
if ((value = rsvg_property_bag_lookup (atts, "width")))
mask->width =
rsvg_css_parse_normalized_length (value,
ctx->dpi,
ctx->dpi_x,
1,
font_size);
if ((value = rsvg_property_bag_lookup (atts, "height")))
mask->height =
rsvg_css_parse_normalized_length (value,
ctx->dpi,
ctx->dpi_y,
1,
font_size);
if ((value = rsvg_property_bag_lookup (atts, "id")))
......
......@@ -87,7 +87,8 @@ struct RsvgHandle {
int width;
int height;
double dpi;
double dpi_x;
double dpi_y;
GString * title;
GString * desc;
......
......@@ -759,13 +759,13 @@ rsvg_start_line (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "x1")))
x1 = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
x1 = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "y1")))
y1 = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
y1 = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "x2")))
x2 = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
x2 = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "y2")))
y2 = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
y2 = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "id")))
......@@ -805,19 +805,19 @@ rsvg_start_rect (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "width")))
w = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
w = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "height")))
h = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
h = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "rx"))) {
rx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
rx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
got_rx = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "ry"))) {
ry = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
ry = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
got_ry = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
......@@ -942,11 +942,11 @@ rsvg_start_circle (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "cx")))
cx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
cx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "cy")))
cy = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
cy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "r")))
r = rsvg_css_parse_normalized_length (value, ctx->dpi,
r = rsvg_css_parse_normalized_length (value, rsvg_dpi_percentage (ctx),
rsvg_viewport_percentage((gdouble)ctx->width, (gdouble)ctx->height),
font_size);
if ((value = rsvg_property_bag_lookup (atts, "class")))
......@@ -1039,13 +1039,13 @@ rsvg_start_ellipse (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "cx")))
cx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
cx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "cy")))
cy = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
cy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "rx")))
rx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, font_size);
rx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, font_size);
if ((value = rsvg_property_bag_lookup (atts, "ry")))
ry = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, font_size);
ry = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, font_size);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "id")))
......@@ -1682,13 +1682,13 @@ rsvg_start_image (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "width")))
w = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
w = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "height")))
h = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
h = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
/* path is used by some older adobe illustrator versions */
if ((value = rsvg_property_bag_lookup (atts, "path")) || (value = rsvg_property_bag_lookup (atts, "xlink:href")))
href = value;
......@@ -1799,15 +1799,15 @@ rsvg_start_use (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size(atts))
{
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "width"))) {
width = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
width = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->height, state->font_size);
got_width = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "height"))) {
height = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
height = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
got_height = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "class")))
......@@ -1907,19 +1907,19 @@ rsvg_start_marker (RsvgHandle *ctx, RsvgPropertyBag *atts)
&vbw, &vbh);
}
if ((value = rsvg_property_bag_lookup (atts, "refX"))) {
x = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, font_size);
got_x = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "refY"))) {
y = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, font_size);
got_y = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "markerWidth"))) {
w = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, font_size);
w = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, font_size);
got_width = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "markerHeight"))) {
h = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, font_size);
h = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, font_size);
got_height = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "orient"))) {
......
......@@ -58,6 +58,12 @@ rsvg_viewport_percentage (gdouble width, gdouble height)
return sqrt(width * height);
}
gdouble
rsvg_dpi_percentage (RsvgHandle * ctx)
{
return sqrt(ctx->dpi_x * ctx->dpi_y);
}
void
rsvg_state_init (RsvgState *state)
{
......@@ -467,7 +473,7 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
}
else if (rsvg_css_param_match (str, "stroke-width"))
{
state->stroke_width = rsvg_css_parse_normalized_length (str + arg_off, ctx->dpi,
state->stroke_width = rsvg_css_parse_normalized_length (str + arg_off, ctx->dpi_x,
(gdouble)ctx->height, state->font_size);
state->has_stroke_width = TRUE;
}
......@@ -502,7 +508,7 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
}
else if (rsvg_css_param_match (str, "font-size"))
{
state->font_size = rsvg_css_parse_normalized_length (str + arg_off, ctx->dpi,
state->font_size = rsvg_css_parse_normalized_length (str + arg_off, ctx->dpi_y,
(gdouble)ctx->height, state->font_size);
state->has_font_size = TRUE;
}
......@@ -669,7 +675,7 @@ rsvg_parse_style_arg (RsvgHandle *ctx, RsvgState *state, const char *str)
else if (rsvg_css_param_match (str, "stroke-dashoffset"))
{
state->has_dash = TRUE;
state->dash.offset = rsvg_css_parse_normalized_length (str + arg_off, ctx->dpi,
state->dash.offset = rsvg_css_parse_normalized_length (str + arg_off, rsvg_dpi_percentage (ctx),
rsvg_viewport_percentage((gdouble)ctx->width, (gdouble)ctx->height), state->font_size);
if (state->dash.offset < 0.)
state->dash.offset = 0.;
......
......@@ -165,11 +165,11 @@ void rsvg_parse_style_attrs (RsvgHandle *ctx, RsvgState *state, const char * tag
RsvgPropertyBag *atts);
gdouble rsvg_viewport_percentage (gdouble width, gdouble height);
void
rsvg_pop_discrete_layer(RsvgHandle *ctx);
gdouble rsvg_dpi_percentage (RsvgHandle * ctx);
void rsvg_pop_discrete_layer(RsvgHandle *ctx);
void rsvg_push_discrete_layer (RsvgHandle *ctx);
gboolean
rsvg_needs_discrete_layer(RsvgState *state);
gboolean rsvg_needs_discrete_layer(RsvgState *state);
gboolean rsvg_parse_transform (double dst[6], const char *src);
RsvgState * rsvg_state_parent (RsvgHandle *ctx);
......
......@@ -260,18 +260,18 @@ rsvg_start_tspan (RsvgSaxHandlerText *self, RsvgPropertyBag *atts)
{
if ((value = rsvg_property_bag_lookup (atts, "x")))
{
tspan->x = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
tspan->x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
tspan->hasx = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "y")))
{
tspan->y = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
tspan->y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
tspan->hasy = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "dx")))
tspan->dx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
tspan->dx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "dy")))
tspan->dy = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
tspan->dy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "id")))
......@@ -354,13 +354,13 @@ rsvg_start_text (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (rsvg_property_bag_size (atts))
{
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "dx")))
dx = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->width, state->font_size);
dx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, (gdouble)ctx->width, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "dy")))
dy = rsvg_css_parse_normalized_length (value, ctx->dpi, (gdouble)ctx->height, state->font_size);
dy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, (gdouble)ctx->height, state->font_size);
if ((value = rsvg_property_bag_lookup (atts, "class")))
klazz = value;
if ((value = rsvg_property_bag_lookup (atts, "id")))
......@@ -466,7 +466,7 @@ rsvg_text_get_pango_context (RsvgHandle *ctx)
fontmap = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
pango_ft2_font_map_set_resolution (fontmap, ctx->dpi, ctx->dpi);
pango_ft2_font_map_set_resolution (fontmap, ctx->dpi_x, ctx->dpi_y);
pango_ft2_font_map_set_default_substitute (fontmap,
rsvg_text_ft2_subst_func,
......@@ -518,7 +518,7 @@ rsvg_text_layout_new (RsvgHandle *ctx,
pango_font_description_set_variant (font_desc, state->font_variant);
pango_font_description_set_weight (font_desc, state->font_weight);
pango_font_description_set_stretch (font_desc, state->font_stretch);
pango_font_description_set_size (font_desc, state->font_size * PANGO_SCALE / ctx->dpi * 72);
pango_font_description_set_size (font_desc, state->font_size * PANGO_SCALE / ctx->dpi_y * 72);
pango_layout_set_font_description (layout->layout, font_desc);
pango_font_description_free (font_desc);
......
......@@ -47,8 +47,10 @@
/*
* This is configurable at runtime
*/
#define RSVG_DEFAULT_DPI 90.0
static double internal_dpi = RSVG_DEFAULT_DPI;
#define RSVG_DEFAULT_DPI_X 90.0
#define RSVG_DEFAULT_DPI_Y 90.0
static double internal_dpi_x = RSVG_DEFAULT_DPI_X;
static double internal_dpi_y = RSVG_DEFAULT_DPI_Y;
static void
rsvg_ctx_free_helper (gpointer key, gpointer value, gpointer user_data)
......@@ -97,13 +99,13 @@ rsvg_start_svg (RsvgHandle *ctx, RsvgPropertyBag *atts)
&vbox_w, &vbox_h);
}
if ((value = rsvg_property_bag_lookup (atts, "width")))
width = rsvg_css_parse_normalized_length (value, ctx->dpi, vbox_w, 1);
width = rsvg_css_parse_normalized_length (value, ctx->dpi_x, vbox_w, 1);
if ((value = rsvg_property_bag_lookup (atts, "height")))
height = rsvg_css_parse_normalized_length (value, ctx->dpi, vbox_h, 1);
height = rsvg_css_parse_normalized_length (value, ctx->dpi_y, vbox_h, 1);
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, vbox_w, 1);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, vbox_w, 1);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, vbox_h, 1);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, vbox_h, 1);
if (has_vbox && vbox_w > 0. && vbox_h > 0.)
{
......@@ -231,13 +233,13 @@ rsvg_start_sub_svg (RsvgHandle *ctx, RsvgPropertyBag *atts)
&vbox_w, &vbox_h);
}
if ((value = rsvg_property_bag_lookup (atts, "width")))
width = rsvg_css_parse_normalized_length (value, ctx->dpi, ctx->width, 1);
width = rsvg_css_parse_normalized_length (value, ctx->dpi_x, ctx->width, 1);
if ((value = rsvg_property_bag_lookup (atts, "height")))
height = rsvg_css_parse_normalized_length (value, ctx->dpi, ctx->height, 1);
height = rsvg_css_parse_normalized_length (value, ctx->dpi_y, ctx->height, 1);
if ((value = rsvg_property_bag_lookup (atts, "x")))
x = rsvg_css_parse_normalized_length (value, ctx->dpi, ctx->width, 1);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, ctx->width, 1);
if ((value = rsvg_property_bag_lookup (atts, "y")))
y = rsvg_css_parse_normalized_length (value, ctx->dpi, ctx->height, 1);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, ctx->height, 1);
if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
......@@ -357,7 +359,7 @@ rsvg_gradient_stop_handler_start (RsvgSaxHandler *self, const xmlChar *name,
if ((value = rsvg_property_bag_lookup (atts, "offset")))
{
/* either a number [0,1] or a percentage */
offset = rsvg_css_parse_normalized_length (value, z->ctx->dpi, 1., 0.);
offset = rsvg_css_parse_normalized_length (value, rsvg_dpi_percentage (z->ctx), 1., 0.);
if (offset < 0.)
offset = 0.;
......@@ -484,19 +486,19 @@ rsvg_start_linear_gradient (RsvgHandle *ctx, RsvgPropertyBag *atts)
if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
if ((value = rsvg_property_bag_lookup (atts, "x1"))) {
x1 = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
x1 = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_x1 = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "y1"))) {
y1 = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
y1 = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_y1 = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "x2"))) {
x2 = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
x2 = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_x2 = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "y2"))) {
y2 = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
y2 = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_y2 = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "spreadMethod")))
......@@ -537,7 +539,7 @@ rsvg_start_linear_gradient (RsvgHandle *ctx, RsvgPropertyBag *atts)
if (obj_bbox)
x2 = 1.0;
else
x2 = rsvg_css_parse_normalized_length ("100%", ctx->dpi, (gdouble)ctx->width, state->font_size);
x2 = rsvg_css_parse_normalized_length ("100%", ctx->dpi_x, (gdouble)ctx->width, state->font_size);
}
if (xlink_href != NULL)
......@@ -626,24 +628,24 @@ rsvg_start_radial_gradient (RsvgHandle *ctx, RsvgPropertyBag *atts, const char *
if ((value = rsvg_property_bag_lookup (atts, "id")))
id = value;
if ((value = rsvg_property_bag_lookup (atts, "cx"))) {
cx = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
cx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_cx = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "cy"))) {
cy = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
cy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_cy = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "r"))) {
r = rsvg_css_parse_normalized_length (value, ctx->dpi, 1,
r = rsvg_css_parse_normalized_length (value, rsvg_dpi_percentage (ctx), 1,
state->font_size);
got_r = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "fx"))) {
fx = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
fx = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_fx = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "fy"))) {
fy = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
fy = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_fy = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "xlink:href")))
......@@ -702,19 +704,19 @@ rsvg_start_radial_gradient (RsvgHandle *ctx, RsvgPropertyBag *atts, const char *
if (obj_bbox)
cx = 0.5;
else
cx = rsvg_css_parse_normalized_length ("50%", ctx->dpi, (gdouble)ctx->width, state->font_size);
cx = rsvg_css_parse_normalized_length ("50%", ctx->dpi_x, (gdouble)ctx->width, state->font_size);
}
if (!got_cy) {
if (obj_bbox)
cy = 0.5;
else
cy = rsvg_css_parse_normalized_length ("50%", ctx->dpi, (gdouble)ctx->height, state->font_size);
cy = rsvg_css_parse_normalized_length ("50%", ctx->dpi_y, (gdouble)ctx->height, state->font_size);
}
if (!got_r) {
if (obj_bbox)
r = 0.5;
else
r = rsvg_css_parse_normalized_length ("50%", ctx->dpi, rsvg_viewport_percentage((gdouble)ctx->width, (gdouble)ctx->height), state->font_size);
r = rsvg_css_parse_normalized_length ("50%", rsvg_dpi_percentage (ctx), rsvg_viewport_percentage((gdouble)ctx->width, (gdouble)ctx->height), state->font_size);
}
if (!got_fx) {
fx = cx;
......@@ -793,19 +795,19 @@ rsvg_start_pattern (RsvgHandle *ctx, RsvgPropertyBag *atts)
&vbw, &vbh);
}
if ((value = rsvg_property_bag_lookup (atts, "x"))) {
x = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
x = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_x = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "y"))) {
y = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
y = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_y = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "width"))) {
width = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
width = rsvg_css_parse_normalized_length (value, ctx->dpi_x, 1, state->font_size);
got_width = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "height"))) {
height = rsvg_css_parse_normalized_length (value, ctx->dpi, 1, state->font_size);
height = rsvg_css_parse_normalized_length (value, ctx->dpi_y, 1, state->font_size);
got_height = TRUE;
}
if ((value = rsvg_property_bag_lookup (atts, "xlink:href")))
......@@ -1555,7 +1557,8 @@ rsvg_handle_init (RsvgHandle * handle)
handle->defs = rsvg_defs_new ();
handle->handler_nest = 0;
handle->entities = g_hash_table_new (g_str_hash, g_str_equal);
handle->dpi = internal_dpi;
handle->dpi_x = internal_dpi_x;
handle->dpi_y = internal_dpi_y;
handle->css_props = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
......@@ -1569,7 +1572,8 @@ rsvg_handle_init (RsvgHandle * handle)
/**
* rsvg_set_default_dpi
* @dpi: Dots Per Inch (aka Pixels Per Inch)
* @dpi_x: Dots Per Inch (aka Pixels Per Inch)
* @dpi_y: Dots Per Inch (aka Pixels Per Inch)
*
* Sets the DPI for the all future outgoing pixbufs. Common values are
* 72, 90, and 300 DPI. Passing a number <= 0 to #dpi will
......@@ -1578,18 +1582,24 @@ rsvg_handle_init (RsvgHandle * handle)
* Since: 2.2
*/
void
rsvg_set_default_dpi (double dpi)
rsvg_set_default_dpi (double dpi_x, double dpi_y)
{
if (dpi <= 0.)
internal_dpi = RSVG_DEFAULT_DPI;
if (dpi_x <= 0.)
internal_dpi_x = RSVG_DEFAULT_DPI_X;
else
internal_dpi = dpi;
internal_dpi_x = dpi_x;
if (dpi_y <= 0.)
internal_dpi_y = RSVG_DEFAULT_DPI_Y;
else
internal_dpi_y = dpi_y;
}
/**
* rsvg_handle_set_dpi
* @handle: An #RsvgHandle
* @dpi: Dots Per Inch (aka Pixels Per Inch)
* @dpi_x: Dots Per Inch (aka Pixels Per Inch)
* @dpi_y: Dots Per Inch (aka Pixels Per Inch)
*
* Sets the DPI for the outgoing pixbuf. Common values are
* 72, 90, and 300 DPI. Passing a number <= 0 to #dpi will
......@@ -1598,14 +1608,19 @@ rsvg_set_default_dpi (double dpi)
* Since: 2.2
*/
void
rsvg_handle_set_dpi (RsvgHandle * handle, double dpi)
rsvg_handle_set_dpi (RsvgHandle * handle, double dpi_x, double dpi_y)
{
g_return_if_fail (handle != NULL);
if (dpi <= 0.)
handle->dpi = internal_dpi;
if (dpi_x <= 0.)
handle->dpi_x = internal_dpi_x;
else
handle->dpi_x = dpi_x;
if (dpi_y <= 0.)
handle->dpi_y = internal_dpi_y;
else
handle->dpi = dpi;
handle->dpi_y = dpi_y;
}
/**
......
......@@ -54,10 +54,10 @@ typedef void (* RsvgSizeFunc) (gint *width,
gpointer user_data);
void rsvg_set_default_dpi (double dpi);
void rsvg_set_default_dpi (double dpi_x, double dpi_y);
RsvgHandle *rsvg_handle_new (void);
void rsvg_handle_set_dpi (RsvgHandle * handle, double dpi);
void rsvg_handle_set_dpi (RsvgHandle * handle, double dpi_x, double dpi_y);
void rsvg_handle_set_size_callback (RsvgHandle *handle,
RsvgSizeFunc size_func,
gpointer user_data,
......
......@@ -461,7 +461,8 @@ main (int argc, char **argv)
poptContext popt_context;
double x_zoom = 1.0;
double y_zoom = 1.0;
double dpi = -1.0;
double dpi_x = -1.0;
double dpi_y = -1.0;
int width = -1;
int height = -1;
int bVersion = 0;
......@@ -481,7 +482,8 @@ main (int argc, char **argv)
{ "xid", 'i', POPT_ARG_INT, &xid, 0, _("XWindow ID [for X11 embedding]"), _("<int>") },
#endif
{ "stdin", 's', POPT_ARG_NONE, &from_stdin, 0, _("Read from stdin instead of a file"), NULL },
{ "dpi", 'd', POPT_ARG_DOUBLE, &dpi, 0, _("Set the # of Pixels Per Inch"), _("<float>") },
{ "dpi-x", 'd', POPT_ARG_DOUBLE, &dpi_x, 0, _("Set the # of Pixels Per Inch"), _("<float>") },
{ "dpi-y", 'p', POPT_ARG_DOUBLE, &dpi_y, 0, _("Set the # of Pixels Per Inch"), _("<float>") },
{ "x-zoom", 'x', POPT_ARG_DOUBLE, &x_zoom, 0, _("Set the x zoom factor"), _("<float>") },
{ "y-zoom", 'y', POPT_ARG_DOUBLE, &y_zoom, 0, _("Set the y zoom factor"), _("<float>") },
{ "width", 'w', POPT_ARG_INT, &width, 0, _("Set the image's width"), _("<int>") },
......@@ -531,8 +533,7 @@ main (int argc, char **argv)
/* initialize gtk+ */
gtk_init (&argc, &argv) ;
if (dpi > 0.)
rsvg_set_default_dpi (dpi);
rsvg_set_default_dpi (dpi_x, dpi_y);
/* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
if (width == -1 && height == -1)
......
......@@ -37,7 +37,8 @@ main (int argc, const char **argv)
poptContext popt_context;
double x_zoom = 1.0;
double y_zoom = 1.0;
double dpi = -1.0;
double dpi_x = -1.0;
double dpi_y = -1.0;
int width = -1;
int height = -1;
int bVersion = 0;
......@@ -46,14 +47,15 @@ main (int argc, const char **argv)
char * format = "png";
struct poptOption options_table[] = {
{ "dpi" , 'd', POPT_ARG_DOUBLE, NULL, 0, "pixels per inch", "<float>"},
{ "x-zoom", 'x', POPT_ARG_DOUBLE, NULL, 0, "x zoom factor", "<float>" },
{ "y-zoom", 'y', POPT_ARG_DOUBLE, NULL, 0, "y zoom factor", "<float>" },
{ "width", 'w', POPT_ARG_INT, NULL, 0, "width", "<int>" },
{ "height", 'h', POPT_ARG_INT, NULL, 0, "height", "<int>" },
{ "quality", 'q', POPT_ARG_INT, NULL, 0, "JPEG quality", "<int>"},
{ "format", 'f', POPT_ARG_STRING, NULL, 0, "save format", "[png, jpeg]"},
{ "version", 'v', POPT_ARG_NONE, NULL, 0, "show version information", NULL },
{ "dpi-x", 'd', POPT_ARG_DOUBLE, &dpi_x, 0, "pixels per inch", "<float>"},
{ "dpi-y", 'p', POPT_ARG_DOUBLE, &dpi_y, 0, "pixels per inch", "<float>"},
{ "x-zoom", 'x', POPT_ARG_DOUBLE, &x_zoom, 0, "x zoom factor", "<float>" },
{ "y-zoom", 'y', POPT_ARG_DOUBLE, &y_zoom, 0, "y zoom factor", "<float>" },
{ "width", 'w', POPT_ARG_INT, &width, 0, "width", "<int>" },
{ "height", 'h', POPT_ARG_INT, &height, 0, "height", "<int>" },
{ "quality", 'q', POPT_ARG_INT, &quality, 0, "JPEG quality", "<int>"},
{ "format", 'f', POPT_ARG_STRING, &format, 0, "save format", "[png, jpeg]"},
{ "version", 'v', POPT_ARG_NONE, &bVersion, 0, "show version information", NULL },
POPT_AUTOHELP
POPT_TABLEEND
};
......@@ -62,15 +64,6 @@ main (int argc, const char **argv)
gint n_args = 0;
GdkPixbuf *pixbuf;
options_table[0].arg = &dpi;
options_table[1].arg = &x_zoom;
options_table[2].arg = &y_zoom;
options_table[3].arg = &width;
options_table[4].arg = &height;
options_table[5].arg = &quality;
options_table[6].arg = &format;
options_table[7].arg = &bVersion;
popt_context = poptGetContext ("rsvg", argc, argv, options_table, 0);
poptSetOtherOptionHelp(popt_context, "[OPTIONS...] file.svg file.png");
......@@ -101,8 +94,7 @@ main (int argc, const char **argv)
g_type_init ();
if (dpi > 0.)
rsvg_set_default_dpi (dpi);
rsvg_set_default_dpi (dpi_x, dpi_y);
/* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
if (width == -1 && height == -1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment