Print Page | Close Window

Fit Text to a non regular shape

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1874
Printed Date: 22 Nov 24 at 7:22PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Fit Text to a non regular shape
Posted By: rweetch
Subject: Fit Text to a non regular shape
Date Posted: 30 Jun 11 at 6:02PM
I have an area on my pdf which is to be populated with text. This isn't a regular shape and the top and bottom rows are about 60% the width of the centre section so the text would need to be something like
 
            here is some
text that needs to
fit into a very strange
shape
 
and it needs to be filled from the middle out.
 
I thought of defining 3 areas. But how to decide what text to place in what area.....
 
Any ideas very gratefully received!



Replies:
Posted By: Rowan
Date Posted: 30 Jun 11 at 8:49PM
Well that is kind of tricky. It might be that you have to make a call to DrawText for each line. I'm not sure how else you can do this, unless you were to use the DrawHTMLTextBox function and use the space HTML tag to indent the text, but this would require a bit of trial and error to get the indenting right, while matching the width and height of the text box and font size.


Posted By: rweetch
Date Posted: 01 Jul 11 at 11:18AM
Thansk Rowan. Thinking along similar path. My Idea is to use DrawTextBox to draw the text. General approach is:
 
1. Find Lines per Box (something like Box Height / Text Height)
2. Find out how many lines the text will take (GetTextWrappedLineCount)
3. If LineCount is Greater than LinesPerBox - 2 then
4. Calculate textWidth of a space character
5. Pack the fron of the text with the required number of spaces.
 
probably need to do some iterations.
 
Does that sound sane?
 


Posted By: Rowan
Date Posted: 01 Jul 11 at 11:48AM
Your approach sounds good but you may need to use the DrawHTMLTextBox function and explicitly insert the spaces because otherwise I believe they will automatically be removed. Much like in HTML where there is only ever one space between two words unless you explicitly insert a space tag.


Posted By: rweetch
Date Posted: 10 Aug 11 at 4:34PM
Out of interest the final solution for this was as follows. The area to be filled is specified by a formfield, but this is just a place holder and not used except to get height, width, font etc.
 
1. Find Lines available per box (Box Height / Text Height)
2. Break the text into lines using the GetWrappedText method
3. Calculate the width of the first line (60% of the box width)
4. Get the text width of the first line
5. if it is too wide for the first line then use GetWrappedText to find out how much will fit. Add the remaining text back to the rest of the text and run through GetWrappedText again to get the remaining lines.
6. write the text to the document using DrawTextBox for each line, setting alignment as necessary.
 
code if you are interested:
//uW := width of field
       ts := TStringlist.Create;
       try
         ts.Text := PDFLibrary.GetWrappedText(uW, #13#10, uText);  
         nW := uW * 0.6;
         if PDFLibrary.GetTextWidth(ts[0]) > nW then
         begin
           js := TStringList.Create;
           try
             js.Text := PDFLibrary.GetWrappedText(nW, #13#10, ts[0]);
             ts.Clear;
             ts.Text := PDFLibrary.GetWrappedText(nW, #13#10, copy(uText, length(js[0]) + 1, length(uText)));
             ts.Insert(0, js[0]);
           finally
             js.Free;
           end;
         end;


Posted By: rweetch
Date Posted: 10 Aug 11 at 4:35PM
Now just to work out how to that for HTML Text



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk