SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

General TRichView support forum. Please post your questions here
Post Reply
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by wolf1860 »

I use TRVPrint to draw page,not test TSRichViewEdit draw page yet.
The pagenumber code:

Code: Select all

    var
    nomalStylef := GetTextStyle(RVStyleF, 8, [], clBlack, '宋体');
    var
    pgn := TRVPageNumberItemInfo.CreateEx(ifooter, rvpntDecimal, nomalStylef);
    pgn.Style.ParaStyles[0].Alignment := rvaCenter;
    ifooter.AddItem(TMyGlobal.CreateSortID, pgn);
The pagenumber looks in TSRichViewEdit:
Image

The pagenumber looks in PDF:
Image
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by Sergey Tkachenko »

Our component simply draws text. It cannot control how it will be scaled in PDF.
Recent changes do not fix this problem.

The first thing to check, maybe this problem occurs because of the font substitution.
- make sure that you really use the style specified in nomalStylef (for example, specify another text color to make sure that it is used); I cannot check it in your code fragment, because I do not know if RVFtyleF really used for ifooter.
- maybe PDF library has problems with this specific font (or maybe it has problems with fonts having non-English names). Try using another font.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by wolf1860 »

I have tested ur suggestion:
1) The style---nomalStylef used for the pagenumber:I changed the font color,the pdf displayed ok.
2)I changed font name 'Arial Unicode MS',that's the synpdf's author recommend font for Chinese/Japanese and other Asia texts,but can not fix the problem.
Anyway,thank u again,I will find a solution to avoid this.
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by Sergey Tkachenko »

Please note 'Arial Unicode MS' font may be considered obsolete. It's not longer shipped with Windows or MS Office.
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

hum...I have the same strange bug

I've added some AddNL() to see the difference between "FontSmall" and the PageNumber & Count font.

Code: Select all

procedure TFramePrescription.AddPageNumber(RVData: TCustomRVData);
begin
  RVData.AddNL('Page 1/2:', FontSmall, ParaCenter);
  var p := TRVPageNumberItemInfo.Create(RVData);
  p.TextStyleNo := FontSmall;
  p.ParaNo := -1;
  RVData.AddItem('', p);
  RVData.AddNL(' (1/2) ', FontSmall, -1);
  var n := TRVPageCountItemInfo.Create(RVData);
  n.TextStyleNo := FontSmall;
  n.ParaNo := -1;
  RVData.AddItem('', n);
end;
the top of the picture is TRichView, the bottom a PDF build with SynPDF (with RVPrint.MetafileCompatibility = True)
Presse-papiers.png
Presse-papiers.png (3.34 KiB) Viewed 24999 times
and the code to select the fonts

Code: Select all

var
  FI: TFontInfo;
  PI: TParaInfo;
begin
  FI := TFontInfo.Create(nil);
  FI.FontName := 'Arial';
  FI.Size := 10;
  FI.Color := clWindowText;
  FontText := Style.FindTextStyle(FI);
  FI.Size := 9;
  FI.Style := [fsBold];
  FI.Color := clBlack;
  FontBold := Style.FindTextStyle(FI);
  FI.Style := [fsBold, TFontStyle.fsUnderline];
  FontBoldU := Style.FindTextStyle(FI);
  FI.Size := 8;
  FI.Style := [];
  FontSmall := Style.FindTextStyle(FI);
  FI.Style := [fsItalic];
  FontSmalli := Style.FindTextStyle(FI);
  FI.Free;
  
EDIT: can it be related to TRVPageCountItemInfo.GetTextForPrintMeasuring returning '00' ?

Yep I can fix the problem with

Code: Select all

  p.AlwaysUseText := True;
  p.Text := '0';
  n.AlwaysUseText := True;
  n.Text := '0';
but it will cause problems for more then 9 pages :)
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by Sergey Tkachenko »

What font name do you use? Is it a raster or a TrueType font?
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

Arial, has you can see in the code.

but I think it is related also to MetafileCompatibility

I have another pb when this option is not set, if I put underlined text and normal text on the same line, the space between the two items is not visible

Code: Select all

AddNL('some text', NormalText, ParaNo)
AddNL(' ', NormalText);
AddNl('some text', UnderlinedText);
the PDF shows "some textsome text" instead of "some text some text"
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by Sergey Tkachenko »

By default, our VCL components use Uniscribe library to display text, and draw text using glyph indexes instead of character codes.
If MetafileCompatibility is True, the components calculate character positions using Uniscribe, but draw text using WinApi (ExtTextOut), using character indexes. Note that
- while this function accepts the parameter specifies distance between characters, it's not assumed that it should draw characters deformed; this parameter specifies character positions, not their widths.
- position of each character is specified on drawing.

Probably, SynPDF does not handle ExtTextOut properly. In this case, I can suggest:
1. Check, may be the problem is in fonts. Maybe positions of characters are calculated using the specified font, but PDF uses another font, so all character positions/sizes are wrong.
2. try to use only WinAPI, without Uniscribe. Assign "Windows" to SRichViewEdit.TextEngine
3. If nothing helps, use another PDF engine, such as LLPDFLib.
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

ok , in this case I use 4 TRichView, 1 RVStyle and a RVPrint

Code: Select all

// Dispatch
  RVStyle.TextEngine := rvteWindows;
  RVPrint.TitlePage := True;
  RVPrint.SetHeader(RVHeader.RVData, TRVHFType.rvhftFirstPage);
  RVPrint.SetFooter(RVFooter.RVData, TRVHFType.rvhftFirstPage);
  RVPrint.SetHeader(RVHeader2.RVData, TRVHFType.rvhftNormal);
  RVPrint.SetFooter(RVFooter2.RVData, TRVHFType.rvhftNormal);
  RVPrint.AssignSource(RVBody);
// Save PDF
  RVPrint.PDF := 'FORMAT';
  RVPrint.FormatPages(rvdoALL);
  RVPrint.PDF := 'FileName.PDF';
  RVPrint.Print('ePrescription', 1, True);
I've set the RVStyle textEngin but it change nothing, I still don't have space between the words when I use underlined text and the page numbers are scalled.

Note that I've made a change in your code to support PDF (hence ce RVPRint.PDF property)

when I set this property, my code use SynPDF's VCLCanvas to print the document.

for instance, in TPrintableRVData.InitPrinterCanvas I have this

Code: Select all

 {$IFDEF PDF}
  if FPdfDocument <> nil then
  begin
    Canvas := FPdfDocument.VCLCanvas;
    ExtraData := nil;
  end else
 {$ENDIF}
  begin
    RVPrint := GetRVPrint(Self) as TRVPrint;
    ...
in GetPageHeight

Code: Select all

{$IFDEF PDF}
  if FPdfDocument <> nil then
    Exit(FPdfDocument.VCLCanvasSize.Height);
{$ENDIF}
etc...so basically I use your printing logic on SynPDF canvas, I did that on a old version of RichView (before Uniscribe) and ported my modifications to the last version. Except the space bug that I've fixed with MetafileCompatibility everithing works great...until I've tried to add the page number.

as a workaround, I've put a text item that I update myself
for the footer of the first page

Code: Select all

RVFooter.RVData.SetItemText(PageCount1, '1/' + RVPrint.PagesCount.ToString); // PageCount is made public
and on PagePrepaint, for the other pages

Code: Select all

RVFooter2.RVData.SetItemText(PageCount2, PageNo.ToString + '/' + RVPrint.PagesCount.ToString);
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

ok , in this case I use 4 TRichView, 1 RVStyle and a RVPrint

Code: Select all

// Dispatch
  RVStyle.TextEngine := rvteWindows;
  RVPrint.TitlePage := True;
  RVPrint.SetHeader(RVHeader.RVData, TRVHFType.rvhftFirstPage);
  RVPrint.SetFooter(RVFooter.RVData, TRVHFType.rvhftFirstPage);
  RVPrint.SetHeader(RVHeader2.RVData, TRVHFType.rvhftNormal);
  RVPrint.SetFooter(RVFooter2.RVData, TRVHFType.rvhftNormal);
  RVPrint.AssignSource(RVBody);
// Save PDF
  RVPrint.PDF := 'FORMAT';
  RVPrint.FormatPages(rvdoALL);
  RVPrint.PDF := 'FileName.PDF';
  RVPrint.Print('ePrescription', 1, True);
I've set the RVStyle textEngin but it change nothing, I still don't have space between the words and the page numbers are scalled.

Note that I've made a change in your code to support PDF (hence ce RVPRint.PDF property)

when I set this property, my code use SynPDF's VCLCanvas to print the document.

for instance, in TPrintableRVData.InitPrinterCanvas I have this

Code: Select all

 {$IFDEF PDF}
  if FPdfDocument <> nil then
  begin
    Canvas := FPdfDocument.VCLCanvas;
    ExtraData := nil;
  end else
 {$ENDIF}
  begin
    RVPrint := GetRVPrint(Self) as TRVPrint;
    ...
in GetPageHeight

Code: Select all

{$IFDEF PDF}
  if FPdfDocument <> nil then
    Exit(FPdfDocument.VCLCanvasSize.Height);
{$ENDIF}
etc...so basically I use your printing logic on SynPDF canvas, I did that on a old version of RichView (before Uniscribe) and ported my modifications to the last version. Except the space bug that I've fixed with MetafileCompatibility everithing works great...until I've tried to add the page number.

as a workaround, I've put a text item that I update myself
for the footer of the first page

Code: Select all

RVFooter.RVData.SetItemText(PageCount1, '1/' + RVPrint.PagesCount.ToString); // PageCount is made public
and on PagePrepaint, for the other pages

Code: Select all

RVFooter2.RVData.SetItemText(PageCount2, PageNo.ToString + '/' + RVPrint.PagesCount.ToString);
I have to check your code for the difference between a simple text item and TCustomRVPageNumberItemInfo...there must be special treatment

BTW: I have to check the "new" VirtualPrinter property :D
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

OK, it way easier with VirtualPrinter ^^

but I can show some problems
PDF.zip
(90.92 KiB) Downloaded 930 times
by default, the footer display "Page 1 /1" with a space before the "/", and if you set PageNoFromNumber to 100 the text override the /

if you change one of the checkbox the page numbers are scaled to fit the orginal allocated place (width of "00" I guess)

even stranger...the space bug can be seen with this code

Code: Select all

  RichViewEdit1.RVData.Clear;
  RichViewEdit1.RVData.AddNL('DIANE', FontBold, ParaText); // why DIANE eat the space ?
  RichViewEdit1.RVData.AddNL(' ', FontBold);
  RichViewEdit1.RVData.AddNL('Some text', FontBoldU);
  RichViewEdit1.Format();
  
and with this text 'DIANE Sav lait d''ânesse frais & bio cacao cremeux 100g', the space is gone even with MetafileCompatibility set
tothpaul
Posts: 42
Joined: Fri Feb 06, 2015 10:41 am

Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed

Post by tothpaul »

OK, you're right, I don't have those problems with llPDFDocument
Post Reply