TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.03k stars 400 forks source link

[bug] pen.lineWidth global property ignored #249

Closed ari closed 2 years ago

ari commented 2 years ago

We are upgrading from an old JasperReports version, but in 6.2.1 a change causes all boxes to be given a default 1 pixel border. Because we have a lot of user contributed reports, we can't easily update all those reports to set the border line width so we are trying to do this globally.

We found this property:

net.sf.jasperreports.style.pen.lineWidth=0.0

We have tried to put it into jasperreports.properties file - no luck (note that other properties in that file work correctly)

I have tried to set it programmatically in java code like:

var exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(printJobs));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportOutput));

SimplePdfExporterConfiguration conf = new SimplePdfExporterConfiguration();
conf.setCompressed(true);
exporter.setConfiguration(conf);
exporter.getExporterContext().setValue(net.sf.jasperreports.engine.style.PropertyStyleProvider.STYLE_PROPERTY_PEN_LINE_WIDTH, "0.0");
exporter.getExporterContext().getJasperReportsContext().setProperty(net.sf.jasperreports.engine.style.PropertyStyleProvider.STYLE_PROPERTY_PEN_LINE_WIDTH, "0.0" );

We also tries to put it into JRXML file directly:

<property name="net.sf.jasperreports.style.pen.lineWidth" value="0.0"/>

None of these things work.

screen_shot_2021-07-01_at_8 42 50_pm
teodord commented 2 years ago

Are you upgrading to 6.2.1? Is this what you are saying?

ari commented 2 years ago

We are currently running 6.1.1 and wanting to upgrade to the latest release (very excited by the support for groovy closures!). But the problem with border width defaulting to 1px started in 6.2.1.

We can add the 0 border with to our reports here: https://github.com/ishgroup/oncourse/tree/main/server/src/main/resources/reports but users have the opportunity to add their own reports and it might be confusing for them to have to update them all.

teodord commented 2 years ago

Can you provide a simple JRXML reproducing this problem? Is this about HTML export only, or do you have unwanted border in PDF and other export formats too?

ari commented 2 years ago

@KeyrisXdSnow Did some work on this and discovered that the properties

net.sf.jasperreports.style.box.bottom.pen.lineWidth
net.sf.jasperreports.style.box.top.pen.lineWidth
net.sf.jasperreports.style.box.left.pen.lineWidth
net.sf.jasperreports.style.box.right.pen.lineWidth

do actually work and set these borders. So net.sf.jasperreports.style.pen.lineWidth might just be the wrong property to use here.

@teodord There are two issues here:

  1. 6.2.1 changed the behaviour so that pen widths no longer default to 0 if not explicitly set
  2. It is unclear in the docs what net.sf.jasperreports.style.pen.lineWidth is supposed to do. Perhaps that should be documented better.

6.2.1 was so long ago and even if this was a bug, perhaps changing it again would upset more people than it helps. So if you feel this is appropriate behaviour, please just close the task.

teodord commented 2 years ago

If default border would have suddenly change from 0 to 1 in 6.2.1, I'm sure we would have heard about it by now as it would have upset many people. You can download the JRL project distributions from various releases and check the samples under /demo/samples folder. All of them can be easily run using Ant+Ivy.

The properties with the "net.sf.jasperreports.style" prefix are not used to control the defaults for style properties. These properties are used to provide dynamic style values at element level. For example, you could have the backcolor of an element decided at runtime based on a report field or report variable value using a at element level. This way the element would have a variable backcolor as the result of an expression being evaluated and not a static backcolor decided at design time. This is explained here: http://jasperreports.sourceforge.net/sample.reference/crosstabs/index.html#dynamic_styles

The fact that some of the "net.sf.jasperreports.style.box" properties you mentioned above seem to work is a bit suspicious, unless they are set at element level, which would defeat the purpose of them controlling the defaults for all elements.

Again, although these properties can only be set at element level for dynamic styling support, and cannot be used to control global defaults, I want to point out the difference between "pen" and "box" elements.

The property you tried first is for setting the pen width for graphical elements such as lines, rectangles and ellipses, as documentations says here: http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.style.pen.lineWidth

The text elements and image elements are box elements, meaning the border can be controlled independently on the four sides: top, left, bottom, right. The property to use is this one: http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.style.box.pen.lineWidth

teodord commented 2 years ago

Feel free to reopen this if you still experience the problem and can provide more details about it so that we can reproduce it on our side.

KeyrisXdSnow commented 2 years ago

Yes, these properties only work at element level.

However, is it possible to set the default border width globally for all reports? We use a rectangle to group elements. This element is rendered with a black border by default. Example:

<rectangle>
     <reportElement style="alternateRow" stretchType="RelativeToBandHeight" x="0" y="0" width="513" height="20" uuid="8851264c-c3a4-4fee-8b24-1e64151feb82">
    <property name="com.jaspersoft.studio.unit.x" value="mm"/>
    </reportElement>
</rectangle>

We could add a element

<rectangle>
     <reportElement style="alternateRow" stretchType="RelativeToBandHeight" x="0" y="0" width="513" height="20" uuid="8851264c-c3a4-4fee-8b24-1e64151feb82">
    <property name="com.jaspersoft.studio.unit.x" value="mm"/>
    </reportElement>
    <graphicElement>
    <pen lineWidth="0.0"/>
    </graphicElement> 
</rectangle>    

or change element <rectangle> to a <frame>. This cases would solve our problem.

But since our clients can overriding templates, we would like to find solution for our problem without changing the structure of reports.

teodord commented 2 years ago

The style properties at element level that you tried to use to control the defaults (something that they are not meant for and thus did not work for you) are actually implemented using a StyleProviderFactory extension.

StyleProviderFactory is an extension point in the JasperReports Library and you could write your own extension to control styling of elements globally and from outside the reports themselves.

Your own custom StyleProviderFactory could create StyleProvider implementations that would check if an element is a rectangle and could force its border to be whatever you want it to be.

You can take a look at the StyleProvider implementation that we ship inside the library itself and use it as an example to create your own. You can also read more about how to add your JasperReports extensions in the JasperReports Ultimate Guide, the Extension Support chapter.

Still, it is not clear to me what exactly has changed in your environment that caused rectangles to have borders over night. Nothing would explain this.

KeyrisXdSnow commented 2 years ago

This might be the perfect solution for us. Thanks. We try it.

We have updated the Jasper report from version 6.1.1 to 6.17 . After the update, all elements where not configured pen lineWidth have borders.

teodord commented 2 years ago

If you have noticed a change in 6.2.1 with respect to default rectangle border, maybe you should check if setting this property to false solves it: http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.styles.inherit.from.default

P.S. This property needs to be set in the jasperreports.properties file in the root package of the classpath.

KeyrisXdSnow commented 2 years ago

Yes, this property helped to get rid of borders. Thank a lot.

teodord commented 2 years ago

This means your clients have set the border in some default style they were using with their reports. Prior to 6.2.1, the default style properties were not automatically inherited by styles or elements that did not have a parent style. The behavior changed in 6.2.1 and it can be inhibited with the property mentioned above.

ari commented 2 years ago

For reference, and anyone else who might come across this ticket, here is the really simple fix: https://github.com/ishgroup/oncourse/pull/677/files

@teodord Thank you for your excellent library and for releasing it open source.