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

📄 pdfjpfonts.pas

📁 作者:Takeshi Kanno. PowerPdf是一款制作PDF文档的VCL控件。使用上和QuickReport类似。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{*
 * << P o w e r P d f >> -- PdfJpFonts.pas
 *
 * << Japanese font set for Shift-JIS Charactors >>
 *
 * Copyright (c) 1999-1101 Takezou. <takeshi_kanno@est.hi-ho.ne.jp>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Library General Public License as published
 * by the Free Software Foundation; either version 2 of the License, or any
 * later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
 * details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library.
 *
 * Create 2001.04.14
 *
 *}
unit PdfJpFonts;

interface

uses
  SysUtils, Classes, PdfDoc, PdfTypes;

const
  CIDTYPE2_JP_FONT_STR_TABLE: array[0..2] of TPDF_STR_TBL =(
                         (KEY: 'Type'; VAL: 'Font'),
                         (KEY: 'Subtype'; VAL: 'CIDFontType2'),
                         (KEY: 'WinCharSet'; VAL: '128')
                         );

  CIDTYPE2_JP_FONT_DEFAULT_WIDTH = 1000;
  CIDTYPE2_JP_FONT_WIDTH_ARRAY: array[0..2] of Integer = (231, 631, 500);

  CIDTYPE2_JP_FONT_BBOX: array[0..3] of Integer = (0,-141,1000,859);

  CIDTYPE2_JP_FONT_DISC_INT_TABLE: array[0..3] of TPDF_INT_TBL =(
                         (KEY: 'Ascent'; VAL: 859),
                         (KEY: 'CapHeight'; VAL: 859),
                         (KEY: 'Descent'; VAL: -141),
                         (KEY: 'MissingWidth'; VAL: 500)
                         );

  TYPE0_JP_FONT_STR_TABLE: array[0..2] of TPDF_STR_TBL =(
                         (KEY: 'Type'; VAL: 'Font'),
                         (KEY: 'Subtype'; VAL: 'Type0'),
                         (KEY: 'Encoding'; VAL: '90ms-RKSJ-H')
                         );

  TYPE0_JPP_FONT_STR_TABLE: array[0..2] of TPDF_STR_TBL =(
                         (KEY: 'Type'; VAL: 'Font'),
                         (KEY: 'Subtype'; VAL: 'Type0'),
                         (KEY: 'Encoding'; VAL: '90msp-RKSJ-H')
                         );

  // PGothic widths array from CID 1
  PGOTHIC_FONT_WIDTH_ARRAY1: array[0..94]of Integer = (
       305,219,500,500,500,500,594,203,305,305,500,500,203,500,203,500,
       500,500,500,500,500,500,500,500,500,500,203,203,500,500,500,453,
       668,633,637,664,648,566,551,680,641,246,543,598,539,742,641,707,
       617,707,625,602,590,641,633,742,602,590,566,336,504,336,414,305,
       414,477,496,500,496,500,305,461,500,211,219,461,211,734,500,508,
       496,496,348,461,352,500,477,648,461,477,457,234,234,234,414
       );

  // PGothic widths array from CID 326
  PGOTHIC_FONT_WIDTH_ARRAY2: array[0..63] of Integer = (
       500,441,441,441,441,441,547,523,445,480,469,516,523,504,438,500,
       641,617,566,625,598,637,563,652,539,621,523,664,590,637,645,555,
       527,602,602,602,461,645,598,578,648,492,637,516,547,613,641,605,
       453,660,508,609,664,641,520,559,512,656,566,559,590,563,250,230
       );

  // PGothic widths array from CID 633
  PGOTHIC_FONT_WIDTH_ARRAY3: array[0..62]of Integer = (
       664,664,664,664,664,500,500,500,1000,1000,500,500,500,500,500,500,
       1000,1000,746,746,734,699,1000,1000,1000,1000,1000,961,1000,500,1000,1000,
       1000,1000,1000,1000,1000,500,500,500,500,500,500,500,500,500,500,500,
       500,500,500,500,500,500,500,500,500,500,500,1000,1000,1000,1000
       );

  // PGothic widths array from CID 771
  PGOTHIC_FONT_WIDTH_ARRAY4: array[0..7]of Integer = (
       1000,1000,1000,1000,1000,500,500,500
       );

  // PGothic widths array from CID 780
  PGOTHIC_FONT_WIDTH_ARRAY5: array[0..9]of Integer = (
       684,684,684,684,684,684,684,684,684,684
       );

  // PGothic widths array from CID 790
  PGOTHIC_FONT_WIDTH_ARRAY6: array[0..25]of Integer = (
       715,777,742,758,711,633,773,770,273,605,754,629,934,770,805,711,
       805,758,742,617,770,715,980,652,648,648
       );

  // PGothic widths array from CID 816
  PGOTHIC_FONT_WIDTH_ARRAY7: array[0..25]of Integer = (
       574,602,563,602,563,297,578,621,250,250,594,250,938,621,605,605,
       602,379,570,336,621,512,777,520,496,508
       );

  // PGothic widths array from CID 842
  PGOTHIC_FONT_WIDTH_ARRAY8: array[0..82]of Integer = (
       746,941,805,945,602,707,750,902,805,945,1000,1000,844,902,590,816,
       945,980,797,895,766,883,766,766,961,980,1000,1000,922,961,922,922,
       863,902,805,953,957,902,902,766,883,902,941,1000,1000,1000,1000,1000,
       1000,961,961,961,1000,1000,1000,1000,1000,1000,1000,1000,1000,891,1000,980,
       980,805,844,1000,844,980,727,863,805,746,863,1000,844,863,1000,1000,
       1000,855,961
       );

  // PGothic widths array from CID 925
  PGOTHIC_FONT_WIDTH_ARRAY9: array[0..62]of Integer = (
       758,898,652,824,754,941,742,895,809,934,824,922,961,965,805,941,
       930,961,797,891,1000,1000,898,898,902,965,914,980,805,883,766,922,
       910,961,734,863,922,887,961,648,707,941,910,824,930,707,1000,1000,
       1000,766,863,863,805,883,883,945,945,945,922,953,953,902,668
       );

  // PGothic widths array from CID 988
  PGOTHIC_FONT_WIDTH_ARRAY10: array[0..22]of Integer = (
       977,719,898,805,980,813,961,629,727,809,746,1000,852,863,766,941,
       1000,1000,805,863,961,727,777
       );

  // PMincyo widths array from CID 1
  PMINCYO_FONT_WIDTH_ARRAY1: array[0..94]of Integer = (
       305,305,461,500,500,500,613,305,305,305,500,500,305,500,305,500,
       500,500,500,500,500,500,500,500,500,500,305,305,500,500,500,500,
       727,664,621,699,691,598,598,711,723,289,387,668,586,801,664,766,
       563,766,602,504,625,691,664,871,656,625,563,332,500,332,305,305,
       305,453,500,465,500,473,254,473,500,242,242,492,242,703,500,500,
       500,500,367,414,352,500,477,602,469,477,453,242,219,242,500
       );

  // PMincyo widths array from CID 326
  PMINCYO_FONT_WIDTH_ARRAY2: array[0..63] of Integer = (
       500,441,441,441,441,441,547,523,445,480,469,516,523,504,438,500,
       641,617,566,625,598,637,563,652,539,621,523,664,590,637,645,555,
       527,602,602,602,461,645,598,578,648,492,637,516,547,613,641,605,
       453,660,508,609,664,641,520,559,512,656,566,559,590,563,250,230
       );

  // PMincyo widths array from CID 633
  PMINCYO_FONT_WIDTH_ARRAY3: array[0..62]of Integer = (
       664,664,664,664,664,500,500,500,1000,1000,500,500,500,500,500,500,
       1000,1000,648,801,652,703,1000,1000,1000,1000,1000,1000,1000,500,1000,1000,
       1000,1000,1000,1000,1000,500,500,500,500,500,500,500,500,500,500,500,
       500,500,500,500,500,500,500,500,500,500,500,1000,1000,1000,1000
       );

  // PMincyo widths array from CID 771
  PMINCYO_FONT_WIDTH_ARRAY4: array[0..7]of Integer = (
       1000,1000,1000,1000,1000,500,500,500
       );

  // PMincyo widths array from CID 780
  PMINCYO_FONT_WIDTH_ARRAY5: array[0..9]of Integer = (
       621,621,621,621,621,621,621,621,621,621
       );

  // PMincyo widths array from CID 790
  PMINCYO_FONT_WIDTH_ARRAY6: array[0..25]of Integer = (
       805,715,762,813,719,688,801,859,359,359,805,676,1000,836,832,680,
       832,727,688,719,855,770,977,730,777,656
       );

  // PMincyo widths array from CID 816
  PMINCYO_FONT_WIDTH_ARRAY7: array[0..25]of Integer = (
       531,574,531,574,543,387,559,613,293,293,570,293,875,613,574,574,
       574,414,469,422,613,543,781,574,563,500
       );

  // PMincyo widths array from CID 842
  PMINCYO_FONT_WIDTH_ARRAY8: array[0..82]of Integer = (
       754,883,750,953,508,617,703,898,801,1000,945,949,793,895,645,805,
       914,980,754,867,754,883,777,777,1000,1000,1000,1000,922,961,906,949,
       902,902,855,1000,1000,902,941,703,844,902,949,1000,1000,949,969,1000,
       1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,945,980,980,824,1000,1000,
       953,758,875,1000,836,934,688,785,766,641,793,984,863,801,953,945,
       984,855,945
       );

  // PMincyo widths array from CID 925
  PMINCYO_FONT_WIDTH_ARRAY9: array[0..62]of Integer = (
       750,891,668,777,707,801,805,941,809,941,879,926,887,902,746,883,
       883,934,793,863,953,961,902,902,820,902,930,949,754,855,785,910,
       965,945,734,848,922,902,1000,590,707,973,910,805,922,699,977,977,
       977,656,852,844,844,945,945,1000,1000,1000,883,922,922,930,609
       );

  // PMincyo widths array from CID 988
  PMINCYO_FONT_WIDTH_ARRAY10: array[0..22]of Integer = (
       863,676,941,789,926,793,941,598,703,766,609,980,832,785,699,805,
       965,961,785,863,883,695,766
       );

type
  TCharToCMap = function(S: string; Index: integer): integer;

  TPdfCIDWidthItem = class(TObject)
  private
    FStrCID: integer;
    FEndCID: integer;
    FWidth: Word;
  protected
    property StrCID: integer read FStrCID write FStrCID;
    property EndCID: integer read FEndCID write FEndCID;
    property Width: Word read FWidth write FWidth;
  end;

  TPdfType0Font = class(TPdfFont)
  private
    FCharToCMap: TCharToCMap;
    FArray: TList;
    FDW: Word;
    FMissingWidth: Word;
  protected
    function CidWidth(CID: integer): Word;
  public
    destructor Destroy; override;
    procedure SetData(AData: TPdfDictionary); override;
    procedure SetCharToCMap(AFunc: TCharToCMap); virtual;
    function GetCharWidth(AText: string; APos: integer): integer; override;
  end;

  TPdfJpFont = class(TPdfType0Font)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); virtual;
    procedure AddDescendantFontItem(ADescendantFont: TPdfDictionary); virtual;
    function GetFontName: string; virtual;
  public
    constructor Create(AXref: TPdfXref; AName: string); override;
  end;

  TPdfJpFixedFont = class(TPdfJpFont)
  protected
    procedure AddDescendantFontItem(ADescendantFont: TPdfDictionary); override;
  public
    constructor Create(AXref: TPdfXref; AName: string); override;
  end;

  TPdfGothic = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfGothicBold = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfGothicItalic = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfGothicBoldItalic = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfMincyo = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfMincyoBold = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfMincyoItalic = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfMincyoBoldItalic = class(TPdfJpFixedFont)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfJpProportionalFont = class(TPdfJpFont)
  public
    constructor Create(AXref: TPdfXref; AName: string); override;
  end;

  TPdfPGothic = class(TPdfJpProportionalFont)
  protected
    procedure AddDescendantFontItem(ADescendantFont: TPdfDictionary); override;
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPGothicBold = class(TPdfPGothic)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPGothicItalic = class(TPdfPGothic)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPGothicBoldItalic = class(TPdfPGothic)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPMincyo = class(TPdfJpProportionalFont)
  protected
    procedure AddDescendantFontItem(ADescendantFont: TPdfDictionary); override;
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPMincyoBold = class(TPdfPMincyo)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPMincyoItalic = class(TPdfPMincyo)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

  TPdfPMincyoBoldItalic = class(TPdfPMincyo)
  protected
    procedure AddDescriptorItem(AFontDescriptor: TPdfDictionary); override;
    function GetFontName: string; override;
  end;

implementation

uses

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -