Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #711 > unrolled thread

Why do I not see the characters

Started byCecil Westerhof <Cecil@decebal.nl>
First post2012-06-09 11:30 +0200
Last post2012-06-09 10:24 -0700
Articles 11 — 4 participants

Back to article view | Back to comp.lang.postscript


Contents

  Why do I not see the characters Cecil Westerhof <Cecil@decebal.nl> - 2012-06-09 11:30 +0200
    Re: Why do I not see the characters Cecil Westerhof <Cecil@decebal.nl> - 2012-06-09 14:04 +0200
      Re: Why do I not see the characters John Deubert <john@acumentraining.com> - 2012-06-09 07:18 -0700
        Re: Why do I not see the characters Cecil Westerhof <Cecil@decebal.nl> - 2012-06-09 19:50 +0200
          Re: Why do I not see the characters Helge Blischke <h.blischke@acm.org> - 2012-06-09 22:24 +0200
      Re: Why do I not see the characters luser- -droog <mijoryx@yahoo.com> - 2012-06-09 10:14 -0700
        Re: Why do I not see the characters Cecil Westerhof <Cecil@decebal.nl> - 2012-06-09 22:16 +0200
          Re: Why do I not see the characters luser- -droog <mijoryx@yahoo.com> - 2012-06-09 14:16 -0700
            Re: Why do I not see the characters Cecil Westerhof <Cecil@decebal.nl> - 2012-06-10 00:15 +0200
              Re: Why do I not see the characters luser- -droog <mijoryx@yahoo.com> - 2012-06-09 15:51 -0700
      Re: Why do I not see the characters luser- -droog <mijoryx@yahoo.com> - 2012-06-09 10:24 -0700

#711 — Why do I not see the characters

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-06-09 11:30 +0200
SubjectWhy do I not see the characters
Message-ID<87r4to6ddr.fsf@Compaq.site>
I just started trying to do some things with postscript. I made a
little program based on the rosette example in the bluebook. I want in
the different wedges to display characters of a string, but they do
not appear. What am I doing wrong.

I also started making a library. But I am working with epstopdf to
make a pdf and then convert to create a png. Ideally I would not have
to have the library in the program itself, but could use an include.
But that is not possible with epstopdf. I tried to use the command
that epstopdf generates without the -dSAFER, but to no avail. Anyone
an idea how to solve this?

The code:
    %!PS-Adobe-3.0 EPSF-3.0
    %%BoundingBox: 0 0 600 600

    /pageBottom  0 def
    /pageLeft    0 def
    /pageRight 600 def
    /pageTop   600 def

    %% Library functions
    /grayBackground { % gray
      newpath
      gsave
      setgray
      newpath
      pageLeft pageBottom pageRight pageTop rectangle
      fill
      stroke
      .4 setgray
      usedFont
      authorFont scalefont
      setfont
      ((c) Cecil Westerhof - Decebal Computing) 550 5 rightString
      grestore
    } def

    /rectangle { % left bottom right top
      4 dict begin
      /top    exch def
      /right  exch def
      /bottom exch def
      /left   exch def

      left  bottom moveto
      right bottom lineto
      right top    lineto
      left  top    lineto
      left  bottom lineto
      closepath

      end
    } def

    /rightString { % string x y
      3 dict begin
      /y      exch def
      /x      exch def
      /string exch def

      x y moveto
      string stringwidth pop neg
      0
      rmoveto
      string
      show

      end
    } def


    %% Normal functions
    /wedge { % string
      gsave
      newpath
      0 0 moveto
      1 0 translate
      halfTurn rotate
      0 halfTurn sin translate
      gsave
      0 0 halfTurn sin 90 -90 arc
      closepath
      gsave
      fill
      grestore
      0 setgray
      stroke
      grestore
      0 setgray
      show
      grestore
    } def

    % Library init
    /authorFont     10 def
    /backgroundGray .6 def
    /usedFont       /Bookman findfont def

    % Program init
    /steps    14 def
    /turn     360 steps div neg def
    /halfTurn turn 2 div def
    /string   (Testing) def

    backgroundGray grayBackground

    gsave
      300 300 translate
      200 200 scale
      0.02 setlinewidth
      180 rotate
      0 1 steps 2 div 1 sub
       {
         dup
         steps div .5 add setgray
         string exch 1 getinterval
         wedge
         turn rotate
       } for
    grestore

    showpage

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#712

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-06-09 14:04 +0200
Message-ID<878vfw66a3.fsf@Compaq.site>
In reply to#711
Op zaterdag 9 jun 2012 11:30 CEST schreef Cecil Westerhof:

> I just started trying to do some things with postscript. I made a
> little program based on the rosette example in the bluebook. I want in
> the different wedges to display characters of a string, but they do
> not appear. What am I doing wrong.

The first part I found. I did not understand what was happening
correctly. Below a correct working version. Comment is welcome. ;-}

>
> I also started making a library. But I am working with epstopdf to
> make a pdf and then convert to create a png. Ideally I would not have
> to have the library in the program itself, but could use an include.
> But that is not possible with epstopdf. I tried to use the command
> that epstopdf generates without the -dSAFER, but to no avail. Anyone
> an idea how to solve this?

Help with this is still very welcome.

The new code:
    %!PS-Adobe-3.0 EPSF-3.0
    %%BoundingBox: 0 0 600 600

    /pageBottom  0 def
    /pageLeft    0 def
    /pageRight 600 def
    /pageTop   600 def

    %% Library functions
    /grayBackground { % gray
      newpath
      gsave
      setgray
      newpath
      pageLeft pageBottom pageRight pageTop rectangle
      fill
      stroke
      .4 setgray
      usedFont
      authorFont scalefont
      setfont
      ((c) Cecil Westerhof - Decebal Computing) 550 5 rightString
      grestore
    } def

    /rectangle { % left bottom right top
      4 dict begin
      /top    exch def
      /right  exch def
      /bottom exch def
      /left   exch def

      left  bottom moveto
      right bottom lineto
      right top    lineto
      left  top    lineto
      left  bottom lineto
      closepath

      end
    } def

    /rightString { % string x y
      3 dict begin
      /y      exch def
      /x      exch def
      /string exch def

      x y moveto
      string stringwidth pop neg
      0
      rmoveto
      string
      show

      end
    } def


    %% Normal functions
    /wedge { % string
      gsave
      newpath
      0 0 moveto
      1 0 translate
      halfTurn rotate
      0 halfTurn sin translate
      gsave
      0 0 halfTurn sin 90 -90 arc
      closepath
      gsave
      fill
      grestore
      0 setgray
      stroke
      grestore
      0 setgray
      -90 rotate
      dup stringwidth pop neg 2 div 0 moveto
      show
      grestore
    } def

    % Library init
    /authorFont     10 def
    /backgroundGray .6 def
    /usedFont       /Bookman findfont def

    % Program init
    /steps    14 def
    /turn     360 steps div neg def
    /halfTurn turn 2 div def
    /string   (Testing) def

    backgroundGray grayBackground

    gsave
      300 300 translate
      0 0 moveto
      200 200 scale
      usedFont
      .25 scalefont
      setfont
      0.02 setlinewidth
      180 rotate
      0 1 steps 2 div 1 sub
       {
         dup
         steps div .5 add setgray
         string exch 1 getinterval
         wedge
         turn rotate
       } for
    grestore

    showpage

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#713

FromJohn Deubert <john@acumentraining.com>
Date2012-06-09 07:18 -0700
Message-ID<2012060907184822140-john@acumentrainingcom>
In reply to#712
Hi, Cecil -

By "library" do you mean PS code stored on your hard disk?

If so, you can store the code in a .ps file and execute it from within 
another PS program with the "run" operator:

	(myLibraryCode.ps) run

As you can see, "run" is the PS equivalent of "#include."

The only tricky bit is figuring out what directory on your disk 
epstopdf considers to be its "home" directory, that is, where it will 
look for the myLibraryCode.ps file. It may be the directory in which 
the epstopdf executable resides; that's common, but by no means the 
only possibility. One way to ferret this out is to make a file from 
within a PS program and see where the file shows up on your disk. Try 
this:

% ====Cut here======
(TestFile.txt)(w) file
dup (This is a test.) writestring
closefile
% ====Cut here======

Run this program and see where the TestFile.txt file shows up; that's 
the home directory.

There's a detailed article on this in the January 2002 issue of the 
Acumen Journal (free for the downloading here: 
www.acumentraining.com/acumenjournal.html)

Or am I mistaken about what you're wanting to do?

- John

P.S.  Incidentally, the "run" operator's string argument can take a 
UNIX-style pathname:

	(librarycode/myLibraryCode.ps) run



========
John Deubert
Acumen Training
PostScript & PDF Engineering Classes & Consulting
www.acumentraining.com

Learn PostScript programming techniques
Read the free Acumen Journal
acumentraining.com/acumenjournal.html




On 2012-06-09 12:04:04 +0000, Cecil Westerhof said:

> Op zaterdag 9 jun 2012 11:30 CEST schreef Cecil Westerhof:
> 
>> I just started trying to do some things with postscript. I made a
>> little program based on the rosette example in the bluebook. I want in
>> the different wedges to display characters of a string, but they do
>> not appear. What am I doing wrong.
> 
> The first part I found. I did not understand what was happening
> correctly. Below a correct working version. Comment is welcome. ;-}
> 
>> 
>> I also started making a library. But I am working with epstopdf to
>> make a pdf and then convert to create a png. Ideally I would not have
>> to have the library in the program itself, but could use an include.
>> But that is not possible with epstopdf. I tried to use the command
>> that epstopdf generates without the -dSAFER, but to no avail. Anyone
>> an idea how to solve this?
> 
> Help with this is still very welcome.
> 
> The new code:
>     %!PS-Adobe-3.0 EPSF-3.0
>     %%BoundingBox: 0 0 600 600
> 
>     /pageBottom  0 def
>     /pageLeft    0 def
>     /pageRight 600 def
>     /pageTop   600 def
> 
>     %% Library functions
>     /grayBackground { % gray
>       newpath
>       gsave
>       setgray
>       newpath
>       pageLeft pageBottom pageRight pageTop rectangle
>       fill
>       stroke
>       .4 setgray
>       usedFont
>       authorFont scalefont
>       setfont
>       ((c) Cecil Westerhof - Decebal Computing) 550 5 rightString
>       grestore
>     } def
> 
>     /rectangle { % left bottom right top
>       4 dict begin
>       /top    exch def
>       /right  exch def
>       /bottom exch def
>       /left   exch def
> 
>       left  bottom moveto
>       right bottom lineto
>       right top    lineto
>       left  top    lineto
>       left  bottom lineto
>       closepath
> 
>       end
>     } def
> 
>     /rightString { % string x y
>       3 dict begin
>       /y      exch def
>       /x      exch def
>       /string exch def
> 
>       x y moveto
>       string stringwidth pop neg
>       0
>       rmoveto
>       string
>       show
> 
>       end
>     } def
> 
> 
>     %% Normal functions
>     /wedge { % string
>       gsave
>       newpath
>       0 0 moveto
>       1 0 translate
>       halfTurn rotate
>       0 halfTurn sin translate
>       gsave
>       0 0 halfTurn sin 90 -90 arc
>       closepath
>       gsave
>       fill
>       grestore
>       0 setgray
>       stroke
>       grestore
>       0 setgray
>       -90 rotate
>       dup stringwidth pop neg 2 div 0 moveto
>       show
>       grestore
>     } def
> 
>     % Library init
>     /authorFont     10 def
>     /backgroundGray .6 def
>     /usedFont       /Bookman findfont def
> 
>     % Program init
>     /steps    14 def
>     /turn     360 steps div neg def
>     /halfTurn turn 2 div def
>     /string   (Testing) def
> 
>     backgroundGray grayBackground
> 
>     gsave
>       300 300 translate
>       0 0 moveto
>       200 200 scale
>       usedFont
>       .25 scalefont
>       setfont
>       0.02 setlinewidth
>       180 rotate
>       0 1 steps 2 div 1 sub
>        {
>          dup
>          steps div .5 add setgray
>          string exch 1 getinterval
>          wedge
>          turn rotate
>        } for
>     grestore
> 
>     showpage


-- 

[toc] | [prev] | [next] | [standalone]


#716

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-06-09 19:50 +0200
Message-ID<87fwa4s7cf.fsf@Compaq.site>
In reply to#713
Op zaterdag 9 jun 2012 16:18 CEST schreef John Deubert:

> By "library" do you mean PS code stored on your hard disk?

Yes, exactly. I do not want to copy that code every time. The program
looks less and when I make a change …


> If so, you can store the code in a .ps file and execute it from within
> another PS program with the "run" operator:
>
> 	(myLibraryCode.ps) run
>
> As you can see, "run" is the PS equivalent of "#include."
>
> The only tricky bit is figuring out what directory on your disk epstopdf
> considers to be its "home" directory, that is, where it will look for
> the myLibraryCode.ps file. It may be the directory in which the epstopdf
> executable resides; that's common, but by no means the only possibility.
> One way to ferret this out is to make a file from within a PS program
> and see where the file shows up on your disk. Try this:
>
> % ====Cut here======
> (TestFile.txt)(w) file
> dup (This is a test.) writestring
> closefile
> % ====Cut here======
>
> Run this program and see where the TestFile.txt file shows up; that's
> the home directory.

That gives:
    Error: /invalidfileaccess in --file--
    Operand stack:
       (TestFile.txt)   (w)

Exactly what I got before. As I understand it epstopdf does not allow
file access for security reasons.


> There's a detailed article on this in the January 2002 issue of the
> Acumen Journal (free for the downloading here:
> www.acumentraining.com/acumenjournal.html)

I will look at it. (And the other stuff.)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#719

FromHelge Blischke <h.blischke@acm.org>
Date2012-06-09 22:24 +0200
Message-ID<a3hpn5ForiU1@mid.individual.net>
In reply to#716
Cecil Westerhof wrote:

> Op zaterdag 9 jun 2012 16:18 CEST schreef John Deubert:
> 
>> By "library" do you mean PS code stored on your hard disk?
> 
> Yes, exactly. I do not want to copy that code every time. The program
> looks less and when I make a change …
> 
> 
>> If so, you can store the code in a .ps file and execute it from within
>> another PS program with the "run" operator:
>>
>> (myLibraryCode.ps) run
>>
>> As you can see, "run" is the PS equivalent of "#include."
>>
>> The only tricky bit is figuring out what directory on your disk epstopdf
>> considers to be its "home" directory, that is, where it will look for
>> the myLibraryCode.ps file. It may be the directory in which the epstopdf
>> executable resides; that's common, but by no means the only possibility.
>> One way to ferret this out is to make a file from within a PS program
>> and see where the file shows up on your disk. Try this:
>>
>> % ====Cut here======
>> (TestFile.txt)(w) file
>> dup (This is a test.) writestring
>> closefile
>> % ====Cut here======
>>
>> Run this program and see where the TestFile.txt file shows up; that's
>> the home directory.
> 
> That gives:
>     Error: /invalidfileaccess in --file--
>     Operand stack:
>        (TestFile.txt)   (w)
> 
> Exactly what I got before. As I understand it epstopdf does not allow
> file access for security reasons.
> 
> 
>> There's a detailed article on this in the January 2002 issue of the
>> Acumen Journal (free for the downloading here:
>> www.acumentraining.com/acumenjournal.html)
> 
> I will look at it. (And the other stuff.)
> 

Well, epstopdf calls Ghostscript with the option "-dSAFER" which denies most 
file access, especially write acdcess.

Helge

[toc] | [prev] | [next] | [standalone]


#714

Fromluser- -droog <mijoryx@yahoo.com>
Date2012-06-09 10:14 -0700
Message-ID<fd5b6443-511b-49ae-91a7-3a1004854ccf@x39g2000yqx.googlegroups.com>
In reply to#712
On Jun 9, 7:04 am, Cecil Westerhof <Ce...@decebal.nl> wrote:
> Op zaterdag 9 jun 2012 11:30 CEST schreef Cecil Westerhof:
>
> > I just started trying to do some things with postscript. I made a
> > little program based on the rosette example in the bluebook. I want in
> > the different wedges to display characters of a string, but they do
> > not appear. What am I doing wrong.
>
> The first part I found. I did not understand what was happening
> correctly. Below a correct working version. Comment is welcome. ;-}
>
>
>
> > I also started making a library. But I am working with epstopdf to
> > make a pdf and then convert to create a png. Ideally I would not have
> > to have the library in the program itself, but could use an include.
> > But that is not possible with epstopdf. I tried to use the command
> > that epstopdf generates without the -dSAFER, but to no avail. Anyone
> > an idea how to solve this?


There's some useful stuff on this page:
http://stackoverflow.com/questions/9820646/overlay-two-postscript-files-command-line-approach/9833901#9833901


> Help with this is still very welcome.
>
> The new code:
>     %!PS-Adobe-3.0 EPSF-3.0
>     %%BoundingBox: 0 0 600 600
>
>     /pageBottom  0 def
>     /pageLeft    0 def
>     /pageRight 600 def
>     /pageTop   600 def
>
>     %% Library functions
>     /grayBackground { % gray
>       newpath
>       gsave
>       setgray
>       newpath
>       pageLeft pageBottom pageRight pageTop rectangle
>       fill
>       stroke

'fill' just ate the path! 'stroke' has nothing to do.
You can do 'gsave fill grestore stroke' if you really
want to. Since you're not changing colors, it'll just
make the box a little bigger. But it would give you
the linejoin effect at the corners.

>       .4 setgray
>       usedFont
>       authorFont scalefont
>       setfont
>       ((c) Cecil Westerhof - Decebal Computing) 550 5 rightString
>       grestore
>     } def
>
>     /rectangle { % left bottom right top
>       4 dict begin
>       /top    exch def
>       /right  exch def
>       /bottom exch def
>       /left   exch def
>
>       left  bottom moveto
>       right bottom lineto
>       right top    lineto
>       left  top    lineto
>       left  bottom lineto
>       closepath
>
>       end
>     } def
>
>     /rightString { % string x y
>       3 dict begin
>       /y      exch def
>       /x      exch def
>       /string exch def
>
>       x y moveto
>       string stringwidth pop neg
>       0
>       rmoveto
>       string
>       show
>
>       end
>     } def
>
>     %% Normal functions
>     /wedge { % string
>       gsave
>       newpath
>       0 0 moveto
>       1 0 translate
>       halfTurn rotate
>       0 halfTurn sin translate
>       gsave
>       0 0 halfTurn sin 90 -90 arc
>       closepath
>       gsave
>       fill
>       grestore
>       0 setgray
>       stroke
>       grestore
>       0 setgray
>       -90 rotate
>       dup stringwidth pop neg 2 div 0 moveto
>       show
>       grestore
>     } def
>
>     % Library init
>     /authorFont     10 def
>     /backgroundGray .6 def
>     /usedFont       /Bookman findfont def

Your font handling is a little hard to follow.
I like to do this:

/body /Palatino-Roman findfont 10 scalefont def
/ital /Palatino-Italic findfont 10 scalefont def
/bold /Palatino-Bold findfont 10 scalefont def
bold setfont

Or you can make them self-setting procedures.

/fontproc { [ exch /setfont cvx ] cvx } def
/body /Palatino-Roman findfont 10 scalefont fontproc def
body


>     % Program init
>     /steps    14 def
>     /turn     360 steps div neg def
>     /halfTurn turn 2 div def
>     /string   (Testing) def
>
>     backgroundGray grayBackground
>
>     gsave
>       300 300 translate
>       0 0 moveto
>       200 200 scale
>       usedFont
>       .25 scalefont
>       setfont
>       0.02 setlinewidth
>       180 rotate
>       0 1 steps 2 div 1 sub
>        {
>          dup
>          steps div .5 add setgray
>          string exch 1 getinterval
>          wedge
>          turn rotate
>        } for
>     grestore
>
>     showpage

It mostly looks good. But I'd recommend more indentation levels.
Treat 'gsave' like '{' and 'grestore' like '}'. Sometimes I'll
indent all 'lineto' and 'moveto's and come back out for the
'stroke', since they are all "functionally subordinate".

[toc] | [prev] | [next] | [standalone]


#717

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-06-09 22:16 +0200
Message-ID<87bokss0jo.fsf@Compaq.site>
In reply to#714
Thanks for the input.

Op zaterdag 9 jun 2012 19:14 CEST schreef luser:

>>> I also started making a library. But I am working with epstopdf to
>>> make a pdf and then convert to create a png. Ideally I would not have
>>> to have the library in the program itself, but could use an include.
>>> But that is not possible with epstopdf. I tried to use the command
>>> that epstopdf generates without the -dSAFER, but to no avail. Anyone
>>> an idea how to solve this?
>
>
> There's some useful stuff on this page:
> http://stackoverflow.com/questions/9820646/overlay-two-postscript-files-command-line-approach/9833901#9833901

The problem is that epstopdf makes the run illegal. Maybe I should use
bash to do the include myself.


>>     %% Library functions
>>     /grayBackground { % gray
>>       newpath
>>       gsave
>>       setgray
>>       newpath
>>       pageLeft pageBottom pageRight pageTop rectangle
>>       fill
>>       stroke
>
> 'fill' just ate the path! 'stroke' has nothing to do.
> You can do 'gsave fill grestore stroke' if you really
> want to. Since you're not changing colors, it'll just
> make the box a little bigger. But it would give you
> the linejoin effect at the corners.

I did not know what I was doing. Changed. Now I need to do it in all
the others also. :-{


>>     % Library init
>>     /authorFont     10 def
>>     /backgroundGray .6 def
>>     /usedFont       /Bookman findfont def
>
> Your font handling is a little hard to follow.

In the first program I used several different font sizes. In this way
I need only to make a change at one place. But I will look into your
suggestions.

Also what are good fonts to use? And in which situation?


> It mostly looks good.

Thank you. ;-}


> But I'd recommend more indentation levels.
> Treat 'gsave' like '{' and 'grestore' like '}'. Sometimes I'll

In some places I did this, but I will do it more consequent.


> indent all 'lineto' and 'moveto's and come back out for the
> 'stroke', since they are all "functionally subordinate".

That could be a good idea also.

I also changed string to msg.

I used the program to write a logo program. It is given below. I only
have one problem. I now have a compleet rosetta. The letters in de
lower part have te be placed differently. I have a function
textheight, which does what it should in other places, but here it
does not. Because of the I now use textwidth. It is better as nothing,
but for example the m is not placed very good. What is going wrong
here?

The program:
    %!PS-Adobe-3.0 EPSF-3.0
    %%BoundingBox: 0 0 600 600

    /pageBottom  0 def
    /pageLeft    0 def
    /pageRight 600 def
    /pageTop   600 def

    %% Library functions
    /colorBlack {
      0 0 0
    }

    /colorBlue {
      0 0 1
    } def

    /colorGreen {
      0 .5 0
    } def

    /colorIndigo {
      .3125 0 .5
    } def

    /colorOrange {
      1 .5625 0
    } def

    /colorRed {
      1 0 0
    } def

    /colorViolet {
      .9375 .5 .9375
    } def

    /colorWhite {
     1 1 1
    }

    /colorYellow {
      1 1 0
    } def

    /grayBackground { % gray
      newpath
      gsave
        setgray
        newpath
        pageLeft pageBottom pageRight pageTop rectangle
        fill
        .4 setgray
        usedFont
        authorFont scalefont
        setfont
        ((c) Cecil Westerhof - Decebal Computing) 550 5 rightString
      grestore
    } def

    /rectangle { % left bottom right top
      4 dict begin
        /top    exch def
        /right  exch def
        /bottom exch def
        /left   exch def

        left  bottom moveto
        right bottom lineto
        right top    lineto
        left  top    lineto
        left  bottom lineto
        closepath
      end
    } def

    /rightString { % msg x y
      3 dict begin
        /y   exch def
        /x   exch def
        /msg exch def

        x y moveto
        msg stringwidth pop neg
        0
        rmoveto
        msg show
      end
    } def

    /textheight {
      gsave
        {
          newpath
          100 100 moveto
          (HÍpg) true charpath pathbbox      % gets text path bounding box (LLx LLy URx URy)
          exch pop 3 -1 roll pop             % keeps LLy and URy
          exch sub                           % URy - LLy
        }
        stopped                                % did the last block fail?
        {
          pop pop                            % get rid of "stopped" junk
          currentfont /FontMatrix get 3 get  % gets alternative text height
        }
        if
      grestore
    } def


    %% Normal functions
    /createWedgeValues {
      /steps    msg length def
      /turn     360 steps 2 mul div neg def
      /halfTurn turn 2 div def
    } def

    /wedge { % msg downward
      gsave
        newpath
        0 0 moveto
        1 0 translate
        halfTurn rotate
        0 halfTurn sin translate
        gsave
          0 0 halfTurn sin 90 -90 arc
          closepath
          gsave
            fill
          grestore
          0 setgray
          stroke
        grestore
        0 setgray
        dup
        {  90 rotate }
        { -90 rotate } ifelse
        exch
        dup
        stringwidth pop 2 div neg
        3 -1 roll
        { dup  moveto }
        { 0 moveto } ifelse
        show
      grestore
    } def

    % Library init
    /authorFont     10 def
    /backgroundGray .6 def
    /usedFont       /Bookman findfont def

    % Program init

    %backgroundGray grayBackground

    gsave
      300 300 translate
      0 0 moveto
      245 245 scale
      usedFont
      .25 scalefont
      setfont
      0.02 setlinewidth
      180 rotate
      colorBlue
      setrgbcolor
      /msg (Decebal) def
      createWedgeValues
      0 1 steps 1 sub {
        msg exch 1 getinterval
        false wedge
        turn rotate
      } for
      colorGreen
      setrgbcolor
      /msg (Computing) def
      createWedgeValues
      180 turn sub rotate
      0 1 steps 1 sub {
        msg exch 1 getinterval
        true wedge
        turn neg rotate
      } for
    grestore

    showpage

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#722

Fromluser- -droog <mijoryx@yahoo.com>
Date2012-06-09 14:16 -0700
Message-ID<bfa2675b-f4b2-44e0-b80b-c498af3a3eb1@h9g2000yqi.googlegroups.com>
In reply to#717
On Jun 9, 3:16 pm, Cecil Westerhof <Ce...@decebal.nl> wrote:
> Thanks for the input.
>
> Op zaterdag 9 jun 2012 19:14 CEST schreef luser:
>
> >>> I also started making a library. But I am working with epstopdf to
> >>> make a pdf and then convert to create a png. Ideally I would not have
> >>> to have the library in the program itself, but could use an include.
> >>> But that is not possible with epstopdf. I tried to use the command
> >>> that epstopdf generates without the -dSAFER, but to no avail. Anyone
> >>> an idea how to solve this?
>
> > There's some useful stuff on this page:
> >http://stackoverflow.com/questions/9820646/overlay-two-postscript-fil...
>
> The problem is that epstopdf makes the run illegal. Maybe I should use
> bash to do the include myself.

I forgot there was so much info on that page. My link goes straight
to
my answer. In the last comment to my answer, there's this:

==
Also wanted to say thanks for the psinc tip, @luserdroog - that
finally helped me cook a solution that works for me, using the command
line and evince (added as separate answer); however, the regex in the
original script didn't work with indented runs as in your example, so
I made a mod: psinc.pl. Many thanks again for the answers - cheers!
== http://sdaaubckp.svn.sourceforge.net/viewvc/sdaaubckp/single-scripts/psinc.pl

This script will do what you propose to do with bash, in-lining
all '(...) run' commands (may now be indented, but don't put other
stuff on the same line).


> >>     %% Library functions
> >>     /grayBackground { % gray
> >>       newpath
> >>       gsave
> >>       setgray
> >>       newpath
> >>       pageLeft pageBottom pageRight pageTop rectangle
> >>       fill
> >>       stroke
>
> > 'fill' just ate the path! 'stroke' has nothing to do.
> > You can do 'gsave fill grestore stroke' if you really
> > want to. Since you're not changing colors, it'll just
> > make the box a little bigger. But it would give you
> > the linejoin effect at the corners.
>
> I did not know what I was doing. Changed. Now I need to do it in all
> the others also. :-{
>
> >>     % Library init
> >>     /authorFont     10 def
> >>     /backgroundGray .6 def
> >>     /usedFont       /Bookman findfont def
>
> > Your font handling is a little hard to follow.
>
> In the first program I used several different font sizes. In this way
> I need only to make a change at one place. But I will look into your
> suggestions.

That's good: DRY principle.
But better to make names with "*font" yield a font object.
For sizes, call it "*fontsize" or "*fsz" or sthg.

> Also what are good fonts to use? And in which situation?

Well, my rule of thumb is to use Palatino unless you have a reason not
to.
But Bookman's good, too. It's still Zapf, I think. Also, stick with
Zapf
unless you have a reason not to.

[...]
> I used the program to write a logo program. It is given below. I only
> have one problem. I now have a compleet rosetta. The letters in de
> lower part have te be placed differently. I have a function
> textheight, which does what it should in other places, but here it
> does not. Because of the I now use textwidth. It is better as nothing,
> but for example the m is not placed very good. What is going wrong
> here?
>
> The program:
[...]
>     /colorViolet {
>       .9375 .5 .9375
>     } def
>
>     /colorWhite {
>      1 1 1
>     }

Missed a 'def'. For lots of little defs like this,
I'd wrap it in a dict:

/colors <<
    /colorViolet { .9375 .5 .9375 }
    /colorWhite { 1 1 1 }
    >> def
colors begin

[toc] | [prev] | [next] | [standalone]


#723

FromCecil Westerhof <Cecil@decebal.nl>
Date2012-06-10 00:15 +0200
Message-ID<873964rv1p.fsf@Compaq.site>
In reply to#722
Op zaterdag 9 jun 2012 23:16 CEST schreef luser:

> On Jun 9, 3:16 pm, Cecil Westerhof <Ce...@decebal.nl> wrote:
>> Thanks for the input.
>>
>> Op zaterdag 9 jun 2012 19:14 CEST schreef luser:
>>
>>>>> I also started making a library. But I am working with epstopdf to
>>>>> make a pdf and then convert to create a png. Ideally I would not have
>>>>> to have the library in the program itself, but could use an include.
>>>>> But that is not possible with epstopdf. I tried to use the command
>>>>> that epstopdf generates without the -dSAFER, but to no avail. Anyone
>>>>> an idea how to solve this?
>>
>>> There's some useful stuff on this page:
>>> http://stackoverflow.com/questions/9820646/overlay-two-postscript-fil...
>>
>> The problem is that epstopdf makes the run illegal. Maybe I should use
>> bash to do the include myself.
>
> I forgot there was so much info on that page. My link goes straight
> to
> my answer. In the last comment to my answer, there's this:
>
> ==
> Also wanted to say thanks for the psinc tip, @luserdroog - that
> finally helped me cook a solution that works for me, using the command
> line and evince (added as separate answer); however, the regex in the
> original script didn't work with indented runs as in your example, so
> I made a mod: psinc.pl. Many thanks again for the answers - cheers!
> == http://sdaaubckp.svn.sourceforge.net/viewvc/sdaaubckp/single-scripts/psinc.pl
>
> This script will do what you propose to do with bash, in-lining
> all '(...) run' commands (may now be indented, but don't put other
> stuff on the same line).

I already made the script. Does a few things more:
  - only includes from the include directory
  - creates the png also

Included it at the end of the script. Now my postscript program takes
less as half the room and more importantly it fits on my screen. :-D


>>>>     % Library init
>>>>     /authorFont     10 def
>>>>     /backgroundGray .6 def
>>>>     /usedFont       /Bookman findfont def
>>
>>> Your font handling is a little hard to follow.
>>
>> In the first program I used several different font sizes. In this way
>> I need only to make a change at one place. But I will look into your
>> suggestions.
>
> That's good: DRY principle.

DRY is also why I wanted to work with a library.


> But better to make names with "*font" yield a font object.
> For sizes, call it "*fontsize" or "*fsz" or sthg.

I will take it into account.


>> Also what are good fonts to use? And in which situation?
>
> Well, my rule of thumb is to use Palatino unless you have a reason not
> to.
> But Bookman's good, too. It's still Zapf, I think. Also, stick with
> Zapf
> unless you have a reason not to.

Why stick with Zapf?


>>     /colorViolet {
>>       .9375 .5 .9375
>>     } def
>>
>>     /colorWhite {
>>      1 1 1
>>     }
>
> Missed a 'def'. For lots of little defs like this,

Oops.


> I'd wrap it in a dict:
>
> /colors <<
> /colorViolet { .9375 .5 .9375 }
> /colorWhite { 1 1 1 }
>>> def
> colors begin

Looks nice. I will try it out.


The bash script:
    #!/bin/bash

    set -o errexit
    set -o nounset

    declare -r INCLUDE_PATH=${HOME}/postscript/include
    declare -r OLD_IFS=${IFS}
    declare -r SCRIPTNAME=$(basename ${0})
    declare    INPUT_FILE
    declare    LOG_FILE
    declare    PDF_FILE
    declare    PNG_FILE
    declare    TMP_FILE

    declare include
    declare line
    declare temp

    if [[ ${#} -ne 1 ]] ; then
      echo "ERROR: ${SCRIPTNAME} FILE_NAME"
      exit 1
    fi
    if [[ ${1:(-4)} != .eps ]] ; then
      echo "ERROR: file should end with eps"
      exit 1
    fi

    INPUT_FILE=${1}; shift
    LOG_FILE=${INPUT_FILE}.log
    TMP_FILE=${INPUT_FILE}.tmp
    temp=${INPUT_FILE::(-4)}
    PDF_FILE=${temp}.pdf
    PNG_FILE=${temp}.png
    readonly INPUT_FILE
    readonly LOG_FILE
    readonly PDF_FILE
    readonly PNG_FILE
    readonly TMP_FILE

    rm -f ${TMP_FILE}
    rm -f ${LOG_FILE}
    IFS=$'\n'
    while read -r line ; do
      if [[ ${line::1} == '#' ]] ; then
        include=${line:1}
        if grep '^[-0-9a-zA-Z]*$' <<<${include} >/dev/null ; then
          cat ${INCLUDE_PATH}/${include} >>${TMP_FILE}
        else
          echo "ERROR: used an illegal include (${include})"
          exit 1
        fi
      else
        echo ${line} >>${TMP_FILE}
      fi
    done <${INPUT_FILE}
    IFS=${OLD_IFS}
    epstopdf ${TMP_FILE} --outfile=${PDF_FILE} 2>>${LOG_FILE}
    convert ${PDF_FILE} ${PNG_FILE}
    echo "${INPUT_FILE} converted"

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#724

Fromluser- -droog <mijoryx@yahoo.com>
Date2012-06-09 15:51 -0700
Message-ID<747f3b35-3ed2-4bb8-908b-d2202238dd0d@x17g2000yqg.googlegroups.com>
In reply to#723
On Jun 9, 5:15 pm, Cecil Westerhof <Ce...@decebal.nl> wrote:
> Op zaterdag 9 jun 2012 23:16 CEST schreef luser:

> >> Also what are good fonts to use? And in which situation?
>
> > Well, my rule of thumb is to use Palatino unless you have a reason not
> > to.
> > But Bookman's good, too. It's still Zapf, I think. Also, stick with
> > Zapf
> > unless you have a reason not to.
>
> Why stick with Zapf?
>

Because he's the greatest. Read Knuth's Digital Typography.
The love-letters between them... sigh.

You gotta have heros. And Zapf belongs among them.

--
Eschew Helvetica. Gesundheit.

[toc] | [prev] | [next] | [standalone]


#715

Fromluser- -droog <mijoryx@yahoo.com>
Date2012-06-09 10:24 -0700
Message-ID<62513005-e7fc-4eb4-ab31-66a32439425f@v9g2000yqm.googlegroups.com>
In reply to#712
On Jun 9, 7:04 am, Cecil Westerhof <Ce...@decebal.nl> wrote:

>     /rightString { % string x y
>       3 dict begin
>       /y      exch def
>       /x      exch def
>       /string exch def
>
>       x y moveto
>       string stringwidth pop neg
>       0
>       rmoveto
>       string
>       show
>
>       end
>     } def
>

Just a nit. You're hijacking an operator name, 'string'.
Nothing *wrong* per se, but it does block the operator
while the dict is in effect. If you were to forget the
'end', and then call some code that needs dynamic
strings; you could create something very hard to debug.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web