#1 2011-01-26 13:47:49

Pavel
Member
Registered: 2011-01-26
Posts: 9

Problems with Courier New font

Hello Arnaud,

Your Pdf Engine is a great product.

I use it for more then last half year. At a very beginning I found problem with Courier New font (pdf from example below I send you to email mentioned during registration). Then I used Lucida Console instead, that works OK, but people don't like this font.

I always thaught new version of pdf engine corrects this, that never happend. Now I tried last one, 1.12 and it is the same.

My computer is W7 64 bit, Delphi XE.
I even tried D2007 and WXP 32 bit w.o. success.

Would you be so kind and try to look to this problem?

Thanks,
Pavel

procedure TForm1.btnViaCanvasClick(Sender: TObject);
var
  i:Integer;
  PdfDocumentGDI: TPdfDocumentGDI;
begin
  PdfDocumentGDI:=TPdfDocumentGDI.Create;
  with PdfDocumentGDI do
  try
    AddPage;
    with VCLCanvas do
    begin
      for i := 0 to 9 do
      begin
        Font.Name := 'Courier New';//'Courier';
        Font.Size := 12;
        //Font.Style := [fsBold,fsItalic];
        TextOut(20, 100 + i*40,'Příliš žluťoučký kůň');
        //TextOut(20, 100 + i*40,'áÁčČďĎéÉíÍňŇóÓřŘšŠťŤúÚůýÝžŽ');
        TextOut(20, 100 + i*40+20,'ερτυθσδφγη йцукенгш asdffghj');
      end;

      for i := 0 to 9 do
      begin
        Font.Name := 'Lucida console';
        Font.Size := 12;
        //Font.Style := [fsBold,fsItalic];
        TextOut(20, 600 + i*40,'Příliš žluťoučký kůň');
        //TextOut(20, 100 + i*40,'áÁčČďĎéÉíÍňŇóÓřŘšŠťŤúÚůýÝžŽ');
        TextOut(20, 600 + i*40+20,'ερτυθσδφγη йцукенгш asdffghj');
      end;
    end;

    SaveToFile('TestVcl.pdf');
  finally
    Free;
  end;
end;

Offline

#2 2011-01-26 16:11:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

What is the exact problem?
Some missing Unicode characters in the resulting PDF?

Did you try with UseUniscribe := true; ?

As stated in the source code, we didn't implement FontFallBack yet...
That's perhaps the problem here.
But Uniscribe should solve most of the other issues. It even handled glyph shaping and such...

And don't forget to use the last available version of SynCommons+SynPDF from http://synopse.info/fossil

Offline

#3 2011-01-26 18:39:15

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

Arnaud,

I used version 1.12 from few days ago.

I tried UseUniScribe:=true, no success.

In SynPdf you write:

    // must contain ALL glyphs necessary for the supplied unicode text - squares
    // or blanks will be drawn for any missing glyph/character

My output (either run my example or look to my email with testvcl.pdf) has for writing in COURIER NEW no squares or blanks, it just has 'international' characters overwritten over previous character.

And this is for Czech, Greek and Cyrilic (others I don't know).

I tried also Arabic, and it gives above mentioned squares.

Pavel

Offline

#4 2011-01-27 12:45:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

There was no official 1.12 version released yet, as far as I remember (only BigTable). wink

I didn't receive any mail. Where did you post it, and when?

But I was able to reproduce the issue.
I'll find out what's wrong with this.

I guess its about the font metrics which is stored wrongly for fixed-width font, for unicode characters...

Offline

#5 2011-01-27 12:46:32

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

Arnaud,

please, look to my sample code below.

When writing to VclCanvas SEPARATE CHARACTERS (range 32-511), they appear normally.
When writing to VclCanvas the same characters as STRING, they are overwriting each other for codes above 255.

I think this is something between your code and Courier New font and doesn't has to do anything with FontFallBack.

Pavel

procedure TForm3.Button1Click(Sender: TObject);
var
  i, j: Integer;
  s: string;
  ch: char;
  PdfDocumentGDI: TPdfDocumentGDI;
begin
  PdfDocumentGDI:=TPdfDocumentGDI.Create;
  with PdfDocumentGDI do
  try
    AddPage;
    //UseUniScribe := true; {gives error during savetofile}
    with VCLCanvas do begin
      Font.Name := 'Courier New';
      Font.Size := 12;
      for i := 0 to 15 do begin
        s := '';
        for j := 0 to 31 do
          if i*32+j>=32 then begin
            ch := chr(i*32+j);
            s := s+ch;
            TextOut(10+j*20, i*50, ch);
          end;
          TextOut(10, i*50+25, s);
      end;
    end;
    SaveToFile('TestVcl.pdf');
  finally
    Free;
  end;
end;

Offline

#6 2011-01-27 12:49:42

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

You wrote answer when I was writing my another comment.
Greetings to France.
Pavel

Offline

#7 2011-01-27 13:57:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

Thanks to your source code sample, I found out the issue.

It was indeed a wrong width char calculation for fixed-width fonts, only for Unicode characters.
It did have nothing to do with fontfallback.

It's now fixed in our Source code repository.
smile

Thanks for your report and interest!
Hope we'll make this unit always better (I'm currently trying to make it PDF/A-1 compliant).

Offline

#8 2011-01-27 21:07:19

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

I download it from code repository, many thanks for your immediate action.

Just a small remark - you have DefaultPaperSize for PdfDocument. I need from time to time also different orientation, i.e. poLandscape and I add it to every new version. Wouldn't it be useful to have it there from you?

I know you tried not to be dependent on Printers unit.

procedure TPdfDocument.SetOrientation(const Value: TPrinterOrientation);
var tmp: integer;
begin
  FOrientation := Value;
  if Value=poPortrait then begin
    if FDefaultPageWidth>FDefaultPageHeight then begin
      tmp:=FDefaultPageWidth;
      FDefaultPageWidth:=FDefaultPageHeight;
      FDefaultPageHeight:=tmp;
    end
  end
  else begin // landscape
    if FDefaultPageHeight>FDefaultPageWidth then begin
      tmp:=FDefaultPageWidth;
      FDefaultPageWidth:=FDefaultPageHeight;
      FDefaultPageHeight:=tmp;
    end
  end;
end;

Offline

#9 2011-01-27 22:19:10

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

Works great through TPdfDocumentGDI.VclCanvas.
There are some buts with TPdfDocument.Canvas that I post with example tomorrow, maybe they are not on your side.
SynPdf: missing SetPDFA1 declaration.

Offline

#10 2011-01-28 06:55:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

Pavel wrote:

Works great through TPdfDocumentGDI.VclCanvas.
There are some buts with TPdfDocument.Canvas that I post with example tomorrow, maybe they are not on your side.

OK - waiting for your feedback.


Pavel wrote:

SynPdf: missing SetPDFA1 declaration.

What does it mean?
Perhaps you don't have the correct files: you need to retrieve SynPDF and SynCommons units from the same version.

Offline

#11 2011-01-28 10:53:05

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

1. Look please possibly to printer Orientation
2. SetPDFA1 declaration: it's OK - my mistake
3. Try please following code (VclCanvas/Canvas).
    Maybe it works correct, maybe there is some wrong conversion from Unicode, comments are in source.
    It works the same way for fixed-width and proportional fonts.

procedure TForm3.Button2Click(Sender: TObject);
begin
  with TPdfDocumentGDI.Create do
  try
    AddPage;
    UseUniScribe := true;
    with VCLCanvas do begin
      Font.Name := 'Courier New';
      Font.Size := 14;
      Font.Style := [fsBold,fsItalic];
      TextOut(100, 100,'áÁčČďĎéÉíÍňŇóÓřŘšŠťŤúÚůýÝžŽ');
      // all characters printed correctly
    end;
    SaveToFile('TestVcl.pdf');
  finally
    Free;
  end;

  with TPdfDocument.Create do
  try
    AddPage;
    UseUniScribe := true;
    Canvas.SetFont('Courier New',14,[fsItalic,fsBold]);
    Canvas.TextOut(100, 700,'áÁčČďĎéÉíÍňŇóÓřŘšŠťŤúÚůýÝžŽ');
    // ? only characters that exists in range 0..255 prints OK,
    // others with removed signs
    SaveToFile('TestDirect.pdf');
  finally
    Free;
  end;
end;

Offline

#12 2011-01-28 10:57:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

Pavel wrote:

Just a small remark - you have DefaultPaperSize for PdfDocument. I need from time to time also different orientation, i.e. poLandscape and I add it to every new version. Wouldn't it be useful to have it there from you?

I've added this new property to TPdfDocument, to handle a default orientation, when a page is about to be added:

    /// the default page orientation
    // - a call to this property will swap default page width and height if the
    // orientation is not correct
    property DefaultPageLandscape: boolean read GetDefaultPageLandscape write SetDefaultPageLandscape;

And this one to TPdfPage, for changing the orientation of the current canvas page:

    /// retrieve or set the paper orientation
    property PageLandscape: Boolean read GetPageLandscape write SetPageLandscape;

Offline

#13 2011-01-28 11:06:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

Pavel wrote:

3. Try please following code (VclCanvas/Canvas).

Check out the interfaces:

    /// show some text at a specified page position
    procedure TextOut(X, Y: Single; const Text: PDFString);
    /// show some unicode text at a specified page position
    procedure TextOutW(X, Y: Single; PW: PWideChar);

So.... TextOut doesn't handle unicode, but only PDFString, i.e. ansitext!!!
Try again with TextOutW.
wink

It's one drawback of making an unit working from Delphi 6 up to XE.

If you use TPdfDocument directly, you MUST check carrefully for the string types...
PDFString is not a generic string, it's an Ansi string, as most PDF tags are not Unicode at all, but raw 8 bit win-ansi...

That's why using the VCLCanvas, or TGdiPages, make sense for the end-user.

Offline

#14 2011-01-28 16:34:13

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

TextOut/TextOutW: I had to look to interfaces, sorry to disturb you.
Thanks for landscape support.
If everybody (every company) would support it's product like you, life would be so much easier.

Many thanks,

Pavel

Offline

#15 2011-01-28 16:58:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Problems with Courier New font

That's because there are users like you, which supply good problem description, and some source code to reproduce it easily.

It helped me a lot, having such precise steps for reproducing the issue.

And we are not a company... since I'm a lonesome programmer, and making no money with all the published components.
I made those units because none was existing as open source yet.
And since I like Delphi very much, working open source libraries will always help the community, and the language.
Even if I didn't have enough money to buy the latest Delphi compiler (to be fair, it was because the amount was not worth it IMHO)!!!
smile

Offline

#16 2011-01-31 13:02:22

Pavel
Member
Registered: 2011-01-26
Posts: 9

Re: Problems with Courier New font

Arnaud,

I have to (positively) disagree with you.

It is not about users (like me), they have to anyway transfer their problems to their suppliers. When the problem is then understandable to supplier, then it starts to be interesting. And your reaction was - GRREEAATT.

Pavel

Offline

Board footer

Powered by FluxBB