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/QuartzTextLayout.h | |
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/QuartzTextLayout.h')
-rw-r--r-- | cocoa/QuartzTextLayout.h | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/cocoa/QuartzTextLayout.h b/cocoa/QuartzTextLayout.h index a3ed910de..62e695525 100644 --- a/cocoa/QuartzTextLayout.h +++ b/cocoa/QuartzTextLayout.h @@ -23,35 +23,49 @@ public: } ~QuartzTextLayout() { - if (mString != NULL) { + if (mString) { CFRelease(mString); mString = NULL; } - if (mLine != NULL) { + if (mLine) { CFRelease(mLine); mLine = NULL; } } - void setText(std::string_view sv, CFStringEncoding encoding, const QuartzTextStyle &r) { + CFStringEncoding setText(std::string_view sv, CFStringEncoding encoding, const QuartzTextStyle &r) { + // First clear current values in case of failure. + if (mString) { + CFRelease(mString); + mString = NULL; + } + if (mLine) { + CFRelease(mLine); + mLine = NULL; + } + const UInt8 *puiBuffer = reinterpret_cast<const UInt8 *>(sv.data()); CFStringRef str = CFStringCreateWithBytes(NULL, puiBuffer, sv.length(), encoding, false); - if (!str) - return; + if (!str) { + // Failed to decode bytes into string with given encoding so try + // MacRoman which should accept any byte. + encoding = kCFStringEncodingMacRoman; + str = CFStringCreateWithBytes(NULL, puiBuffer, sv.length(), encoding, false); + } + if (!str) { + return encoding; + } stringLength = CFStringGetLength(str); CFMutableDictionaryRef stringAttribs = r.getCTStyle(); - if (mString != NULL) - CFRelease(mString); mString = ::CFAttributedStringCreate(NULL, str, stringAttribs); - if (mLine != NULL) - CFRelease(mLine); mLine = ::CTLineCreateWithAttributedString(mString); CFRelease(str); + return encoding; } /** Draw the text layout into a CGContext at the specified position. |