gpt4 book ai didi

fonts - 在 WinRT 中计算字体基线

转载 作者:行者123 更新时间:2023-12-01 03:57:39 25 4
gpt4 key购买 nike

我想找出baseline of a font在 WinRT 中。

我还通过 creating a dummy TextBlock 计算了特定字体的文本大小,但我不确定如何计算基线。这在 WinRT 中甚至可能吗?

最佳答案

不幸的是,您要找的是FormattedText [MSDN:1 2 ] 存在于 WPF 中,而在 WinRT 中不存在(我什至不认为它甚至在 Silverlight 中)。

它可能会包含在 future 的版本中,因为它似乎是一个非常受追捧的功能,非常想念并且团队意识到它被遗漏了。看这里:http://social.msdn.microsoft.com .

如果您有兴趣或真的,真的需要一种方法来测量字体的细节,您可以尝试为 编写一个包装器。直写 据我所知,它位于 WinRT 可用技术堆栈中,但只能通过 C++ 访问

如果您想尝试,这里有几个起点供您引用:

  • these guys seem to actually be using DirectWrite in a WinRT app
  • this is a wrapper for C++ making DX available, DirectWrite would bemuch of the same

  • 希望这会有所帮助,祝你好运 -ck

    更新

    我想了想,想起了 TextBlock s 拥有经常被遗忘的属性(property) BaselineOffset这为您提供了所选字体从框顶部的基线下降!因此,您可以使用每个人都使用的相同 hack 来替换 MeasureString代替 FormattedText的损失.酱汁来了:
        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;
    }

    我用它来做到这一点:
    screenshot

    完美的!对?希望这有帮助 -ck

    关于fonts - 在 WinRT 中计算字体基线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15862600/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com