⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdffonts.pas

📁 作者:Takeshi Kanno. PowerPdf是一款制作PDF文档的VCL控件。使用上和QuickReport类似。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                         (KEY: 'CapHeight'; VAL: 905),
                         (KEY: 'Descent'; VAL: -212),
                         (KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET +
                           PDF_FONT_FOURCE_BOLD),
                         (KEY: 'ItalicAngle'; VAL: -15),
                         (KEY: 'StemV'; VAL: 156),
                         (KEY: 'MissingWidth'; VAL: 750));

  ARIAL_BOLDITALIC_BBOX: array[0..3] of Integer = (-174,-228,1114,962);

  // Times definition

  TIMES_ROMAN_W_ARRAY: array[32..255] of Integer = (
    250,333,408,500,500,833,778,180,333,333,500,564,250,333,
    250,278,500,500,500,500,500,500,500,500,500,500,278,278,564,564,
    564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,
    722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,
    469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,
    500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,
    541,0,500,0,333,500,444,1000,500,500,333,1000,556,333,889,0,
    611,0,0,333,333,444,444,350,500,1000,333,980,389,333,722,0,
    444,722,0,333,500,500,500,500,200,500,333,760,276,500,564,0,
    760,333,400,564,300,300,333,500,453,250,333,300,310,500,750,750,
    750,444,722,722,722,722,722,722,889,667,611,611,611,611,333,333,
    333,333,722,722,722,722,722,722,722,564,722,722,722,722,722,722,
    556,500,444,444,444,444,444,444,667,444,444,444,444,444,278,278,
    278,278,500,500,500,500,500,500,500,564,500,500,500,500,500,500,
    500,500);

  TIMES_INT_TABLE: array[0..1] of TPDF_INT_TBL = (
                       (KEY: 'FirstChar'; VAL: 32),
                       (KEY: 'LastChar'; VAL: 255)
                       );

  TIMES_DISC_STR_TABLE: array[0..2] of TPDF_STR_TBL =(
                         (KEY: 'Type'; VAL: 'FontDescriptor'),
                         (KEY: 'FontName'; VAL: 'Type1'),
                         (KEY: 'Encoding'; VAL: 'WinAnsiEncoding')
                         );

  TIMES_DISC_INT_TABLE: array[0..6] of TPDF_INT_TBL =(
                         (KEY: 'Ascent'; VAL: 891),
                         (KEY: 'CapHeight'; VAL: 891),
                         (KEY: 'Descent'; VAL: -216),
                         (KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET +
                           PDF_FONT_SERIF),
                         (KEY: 'ItalicAngle'; VAL: 0),
                         (KEY: 'StemV'; VAL: 78),
                         (KEY: 'MissingWidth'; VAL: 778)
                         );

  TIMES_BBOX: array[0..3] of Integer = (-168,-218,1000,898);

  // Times-Italic definition

  TIMES_ITALIC_W_ARRAY: array[32..255] of Integer = (
    250,333,420,500,500,833,778,214,333,333,500,675,250,333,
    250,278,500,500,500,500,500,500,500,500,500,500,333,333,675,675,
    675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,
    667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,
    422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,
    500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,
    541,0,500,0,333,500,556,889,500,500,333,1000,500,333,944,0,
    556,0,0,333,333,556,556,350,500,889,333,980,389,333,667,0,
    389,556,0,389,500,500,500,500,275,500,333,760,276,500,675,0,
    760,333,400,675,300,300,333,500,523,250,333,300,310,500,750,750,
    750,500,611,611,611,611,611,611,889,667,611,611,611,611,333,333,
    333,333,722,667,722,722,722,722,722,675,722,722,722,722,722,556,
    611,500,500,500,500,500,500,500,667,444,444,444,444,444,278,278,
    278,278,500,500,500,500,500,500,500,675,500,500,500,500,500,444,
    500,444);

  TIMES_ITALIC_DISC_INT_TABLE: array[0..6] of TPDF_INT_TBL =(
                         (KEY: 'Ascent'; VAL: 891),
                         (KEY: 'CapHeight'; VAL: 891),
                         (KEY: 'Descent'; VAL: -216),
                         (KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET +
                           PDF_FONT_SERIF + PDF_FONT_ITALIC),
                         (KEY: 'ItalicAngle'; VAL: -15),
                         (KEY: 'StemV'; VAL: 78),
                         (KEY: 'MissingWidth'; VAL: 778));

  TIMES_ITALIC_BBOX: array[0..3] of Integer = (-169,-217,1010,883);

  // Times-BOLD definition

  TIMES_BOLD_W_ARRAY: array[32..255] of Integer = (
    250,333,555,500,500,1000,833,278,333,333,500,570,250,333,
    250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,
    570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,
    722,778,611,778,722,556,667,722,722,1000,722,722,667,333,278,333,
    581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,
    556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,
    520,0,500,0,333,500,500,1000,500,500,333,1000,556,333,1000,0,
    667,0,0,333,333,500,500,350,500,1000,333,1000,389,333,722,0,
    444,722,0,333,500,500,500,500,220,500,333,747,300,500,570,0,
    747,333,400,570,300,300,333,556,540,250,333,300,330,500,750,750,
    750,500,722,722,722,722,722,722,1000,722,667,667,667,667,389,389,
    389,389,722,722,778,778,778,778,778,570,778,722,722,722,722,722,
    611,556,500,500,500,500,500,500,722,444,444,444,444,444,278,278,
    278,278,500,556,500,500,500,500,500,570,500,556,556,556,556,500,
    556,500);

  TIMES_BOLD_DISC_INT_TABLE: array[0..6] of TPDF_INT_TBL =(
                         (KEY: 'Ascent'; VAL: 891),
                         (KEY: 'CapHeight'; VAL: 891),
                         (KEY: 'Descent'; VAL: -216),
                         (KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET +
                           PDF_FONT_SERIF + PDF_FONT_FOURCE_BOLD),
                         (KEY: 'ItalicAngle'; VAL: 0),
                         (KEY: 'StemV'; VAL: 156),
                         (KEY: 'MissingWidth'; VAL: 778));

  TIMES_BOLD_BBOX: array[0..3] of Integer = (-168,-218,1000,935);

  // Times-BoldItalic definition

  TIMES_BOLDITALIC_W_ARRAY: array[32..255] of Integer = (
    250,389,555,500,500,833,778,278,333,333,500,570,250,333,
    250,278,500,500,500,500,500,500,500,500,500,500,333,333,570,570,
    570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,
    722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,
    570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,
    556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,
    570,0,500,0,333,500,500,1000,500,500,333,1000,556,333,944,0,
    611,0,0,333,333,500,500,350,500,1000,333,1000,389,333,722,0,
    389,611,0,389,500,500,500,500,220,500,333,747,266,500,606,0,
    747,333,400,570,300,300,333,576,500,250,333,300,300,500,750,750,
    750,500,667,667,667,667,667,667,944,667,667,667,667,667,389,389,
    389,389,722,722,722,722,722,722,722,570,722,722,722,722,722,611,
    611,500,500,500,500,500,500,500,722,444,444,444,444,444,278,278,
    278,278,500,556,500,500,500,500,500,570,500,556,556,556,556,444,
    500,444);

  TIMES_BOLDITALIC_DISC_INT_TABLE: array[0..6] of TPDF_INT_TBL =(
                         (KEY: 'Ascent'; VAL: 891),
                         (KEY: 'CapHeight'; VAL: 891),
                         (KEY: 'Descent'; VAL: -216),
                         (KEY: 'Flags'; VAL: PDF_FONT_STD_CHARSET +
                           PDF_FONT_SERIF + PDF_FONT_FOURCE_BOLD),
                         (KEY: 'ItalicAngle'; VAL: -15),
                         (KEY: 'StemV'; VAL: 156),
                         (KEY: 'MissingWidth'; VAL: 778));

  TIMES_BOLDITALIC_BBOX: array[0..3] of Integer = (-200,-218,996,921);

  SCRIPT_W_ARRAY: array[32..255] of Integer = (
    323,202,323,424,404,485,525,202,283,283,323,525,202,525,202,444,
    404,404,404,404,404,404,404,404,404,404,202,202,485,525,485,364,
    545,404,465,404,465,404,404,465,485,343,303,485,384,667,485,424,
    505,444,505,404,384,485,465,566,485,465,424,283,283,283,444,323,
    222,323,283,222,323,202,162,303,303,141,141,283,162,505,364,283,
    303,303,263,222,182,303,303,424,323,303,283,283,162,283,485,202,
    202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,202,
    202,222,202,202,202,202,202,202,202,202,202,202,202,202,202,202,
    202,202,222,384,283,465,162,283,404,283,323,404,404,404,283,404,
    404,404,404,404,404,384,424,404,404,404,283,404,404,404,404,364,
    404,404,404,404,404,404,566,404,404,404,404,404,343,343,343,343,
    465,485,424,424,424,424,424,323,404,485,485,485,485,465,444,444,
    323,323,323,323,323,323,384,222,202,202,202,202,141,141,141,141,
    283,364,283,283,283,283,283,404,283,303,303,303,303,303,384,303
    );

  SCRIPT_INT_TABLE: array[0..1] of TPDF_INT_TBL = (
                       (KEY: 'FirstChar'; VAL: 32),
                       (KEY: 'LastChar'; VAL: 255)
                         );

  SCRIPT_DISC_STR_TABLE: array[0..2] of TPDF_STR_TBL =(
                         (KEY: 'Type'; VAL: 'FontDescriptor'),
                         (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;

  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;

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;

{ FixedWidth }
constructor TPdfFixedWidth.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 + -