Skip to Content
SAP Crystal Reports

How to use different font faces in a diacritical cases in SAP Crystal Reports

Tags:

As a support engineer I am facing many times with the following recurring question: What font face can be used in a Crystal Report which is fitting or can be used with different languages or charsets like European, Chinese or Arabic. In this  document i would like to share basic fundamental information about how to develop such reports or how to modify change fonts in runtime with formulas.

Diacritical marks and languages

To prepare and test a sample text in multi-language environment with many-many diacritical marks, a useful tool is Lorem ipsum generator. Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content.  It's also called placeholder (or filler) text. It's a convenient tool for mock-ups. It helps to outline the visual elements of a document or presentation, eg typography, font, or layout. Lorem ipsum is mostly a part of a Latin text by the classical author and philosopher Cicero. Its words and letters have been changed by addition or removal, so to deliberately render its content nonsensical; it's not genuine, correct, or comprehensible Latin anymore. While lorem ipsum's still resembles classical Latin, it actually has no meaning whatsoever. As Cicero's text doesn't contain the letters K, W, or Z, alien to latin, these, and others are often inserted randomly to mimic the typographic appearence of European languages, as are digraphs not to be found in the original. A sample text generator can be reached at the following link: professional lorem ipsum generator for typographers

Different font faces for different languages

Crystal reports by default using Arial Font face. Using Arial or Tahoma font face is a good choice for most of Latin charset based languages, and it is includes a limited charsets for Cirillic, Greek, Hebrew and Arabic languages. When you step out with your reports from the local environment you may facing the problems of diacritical marks. These special chars or different subset of characters are described covered in by the unicode fonts. If you moving to Asia, to display Chinese and Japanese text  the best fit font type is the "@MS Mincho""@MS Gothic". These fonts are licensed from Microsoft and supplied with the windows operating system itself. (see more at MS Mincho - Version 2.30 or MS Gothic - Version 5.02)

A Unicode font (also known as UCS font and Unicode typeface) is a computer font that contains a wide range of characters, letters, digits, glyphs, symbols, ideograms, logograms, etc., which are collectively mapped into the standard Universal Character Set, derived from many different languages and scripts from around the world.

BTW, the Unicode standard does not specify or create the font (typeface), a collection of graphical shapes called glyphs, itself. Rather, it defines the abstract characters as a specific number (known as a codepoint) and also defines the required changes of shape depending on the context the glyph is used in (e.g., combining characters, precomposed characters and letter-diacritic combinations).

The choice of font, which governs how the abstract UCS characters are converted into a bitmap or vector output that can be viewed on a screen or printed, is left up to the user. If a font is chosen which does not contain a glyph for a codepoint used in the document, typically a question mark, a box, or some other substitute character is displayed.

Best tip for troubleshooting: "Arial Unicode MS" is a jolly joker font type: almost fit with all languages, but it is consumed with Microsoft Office so this is not a free font face. Licensing information can be reached at Arial Unicode - Fonts.com.

For licensing informations, comparing tables,  technical and deep detailed descriptions please visit Wikipedia site at Unicode font - Wikipedia, the free encyclopedia


Crystal Designer - Absolute and Conditional Formatting of Objects

The Crystal Reports Designer (CR20xx) unsurprisingly is always using the avaiable fonts from the windows operating system when you designing a report.  In the designer, you can set formatting properties using the Format Editor for objects and the Section Expert for report sections. In most cases, you can set one of two types of properties:

  • Absolute (always apply the property).
  • Conditional (apply the property only if certain criteria are met) via Formula workshop


Absolute formatting is formatting that applies under any condition. This type of formatting property always follows a "select, then apply" procedure. For example, you select what it is that you want to format (object or section), then you apply the formatting to the selection using property settings.
You can use the following dialog boxes to format your reports:

  • Format Editor to format field values.
  • Section Expert to format entire sections.
  • Highlighting Expert to conditionally format all types of fields.

The following Figure 1 show an absolute formatting of a report field.

Figure 1. Format editor - font settins

Each of these dialog boxes contains a number of different formatting properties, as well as the tools for turning the properties on or off and specifying attributes.

Conditional formatting is formatting that applies only under certain conditions, in our case with conditional formatting we can change the font face based on a parameter or a variable.  For conditional formatting, you follow the same general procedure, but you go a step further and set up conditions that determine whether or not the formatting will be applied. You specify these conditions using simple formulas. For more information on creating formulas using Crystal or Basic syntax, see the online help.

When a conditional formatting formula is set up, the formula overrides any fixed settings you have made in the Format Editor. The new font face will apply only if the condition in the formula is met.

Figure 2. Format editor - conditional formatting of font face

In the formula editor by the following code the font face can will be changed.  We can use If-Then-Else formula for this kind of conditional formatting.

The syntax is the following, in case of display chinese and japanese text in the formula editor

if CONDITION then

  // true new font face will be applied

  "@MS Gothic"

else

  //false we use default font face

"Verdana"


This code means: If the evaulation of the CONDITION is true, the font face will change to "@MS Gothic", otherwise the font face will be "Verdana". By this formula all other settings are overwritten, the absolute formatting is not applied.  The CONDITION can be driven by a parameter which can be a display language.


In the sample report attached to this how-to document  you can found samples about formulas.


To re-use or re-develop an existing reports to change the font face in runtime the best tip is to use a parameter for the language. Based on this paramater you can use Formulas to change the font faces, or the reading direction from left-to-right or right-to-left.


Changing font .NET applications

Pragmatically the font change is possible in a .NET code. In the CrystalDecisions.CrystalReports.Engine namespace  the FieldObject.ApplyFont Method can be used to change the fonts during displaying the report from a custom code.

Declaration in VB:

Public Overrideable Sub ApplyFont( _

        ByVal  value As System.Drawing.Font _

)


The following sample code is changes the fonts to "@Arial uncode MS" size 12 and bold all the text Objects in Section2 in a report.

Imports System.Drawing.Font

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Dim crReport As New CrystalReport1()

Dim crReportObject as ReportObject

Dim crTextObject as TextObject

Dim ArialFont as New Font("@Arial Unicode MS", 12, FontStyle.Bold)

For Each crReportObject in Report.Section2.ReportObjects

  If crReportObject.Kind = ReportObjectKind.TextObject Then

crTextObject = CType(crReportObject, TextObject)

  crTextObject.ApplyFont(ArialFont)

End If

Next

CrystalReportViewer1.ReportSource = crReport

More information can be found at the following link: https://msdn.microsoft.com/en-US/library/ms225739(v=vs.80).aspx

Troubleshooting tips


If a font is chosen which does not contain a glyph for a codepoint used in the document, typically a question mark, a box, or some other substitute character is displayed (see Fiugre 3.) In this case you must ensure, that the font face is used in the Crystal Reports document are properly installed on the platform or application where the report is displayed or generated.

Figure 3. block displayed instead of text

Tips:

- if you are using BI platform, the issue is appears in the infoview/launchpad, you can compare the installed fonts in the server with the fonts used in the report.

- if you using your own developed application, you can compare the installed fonts in the client machine were the reports executed with the fonts used in the report.

Also a good start for troubleshooting to export the issued crystal report file into PDF format. Crystal reports designer and viewer always embedd the fonts - used in the crystal report -  into the PDF document.

- From the PDF export you compare the embedded fonts with fonts used in the crystal reports file.

Figure 4. PDF export of Crystal reports file - fonts properties

For troubleshooting, you may check the following KBA-s

1754427 - Crystal Report's Japanese chart appear square in InfoView
1311036 - Japanese Characters not being displayed in scheduling the Crystal Report to Adobe Acrobat format
1546702 - The text string fields are partially truncated when exporting Crystal Reports reports to PDF
1220499 - How to install a custom True Type Font on UNIX and Linux in Enterprise
1456641 - Error: “Failed to export” when exporting Crystal Report with Unicode characters and Chinese fonts to PDF
1532489 - Crystal Reports with Chinese Characters are displayed as boxes when exported to pdf
1804874 - Unable to see chinese characters of a Crystal Report in a text format
1213378 - Chinese characters not displayed correctly when viewer over the

Sample document - testing fonts

You can download the attachment "Steps to execute Crystal Font and text tester report.docx" word document which embedd a crystal reports document and xml file for several languages and texts generated by Lorem ipsum generator. Please follow the steps in the document to execute the report in Crystal Designer. The report developed with Crystal Reports Designer version  14.0.2.364.

The download link is: https://mdocs.sap.com/mcm/public/v1/open?shr=eVUUMkiwuRPewjaBtPY6bD14WwM9AdZcK6mFXROksDw

Instructions for the report

The report uses  xml file as datasource for many languages and sample simple text generated by  Lorem ipsum generator.

Parameters of the report

  1. Generic font face: Select a font face for all the fields
  2. Special text type: select a language
  3. Special Font face: select a special font face for the language  

Figure 5. test report parameters

The result of the report: Lorem ipsum text with diacritical characters in many languages. The report compares the font faces defined in parameters (1-3). The result can be used for identifying the best font face usage in your environment.

Figure 6. Report highlits with red: font face test results

No comments