wrapping lines?? 
Author Message
 wrapping lines??

Quick background to my query - I need to get documents generating
dynamically from template (ps files) and send them to printers or pdf or
whatever. I am a web developer and my current project required a html form
to post to php which runs ghostscript to hand the dynamic bits. The document
in question is a fax cover sheet which has some simple single line text
fields but also a big one (the document body) spanning lines.

Is there any (easy) way to detect line length and have postscript output
break this big chunk of text into neat lines??? Or is there any way to put
line breaks in a single show command.

Ideally I would like to do something like:

250 250 moveto

(Hello there is a line break right here \n and there is another one here \r
ok?) show

And get an output of

Hello there is a line break right here

and there is another one here

ok?

Any ideas or feedback would be greatly appreciated. Thanks for your time.



Sun, 07 Mar 2004 11:45:47 GMT  
 wrapping lines??

There's no automatic line breaking in PostScript, and putting \n or \r
into the string will *not* do what you want.  You could, of course
write your own procedures to do this.  Take a look at Graham Freeman's
QuikScript (http://www.cs.adfa.oz.au/~gfreeman/) for an example of
this.  If you just want to break text into lines, this is pretty
straightforward.  However, if you want hyphenation, justification,
pair kerning, etc., this becomes a *very* complex problem.

-pd

Quote:

> Quick background to my query - I need to get documents generating
> dynamically from template (ps files) and send them to printers or pdf or
> whatever. I am a web developer and my current project required a html form
> to post to php which runs ghostscript to hand the dynamic bits. The document
> in question is a fax cover sheet which has some simple single line text
> fields but also a big one (the document body) spanning lines.

> Is there any (easy) way to detect line length and have postscript output
> break this big chunk of text into neat lines??? Or is there any way to put
> line breaks in a single show command.

> Ideally I would like to do something like:

> 250 250 moveto

> (Hello there is a line break right here \n and there is another one here \r
> ok?) show

> And get an output of

> Hello there is a line break right here

> and there is another one here

> ok?

> Any ideas or feedback would be greatly appreciated. Thanks for your time.



Sun, 07 Mar 2004 21:28:57 GMT  
 wrapping lines??

Quote:

> Quick background to my query - I need to get documents generating
> dynamically from template (ps files) and send them to printers or pdf or
> whatever. I am a web developer and my current project required a html form
> to post to php which runs ghostscript to hand the dynamic bits. The document
> in question is a fax cover sheet which has some simple single line text
> fields but also a big one (the document body) spanning lines.

> Is there any (easy) way to detect line length and have postscript output
> break this big chunk of text into neat lines??? Or is there any way to put
> line breaks in a single show command.

> Ideally I would like to do something like:

> 250 250 moveto

> (Hello there is a line break right here \n and there is another one here \r
> ok?) show

> And get an output of

> Hello there is a line break right here

> and there is another one here

> ok?

> Any ideas or feedback would be greatly appreciated. Thanks for your time.

Use my gonzo utilities at http://www.tinaja.com/post01.asp
See any .psl file in http://www.tinaja.com/must01.asp for examples.

consulting services available per http://www.tinaja.com/info01.asp

--
Many thanks,

Don Lancaster
Synergetics   3860 West First Street  Box 809  Thatcher, AZ 85552

Please visit my GURU's LAIR web site at http://www.tinaja.com



Mon, 08 Mar 2004 00:03:04 GMT  
 wrapping lines??

Quote:

> Quick background to my query - I need to get documents generating
> dynamically from template (ps files) and send them to printers or pdf or
> whatever. I am a web developer and my current project required a html form
> to post to php which runs ghostscript to hand the dynamic bits. The document
> in question is a fax cover sheet which has some simple single line text
> fields but also a big one (the document body) spanning lines.

> Is there any (easy) way to detect line length and have postscript output
> break this big chunk of text into neat lines??? Or is there any way to put
> line breaks in a single show command.

> Ideally I would like to do something like:

> 250 250 moveto

> (Hello there is a line break right here \n and there is another one here \r
> ok?) show

> And get an output of

> Hello there is a line break right here

> and there is another one here

> ok?

> Any ideas or feedback would be greatly appreciated. Thanks for your time.

Line-breaking can be done in PostScript, but it's not automatic or
necessarily very easy.

How about a different approach? Pass the text through fmt to break the
lines and then through enscript to produce the PostScript.

--



Mon, 08 Mar 2004 00:05:41 GMT  
 wrapping lines??
Thanks all. Will let you know how I go. I am pretty much assuming I'm going
to have to write something myself but I think Graham & Don's code will
certainly help.

Cheers

Mark

--
### - replace "spam" with "com" in my email - ###

Quote:
> Quick background to my query - I need to get documents generating
> dynamically from template (ps files) and send them to printers or pdf or
> whatever. I am a web developer and my current project required a html form
> to post to php which runs ghostscript to hand the dynamic bits. The
document
> in question is a fax cover sheet which has some simple single line text
> fields but also a big one (the document body) spanning lines.

> Is there any (easy) way to detect line length and have postscript output
> break this big chunk of text into neat lines??? Or is there any way to put
> line breaks in a single show command.

> Ideally I would like to do something like:

> 250 250 moveto

> (Hello there is a line break right here \n and there is another one here
\r
> ok?) show

> And get an output of

> Hello there is a line break right here

> and there is another one here

> ok?

> Any ideas or feedback would be greatly appreciated. Thanks for your time.



Mon, 08 Mar 2004 10:20:09 GMT  
 wrapping lines??
Hi Don

I was unable to open the one of your links:

http://www.tinaja.com/must01.asp

I also tried :

http://www.tinaja.com/must01.htm
http://www.tinaja.com/must01.html

No luck, any ideas.

Cheers

Mark
--
### - replace "spam" with "com" in my email - ###

Quote:

> > Quick background to my query - I need to get documents generating
> > dynamically from template (ps files) and send them to printers or pdf or
> > whatever. I am a web developer and my current project required a html
form
> > to post to php which runs ghostscript to hand the dynamic bits. The
document
> > in question is a fax cover sheet which has some simple single line text
> > fields but also a big one (the document body) spanning lines.

> > Is there any (easy) way to detect line length and have postscript output
> > break this big chunk of text into neat lines??? Or is there any way to
put
> > line breaks in a single show command.

> > Ideally I would like to do something like:

> > 250 250 moveto

> > (Hello there is a line break right here \n and there is another one here
\r
> > ok?) show

> > And get an output of

> > Hello there is a line break right here

> > and there is another one here

> > ok?

> > Any ideas or feedback would be greatly appreciated. Thanks for your
time.

> Use my gonzo utilities at http://www.tinaja.com/post01.asp
> See any .psl file in http://www.tinaja.com/must01.asp for examples.

> consulting services available per http://www.tinaja.com/info01.asp

> --
> Many thanks,

> Don Lancaster
> Synergetics   3860 West First Street  Box 809  Thatcher, AZ 85552

> Please visit my GURU's LAIR web site at http://www.tinaja.com



Mon, 08 Mar 2004 14:48:21 GMT  
 wrapping lines??

Quote:

>> > Is there any (easy) way to detect line length and have postscript output
>> > break this big chunk of text into neat lines??? Or is there any way to
>put
>> > line breaks in a single show command.

<snip>

>> > Any ideas or feedback would be greatly appreciated. Thanks for your
>time.

>> Use my gonzo utilities at http://www.tinaja.com/post01.asp
>> See any .psl file in http://www.tinaja.com/must01.asp for examples.

>> consulting services available per http://www.tinaja.com/info01.asp

See my recent postiong to the NG on linewrapping or use the TinyDict
Direct PostScript Mark-up.

Cappella Archive, Book on Demand Editions  
The TinyDict mark-up for self-printing books
www.cappella-archive.com



Thu, 11 Mar 2004 02:59:37 GMT  
 wrapping lines??
Thanks David

I have downloaded some of your work and documentation and it is very
interesting (esp. its simplicity). There is one thing that is preventing it
from working for me. Unfortunately I have not been able to find your line
wrapping post as I am new to the group and I think it has been archived.

Basically all of my information is arriving at my ps file in one big blob. I
then need to be able to break this into lines and then run your P, H & L
commands (minidict) over each of these segments.

I am falling into a trap I know by comparing postscript to any other
language, but in my previous experience I have found languages to have the
ability to either join two strings together into a long string (bigstring =
string1 & string2 or bigstring = string1 . string2  or bigstring = string1 +
string2, etc..).I have so far been unable to find anything of the sort in
postscript. Copy, putinterval and others have all failed. Is there any way
of doing this.

I have also looked at arrays as a possible solution, where each of the
strings is add as an element of an array, but again I have much the same
problem as I did with put interval. IE. my initial array has certain
dimesions and these can not be changed (to my knowledge).

Am I crazy or blind is there not a simple solution to such a simple
problem.... HELP

Mark

PS a little background

The senario that I am faced with is with a large "blob" of text arriving at
my ps file through ghostscript. I set out certain params (x pos, y pos, line
width etc...) I then loop over my text looking for spaces (using search) and
testing the stringwidth of my "pre" string to make sure its less than my
line length. If it is less than the line length the word/s & space are added
(<this is where my problem is>) to my line (pre) variable and I move on to
find the next space. When the line length is hit I dump the current line
variable to the page, reset it to null and continue looping through the
remaining text.

I know this is not a very graceful method of going about things, but I am
really stumped at present.

--
### - replace "spam" with "com" in my email - ###

Quote:


> >> > Is there any (easy) way to detect line length and have postscript
output
> >> > break this big chunk of text into neat lines??? Or is there any way
to
> >put
> >> > line breaks in a single show command.

> <snip>

> >> > Any ideas or feedback would be greatly appreciated. Thanks for your
> >time.

> >> Use my gonzo utilities at http://www.tinaja.com/post01.asp
> >> See any .psl file in http://www.tinaja.com/must01.asp for examples.

> >> consulting services available per http://www.tinaja.com/info01.asp

> See my recent postiong to the NG on linewrapping or use the TinyDict
> Direct PostScript Mark-up.

> Cappella Archive, Book on Demand Editions
> The TinyDict mark-up for self-printing books
> www.cappella-archive.com



Fri, 12 Mar 2004 14:12:49 GMT  
 wrapping lines??
-- from ThinkingInPostScript.pdf p.140 (pdf p.156)

CONCATENATING ARRAYS AND STRINGS

Arrays and strings have a fixed length. You cannot dynamically extend
them. In order to tack two of them together, you must allocate a third
array or string that is big enough to hold the other two, then copy them
both into it. There is no easier way to do it, unfortunately.
Example 11.7 sets forth a procedure called concatenate. This
concatenate procedure tacks together two string bodies into a third string
that is left on the operand stack as the result of the procedure call. The
procedure works with arrays in precisely the same way. If you copy this
example, be careful not to call it concat, since that is the name of another
PostScript operator for concatenating matrices.
The roll operator is used in the body of this procedure to avoid having to
make any dictionary entries. This is intentional, since a procedure used as
an operator-equivalent (as concatenate is) should have as few side effects
as possible.
Note the use of putinterval in this procedure. It is called once to copy the
body of the first argument into the destination at position 0, then it is
called a second time with the position in the destination equal to the
length of the first argument, so the second argument lands exactly where
the first part left off. Note the use of length to determine this
position, and
the careful use of dup and index to keep copies of the various strings or
arrays until we are done with them. The length, putinterval, and type
operators all consume their operands, so you must take care to operate on
a copy of the original arguments until they are no longer needed.

Example 11.7: Concatenating Two Strings Together
/concatenate % (string1) (string2) concatenate string3
% array1 array2 concatenate array3
{ %def
dup type 2 index type 2 copy ne { %if
pop pop
errordict begin (concatenate) typecheck end

Quote:
}{ %else

/stringtype ne exch /arraytype ne and {
errordict begin (concatenate) typecheck end
Quote:
} if
} ifelse

dup length 2 index length add 1 index type
/arraytype eq { array }{ string } ifelse
% stack: arg1 arg2 new
dup 0 4 index putinterval
% stack: arg1 arg2 new
dup 4 -1 roll length 4 -1 roll putinterval
% stack: new
Quote:
} bind def

(string1) (string2) concatenate ==
[ /zero /one /two ] [ /three /four /five /six ] concatenate ==
Quote:

> Thanks David

> I have downloaded some of your work and documentation and it is very
> interesting (esp. its simplicity). There is one thing that is preventing it
> from working for me. Unfortunately I have not been able to find your line
> wrapping post as I am new to the group and I think it has been archived.

> Basically all of my information is arriving at my ps file in one big blob. I
> then need to be able to break this into lines and then run your P, H & L
> commands (minidict) over each of these segments.

> I am falling into a trap I know by comparing postscript to any other
> language, but in my previous experience I have found languages to have the
> ability to either join two strings together into a long string (bigstring =
> string1 & string2 or bigstring = string1 . string2  or bigstring = string1 +
> string2, etc..).I have so far been unable to find anything of the sort in
> postscript. Copy, putinterval and others have all failed. Is there any way
> of doing this.

> I have also looked at arrays as a possible solution, where each of the
> strings is add as an element of an array, but again I have much the same
> problem as I did with put interval. IE. my initial array has certain
> dimesions and these can not be changed (to my knowledge).

> Am I crazy or blind is there not a simple solution to such a simple
> problem.... HELP

> Mark

> PS a little background

> The senario that I am faced with is with a large "blob" of text arriving at
> my ps file through ghostscript. I set out certain params (x pos, y pos, line
> width etc...) I then loop over my text looking for spaces (using search) and
> testing the stringwidth of my "pre" string to make sure its less than my
> line length. If it is less than the line length the word/s & space are added
> (<this is where my problem is>) to my line (pre) variable and I move on to
> find the next space. When the line length is hit I dump the current line
> variable to the page, reset it to null and continue looping through the
> remaining text.

> I know this is not a very graceful method of going about things, but I am
> really stumped at present.

> --
> ### - replace "spam" with "com" in my email - ###




> > >> > Is there any (easy) way to detect line length and have postscript
> output
> > >> > break this big chunk of text into neat lines??? Or is there any way
> to
> > >put
> > >> > line breaks in a single show command.

> > <snip>

> > >> > Any ideas or feedback would be greatly appreciated. Thanks for your
> > >time.

> > >> Use my gonzo utilities at http://www.tinaja.com/post01.asp
> > >> See any .psl file in http://www.tinaja.com/must01.asp for examples.

> > >> consulting services available per http://www.tinaja.com/info01.asp

> > See my recent postiong to the NG on linewrapping or use the TinyDict
> > Direct PostScript Mark-up.

> > Cappella Archive, Book on Demand Editions
> > The TinyDict mark-up for self-printing books
> > www.cappella-archive.com



Sun, 14 Mar 2004 23:54:44 GMT  
 wrapping lines??
Thanks Al

I have managed to perform this operation since my initial post. My effort is
pretty ugly but it works. I do really appreciate your effort.

Cheers

Mark

--
### - replace "spam" with "com" in my email - ###

Quote:
> -- from ThinkingInPostScript.pdf p.140 (pdf p.156)

> CONCATENATING ARRAYS AND STRINGS

> Arrays and strings have a fixed length. You cannot dynamically extend
> them. In order to tack two of them together, you must allocate a third
> array or string that is big enough to hold the other two, then copy them
> both into it. There is no easier way to do it, unfortunately.
> Example 11.7 sets forth a procedure called concatenate. This
> concatenate procedure tacks together two string bodies into a third string
> that is left on the operand stack as the result of the procedure call. The
> procedure works with arrays in precisely the same way. If you copy this
> example, be careful not to call it concat, since that is the name of
another
> PostScript operator for concatenating matrices.
> The roll operator is used in the body of this procedure to avoid having to
> make any dictionary entries. This is intentional, since a procedure used
as
> an operator-equivalent (as concatenate is) should have as few side effects
> as possible.
> Note the use of putinterval in this procedure. It is called once to copy
the
> body of the first argument into the destination at position 0, then it is
> called a second time with the position in the destination equal to the
> length of the first argument, so the second argument lands exactly where
> the first part left off. Note the use of length to determine this
> position, and
> the careful use of dup and index to keep copies of the various strings or
> arrays until we are done with them. The length, putinterval, and type
> operators all consume their operands, so you must take care to operate on
> a copy of the original arguments until they are no longer needed.

> Example 11.7: Concatenating Two Strings Together
> /concatenate % (string1) (string2) concatenate string3
> % array1 array2 concatenate array3
> { %def
> dup type 2 index type 2 copy ne { %if
> pop pop
> errordict begin (concatenate) typecheck end
> }{ %else
> /stringtype ne exch /arraytype ne and {
> errordict begin (concatenate) typecheck end
> } if
> } ifelse
> dup length 2 index length add 1 index type
> /arraytype eq { array }{ string } ifelse
> % stack: arg1 arg2 new
> dup 0 4 index putinterval
> % stack: arg1 arg2 new
> dup 4 -1 roll length 4 -1 roll putinterval
> % stack: new
> } bind def
> (string1) (string2) concatenate ==
> [ /zero /one /two ] [ /three /four /five /six ] concatenate ==


> > Thanks David

> > I have downloaded some of your work and documentation and it is very
> > interesting (esp. its simplicity). There is one thing that is preventing
it
> > from working for me. Unfortunately I have not been able to find your
line
> > wrapping post as I am new to the group and I think it has been archived.

> > Basically all of my information is arriving at my ps file in one big
blob. I
> > then need to be able to break this into lines and then run your P, H & L
> > commands (minidict) over each of these segments.

> > I am falling into a trap I know by comparing postscript to any other
> > language, but in my previous experience I have found languages to have
the
> > ability to either join two strings together into a long string
(bigstring =
> > string1 & string2 or bigstring = string1 . string2  or bigstring =
string1 +
> > string2, etc..).I have so far been unable to find anything of the sort
in
> > postscript. Copy, putinterval and others have all failed. Is there any
way
> > of doing this.

> > I have also looked at arrays as a possible solution, where each of the
> > strings is add as an element of an array, but again I have much the same
> > problem as I did with put interval. IE. my initial array has certain
> > dimesions and these can not be changed (to my knowledge).

> > Am I crazy or blind is there not a simple solution to such a simple
> > problem.... HELP

> > Mark

> > PS a little background

> > The senario that I am faced with is with a large "blob" of text arriving
at
> > my ps file through ghostscript. I set out certain params (x pos, y pos,
line
> > width etc...) I then loop over my text looking for spaces (using search)
and
> > testing the stringwidth of my "pre" string to make sure its less than my
> > line length. If it is less than the line length the word/s & space are
added
> > (<this is where my problem is>) to my line (pre) variable and I move on
to
> > find the next space. When the line length is hit I dump the current line
> > variable to the page, reset it to null and continue looping through the
> > remaining text.

> > I know this is not a very graceful method of going about things, but I
am
> > really stumped at present.

> > --
> > ### - replace "spam" with "com" in my email - ###




> > > >> > Is there any (easy) way to detect line length and have postscript
> > output
> > > >> > break this big chunk of text into neat lines??? Or is there any
way
> > to
> > > >put
> > > >> > line breaks in a single show command.

> > > <snip>

> > > >> > Any ideas or feedback would be greatly appreciated. Thanks for
your
> > > >time.

> > > >> Use my gonzo utilities at http://www.tinaja.com/post01.asp
> > > >> See any .psl file in http://www.tinaja.com/must01.asp for examples.

> > > >> consulting services available per http://www.tinaja.com/info01.asp

> > > See my recent postiong to the NG on linewrapping or use the TinyDict
> > > Direct PostScript Mark-up.

> > > Cappella Archive, Book on Demand Editions
> > > The TinyDict mark-up for self-printing books
> > > www.cappella-archive.com



Tue, 16 Mar 2004 15:15:46 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. wrap lines

2. Line wrapping.

3. Corrupted (line wrapped) Postscript file

4. How to stop CDONTS from wrapping message lines

5. VB Script. Line Wrap

6. Preventing line-wrap in text-based emails created through CDONTS

7. Line Wrap

8. word wrap routine in Postscript

9. Slow performance with text tightly wrapped to images

10. Can one programmatically determine if text wraps?

11. Word Wrap

12. Postscript to wrap up the font into the script

 

 
Powered by phpBB® Forum Software