class Cairo::SvgSurface

Overview

The SVG surface is used to render cairo graphics to SVG files and is a multi-page vector surface backend.

Defined in:

cairo/svg_surface.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Cairo::Surface

content : Content content, copy_page copy_page, create_for_rectangle(x : Float64, y : Float64, width : Float64, height : Float64) : Surface create_for_rectangle, create_observer(mode : SurfaceObserverMode) : Surface create_observer, create_similar(content : Content, width : Int32, height : Int32) : Surface create_similar, create_similar_image(format : Format, width : Int32, height : Int32) : Surface create_similar_image, data : Pointer(UInt8) data, device : Device device, device_offset : Point device_offset, device_offset=(offset : Point) device_offset=, device_scale : Point device_scale, device_scale=(scale : Point) device_scale=, extents : NamedTuple(extents: Rectangle, bounded: Bool) extents, fallback_resolution : Point fallback_resolution, fallback_resolution=(res : Point) fallback_resolution=, finalize finalize, finish finish, flush flush, font_options : FontOptions font_options, format : Format format, has_show_text_glyphs? : Bool has_show_text_glyphs?, height : Int32 height, ink_extents : Rectangle ink_extents, map_to_image(extents : RectangleInt?) : Surface map_to_image, mark_dirty mark_dirty, mark_dirty_rectangle(x : Int32, y : Int32, width : Int32, height : Int32) mark_dirty_rectangle, mime_data(mime_type : String) : Bytes mime_data, observer_add_fill_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_fill_callback, observer_add_finish_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_finish_callback, observer_add_flush_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_flush_callback, observer_add_glyphs_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_glyphs_callback, observer_add_mask_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_mask_callback, observer_add_paint_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_paint_callback, observer_add_stroke_callback(func : LibCairo::SurfaceObserverCallbackT, data : Pointer(Void)) : Status observer_add_stroke_callback, observer_elapsed : Float64 observer_elapsed, observer_print(write_func : LibCairo::WriteFuncT, closure : Pointer(Void)) : Status observer_print, reference : Surface reference, reference_count : UInt32 reference_count, set_device_offset(x_offset : Float64, y_offset : Float64) set_device_offset, set_device_scale(x_scale : Float64, y_scale : Float64) set_device_scale, set_fallback_resolution(x_pixels_per_inch : Float64, y_pixels_per_inch : Float64) set_fallback_resolution, set_mime_data(mime_type : String, data : Bytes, destroy : LibCairo::DestroyFuncT, closure : Pointer(Void)) : Status set_mime_data, set_user_data(key : UserDataKey, user_data : Pointer(Void), destroy : LibCairo::DestroyFuncT) : Status set_user_data, status : Status status, stride : Int32 stride, supports_mime_type?(mime_type : String) : Bool supports_mime_type?, surface_show_page surface_show_page, to_unsafe : LibCairo::PSurfaceT to_unsafe, type : SurfaceType type, unmap_image(image : Surface) unmap_image, user_data(key : UserDataKey) : Pointer(Void) user_data, width : Int32 width, write_to_png(filename : String) : Status write_to_png, write_to_png_stream(write_func : LibCairo::WriteFuncT, closure : Pointer(Void)) : Status write_to_png_stream

Constructor methods inherited from class Cairo::Surface

new(data : Bytes, format : Format, width : Int32, height : Int32, stride : Int32)
new(format : Format, width : Int32, height : Int32)
new(read_func : LibCairo::ReadFuncT, closure : Pointer(Void))
new(content : Content, extents : Rectangle?)
new(surface : LibCairo::PSurfaceT)
new(filename : String)
new

Constructor Detail

def self.new(write_func : LibCairo::WriteFuncT, closure : Pointer(Void), width_in_points : Float64, height_in_points : Float64) #

Creates a SVG surface of the specified size in points to be written incrementally to the stream represented by write_func and closure .

###Parameters

  • write_func a Cairo::C::LibCairo::WriteFuncT to accept the output data, may be nil to indicate a no-op write_func. With a no-op write_func, the surface may be queried or used as a source without generating any temporary files.
  • closure the closure argument for write_func
  • width_in_points width of the surface, in points (1 point == 1/72.0 inch)
  • height_in_points height of the surface, in points (1 point == 1/72.0 inch)

###Returns A pointer to the newly created surface. The caller owns the surface and should call Surface#finalize when done with it.

This function always returns a valid pointer, but it will return a pointer to a nil surface if an error such as out of memory occurs. You can use Surface#status` to check for this.


[View source]
def self.new(filename : String, width_in_points : Float64, height_in_points : Float64) #

Creates a SVG surface of the specified size in points to be written to filename.

The SVG surface backend recognizes the following MIME types for the data attached to a surface (see Surface#set_mime_data) when it is used as a source pattern for drawing on this surface:

The unofficial MIME type Cairo::C::LibCairo::MIME_TYPE_URI is examined first. If present, the URI is emitted as is: assuring the correctness of URI is left to the client code.

If Cairo::C::LibCairo::MIME_TYPE_URI is not present, but Cairo::C::LibCairo::MIME_TYPE_JPEG or Cairo::C::LibCairo::MIME_TYPE_PNG is specified, the corresponding data is Base64-encoded and emitted.

If Cairo::C::LibCairo::MIME_TYPE_UNIQUE_ID is present, all surfaces with the same unique identifier will only be embedded once.

###Parameters

  • filename a filename for the SVG output (must be writable), nil may be used to specify no output. This will generate a SVG surface that may be queried and used as a source, without generating a temporary file.
  • width_in_points width of the surface, in points (1 point == 1/72.0 inch)
  • height_in_points height of the surface, in points (1 point == 1/72.0 inch)

###Returns A pointer to the newly created surface. The caller owns the surface and should call Surface#finalize when done with it.

This function always returns a valid pointer, but it will return a pointer to a nil surface if an error such as out of memory occurs. You can use Surface#status to check for this.


[View source]

Class Method Detail

def self.versions : Array(SvgVersion) #

Used to retrieve the list of supported versions. See SvgSurface#restrict_to_version.

###Returns The supported version list.


[View source]

Instance Method Detail

def document_unit : SvgUnit #

Get the unit of the SVG surface.

If the surface passed as an argument is not a SVG surface, the function sets the error status to Status::SurfaceTypeMismatch and returns SvgUnit::User.

###Returns The SVG unit of the SVG surface.


[View source]
def ducument_unit=(unit : SvgUnit) #

Use the specified unit for the width and height of the generated SVG file. See SvgUnit for a list of available unit values that can be used here.

This function can be called at any time before generating the SVG file.

However to minimize the risk of ambiguities it's recommended to call it before any drawing operations have been performed on the given surface, to make it clearer what the unit used in the drawing operations is.

The simplest way to do this is to call this function immediately after creating the SVG surface.

NOTE if this function is never called, the default unit for SVG documents generated by cairo will be "pt". This is for historical reasons.

###Parameters

  • unit SVG unit

[View source]
def restrict_to_version(version : SvgVersion) #

Restricts the generated SVG file to version. See SvgSurface#versions for a list of available version values that can be used here.

This function should only be called before any drawing operations have been performed on the given surface. The simplest way to do this is to call this function immediately after creating the surface.

###Parameters

  • version SVG version

[View source]