Commit 10769d8a authored by Julian Sparber's avatar Julian Sparber
Browse files

Load svg file on build time

parent bacdd2fd
/target
**/*.rs.bk
input
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="361.42084mm"
height="668.86664mm"
viewBox="0 0 361.42084 668.86664"
version="1.1"
id="svg10385"
inkscape:version="0.92.2 2405546, 2018-03-11"
sodipodi:docname="drawing.svg">
<defs
id="defs10379">
<clipPath
clipPathUnits="userSpaceOnUse"
id="clipPath10924">
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#26263f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.26458332;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect10926"
width="1372.9745"
height="771.9212"
x="-384.06146"
y="1851.6222" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.24748738"
inkscape:cx="-206.53015"
inkscape:cy="1071.5585"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="1053"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata10382">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(2.3056512,107.7369)">
<g
id="slides"
inkscape:label="#g928"
transform="translate(3.0517578e-5)">
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#ffff00;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect672-5"
width="361.42081"
height="203.19997"
x="-0.16751099"
y="-105.59875" />
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#ffff00;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect672-5-4"
width="361.42081"
height="203.19997"
x="-0.16748047"
y="127.23461" />
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#ffff00;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect672-5-1"
width="361.42081"
height="203.19997"
x="-0.16748022"
y="360.06793" />
</g>
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#26263f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect3754-3-7"
width="361.42081"
height="203.19997"
x="-0.16748022"
y="127.23461" />
<rect
y="-105.59875"
x="-0.16748022"
height="203.19997"
width="361.42081"
id="rect672"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#26263f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<rect
y="360.06793"
x="-0.16748022"
height="203.19997"
width="361.42081"
id="rect3419"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;color-interpolation:sRGB;color-interpolation-filters:linearRGB;fill:#26263f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.07000434;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
<text
id="text1638"
y="-16.248285"
x="180.37938"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;line-height:1.25;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434"
y="-16.248285"
x="180.37938"
id="tspan1632"
sodipodi:role="line">Designing</tspan><tspan
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434"
y="15.501714"
x="180.37938"
sodipodi:role="line"
id="tspan1634">GNOME</tspan><tspan
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434"
y="47.251713"
x="180.37938"
sodipodi:role="line"
id="tspan1636">Mobile</tspan></text>
<text
id="text1642"
y="-62.350765"
x="180.76102"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10.58333206px;line-height:1.25;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434"
y="-62.350765"
x="180.76102"
id="tspan1640"
sodipodi:role="line">Tobias Bernard</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;line-height:1.25;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
x="177.51851"
y="195.94768"
id="text1878"><tspan
id="tspan1876"
sodipodi:role="line"
x="177.51851"
y="195.94768"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.39999962px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434">Librem 5</tspan></text>
<text
id="text1887"
y="225.05199"
x="177.51851"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:14.11110973px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:14.11110973px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434"
y="225.05199"
x="177.51851"
sodipodi:role="line"
id="tspan1883">iMX8 ARM processor</tspan><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:14.11110973px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434"
y="244.80754"
x="177.51851"
sodipodi:role="line"
id="tspan1890">5.5&quot; display</tspan><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:14.11110973px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434"
y="264.56308"
x="177.51851"
sodipodi:role="line"
id="tspan1879">720 x 1440 px</tspan><tspan
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:14.11110973px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434"
y="284.31863"
x="177.51851"
sodipodi:role="line"
id="tspan1888">runs GNOME*</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.3999958px;line-height:1.25;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
x="180.37938"
y="433.01422"
id="text1898"><tspan
id="tspan1896"
sodipodi:role="line"
x="180.37938"
y="433.01422"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:25.3999958px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434">it runs</tspan></text>
<text
id="text1907"
y="489.63507"
x="180.37938"
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:50.79999161px;line-height:1.25;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:800;font-stretch:normal;font-size:50.79999161px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Ultra-Bold';text-align:center;text-anchor:middle;fill:#ffffff;stroke-width:0.07000434"
y="489.63507"
x="180.37938"
sodipodi:role="line"
id="tspan1905">GNOME!?</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;letter-spacing:0px;word-spacing:0px;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.07000434"
x="309.81018"
y="317.65613"
id="text18134"><tspan
sodipodi:role="line"
x="309.81018"
y="317.65613"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.3499999px;line-height:1.39999998;font-family:Cantarell;-inkscape-font-specification:Cantarell;text-align:start;text-anchor:start;fill:#ffffff;stroke-width:0.07000434"
id="tspan18149">* by default</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:17.63888741px;line-height:0;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="142.7075"
y="286.58932"
id="text845"><tspan
sodipodi:role="line"
id="tspan843"
x="142.7075"
y="286.58932"
style="font-size:176.3888855px;stroke-width:0.26458332">2</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:17.63888741px;line-height:0;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="129.65472"
y="60.156391"
id="text845-8"><tspan
sodipodi:role="line"
id="tspan843-5"
x="129.65472"
y="60.156391"
style="font-size:176.38890076px;stroke-width:0.26458332">1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:17.63888741px;line-height:0;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="137.9702"
y="520.53143"
id="text845-7"><tspan
sodipodi:role="line"
id="tspan843-4"
x="137.9702"
y="520.53143"
style="font-size:176.38890076px;stroke-width:0.26458332">3</tspan></text>
</g>
</svg>
extern crate xml;
extern crate cairo;
extern crate gtk;
extern crate rsvg;
use std::env;
use gtk::prelude::*;
use gtk::DrawingArea;
use cairo::Context;
use rsvg::Handle;
use rsvg::HandleExt;
......@@ -23,13 +16,15 @@ pub struct Coord {
y: f64,
width: f64,
height: f64,
name: String,
}
fn main() {
let file = File::open("./drawing.svg").unwrap();
let group_name = "slides";
let path = "./drawing.svg";
let file = File::open(path).unwrap();
let file = BufReader::new(file);
let group_name = "slides";
let parser = EventReader::new(file);
let mut found = false;
let mut slides: Vec<Coord> = vec!();
......@@ -52,25 +47,28 @@ fn main() {
let y = xml::name::OwnedName::local("y");
let width = xml::name::OwnedName::local("width");
let height = xml::name::OwnedName::local("height");
let mut value = Coord {x : 0f64, y : 0f64, width : 0f64, height : 0f64};
let mut set = false;
let name = xml::name::OwnedName::local("id");
let mut value = Coord {name: String::from(""), x : 0f64, y : 0f64, width : 0f64, height : 0f64};
//361.421 inkscape width for slides group
//1280 rsvg width for slides group
for a in attributes {
if a.name == name {
value.name = a.value.clone();
}
if a.name == x {
value.x = a.value.parse::<f64>().unwrap();
value.x = (a.value.parse::<f64>().unwrap() * 3.5416).round();
}
if a.name == y {
value.y = a.value.parse::<f64>().unwrap();
value.y = (a.value.parse::<f64>().unwrap() * 3.5416).round();
}
if a.name == width {
value.width = a.value.parse::<f64>().unwrap();
value.width = (a.value.parse::<f64>().unwrap() * 3.5416).round();
}
if a.name == height {
value.height = a.value.parse::<f64>().unwrap();
value.height = (a.value.parse::<f64>().unwrap() * 3.5416).round();
}
}
println!("x={},y={}", value.x, value.y);
println!("width={},height={}", value.width, value.height);
slides.push(value);
slides.push(value);
}
}
Ok(XmlEvent::EndElement { name }) => {
......@@ -86,55 +84,33 @@ fn main() {
}
}
let current = slides.iter().nth(2).unwrap();
create_pdf(String::from("./drawing.svg"), current);
}
fn create_pdf(file: String, size: &Coord) -> Option<()> {
if gtk::init().is_err() {
println!("Failed to initialize GTK.");
return None;
slides.sort_by(|a, b| a.y.partial_cmp(&b.y).unwrap());
//println!("{:?}", slides);
let first = slides.iter().nth(0).unwrap();
let handle = Handle::new_with_flags(rsvg::HandleFlags::FLAG_UNLIMITED);
let data = include_bytes!("/home/julian/code/parser/export/drawing.svg");
//let handle = Handle::new_from_file(&path);
let result = handle.write(data);
handle.close();
if let Err(ref e) = result {
println!("{}", e);
}
//let handle = handle.unwrap();
let handle = Handle::new_from_file(&file);
let handle = handle.unwrap();
let svg_dimensions = handle.get_dimensions();
println!("{}", file);
let window = gtk::Window::new(gtk::WindowType::Toplevel);
let drawing_area = Box::new(DrawingArea::new)();
window.set_default_size(500, 500);
window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
window.add(&drawing_area);
window.show_all();
let size = size.clone();
drawing_area.connect_draw(move |drawing_area, cr| {
let (da_width, da_height) = (drawing_area.get_allocated_width(), drawing_area.get_allocated_height());
let (svg_width, svg_height) = (svg_dimensions.width, svg_dimensions.height);
println!("Size: {}, {}", svg_width, svg_height);
/*
let surface = cr.get_target();
let subsurface = surface.create_for_rectangle(size.x, size.y, size.width, size.height);
*/
let size = size.clone();
println!("x={},y={}", size.x, size.y);
println!("width={},height={}", size.width, size.height);
cr.translate(size.x, size.y);
cr.paint_with_alpha(0.0);
handle.render_cairo(&cr);
for (index, current) in slides.iter().enumerate() {
create_pdf(&handle, index, format!("#{}",current.name));
}
}
Inhibit(false)
});
fn create_pdf(handle: &Handle, index: usize, name: String) -> Option<()> {
let position = handle.get_position_sub(&name).unwrap();
let dim = handle.get_dimensions_sub(Some(name.as_str())).unwrap();
gtk::main();
let pdf_surface = cairo::PDFSurface::create(format!("./output{}.pdf", index + 1),
f64::from(dim.width - 5), f64::from(dim.height - 5));
let cr = cairo::Context::new(&pdf_surface);
cr.translate(- f64::from(position.x) - 2.5, - f64::from(position.y) - 2.5);
cr.paint_with_alpha(0.0);
handle.render_cairo(&cr);
return None;
}
File deleted
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