Fix GetPartialTextExtents() to handle non-BMP chars under OS X
On OS X, wxString operates on UTF-32 code units, but CoreText API use UTF-16 code units. So we need to take care of surrogate pairs. Closes https://github.com/wxWidgets/wxWidgets/pull/261
This commit is contained in:
committed by
Vadim Zeitlin
parent
55d77f271e
commit
cf000e7e02
@@ -81,6 +81,7 @@ wxMSW:
|
||||
|
||||
wxOSX:
|
||||
|
||||
- Fix handling of non-BMP characters in GetPartialTextExtents() (ARATA Mizuki).
|
||||
- Remove extra borders around wxFilePickerCtrl (John Roberts).
|
||||
- Set up extensions filter correctly in wxFileDialog (nick863).
|
||||
- Turn off automatic quotes substitutions in wxTextCtrl (Xlord2).
|
||||
|
@@ -2360,8 +2360,7 @@ void wxMacCoreGraphicsContext::GetTextExtent( const wxString &str, wxDouble *wid
|
||||
|
||||
void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const
|
||||
{
|
||||
widths.Empty();
|
||||
widths.Add(0, text.length());
|
||||
widths.clear();
|
||||
|
||||
wxCHECK_RET( !m_font.IsNull(), wxT("wxMacCoreGraphicsContext::DrawText - no valid font set") );
|
||||
|
||||
@@ -2379,10 +2378,17 @@ void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString& text, wxArr
|
||||
wxCFRef<CFAttributedStringRef> attrtext( CFAttributedStringCreate(kCFAllocatorDefault, t, attributes) );
|
||||
wxCFRef<CTLineRef> line( CTLineCreateWithAttributedString(attrtext) );
|
||||
|
||||
int chars = text.length();
|
||||
for ( int pos = 0; pos < (int)chars; pos ++ )
|
||||
widths.reserve(text.length());
|
||||
CFIndex u16index = 1;
|
||||
for ( wxString::const_iterator iter = text.begin(); iter != text.end(); ++iter, ++u16index )
|
||||
{
|
||||
widths[pos] = CTLineGetOffsetForStringIndex( line, pos+1 , NULL );
|
||||
// Take care of surrogate pairs: they take two, not one, of UTF-16 code
|
||||
// units used by CoreText.
|
||||
if ( *iter >= 0x10000 )
|
||||
{
|
||||
++u16index;
|
||||
}
|
||||
widths.push_back( CTLineGetOffsetForStringIndex( line, u16index, NULL ) );
|
||||
}
|
||||
|
||||
CheckInvariants();
|
||||
|
Reference in New Issue
Block a user