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

I need to make a lot of drawings on a grid with an interval of 12.5 pixels X and 20 pixels Y (PICA scale). The font should be a certain size, and the lines should still be one pixel. Currently, I save these values ​​in floats and multiply them (for example, text starting on line 3, column 6 is drawn as 2f * cx, 5f * cy coordinates). I would like to avoid all this unnecessary multiplication using scale conversion, but, unfortunately, this affects the font size and line thickness. Is there any way to avoid this? Or will the compiler silently do this for me, since cx / cy values ​​are constants?

+3
source share
2 answers

The compiler should reduce the constant part of the expressions to one constant, but still have to multiply at run time, since the value of your float is unknown at compile time. So, (1 + 2 + c) * 6 * f can be reduced to n * f by the compiler if c is a constant.

It’s best to prevent the text from scaling, perhaps adjust the scaling transformation, draw all your non-text graphics that you don’t care about the minimum line width, and then draw the text without using the transformation. You can use the transform to find where the text should start, to save yourself, to calculate it independently - a function like LPtoDP (logical point to device point) should do the trick.

, . , 5%, 5%. , .

+1

... , Microsoft "", , . 0px, .

+6

Source: https://habr.com/ru/post/1778138/


All Articles