|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Font ScalingVB6 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. "Bee" <B**@discussions.microsoft.com> wrote in message Firstly your code as shown above is setting pic2.font.size as a proportion news:0A753041-55FD-4161-98C6-F201E6CC2770@microsoft.com... > 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. 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 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. Show quoteHide quote "Michael Williams" wrote: > "Bee" <B**@discussions.microsoft.com> wrote in message > news:0A753041-55FD-4161-98C6-F201E6CC2770@microsoft.com... > > > 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 > > > > "Bee" <B**@discussions.microsoft.com> wrote in message Actually, especially when dealing with low resolution devices such as the news:E4047A90-58DE-426C-9DE8-DBEA2EDA406A@microsoft.com... > 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. 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
Help using SendMessage() function
can the loading of a large number of records go as quick as in DOS Auto Spacing Labels in 2D Graph What is Sendkeys Chr(188)? 8 to 24 Download website OLEDragDrop custom format Refresh a form FMLabs FMTKit functions BigInteger and BigDecimal [equivalents] for VB.NET? |
|||||||||||||||||||||||