Jump to content
We've recently updated our Privacy Statement, available here ×

Specify line spacing by pixels


michael_s

Recommended Posts

Is there a way to specify line spacing other than Single/1_1_2/Double?   In iReport, I've tried to set the markup type to HTML and then put <style type="text/css"> abc {  .....  } </style> <div class="abc"> some text here that spills onto multiple lines <div>  but that does not seem to work.

We want to specify 2-5 pixels between lines in different sections of the report.   We'll be doing this for dozens of reports over time, so splitting the text into single line text fields spaced 2-5 pixels apart will really slow production.

Is there some other option I'm missing?   I own relatively old PDF copies of the guides to Jasper Reports and iReport.   If newer copies of either cover this scenario, please let me know and I'll just buy an upgrade.

Thank you for the help. 



Post Edited by michael_s at 09/02/2009 15:10
Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

JasperReports only supports the three line spacing values that you mentioned.

Depending on your exact requirements, it might be possible to customize JR to do this. For instance, you could have a custom JRTextMeasurer implementation that sets a bigger lineSpacing value for certain text elements.

Regards,

Lucian

Link to comment
Share on other sites

I have started to work on a solution, and would like to discuss getting it accepted into Jasper Reports. We want our reports to have the option of font height 40 dots (using Jasper/Java's 72 dpi) but with line spacing of 2 dots, or 14 line spacing 2.5, and similar.

My solution is crude, and I welcome a better proposal - but it requires no changes to Jasper architecture. A superior solution would parameterize the spacing but would require more work.

1. In src/net/sf/jasperreports/engine/JRTextElement.java under LINE_SPACING_DOUBLE byte constant, add constants for LINE_SPACING_ONE_DOT, LINE_SPACING_TWO_DOTS, LINE_SPACING_TWO_HALF_DOTS, etc...

2. In src/net/sf/jasperreports/engine/xml/JRXmlConstants.java under LINE_SPACING_DOUBLE String constant, add String constants for the same values created in JRTextElement. Change the lineSpacingMap lookup Map to include the new values as forward and reverse lookups.

3. In src/net/sf/jasperreports/engine/xml/TextMeasurer.java, in the function initialize, add something like the following code before the switch (textElement.getLineSpacing())

int fontHeight = textElement.getFontSize();
float floatFontHeight = 12f; // semi-intelligent default
if (fontHeight > 0)
{
floatFontHeight = (float)fontHeight;
}
Then in the switch, add a case for each of the new values like this
case LINE_SPACING_THREE_DOTS: lineSpacing = 1f + ( 3f / floatFontHeight ); break;
Other than that, I think all necessary changes are in /net/sf/jasperreports/engine/dtds to allow the new values. Again, it works, but it's ugly. Any thoughts?
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

This feature very much depends on the output format that you target.

Note that for XLS export, there is absolutely now way to control line spacing.

This is the case with other document formats as well.

For instance, in HTML/CSS, the line spacing is specified in percentage out of normal line height.

 

So unless you are interested in AWT and PDF outputs, implementing this might not worth it.

 

Thank you,
Teodor

 

Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

Hi,

In the newly released JR 4.0.2, we added three new possible values for the line spacing type: AtLeast, Exact and Proportional.
They work in conjunction with an additional numeric value specified by the lineSpacingSize property available for <paragraph> tag in JRXML.

The API was refactored to move line spacing properties inside the JRParagraph interface, along with additional paragraph styling properties.

Thank you,
Teodor
 

Link to comment
Share on other sites

  • 1 month later...

I have a trouble with updating to 4.0.2 -> generating PDF file the text field go down (carriage return) for no apparent reason.

The same report in 4.0.1 not show this "bug" (?) ... and if I generate the same jrxml in two design ambient (4.0.1 and 4.0.2) the report in 4.0.1 is printed in pdf correctly...in 4.0.2 not correctly (see attach).

Is caused by linespacing new properites?

I dont know... but for the moment I return to 4.0.1 because of my urgency iussue :-)

 

bye

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...