Text Width Incorrectly calculated

By: Roger Choi - roger644
Text Width Incorrectly calculated
2003-12-03 00:54
Hi,

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>
</reportElement>
<textElement textAlignment="Right" verticalAlignment="Middle" lineSpacing="Single">
<font reportFont="Address" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{trxId}]]></textFieldExpression>
</textField>

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);
lineMeasurer.setPosition(paragraphStart);

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.

Thanks.

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

Hi,

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





By: Roger Choi - roger644
RE: Text Width Incorrectly calculated
2003-12-03 23:23
Teodord,

It works. Thanks.

Roger
2002 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:28am
Last seen: 16 years 7 months ago

0 Answers:

No answers yet
Feedback