New API: Replace cairo_{ps,pdf,svg}_set_dpi with new cairo_surface_set_fallback_resolution.

This just provides the mechanics for storing the value and removing the old
function calls. The new value is still not used anywhere (though nor where
the old values), so there should be no functional change (other than forcing
any programs calling the old API to be updated).
This commit is contained in:
Carl Worth 2006-06-09 16:52:17 -07:00
parent a812b3c490
commit b2f274b3e8
11 changed files with 58 additions and 127 deletions

View file

@ -110,8 +110,6 @@ typedef struct _cairo_pdf_surface {
double width;
double height;
double x_dpi;
double y_dpi;
cairo_array_t objects;
cairo_array_t pages;
@ -138,7 +136,6 @@ typedef struct _cairo_pdf_surface {
cairo_paginated_mode_t paginated_mode;
} cairo_pdf_surface_t;
#define PDF_SURFACE_DPI_DEFAULT 300
#define PDF_SURFACE_MAX_GLYPHS_PER_FONT 256
static cairo_pdf_resource_t
@ -269,8 +266,6 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t *output,
surface->width = width;
surface->height = height;
surface->x_dpi = PDF_SURFACE_DPI_DEFAULT;
surface->y_dpi = PDF_SURFACE_DPI_DEFAULT;
_cairo_array_init (&surface->objects, sizeof (cairo_pdf_object_t));
_cairo_array_init (&surface->pages, sizeof (cairo_pdf_resource_t));
@ -412,36 +407,6 @@ _extract_pdf_surface (cairo_surface_t *surface,
return CAIRO_STATUS_SUCCESS;
}
/**
* cairo_pdf_surface_set_dpi:
* @surface: a PDF cairo_surface_t
* @x_dpi: horizontal dpi
* @y_dpi: vertical dpi
*
* Set the horizontal and vertical resolution for image fallbacks.
* When the pdf backend needs to fall back to image overlays, it will
* use this resolution. These DPI values are not used for any other
* purpose, (in particular, they do not have any bearing on the size
* passed to cairo_pdf_surface_create() nor on the CTM).
**/
void
cairo_pdf_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi)
{
cairo_pdf_surface_t *pdf_surface;
cairo_status_t status;
status = _extract_pdf_surface (surface, &pdf_surface);
if (status) {
_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return;
}
pdf_surface->x_dpi = x_dpi;
pdf_surface->y_dpi = y_dpi;
}
/**
* cairo_pdf_surface_set_size:
* @surface: a PDF cairo_surface_t

View file

@ -54,11 +54,6 @@ cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func,
double width_in_points,
double height_in_points);
cairo_public void
cairo_pdf_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi);
void
cairo_pdf_surface_set_size (cairo_surface_t *surface,
double width_in_points,

View file

@ -67,8 +67,6 @@ typedef struct cairo_ps_surface {
double height;
double max_width;
double max_height;
double x_dpi;
double y_dpi;
int num_pages;
@ -84,7 +82,6 @@ typedef struct cairo_ps_surface {
} cairo_ps_surface_t;
#define PS_SURFACE_DPI_DEFAULT 300.0
#define PS_SURFACE_MAX_GLYPHS_PER_FONT 256
static cairo_status_t
@ -376,8 +373,6 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
surface->height = height;
surface->max_width = width;
surface->max_height = height;
surface->x_dpi = PS_SURFACE_DPI_DEFAULT;
surface->y_dpi = PS_SURFACE_DPI_DEFAULT;
surface->paginated_mode = CAIRO_PAGINATED_MODE_ANALYZE;
surface->num_pages = 0;
@ -519,36 +514,6 @@ _extract_ps_surface (cairo_surface_t *surface,
return CAIRO_STATUS_SUCCESS;
}
/**
* cairo_ps_surface_set_dpi:
* @surface: a PostScript cairo_surface_t
* @x_dpi: horizontal dpi
* @y_dpi: vertical dpi
*
* Set the horizontal and vertical resolution for image fallbacks.
* When the ps backend needs to fall back to image overlays, it will
* use this resolution. These DPI values are not used for any other
* purpose, (in particular, they do not have any bearing on the size
* passed to cairo_ps_surface_create() nor on the CTM).
**/
void
cairo_ps_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi)
{
cairo_ps_surface_t *ps_surface;
cairo_status_t status;
status = _extract_ps_surface (surface, &ps_surface);
if (status) {
_cairo_surface_set_error (surface, status);
return;
}
ps_surface->x_dpi = x_dpi;
ps_surface->y_dpi = y_dpi;
}
/**
* cairo_ps_surface_set_size:
* @surface: a PostScript cairo_surface_t

View file

@ -73,11 +73,6 @@ cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface);
cairo_public void
cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface);
cairo_public void
cairo_ps_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi);
CAIRO_END_DECLS
#else /* CAIRO_HAS_PS_SURFACE */

View file

@ -55,6 +55,8 @@ const cairo_surface_t _cairo_surface_nil = {
}, /* user_data */
0.0, /* device_x_offset */
0.0, /* device_y_offset */
0.0, /* x_fallback_resolution */
0.0, /* y_fallback_resolution */
0, /* next_clip_serial */
0 /* current_clip_serial */
};
@ -73,6 +75,8 @@ const cairo_surface_t _cairo_surface_nil_file_not_found = {
}, /* user_data */
0.0, /* device_x_offset */
0.0, /* device_y_offset */
0.0, /* x_fallback_resolution */
0.0, /* y_fallback_resolution */
0, /* next_clip_serial */
0 /* current_clip_serial */
};
@ -91,6 +95,8 @@ const cairo_surface_t _cairo_surface_nil_read_error = {
}, /* user_data */
0.0, /* device_x_offset */
0.0, /* device_y_offset */
0.0, /* x_fallback_resolution */
0.0, /* y_fallback_resolution */
0, /* next_clip_serial */
0 /* current_clip_serial */
};
@ -200,6 +206,9 @@ _cairo_surface_init (cairo_surface_t *surface,
surface->device_x_offset = 0.0;
surface->device_y_offset = 0.0;
surface->x_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT;
surface->y_fallback_resolution = CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT;
surface->clip = NULL;
surface->next_clip_serial = 0;
surface->current_clip_serial = 0;
@ -651,6 +660,38 @@ cairo_surface_get_device_offset (cairo_surface_t *surface,
*y_offset = surface->device_y_offset;
}
/**
* cairo_surface_set_fallback_resolution:
* @surface: a #cairo_surface_t
* @x_pixels_per_inch: horizontal setting for pixels per inch
* @y_pixels_per_inch: vertical setting for pixels per inch
*
* Set the horizontal and vertical resolution for image fallbacks.
*
* When certain operations aren't supported natively by a backend,
* cairo will fallback by rendering operations to an image and then
* overlaying that image onto the output. For backends that are
* natively vector-oriented, this function can be used to set the
* resolution used for these image fallbacks, (larger values will
* result in more detailed images, but also larger file sizes).
*
* Some examples of natively vector-oriented backends are the ps, pdf,
* and svg backends.
*
* For backends that are natively raster-oriented, image fallbacks are
* still possible, but they are always performed at the native
* device resolution. So this function has no effect on those
* backends.
**/
void
cairo_surface_set_fallback_resolution (cairo_surface_t *surface,
double x_pixels_per_inch,
double y_pixels_per_inch)
{
surface->x_fallback_resolution = x_pixels_per_inch;
surface->y_fallback_resolution = y_pixels_per_inch;
}
cairo_bool_t
_cairo_surface_has_device_offset_or_scale (cairo_surface_t *surface)
{
@ -1934,3 +1975,6 @@ _cairo_surface_copy_pattern_for_destination (const cairo_pattern_t *pattern,
_cairo_pattern_transform (pattern_out, &device_to_surface);
}
}
/* LocalWords: rasterized
*/

View file

@ -53,8 +53,6 @@
#define CAIRO_SVG_DTOSTR_BUFFER_LEN 30
#define CAIRO_SVG_DEFAULT_DPI 300
typedef struct cairo_svg_document cairo_svg_document_t;
typedef struct cairo_svg_surface cairo_svg_surface_t;
@ -84,8 +82,6 @@ struct cairo_svg_document {
double width;
double height;
double x_dpi;
double y_dpi;
xmlDocPtr xml_doc;
xmlNodePtr xml_node_defs;
@ -265,38 +261,6 @@ _extract_svg_surface (cairo_surface_t *surface,
return CAIRO_STATUS_SUCCESS;
}
/**
* cairo_svg_surface_set_dpi:
* @surface: a svg cairo_surface_t
* @x_dpi: horizontal dpi
* @y_dpi: vertical dpi
*
* Set the horizontal and vertical resolution for image fallbacks.
* When the svg backend needs to fall back to image overlays, it will
* use this resolution. These DPI values are not used for any other
* purpose (in particular, they do not have any bearing on the size
* passed to cairo_pdf_surface_create() nor on the CTM).
**/
void
cairo_svg_surface_set_dpi (cairo_surface_t *abstract_surface,
double x_dpi,
double y_dpi)
{
cairo_svg_surface_t *surface;
cairo_status_t status;
status = _extract_svg_surface (abstract_surface, &surface);
if (status) {
_cairo_surface_set_error (abstract_surface,
CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
return;
}
surface->document->x_dpi = x_dpi;
surface->document->y_dpi = y_dpi;
}
/**
* cairo_svg_surface_restrict_to_version:
* @surface: a SVG #cairo_surface_t
@ -1841,8 +1805,6 @@ _cairo_svg_document_create (cairo_output_stream_t *output_stream,
document->finished = FALSE;
document->width = width;
document->height = height;
document->x_dpi = CAIRO_SVG_DEFAULT_DPI;
document->y_dpi = CAIRO_SVG_DEFAULT_DPI;
document->surface_id = 0;
document->linear_pattern_id = 0;

View file

@ -55,11 +55,6 @@ cairo_svg_surface_create_for_stream (cairo_write_func_t write_func,
double width_in_points,
double height_in_points);
cairo_public void
cairo_svg_surface_set_dpi (cairo_surface_t *surface,
double x_dpi,
double y_dpi);
cairo_public void
cairo_svg_surface_restrict_to_version (cairo_surface_t *surface,
cairo_svg_version_t version);

View file

@ -1317,6 +1317,11 @@ cairo_surface_get_device_offset (cairo_surface_t *surface,
double *x_offset,
double *y_offset);
cairo_public void
cairo_surface_set_fallback_resolution (cairo_surface_t *surface,
double x_pixels_per_inch,
double y_pixels_per_inch);
/* Image-surface functions */
/**

View file

@ -858,6 +858,9 @@ struct _cairo_surface {
double device_x_offset;
double device_y_offset;
double x_fallback_resolution;
double y_fallback_resolution;
cairo_clip_t *clip;
/*
@ -1033,6 +1036,8 @@ typedef struct _cairo_traps {
#define CAIRO_GSTATE_MITER_LIMIT_DEFAULT 10.0
#define CAIRO_GSTATE_DEFAULT_FONT_SIZE 10.0
#define CAIRO_SURFACE_FALLBACK_RESOLUTION_DEFAULT 300.0
typedef struct _cairo_gstate cairo_gstate_t;
typedef struct _cairo_stroke_face {

View file

@ -1158,7 +1158,7 @@ create_ps_surface (cairo_test_t *test,
free (ptc);
return NULL;
}
cairo_ps_surface_set_dpi (surface, 72., 72.);
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
ptc->target = surface;
@ -1259,7 +1259,7 @@ create_pdf_surface (cairo_test_t *test,
free (ptc);
return NULL;
}
cairo_pdf_surface_set_dpi (surface, 72., 72.);
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
ptc->target = surface;
@ -1369,7 +1369,7 @@ create_svg_surface (cairo_test_t *test,
free (ptc);
return NULL;
}
cairo_svg_surface_set_dpi (surface, 72., 72.);
cairo_surface_set_fallback_resolution (surface, 72., 72.);
if (content == CAIRO_CONTENT_COLOR) {
ptc->target = surface;

View file

@ -58,7 +58,7 @@ main (void)
cairo_pdf_test_force_fallbacks ();
for (i = 0; i < sizeof(dpi) / sizeof (dpi[0]); i++) {
cairo_pdf_surface_set_dpi (surface, dpi[i], dpi[i]);
cairo_surface_set_fallback_resolution (surface, dpi[i], dpi[i]);
cairo_arc (cr, SIZE / 2.0, SIZE / 2.0,
0.75 * SIZE / 2.0,
0, 2.0 * M_PI);