Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

add get/set_document_unit() to svg surface #215

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cairo-sys-rs/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ pub enum SurfaceType {
#[cfg(feature = "use_glib")]
gvalue_impl!(SurfaceType, ::gobject::cairo_gobject_surface_type_get_type);

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SvgUnit {
User = 0,
Em,
Ex,
Px,
In,
Cm,
Mm,
Pt,
Pc,
Percent,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Format {
Expand Down
6 changes: 6 additions & 0 deletions cairo-sys-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use enums::{
PatternType,
Format,
SurfaceType,
SvgUnit,
Operator,
};

Expand Down Expand Up @@ -101,6 +102,7 @@ pub type cairo_antialias_t = Antialias;
pub type cairo_line_join_t = LineJoin;
pub type cairo_line_cap_t = LineCap;
pub type cairo_content_t = Content;
pub type cairo_svg_unit_t = SvgUnit;

#[cfg(any(feature = "xcb", feature = "dox"))]
#[repr(C)]
Expand Down Expand Up @@ -596,6 +598,10 @@ extern "C" {
height_in_points: c_double) -> *mut cairo_surface_t;
#[cfg(any(feature = "svg", feature = "dox"))]
pub fn cairo_svg_surface_restrict_to_version (surface: *mut cairo_surface_t, version: SvgVersion);
#[cfg(any(feature = "svg", feature = "dox"))]
pub fn cairo_svg_surface_get_document_unit(surface: *const cairo_surface_t) -> SvgUnit;
#[cfg(any(feature = "svg", feature = "dox"))]
pub fn cairo_svg_surface_set_document_unit(surface: *mut cairo_surface_t, unit: SvgUnit);
// CAIRO PS
#[cfg(any(feature = "ps", feature = "dox"))]
pub fn cairo_ps_surface_create (filename: *const c_char,
Expand Down
34 changes: 14 additions & 20 deletions src/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ use support;
#[cfg(feature = "use_glib")]
use glib::translate::*;

macro_rules! imp {
() => {
pub fn restrict(&self, version: PdfVersion) {
unsafe {
ffi::cairo_pdf_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
}
}

pub struct File {
inner: Surface
}
Expand Down Expand Up @@ -43,11 +53,7 @@ impl File {
}
}

pub fn restrict(&self, version: PdfVersion) {
unsafe {
ffi::cairo_pdf_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl AsRef<Surface> for File {
Expand Down Expand Up @@ -116,11 +122,7 @@ impl Buffer {
}
}

pub fn restrict(&self, version: PdfVersion) {
unsafe {
ffi::cairo_pdf_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl AsRef<[u8]> for Buffer {
Expand Down Expand Up @@ -171,11 +173,7 @@ impl<'a> Writer<'a> {
}
}

pub fn restrict(&self, version: PdfVersion) {
unsafe {
ffi::cairo_pdf_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl<'a> AsRef<Surface> for Writer<'a> {
Expand Down Expand Up @@ -223,11 +221,7 @@ impl<'a> Stream<'a> {
}
}

pub fn restrict(&self, version: PdfVersion) {
unsafe {
ffi::cairo_pdf_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl<'a> AsRef<Surface> for Stream<'a> {
Expand Down
57 changes: 36 additions & 21 deletions src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ use std::path::Path;
use std::io;

use ffi;
use ffi::enums::{SurfaceType, SvgVersion};
use ffi::enums::{SurfaceType, SvgVersion, SvgUnit};
use surface::{Surface, SurfaceExt};
use support;

#[cfg(feature = "use_glib")]
use glib::translate::*;

macro_rules! imp {
() => {
pub fn restrict(&self, version: SvgVersion) {
unsafe {
ffi::cairo_svg_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
pub fn set_document_unit(&mut self, unit : SvgUnit) {
unsafe {
ffi::cairo_svg_surface_set_document_unit(self.inner.to_raw_none(), unit);
}
}
pub fn get_document_unit(&self) -> SvgUnit {
unsafe {
ffi::cairo_svg_surface_get_document_unit(self.inner.to_raw_none())
}
}
}
}

pub struct File {
inner: Surface
}
Expand Down Expand Up @@ -43,11 +63,7 @@ impl File {
}
}

pub fn restrict(&self, version: SvgVersion) {
unsafe {
ffi::cairo_svg_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl AsRef<Surface> for File {
Expand Down Expand Up @@ -115,11 +131,7 @@ impl Buffer {
}
}

pub fn restrict(&self, version: SvgVersion) {
unsafe {
ffi::cairo_svg_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl AsRef<[u8]> for Buffer {
Expand Down Expand Up @@ -169,11 +181,7 @@ impl<'a> Writer<'a> {
}
}

pub fn restrict(&self, version: SvgVersion) {
unsafe {
ffi::cairo_svg_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl<'a> AsRef<Surface> for Writer<'a> {
Expand Down Expand Up @@ -219,11 +227,7 @@ impl<'a> Stream<'a> {
}
}

pub fn restrict(&self, version: SvgVersion) {
unsafe {
ffi::cairo_svg_surface_restrict_to_version(self.inner.to_raw_none(), version);
}
}
imp!();
}

impl<'a> AsRef<Surface> for Stream<'a> {
Expand Down Expand Up @@ -300,4 +304,15 @@ mod test {
draw(&surface);
surface.finish();
}

#[test]
fn unit() {
let file = ::std::fs::File::create("test1.svg").unwrap();
let mut surface = Writer::new(100., 100., file);

surface.set_document_unit(SvgUnit::Px);
let unit = surface.get_document_unit();
assert_eq!(unit, SvgUnit::Px);
surface.finish();
}
}