Print Page | Close Window

FitTextBox

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3347
Printed Date: 26 Apr 24 at 6:52AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: FitTextBox
Posted By: Ingo
Subject: FitTextBox
Date Posted: 18 Jun 16 at 9:07AM
a sample code from "rweetch".
How to reduce fontsize to fit into the area of a fix textbox:

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; 


-------------
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