Giter VIP home page Giter VIP logo

Comments (14)

SimonSapin avatar SimonSapin commented on May 31, 2024

Yes, this would be nice to have. The docs say " See corresponding backend surface docs for details about which MIME types it can handle. " I didn’t find such docs for PDF, but looking through the source shows some signs of supporting JPEG and JPEG2000, so that looks good.

As you say, it’s not on pycairo yet. There are a few options:

  • Take this to the cairo mailing-list, wait for someone to feel like doing it, then wait for the next pycairo version.
  • Take this to the cairo mailing-list, do it ourselves, then wait for the next pycairo version.
  • Do it in C in a separated extension that uses the pycairo C API
  • Do it in Cython in a separated extension that uses the pycairo C API

Which do you like most?

from weasyprint.

mbarkhau avatar mbarkhau commented on May 31, 2024

I don't think 3 or 4 are very good options. I've already written to the cairo mailing-list concerning 1, I'd see what they think before digging into the pycairo implementation myself.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

Great. I subscribed to the cairo ML, we’ll see how it goes.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

Actually this shouldn’t be too hard to do in pycairo. Accept any object with the buffer protocol, INCREF it in Surface.set_mime_data (on CAIRO_STATUS_SUCCESS ) and register a destroy callback that does a DECREF.

from weasyprint.

mbarkhau avatar mbarkhau commented on May 31, 2024

It doesn't seem that anybody on the mailing list is picking up on this.

from weasyprint.

mbarkhau avatar mbarkhau commented on May 31, 2024

Looks like I spoke too soon.

The function should appear in the next version of pycairo. You could
open a bug report if you want to make sure it is not forgotten, and
submit a patch if you are really keen.

The question is then, when will the next version of pycairo come out. By the looks of it once every year, but then we're overdue atm.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

I’ll have a go at it unless you want to. Assuming we get a working patch, the question remain of when it will be in a release.
By the way, do you use Python 2 or 3? (py2cairo and pycairo are separate code bases.)

from weasyprint.

mbarkhau avatar mbarkhau commented on May 31, 2024

I won't have time for at least another month, so by all means have a go.
We're currently on python 2.

from weasyprint.

liujuncn avatar liujuncn commented on May 31, 2024

Is there a patch for it?

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

@liujuncn not yet. The plan goes like this:

  1. Patch pycairo and py2cairo to add Surface.set_mime_data(), exposing cairo’s existing function.
  2. Patch WeasyPrint to use it if available (we still want to support older version of pycairo.)

(I think it’s a bad idea to start 2 speculatively before 1 is done at least in a git version of pycairo.)

I intend to work on this at some point but it’s low-priority for me at the moment. Anyone interested is welcome to start on 1.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

Hi @liujuncn .

For 1. see the CSS for Paged Media spec. (It’s down at the moment but should be back soon.) At some point I plan on writing some documentation that is more author-friendly than a spec, but it’s not there yet :) In brief: @page { size: A5 portrait; margin: 1cm }

  1. seems related to #9

However both of your questions are unrelated to this bug. If you have further questions, please start a new issue or write to the mailing list or IRC; keep this about embedding JPEG images in PDF.

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

The patch for pycairo is ready:
SimonSapin/py2cairo@ebe487cabd40a3eac
http://lists.cairographics.org/archives/cairo/2012-December/023839.html

The change in WeasyPrint should be easy. What remains is having a pycairo release.

from weasyprint.

seiflotfy avatar seiflotfy commented on May 31, 2024

Assuming 1 gets accepted! What in WeazyPrint needs to be modified?

from weasyprint.

SimonSapin avatar SimonSapin commented on May 31, 2024

@mbarkhau, @liujuncn, @seiflotfy: using WeasyPrint’s git version with the py2cairo patch should Just Work (no change in client code.) Please test :)

Ideally, run the test suite (see docs on the website.) Otherwise test with b'/Filter /DCTDecode' in HTML(…).write_pdf()

from weasyprint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.