glyphpath

Showing 1-10 of 10 messages
glyphpath jdaw1 5/25/06 7:23 PM
Please, what is the easiest way to do a charpath type thing to a glyph
(in the current font)?

Re: glyphpath Aandi Inston 5/25/06 11:59 PM
"jdaw1" <jdawi...@gmail.com> wrote:

>Please, what is the easiest way to do a charpath type thing to a glyph
>(in the current font)?

If you have the glyph name but not the encoding point, you need to
re-encode the font. Since you should always re-encode fonts this
should be pretty easy.
----------------------------------------
Aandi Inston  qu...@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

Re: glyphpath jdaw1 5/26/06 5:01 AM
Oh. I never re-encode fonts, and don't know how. Please, with (say)
/quotedblleft on the stack, how do I append its outline to the current
path.

(FYI, I'm writing a version of show, and associated bounding-box
functions StringWidth and StringHeight, that will accept an array
containing strings, names of glyphs, of further arrays containing same.
I need glyphpath for the StringHeight function.)

Re: glyphpath jdaw1 5/26/06 10:47 AM
I've tried the following, but it produces a blank page. Please, what's
wrong? (And this creates a whole new font, so GlyphPath will need to
know its size: I'm hoping to use the currentfont, at whatever size it
is, rather than a new font. Please, how might that be done?)

%!PS-Adobe-2.1

/GlyphPath
{
        /glyphname exch def
        currentfont length dict begin
        currentfont {1 index /FID ne {def} {pop pop} ifelse} forall
        /Encoding 256 array def
        0 1 255 {Encoding exch /.notdef put} for
        Encoding 97 glyphname put  % ASCII a = 97
        currentdict
        end
        /TemporaryFont exch definefont pop
        /TemporaryFont 48 selectfont
        (abcd) false charpath

} def

/TimesNewRomanPS-BoldMT 128 selectfont
50 500 moveto
0 setgray 1.2 setlinewidth 1 setlinecap 1 setlinejoin

/dagger GlyphPath gsave 0.75 setgray fill grestore stroke

showpage
(pstack start) ==
pstack
(pstack done) ==

Re: glyphpath Aandi Inston 5/26/06 11:17 AM
"jdaw1" <jdawi...@gmail.com> wrote:

>Oh. I never re-encode fonts, and don't know how. Please, with (say)
>/quotedblleft on the stack, how do I append its outline to the current
>path.

1. Re-encode the font to a new encoding vector that includes
/quotedblleft (or, if the current encoding array includes
/quotedblleft, look up its index).

Re-encoding fonts is fundamental and should be covered in any
PostScript book that talks about working with fonts. It should always
be done, except in the case where you only use glyphshow, because you
do not know what the original encoding is.

2. Use charpath with a suitable character index into the new encoding.


>
>(FYI, I'm writing a version of show, and associated bounding-box
>functions StringWidth and StringHeight, that will accept an array
>containing strings, names of glyphs, of further arrays containing same.
>I need glyphpath for the StringHeight function.)

Then re-encoding is going to be pretty important to you!


----------------------------------------
Aandi Inston  qu...@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

Re: glyphpath Aandi Inston 5/26/06 11:31 AM
"jdaw1" <jdawi...@gmail.com> wrote:

>Please, how might that be done?)

glyphshow is a convenience operator, but it is only a convenience in
the simple case. Otherwise you have a lot to do, and I think you have
created a scenario that is too complex for the benefits it gives.
>
>%!PS-Adobe-2.1

Please use

%!

The line you have used says that your file is DSC compliant, and it is
not; this could cause errors.

>        /TemporaryFont exch definefont pop
>        /TemporaryFont 48 selectfont
>        (abcd) false charpath

In the implementation I tested with, the modified font retained the
original font scaling. This was then further scaled by another factor
of 48. When replaced by 1 it worked as expected.
>
>} def
>
>/TimesNewRomanPS-BoldMT 128 selectfont

If it matters to you, Times-Roman is a more portable choice.


>50 500 moveto
>0 setgray 1.2 setlinewidth 1 setlinecap 1 setlinejoin
>
>/dagger GlyphPath gsave 0.75 setgray fill grestore stroke
>
>showpage
----------------------------------------
Aandi Inston  qu...@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

Re: glyphpath jdaw1 5/26/06 12:03 PM
Fantastic; thank you for your expert and quick help. For the benefit of
others googling the same problem, I'll post the lastest version of my
code, but after I get GlyphPath to do the sensible thing with the
currentpoint.

Other issues outstanding:
-- Distiller 6.0.1 on a PC didn't recognise /Times-Roman; nor any
versions I could invent that might be bold;
-- Is "a" guaranteed to be 97?

Thanks again.

Re: glyphpath Aandi Inston 5/26/06 2:06 PM
"jdaw1" <jdawi...@gmail.com> wrote:

>-- Distiller 6.0.1 on a PC didn't recognise /Times-Roman

It should do, though it won't be able to embed it if you don't own it.
Nevetheless, this is the standard Times font name

>. nor any


>versions I could invent that might be bold;

Times-Bold.

>-- Is "a" guaranteed to be 97?

That's up to you.  If you mean in the string (a), then you can check
in a binary editor what the value you code is; likely to be the same
on all systems.  You can set specific codes into a string using "put".


----------------------------------------
Aandi Inston  qu...@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

Re: glyphpath jdaw1 5/26/06 9:09 PM
Excellent: thank you again. Code, for others to criticise or re-use:

/BaseHeight {
        gsave
                newpath 0 0 moveto
                [ 0 0 0 0 0 0 ] defaultmatrix setmatrix
                (ABCFJ1hli^"/) true charpath flattenpath pathbbox exch pop sub neg
exch pop
        grestore
} def

/StringHeight {
        gsave
                newpath 0 0 moveto
                [ 0 0 0 0 0 0 ] defaultmatrix setmatrix
                true CharPathRecursive flattenpath pathbbox exch pop sub neg exch pop
        grestore
} def

% A valid parameter is a glyph name, a string, or an array of valid
paramters.
% Computes the total width.
/StringWidthRecursive
{
        dup type /stringtype eq
        {stringwidth pop}
        {
        dup type /nametype eq
        {matrix currentmatrix gsave newpath nulldevice setmatrix 0 0 moveto
glyphshow currentpoint grestore pop} %
http://groups.google.com/group/comp.lang.postscript/browse_thread/thread/810a694812fec7be/
        {
        dup type /arraytype eq
        {0 exch {StringWidthRecursive add} forall}
        {
                pop (Error: StringWidthRecursive parameter neither string nor name
nor array) =
        } ifelse  % arraytype
        } ifelse  % nametype
        } ifelse  % stringtype
} def

% A valid parameter is a glyph name, a string, or an array of valid
paramters.
% ShowRecursive shows the sequences of entities in the natural manner.
/ShowRecursive
{
        1 dict begin
        /param exch def
        param type /stringtype eq {param show}
        {
        param type /nametype eq {param glyphshow}
        {
        param type /arraytype eq
        {
                param {ShowRecursive} forall
        }
        {
                (Error: ShowRecursive parameter neither string nor name nor array) =
        } ifelse  % arraytype
        } ifelse  % nametype
        } ifelse  % stringtype
        end
} def

% Computes the path of a glyph, with the charpath-style boolean flag,
destroying the currentpoint.
/GlyphPath
{
        2 dict begin
        /bln exch def
        /glyphname exch def
        currentfont


        currentfont length dict begin
        currentfont {1 index /FID ne {def} {pop pop} ifelse} forall
        /Encoding [ 256 {/.notdef} repeat ] def

        Encoding 97 glyphname put  % ASCII a = 97
        currentdict
        end
        /TemporaryFont exch definefont pop
        /TemporaryFont 1 selectfont
        (a) bln charpath
         setfont
        /TemporaryFont undefinefont
        end
} def

% Computes the path of a glyph, with the charpath-style boolean flag,
moving the currentpoint as if after a show.
/GlyphPathMoveto
{
        2 dict begin
        /bln exch def
        /glyphname exch def
        currentfont


        currentfont length dict begin
        currentfont {1 index /FID ne {def} {pop pop} ifelse} forall
        /Encoding [ 256 {/.notdef} repeat ] def

        Encoding 97 glyphname put  % ASCII a = 97
        currentdict
        end
        /TemporaryFont exch definefont pop
        /TemporaryFont 1 selectfont
        currentpoint exch (a) stringwidth pop add exch
        (a) bln charpath
        moveto
        setfont
        /TemporaryFont undefinefont
        end
} def

% A valid first parameter is a glyph name, a string, or an array of
valid paramters.
% CharPathRecursiveMoveto computes the path, destroying the
currentpoint.
/CharPathRecursive
{
        2 dict begin
        /bln exch def
        /param exch def
        param type /stringtype eq {param bln charpath}
        {
        param type /nametype eq {param bln GlyphPath}
        {
        param type /arraytype eq
        {
                0 1 param length 2 sub
                {
                        param exch get bln CharPathRecursiveMoveto
                } for
                param  param length 1 sub  get   bln CharPathRecursive
        }
        {
                (Error: CharPathRecursive parameter neither string nor name nor array
) =
        } ifelse  % arraytype
        } ifelse  % nametype
        } ifelse  % stringtype
        end
} def

% A valid first parameter is a glyph name, a string, or an array of
valid paramters.
% CharPathRecursiveMoveto computes the path, moving the currentpoint as
if after a show.
/CharPathRecursiveMoveto
{
        2 dict begin
        /bln exch def
        /param exch def
        param type /stringtype eq
        {
                currentpoint exch param stringwidth pop add exch
                param bln charpath
                moveto
        }
        {
        param type /nametype eq {param bln GlyphPathMoveto}
        {
        param type /arraytype eq
        {
                param {bln CharPathRecursiveMoveto} forall
        }
        {
                (Error: CharPathRecursiveMoveto parameter neither string nor name nor
array ) =
        } ifelse  % arraytype
        } ifelse  % nametype
        } ifelse  % stringtype
        end
} def

% A valid first parameter is a glyph name, a string, or an array of
valid paramters.
% DeGlyphRecursive computes a concatenated string, with glyphs replaced
by the first character of their name (which typically copes with
accents).
/DeGlyphRecursive
{
        1 dict begin
        /param exch def
        param type /stringtype eq {param}
        {
        param type /nametype eq {param 127 string cvs 0 1 getinterval}
        {
        param type /arraytype eq
        {
                () param {DeGlyphRecursive Concatenate} forall
        }
        {
                (Error: DeGlyphRecursive parameter neither string nor name nor array
) =
                ()
        } ifelse  % arraytype
        } ifelse  % nametype
        } ifelse  % stringtype
        end
} def

Re: glyphpath jdaw1 5/28/06 7:52 AM
Thank you again for your help. The latest version of
http://www.jdawiseman.com/papers/trivia/glasses.html is now working.
Share and enjoy.