Giter VIP home page Giter VIP logo

Comments (5)

hageldave avatar hageldave commented on August 23, 2024

PDF export functionality has been implemented and merged into master (#28). However, the PDF rendering routines lack support for use of transparent colors since they do not take color alpha into account yet.
For example the helper method for creating a linear color gradient currently ignores alpha.

protected static PDShadingType2 createGradientColor(int color1, int color2, Point2D p0, Point2D p1) throws IOException {

Support for transparent colors in PDF export is pending.

from jplotter.

hageldave avatar hageldave commented on August 23, 2024

I think most renderers are now alpha capable, except for triangles due to some complication with gouraud shading (not allowing for alpha specification of vertex colors?).
I skimmed through the PDF specification and found a section on transparency (section 7). I think we could try and use a softmask as described in section 7.4 to specify transparency for triangles. From what I understood from section 7.4.2 (Deriving a Soft Mask from Group Luminosity), we can create a softmask that will use the luminosity of things drawn into it as alpha. So basically we can draw the triangles in greyscale with their alpha value as grey, and then use this softmask with the actual colored triangles.

https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf#%5B%7B%22num%22%3A582%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C88%2C565%2Cnull%5D

@lvcarx what do you think? Maybe there is also a better way

from jplotter.

lvcarx avatar lvcarx commented on August 23, 2024

Yep that solved the issue. Should be working now as expected and i will push it after some more testing. Thank you!

from jplotter.

hageldave avatar hageldave commented on August 23, 2024

Since we are currently having some problems with triangle mesh creation for PDF, I had a look again at the specification. Currently we are creating a new PDShadingType4 object including the decode array for every single triangle.

public static PDPageContentStream createPDFShadedTriangle(PDDocument doc, PDPageContentStream cs, Point2D p0,

It is however possible to provide a whole stream of triangles for the same shading object, which allows us to save memory and should also improve render performance in PDF readers. This is described in the PDF reference for type 4 shading.
Basically the stream of triangles consists of tuples f x y c1 .. cn or in our case f x y r g b, where each such tuple is a vertex.

  • f is a flag with possible values 0,1,2 . It specifies how to use the vertices in the stream.
    • 0 = start a new triangle. This vertex and the next two vertices will form the triangle. Flags on the next two triangles will be ignored.
    • 1 = form a triangle with the second edge of the previous triangle (prev. triangle with vertices {A,B,C}, new triangle with vertices {B,C,D} where D is the current vertex)
    • 2 = form a triangle with the third edge of the previous triangle (prev. triangle with vertices {A,B,C}, new triangle with vertices {C,A,D} where D is the current vertex)
    • Note: In our case we can only use f=0 because we don't have this implicit triangle mesh structure in the Triangles class.
  • x, y coordinates of the vertex. Integer valued in range 0 .. 2^n -1, where n is the number of bits per coordinate.
    • these coordinates are not used as they are, but transformed to another range of values specified in the decode array of the shading.
    • The decode array consists of min,max tuples [Xmin Xmax Ymin Ymax Rmin Rmax Gmin Gmax Bmin Bmax]
    • The x coordinate will be transformed to x_new as follows:
      x_normalized := x/(2^n -1) where n is the number of bits per coordinate (from setBitsPerCoordinate(16))
      x_new := x_normalized*(Xmax-Xmin)+Xmin
    • Decode arrays in the specification
    • Note: In the current code Xmax and Ymax are set to (2^n -1) = (2^16 -1) = 0xFFFF, and Xmin=Ymin=0,
      so that the transformation effectively results in x_new := x.
      I think we can consider to do a more sophisticated transform to allow for higher precision of x_new than integer values. (later)
  • r, g, b color of the vertex. Integer valued in range 0 .. 2^m -1, where m is the number of bits per component.
    • These values are also transformed to a new value range, like the coordinates x, y are.
    • Note: In the current code m=8 and Rmax=Gmax=Bmax=1 so that we transform to normalized color values [0,1]. That's alright.

from jplotter.

hageldave avatar hageldave commented on August 23, 2024

released as of bd7cf5c

from jplotter.

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.