Print Page | Close Window

FitTextBox but do not increase the fontsize

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=3344
Printed Date: 04 May 24 at 2:33PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: FitTextBox but do not increase the fontsize
Posted By: rweetch
Subject: FitTextBox but do not increase the fontsize
Date Posted: 15 Jun 16 at 7:20PM
The FitTextBox method allows you to specify the option to expand the font size (add 1000 to the options argument) so that the text fills the space available.

What I want to do is reduce the font size so the text always displays (without wrapping) in the space available, but not to ever increase the font's size.

An example would be an address, if it fits the area with the current font size then fine, leave it as it is. However if it doesn't fit, reduce the fontsize until it does.

Thanks 



Replies:
Posted By: rweetch
Date Posted: 17 Jun 16 at 3:12PM
I couldn't see how to do this using the methods, so rolled my own and added it to my TDebenuPDFLibrary Helper. Here's the code if you are interested:


procedure TsmDebenuPDFLibraryHelper.DrawDownScaledText(const aText: string; const X, Y aWidth, aHeight: Double);
var lTextSize, lStartSize: Double;
begin

  lStartSize := GetTextSize;
  lTextSize := lStartSize;

  if GetWrappedTextHeight(aWidth, aText) > aHeight then
  begin
    
     lTextSize := lStartSize;

    repeat

       lTextSize := lTextSize * 0.95;

       SetTextSize(lTextSize);

       until (GetWrappedTextHeight(aWidth, aText) <= aHeight);

  end;

  DrawWrappedText(X, Y, aWidth, aText);

   if lTextSize < lStartSize then
      SetTextSize(lStartSize);

end;


Posted By: Ingo
Date Posted: 18 Jun 16 at 9:07AM
Hi,

i've put it into the samples section ;-)
Thanks :)



-------------
Cheers,
Ingo




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