Calculate basic font level in WinRT

I would like to know the basic font in WinRT.

I also calculated the text size for a specific font by creating a dummy TextBlock , but I'm not sure how to calculate the baseline. Is this possible in WinRT?

+4
source share
1 answer

Unfortunately, you are looking for a FormattedText [MSDN: 1 2 ] that exists in WPF and does not exist in WinRT (I don’t even think it is even in silverlight yet).

It will probably be included in a future version, because it seems to be a very popular feature, it is greatly missed, and the team is aware of its omission. See here: http://social.msdn.microsoft.com .

If you are interested or really really need a way to measure the specifics of a face type, you can try writing a wrapper for DirectWrite , which, as far as I know, is in the available WinRT stack technology, but it is only available through C ++

here are a couple of jumping points for you if you want to try:

hope this helps, good luck -ck

Update

I thought about this a bit and remembered that TextBlock has the forgotten BaselineOffset property, which gives you the base drop from the top of the window for the selected face type! So you can use the same hack that everyone uses to replace MeasureString to replace the loss of FormattedText . Here's the sauce:

  private double GetBaselineOffset(double size, FontFamily family = null, FontWeight? weight = null, FontStyle? style = null, FontStretch? stretch = null) { var temp = new TextBlock(); temp.FontSize = size; temp.FontFamily = family ?? temp.FontFamily; temp.FontStretch = stretch ?? temp.FontStretch; temp.FontStyle = style ?? temp.FontStyle; temp.FontWeight = weight ?? temp.FontWeight; var _size = new Size(10000, 10000); var location = new Point(0, 0); temp.Measure(_size); temp.Arrange(new Rect(location, _size)); return temp.BaselineOffset; } 

and I used this for this: screenshot

excellent! right? hope this helps -ck

+2
source

All Articles