Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting between WPF font size and "standard" font size

I've noticed in WPF, the default font size of 12 points is roughly equivalent to 9 points in "normal" applications (e.g. WordPad), 10 pt in WPF is roughly 7 pt standard, and when I try to match the default font size of 10 pt in WordPad in WPF, I've found 13 is the closest.

First of all, why does WPF use such bizarre non-standard font sizes, and secondly, is there a reliable way to convert between the two?

My reason for asking is I want to build a font size menu with "standard" font sizes of 9, 10, 12, 14, 16, 18, 24, 36, 48, but I'm pretty sure if I use those actual values they will be wildly off.

like image 390
devios1 Avatar asked Aug 09 '10 21:08

devios1


People also ask

What is the default WPF font?

In WPF, the default font family for text displayed on controls (like Label and Button) is Segoe UI, with a default size of 12.0 device-independent units. Because a device-independent unit is 1/96 inch, a FontSize value of 12 represents characters whose capitals are 1/8″ high.

What font size is 12px?

If the font-size you want is 12px , then you should specify 0.75em (because 12/16 = 0.75).

What is the default value of font size property?

Note: The default value for the font-size property is medium (16px) in all modern browsers like Firefox, Chrome, IE, Safari, Opera etc.


1 Answers

WPF uses pixels as its default unit for font size. The mapping between points (probably what you mean when you say "standard" font size) and pixels is: 1 pt = (96/72) px

This gives us a simple conversion function:

public static double PointsToPixels(double points) {     return points*(96.0/72.0); } 

See this question for more details.

like image 199
Joseph Sturtevant Avatar answered Oct 21 '22 15:10

Joseph Sturtevant