Commit ac8d26c9 authored by Christian Persch's avatar Christian Persch

Don't export private function _rsvg_size_callback

Move it to its own file, and include that in rsvg-convert and the tests.
parent acaa6c6f
......@@ -65,6 +65,8 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
rsvg.c \
rsvg-gobject.c \
rsvg-file-util.c \
rsvg-size-callback.c \
rsvg-size-callback.h \
rsvg-xml.c \
rsvg-xml.h \
rsvg.h \
......@@ -108,7 +110,10 @@ dist_man_MANS = rsvg.1
endif
rsvg_convert_SOURCES = \
rsvg-convert.c
rsvg-convert.c \
rsvg-size-callback.c \
rsvg-size-callback.h \
$(NULL)
rsvg_convert_CPPFLAGS = \
-I$(top_srcdir) \
......@@ -129,7 +134,8 @@ rsvg_convert_LDADD = \
$(LIBM)
rsvg_view_3_SOURCES = \
test-display.c
test-display.c \
rsvg-size-callback.h
rsvg_view_3_CPPFLAGS = \
-I$(top_srcdir) \
......
......@@ -34,7 +34,6 @@ rsvg_pixbuf_from_file_at_zoom_with_max
rsvg_handle_render_cairo
rsvg_handle_render_cairo_sub
rsvg_handle_get_type
_rsvg_size_callback
_rsvg_register_types
rsvg_defs_lookup
rsvg_pixbuf_from_data_with_size_data
......
......@@ -39,6 +39,7 @@
#include "rsvg.h"
#include "rsvg-cairo.h"
#include "rsvg-private.h"
#include "rsvg-size-callback.h"
#ifdef CAIRO_HAS_PS_SURFACE
#include <cairo-ps.h>
......
......@@ -37,95 +37,19 @@
#include "rsvg.h"
#include "rsvg-private.h"
#include "rsvg-io.h"
#include "rsvg-size-callback.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SVG_BUFFER_SIZE (1024 * 8)
void
_rsvg_size_callback (int *width, int *height, gpointer data)
{
struct RsvgSizeCallbackData *real_data = (struct RsvgSizeCallbackData *) data;
double zoomx, zoomy, zoom;
int in_width, in_height;
in_width = *width;
in_height = *height;
switch (real_data->type) {
case RSVG_SIZE_ZOOM:
if (*width < 0 || *height < 0)
return;
*width = floor (real_data->x_zoom * *width + 0.5);
*height = floor (real_data->y_zoom * *height + 0.5);
break;
case RSVG_SIZE_ZOOM_MAX:
if (*width < 0 || *height < 0)
return;
*width = floor (real_data->x_zoom * *width + 0.5);
*height = floor (real_data->y_zoom * *height + 0.5);
if (*width > real_data->width || *height > real_data->height) {
zoomx = (double) real_data->width / *width;
zoomy = (double) real_data->height / *height;
zoom = MIN (zoomx, zoomy);
*width = floor (zoom * *width + 0.5);
*height = floor (zoom * *height + 0.5);
}
break;
case RSVG_SIZE_WH_MAX:
if (*width < 0 || *height < 0)
return;
zoomx = (double) real_data->width / *width;
zoomy = (double) real_data->height / *height;
if (zoomx < 0)
zoom = zoomy;
else if (zoomy < 0)
zoom = zoomx;
else
zoom = MIN (zoomx, zoomy);
*width = floor (zoom * *width + 0.5);
*height = floor (zoom * *height + 0.5);
break;
case RSVG_SIZE_WH:
if (real_data->width != -1)
*width = real_data->width;
if (real_data->height != -1)
*height = real_data->height;
break;
default:
g_assert_not_reached ();
}
if (real_data->keep_aspect_ratio) {
int out_min = MIN (*width, *height);
if (out_min == *width) {
*height = in_height * ((double) *width / (double) in_width);
} else {
*width = in_width * ((double) *height / (double) in_height);
}
}
}
/* private */
GdkPixbuf *
rsvg_pixbuf_from_data_with_size_data (const guchar * buff,
size_t len,
struct RsvgSizeCallbackData *data,
/* RsvgSizeCallbackData */ gpointer data,
const char *base_uri, GError ** error)
{
RsvgHandle *handle;
......
......@@ -247,29 +247,10 @@ typedef struct {
gboolean virgin;
} RsvgBbox;
typedef enum {
RSVG_SIZE_ZOOM,
RSVG_SIZE_WH,
RSVG_SIZE_WH_MAX,
RSVG_SIZE_ZOOM_MAX
} RsvgSizeType;
typedef enum {
objectBoundingBox, userSpaceOnUse
} RsvgCoordUnits;
struct RsvgSizeCallbackData {
RsvgSizeType type;
double x_zoom;
double y_zoom;
gint width;
gint height;
gboolean keep_aspect_ratio;
};
void _rsvg_size_callback (int *width, int *height, gpointer data);
typedef enum {
RSVG_NODE_TYPE_INVALID = 0,
......@@ -355,7 +336,7 @@ void rsvg_property_bag_enumerate (RsvgPropertyBag * bag, RsvgPro
GdkPixbuf *rsvg_pixbuf_from_data_with_size_data (const guchar * buff,
size_t len,
struct RsvgSizeCallbackData *data,
gpointer data,
const char *base_uri, GError ** error);
gboolean rsvg_eval_switch_attributes (RsvgPropertyBag * atts, gboolean * p_has_cond);
......
/*
Copyright (C) 2000 Eazel, Inc.
Copyright (C) 2002 Dom Lachowicz <cinamod@hotmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Raph Levien <raph@artofcode.com>
*/
#include "config.h"
#include "rsvg-size-callback.h"
#include <math.h>
void
_rsvg_size_callback (int *width, int *height, gpointer data)
{
struct RsvgSizeCallbackData *real_data = (struct RsvgSizeCallbackData *) data;
double zoomx, zoomy, zoom;
int in_width, in_height;
in_width = *width;
in_height = *height;
switch (real_data->type) {
case RSVG_SIZE_ZOOM:
if (*width < 0 || *height < 0)
return;
*width = floor (real_data->x_zoom * *width + 0.5);
*height = floor (real_data->y_zoom * *height + 0.5);
break;
case RSVG_SIZE_ZOOM_MAX:
if (*width < 0 || *height < 0)
return;
*width = floor (real_data->x_zoom * *width + 0.5);
*height = floor (real_data->y_zoom * *height + 0.5);
if (*width > real_data->width || *height > real_data->height) {
zoomx = (double) real_data->width / *width;
zoomy = (double) real_data->height / *height;
zoom = MIN (zoomx, zoomy);
*width = floor (zoom * *width + 0.5);
*height = floor (zoom * *height + 0.5);
}
break;
case RSVG_SIZE_WH_MAX:
if (*width < 0 || *height < 0)
return;
zoomx = (double) real_data->width / *width;
zoomy = (double) real_data->height / *height;
if (zoomx < 0)
zoom = zoomy;
else if (zoomy < 0)
zoom = zoomx;
else
zoom = MIN (zoomx, zoomy);
*width = floor (zoom * *width + 0.5);
*height = floor (zoom * *height + 0.5);
break;
case RSVG_SIZE_WH:
if (real_data->width != -1)
*width = real_data->width;
if (real_data->height != -1)
*height = real_data->height;
break;
default:
g_assert_not_reached ();
}
if (real_data->keep_aspect_ratio) {
int out_min = MIN (*width, *height);
if (out_min == *width) {
*height = in_height * ((double) *width / (double) in_width);
} else {
*width = in_width * ((double) *height / (double) in_height);
}
}
}
/*
Copyright (C) 2000 Eazel, Inc.
Copyright (C) 2002 Dom Lachowicz <cinamod@hotmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Raph Levien <raph@artofcode.com>
*/
#ifndef RSVG_SIZE_CALLBACK_H
#define RSVG_SIZE_CALLBACK_H
#include <glib.h>
G_BEGIN_DECLS
typedef enum {
RSVG_SIZE_ZOOM,
RSVG_SIZE_WH,
RSVG_SIZE_WH_MAX,
RSVG_SIZE_ZOOM_MAX
} RsvgSizeType;
struct RsvgSizeCallbackData {
RsvgSizeType type;
double x_zoom;
double y_zoom;
gint width;
gint height;
gboolean keep_aspect_ratio;
};
G_GNUC_INTERNAL
void _rsvg_size_callback (int *width, int *height, gpointer data);
G_END_DECLS
#endif /* RSVG_SIZE_CALLBACK_H */
......@@ -21,6 +21,7 @@
#include "rsvg.h"
#include "rsvg-cairo.h"
#include "rsvg-private.h"
#include "rsvg-size-callback.h"
#include <stdio.h>
#include <stdlib.h>
......
......@@ -30,7 +30,9 @@ DISTCLEANFILES = rsvg-test.html \
libtest_utils_la_SOURCES = \
test-utils.c \
test-utils.h
test-utils.h \
$(top_srcdir)/rsvg-size-callback.c \
$(top_srcdir)/rsvg-size-callback.h
EXTRA_DIST = \
fixtures/crash/bug620238.svg \
......
......@@ -42,6 +42,7 @@
#include "rsvg.h"
#include "rsvg-cairo.h"
#include "rsvg-private.h"
#include "rsvg-size-callback.h"
#include "pdiff.h"
......
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