Article View: comp.lang.postscript
Article #6714Re: Underlining and character lengths
From: zaphod
Date: Wed, 28 Oct 1987 14:43
Date: Wed, 28 Oct 1987 14:43
69 lines
3372 bytes
3372 bytes
In article <1987Oct27.134058.23182@gpu.utcs.toronto.edu> tomwest@gpu.utcs.toronto.edu (Tom West) writes:
>
> I am adapting our word processor to a postscript engine. However, I
>am not sure how to handle underlines. Is there any easy way to know where
>or how to underline?
yes
> We use a mono-spaced font (for the most part). Can
>one just draw a horizontal line of the appropriate length with the same
>vertical position as the characters?
no, the line will "melt" into the letters
>
> As well, if we decide to get sophisticated, we would want to use non-mono
>fonts. Is there anywhere that we can get the length of characters in the
>standard fonts (Times, Helvetica and Symbols)?
again, yes the stringwidth operator
gives you the x and y offsets if the string on the top of the
stack were printed. the y offset (for non-japanese letters)
is usually 0 and therefore popped
this code will perform the trick.
/undershow
{ currentlinewidth exch
dup show currentpoint 3 2 roll
stringwidth exch neg exch
0 -2 rmoveto rlineto 0.5 setlinewidth stroke
moveto setlinewidth
} def
(string) undershow
the code works as follows.
currentlinewidth is stored on the stack
(string) is pushed onto the stack and undershow does the following:
top of stack is duplicated and shown.
the new currentpoint is saved, the roll tucks the currentpoint under the
string-in-question.
stringwidth gives us x and y displacements, exch to access the x value
negate the x value as we will be drawing BACK under the already shown string
exch to switch back the x and y values. move down 2 dots. I have found
this to be a good amount to avoid the line from melting into the letters.
now rlineto based on the x and y still on the stack. the 0.5 linewidth
is arbitrary, again, i have found it to be nice. stroke, reset the linewidth
and moveto the stored currentpoint.
THis is the cleanest way. a gsave/grestore combination could be used
to save currentpoint, but why store the entire graphics state for only
two values?
>
> Thanks in advance.
no problem, call me at 1-519-663-3787, i actually enjoy typesetting in raw
postscript and so have tackled many of the commen problems.
I also enjoy fixing postscript on third party wordprocessors (like
micro soft word) -- but i digress
>
--
humbly yours, Lance Bailey
Univ. Western Ontario | Robart's Research Institute
Dept. of Computer Science | Clinical Trials Unit
Graduate Studies | PO Box 5015
London, Canada | London, Canada
N6A 5B7 | N6A 5K8
decvax!{utcs|utzoo|watmath}!deepthot!zaphod
-or- zaphod@deepthot.uucp
Technical Details
Message-ID:
<936@deepthot.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!julian!deepthot!zaphodReferences:
<1987Oct27.134058.23182@gpu.utcs.toronto.edu>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!julian!deepthot!zaphod From: zaphod@deepthot.UUCP Newsgroups: comp.lang.postscript Subject: Re: Underlining and character lengths Message-ID: <936@deepthot.UUCP> Date: Wed, 28-Oct-87 09:43:40 EST Article-I.D.: deepthot.936 Posted: Wed Oct 28 09:43:40 1987 Date-Received: Fri, 30-Oct-87 19:48:05 EST References: <1987Oct27.134058.23182@gpu.utcs.toronto.edu> Reply-To: zaphod@deepthot.UUCP Organization: UWO CS, London Canada Lines: 69 Keywords: Underlining.