Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Font Sizing

Posted on 2003-03-17
5
Medium Priority
?
248 Views
Last Modified: 2013-12-02
I am trying to size Text to fit a box. I want the text to fit as closely as possible. For example I have the word "Super" and I want to fit it in a box 40 pixels X 60 pixels. What do I need to tweak in order to accomplish this. I have tried messig with the point size but that dosn't give the disired effect.

Apps like corel draw, arts and letters, openoffice, etc. do this sort of thing. I just thought that maybe someone had some experience with tweaking fonts. The fonts have to be tweaked in many different ways. Some situations will produce short fat letters and others will produce tall skinny letters. I realize that it may be impossible to get a perfect fit within the box but some reasonable estimate should be possible.

Thanks
0
Comment
Question by:qrstuvlmnop
5 Comments
 
LVL 1

Expert Comment

by:SimesA
ID: 8155122
My best guess, and it is a guess, would be to draw the text to a bitmap of size TextWidth(Text) x TextHeight(Text) and then StretchDraw that bitmap to the desired rectangle.
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 60 total points
ID: 8155991
hello qrstuvlmnop , there are several ways to size fonts for a word to fit a certain width, but to fit both the width and height, might be a problem, I would use a TMetaFile, and the suggestion of SimesA, ,  of resizing it to the dimentions you need. maybe like this -


procedure TForm1.button_FitTextClick(Sender: TObject);
var
Emf1: TMetaFile;
begin
Emf1 := TMetafile.Create;
try
  Emf1.Enhanced := True;
  Emf1.Transparent := True;
  Canvas.Font.Name := 'Times New Roman';
  Canvas.Font.Height := -20;
  Emf1.Width := Canvas.TextWidth('Super');
  Emf1.Height := Canvas.TextHeight('Super');
{set the Emf height and width to the textHeight and textWidth}
  with TMetafileCanvas.Create(Emf1, 0) do
    try
      Font.Assign(Canvas.Font);
      SetBkMode(Handle, 1);
  {set the background Mode to Transparent}
      TextOut(0,0,'Super');
      finally
      Free;
      end;
  Canvas.Draw(100,200, Emf1);
  Emf1.Width := 60;
  Emf1.Height := 40;
{unlike a Bitmap, when you change the size of a MetaFile
everything on the metafile changes size to match the new dimentions
also there is No pixelization, when you make it larger, even
very much larger}
  Canvas.Draw(120,260, Emf1);
  Emf1.Width := 340;
  Emf1.Height := 280;
  Canvas.Draw(20,240, Emf1);
  finally
  Emf1.Free;
  end;

end;


 - - - - - - - - -  - - - - - - - - - - - - - -
you can resize the Emf1, by just changing the with and height, and when you draw it on a canvas it will appear like a text draw. . .  ask questions if you need more
0
 
LVL 1

Expert Comment

by:sassas081597
ID: 8157646
Hi
How about to change the font size of the textbox in order  to either get the TextWidth=60 or TextHeight=40?
sassas
0
 

Author Comment

by:qrstuvlmnop
ID: 8182468
Thank You, Slick812.
This Solution Works quite well.
I am also working on a solution that will envolve converting the font outline to a bezier curve and then resizing the curve to fit the box.  I'll post my solution if I ever get it to work.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8182959
I have tried that, but it takes more than I could do to get the font drawing functions from the font file. . .  Good Luck, and Post the code if you are able to do that
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question