简体   繁体   English

DirectWrite字体拉伸

[英]DirectWrite font stretching

I want to use DirectWrite to stretch a font vertically or horizontally by x percent. 我想使用DirectWrite将字体垂直或水平拉伸x%。

I'm using IDWriteTextFormat::CreateTextFormat and IDWriteFactory::CreateTextLayout and DrawTextLayout. 我正在使用IDWriteTextFormat :: CreateTextFormat和IDWriteFactory :: CreateTextLayout和DrawTextLayout。

The DWRITE_FONT_STRETCH enumeration passed into CreateTextFormat is too coarse and doesn't give me enough control. 传递给CreateTextFormat的DWRITE_FONT_STRETCH枚举过于粗糙,无法提供足够的控制权。 For example, instead of "semi-condensed" I want exactly 71% vertically condensed. 例如,我要的是71%的垂直冷凝,而不是“半冷凝”。

So far I can't figure out how to do this without direct2d scaling transformations or using GDI. 到目前为止,我不知道如何在没有Direct2d缩放转换或使用GDI的情况下执行此操作。 I'd rather avoid using GDI's LOGFONT because it will make my application much more complicated. 我宁愿避免使用GDI的LOGFONT,因为这会使我的应用程序更加复杂。

Font stretch specified with DWRITE_FONT_STRETCH is meant to be used for matching process only. 用DWRITE_FONT_STRETCH指定的字体拉伸仅用于匹配过程。 Treat it as an input argument for matching logic - you specify desired stretch (and other parameters) and DirectWrite picks "closest" font. 将其视为匹配逻辑的输入参数-您指定所需的拉伸(和其他参数),然后DirectWrite选择“最接近”的字体。 Strictly speaking different stretch values do not imply any different visual appearance, it's a metadata that font designer specified. 严格说来,不同的拉伸值并不意味着任何不同的视觉外观,它是字体设计师指定的元数据。 Now what you're asking sounds more like variable fonts, when variable font supports stretch axis you can set it to any value in allowed range and get different rendering results. 现在,您的要求听起来更像是可变字体,当可变字体支持拉伸轴时,您可以将其设置为允许范围内的任何值,并获得不同的渲染结果。

Of course you can transform outlines manually, scale along coordinate axis if you wish. 当然,您可以手动变换轮廓,如果需要,可以沿坐标轴缩放。 But that has its own limitations. 但这有其局限性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM