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


Groups > comp.lang.postscript > #1023

Re: How to make bounding box depending on input text

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Wed, 31 Oct 2012 12:05:36 -0500
From John Deubert <john@acumentraining.com>
Organization Acumen Training
Newsgroups comp.lang.postscript
Date Wed, 31 Oct 2012 10:05:36 -0700
Message-ID <2012103110053683950-john@acumentrainingcom> (permalink)
References <87vcdxy187.fsf@Compaq.site> <zKidnVwRsYA8LhfNnZ2dnUVZ8i2dnZ2d@brightview.co.uk>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Subject Re: How to make bounding box depending on input text
User-Agent Unison/2.1.9
Lines 99
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-LIy049AAtoTSqVAE4BX/NmS+zfIrb6J540PeWovJuHJosIGSkF07RWDB3ebKMSTXYuemefKO3KCOV1S!AcHIVyQc8hiftTtBU7DF7MyF+LxgH1Vw3YUy3j63P7JAp3fJStEVhTY/3uzY9f/vFxabWX8O
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 4210
Xref csiph.com comp.lang.postscript:1023

Show key headers only | View raw


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


Back to comp.lang.postscript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web