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. On Mac OS X we used StringWidth(Const开发者_如何学GoStr255Param s), however since OS X 10.4 this has been deprecated. So my question is, how would one go about successfully calculating the width of a string on OS X 10.4 and higher.
For Cocoa, utilizing the technique for calculating string height should get you going if you use an arbitrary large value for the containers width instead of height.
精彩评论