Text
Text
% Text support
%----------------------------------------------------------------------------
%----------------------------------------------------------------------------
% Proc: z
% Stack: fontname size z -
% Desc: sets current font, ptsize
%----------------------------------------------------------------------------
/z
{
exch findfont exch scalefont
setfont % set the current
font
} bd
%----------------------------------------------------------------------------
% Proc: ZB
% Stack: fontname default_metrics_entry FontBBox FontMatrix ZB
% Desc: define raster font
%----------------------------------------------------------------------------
/ZB
{
9 dict %:
fontname default_metrics_entry FontBBox
begin
Encoding exch get CharStrings exch get
end
exec
} def
end %
stack: fontname fontdict
definefont pop
} bd
%----------------------------------------------------------------------------
% Proc: ZBAddChar
% Stack: metrics_entry char_proc char_code char_name fontname ZBAddChar
% Desc:
%----------------------------------------------------------------------------
/ZBAddChar
{
findfont begin %: metrics_entry
char_proc char_code char_name
dup 4 1 roll dup 6 1 roll %: char_name metrics_entry char_name char_proc
char_code char_name
Encoding 3 1 roll put %: char_name metrics_entry char_name
char_proc
CharStrings 3 1 roll put %: char_name metrics_entry
Metrics 3 1 roll put
end
} bd
%----------------------------------------------------------------------------
% Proc: Z
% Stack: width-array encode-array newfontname fontname Z -
% Desc: re-encode font
%----------------------------------------------------------------------------
/Z
{
findfont % get font
dictionary on stack
dup maxlength 2 add dict exch % get its size & create new font dictionary
% Now, get the new encoding array into the new dictionary
% stack: width-array encode-array newfontname new-dict old-dict
%... new-dict
dup /Fontname 3 index put % store it's own new name in that font
%... new-dict
%... metricsdict
dup /$met xd % prepare a pointer to the dest
Metrics dict
/Metrics exch put %stack: width-array newname
newfontdict
% Character widths in width-array are for a 1000 unit character coordinate
% system. If this is not the coordinate system used for this font, the
% character widths have to be scaled appropriately. This scale factor
% is being calculated here.
pop %:
width-array newname newfontdict
definefont pop % then, record that new font
in the font list
%: width-array
pop
} bd
%----------------------------------------------------------------------------
% Proc: CorelIsValidCharpath
% Stack: @ftx bool
% Desc: checks current path if it has points or is bogus. Used mainly to
% weed out space characters which only have a moveto in their
path.
% NOTE : can't just check if width or height = 0, even with 1
moveto as the
% current path, interpreters will return a box with width and/or
height
%----------------------------------------------------------------------------
/CorelIsValidCharpath
{
pathbbox
3 -1 roll
%----------------------------------------------------------------------------
% Proc: @ftx
% Stack: string @ftx -
% Desc: fill text with pattern or fountain
%----------------------------------------------------------------------------
/@ftx
{
{ % loop
for each character in the string
currentpoint 3 -1 roll %
(0) dup 3 -1 roll 0 exch put % convert integer into a string
dup
@gs
true charpath % get character outline in
path
$ctm setmatrix % set matrix for pattern
filling
CorelIsValidCharpath % check if we have a valid
charpath
{@@txt} if % pattern fill or fountain
@gr
@np
% set current point for next character
stringwidth pop 3 -1 roll add exch m
} forall
} bd
%----------------------------------------------------------------------------
% Proc: @ft
% Stack: string @ft -
% Desc: fill current text object
%----------------------------------------------------------------------------
/@ft
{
matrix currentmatrix exch % save current transfo matrix on stack
$sdf {$scf $sca $scp @ss} if % alternate halftone screen?
$fil 1 eq % pattern fill?
{/@@txt /@pf ld @ftx} % pattern fill on text
{
$fil 2 eq % fountain fill?
{/@@txt /gradient_fill ld @ftx} % fountain fill on text
{
$fil 3 eq % Postscript fill?
{/@@txt /@Pf ld @ftx} % PS fill on text
{
$fil 4 eq
{/@@txt /output_shading_gradient ld @ftx} % Level3 shaded fill on text
{
FillOverprint safe_setoverprint
FillColor /separate_set_color dexec % separate and set
fill color, returns TRUE if we fill, FALSE if not
{show} % show text
{pop} ifelse
} ifelse
} ifelse
} ifelse
} ifelse
$sdf {$dsf $dsa $dsp @ss} if % reset default halftone screen
setmatrix % reset original transfo matrix on stack
} bd
%----------------------------------------------------------------------------
% Proc: @st
% Stack: string @st -
% Desc: stroke current text object
%----------------------------------------------------------------------------
/@st
{
matrix currentmatrix exch % save current transfo matrix on
stack
$SDF {$SCF $SCA $SCP @ss} if % alternate halftone screen?
OutlineOverprint safe_setoverprint
OutlineColor /separate_set_color dexec % separate and set current stroke
color, returns TRUE if we paint, FALSE if not
{
{ % loop
for each character in the string
currentpoint 3 -1 roll
(0) dup 3 -1 roll 0 exch put % convert integer into a string
dup
@gs
true charpath % get character outline in path
$ctm setmatrix $ptm concat % set matrix for stroking
stroke % stroke it
@gr
@np
%----------------------------------------------------------------------------
% Proc: @te
% Stack: string @te -
% Desc: prints text as filled only
%----------------------------------------------------------------------------
/@te
{
@ft % fill that text
} bd
%----------------------------------------------------------------------------
% Proc: @tr
% Stack: string @tr -
% Desc: prints text as stroked only
%----------------------------------------------------------------------------
/@tr % prints
text as stroked only
{
@st % stroke that text
} bd
%----------------------------------------------------------------------------
% Proc: @ta
% Stack: string @ta -
% Desc: prints text as filled & stroked
%----------------------------------------------------------------------------
/@ta
{
dup
@gs @ft @gr % fill the text
@st % then stroke text
} bd
%----------------------------------------------------------------------------
% Proc: @t@a
% Stack: string @t@a -
% Desc: prints text as stroked & filled
%----------------------------------------------------------------------------
/@t@a
{
dup
@gs @st @gr % stroke the text
@ft % then fill text
} bd
%----------------------------------------------------------------------------
% Proc: @tm
% Stack: matrix @tm -
% Desc: set text matrix
%----------------------------------------------------------------------------
/@tm
{
@sm % save current
matrix
concat
} bd
%----------------------------------------------------------------------------
% Proc: e
% Stack: - e -
% Desc: filled tex
%----------------------------------------------------------------------------
/e
{
/t {@te} def % define operator t as @te
} bd
%----------------------------------------------------------------------------
% Proc: r
% Stack: - r -
% Desc: stroked text
%----------------------------------------------------------------------------
/r
{
/t {@tr} def % define operator t as @tr
} bd
%----------------------------------------------------------------------------
% Proc: o
% Stack: - o -
% Desc: invisible text
%----------------------------------------------------------------------------
/o
{
/t {pop} def % define operator t as
nothing
} bd
%----------------------------------------------------------------------------
% Proc: a
% Stack: - a -
% Desc: fill&stroke text
%----------------------------------------------------------------------------
/a
{
/t {@ta} def % define operator t as @ta
} bd
%----------------------------------------------------------------------------
% Proc: @a
% Stack: - @a -
% Desc: stroke&fill text
%----------------------------------------------------------------------------
/@a
{
/t {@t@a} def % define operator t as @t@a
} bd
%----------------------------------------------------------------------------
% Proc: t
% Stack: string t -
% Desc: text body
%----------------------------------------------------------------------------
/t {@te} def % default value: will be
redefined by a,e,o,r, and I
%----------------------------------------------------------------------------
% Proc: T
% Stack: - T -
% Desc: end text (restore)
%----------------------------------------------------------------------------
/T
{
@np % Clear path.
$ctm setmatrix % Reset current matrix.
/$ttm matrix def % Reset extended text matrix.
} bd
%----------------------------------------------------------------------------
% Proc: ddt
% Stack:
% Desc:
%----------------------------------------------------------------------------
/ddt
{
t
} def % NO "bind
def" because of t (can be modified)
%----------------------------------------------------------------------------
% Proc: @t
% Stack: xpos ypos string @t -
% Desc: paints a 1-character string at desired position
%----------------------------------------------------------------------------
/@t % paints a 1-
character string at desired position
{
/$stm $stm currentmatrix def % save current matrix
3 1 roll % send string to bottom
m % move to character position
$ttm concat % add text matrix
ddt % draw the character (current t operator)
$stm setmatrix % restore saved matrix
} bd
%----------------------------------------------------------------------------
% Proc: @n
% Stack: angle @n -
% Desc: paints a 1-character string at desired position
%----------------------------------------------------------------------------
/@n
{
/$ttm exch matrix rotate def % modify current text matrix accordingly
} bd
%----------------------------------------------------------------------------
% Proc: @s
% Stack: - @s -
% Desc: Mark a space
%----------------------------------------------------------------------------
/@s {} bd % mark a
space character in extended text
%----------------------------------------------------------------------------
% Proc: @l
% Stack: - @l -
% Desc: Mark an end of line
%----------------------------------------------------------------------------
/@l {} bd % mark an end of line in
extended text
%----------------------------------------------------------------------------
% Initalizations for CJK fonts
%----------------------------------------------------------------------------
/_lineorientation 0 def
/_bitfont null def
/_bitlobyte 0 def
/_bitkey null def
/_bithibyte 0 def