Font Scaling 
Author Message
 Font Scaling

VB6 I have two pictureboxes, pic1 & pic2 with a label in pic1.
pc2 is a different size but with the same aspect ratio.
Both have the same scalemode=vbpixels
I control the label size by the text caption and the label.fontsize.
I want the print text in pic2 to scale correctly and look like the pic1
apears.
I tried using width and height to scale the second, e.g.

pic1.fontsize=pic2.fontsize * pic2.width / pic1.width

but that is way off.

How do I scale the label.fontsize in pic1 such that Print label.caption in
pic2 apears  the same size in the pic2.  The only way I can think of is to
increment a label.fontsize in pic2 such that the ratio is equal.  Must be an
easier way to just calculate.



Thu, 03 Nov 2011 05:06:03 GMT  
 Font Scaling

Quote:
> VB6 I have two pictureboxes, pic1 & pic2 with a label in
> pic1. pc2 is a different size but with the same aspect ratio.
> Both have the same scalemode=vbpixels. I control the label
> size by the text caption and the label.fontsize. I want the print
> text in pic2 to scale correctly and look like the pic1 apears.
> I tried using width and height to scale the second, e.g.
>     pic1.fontsize=pic2.fontsize * pic2.width / pic1.width
> but that is way off.

Firstly your code as shown above is setting pic2.font.size as a proportion
of pic1.font.size whereas in fact it should be setting it as a proportion of
Label1.font.size. Also to get the correct ratio you need to use the
ScaleWidth rather than the width (or ScaleHeight rather than Height). And of
course you need to make sure that the pic2.font.name is the same as
Label1.font.name. Something like (air code):

Pic2.font.name = Label1.font.name
Pic2.font.size = Label1.font.Size * Pic2.ScaleWidth / Pic1.ScaleWidth

You also need to make sure that you are using a TrueType font (as opposed to
a bitmap screen font such as the default MS Sans Serif) because bitmap
screen fonts are extremely fussy about the sizes they can use. TrueType
fonts are themselves slightly limited in that all point sizes you ask for
will actually produce the nearest equivalent point size that is a "whole
pixel" value on the specific output device (the screen in your case) but
TrueType fonts can have a wide range of sizes subject to that limitation, so
you will get much closer to the actual point size you require.

What, exactly, is the overall task you are trying to accomplish? I ask
because there may be more reliable ways of achieving your aims, depending on
exactly what it is you are trying to do and on how much work you are
prepared to put in to do it.

Mike



Thu, 03 Nov 2011 06:00:57 GMT  
 Font Scaling
Well, I cheated and incemented a label.fontsize on pic2 until it was >= the
proprotionalte desired value.  This works fine and is fast enough for all
fonts I have tested.
Thanks for the info about truetype etc.
Doing? Allow the user to size some text in a thumbnail pic1 and then apply
it to the final image pic2 and make it look much like the thumbnail.
So far so good.
Quote:



> > VB6 I have two pictureboxes, pic1 & pic2 with a label in
> > pic1. pc2 is a different size but with the same aspect ratio.
> > Both have the same scalemode=vbpixels. I control the label
> > size by the text caption and the label.fontsize. I want the print
> > text in pic2 to scale correctly and look like the pic1 apears.
> > I tried using width and height to scale the second, e.g.
> >     pic1.fontsize=pic2.fontsize * pic2.width / pic1.width
> > but that is way off.

> Firstly your code as shown above is setting pic2.font.size as a proportion
> of pic1.font.size whereas in fact it should be setting it as a proportion of
> Label1.font.size. Also to get the correct ratio you need to use the
> ScaleWidth rather than the width (or ScaleHeight rather than Height). And of
> course you need to make sure that the pic2.font.name is the same as
> Label1.font.name. Something like (air code):

> Pic2.font.name = Label1.font.name
> Pic2.font.size = Label1.font.Size * Pic2.ScaleWidth / Pic1.ScaleWidth

> You also need to make sure that you are using a TrueType font (as opposed to
> a bitmap screen font such as the default MS Sans Serif) because bitmap
> screen fonts are extremely fussy about the sizes they can use. TrueType
> fonts are themselves slightly limited in that all point sizes you ask for
> will actually produce the nearest equivalent point size that is a "whole
> pixel" value on the specific output device (the screen in your case) but
> TrueType fonts can have a wide range of sizes subject to that limitation, so
> you will get much closer to the actual point size you require.

> What, exactly, is the overall task you are trying to accomplish? I ask
> because there may be more reliable ways of achieving your aims, depending on
> exactly what it is you are trying to do and on how much work you are
> prepared to put in to do it.

> Mike



Thu, 03 Nov 2011 07:59:01 GMT  
 Font Scaling

Quote:
> Well, I cheated and incemented a label.fontsize on
> pic2 until it was >= the proprotionalte desired value.
> This works fine and is fast enough for all fonts I have
> tested. Thanks for the info about truetype etc.

Actually, especially when dealing with low resolution devices such as the
screen (or a VB Form or PictureBox or whatever), even if you calculate the
desired point size directly you still usually need to do something along
those lines to "fine tune" the result because of the fact that the printed
widths of each individual character in the string are rounded either up or
down to the nearest whole pixel, resulting in a string of text almost never
being (for example) exactly twice the printed width when printed at twice
the point size, and often being considerably different than twice the width,
with some strings being significantly smaller than expected and others being
significantly larger than expected, depending on the specific characters
they contain.

So, if you're happy with that method then that's fine, although personally I
would save a bit of time by first calculating the approximate desired point
size (which can be done extremely quickly) and testing the actual textwidth
at that point size and then testing the textwidths of various point sizes up
or down from that point depending on the result until you reach an
acceptable width. There are of course other ways to make sure a printed
string is approximately the desired printed length, and there are also ways
of making it exactly the desired printed length, but the method you are
using works fine and fairly quickly using just native VB methods.

By the way, to get a point size as close as possible to the point size
required to produce your desired textwidth then I would advise you to alter
the point size by 0.5 at each iteration rather than 1 (if that is the
increment you are currently using). Changing the point size by 0.5 at each
iteration will allow your code to test up 30 per cent more actual available
point sizes than an increment of one, and up to 60 per cent more actual
available point sizes on some systems.

Mike



Thu, 03 Nov 2011 21:51:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Font scaling problem...

2. Restore font size in scaled Graph (in PPT)

3. Avoiding window scaling when large system fonts are used

4. Scaling a Window depending on font size

5. Correct scaling of vertical fonts - solution

6. Scaling fonts

7. Font Size/Scaling problem with print preview

8. Fonts, Fonts and damn Fonts!!!!!

9. font fOnt foNt fonT foNT? argh.

10. <font color=red><font size=256>S.O.S.!!!</font></font>

11. Get width of text in pixels (taking into account font, font size and style)

12. Userform fonts not obeying font property specs

 

 
Powered by phpBB® Forum Software