FPReport: HTML < b > and < i > can select wrong PostScript font name
Original Reporter info from Mantis: Doyenne
-
Reporter name:
Original Reporter info from Mantis: Doyenne
- Reporter name:
Description:
Current behaviour:
If (on Windows) a Memo uses the Arial font (PostScript name: ArialMT) and the memo uses the <b&;gt tag, an exception is raised: font ArialMT-Bold not found in font cache.
Cause:
If HTML < b > and/or < i > tags are used in a memo, the HTMLOnFoundText() procedure in FPReport.pp chooses the appropriate PostScript font name as follows (from line 4463 in current trunk version):
lNewFontName := Font.Name;
if [htBold, htItalic] <= FTextBlockState then // test if it is a sub-set of FTextBlockState
lNewFontName := lNewFontName + '-BoldItalic'
else if htBold in FTextBlockState then
lNewFontName := lNewFontName + '-Bold'
else if htItalic in FTextBlockState then
lNewFontName := lNewFontName + '-Italic';
FCurTextBlock.FontName := lNewFontName;
So this procedure assumes that PostScript font names follow a regular pattern, where the bold version of the font has '-Bold' appended to the name, and so on. This is true in some cases, e.g. LiberationSans -> LiberationSans-Bold. However, is it not true in all cases. On Windows, a standard font like Arial does not follow this pattern:
PostScript name regular font: ArialMT
PostScript name bold version: Arial-BoldMT (NOT ArialMT-Bold)
This procedure will also fail in a case where a memo uses a bold font (e.g. LiberationSans-Bold) and uses the < i > tag. This procedure will transform the name into LiberationSans-Bold-Italic, which should be LiberationSans-BoldItalic.
However, this can easily be solved, since the fpttf unit already contains procedures that select the correct PostScript font name from a font family.
The following code solves the problem:
lNewFontName := gTTFontCache.Find(
gTTFontCache.Find(Font.Name).FamilyName,
htBold in FTextBlockState,
htItalic in FTextBlockState).PostScriptName;
FCurTextBlock.FontName := lNewFontName;
Note: this is not safe code, since the result of the inner gTTFontCache.Find() is not checked for nil values. This code is for illustrative purposes only.
It might be elegant to introduce a helper function (maybe in the fpttf unit) that 'converts' a PostScript font name to a new PostScript font name, based on bold and italic booleans. This helper function could then handle errors (by raising an exception or by not changing the font name).
Mantis conversion info:
- Mantis ID: 35049
- Fixed in version: 3.3.1
- Fixed in revision: 41592 (#5fd42f50)
- Monitored by: » Doyenne (Doyenne)
- Target version: 3.2.0