开发者

C# Scaling GDI positions but not font size or line thickness

I need to do a lot of drawing on a grid with spacing of 12.5 pi开发者_如何学运维xels X and 20 pixels Y (the PICA scale). The font needs to be a specific size and the lines need to still be one pixel thick. Currently I'm saving these values in floats and multiplying them (for example, text starting on row 3, column 6 is drawn as coords 2f*cx,5f*cy). I'd like to avoid all this unnecessary multiplication by using a scale transform, but unfortunately those affect the font size and line thickness as well. Is there a way to avoid this? Or would the compiler be silently doing this for me as the cx/cy values are constants?


...also, Microsoft has left a little "hack" for us if you don't want lines to be scaled. Set the width of the line to 0px, and it will always be drawn a single pixel thick.


The compiler should reduce the constant portion of expressions to a single constant, but there will still have to be a multiply at runtime since the value of your float is not known at compile time. So, (1 + 2 + c) * 6 * f can be reduced to n * f by the compiler if c is a constant.

Your best bet to prevent scaling of your text is probably to set up a scaling transform, draw all your non-text graphics that you don't care about maintaining minimum line widths, then draw your text without using the transform. You can use the transform to locate where the text should start to save yourself having to calculate that independently - a function like LPtoDP (logical point to device point) should do the trick.

Another other way to approach this is to render the text in the transform, but apply a reverse scaling to the text size itself. So, if the transform scales down 5%, you scale the font size up by 5%. This will not give exact results, but might be close enough for visuals.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜