简体   繁体   English

在Mac OS X上相当于GetTextExtentPoint32

[英]GetTextExtentPoint32 equivalent on Mac OS X

I am working on a cross platform library that needs to draw text using fonts into a device context. 我正在跨平台库上工作,该库需要使用字体在设备上下文中绘制文本。 The width of the text combined with the user selected font is proving difficult to calculate. 事实证明,与用户选择的字体结合的文本宽度很难计算。

In Windows we use BOOL GetTextExtentPoint32(HDC hdc, LPCTSTR lpString, int cbString, LPSIZE lpSize) this works without problem. 在Windows中,我们使用BOOL GetTextExtentPoint32(HDC hdc,LPCTSTR lpString,int cbString,LPSIZE lpSize)可以正常工作。 On Mac OS X we used StringWidth(ConstStr255Param s), however since OS X 10.4 this has been deprecated. 在Mac OS X上,我们使用StringWidth(ConstStr255Param s),但是自OS X 10.4起,此功能已被弃用。 So my question is, how would one go about successfully calculating the width of a string on OS X 10.4 and higher. 所以我的问题是,如何在OS X 10.4及更高版本上成功计算字符串的宽度。

对于可可,如果对容器的宽度而不是高度使用任意大的值,那么利用计算字符串高度的技术应该可以帮助您。

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

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