pcode39用postscript实现的代码(抄的)

%! PS-Adobe-2.1
% Bar39 Version 1.0 6/25/95 by Marty Chandler

% This file defines a code 3 of 9 postscript barcode font and is designed to
% be added as a prologue to PostScript file which requires this font.

% For this font the unit of measurement is one narrow bar.

% The ratio of the wide bar to a narrow bar has been set at 3:1; this
% follows the preferred wide-to-narrow ratio recommended in
% MIL-STD-1189B (MILITARY STANDARD, STANDARD DEPARTMENT OF DEFENSE BARCODE
% SYMBOLOGY, DODSTS Issue 95-02).  The intercharacter gap has been set to
% one unit following paragraph 5.2.2 of MIL-STD-1189B. 
% The dimensions of each character are therefore:
%               length: 15 units (3*3+6)
%               height: 50 units

% This font has been developed by analogy with the example given on page 107 of
% the third printing of "PostScript Language Reference Manual" published by
% Adobe Systems Incorporated in May of 1988. 

% start font definition
/bar39 10 dict def
bar39 begin

   /FontType 3 def                           % required elements

% In the implementation the intercharacter gap has been added to the
% definition of a character, this extended character has a length of 16
% units.  Because of this a width of 16 has been used in setting up the
% font.

   /FontMatrix [.06250 0 0 .0625 0 0] def
   /FontBBox [0 0 16 50] def

% The 3 of 9 barcode character set (0-9,A-Z,-,.,$,/,+,% and space) and
% the start and stop delimiter (*) is encoded here.

   /Encoding 256 array def                       % encoding vector
   0 1 255 {Encoding exch /.notdef put} for

        Encoding 32 /space put
        Encoding 36 /dollar put
        Encoding 37 /percent put
        Encoding 42 /asterix put
        Encoding 43 /plus put
        Encoding 45 /dash put
        Encoding 46 /period put
        Encoding 47 /slash put

        Encoding 48 /0 put
        Encoding 49 /1 put
        Encoding 50 /2 put
        Encoding 51 /3 put
        Encoding 52 /4 put
        Encoding 53 /5 put
        Encoding 54 /6 put
        Encoding 55 /7 put
        Encoding 56 /8 put
        Encoding 57 /9 put

        Encoding 65 /A put % ascii 'A'=65
        Encoding 66 /B put
        Encoding 67 /C put
        Encoding 68 /D put
        Encoding 69 /E put
        Encoding 70 /F put
        Encoding 71 /G put
        Encoding 72 /H put
        Encoding 73 /I put
        Encoding 74 /J put
        Encoding 75 /K put
        Encoding 76 /L put
        Encoding 77 /M put
        Encoding 78 /N put
        Encoding 79 /O put
        Encoding 80 /P put
        Encoding 81 /Q put
        Encoding 82 /R put
        Encoding 83 /S put
        Encoding 84 /T put
        Encoding 85 /U put
        Encoding 86 /V put
        Encoding 87 /W put
        Encoding 88 /X put
        Encoding 89 /Y put
        Encoding 90 /Z put

% dir for char defs
/CharProcs 3 dict def
CharProcs begin
        /.notdef {} def

% This defines the procedures to be used in drawing each bar code
% character.  bc is the procedure which actually draws the barcode
% character, Its arguements consist the bars and spaces notation
% presented in table 1 of MIL-STD-1189B.  Note that the spaces notation
% has modified to include a fifth element in the array which represents
% the intercharacter gap.

        /space   {[0 1 0 1 0] [1 0 0 0 0] bc } def
        /dollar  {[0 0 0 0 0] [1 1 1 0 0] bc } def
        /percent {[0 0 0 0 0] [0 1 1 1 0] bc } def
        /asterix {[0 0 1 1 0] [1 0 0 0 0] bc } def
        /plus    {[0 0 0 0 0] [1 0 1 1 0] bc } def
        /dash    {[0 0 0 1 1] [1 0 0 0 0] bc } def
        /period  {[1 0 0 1 0] [1 0 0 0 0] bc } def
        /slash   {[0 0 0 0 0] [1 1 0 1 0] bc } def

        /0 {[0 0 1 1 0] [0 1 0 0 0] bc } def
        /1 {[1 0 0 0 1] [0 1 0 0 0] bc } def
        /2 {[0 1 0 0 1] [0 1 0 0 0] bc } def
        /3 {[1 1 0 0 1] [0 1 0 0 0] bc } def
        /4 {[0 0 1 0 1] [0 1 0 0 0] bc } def
        /5 {[1 0 1 0 0] [0 1 0 0 0] bc } def
        /6 {[0 1 1 0 0] [0 1 0 0 0] bc } def
        /7 {[0 0 0 1 1] [0 1 0 0 0] bc } def
        /8 {[1 0 0 1 0] [0 1 0 0 0] bc } def
        /9 {[0 1 0 1 0] [0 1 0 0 0] bc } def

        /A {[1 0 0 0 1] [0 0 1 0 0] bc } def            % ascii 'A'=65
        /B {[0 1 0 0 1] [0 0 1 0 0] bc } def
        /C {[1 1 0 0 0] [0 0 1 0 0] bc } def
        /D {[0 0 1 0 1] [0 0 1 0 0] bc } def
        /E {[1 0 1 0 0] [0 0 1 0 0] bc } def
        /F {[0 1 1 0 0] [0 0 1 0 0] bc } def
        /G {[0 0 0 1 1] [0 0 1 0 0] bc } def
        /H {[1 0 0 1 0] [0 0 1 0 0] bc } def
        /I {[0 1 0 1 0] [0 0 1 0 0] bc } def
        /J {[0 0 1 1 0] [0 0 1 0 0] bc } def
        /K {[1 0 0 0 1] [0 0 0 1 0] bc } def
        /L {[0 1 0 0 1] [0 0 0 1 0] bc } def
        /M {[1 1 0 0 0] [0 0 0 1 0] bc } def
        /N {[0 0 1 0 1] [0 0 0 1 0] bc } def
        /O {[1 0 1 0 0] [0 0 0 1 0] bc } def
        /P {[0 1 1 0 0] [0 0 0 1 0] bc } def
        /Q {[0 0 0 1 1] [0 0 0 1 0] bc } def
        /R {[1 0 0 1 0] [0 0 0 1 0] bc } def
        /S {[0 1 0 1 0] [0 0 0 1 0] bc } def
        /T {[0 0 1 1 0] [0 0 0 1 0] bc } def
        /U {[1 0 0 0 1] [1 0 0 0 0] bc } def
        /V {[0 1 0 0 1] [1 0 0 0 0] bc } def
        /W {[1 1 0 0 0] [1 0 0 0 0] bc } def
        /X {[0 0 1 0 1] [1 0 0 0 0] bc } def
        /Y {[1 0 1 0 0] [1 0 0 0 0] bc } def
        /Z {[0 1 1 0 0] [1 0 0 0 0] bc } def
end

/BuildChar {                                    % stack has font char

        /n 3.0 def                              % wide to narrow ratio
        /xw 1.0 def                             % nominal narrow width
        /aspect 50 def                          % aspect ratio
        /ig 1.0 def                             % inter character gap
        /x 0 def                                % initial x
        /y 0 def                                % initial y
        /ib 0 def                               % bar index
       
% Procedure to calculate width of bar or space, given that its code is
% at the top of the stack.  This procedure assumes a 3:1 wide to narrow
% ratio.
 
        /wid {
                2 mul 1 add
        } def

% This procedure simply draws a bar.

        /dbar {
                        newpath
                        x y moveto
                        x aspect y add lineto
                        x bwidth add aspect y add lineto
                        x bwidth add y lineto
                        closepath
                        fill
         } def         

% This procedure processes the bars array, keeps track of the x
% coordinates of the bars and spaces and calls dbar to draw them.

        /bc {
                /spaces exch def                % spaces array
                /bars exch def                  % bars array
                bars {
                        wid  /bwidth exch def   % calculate bar width
                        dbar
                        /x x bwidth add def
                        ib 5 lt {
                                spaces ib get wid /x exch x add def
                        } if
                        /ib ib 1 add def
       
                } forall

        } def                                   % barcode routine

        16 0                                    % width
        0 0 16 50                               % bounding box
        setcachedevice                         
        exch begin                              % font begin
        Encoding exch get                       % index by char in Encoding
        CharProcs exch get                      % lookup name in CharProcs
        end
        exec                                    % execute char procdure
} def
end                                             % of bar39

/Bar39 bar39 definefont pop

% ******************************************************************
% Example of use of Bar39 font
% ******************************************************************
%
% Note the makefont procedure can be used in place of scalefont to alter
% the aspect ratio (ratio of font height to narrow bar) as follows:
%
%            /Bar39 findfont [SX 0 0 SY 0 0] makefont setfont
%
% where SX and SY are horizontal and verical scale factors.
%

/Bar39 findfont 60 scalefont setfont

74 240 moveto (*ABC*) show
/Times-Bold findfont 60 scalefont setfont
74 500 moveto (*ABC*) show
showpage

你可能感兴趣的:(vector,character,reference,encoding,printing,postscript)