Convert the Font size in inch

五迷三道 提交于 2019-12-10 11:02:00

问题


I need to convert between Drawing.Font.Size (float, ?) and WPF FontSize (double, WPF pixels).

Finally, I decided to store in the database the fontSize in inch...

How can I convert the GDI FontSize to inch and the WPF FontSize to inch?

sizeInInch = wpfFontSize / 96
sizeInInch = gdiFontSize / ?

Can I use something DPI independent? Maybe System.Windows.FontSizeConverter?

I need to convert to something, that will allow me to switch multiple time between WPF and GDI without changing the "real value".

Each division and following multiplication will accumulate errors...

FontSizeConverter does a ConvertTo, but I don't understand to use it: say

myUniversalFontSize = (double)(myFontSizeConverter.ConvertFrom(
    gdiFont.SizeInPoints.ToString() + "pt"))

will transform my gdiFont size in ...? WPF Pixels?

How now should I convert back that value to GDI?

gdiFont.SizeInPoints = myUniversalFontSize / 96 * 72???

Can I use in the second example the myFontSizeConverter too?


回答1:


See documentation http://msdn.microsoft.com/en-us/library/system.windows.controls.control.fontsize.aspx

"in is inches; 1in==96px"

Use a LengthConverter for conversion. http://msdn.microsoft.com/en-us/library/system.windows.lengthconverter.aspx




回答2:


Don't know much about the WPF stuff, but if there is a method to convert from pixels to points, you can use the scale of 1 inch = 72 points.



来源:https://stackoverflow.com/questions/9840810/convert-the-font-size-in-inch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!