dxfedit/03_Python_OpenSource_DXF/fonts/ACADPSF.PS
puzzlesion 5e87bd7c33 refactor(dxf): optimize table drawing and add diagnostic scripts
This commit includes several updates to the Python_OpenSource_DXF project:

- The core script draw_table_from_template.py has been refactored for better logic and clarity.

- New utility scripts such as diagnose_blocks.py, export_dxf.py, and plot_by_block_name.py have been added to enhance diagnostic and plotting capabilities.

- The convert_dxf_to_pdf.py script was removed as its functionality is now covered by other modules.

- README.md and .specstory documentation have been updated to reflect these changes.
2025-09-12 17:21:08 +08:00

276 lines
11 KiB
PostScript

% Copyright (C) 1990, 1991 Aladdin Enterprises. All rights reserved.
% Distributed by Free Software Foundation, Inc.
%
% This file is part of Ghostscript.
%
% Ghostscript is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
% to anyone for the consequences of using it or for whether it serves any
% particular purpose or works at all, unless he says so in writing. Refer
% to the Ghostscript General Public License for full details.
%
% Everyone is granted permission to copy, modify and redistribute
% Ghostscript, but only under the conditions described in the Ghostscript
% General Public License. A copy of this license is supposed to have been
% given to you along with Ghostscript so you can know your rights and
% responsibilities. It should be in a file named COPYING. Among other
% things, the copyright notice and this notice must be preserved on all
% copies.
% Font initialization for Ghostscript. Despite anything claimed below,
% Ghostscript fonts are actually in the same format as Adobe Type 1 fonts,
% except that the external form customarily does not use eexec encryption.
% Someday there will be GNU documentation that describes this format.
% Until then, you'll have to either get a copy of Adobe's book, or read
% the Ghostscript code. The interpreter for Type 1 fonts, which reveals
% most of their structure, is in the file gstype1.c.
%
% ***********************************************************************
% * *
% * M M OOO DDDD III FFFFF III EEEEE DDDD *
% * MM MM O O D D I F I E D D *
% * M M M O O D D I F I E D D *
% * M M O O D D I FFF I EEE D D *
% * M M O O D D I F I E D D *
% * M M O O D D I F I E D D *
% * M M OOO DDDD III F III EEEEE DDDD *
% * *
% * *
% * FFFFF III L EEEEE *
% * F I L E *
% * F I L E *
% * FFF I L EEE *
% * F I L E *
% * F I L E *
% * F III LLLLL EEEEE *
% * *
% ***********************************************************************
%
% .-------------.
% | /\ |
% | / \ |
% | / /\ \ |
% | / / \ \ |
% | / / /\ \ \ |
% | / / / \ \ \|
% `-------------' (R)
% Autodesk, Inc.
% Tools For the Golden Age of Engineering
%
% In keeping with subparagraph 2a of the Gnu General Public License
% (Version 1, February 1989):
%
% 2. You may modify your copy or copies of the Program or any
% portion of it, and copy and distribute such modifications under
% the terms of Paragraph 1 above, provided that you also do the
% following:
%
% a) cause the modified files to carry prominent notices stating
% that you changed the files and the date of any change; and...
%
% the following is a summary of the changes to this file made by
% Autodesk, Inc. in August 1991 in order to adapt Ghostscript to run
% as an ADS application and thereby to perform rendering of
% PostScript files within AutoCAD.
%
% ACADPSF.PS Ghostscript font loading procedures. Called
% GS_FONTS.PS in standard Ghostscript.
%
% Added handling for various strange characteristics of
% fonts encountered in the real world.
%
% Added exception handling when fontmap.ps has an incorrect
% entry, to prevent infinite recursion.
% ************************************************************************
% Define the default font.
/defaultfontname /Ugly def
% Internal procedure to load the font name -> font file name map
% if it isn't loaded already, and push it on the stack.
/Fontmap
{ /FontFileMap where
{ /FontFileMap get }
{ (fontmap.ps) findlibfile not
{ (Can't find ) print print (!\n) print stop }
if
FontDirectory maxlength dict exch
2 dict begin
mark exch 2 index exch
/;
{ % The stack contains a mark, the dictionary, the font name,
% the file name, and additional information about the font.
counttomark 3 sub { pop } repeat put
1 index
} bind def
run
end
pop pop % pop the mark and the copy of the dictionary
userdict exch /FontFileMap exch put
FontFileMap
}
ifelse
} bind def
% Define definefont. This is a procedure built on an operator that
% does all the error checking and key insertion.
/definefont
{ 1 dict begin count /d exch def % save stack depth in case of error
{ .buildfont readonly } stopped
{ count d sub { pop } repeat end /invalidfont signalerror }
{ end dup FontDirectory 4 2 roll put }
ifelse
} odef
/GnernDict 1 dict def
% Define findfont so it tries to load a font if it's not found.
/findfont
{
% If the key is a string, convert it to a name for lookup.
dup type /stringtype eq { cvn } if
% If the font isn't in FontDirectory already, load it.
dup FontDirectory exch known
{ FontDirectory exch get
}
{ dup % save the font name on the stack
% Push the font name -> font file name map on the stack,
% loading it if necessary.
Fontmap
% Read the file name from the map.
% (The stack contains the font name and the font file map.)
1 index known not
{ QUIET not
{ (Substituting ) print defaultfontname cvx =only
( for unknown font ) print == flush
} { pop } ifelse
pop defaultfontname findfont
}
{ FontFileMap exch get
% If we can't find the file, substitute for the font.
dup findlibfile
% save the filename here; we'll need it if the load fails.
2 index /savedfilename exch def
{ QUIET not
{ (Loading font file ) print exch print (... ) print flush }
{ exch pop }
ifelse
%
% Discard trash before PostScript sentinel
%
% Fonts that come with Adobe Type Manager have some
% trash binary bytes before the "%!" sentinel. Walk
% through the file and make sure we start reading at
% the sentinel.
%
{ dup read
{ 37 eq { dup read { 33 eq
{ dup dup fileposition 2 sub setfileposition exit }
{ unread } } { exit} ifelse
ifelse } if }
{ exit } ifelse
} loop
%
% End discarding of trash before PostScript sentinel
%
% Now it's time for some more adhocracy, another
% indulgence in Kelvinist predestination. It turns out
% that the various fonts we've accreted over the years
% obey no coherent conventions for what they leave or don't
% leave on the stack and some, based on the Adobe Type 1
% encryption decoder, even leave marks on the stack. To
% guarantee that we emerge from the font code with the
% stack in a valid state, we save the stack depth in a
% variable then programmatically pop any trash off the
% stack when we're done. This is ugly, but it works
% with every font I've tried.
count GnernDict begin /GnernK exch def end
mark exch
systemdict begin run end % run can take a file
cleartomark
% Now for the actial dirty work to put the stack back
% the way it was before we loaded the font.
GnernDict begin
{ count GnernK lt { exit } if pop} loop
end
QUIET not
{ vmstatus 3 { =only ( ) print } repeat
(done.\n) print flush
} if
% OK, make sure the thing has really been loaded.
dup FontDirectory exch known not
{
% Oops.
(The font ) print =only
( is not really in the file ) print
savedfilename =only
(\n) print flush
defaultfontname
} if
findfont
}
{ pop 1 index defaultfontname eq
{ (Can't find default font!\n) print
pop pop NullFont
}
{ (Can't find font file ) print print
(, substituting ) print defaultfontname cvx =only
(.\n) print flush
pop defaultfontname findfont
}
ifelse
}
ifelse
}
ifelse
} ifelse
} bind def
% The CharStrings for a Ghostscript font are a dictionary in which
% the key is the character name, and the value is a compressed
% representation of a path, as produced by type1imagepath.
% For detailed information, see the book
% "Adobe Type 1 Font Format", published by Adobe Systems Inc.
% Here is the BuildChar implementation
% for Type 1 (Ghostscript standard) fonts.
% The name Type1BuildChar is known to the interpreter.
/Type1BuildChar
{ exch begin
Encoding exch get
dup CharStrings exch known not
{ QUIET not
{ (Substituting .notdef for ) print = flush
} { pop } ifelse
/.notdef
} if
CharStrings exch get
PaintType 0 ne
{ 1 setmiterlimit 1 setlinejoin 1 setlinecap
currentdict /StrokeWidth known { StrokeWidth } { 0 } ifelse
setlinewidth }
if
type1addpath % does a fill or stroke
end
} bind def