View source | View content page | Page history | Printable version   

Projects:Unicode Fonts in iReports/Technical Specification

Contents

Introduction

Currently in Jasper Reports 2.40 the font being used does not support Unicode characters. This document outlines how this will be replaced.

The current fonts in use in the Jasper Reports in Openbravo ERP include:


Overview

The scope of this specification does require further clarification to ensure that it meets the required outcomes. Some questions relating to this can be found in the discussion section at the bottom of the page.

In order to fulfill this specification it is important to clarify and understand the impact of terms like font, encoding, unicode, and how they work within the Jasper framework.


Scope

Global Test Fonts


Ubiquitous Language


Technical Implementation

The issue with displaying non western characters inside of Jasper reports and iReports is to do with encoding and ensuring that the font and encoding are compatible. Jasper Reports uses iText for creation of PDF documents, further information on this can be found in the link in the references section below.

While it is nice to ensure that the solution is complete and covers all possible languages this is not realistically going to be possible. The solution should be to find the simplest solution for configuring each installation.

In line with this the solution being proposed is to define the output font and encoding in a language specific format. This can be integrated into the language-country implementation within the application and as such bears a direct relationship with the translation process. This process proposes including font characteristics in the language object that would cover:

To ensure that this work is functioning there is a test jrxml file available that includes various languages that can be used to check the rendering of non western characters.


Language

The language object for a translation will include font objects. This relationship is outline in the diagram below.

FontClass.svg

A specific font object will be set as the default and this will be used for the rendering of Jasper reports with Openbravo ERP, if there is no default value set then the application will use the default font for the entire application. The attributes within the font object can then be passed through to the relevant report object being created to set the encoding and font required for rendering that language.


iReports

Inside the iReports tool there is a setting that allows the user to set the encoding and font for PDF rendering. This should be set to a unicode compliant encoding setting (settings contained here are Java naming conventions) and the font should be capable of displaying non western characters.


PDF Font Handling

Within Jasper Reports there is a specific method to define the font and encoding to be used in a PDF document produced from the application. There is also a third attribute that can be defined which embeds the font in the pdf document thereby not requiring the view to have the font enabled within their system. This seems a far more reliable option when it comes to correctly rendering the correct text.

There is a clear benefit to embedding the font in the document as it will ensure the document renders properly irrespective of whether the viewer has the font installed or not, the overhead to embedding the font is not significant enough to outweigh the benefit.


Jasper Reports Font definition


font

Defines the font to use with the text element.


CONTAINS EMPTY


ATTRIBUTES'

	Name of the font.


HTTPSecureAppServlet - renderJR method

The above settings will be implemented within the renderJR() method in the org.openbravo.base.secureapp.HttpSecureAppServlet class. This should be implemented in a separate private method that is called should the language include font attributes, if attributes are not available then the application will use the attributes defined in the jasper report.


Appendices

Appendix A. UML Diagrams

Appendix B. Test Cases

The following code is a test jrxml file that can be used to display non western characters.

<?xml version="1.0" encoding="UTF-8"  ?>
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
		 name="Test Report"
		 columnCount="1"
		 printOrder="Vertical"
		 orientation="Portrait"
		 pageWidth="595"
		 pageHeight="842"
		 columnWidth="535"
		 columnSpacing="0"
		 leftMargin="30"
		 rightMargin="30"
		 topMargin="20"
		 bottomMargin="20"
		 whenNoDataType="NoPages"
		 isTitleNewPage="false"
		 isSummaryNewPage="false">
	<property name="ireport.scriptlethandling" value="0" />
	<property name="ireport.encoding" value="UTF-8" />
	<import value="java.util.*" />
	<import value="net.sf.jasperreports.engine.*" />
	<import value="net.sf.jasperreports.engine.data.*" />
 

		<background>
			<band height="0"  isSplitAllowed="true" >
			</band>
		</background>
		<title>
			<band height="50"  isSplitAllowed="true" >
				<staticText>
					<reportElement
						x="0"
						y="10"
						width="535"
						height="32"
						key="staticText-1"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement textAlignment="Center" verticalAlignment="Middle">
						<font size="18" isBold="true" isUnderline="true"/>
					</textElement>
				<text><![CDATA[Font Test Report]]></text>
				</staticText>
			</band>
		</title>
		<pageHeader>
			<band height="50"  isSplitAllowed="true" >
			</band>
		</pageHeader>
		<columnHeader>
			<band height="30"  isSplitAllowed="true" >
			</band>
		</columnHeader>
		<detail>
			<band height="133"  isSplitAllowed="true" >
				<staticText>
					<reportElement
						x="8"
						y="7"
						width="317"
						height="113"
						key="staticText-2"/>
					<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
					<textElement>
						<font pdfFontName="Times-Roman" pdfEncoding ="Identity-H"/>
					</textElement>
				<text><![CDATA[Test Chinese characters - 甲 骨 文 章 草 新 隸 體 書
Test Arabic characters - ﺀ ﻻ للها لله ﻼ ﷲ گ ﭪﭖ
Test Hindi characters - अ आ इ ई उ ऊ ऋ ऌ ऍ ऎ ए ऐ
Test Russian characters - И з м е н и т ь з а д а ч и
Test Farsi characters - ماموریت نگهداری نرخ تبدیل ارز
Test Hungarian characters - Üzenet szöveg
Test Turkish characters - Açıklama
Test Spanish characters - Descripción
Test English characters - Description ]]></text>
				</staticText>
			</band>
		</detail>
		<columnFooter>
			<band height="4"  isSplitAllowed="true" >
			</band>
		</columnFooter>
		<pageFooter>
			<band height="50"  isSplitAllowed="true" >
			</band>
		</pageFooter>
		<lastPageFooter>
			<band height="50"  isSplitAllowed="true" >
			</band>
		</lastPageFooter>
		<summary>
			<band height="50"  isSplitAllowed="true" >
			</band>
		</summary>
</jasperReport>


References

  1. Jasper Reports quick reference - Font definition - http://jasperreports.sourceforge.net/quick.reference.html#font
  2. Jasper Reports quick reference - ReportFont definition - http://jasperreports.sourceforge.net/quick.reference.html#reportFont
  3. Unicode.org FAQ - http://www.unicode.org/faq/
  4. Jasper Forum post - http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=1003
  5. Lowagie tutorial on iText and font usage - http://itextdocs.lowagie.com/tutorial/fonts/index.php


Discussion Items

What is the scope of this project?

Is the objective to cover producing output documents from Openbravo ERP that are readable in all languages including non-western languages? Should this be out-of-the-box implementation or a configuration task? Does it only cover how to implement non western characters in the iReport tool?

Retrieved from "http://wiki.openbravo.com/wiki/Projects:Unicode_Fonts_in_iReports/Technical_Specification"

This page has been accessed 41,611 times. This page was last modified on 8 June 2012, at 05:31. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.