Jump to content
Changes to the Jaspersoft community edition download ×

Text Width Incorrectly calculated

Recommended Posts

By: Roger Choi - roger644

Text Width Incorrectly calculated

2003-12-03 00:54



I am using jasperreports 0.5.0 and I use embedded pdf fonts:


<reportFont name="Address" isDefault="false" fontName="Arial" size="9" isItalic="true" pdfFontName="resources/fonts/mingliu.ttf" pdfEncoding="Identity-H" isPdfEmbedded="true"/>


I have this line in the pageHeader:

<textField isBlankWhenNull="true" isStretchWithOverflow="false">

<reportElement x="450" y="120" width="81" height="15" mode="Opaque" positionType="Float" isRemoveLineWhenBlank="false" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF">

<printWhenExpression><![CDATA[new Boolean($F{trxId}!=null)]]></printWhenExpression>


<textElement textAlignment="Right" verticalAlignment="Middle" lineSpacing="Single">

<font reportFont="Address" />


<textFieldExpression class="java.lang.String"><![CDATA[$F{trxId}]]></textFieldExpression>



where the $F{trxId} should be "123457890123456" which is around 1 inch when printed on a PDF.


The problem is that the last character of this string is chopped when filling the report. I have traced the problem down to the JRFillTextElement.java chopTextElement() method around line 417:


atext = new AttributedString(paragr_text, fontAttributes);

paragraph = atext.getIterator();

paragraphStart = paragraph.getBeginIndex();

paragraphEnd = paragraph.getEndIndex();

lineMeasurer = new LineBreakMeasurer(paragraph,fontRenderContext);



I think this is where the original text get evaluated and get chopped off. If I increased the width of the element to 96 instead of 81, the complete text will be shown.


Do anyone have a work around for this problem? My report is quite crowded with text so I am trying to squeeze an extra 15 pixel for other fields.




PS. The font I used is Chinese True Type Font from windows. It may be the source of the error.





By: Teodor Danciu - teodord

RE: Text Width Incorrectly calculated

2003-12-03 03:21




The "fontName" and "pdfFontName" attributes have

to point to the same physical font.

The properties of the "fontName" are use by the

engine to layout content. But if in PDF format you use

a different font to actually print the text, then it

should be obvious that the results won't be the same

as the two fonts ahve different properties, like the

caracter width for example.


You use "Arial" as a fontName, but in PDF you use

"mingliu.ttf". Install this "mingliu.ttf" font on your

platform so that it is available from Java and use it

also for the fontName attribute.


I hope this helps.







By: Roger Choi - roger644

RE: Text Width Incorrectly calculated

2003-12-03 23:23



It works. Thanks.



Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...