Page 1 of 1
SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Mar 11, 2022 12:51 am
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:
The pagenumber looks in PDF:
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Mar 11, 2022 8:38 am
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.
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Sat Mar 12, 2022 12:07 pm
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.
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Sat Mar 12, 2022 12:48 pm
by Sergey Tkachenko
Please note 'Arial Unicode MS' font may be considered obsolete. It's not longer shipped with Windows or MS Office.
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Mon Oct 10, 2022 12:32 pm
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 (3.34 KiB) Viewed 27425 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
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Thu Oct 13, 2022 4:00 pm
by Sergey Tkachenko
What font name do you use? Is it a raster or a TrueType font?
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Thu Oct 13, 2022 4:11 pm
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 text
some text" instead of "some text
some text"
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Oct 14, 2022 6:52 am
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.
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Oct 14, 2022 8:43 am
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);
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Oct 14, 2022 8:57 am
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
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Oct 14, 2022 9:36 am
by tothpaul
OK, it way easier with VirtualPrinter ^^
but I can show some problems
- PDF.zip
- (90.92 KiB) Downloaded 1259 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
Re: SynPDF+TSrichViewEdit,The pagenumber in pdf deformed
Posted: Fri Oct 14, 2022 3:43 pm
by tothpaul
OK, you're right, I don't have those problems with llPDFDocument