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

Better support for PDF, SVG and PostScript. #165

Merged
merged 1 commit into from
Nov 15, 2018

Conversation

meh
Copy link
Contributor

@meh meh commented Nov 11, 2017

Don't merge yet, just need some eyes on the unsafe part.

@meh meh force-pushed the everything branch 4 times, most recently from 30aa165 to acf1a4b Compare November 12, 2017 14:54
@meh
Copy link
Contributor Author

meh commented Nov 12, 2017

@GuillaumeGomez this is ready as far as I'm concerned.

src/lib.rs Outdated
@@ -125,9 +122,19 @@ mod rectangle;
mod region;
mod surface;
mod matrices;
mod support;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this better have #[cfg(any(feature = "pdf", feature = "svg", feature = "ps", feature = "dox"))]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, commit incoming.

@EPashkin
Copy link
Member

Second problem that all docs need moved to https://github.com/gtk-rs/lgpl-docs repo to cairo/docs.rs.
Current comments can be stripped with rustdoc-stripper binary from https://github.com/GuillaumeGomez/rustdoc-stripper

@EPashkin
Copy link
Member

@GuillaumeGomez there problem with regenerating stripped comments: in ps.rs comment moved from impl<'a> Stream<'a>::new to impl<'a> Writer<'a>::new

@meh
Copy link
Contributor Author

meh commented Nov 12, 2017

@EPashkin any direction to move them over without suffering too much?

@EPashkin
Copy link
Member

@meh Theoretically you just need run rustdoc-stripper on cairo repo, it produces comments.md that need added to doc.rs.
But as it not restored rightly better wait @GuillaumeGomez answer.

@meh
Copy link
Contributor Author

meh commented Nov 12, 2017

@EPashkin oh I see, yeah I'll wait, he's probably still traveling 🐼

@GuillaumeGomez
Copy link
Member

Ok so, if docs issue you have, regen the docs (cargo build --features "embed-lgpl" is my memory is correct) then add the new docs then strip everything in the comment file and send us the comment file.

If it wasn't the problem, then it just mean I need to sleep and I'll check this tomorrow. 😀

@EPashkin
Copy link
Member

@GuillaumeGomez for tomorrow check:
I run last version of rustdoc-stripper for this PR,
get filled comments.md,
on call rustdoc-stripper -g it restored all comments with one exception:
in ps.rs comment moved from impl<'a> Stream<'a>::new to impl<'a> Writer<'a>::new

@GuillaumeGomez
Copy link
Member

That's weird. I suppose it's a rustdoc-stripper's issue but I don't see what it is for the moment. I'll look into it.

@EPashkin
Copy link
Member

@meh, @GuillaumeGomez Found "solution": it restored right way if Writer::new also have comments

@GuillaumeGomez
Copy link
Member

That's weird...

@meh
Copy link
Contributor Author

meh commented Nov 12, 2017

Should I also purge the documentation from the git history?

@GuillaumeGomez
Copy link
Member

It depends if it's lgpl docs or not.

@meh
Copy link
Contributor Author

meh commented Nov 12, 2017

I don't know, I wrote them 🤔

@GuillaumeGomez
Copy link
Member

Then it's not lgpl. :)

@meh
Copy link
Contributor Author

meh commented Nov 13, 2017

I think I did something wrong while generating the docs, see pull request on docs.

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PdfVersion {
_1_4,
_1_5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do I need to do exactly here? Kind of unclear from the issue.

Should I just add an Unknown variant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the -sys crate you use an integer and constants, in the non-sys crate you have a real enum with the Unknown variant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

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

pub struct File {
Copy link
Member

@sdroege sdroege Nov 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some potential of sharing code here (macro I guess?) between PDF and PS. It's basically the same except for the types and the functions called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there's a lot of code duplication between PDF, PS and SVG, I could add a macro to src/support.rs that generates those, wasn't sure if that was wanted or not.

unsafe {
let mut out = Box::from_raw(buffer);
out.extend(data);
Box::into_raw(out);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. The buffer you store in Buffer could become invalid in theory. Box::from_raw() followed by Box::into_raw() could in theory move things to a different place on the heap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that's safe, or stuff like owning_ref and rental would explode in really funny ways.

The part I'm unsure about is the story with aliasing which might be UB there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with from_raw/into_raw() is that they operate on owned values. They could do whatever they want with them, including moving to different memory locations. The assumption is that nothing is borrowing the data currently (and nothing is as far as the compiler is concerned, otherwise into_raw() would not compile), and with all your pointers that still point to the data you're on your own and need to ensure correctness.

I would recommend to work directly on the pointers here: let out = &mut *buffer;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into it.

@sdroege
Copy link
Member

sdroege commented Aug 6, 2018

What's the status/plan here?

@GuillaumeGomez
Copy link
Member

I'll see @meh this week-end. I'll try to motivate him to finish it. :)

@meh
Copy link
Contributor Author

meh commented Aug 6, 2018

It will happen, I believe.

@GuillaumeGomez
Copy link
Member

🎉 Finally! 🎉

Thanks!

@GuillaumeGomez GuillaumeGomez merged commit d00687e into gtk-rs:master Nov 15, 2018
@yannleretaille
Copy link

🎉

@ekg
Copy link

ekg commented Apr 26, 2019

The Cairo library has no such concepts in its PDF, SVG, PS,... support, it just has a single object for a surface representing each format which can be constructed in various ways. Since this is a binding library, I think it's bets to stay true to the way things are organized in the original library, otherwise it gets confusing for users.

This is absolutely true. I am going to have to look for a simpler set of bindings :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants