📄 embeddedpdffonts.pas
字号:
(KEY: 'FontName'; VAL: 'Type1'),
(KEY: 'Encoding'; VAL: 'WinAnsiEncoding')
);
SCRIPT_DISC_INT_TABLE: array[0..6] of TPDF_INT_TBL =(
(KEY: 'Ascent'; VAL: 758),
(KEY: 'CapHeight'; VAL: 758),
(KEY: 'Descent'; VAL: -363),
(KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET + PDF_FONT_ITALIC),
(KEY: 'ItalicAngle'; VAL: 0),
(KEY: 'StemV'; VAL: 78),
(KEY: 'MissingWidth'; VAL: 202));
SCRIPT_BBOX: array[0..3] of Integer = (-184,-363,505,758);
type
TPdfType1Font = class(TPdfFont)
private
FFirstChar: Byte;
FLastChar: Byte;
FArray: array[0..255] of Word;
public
procedure SetData(Value: TPdfDictionary); override;
function GetCharWidth(AText: string; APos: integer): integer; override;
end;
TPdfTrueTypeFont = class(TPdfFont)
private
FFirstChar: Byte;
FLastChar: Byte;
FArray: array[0..255] of Word;
public
procedure SetData(Value: TPdfDictionary); override;
function GetCharWidth(AText: string; APos: integer): integer; override;
end;
TPdfFixedWidth = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfFixedWidthBold = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfFixedWidthItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfFixedWidthBoldItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfArial = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfArialBold = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfArialItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfArialBoldItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTimesRoman = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTimesBold = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTimesItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTimesBoldItalic = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfScript = class(TPdfType1Font)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTahoma = class(TPdfTrueTypeFont)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTahomaBold = class(TPdfTrueTypeFont)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTrebuchetMS = class(TPdfTrueTypeFont)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
TPdfTrebuchetMSBold = class(TPdfTrueTypeFont)
public
constructor Create(AXref: TPdfXref; AName: string); override;
end;
implementation
{ TPdfType1Font }
function TPdfType1Font.GetCharWidth(AText: string; APos: integer): integer;
begin
result := FArray[ord(AText[APos])];
end;
procedure TPdfType1Font.SetData(Value: TPdfDictionary);
var
i: integer;
DefaultWidth: Word;
Widths: TPdfArray;
begin
inherited SetData(Value);
// initialize char widths array by default value (if missing width parameter
// is defined, use it as default value.)
if Data.PdfNumberByName('MissingWidth') <> nil then
DefaultWidth := Data.PdfNumberByName('MissingWidth').Value
else
DefaultWidth := 0;
for i := 0 to 255 do
FArray[i] := DefaultWidth;
FFirstChar := Data.PdfNumberByName('FirstChar').Value;
FLastChar := Data.PdfNumberByName('LastChar').Value;
// fill width array with "Widths" table values.
Widths := Data.PdfArrayByName('Widths');
for i := 0 to Widths.ItemCount - 1 do
FArray[i + FFirstChar] := TPdfNumber(Widths.Items[i]).Value;
end;
{ TPdfTrueTypeFont }
function TPdfTrueTypeFont.GetCharWidth(AText: string; APos: integer): integer;
begin
result := FArray[ord(AText[APos])];
end;
procedure TPdfTrueTypeFont.SetData(Value: TPdfDictionary);
var
i: integer;
DefaultWidth: Word;
Widths: TPdfArray;
begin
inherited SetData(Value);
// initialize char widths array by default value (if missing width parameter
// is defined, use it as default value.)
if Data.PdfNumberByName('MissingWidth') <> nil then
DefaultWidth := Data.PdfNumberByName('MissingWidth').Value
else
DefaultWidth := 0;
for i := 0 to 255 do
FArray[i] := DefaultWidth;
FFirstChar := Data.PdfNumberByName('FirstChar').Value;
FLastChar := Data.PdfNumberByName('LastChar').Value;
// fill width array with "Widths" table values.
Widths := Data.PdfArrayByName('Widths');
for i := 0 to Widths.ItemCount - 1 do
FArray[i + FFirstChar] := TPdfNumber(Widths.Items[i]).Value;
end;
{ FixedWidth }
constructor TPdfFixedWidth.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
// make instance of TPdfDictionary and register to Xref table.
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
// adding element to the dictionary.
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, FIXED_WIDTH_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Courier'));
// create "Width" table of the font.
FWidths := TPdfArray.CreateNumArray(AXref, FIXED_WIDTH_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ FixedWidthBold }
constructor TPdfFixedWidthBold.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, FIXED_WIDTH_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Courier-Bold'));
FWidths := TPdfArray.CreateNumArray(AXref, FIXED_WIDTH_BOLD_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ FixedWidthItalic }
constructor TPdfFixedWidthItalic.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, FIXED_WIDTH_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Courier-Oblique'));
FWidths := TPdfArray.CreateNumArray(AXref, FIXED_WIDTH_ITALIC_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ FixedWidthBoldItalic }
constructor TPdfFixedWidthBoldItalic.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, FIXED_WIDTH_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Courier-BoldOblique'));
FWidths := TPdfArray.CreateNumArray(AXref, FIXED_WIDTH_BOLDITALIC_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ Arial }
constructor TPdfArial.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, ARIAL_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Helvetica'));
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ Arial-Bold }
constructor TPdfArialBold.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
FFont := TPdfDictionary.CreateDictionary(AXref);
AXref.AddObject(FFont);
AddStrElements(FFont, TYPE1_FONT_STR_TABLE);
AddIntElements(FFont, ARIAL_INT_TABLE);
FFont.AddItem('BaseFont', TPdfName.CreateName('Helvetica-Bold'));
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_BOLD_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths);
SetData(FFont);
end;
{ Arial-Italic }
constructor TPdfArialItalic.Create(AXref: TPdfXref; AName: string);
var
FWidths: TPdfArray;
FFont: TPdfDictionary;
begin
inherited Create(AXref, AName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -