View Issue Details

IDProjectCategoryView StatusLast Update
0019435LazarusPrinterpublic2016-12-22 13:40
ReporterLuiz AmericoAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version1.2.0Fixed in Version1.1 (SVN) 
Summary0019435: Arabic text is not printed under Linux (Ubuntu)
DescriptionArabic text is not printed through TPrinter.Canvas.TextOut in Linux (tested in Ubuntu 11.04 and 9.04)

As a side effect both LazReport and FortesReport ( http://forum.lazarus.freepascal.org/index.php/topic,13206.0.html ) cannot print such text.

The arabic text is visible in the preview of both report components as well in the font selecting dialog.

There's an sample test attached. It works under windows.

To test Lazreport just copy the arabic text to an empty report
TagsNo tags attached.
Fixed in Revision40667
LazTarget1.2
Widgetset
Attached Files

Relationships

related to 0015161 resolvedJesus Reyes lazreport with gtk2 and gtk2 widgetset could not print Chinese 

Activities

2011-05-28 02:38

 

arabic_print.zip (2,196 bytes)

Motaz Abdel Azeem

2013-01-05 09:46

reporter   ~0064635

I have test printing in Linux using QT compiled Lazarus application, the Arabic text is printed without any problem. It seems that the problem exist in GTK2

Stephano

2013-01-05 11:42

developer   ~0064640

Tested on Ubuntu 11.04/GTK2 and Arabic is not printed

Anton Kavalenka

2013-01-05 16:08

reporter   ~0064651

PostScript canvas maps user-selected font name to the predefined PS font names (TimesRoman,Courier,Helvetica), which may not have complex scripts.

The same problem with Greek.

The PostScript output (TPostScriptCanvas) should be patched not to replace user-selected typeface name.

Stephano

2013-01-05 17:16

developer   ~0064654

Disabling the font mapping produces mixed results:

- Fonts like Sans and Symbol do not show the Arabic characters though the character map shows that they have Arabic script

- Fonts like Arial displayed the Arabic characters, but in detached (isolated) form

Zaher Dirkey

2013-04-02 20:33

reporter   ~0066766

This example not print Arabic words
var
  p: TPostScriptCanvas;
begin
  p:= TPostScriptCanvas.Create;
  p.BeginDoc;
  P.Font.Name := 'Arial';
  P.textOut(0,0,'English with font ');
  P.TextOut(0,80,'Arabic: ');
  P.TextOut(250,80,'اللغة العربية');
  p.SaveToFile('c:\temp\printer.ps');
  P.EndDoc;
end;

Luiz Americo

2013-04-02 23:31

developer   ~0066771

@zaher: in trunk the printer uses now the canvas based in cairo (TCairoPsCanvas)

Stephano

2013-04-02 23:35

developer   ~0066772

Last edited: 2013-04-03 11:55

View 2 revisions

TPostScriptCanvas is still buggy in this regard. I am not sure if there is interest in fixing it especially that printing now uses TCairoPsCanvas instead.

Maybe TPostScriptCanvas should be marked as deprecated, while TCairoPsCanvas.BeginDoc and TCairoPsCanvas.EndDoc are changed to public. You can then use the following code (works under Linux, not tested under Windows):

var
  p: TCairoPsCanvas;
begin
  p:= TCairoPsCanvas.Create;
  p.OutputFileName := '/tmp/printer.ps';
  p.BeginDoc;
  P.Font.Assign(MyFont);
  P.textOut(0,0,'English with font ');
  P.TextOut(0,80,'Arabic: ');
  P.TextOut(250,80,'اللغة العربية');
  P.EndDoc;
end;

Jesus Reyes

2013-04-03 20:12

developer   ~0066785

I don't think TPostscriptCanvas should be marked as deprecated, it has at least one advantage that CairoCanvas doesn't have: It's pure pascal code and doesn't need external libraries. On the other hand, yes, TPostscriptCanvas do not support anything else than Latin and Cyrillic.

The sample as modified by Stephano doesn't work, as BeginDoc is protected, in r40701 CairoPrinter unit was introduced which should allow easier access to cairo backends. The example rewritten using cairo printer:

uses ..., graphics, cairoprinter;
var
  CairoPrinter: TCairoFilePrinter;
  sz: TSize;
begin
  CairoPrinter := TCairoFilePrinter.create;
  //CairoPrinter.CairoBackend:=cbPS;
  CairoPrinter.CairoBackend:=cbPDF;
  CairoPrinter.FileName:='19435';
  CairoPrinter.BeginDoc;
  with CairoPrinter.Canvas do
  begin
    Font.Name := 'Sans';
    Font.Size := 24; // specifying font size is important!
    TextOut(0,0,'English with font ');
    // alternative 1, depend on font size, but for size=24 both texts overlaps
    TextOut(0,80,'Arabic: ');
    TextOut(250,80,'اللغة العربية');

    // alternative 2, measure prefix
    sz := TextExtent('Arabic: ');
    TextOut(0, 80+sz.cy*1, 'Arabic: ');
    TextOut(sz.cx, 80+sz.cy*1, 'اللغة العربية');

    // alternative 3, simpler
    TExtout(0, 80+sz.cy*2, 'Arabic: اللغة العربية');
  end;
  CairoPrinter.EndDoc;
  CairoPrinter.Free;
end;

Don't forget, Work is in progress!

Jesus Reyes

2013-04-03 20:16

developer   ~0066786

Damn Mantis, why do you allow to add notes but do not allow to modify them!.

anyway.

This will create a 19435.pdf file on program's directory. The pdf (or the corresponding to the selected backend) extension will be added if FileName property do not include one.

raftakis ioannis

2013-09-04 14:47

reporter   ~0069724

I had the same problem for long time with Greek characters. not prinable at all from Lazarus with GTK2 Widgetset.

Finally I was able to print Greek UTF-8 Characters via Cups and Cups-pdf from Lazarus by modifying the PostScriptCanvas.pas not to map Fonts to predefined fonts, as follows:


function TPostScriptPrinterCanvas.MappedFontName: string;
var
  Atr: string;
begin
Result:=Font.Name; //MOFIFICATION
end;

My Application was ported from windows to linux and uses Firebird with UTF-8 Encoding.

I use Linux Mint 15 Debian MATE Edition with Cups and Cups-pdf Installed.

I also make a modification to TPostScriptPrinterCanvas.TextRect to correct text positioning (because TextOut(X,Y) cordinates was wrong for some reason
and the text was misplaced on LazReport.
as follows:

procedure TPostScriptPrinterCanvas.TextRect(ARect: TRect; X, Y: integer;
  const Text: string; const Style: TTextStyle);
var
  OldClip: TRect;
begin
  {$IFDEF VerboseLCLTodos}{$WARNING TPostScriptPrinterCanvas.TextRect is not yet fully implemented!}
{$ENDIF}
  //TODO: layout, etc.

  if Style.Clipping then
  begin
    OldClip := GetClipRect;
    SetClipRect(ARect);
  end;

  //TextOut(X, Y, Text); // WRONG
  TextOut(ARect.Left, Arect.Top, Text); //CORRECT

  if Style.Clipping then
    SetClipRect(OldClip);
end;

FYI: This solution has much better results (for Me) than use CairoCancvas. witch is incomplete yet.

Motaz Abdel Azeem

2014-02-16 15:11

reporter   ~0073090

I'm using Lazarus trunk version 1.3, but cairoprinter does not exist.

raftakis: could you please upload simple Lazarus application here representing your solution, thanks

Issue History

Date Modified Username Field Change
2011-05-28 02:38 Luiz Americo New Issue
2011-05-28 02:38 Luiz Americo File Added: arabic_print.zip
2011-05-28 02:38 Luiz Americo LazTarget => -
2011-10-05 16:58 Vincent Snijders Status new => acknowledged
2013-01-05 09:46 Motaz Abdel Azeem Note Added: 0064635
2013-01-05 11:42 Stephano Note Added: 0064640
2013-01-05 16:08 Anton Kavalenka Note Added: 0064651
2013-01-05 17:16 Stephano Note Added: 0064654
2013-04-01 05:40 Jesus Reyes Assigned To => Jesus Reyes
2013-04-01 05:40 Jesus Reyes Status acknowledged => assigned
2013-04-01 06:44 Jesus Reyes Relationship added related to 0015161
2013-04-01 06:45 Jesus Reyes Fixed in Revision => 40667
2013-04-01 06:45 Jesus Reyes LazTarget - => 1.2
2013-04-01 06:45 Jesus Reyes Status assigned => resolved
2013-04-01 06:45 Jesus Reyes Fixed in Version => 1.1 (SVN)
2013-04-01 06:45 Jesus Reyes Resolution open => fixed
2013-04-01 06:45 Jesus Reyes Target Version => 1.2.0
2013-04-02 20:33 Zaher Dirkey Note Added: 0066766
2013-04-02 23:31 Luiz Americo Note Added: 0066771
2013-04-02 23:35 Stephano Note Added: 0066772
2013-04-03 11:55 Stephano Note Edited: 0066772 View Revisions
2013-04-03 20:12 Jesus Reyes Note Added: 0066785
2013-04-03 20:16 Jesus Reyes Note Added: 0066786
2013-09-04 14:47 raftakis ioannis Note Added: 0069724
2014-02-16 15:11 Motaz Abdel Azeem Note Added: 0073090
2016-12-22 13:40 Luiz Americo Status resolved => closed