Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JasperReports Library Custom Visualization ignores dominant-baseline and alignment-baseline attributes #191

Open
dhombios opened this issue May 21, 2021 · 2 comments

Comments

@dhombios
Copy link

When using dominant-baseline and alignment-baseline attributes in a Custom Visualization to set a text element position in the svg viewport as hanging in a report generated from a custom Java application using JasperReports Library version 6.16, the resulting pdf is rendered ignoring them independently on whether PhantomJs or Chromium is used, resulting in the text being located outside of the viewport. Nevertheless, if the report is exported as html, the report is rendered correctly in the same version of chromium that I am bundling with the executable.

Additionally, this problem also happens when the same report is exported in html and opened inside Jaspersoft Studio Community, yet if the html file is opened in chrome it is also rendered correctly.

According to some answers in stackoverflow, this error can be caused due to inhereting the svg a display inline attribute from the html in which it is embedded. However, setting the svg display attribute to block does not solve it.

A workaround for solving this is to set the dy property of the text to 0.75em, but the resulting top margin might change if several texts with different font sizes are used.

This problem was initially mentioned in #189 (comment)

Thanks in advance

Generated SVG passed to Chromium or PhantomJS:

<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"><svg xmlns=\ "http://www.w3.org/2000/svg\" id=\ "element66576560284652498011372360525284671058svg\" width=\ "389\" height=\ "240\" style=\ "fill: transparent;\" version=\ "1.1\"><defs><style type=\"text/css\">\nsvg circle { fill: rgb(240, 0, 255); }\n.number-text { fill: white; font-family: arial; }</style></defs><text dominant-baseline=\"hanging\" aligment-baseline=\"hanging\" x=\"389\" y=\"0\" text-anchor=\"end\" class=\"number-text\" style=\"font-size: 60px;\">.95</text><text dominant-baseline=\"hanging\" aligment-baseline=\"hanging\" x=\"305.578125\" y=\"0\" text-anchor=\"end\" class=\"number-text\" style=\"font-size: 240px;\">8</text><text dominant-baseline=\"hanging\" aligment-baseline=\"hanging\" x=\"172.09375\" y=\"0\" text-anchor=\"end\" class=\"number-text\" style=\"font-size: 120px;\">\ufffd</text></svg>

Example of the D3js code that generates one of those text elements:

var cents_text = svg.append("text")
        .attr('dominant-baseline', "hanging") // set text baseline
        .attr('alignment-baseline', "hanging") // set viewport baseline
        .attr("text-anchor", "end") // left alignment
            .attr("x", w)           // set x position of left side of the text
            .attr("y", 0) // set y position of upper side of the text
        .attr("class", "number-text") // set css class
        .text(cents)          // define the text to display
        .style('font-size', "60px");

And its CSS style:

.number-text {
    fill: white;
    font-family: arial;
}
@dadza
Copy link
Collaborator

dadza commented May 24, 2021

Looks like a Batik limitation. The SVG implementation status page lists alignment-baseline and dominant-baseline as not implemented.

@dhombios
Copy link
Author

Thanks, I'll open a feature request in their issue tracker

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

No branches or pull requests

2 participants