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

📄 flatcode.pas

📁 comerose_flatstyle_v4.42.9.0_d7.rar
💻 PAS
📖 第 1 页 / 共 4 页
字号:
unit FlatCode;

interface

uses windows, Messages, SysUtils, Classes, Graphics, Controls, FlatUtils;

type
  TFlatLines     = (ltWhite,ltBlack, ltblack_half);
  //定义条形码类型
  TFlatColeType  =(Code25IL, Code25IT, Code25Mx, Code39,
                   Code39Ext, Code128A, Code128B, Code128C,
                   Code93, Code93Ext, CodeMSI, PostNet, Codabar,
                   EAN8, EAN13, EAN128A, EAN128B, EAN128C,
                   UPC_A, UPC_EODD, UPC_EVEN, UPC_S2, UPC_S5);
  TFlatRotation =(raNone,ra090,ra180,ra270);


  TFlatModules = array[0..3] of ShortInt;
  { TFlatBarcode }
  TFlatBarcode = class(TVersionControl)
   private
    fText           : string;
    FModul          : integer;
    FRatio          : double;
    FCodeType       : TFlatColeType;
    FRotateType     : TFlatRotation;
    fBarHeight      : Integer;
    fBorderWidth    : Byte;
    fBarColor       : TColor;
    fBarTop         : Byte;

    fTypName        : String;
    fColor          : TColor;
    FShowText       : boolean;
    FCheckSum       : boolean;
    fCheckOdd       : Boolean;
    fTransparent    : boolean;
    fAutoSize       : Boolean;
    procedure SetModul(const Value:Integer);
    procedure SetRotateType(const Value: TFlatRotation);
    procedure SetRatio(const Value: double);
    procedure SetCodeType(const Value: TFlatColeType);
    procedure SetText(const Value: string);
    procedure SetBarHeight(const Value: Integer);
    procedure SetBorderWidth(const Value: Byte);
    procedure SetBarColor(const Value: TColor);
    procedure SetBarTop(const Value: Byte);
    procedure SetColor(const Value: TColor);
    procedure FontChange(sender : TObject);
    procedure SetBools(Index: Integer; Value: Boolean);
   protected
    fBitmap: TBitmap;
    function Code_25ILeaved  : string;
    function Code_25ITrial   : string;
    function Code_25Matrix   : string;
    function Code_39         : string;
    function Code_128        : string;
    function Code_93         : string;
    function Code_MSI        : string;
    function Code_PostNet    : string;
    function Code_CodaBar    : string;
    function Code_EAN8       : string;
    function Code_EAN13      : string;
    function Code_UPC_A      : string;
    function Code_UPC_EODD   : string;
    function Code_UPC_EVEN   : string;
    function Code_Supp5      : string;
    function Code_Supp2      : string;
    Function MakeData        : string;
    function MakeBarText     : String;
    function GetTypName      : String;
    function GetProLine      : Integer;
    function DoCheckSumming(const Data: string;OddCheck:Boolean=True): string;
    function GetCheckLen(CodeType: TFlatColeType; Data: String): String;
    function SetLen(pI:byte): string;
    function ClearNotText(Value: String): String;
    function MakeModules : TFlatModules;

    procedure DrawBarcode;
    procedure OneBarProps(Data: Char; var Width: Integer; var lt: TFlatLines);
    procedure GetABCED(var a, b, c, d, orgin: TPoint; xadd, Width, Height: Integer);
    procedure DrawEAN13Text(Canvas: TCanvas; width,wBorder: Integer);
    procedure DrawEAN8Text(Canvas: TCanvas; width, wBorder: Integer);
    procedure DrawUPC_AText(Canvas: TCanvas; width, wBorder: Integer);
    procedure DrawUPC_EText(Canvas: TCanvas; width, wBorder: Integer);
    property Data      : String read MakeData;
    property BarText   : String read MakeBarText;
    property Modules   : TFlatModules read MakeModules;
    property ProLine   : Integer read GetProLine;
    procedure Paint; override;
    procedure WMSize (var Message: TWMSize); message WM_SIZE;
   public
    constructor Create(Owner:TComponent); override;
    destructor destroy;override;
    property Bitmap: TBitmap read fBitmap;
   published
    property BarCode: String  read GetTypName write fTypName;
    property Rotate: TFlatRotation read FRotateType write SetRotateType;
    property Modul: Integer read fModul write SetModul;
    property Ratio: double read fRatio write SetRatio;
    property CodeType: TFlatColeType read FCodeType write SetCodeType default EAN13;
    property Text: string  read fText write SetText;
    property LineHeight: Integer read fBarHeight write SetBarHeight;
    property BorderWidth: Byte read fBorderWidth write SetBorderWidth;
    property LineTop: Byte read fBarTop write SetBarTop;
    property Color: TColor read FColor write SetColor default clWhite;
    property LineColor: TColor read fBarColor write SetBarColor default clBlack;
    property AutoSize: Boolean index 0 read fAutoSize write SetBools default True;
    property Checksum: boolean index 1 read FCheckSum write SetBools default FALSE;
    property CheckOdd: Boolean index 2 read fCheckOdd write SetBools default true;
    property ShowText: boolean index 3 read FShowText write SetBools default True;
    property Transparent: boolean index 4 read fTransparent write SetBools default false;
    property ShowHint;
    property ParentFont;
    property Font;
    property Height;
    property Width;
    property Top;
    property Left;
    property OnClick;
    property OnDblClick;
    property OnMouseMove;
    property OnMouseDown;
    property OnMouseUp;
    property OnKeyDown;
    property OnKeyPress;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyUp;
    property OnStartDock;
    property OnStartDrag;
  end;

implementation

type
  TCode93 = record
     c : char;
     data : array[0..5] of char;
  end;

  TCode39 = record
     c : char;
     data : array[0..9] of char;
     chk: shortint;
  end;

  TCode128 = record
     a, b : char;
     c : string[2];
     data : string[6];
  end;

  TCodabar = record
     c : char;
     data : array[0..6] of char;
  end;

  TBCData = record
     Name:string;        { Name of Barcode }
     num :Boolean;       { numeric data only }
  end;

const
  StartA       = '211412';
  StartB       = '211214';
  StartC       = '211232';
  Stop         = '2331112';
  {Pattern for Barcode EAN Charset A} {L1   S1   L2   S2}
  BARCode_EAN_A:array['0'..'9'] of string =
              (('2605'), { 0 } ('1615'), { 1 }
               ('1516'), { 2 } ('0805'), { 3 }
               ('0526'), { 4 } ('0625'), { 5 }
               ('0508'), { 6 } ('0706'), { 7 }
               ('0607'), { 8 } ('2506'));{ 9 }
  BARCode_EAN_B:array['0'..'9'] of string =
              (('0517'), { 0 } ('0616'), { 1 }
               ('1606'), { 2 } ('0535'), { 3 }
               ('1705'), { 4 } ('0715'), { 5 }
               ('3505'), { 6 } ('1525'), { 7 }
               ('2515'), { 8 } ('1507'));{ 9 }
{Pattern for Barcode EAN Charset C}		 {S1   L1   S2   L2}
  BARCode_EAN_C:array['0'..'9'] of string =
              (('7150' ), { 0 }('6160' ), { 1 }
               ('6061' ), { 2 }('5350' ), { 3 }
               ('5071' ), { 4 }('5170' ), { 5 }
               ('5053' ), { 6 }('5251' ), { 7 }
               ('5152' ), { 8 }('7051' ));{ 9 }
  BARCode_ParityEAN13:array[0..9, 1..6] of char =
              (('A', 'A', 'A', 'A', 'A', 'A'), { 0 }
               ('A', 'A', 'B', 'A', 'B', 'B'), { 1 }
               ('A', 'A', 'B', 'B', 'A', 'B'), { 2 }
               ('A', 'A', 'B', 'B', 'B', 'A'), { 3 }
               ('A', 'B', 'A', 'A', 'B', 'B'), { 4 }
               ('A', 'B', 'B', 'A', 'A', 'B'), { 5 }
               ('A', 'B', 'B', 'B', 'A', 'A'), { 6 }
               ('A', 'B', 'A', 'B', 'A', 'B'), { 7 }
               ('A', 'B', 'A', 'B', 'B', 'A'), { 8 }
               ('A', 'B', 'B', 'A', 'B', 'A'));  { 9 }
  BARCode_UPC_E:array['0'..'9', 1..6] of char =
              (('E', 'E', 'E', 'O', 'O', 'O' ), { 0 }
               ('E', 'E', 'O', 'E', 'O', 'O' ), { 1 }
               ('E', 'E', 'O', 'O', 'E', 'O' ), { 2 }
               ('E', 'E', 'O', 'O', 'O', 'E' ), { 3 }
               ('E', 'O', 'E', 'E', 'O', 'O' ), { 4 }
               ('E', 'O', 'O', 'E', 'E', 'O' ), { 5 }
               ('E', 'O', 'O', 'O', 'E', 'E' ), { 6 }
               ('E', 'O', 'E', 'O', 'E', 'O' ), { 7 }
               ('E', 'O', 'E', 'O', 'O', 'E' ), { 8 }
               ('E', 'O', 'O', 'E', 'O', 'E' ));  { 9 }
  BARCode_PostNet:array['0'..'9'] of string[10] =
              (('5151A1A1A1'),{0}
               ('A1A1A15151'),{1}
               ('A1A151A151'),{2}
               ('A1A15151A1'),{3}
               ('A151A1A151'),{4}
               ('A151A151A1'),{5}
               ('A15151A1A1'),{6}
               ('51A1A1A151'),{7}
               ('51A1A151A1'),{8}
               ('51A151A1A1'));   {9}
  BARCode_MSI:array['0'..'9'] of string[8] =
              (('51515151'),{0}
               ('51515160'),{1}
               ('51516051'),{2}
               ('51516060'),{3}
               ('51605151'),{4}
               ('51605160'),{5}
               ('51606051'),{6}
               ('51606060'),{7}
               ('60515151'),{8}
               ('60515160'));{9}
  BARCode_25:array['0'..'9', 1..5] of char =
              (('0', '0', '1', '1', '0'),    // 0
               ('1', '0', '0', '0', '1'),    // 1
               ('0', '1', '0', '0', '1'),    // 2
               ('1', '1', '0', '0', '0'),    // 3
               ('0', '0', '1', '0', '1'),    // 4
               ('1', '0', '1', '0', '0'),    // 5
               ('0', '1', '1', '0', '0'),    // 6
               ('0', '0', '0', '1', '1'),    // 7
               ('1', '0', '0', '1', '0'),    // 8
               ('0', '1', '0', '1', '0'));   // 9
  BARCode_Codabar: array[0..19] of TCodabar =
              ((c:'1'; data:'5050615'),
               (c:'2'; data:'5051506'),
               (c:'3'; data:'6150505'),
               (c:'4'; data:'5060515'),
               (c:'5'; data:'6050515'),
               (c:'6'; data:'5150506'),
               (c:'7'; data:'5150605'),
               (c:'8'; data:'5160505'),
               (c:'9'; data:'6051505'),
               (c:'0'; data:'5050516'),
               (c:'-'; data:'5051605'),
               (c:'$'; data:'5061505'),
               (c:':'; data:'6050606'),
               (c:'/'; data:'6060506'),
               (c:'.'; data:'6060605'),
               (c:'+'; data:'5060606'),
               (c:'A'; data:'5061515'),
               (c:'B'; data:'5151506'), //'5151506'  '5061515'
               (c:'C'; data:'5051516'),
               (c:'D'; data:'5051615'));
  BARCode_39x : array[0..127] of string[2] =
              (('%U'), ('$A'), ('$B'), ('$C'), ('$D'), ('$E'), ('$F'), ('$G'),
               ('$H'), ('$I'), ('$J'), ('$K'), ('$L'), ('$M'), ('$N'), ('$O'),
               ('$P'), ('$Q'), ('$R'), ('$S'), ('$T'), ('$U'), ('$V'), ('$W'),
               ('$X'), ('$Y'), ('$Z'), ('%A'), ('%B'), ('%C'), ('%D'), ('%E'),
               (' ' ), ('/A'), ('/B'), ('/C'), ('/D'), ('/E'), ('/F'), ('/G'),
               ('/H'), ('/I'), ('/J'), ('/K'), ('/L'), ('/M'), ('/N'), ('/O'),
               ('0' ), ('1' ), ('2' ), ('3' ), ('4' ), ('5' ), ('6' ), ('7' ),
               ('8' ), ('9' ), ('/Z'), ('%F'), ('%G'), ('%H'), ('%I'), ('%J'),
               ('%V'), ('A' ), ('B' ), ('C' ), ('D' ), ('E' ), ('F' ), ('G' ),
               ('H' ), ('I' ), ('J' ), ('K' ), ('L' ), ('M' ), ('N' ), ('O' ),
               ('P' ), ('Q' ), ('R' ), ('S' ), ('T' ), ('U' ), ('V' ), ('W' ),
               ('X' ), ('Y' ), ('Z' ), ('%K'), ('%L'), ('%M'), ('%N'), ('%O'),
               ('%W'), ('+A'), ('+B'), ('+C'), ('+D'), ('+E'), ('+F'), ('+G'),
               ('+H'), ('+I'), ('+J'), ('+K'), ('+L'), ('+M'), ('+N'), ('+O'),
               ('+P'), ('+Q'), ('+R'), ('+S'), ('+T'), ('+U'), ('+V'), ('+W'),
               ('+X'), ('+Y'), ('+Z'), ('%P'), ('%Q'), ('%R'), ('%S'), ('%T'));
  BARCode_93x : array[0..127] of string[2] =
	            ((']U'), ('[A'), ('[B'), ('[C'), ('[D'), ('[E'), ('[F'), ('[G'),
               ('[H'), ('[I'), ('[J'), ('[K'), ('[L'), ('[M'), ('[N'), ('[O'),
               ('[P'), ('[Q'), ('[R'), ('[S'), ('[T'), ('[U'), ('[V'), ('[W'),
               ('[X'), ('[Y'), ('[Z'), (']A'), (']B'), (']C'), (']D'), (']E'),
               (' ' ), ('{A'), ('{B'), ('{C'), ('{D'), ('{E'), ('{F'), ('{G'),
               ('{H'), ('{I'), ('{J'), ('{K'), ('{L'), ('{M'), ('{N'), ('{O'),
               ('0' ), ('1' ), ('2' ), ('3' ), ('4' ), ('5' ), ('6' ), ('7' ),
               ('8' ), ('9' ), ('{Z'), (']F'), (']G'), (']H'), (']I'), (']J'),
               (']V'), ('A' ), ('B' ), ('C' ), ('D' ), ('E' ), ('F' ), ('G' ),
               ('H' ), ('I' ), ('J' ), ('K' ), ('L' ), ('M' ), ('N' ), ('O' ),
               ('P' ), ('Q' ), ('R' ), ('S' ), ('T' ), ('U' ), ('V' ), ('W' ),
               ('X' ), ('Y' ), ('Z' ), (']K'), (']L'), (']M'), (']N'), (']O'),
               (']W'), ('}A'), ('}B'), ('}C'), ('}D'), ('}E'), ('}F'), ('}G'),
               ('}H'), ('}I'), ('}J'), ('}K'), ('}L'), ('}M'), ('}N'), ('}O'),
               ('}P'), ('}Q'), ('}R'), ('}S'), ('}T'), ('}U'), ('}V'), ('}W'),
               ('}X'), ('}Y'), ('}Z'), (']P'), (']Q'), (']R'), (']S'), (']T'));
  BARCode_93: array[0..46] of TCode93 =
              ((c:'0'; data:'131112'),
               (c:'1'; data:'111213'),
               (c:'2'; data:'111312'),
               (c:'3'; data:'111411'),
               (c:'4'; data:'121113'),
               (c:'5'; data:'121212'),
               (c:'6'; data:'121311'),
               (c:'7'; data:'111114'),
               (c:'8'; data:'131211'),
               (c:'9'; data:'141111'),
               (c:'A'; data:'211113'),
               (c:'B'; data:'211212'),
               (c:'C'; data:'211311'),
               (c:'D'; data:'221112'),
               (c:'E'; data:'221211'),
               (c:'F'; data:'231111'),
               (c:'G'; data:'112113'),
               (c:'H'; data:'112212'),
               (c:'I'; data:'112311'),
               (c:'J'; data:'122112'),
               (c:'K'; data:'132111'),
               (c:'L'; data:'111123'),
               (c:'M'; data:'111222'),
               (c:'N'; data:'111321'),
               (c:'O'; data:'121122'),
               (c:'P'; data:'131121'),
               (c:'Q'; data:'212112'),
               (c:'R'; data:'212211'),
               (c:'S'; data:'211122'),
               (c:'T'; data:'211221'),
               (c:'U'; data:'221121'),
               (c:'V'; data:'222111'),
               (c:'W'; data:'112122'),
               (c:'X'; data:'112221'),
               (c:'Y'; data:'122121'),
               (c:'Z'; data:'123111'),
               (c:'-'; data:'121131'),
               (c:'.'; data:'311112'),
               (c:' '; data:'311211'),
               (c:'$'; data:'321111'),
               (c:'/'; data:'112131'),
               (c:'+'; data:'113121'),
               (c:'%'; data:'211131'),
               (c:'['; data:'121221'),   // only used for Extended Code 93
               (c:']'; data:'312111'),   // only used for Extended Code 93
               (c:'{'; data:'311121'),   // only used for Extended Code 93
               (c:'}'; data:'122211'));  // only used for Extended Code 93
  BARCode_39: array[0..43] of TCode39 =
              ((c:'0'; data:'505160605'; chk:0 ),
               (c:'1'; data:'605150506'; chk:1 ),
               (c:'2'; data:'506150506'; chk:2 ),
               (c:'3'; data:'606150505'; chk:3 ),
               (c:'4'; data:'505160506'; chk:4 ),
               (c:'5'; data:'605160505'; chk:5 ),
               (c:'6'; data:'506160505'; chk:6 ),
               (c:'7'; data:'505150606'; chk:7 ),
               (c:'8'; data:'605150605'; chk:8 ),
               (c:'9'; data:'506150605'; chk:9 ),
               (c:'A'; data:'605051506'; chk:10),
               (c:'B'; data:'506051506'; chk:11),
               (c:'C'; data:'606051505'; chk:12),
               (c:'D'; data:'505061506'; chk:13),
               (c:'E'; data:'605061505'; chk:14),
               (c:'F'; data:'506061505'; chk:15),
               (c:'G'; data:'505051606'; chk:16),
               (c:'H'; data:'605051605'; chk:17),
               (c:'I'; data:'506051600'; chk:18),
               (c:'J'; data:'505061605'; chk:19),
               (c:'K'; data:'605050516'; chk:20),
               (c:'L'; data:'506050516'; chk:21),
               (c:'M'; data:'606050515'; chk:22),
               (c:'N'; data:'505060516'; chk:23),
               (c:'O'; data:'605060515'; chk:24),
               (c:'P'; data:'506060515'; chk:25),
               (c:'Q'; data:'505050616'; chk:26),
               (c:'R'; data:'605050615'; chk:27),
               (c:'S'; data:'506050615'; chk:28),
               (c:'T'; data:'505060615'; chk:29),
               (c:'U'; data:'615050506'; chk:30),
               (c:'V'; data:'516050506'; chk:31),
               (c:'W'; data:'616050505'; chk:32),
               (c:'X'; data:'515060506'; chk:33),
               (c:'Y'; data:'615060505'; chk:34),
               (c:'Z'; data:'516060505'; chk:35),
               (c:'-'; data:'515050606'; chk:36),
               (c:'.'; data:'615050605'; chk:37),
               (c:' '; data:'516050605'; chk:38),
               (c:'*'; data:'515060605'; chk:0 ),
               (c:'$'; data:'515151505'; chk:39),
               (c:'/'; data:'515150515'; chk:40),
               (c:'+'; data:'515051515'; chk:41),
               (c:'%'; data:'505151515'; chk:42));
  BARCode_128: array[0..102] of TCode128 =
              ((a:' '; b:' '; c:'00'; data:'212222'; ),
               (a:'!'; b:'!'; c:'01'; data:'222122'; ),
               (a:'"'; b:'"'; c:'02'; data:'222221'; ),
               (a:'#'; b:'#'; c:'03'; data:'121223'; ),
               (a:'$'; b:'$'; c:'04'; data:'121322'; ),
               (a:'%'; b:'%'; c:'05'; data:'131222'; ),
               (a:'&'; b:'&'; c:'06'; data:'122213'; ),
               (a:'''';b:'''';c:'07'; data:'122312'; ),
               (a:'('; b:'('; c:'08'; data:'132212'; ),
               (a:')'; b:')'; c:'09'; data:'221213'; ),
               (a:'*'; b:'*'; c:'10'; data:'221312'; ),
               (a:'+'; b:'+'; c:'11'; data:'231212'; ),
               (a:'?'; b:'?'; c:'12'; data:'112232'; ),
               (a:'-'; b:'-'; c:'13'; data:'122132'; ),
               (a:'.'; b:'.'; c:'14'; data:'122231'; ),
               (a:'/'; b:'/'; c:'15'; data:'113222'; ),
               (a:'0'; b:'0'; c:'16'; data:'123122'; ),
               (a:'1'; b:'1'; c:'17'; data:'123221'; ),
               (a:'2'; b:'2'; c:'18'; data:'223211'; ),
               (a:'3'; b:'3'; c:'19'; data:'221132'; ),
               (a:'4'; b:'4'; c:'20'; data:'221231'; ),

⌨️ 快捷键说明

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