font resizing algortihm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ajk

    #1

    font resizing algortihm

    I have a user control which displays a number say 12.2 and I would
    like to maximize the size of the number in the control. If a user
    changes the size of the control the number/font size should scale
    accordingly.

    At the moment I create a number of Font's; first large then smaller
    until it fits into the control, then from small to large until it no
    longer fits - then take largest fitting font size. This seems somehow
    like a resource demanding clumsy way so I was wondering if somebody
    knows a best practice for this?

    br/ajk
  • Clayton

    #2
    Re: font resizing algortihm

    On Jul 28, 9:08 am, ajk <a...@workmail. comwrote:
    I have a user control which displays a number say 12.2 and I would
    like to maximize the size of the number in the control. If a user
    changes the size of the control the number/font size should scale
    accordingly.
    >
    At the moment I create a number of Font's; first large then smaller
    until it fits into the control, then from small to large until it no
    longer fits - then take largest fitting font size. This seems somehow
    like a resource demanding clumsy way so I was wondering if somebody
    knows a best practice for this?
    >
    br/ajk
    hi,

    i've seen a good algorithm on Que's book for exam 70-316. when i find
    it i post back here

    Comment

    • Peter Duniho

      #3
      Re: font resizing algortihm

      ajk wrote:
      I have a user control which displays a number say 12.2 and I would
      like to maximize the size of the number in the control. If a user
      changes the size of the control the number/font size should scale
      accordingly.
      >
      At the moment I create a number of Font's; first large then smaller
      until it fits into the control, then from small to large until it no
      longer fits - then take largest fitting font size. This seems somehow
      like a resource demanding clumsy way so I was wondering if somebody
      knows a best practice for this?

      It _is_ resource demanding and a bit clumsy. But it's pretty much what
      you have to do.

      You can make a pretty good initial guess by finding the pixel size of
      some "standard" font size, and then scaling that according to the ratio
      of the size of the space in which you want the displayed text to fit to
      the size that you calculated. But for a perfect fit you will still need
      to test the calculated size and refine it based on the actual metrics.

      IMHO, if you want the least clumsy code and are willing to accept a
      situation where the font could be slightly larger but isn't, you should
      just calculate the ratio-based size, and then reduce it slightly
      iteratively until it fits. That at least avoids having the extra case
      of dealing with when it's too small (which is subtly different from the
      case when it's too big, requiring some almost-the-same-but-not-quite
      duplicated code).

      Pete

      Comment

      • ajk

        #4
        Re: font resizing algortihm

        On Sat, 28 Jul 2007 09:05:35 -0700, Clayton <clayton.curmi@ gmail.com>
        wrote:
        >hi,
        >
        >i've seen a good algorithm on Que's book for exam 70-316. when i find
        >it i post back here
        that would be great! thx!

        Comment

        Working...