Font Sizing

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
qrstuvlmnopAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SimesACommented:
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
Slick812Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sassas081597Commented:
Hi
How about to change the font size of the textbox in order  to either get the TextWidth=60 or TextHeight=40?
sassas
0
qrstuvlmnopAuthor Commented:
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
Slick812Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.