Class: Rsvg::Handle
- Inherits:
-
Object
- Object
- Rsvg::Handle
- Defined in:
- lib/rsvg2/handle.rb
Overview
Class structure for [classRsvg.Handle].
Class Method Summary collapse
-
.new_from_data(data) ⇒ Object
For backward compatibility.
-
.new_from_file(file_name, options = {}) ⇒ Object
For backward compatibility.
Instance Method Summary collapse
-
#base_gfile=(base_file) ⇒ nil
Set the base URI for handle from file.
-
#base_uri ⇒ String
Base URI, to be used to resolve relative references for resources.
-
#base_uri=(base_uri) ⇒ String
Base URI, to be used to resolve relative references for resources.
-
#close ⇒ Boolean
This is used after calling [methodRsvg.Handle.write] to indicate that there is no more data to consume, and to start the actual parsing of the SVG document.
-
#desc ⇒ String
SVG's description.
-
#desc=(desc) ⇒ String
SVG's description.
-
#dpi=(dpi) ⇒ nil
Sets the DPI at which the handle will be rendered.
-
#dpi_x ⇒ Float
Horizontal resolution in dots per inch.
-
#dpi_x=(dpi_x) ⇒ Float
Horizontal resolution in dots per inch.
-
#dpi_y ⇒ Float
Horizontal resolution in dots per inch.
-
#dpi_y=(dpi_y) ⇒ Float
Horizontal resolution in dots per inch.
-
#em ⇒ Float
Exact width, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#em=(em) ⇒ Float
Exact width, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#ex ⇒ Float
Exact height, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#ex=(ex) ⇒ Float
Exact height, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#flags ⇒ Rsvg::HandleFlags
Flags from [flagsRsvg.HandleFlags].
-
#flags=(flags) ⇒ Rsvg::HandleFlags
Flags from [flagsRsvg.HandleFlags].
-
#free ⇒ nil
Frees handle.
-
#get_dimensions(dimension_data) ⇒ nil
Get the SVG's size.
-
#get_dimensions_sub(dimension_data, id) ⇒ Boolean
Get the size of a subelement of the SVG file.
-
#get_geometry_for_element(id, out_ink_rect, out_logical_rect) ⇒ Boolean
Computes the ink rectangle and logical rectangle of a single SVG element.
-
#get_geometry_for_layer(id, viewport, out_ink_rect, out_logical_rect) ⇒ Boolean
Computes the ink rectangle and logical rectangle of an SVG element, or the whole SVG, as if the whole SVG were rendered to a specific viewport.
-
#get_intrinsic_dimensions(out_has_width, out_width, out_has_height, out_height, out_has_viewbox, out_viewbox) ⇒ nil
In simple terms, queries the
width,height, andviewBoxattributes in an SVG document. -
#get_intrinsic_size_in_pixels(out_width, out_height) ⇒ Boolean
Converts an SVG document's intrinsic dimensions to pixels, and returns the result.
-
#get_pixbuf_sub(id) ⇒ GdkPixbuf::Pixbuf
Creates a
GdkPixbufthe same size as the entire SVG loaded into handle, but only renders the sub-element that has the specified id (and all its sub-sub-elements recursively). -
#get_position_sub(position_data, id) ⇒ Boolean
Get the position of a subelement of the SVG file.
-
#has_sub(id) ⇒ Boolean
Checks whether the element id exists in the SVG document.
-
#height ⇒ Integer
Height, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#height=(height) ⇒ Integer
Height, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#initialize(options = {}) ⇒ Rsvg::Handle
constructor
Creates a new [classRsvg.Handle] with flags flags.
-
#initialize_raw ⇒ Rsvg::Handle
Creates a new [classRsvg.Handle] with flags flags.
-
#internal_set_testing(testing) ⇒ nil
Do not call this function.
-
#metadata ⇒ String
SVG's metadata.
-
#metadata=(metadata) ⇒ String
SVG's metadata.
-
#pixbuf ⇒ GdkPixbuf::Pixbuf
Returns the pixbuf loaded by handle.
-
#read_stream_sync(stream, cancellable) ⇒ Boolean
Reads stream and writes the data from it to handle.
-
#render_cairo(cr) ⇒ Boolean
Draws a loaded SVG handle to a Cairo context.
-
#render_cairo_sub(cr, id) ⇒ Boolean
Renders a single SVG element in the same place as for a whole SVG document (a "subset" of the document).
-
#render_document(cr, viewport) ⇒ Boolean
Renders the whole SVG document fitted to a viewport.
-
#render_element(cr, id, element_viewport) ⇒ Boolean
Renders a single SVG element to a given viewport.
-
#render_layer(cr, id, viewport) ⇒ Boolean
Renders a single SVG element in the same place as for a whole SVG document.
-
#set_dpi_x_y(dpi_x, dpi_y) ⇒ nil
Sets the DPI at which the handle will be rendered.
-
#set_size_callback(size_func, user_data, user_data_destroy) ⇒ nil
Sets the sizing function for the handle, which can be used to override the size that librsvg computes for SVG images.
-
#set_stylesheet(css, css_len) ⇒ Boolean
Sets a CSS stylesheet to use for an SVG document.
-
#title ⇒ String
SVG's title.
-
#title=(title) ⇒ String
SVG's title.
-
#width ⇒ Integer
Width, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#width=(width) ⇒ Integer
Width, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
-
#write(buf, count) ⇒ Boolean
Loads the next count bytes of the image.
Constructor Details
#initialize(options = {}) ⇒ Rsvg::Handle
Creates a new [classRsvg.Handle] with flags flags. After calling this function, you can feed the resulting handle with SVG data by using [methodRsvg.Handle.read_stream_sync].
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rsvg2/handle.rb', line 32 def initialize(={}) flags = [:flags] path = [:path] || [:file] data = [:data] if path if flags Gio::File.open(:path => path) do |file| initialize_new_from_gfile_sync(file, flags) end else initialize_new_from_file(path) end elsif data initialize_new_from_data(data) else initialize_raw end end |
Class Method Details
.new_from_data(data) ⇒ Object
For backward compatibility
21 22 23 |
# File 'lib/rsvg2/handle.rb', line 21 def new_from_data(data) new(:data => data) end |
.new_from_file(file_name, options = {}) ⇒ Object
For backward compatibility
26 27 28 |
# File 'lib/rsvg2/handle.rb', line 26 def new_from_file(file_name, ={}) new(.merge(:file => file_name)) end |
Instance Method Details
#base_gfile=(base_file) ⇒ nil
Set the base URI for handle from file.
Note: This function may only be called before [methodRsvg.Handle.write] or [methodRsvg.Handle.read_stream_sync] have been called.
#base_uri ⇒ String
Base URI, to be used to resolve relative references for resources. See the section "Security and locations of referenced files" for details.
#base_uri=(base_uri) ⇒ String
Base URI, to be used to resolve relative references for resources. See the section "Security and locations of referenced files" for details.
#close ⇒ Boolean
This is used after calling [methodRsvg.Handle.write] to indicate that there is no more data to consume, and to start the actual parsing of the SVG document. The only reason to call this function is if you use use [methodRsvg.Handle.write] to feed data into the handle; if you use the other methods like [ctorRsvg.Handle.new_from_file] or [methodRsvg.Handle.read_stream_sync], then you do not need to call this function.
This will return TRUE if the loader closed successfully and the
SVG data was parsed correctly. Note that handle isn't freed until
[methodGObject.Object.unref] is called.
#desc ⇒ String
SVG's description.
#desc=(desc) ⇒ String
SVG's description.
#dpi=(dpi) ⇒ nil
Sets the DPI at which the handle will be rendered. Common values are 75, 90, and 300 DPI.
Passing a number <= 0 to dpi will reset the DPI to whatever the default value happens to be, but since [idrsvg_set_default_dpi] is deprecated, please do not pass values <= 0 to this function.
#dpi_x ⇒ Float
Horizontal resolution in dots per inch.
#dpi_x=(dpi_x) ⇒ Float
Horizontal resolution in dots per inch.
#dpi_y ⇒ Float
Horizontal resolution in dots per inch.
#dpi_y=(dpi_y) ⇒ Float
Horizontal resolution in dots per inch.
#em ⇒ Float
Exact width, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#em=(em) ⇒ Float
Exact width, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#ex ⇒ Float
Exact height, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#ex=(ex) ⇒ Float
Exact height, in pixels, of the rendered SVG before calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#flags ⇒ Rsvg::HandleFlags
Flags from [flagsRsvg.HandleFlags].
#flags=(flags) ⇒ Rsvg::HandleFlags
Flags from [flagsRsvg.HandleFlags].
#free ⇒ nil
Frees handle.
#get_dimensions(dimension_data) ⇒ nil
Get the SVG's size. Do not call from within the size_func callback, because an infinite loop will occur.
This function depends on the [classRsvg.Handle]'s DPI to compute dimensions in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
#get_dimensions_sub(dimension_data, id) ⇒ Boolean
Get the size of a subelement of the SVG file. Do not call from within the size_func callback, because an infinite loop will occur.
This function depends on the [classRsvg.Handle]'s DPI to compute dimensions in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to use the whole SVG.
#get_geometry_for_element(id, out_ink_rect, out_logical_rect) ⇒ Boolean
Computes the ink rectangle and logical rectangle of a single SVG element.
While rsvg_handle_get_geometry_for_layer computes the geometry of an SVG element subtree with
its transformation matrix, this other function will compute the element's geometry
as if it were being rendered under an identity transformation by itself. That is,
the resulting geometry is as if the element got extracted by itself from the SVG.
This function is the counterpart to rsvg_handle_render_element.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
The "ink rectangle" is the bounding box that would be painted for fully- stroked and filled elements.
The "logical rectangle" just takes into account the unstroked paths and text outlines.
Note that these bounds are not minimum bounds; for example, clipping paths are not taken into account.
You can pass NULL for the id if you want to measure all
the elements in the SVG, i.e. to measure everything from the
root element.
This operation is not constant-time, as it involves going through all
the child elements.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to compute the geometry for the
whole SVG.
are returned in the error argument.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#get_geometry_for_layer(id, viewport, out_ink_rect, out_logical_rect) ⇒ Boolean
Computes the ink rectangle and logical rectangle of an SVG element, or the whole SVG, as if the whole SVG were rendered to a specific viewport.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
The "ink rectangle" is the bounding box that would be painted for fully-stroked and filled elements.
The "logical rectangle" just takes into account the unstroked paths and text outlines.
Note that these bounds are not minimum bounds; for example, clipping paths are not taken into account.
You can pass NULL for the id if you want to measure all
the elements in the SVG, i.e. to measure everything from the
root element.
This operation is not constant-time, as it involves going through all
the child elements.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to compute the geometry for the
whole SVG.
are returned in the error argument.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#get_intrinsic_dimensions(out_has_width, out_width, out_has_height, out_height, out_has_viewbox, out_viewbox) ⇒ nil
In simple terms, queries the width, height, and viewBox attributes in an SVG document.
If you are calling this function to compute a scaling factor to render the SVG, consider simply using [methodRsvg.Handle.render_document] instead; it will do the scaling computations automatically.
Before librsvg 2.54.0, the out_has_width and out_has_height arguments would be set to true or false
depending on whether the SVG document actually had width and height attributes, respectively.
However, since librsvg 2.54.0, width and height are now geometry
properties per the SVG2 specification; they
are not plain attributes. SVG2 made it so that the initial value of those properties
is auto, which is equivalent to specifing a value of 100%. In this sense, even SVG
documents which lack width or height attributes semantically have to make them
default to 100%. This is why since librsvg 2.54.0, out_has_width and
out_has_heigth are always returned as TRUE, since with SVG2 all documents have a
default width and height of 100%.
As an example, the following SVG element has a width of 100 pixels and a height of 400 pixels, but no viewBox. This
function will return those sizes in out_width and out_height, and set out_has_viewbox to FALSE.
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="400">
Conversely, the following element has a viewBox, but no width or height. This function will
set out_has_viewbox to TRUE, and it will also set out_has_width and out_has_height to TRUE but
return both length values as 100%.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 400">
Note that the RsvgLength return values have RsvgUnits in them; you should
not assume that they are always in pixels. For example, the following SVG element
will return width and height values whose units fields are RSVG_UNIT_MM.
<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm">
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#get_intrinsic_size_in_pixels(out_width, out_height) ⇒ Boolean
Converts an SVG document's intrinsic dimensions to pixels, and returns the result.
This function is able to extract the size in pixels from an SVG document if the
document has both width and height attributes
with physical units (px, in, cm, mm, pt, pc) or font-based units (em, ex). For
physical units, the dimensions are normalized to pixels using the dots-per-inch (DPI)
value set previously with [methodRsvg.Handle.set_dpi]. For font-based units, this function
uses the computed value of the font-size property for the toplevel
<svg> element. In those cases, this function returns TRUE.
This function is not able to extract the size in pixels directly from the intrinsic
dimensions of the SVG document if the width or
height are in percentage units (or if they do not exist, in which
case the SVG spec mandates that they default to 100%), as these require a
viewport to be resolved to a final size. In this case, the
function returns FALSE.
For example, the following document fragment has intrinsic dimensions that will resolve to 20x30 pixels.
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="30"/>
Similarly, if the DPI is set to 96, this document will resolve to 192×288 pixels (i.e. 96×2 × 96×3).
<svg xmlns="http://www.w3.org/2000/svg" width="2in" height="3in"/>
The dimensions of the following documents cannot be resolved to pixels directly, and
this function would return FALSE for them:
<!-- Needs a viewport against which to compute the percentages. -->
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"/>
<!-- Does not have intrinsic width/height, just a 1:2 aspect ratio which
needs to be fitted within a viewport. -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 200"/>
Instead of querying an SVG document's size, applications are encouraged to render SVG
documents to a size chosen by the application, by passing a suitably-sized viewport to
[methodRsvg.Handle.render_document].
out_width and out_height will be set accordingly. Note that the dimensions are
floating-point numbers, so your application can know the exact size of an SVG document.
To get integer dimensions, you should use ceil() to round up to the nearest integer
(just using round(), may may chop off pixels with fractional coverage). If the
dimensions cannot be converted to pixels, returns FALSE and puts 0.0 in both
out_width and out_height.
#get_pixbuf_sub(id) ⇒ GdkPixbuf::Pixbuf
Creates a GdkPixbuf the same size as the entire SVG loaded into handle, but
only renders the sub-element that has the specified id (and all its
sub-sub-elements recursively). If id is NULL, this function renders the
whole SVG.
This function depends on the [classRsvg.Handle]'s dots-per-inch value (DPI) to compute the "natural size" of the document in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
If you need to render an image which is only big enough to fit a particular sub-element of the SVG, consider using [methodRsvg.Handle.render_element].
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
API ordering: This function must be called on a fully-loaded handle. See
the section "API ordering" for details.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to use the whole SVG.
during rendering.
#get_position_sub(position_data, id) ⇒ Boolean
Get the position of a subelement of the SVG file. Do not call from within the size_func callback, because an infinite loop will occur.
This function depends on the [classRsvg.Handle]'s DPI to compute dimensions in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass nil to use the whole SVG.
#has_sub(id) ⇒ Boolean
Checks whether the element id exists in the SVG document.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
character), for example, #layer1. This notation corresponds to a URL's
fragment ID.
#height ⇒ Integer
Height, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#height=(height) ⇒ Integer
Height, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#initialize_raw ⇒ Rsvg::Handle
Creates a new [classRsvg.Handle] with flags flags. After calling this function, you can feed the resulting handle with SVG data by using [methodRsvg.Handle.read_stream_sync].
|
|
# File 'lib/rsvg2/handle.rb', line 31
|
#internal_set_testing(testing) ⇒ nil
Do not call this function. This is intended for librsvg's internal test suite only.
#metadata ⇒ String
SVG's metadata
#metadata=(metadata) ⇒ String
SVG's metadata
#pixbuf ⇒ GdkPixbuf::Pixbuf
Returns the pixbuf loaded by handle. The pixbuf returned will be reffed, so the caller of this function must assume that ref.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
This function depends on the [classRsvg.Handle]'s dots-per-inch value (DPI) to compute the "natural size" of the document in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand. during rendering.
#read_stream_sync(stream, cancellable) ⇒ Boolean
Reads stream and writes the data from it to handle.
Before calling this function, you may need to call [methodRsvg.Handle.set_base_uri]
or [methodRsvg.Handle.set_base_gfile] to set the "base file" for resolving
references to external resources. SVG elements like
<image> which reference external resources will be
resolved relative to the location you specify with those functions.
If cancellable is not NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the
operation was cancelled, the error G_IO_ERROR_CANCELLED will be
returned.
#render_cairo(cr) ⇒ Boolean
Draws a loaded SVG handle to a Cairo context. Please try to use [methodRsvg.Handle.render_document] instead, which allows you to pick the size at which the document will be rendered.
Historically this function has picked a size by itself, based on the following rules:
-
If the SVG document has both
widthandheightattributes with physical units (px, in, cm, mm, pt, pc) or font-based units (em, ex), the function computes the size directly based on the dots-per-inch (DPI) you have configured with [methodRsvg.Handle.set_dpi]. This is the same approach as [methodRsvg.Handle.get_intrinsic_size_in_pixels]. -
Otherwise, if there is a
viewBoxattribute and bothwidthandheightare set to100%(or if they don't exist at all and thus default to 100%), the function uses the width and height of theviewBoxas a pixel size. This produces a rendered document with the correct aspect ratio. -
Otherwise, this function computes the extents of every graphical object in the SVG document to find the total extents. This is moderately expensive, but no more expensive than rendering the whole document, for example.
-
This function cannot deal with percentage-based units for
widthandheightbecause there is no viewport against which they could be resolved; that is why it will compute the extents of objects in that case. This is why we recommend that you use [methodRsvg.Handle.render_document] instead, which takes in a viewport and follows the sizing policy from the web platform.
Drawing will occur with respect to the cr's current transformation: for example, if the cr has a rotated current transformation matrix, the whole SVG will be rotated in the rendered version.
This function depends on the [classRsvg.Handle]'s DPI to compute dimensions in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
Note that cr must be a Cairo context that is not in an error state, that is,
cairo_status() must return CAIRO_STATUS_SUCCESS for it. Cairo can set a
context to be in an error state in various situations, for example, if it was
passed an invalid matrix or if it was created for an invalid surface.
if a rendering error occurs.
#render_cairo_sub(cr, id) ⇒ Boolean
Renders a single SVG element in the same place as for a whole SVG document (a "subset" of the document). Please try to use [methodRsvg.Handle.render_layer] instead, which allows you to pick the size at which the document with the layer will be rendered.
This is equivalent to [methodRsvg.Handle.render_cairo], but it renders only a single element and its children, as if they composed an individual layer in the SVG.
Historically this function has picked a size for the whole document by itself, based on the following rules:
-
If the SVG document has both
widthandheightattributes with physical units (px, in, cm, mm, pt, pc) or font-based units (em, ex), the function computes the size directly based on the dots-per-inch (DPI) you have configured with [methodRsvg.Handle.set_dpi]. This is the same approach as [methodRsvg.Handle.get_intrinsic_size_in_pixels]. -
Otherwise, if there is a
viewBoxattribute and bothwidthandheightare set to100%(or if they don't exist at all and thus default to 100%), the function uses the width and height of theviewBoxas a pixel size. This produces a rendered document with the correct aspect ratio. -
Otherwise, this function computes the extents of every graphical object in the SVG document to find the total extents. This is moderately expensive, but no more expensive than rendering the whole document, for example.
-
This function cannot deal with percentage-based units for
widthandheightbecause there is no viewport against which they could be resolved; that is why it will compute the extents of objects in that case. This is why we recommend that you use [methodRsvg.Handle.render_layer] instead, which takes in a viewport and follows the sizing policy from the web platform.
Drawing will occur with respect to the cr's current transformation: for example, if the cr has a rotated current transformation matrix, the whole SVG will be rotated in the rendered version.
This function depends on the [classRsvg.Handle]'s DPI to compute dimensions in pixels, so you should call [methodRsvg.Handle.set_dpi] beforehand.
Note that cr must be a Cairo context that is not in an error state, that is,
cairo_status() must return CAIRO_STATUS_SUCCESS for it. Cairo can set a
context to be in an error state in various situations, for example, if it was
passed an invalid matrix or if it was created for an invalid surface.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to render the whole SVG.
if a rendering error occurs.
#render_document(cr, viewport) ⇒ Boolean
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 document is scaled proportionally to fit into this viewport.
The cr must be in a CAIRO_STATUS_SUCCESS state, or this function will not
render anything, and instead will return an error.
in the error argument.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#render_element(cr, id, element_viewport) ⇒ Boolean
Renders a single SVG element to a given viewport.
This function can be used to extract individual element subtrees and render them, scaled to a given element_viewport. This is useful for applications which have reusable objects in an SVG and want to render them individually; for example, an SVG full of icons that are meant to be be rendered independently of each other.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
You can pass NULL for the id if you want to render all
the elements in the SVG, i.e. to render everything from the
root element.
The element_viewport gives the position and size at which the named element will
be rendered. FIXME: mention proportional scaling.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to render the whole SVG document tree.
in the error argument.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#render_layer(cr, id, viewport) ⇒ Boolean
Renders a single SVG element in the same place as for a whole SVG document.
The viewport gives the position and size at which the whole SVG document would be rendered. The document is scaled proportionally to fit into this viewport; hence the individual layer may be smaller than this.
This is equivalent to [methodRsvg.Handle.render_document], but it renders only a single element and its children, as if they composed an individual layer in the SVG. The element is rendered with the same transformation matrix as it has within the whole SVG document. Applications can use this to re-render a single element and repaint it on top of a previously-rendered document, for example.
Element IDs should look like an URL fragment identifier; for example, pass
#foo (hash foo) to get the geometry of the element that
has an id="foo" attribute.
You can pass NULL for the id if you want to render all
the elements in the SVG, i.e. to render everything from the
root element.
hash character), for example, #layer1. This notation corresponds to a
URL's fragment ID. Alternatively, pass NULL to render the whole SVG document tree.
in the error argument.
API ordering: This function must be called on a fully-loaded handle. See the section "API ordering" for details.
Panics: this function will panic if the handle is not fully-loaded.
#set_dpi_x_y(dpi_x, dpi_y) ⇒ nil
Sets the DPI at which the handle will be rendered. Common values are 75, 90, and 300 DPI.
Passing a number <= 0 to dpi will reset the DPI to whatever the default value happens to be, but since [idrsvg_set_default_dpi_x_y] is deprecated, please do not pass values <= 0 to this function.
#set_size_callback(size_func, user_data, user_data_destroy) ⇒ nil
Sets the sizing function for the handle, which can be used to override the size that librsvg computes for SVG images. The size_func is called from the following functions:
- [methodRsvg.Handle.get_dimensions]
- [methodRsvg.Handle.get_dimensions_sub]
- [methodRsvg.Handle.get_position_sub]
- [methodRsvg.Handle.render_cairo]
- [methodRsvg.Handle.render_cairo_sub]
Librsvg computes the size of the SVG being rendered, and passes it to the size_func, which may then modify these values to set the final size of the generated image.
#set_stylesheet(css, css_len) ⇒ Boolean
Sets a CSS stylesheet to use for an SVG document.
The css_len argument is mandatory; this function will not compute the length of the css string. This is because a provided stylesheet, which the calling program could read from a file, can have nul characters in it.
During the CSS cascade, the specified stylesheet will be used with a "User" origin.
Note that <b>import</b> rules will not be resolved, except for data: URLs.
in the error argument.
#title ⇒ String
SVG's title.
#title=(title) ⇒ String
SVG's title.
#width ⇒ Integer
Width, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#width=(width) ⇒ Integer
Width, in pixels, of the rendered SVG after calling the size callback as specified by [methodRsvg.Handle.set_size_callback].
#write(buf, count) ⇒ Boolean
Loads the next count bytes of the image. You can call this function multiple times until the whole document is consumed; then you must call [methodRsvg.Handle.close] to actually parse the document.
Before calling this function for the first time, you may need to call
[methodRsvg.Handle.set_base_uri] or [methodRsvg.Handle.set_base_gfile] to set the "base
file" for resolving references to external resources. SVG elements like
<image> which reference external resources will be
resolved relative to the location you specify with those functions.