#1 2012-09-10 01:26:20

igors233
Member
Registered: 2012-09-10
Posts: 241

Issue with ExtTextOut

Greetings everyone,

I've been trying to implement pdf saving in my program but there is some issue with ExtTextOut when using spacing values, same function works ok on form canvas. I would greatly appreciate if someone could take a look at the code and check if I'm doing something wrong, thanks.

uses
  ShellApi,
  SynPdf;

procedure TForm1.Button1Click(Sender: TObject);
var
  pdf: TPdfDocumentGDI;
  emf: TMetafile;
  pdx: array of Integer;
begin
  pdf := TPdfDocumentGDI.Create;
  pdf.AddPage;

  SetLength(pdx, 4);

  pdx[0] := 10;
  pdx[1] := 24;
  pdx[2] := 10;
  pdx[3] := 10;

  // This one is OK
  ExtTextOutW(pdf.VCLCanvas.Handle, 100, 100, 0, nil, 'Test', 4, @pdx[0]);

  pdx[0] := 10;
  pdx[1] := 34;
  pdx[2] := 40;
  pdx[3] := 10;

  pdf.AddPage;
  // This one fails in SaveToFile (RenderMetaFile)
  ExtTextOutW(pdf.VCLCanvas.Handle, 100, 100, 0, nil, 'Test', 4, @pdx[0]);

  pdf.SaveToFile('Test.pdf');
  pdf.Free;

  // Display text on form canvas, no problem
  ExtTextOutW(Canvas.Handle, 100, 100, 0, nil, 'Test', 4, @pdx[0]);
end;

Offline

#2 2012-09-10 05:18:26

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

Re: Issue with ExtTextOut

Problem here is that the Windows font rendering is not at all the same as the one used for pdf.
There is no such indices of individual glyph position in pdf.

The current implementation of SynPdf use a simple pattern to compute inter-glyph mean for a whole string, then adjust globally spacing for the text.
So individual indexes is not handled.

I know some pdf printers who does individual glyph positioning but it has some drawbacks:
- Generated pdf files are bigger;
- Rendering is slower;
- Search within the text won't work any more in Acrobat Reader.

That is why we did not implement it yet.
We may do it, if you have some code to propose.

For your special case, the easiest is to change the code on the drawing side, calling ExtTextOutW() once per glyph (or group of adjacent glyphs).
Metafile will be a bit bigger in memory, so the pdf, but when converted to pdf, you will have the expected results.

Offline

#3 2012-09-11 20:28:53

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Issue with ExtTextOut

Thank you for detailed explanation, I appreciate it.

I have a printer application that serves as a proxy for DOS applications printing on GDI printers, in general I receive fixed width formatted text file which I process. Due to Windows issues with not equal chars widths in some fixed with Fonts like Lucida Console I'm forced to use ExtTextOut. Also I cannot use SetTextCharacterExtra for intercharspacing since it's not correct, so I need here ExtTextOut as well.

> That is why we did not implement it yet.
> We may do it, if you have some code to propose.

> For your special case, the easiest is to change the code on the drawing side, calling ExtTextOutW() once per glyph (or group of adjacent glyphs).
> Metafile will be a bit bigger in memory, so the pdf, but when converted to pdf, you will have the expected results.

I'll try to solve problem using RenderMetaFile since application produces emf (for previewing) as well. Initial test showed good result. Some chars are more spaced, but that's probably due to computed inter glyph mean you've explained. I would like to try and find better solution but I don't know where to start, it would be good if you could point me in the right direction. 
Here is a link to two example pdf (synPDF and pdfFactory), http://wtrns.fr/Br42Bvos1defnzC.

> I know some pdf printers who does individual glyph positioning but it has some drawbacks:
> - Generated pdf files are bigger;
> - Rendering is slower;
> - Search within the text won't work any more in Acrobat Reader.

I've included pdfFactory example as well since it gives good search results (only one miss), synPDF finds all matches.

Kind regards,
Igor

Offline

Board footer

Powered by FluxBB