I have written a test application that draws text (among other things) on the screen. Before I draw, I scale values of X, Y, Width, Height, and Size according to the ration of the wanted width, and the actuial width of the form. The problem is, when I call Graphics.DrawString, I notice that the fonts change in "steps". Keep in mind, I have set the units to inches, and I supply inches in, and in GENERAL the resulting size is the correct size, but it doesn't smoothly scale (unlike the lines and such). Is there any way to get around this?
Code Snippet
Font TextFont = new Font(this.FontFamily, (float)(this.Size * PageScale), fs, GraphicsUnit.Inch);
g.DrawString(this.Text, TextFont, new SolidBrush(Color.FromName(this.FontColor)),
new RectangleF(
DrawRect.X + ((float)(this.Left * PageScale) * (float)DPI),
DrawRect.Y + ((float)(this.Top * PageScale) * (float)DPI),
((float)(this.Width * PageScale) * (float)DPI ),
((float)(this.Height * PageScale) * (float)DPI )
));
<Edit>
Heres an idea of what I'm talking about:
http://i10.tinypic.com/4v68svc.png
When you grow and shrink the width of the form, between the 'steps' of the font sizing, theres a gap between the bottom of the text and the bottom of the black box. | | Essial Saturday, August 18, 2007 5:20 AM | I setup a sample as best I could with your code, but I'm not sure if I am duplicating it exactly because I don't know the following:
-
What is "this.Size" is referring to?
-
How does "PageScale" get set (what is the calculation/value)?
-
How do you set the"X" and "Y" propertiesof"DrawRect"?
-
How you get/set the value of "DPI"?
-
Does "this" refer to a Form, or some other type of object/class? Some of the code you have implies that it does, yet there are a couple properties in your code that aren't part of a Form... so either you added custom properties to a Form or it isn't a Form.
The other thing that would be good for you to post is the code you use for drawing the rectangle around the text. When I ran my code, then slowly increased the width of the form, I didn't see any dramatic "stepping" occuring. So either I didn't set my value correctly, or it has to do with how you draw/scale the rectangle around the text.
Any chance you could post the code for drawing the rectangle, and maybe give some more insight into how we can more closely duplicate your code (could you provide more code?).
Thanks | | ARK88 Saturday, August 18, 2007 1:35 PM | http://files-upload.com/files/442150/testform.zip
Is a demo of what I'm doing. Just make sure the files are all in the same dir. If you resize, you'll see what I mean.
As far as drawing the rect, I use simple scailing and convert the units from inches to pixels.
Code Snippet
g.FillRectangle( new SolidBrush(Color.Black), new RectangleF(
DrawRect.X + (( float)(this.Left * PageScale) * (float)DPI),
DrawRect.Y + (( float)(this.Top * PageScale) * (float)DPI),
(( float)(this.Width * PageScale) * (float)DPI ),
(( float)(this.Height * PageScale) * (float)DPI )
));
this.Size refers to the font size in inches.
Pagescale:
Code Snippet
PageScale = ((( decimal)(PageRect.Width / (decimal)g.DpiX)) / this.Width);
I get DPI from g.DpiX. | | Essial Saturday, August 18, 2007 3:06 PM | Having run the application, and then referring back to your original question, I'm not sure I know which black box you are talking about... because the original post talks of text in a black box with a gap, the image link in the original post you provided shows text in a black box with no gap, the application has text in a black box with no gap on the first page, and the application also has text in a black box with a gap on the second page... so, which black box are you referring to? The one on the first page of the application or the second page?
In regard to smooth font scaling, I am by no means an expert on Fonts, but I don't think fonts do [natively] what you are trying to accomplish. I thought for a minute that maybe Adobe PDFs did it, but upon reviewing some PDFs I'm pretty sure those fonts step as well. I even checked out MS Word to see what would happen there, and it looks to be stepping also. The only way I could think of getting smooth font scaling would be to do some simulation of it by rendering your information to an off-screen buffer at a constant [non-scaled] size, then rendering it to the screen and utilizing some of the graphics image scaling techniques. I don't know enough about your application to know if that is a feasible option, but if the user is only viewing the information (i.e. not typing, clicking, highlighting, etc...) then maybe it is worth the effort if smooth scaling is that important to you. Then again, maybe someone will correct my misguided assumptions that fonts can't scale smoothly.
| | ARK88 Tuesday, August 21, 2007 5:13 AM | We are changing the issue type to “Comment�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions. Thank you!
| | Yu Guo �MSFT Friday, August 24, 2007 7:36 AM |
|