diff options
| author | Neil Hodgson <nyamatongwe@gmail.com> | 2018-05-21 15:41:57 +1000 |
|---|---|---|
| committer | Neil Hodgson <nyamatongwe@gmail.com> | 2018-05-21 15:41:57 +1000 |
| commit | cc5e63013d7aa447a74fafba0ee4dd560b6952c7 (patch) | |
| tree | ebd6b08100d42c768f91890dda49308055581789 /cocoa/PlatCocoa.mm | |
| parent | e0e105ea1559874a5a9097461d0d7933cb5cbbb4 (diff) | |
| download | scintilla-mirror-cc5e63013d7aa447a74fafba0ee4dd560b6952c7.tar.gz | |
If decoding DBCS text fails, use the MacRoman encoding to ensure something is
visible.
Diffstat (limited to 'cocoa/PlatCocoa.mm')
| -rw-r--r-- | cocoa/PlatCocoa.mm | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 1141cca44..0e1e1544c 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -867,10 +867,20 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION yba void SurfaceImpl::MeasureWidths(Font &font_, std::string_view text, XYPOSITION *positions) { CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, FontCharacterSet(font_)); - textLayout->setText(text, encoding, *TextStyleFromFont(font_)); + const CFStringEncoding encodingUsed = + textLayout->setText(text, encoding, *TextStyleFromFont(font_)); CTLineRef mLine = textLayout->getCTLine(); - assert(mLine != NULL); + assert(mLine); + + if (encodingUsed != encoding) { + // Switched to MacRoman to make work so treat as single byte encoding. + for (int i=0; i<text.length(); i++) { + CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, i+1, nullptr); + positions[i] = static_cast<XYPOSITION>(xPosition); + } + return; + } if (unicodeMode) { // Map the widths given for UTF-16 characters back onto the UTF-8 input string |
