Rename geometry_for_element -> geometry_for_layer throughout

parent 6db7636c
......@@ -382,12 +382,12 @@ extern void rsvg_rust_handle_get_intrinsic_dimensions (RsvgHandle *handle,
RsvgLength *out_height,
gboolean *out_has_viewbox,
RsvgRectangle *out_viewbox);
extern gboolean rsvg_rust_handle_get_geometry_for_element (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error);
extern gboolean rsvg_rust_handle_get_geometry_for_layer (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error);
/* Implemented in rsvg_internals/src/c_api.rs */
......@@ -912,7 +912,7 @@ rsvg_handle_get_dimensions (RsvgHandle *handle, RsvgDimensionData *dimension_dat
* "##foo" (hash <literal>foo</literal>) to get the geometry of the element that
* has an <literal>id="foo"</literal> attribute.
*
* Deprecated: 2.46. Use rsvg_handle_get_geometry_for_element() instead.
* Deprecated: 2.46. Use rsvg_handle_get_geometry_for_layer() instead.
*
* Since: 2.22
*/
......@@ -945,7 +945,7 @@ rsvg_handle_get_dimensions_sub (RsvgHandle *handle,
* "##foo" (hash <literal>foo</literal>) to get the geometry of the element that
* has an <literal>id="foo"</literal> attribute.
*
* Deprecated: 2.46. Use rsvg_handle_get_geometry_for_element() instead.
* Deprecated: 2.46. Use rsvg_handle_get_geometry_for_layer() instead.
*
* Since: 2.22
*/
......@@ -1224,7 +1224,7 @@ rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
}
/**
* rsvg_handle_get_geometry_for_element:
* rsvg_handle_get_geometry_for_layer:
* @handle: An #RsvgHandle
* @id: (nullable): An element's id within the SVG, starting with "##" (a single
* hash character), for example, "##layer1". This notation corresponds to a
......@@ -1266,23 +1266,23 @@ rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
* Since: 2.46
*/
gboolean
rsvg_handle_get_geometry_for_element (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error)
rsvg_handle_get_geometry_for_layer (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error)
{
g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
g_return_val_if_fail (viewport != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return rsvg_rust_handle_get_geometry_for_element (handle,
id,
viewport,
out_ink_rect,
out_logical_rect,
error);
return rsvg_rust_handle_get_geometry_for_layer (handle,
id,
viewport,
out_ink_rect,
out_logical_rect,
error);
}
/**
......
......@@ -281,12 +281,12 @@ void rsvg_handle_get_intrinsic_dimensions (RsvgHandle *handle,
RsvgRectangle *out_viewbox);
RSVG_API
gboolean rsvg_handle_get_geometry_for_element (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error);
gboolean rsvg_handle_get_geometry_for_layer (RsvgHandle *handle,
const char *id,
const RsvgRectangle *viewport,
RsvgRectangle *out_ink_rect,
RsvgRectangle *out_logical_rect,
GError **error);
/* GIO APIs */
......
......@@ -374,6 +374,22 @@ impl<'a> CairoRenderer<'a> {
}
}
/// Renders the whole SVG document fitted to a viewport
///
/// The `viewport` gives the position and size at which the whole SVG
/// document will be rendered.
///
/// The `cr` must be in a `cairo::Status::Success` state, or this function
/// will not render anything, and instead will return
/// `RenderingError::Cairo` with the `cr`'s current error state.
pub fn render_document(
&self,
cr: &cairo::Context,
viewport: &cairo::Rectangle,
) -> Result<(), RenderingError> {
self.handle.0.render_document(cr, viewport, self.dpi, false)
}
/// Computes the (ink_rect, logical_rect) of an SVG element, as if
/// the SVG were rendered to a specific viewport.
///
......@@ -398,33 +414,17 @@ impl<'a> CairoRenderer<'a> {
/// the child elements.
///
/// FIXME: example
pub fn geometry_for_element(
pub fn geometry_for_layer(
&self,
id: Option<&str>,
viewport: &cairo::Rectangle,
) -> Result<(cairo::Rectangle, cairo::Rectangle), RenderingError> {
self.handle
.0
.get_geometry_for_element(id, viewport, self.dpi, false)
.get_geometry_for_layer(id, viewport, self.dpi, false)
.map(|(i, l)| (i.into(), l.into()))
}
/// Renders the whole SVG document fitted to a viewport
///
/// The `viewport` gives the position and size at which the whole SVG
/// document will be rendered.
///
/// The `cr` must be in a `cairo::Status::Success` state, or this function
/// will not render anything, and instead will return
/// `RenderingError::Cairo` with the `cr`'s current error state.
pub fn render_document(
&self,
cr: &cairo::Context,
viewport: &cairo::Rectangle,
) -> Result<(), RenderingError> {
self.handle.0.render_document(cr, viewport, self.dpi, false)
}
/// Renders a single SVG element in the same place as for a whole SVG document
///
/// This is equivalent to `render_document`, but renders only a single element and its
......
......@@ -74,7 +74,7 @@ fn root_geometry_with_percent_viewport() {
height: 100.0,
};
let (ink_r, logical_r) = renderer.geometry_for_element(None, &viewport).unwrap();
let (ink_r, logical_r) = renderer.geometry_for_layer(None, &viewport).unwrap();
let rect = cairo::Rectangle {
x: 10.0,
......@@ -87,7 +87,7 @@ fn root_geometry_with_percent_viewport() {
}
#[test]
fn element_geometry_with_percent_viewport() {
fn layer_geometry_with_percent_viewport() {
let svg = load_svg(
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
......@@ -106,7 +106,7 @@ fn element_geometry_with_percent_viewport() {
};
let (ink_r, logical_r) = renderer
.geometry_for_element(Some("#foo"), &viewport)
.geometry_for_layer(Some("#foo"), &viewport)
.unwrap();
let rect = cairo::Rectangle {
......@@ -120,7 +120,7 @@ fn element_geometry_with_percent_viewport() {
}
#[test]
fn element_geometry_viewport_viewbox() {
fn layer_geometry_viewport_viewbox() {
let svg = load_svg(
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="400" viewBox="0 0 100 400">
......@@ -140,7 +140,7 @@ fn element_geometry_viewport_viewbox() {
};
let (ink_r, logical_r) = renderer
.geometry_for_element(Some("#two"), &viewport)
.geometry_for_layer(Some("#two"), &viewport)
.unwrap();
let rect = cairo::Rectangle {
......@@ -154,7 +154,7 @@ fn element_geometry_viewport_viewbox() {
}
#[test]
fn element_geometry_for_nonexistent_element() {
fn layer_geometry_for_nonexistent_element() {
let svg = load_svg(
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>
......@@ -170,14 +170,14 @@ fn element_geometry_for_nonexistent_element() {
let renderer = CairoRenderer::new(&svg);
match renderer.geometry_for_element(Some("#foo"), &viewport) {
match renderer.geometry_for_layer(Some("#foo"), &viewport) {
Err(RenderingError::InvalidId(DefsLookupErrorKind::NotFound)) => (),
_ => panic!(),
}
}
#[test]
fn element_geometry_for_invalid_id() {
fn layer_geometry_for_invalid_id() {
let svg = load_svg(
br#"<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>
......@@ -192,17 +192,17 @@ fn element_geometry_for_invalid_id() {
};
let renderer = CairoRenderer::new(&svg);
match renderer.geometry_for_element(Some("foo"), &viewport) {
match renderer.geometry_for_layer(Some("foo"), &viewport) {
Err(RenderingError::InvalidId(DefsLookupErrorKind::CannotLookupExternalReferences)) => (),
_ => panic!(),
}
match renderer.geometry_for_element(Some("foo.svg#foo"), &viewport) {
match renderer.geometry_for_layer(Some("foo.svg#foo"), &viewport) {
Err(RenderingError::InvalidId(DefsLookupErrorKind::CannotLookupExternalReferences)) => (),
_ => panic!(),
}
match renderer.geometry_for_element(Some(""), &viewport) {
match renderer.geometry_for_layer(Some(""), &viewport) {
Err(RenderingError::InvalidId(DefsLookupErrorKind::HrefError(HrefError::ParseError))) => (),
_ => panic!(),
}
......
......@@ -702,13 +702,13 @@ impl CHandle {
handle.get_pixbuf_sub(id, self.dpi.get(), &*size_callback, self.is_testing.get())
}
fn get_geometry_for_element(
fn get_geometry_for_layer(
&self,
id: Option<&str>,
viewport: &cairo::Rectangle,
) -> Result<(RsvgRectangle, RsvgRectangle), RenderingError> {
let handle = self.get_handle_ref()?;
handle.get_geometry_for_element(id, viewport, self.dpi.get(), self.is_testing.get())
handle.get_geometry_for_layer(id, viewport, self.dpi.get(), self.is_testing.get())
}
fn get_intrinsic_dimensions(&self) -> Result<IntrinsicDimensions, RenderingError> {
......@@ -1250,7 +1250,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_intrinsic_dimensions(
}
#[no_mangle]
pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_element(
pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_layer(
handle: *mut RsvgHandle,
id: *const libc::c_char,
viewport: *const RsvgRectangle,
......@@ -1262,7 +1262,7 @@ pub unsafe extern "C" fn rsvg_rust_handle_get_geometry_for_element(
let id: Option<String> = from_glib_none(id);
match rhandle.get_geometry_for_element(id.as_ref().map(String::as_str), &(*viewport).into()) {
match rhandle.get_geometry_for_layer(id.as_ref().map(String::as_str), &(*viewport).into()) {
Ok((ink_rect, logical_rect)) => {
if !out_ink_rect.is_null() {
*out_ink_rect = ink_rect;
......
......@@ -252,7 +252,7 @@ impl Handle {
}
}
pub fn get_geometry_for_element(
pub fn get_geometry_for_layer(
&self,
id: Option<&str>,
viewport: &cairo::Rectangle,
......
......@@ -15,7 +15,7 @@ pub use crate::c_api::{
rsvg_rust_handle_get_dpi_x,
rsvg_rust_handle_get_dpi_y,
rsvg_rust_handle_get_flags,
rsvg_rust_handle_get_geometry_for_element,
rsvg_rust_handle_get_geometry_for_layer,
rsvg_rust_handle_get_intrinsic_dimensions,
rsvg_rust_handle_get_pixbuf_sub,
rsvg_rust_handle_get_position_sub,
......
......@@ -944,7 +944,7 @@ get_intrinsic_dimensions (void)
}
static void
get_geometry_for_element (void)
get_geometry_for_layer (void)
{
char *filename = get_test_filename ("geometry.svg");
GError *error = NULL;
......@@ -959,15 +959,15 @@ get_geometry_for_element (void)
RsvgRectangle ink_rect;
RsvgRectangle logical_rect;
g_assert (!rsvg_handle_get_geometry_for_element (handle, "#nonexistent", &viewport,
&ink_rect, &logical_rect, &error));
g_assert (!rsvg_handle_get_geometry_for_layer (handle, "#nonexistent", &viewport,
&ink_rect, &logical_rect, &error));
g_assert (error != NULL);
g_error_free (error);
error = NULL;
g_assert (rsvg_handle_get_geometry_for_element (handle, "#two", &viewport,
&ink_rect, &logical_rect, &error));
g_assert (rsvg_handle_get_geometry_for_layer (handle, "#two", &viewport,
&ink_rect, &logical_rect, &error));
g_assert (error == NULL);
g_assert_cmpfloat (ink_rect.x, ==, 5.0);
......@@ -1205,7 +1205,7 @@ main (int argc, char **argv)
g_test_add_func ("/api/can_draw_to_non_image_surface", can_draw_to_non_image_surface);
g_test_add_func ("/api/render_cairo_sub", render_cairo_sub);
g_test_add_func ("/api/get_intrinsic_dimensions", get_intrinsic_dimensions);
g_test_add_func ("/api/get_geometry_for_element", get_geometry_for_element);
g_test_add_func ("/api/get_geometry_for_layer", get_geometry_for_layer);
g_test_add_func ("/api/no_write_before_close", no_write_before_close);
g_test_add_func ("/api/empty_write_close", empty_write_close);
g_test_add_func ("/api/cannot_request_external_elements", cannot_request_external_elements);
......
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