🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.postscript.programming
Article #1464

Re: Please Help Regarding Scaling

#1464
From: Eric Rose
Date: Thu, 30 May 2002 18:55
247 lines
4555 bytes
Let me try that again... 

%!PS-Adobe-3.0 

% variables 

/ySpacing 63 def % horiz movement 

/xSpacing 151 def % vert movement 

/boxWidth 135 def % label width 

/boxHeight 54 def % label height 

/cpx 306 def % cp of label 

/cpy 396 def % cp of label 

/llx 0 def % fm charpath 

/lly 0 def % fm charpath 

/urx 0 def % fm charpath 

/ury 0 def % fm charpath 

/cpWidth 0 def % charpath width 

/cpHeight 0 def % charpath height 

/myScale 0 def % calc scale 

/ox 0 def % calc origin x 

/oy 0 def % calc origin y 

% functions 

% ------------------------------------- 

% For debug only, draws box 

% Stack in : nothing 

% Stack out: nothing 

% Modifies : nothing 

% ------------------------------------- 

/drawBox 

{boxWidth 2 div cpx exch sub 

 boxHeight 2 div cpy exch sub 

 moveto 

 0 boxHeight rlineto % up 

 boxWidth 0 rlineto % right 

 0 boxHeight -1 mul rlineto % down 

 boxWidth -1 mul 0 rlineto % left 

 stroke 

} def 

% ------------------------------------- 

% Populates charpath variables 

% Stack in : string to center 

% Stack out: same string 

% Modifies : llx, lly, urx, ury, 

% cpWidth, cpHeight 

% ------------------------------------- 

/populateCharPathBounds 

{dup % preserve string 

 gsave % save graphics state 

 newpath % start a new path 

 0 0 moveto % reset origin 

 true charpath % glyph outlines 

 flattenpath % better dimensions 

 pathbbox % bounding box of string 

 grestore % restore graphics 

 /ury exch def % save ury (reals) 

 /urx exch def % save urx 

 /lly exch def % save lly 

 /llx exch def % save llx 

 urx llx sub /cpWidth exch def 

 ury lly sub /cpHeight exch def 

} def 

% ------------------------------------- 

% Calculates scale to fit 

% Stack in : nothing 

% Stack out: nothing 

% Modifies : myScale 

% ------------------------------------- 

/calculateScale 

{cpWidth cpHeight div % charpath ratio 

 boxWidth boxHeight div % box ratio 

 ge % cpRatio >= boxRatio ? 

 {boxWidth cpWidth div % yes 

 } 

 {boxHeight cpHeight div % no 

 } ifelse 

 100 mul % apply to 100 (beg scale) 

 /myScale exch def % save it 

} def 

% ------------------------------------- 

% Calculates movement 

% left movement: (((urx+llx)/2)+llx) 

% down movement: ((ury+lly)/2) 

% Stack in : nothing 

% Stack out: nothing 

% Modifies : ox and oy 

% ------------------------------------- 

/calculateOrigin 

{urx llx sub 2 div % cp of charpath  

 llx add % account for char pading 

 cpx exch sub % apply to center point 

 /ox exch def % save it (left movement) 

 ury lly add % if lly below line, neg 

 2 div % mid point of movement 

 cpy exch sub % apply to center point 

 /oy exch def % save it (down movement) 

} def 

% ------------------------------------- 

% Main subroutine 

% Stack in : string to center 

% Stack out: nothing (consumes string) 

% Modifies : calculated variables 

% ------------------------------------- 

/doJob 

{drawBox % debug only !!! 

 /Helvetica findfont 100 scalefont 

 setfont 

 populateCharPathBounds 

 calculateScale 

 /Helvetica findfont myScale scalefont 

 setfont 

 populateCharPathBounds 

 calculateOrigin 

 ox oy moveto show 

} def 

% main -------------------------------- 

% for testing only 

/cpy 740 def 

/cpx 100 def (This will center around) doJob 

/cpx cpx 140 add def (Horizonal) doJob 

/cpx cpx 140 add def (and) doJob 

/cpx cpx 140 add def (Vert) doJob 

/cpy cpy 60 sub def 

/cpx 100 def (axis) doJob 

/cpx cpx 140 add def (G) doJob 

/cpx cpx 140 add def (g) doJob 

/cpx cpx 140 add def (See?) doJob 

showpage
Technical Details
Message-ID: <ef88c70.2@WebX.aaQKaf7vad4>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <ef88c70.-1@WebX.aaQKaf7vad4>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10c61a,830b42484cb2121b
X-Google-Attributes: gid10c61a,public
X-Google-ArrivalTime: 2002-05-30 12:07:44 PST
From: "Eric Rose" <erose@cskauto.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!iad-peer.news.verio.net!news.verio.net!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.postscript.programming
Subject: Re: Please Help Regarding Scaling
Message-ID: <ef88c70.2@WebX.aaQKaf7vad4>
Date: Thu, 30 May 2002 11:55:03 -0700
References: <ef88c70.-1@WebX.aaQKaf7vad4>
Lines: 247
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit