Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1019 > unrolled thread
| Started by | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| First post | 2012-10-26 12:30 +0200 |
| Last post | 2012-11-25 22:29 +0100 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.postscript
How to make bounding box depending on input text Cecil Westerhof <Cecil@decebal.nl> - 2012-10-26 12:30 +0200
Re: How to make bounding box depending on input text bugbear <bugbear@trim_papermule.co.uk_trim> - 2012-10-26 17:00 +0100
Re: How to make bounding box depending on input text John Deubert <john@acumentraining.com> - 2012-10-31 10:05 -0700
Re: How to make bounding box depending on input text Don Lancaster <don@tinaja.com> - 2012-11-02 14:25 -0700
Re: How to make bounding box depending on input text luser- -droog <mijoryx@yahoo.com> - 2012-11-03 02:50 -0700
Re: How to make bounding box depending on input text Cecil Westerhof <Cecil@decebal.nl> - 2012-11-24 18:21 +0100
Re: How to make bounding box depending on input text "luser.droog" <luser.droog@gmail.com> - 2012-11-25 04:16 -0600
Re: How to make bounding box depending on input text Cecil Westerhof <Cecil@decebal.nl> - 2012-11-25 22:29 +0100
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2012-10-26 12:30 +0200 |
| Subject | How to make bounding box depending on input text |
| Message-ID | <87vcdxy187.fsf@Compaq.site> |
At the moment I use Image Magick to generate pictures for quotes. For
example:
https://www.facebook.com/photo.php?fbid=391593267579727
This is fairly easy. But I was thinking about doing it with
postscript. But then I have define the size of the output and this is
depending on the input. Is there a way to solve this?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [next] | [standalone]
| From | bugbear <bugbear@trim_papermule.co.uk_trim> |
|---|---|
| Date | 2012-10-26 17:00 +0100 |
| Message-ID | <zKidnVwRsYA8LhfNnZ2dnUVZ8i2dnZ2d@brightview.co.uk> |
| In reply to | #1019 |
Cecil Westerhof wrote: > At the moment I use Image Magick to generate pictures for quotes. For > example: > https://www.facebook.com/photo.php?fbid=391593267579727 > > This is fairly easy. But I was thinking about doing it with > postscript. But then I have define the size of the output and this is > depending on the input. Is there a way to solve this? > Speaking a long standing programmer in the graphics arts and pre-press industry, I'd stick with what you've got. Various things could be made to work, but unless you've got a BIG problem with your current process - don't change it. BugBear
[toc] | [prev] | [next] | [standalone]
| From | John Deubert <john@acumentraining.com> |
|---|---|
| Date | 2012-10-31 10:05 -0700 |
| Message-ID | <2012103110053683950-john@acumentrainingcom> |
| In reply to | #1020 |
On 2012-10-26 16:00:33 +0000, bugbear said:
> Cecil Westerhof wrote:
>> At the moment I use Image Magick to generate pictures for quotes. For
>> example:
>> https://www.facebook.com/photo.php?fbid=391593267579727
>>
>> This is fairly easy. But I was thinking about doing it with
>> postscript. But then I have define the size of the output and this is
>> depending on the input. Is there a way to solve this?
>>
>
> Speaking a long standing programmer in the graphics arts
> and pre-press industry, I'd stick with what you've got.
>
> Various things could be made to work, but unless you've got a BIG
> problem with your current process - don't change it.
>
> BugBear
I agree with bugbear that you should stick with your current process
unless some problem is compelling you to change it. That said, if you
really want to do this in PostScript, Below is some sample code.
- John
--
========
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
% ============ Cut here ==================
/$ShowInBox 8 dict def % Scratch dictionary
/ShowInBox % [(array)(of)(lines)] leading [offsetLeft offsetBottom
offsetRight offsetTop] [ boxColorrgb ] [textColorRGB] XBottom YBottom
{ $ShowInBox begin % Push our scratch dict on the dict stack
gsave
translate % Set the origin to the rect's location
/textRGB exch def % Save our arguments
/boxRGB exch def
/offsets exch def
/leading exch def
/lines exch def
/pointSize % Calculate the text's point size
1 1 currentfont /FontMatrix get transform pop
def
/maxLineLength 0 def % Find the length of the longest line
lines { stringwidth pop dup maxLineLength gt
{ /maxLineLength exch def } { pop } ifelse
} forall
/blockHt % Calc. the approximate height of the block of text.
lines length 1 sub leading mul % Note that this is approximate only.
pointSize add % Precision takes more work and is left as
def % an Exercise for the Student.
0 blockHt offsets dup 1 get exch 3 get add add translate % Translate
to the top left corner of the rect...
boxRGB aload pop setrgbcolor % ...and draw the rect
0 0
maxLineLength offsets dup 0 get exch 2 get add add % Width of the rect
blockHt offsets dup 1 get exch 3 get add add neg % Height of the rect
rectfill
textRGB aload pop setrgbcolor % Draw the text
offsets 0 get offsets 3 get pointSize add neg translate % Translate
to the posisition of the 1st line
0 0 moveto
lines { % For each line of text...
show % draw the text
0 currentpoint exch pop % and go to the next line.
leading sub moveto
} forall
grestore
end
} bind def
% Now let's try this baby out.
/Times-Italic 20 selectfont
[ (Twas brillig,)(and the slithy toves)(did gyre and gymbol)(in the wabe.)]
23 [ 10 10 10 5 ] [ 0 0 .7 ] [ 1 1 0 ] 200 300 ShowInBox
showpage
[toc] | [prev] | [next] | [standalone]
| From | Don Lancaster <don@tinaja.com> |
|---|---|
| Date | 2012-11-02 14:25 -0700 |
| Message-ID | <afis2pFp3tiU1@mid.individual.net> |
| In reply to | #1019 |
On 10/26/2012 3:30 AM, Cecil Westerhof wrote: > At the moment I use Image Magick to generate pictures for quotes. For > example: > https://www.facebook.com/photo.php?fbid=391593267579727 > > This is fairly easy. But I was thinking about doing it with > postscript. But then I have define the size of the output and this is > depending on the input. Is there a way to solve this? > < http://www.tinaja.com/glib/autourl.pdf > of course.
[toc] | [prev] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2012-11-03 02:50 -0700 |
| Message-ID | <984545f9-5847-4ac3-a2b6-6c973841fdf0@googlegroups.com> |
| In reply to | #1019 |
On Friday, October 26, 2012 5:35:20 AM UTC-5, Cecil Westerhof wrote: > At the moment I use Image Magick to generate pictures for quotes. For > > example: > > https://www.facebook.com/photo.php?fbid=391593267579727 > > > > This is fairly easy. But I was thinking about doing it with > > postscript. But then I have define the size of the output and this is > > depending on the input. Is there a way to solve this? > Caveat emptor of course, but I made the illustrations for this post http://codegolf.stackexchange.com/questions/8562/recreate-an-xkcd-graph-procedurally-with-your-favorite-plotting-tool/8853#8853 with the two commands 'ps2eps x.ps' 'convert x.eps x.png'. If want a background color, you need to hack that into the .eps *after* the bbox is calculated against the bare image. Otherwise, you're back to square one coming up with parameters for 'rectclip clippath fill'. :) Good Luck! BTW, if you come up with stickier problems, you *can* drag good stuff out of these other guys. Make it something to do with pdf-conversion. They'll be all over it!
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2012-11-24 18:21 +0100 |
| Message-ID | <87sj7ynchm.fsf@Compaq.site.inet> |
| In reply to | #1019 |
Op vrijdag 26 okt 2012 12:30 CEST schreef Cecil Westerhof:
> At the moment I use Image Magick to generate pictures for quotes. For
> example:
> https://www.facebook.com/photo.php?fbid=391593267579727
>
> This is fairly easy. But I was thinking about doing it with
> postscript. But then I have define the size of the output and this is
> depending on the input. Is there a way to solve this?
I have been experimenting a little. Below the code I have. A lot has
to be changed. For example instead of hard-coded the number of lines
should be calculated, the text should come from an input file, an
error should be generated when the text is to wide, the font-size
should between certain values be dependent on the widest line, the
colours and parameters should be selectable, I should use a better
font, …
But I have something that works and I can build on. The output is
posted to:
https://www.facebook.com/photo.php?fbid=447483758622570
%!PS-Adobe-3.0
%%Creator: Cecil Westerhof
%%Title: Sample Text Effects
%%LanguageLevel: 3
/backgroundColour {0 0 1} def
/fontsize 16 def
/pageWidth 404 def
/textColour {1 1 0} def
/x fontsize 2 mul def
/y 0 def
/lineHeight fontsize 5 add def
/pageHeight lineHeight 8 1.5 add mul def
/Bookman findfont fontsize scalefont setfont
<< /PageSize [pageWidth pageHeight] >> setpagedevice
backgroundColour setrgbcolor
0 0 pageWidth pageHeight rectfill
textColour setrgbcolor
(Four people are sitting in a lifeboat.)
(Two at the front and two at the back.)
(In the front there is a leak.)
(The two in the front)
(are frantically throwing water overboard.)
(One in the back says to the other:)
( What a luck)
( that the leak is not at our side.)
8 {
/y y fontsize 5 add add def
x y moveto
show
} repeat
showpage
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [next] | [standalone]
| From | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| Date | 2012-11-25 04:16 -0600 |
| Message-ID | <k8sr93$qu5$1@dont-email.me> |
| In reply to | #1070 |
Cecil Westerhof wrote:
> Op vrijdag 26 okt 2012 12:30 CEST schreef Cecil Westerhof:
>
>> At the moment I use Image Magick to generate pictures for quotes. For
>> example:
>> https://www.facebook.com/photo.php?fbid=391593267579727
>>
>> This is fairly easy. But I was thinking about doing it with
>> postscript. But then I have define the size of the output and this is
>> depending on the input. Is there a way to solve this?
>
> I have been experimenting a little. Below the code I have. A lot has
> to be changed. For example instead of hard-coded the number of lines
> should be calculated, the text should come from an input file, an
> error should be generated when the text is to wide, the font-size
> should between certain values be dependent on the widest line, the
> colours and parameters should be selectable, I should use a better
> font, ?
>
Palatino is the greatest font there is, IMHO.
> But I have something that works and I can build on. The output is
> posted to:
> https://www.facebook.com/photo.php?fbid=447483758622570
>
I hope you don't mind a few comments...
>
> %!PS-Adobe-3.0
The '3.0' part means you're asserting that the file conforms to the Document
Structuring Conventions. But you still need %%Pages and %%Page and perhaps
a few others. You can use '%!PS' or simply '%!' to identify the file as
Postscript without making any claims to DSC conformance. If you plan to run
the file through ps2eps, it'll add all the necessary comments for you.
> %%Creator: Cecil Westerhof
Creator is the software that generated the DSC comments. You are
the %%Author.
> %%Title: Sample Text Effects
> %%LanguageLevel: 3
>
> /backgroundColour {0 0 1} def
> /fontsize 16 def
> /pageWidth 404 def
You can get the page width for the current device with
clippath pathbbox ...
> /textColour {1 1 0} def
> /x fontsize 2 mul def
> /y 0 def
>
> /lineHeight fontsize 5 add def
This is commonly called 'lead' for the strips of lead (Pb) used to add space
for letterpress typography.
> /pageHeight lineHeight 8 1.5 add mul def
>
> /Bookman findfont fontsize scalefont setfont
>
> << /PageSize [pageWidth pageHeight] >> setpagedevice
Oh. Nevermind about the 'clippath' stuff above. :)
>
> backgroundColour setrgbcolor
> 0 0 pageWidth pageHeight rectfill
> textColour setrgbcolor
>
> (Four people are sitting in a lifeboat.)
> (Two at the front and two at the back.)
> (In the front there is a leak.)
> (The two in the front)
> (are frantically throwing water overboard.)
> (One in the back says to the other:)
> ( What a luck)
> ( that the leak is not at our side.)
>
> 8 {
> /y y fontsize 5 add add def
> x y moveto
> show
> } repeat
Wrap your text lines in an array [(line1)(line2)(line3)]. Then you can get
the count with 'length' and iterate through it with 'forall'. Also, you're
increasing the y value, when it would appear to make more sense to decrease
it (moving /down/ the page). One shortcut that avoids redefining y, is
{
gsave show grestore
0 lineHeight neg rmoveto
}
The grestore resets the currentpoint back to where it was when the
corresponding gsave was called. Then you don't have to touch the x
coordinate at all to move down a line.
>
> showpage
>
HTH. Good stuff, keep it coming!
[toc] | [prev] | [next] | [standalone]
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Date | 2012-11-25 22:29 +0100 |
| Message-ID | <87vcctl6c2.fsf@Compaq.site.inet> |
| In reply to | #1075 |
Op zondag 25 nov 2012 11:16 CET schreef luser droog:
> Palatino is the greatest font there is, IMHO.
Looks like it is not installed on my system. :-(
> I hope you don't mind a few comments...
Of-course not. In principal I like them. :-D
>> %!PS-Adobe-3.0
>
> The '3.0' part means you're asserting that the file conforms to the Document
> Structuring Conventions. But you still need %%Pages and %%Page and perhaps
> a few others. You can use '%!PS' or simply '%!' to identify the file as
> Postscript without making any claims to DSC conformance. If you plan to run
> the file through ps2eps, it'll add all the necessary comments for
> you.
Just copied from other files. I will delve into it.
>> %%Creator: Cecil Westerhof
> Creator is the software that generated the DSC comments. You are
> the %%Author.
OK.
>> /pageWidth 404 def
>
> You can get the page width for the current device with
> clippath pathbbox ...
I am making it for FaceBook, so I have to set it to 404 pixels.
>> /lineHeight fontsize 5 add def
>
> This is commonly called 'lead' for the strips of lead (Pb) used to add space
> for letterpress typography.
I am a programmer, not a graphical person, but willing to learn. ;-)
I'll take this into account also.
>> << /PageSize [pageWidth pageHeight] >> setpagedevice
>
> Oh. Nevermind about the 'clippath' stuff above. :)
It is still good to know when I do need it. :-D
>> backgroundColour setrgbcolor
>> 0 0 pageWidth pageHeight rectfill
>> textColour setrgbcolor
>>
>> (Four people are sitting in a lifeboat.)
>> (Two at the front and two at the back.)
>> (In the front there is a leak.)
>> (The two in the front)
>> (are frantically throwing water overboard.)
>> (One in the back says to the other:)
>> ( What a luck)
>> ( that the leak is not at our side.)
>>
>> 8 {
>> /y y fontsize 5 add add def
>> x y moveto
>> show
>> } repeat
>
> Wrap your text lines in an array [(line1)(line2)(line3)]. Then you can get
> the count with 'length' and iterate through it with 'forall'. Also,
> you're
I already am working with count (after putting the strings on the
stack). My next step was to go to work with an array. First of all I
then could go through it twice. First to check the width of the
strings and then the printing. Secondly I want to work with input from
a file. But let first learn to walk before I start running.
By the way, string width is linear to the font size? So when the
longest string is to long (or short) I can change the font size
without checking again.
> increasing the y value, when it would appear to make more sense to decrease
> it (moving /down/ the page). One shortcut that avoids redefining y,
> is
That is because I was popping things of the stack. I already changed
that by putting them reversed on the stack. At the moment I am working
with an array the problem is gone.
> {
> gsave show grestore
> 0 lineHeight neg rmoveto
> }
>
> The grestore resets the currentpoint back to where it was when the
> corresponding gsave was called. Then you don't have to touch the x
> coordinate at all to move down a line.
Nice touch. I'll incorporate it.
> HTH. Good stuff, keep it coming!
It does. Thanks for the help and also for the compliment. Both do not
hurt.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web