473,385 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

font resizing algortihm

ajk
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
Jul 28 '07 #1
3 1414
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

Jul 28 '07 #2
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
Jul 28 '07 #3
ajk
On Sat, 28 Jul 2007 09:05:35 -0700, Clayton <cl***********@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!
Jul 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Martin Ernst | last post by:
Hello! I wonder which font is normally used in IE (6) for windows if i use "sans-serif" as font-family. Does anybody know it? Thanks Martin
12
by: AussieTraders.com.au | last post by:
Should I use <font size=-2> or <font size=1>?? They seem to give the same results... I wish to be able to set the default font family and font size for a website and STILL SUPPORT _fluid_texts_....
23
by: BobK | last post by:
Hello Everyone, I am updating the CSS for my site but want new and original page to appear the same. My original CSS permits small increments of zooming (ctrl/mouse wheel) so that you get...
48
by: Nirvana | last post by:
How to make the font size constant in HTML code, so that in a web browser it remains fixed. For e.g in IE if you press CTRL and move mouse wheel front or back the font size changes, cheers
12
by: newspost2000 | last post by:
http://www.htmldog.com/articles/elasticdesign/demo/ I found this wonderful site the demonstrates how you cannnot resize text formated using styles in ie 6 if you specify font size using pt units...
40
by: Paul Davis | last post by:
Hi all, I'm building some style sheets and trying to play the old game of balancing designer pixel perfection and still allowing users to adjust their font sizes. The compromise I've made with the...
2
by: Matthias Pospiech | last post by:
I need a fast and reliable FFT algorithm in C++. I found a C algorithm on the webseite http://www.fftw.org/index.html (FFTW). But I am stuck at the point howto actually use the algortihm and...
24
by: Harris Kosmidis | last post by:
I have a site up and running (www.solsoft.gr). I tested it with FF2 and IE6 and works ok with some IE hacks. Ok the CSS isn't good cause I started designing it with another look and the customer...
0
by: igalep132 | last post by:
Hey all, I was trying to resize control size to the form size. I'm changing my form size according to current Screen Size by using Screen.PrimaryScreen.WorkingArea; and then I'm making a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.