Error using fpPdf, because the original FPPDF can not be step-by-step debugging I made a copy of FPPDF and renamed it, but there was an error using it. There is no problem using the original FPPDF.
my code
procedure TForm1.Button5Click(Sender: TObject);
var
FontID, FontBoldID: Integer;
Document: TPDFDocument;
Section: TPDFSection;
Page: TPDFPage;
s:utf8string;
AColor : TARGBColor;
begin
Document := TPDFDocument.Create(nil);
Document.FontDirectory := 'C:\Windows\Fonts';
Document.StartDocument;
Document.Infos.Author:='dd颜';//CP936ToUTF8('ymff名字');
Document.Infos.Producer:='测试pdf';
Document.Infos.Title:='汉语';
//Document.Infos.
// FontID := Document.AddFont('simfang.ttf', 'FangSong');
FontBoldID := Document.AddFont('arial.ttf', 'Arial');
// without poNoEmbeddedFonts it works as expected, but with huge file sizes
Document.Options := Document.Options + [poPageOriginAtTop, poNoEmbeddedFonts,poUTF16info];
Section := Document.Sections.AddSection;
Page := Document.Pages.AddPage;
Section.AddPage(Page);
AColor := clBlue;
page.SetColor(AColor ,true);
page.DrawRect(67.944 ,763.18 ,252.82 ,42.744,5,true,false,0.0 );
page.SetFont(FontBoldID ,15);
Page.WriteText(20, 30, 'This is bold text');
// Document.CreateInfoEntry(true); only add this code in fppdf to update Document.Infos.
Document.SaveToFile('output.pdf');
error :invalid type cast at file 'ymfpdf.pas' at line 1756
// TODO: (optional improvement) CID -> Unicode mappings, use ranges to generate a smaller CMap
// See pdfbox's writeTo() method in ToUnicodeWriter.java
procedure TPDFTrueTypeCharWidths.Write(const AStream: TStream);
var
i: integer;
s: string;
lst: TTextMappingList;
lFont: TTFFileInfo;
lWidthIndex: integer;
begin
s := '';
lst := Document.Fonts[EmbeddedFontNum].TextMapping;
lst.Sort;
lFont := Document.Fonts[EmbeddedFontNum].FTrueTypeFile;
// lFont.
{$IFDEF gdebug}
System.WriteLn('****** isFixedPitch = ', BoolToStr(lFont.PostScript.isFixedPitch > 0, True));
System.WriteLn('****** Head.UnitsPerEm := ', lFont.Head.UnitsPerEm );
System.WriteLn('****** HHead.numberOfHMetrics := ', lFont.HHead.numberOfHMetrics );
{$ENDIF}
{ NOTE: Monospaced fonts may not have a width for every glyph
the last one is for subsequent glyphs. }
for i := 0 to lst.Count-1 do
begin
if lst[i].GlyphID < lFont.HHead.numberOfHMetrics then
lWidthIndex := lst[i].GlyphID
else
lWidthIndex := lFont.HHead.numberOfHMetrics-1;
s := s + Format(' %d [%d]', [lst[i].GlyphID, TTTFFriendClass(lFont).ToNatural(lFont.Widths[lWidthIndex].AdvanceWidth)])
//This line throws an error,Debug watch display
// lst[i].GlyphID ,<Error: Cannot access indexed element in expression [>
//TTTFFriendClass(lFont).ToNatural(lFont.Widths[lWidthIndex].AdvanceWidth) <Error: calling functions not allowed at 33: "(">
end;
WriteString(s, AStream);
end;