summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2011-04-17 11:19:41 +0000
committerManolo Gouy <Manolo>2011-04-17 11:19:41 +0000
commitf8d1e074edc644d960a78aaaefb9f7c0f856f67c (patch)
treee8c846525931760b5c6f0f12d7a5fc3ab9896295 /src
parentddc4b21b5502a7331e09c540a3e3d9d5774775a3 (diff)
Made Fl_Quartz_Graphics_Driver::text_extents() resistant to mal-formed UTF-8 text.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8596 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_font_mac.cxx4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx
index 8941ceaa2..df23a495b 100644
--- a/src/fl_font_mac.cxx
+++ b/src/fl_font_mac.cxx
@@ -393,9 +393,10 @@ double Fl_Quartz_Graphics_Driver::width(unsigned int wc) {
void Fl_Quartz_Graphics_Driver::text_extents(const char *str8, int n, int &dx, int &dy, int &w, int &h) {
if (!font_descriptor()) font(FL_HELVETICA, FL_NORMAL_SIZE);
Fl_Font_Descriptor *fl_fontsize = font_descriptor();
+ UniChar *txt = mac_Utf8_to_Utf16(str8, n, &n);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if (fl_mac_os_version >= 100500) {
- CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)str8, n, kCFStringEncodingUTF8, false);
+ CFStringRef str16 = CFStringCreateWithCharactersNoCopy(NULL, txt, n, kCFAllocatorNull);
CFDictionarySetValue (attributes, kCTFontAttributeName, fl_fontsize->fontref);
CFAttributedStringRef mastr = CFAttributedStringCreate(kCFAllocatorDefault, str16, attributes);
CFRelease(str16);
@@ -429,7 +430,6 @@ else {
iValuePtr = &fl_gc;
ATSUSetLayoutControls(layout, 1, &iTag, &iSize, &iValuePtr);
// now measure the bounding box
- UniChar *txt = mac_Utf8_to_Utf16(str8, n, &n);
err = ATSUSetTextPointerLocation(layout, txt, kATSUFromTextBeginning, n, n);
Rect bbox;
err = ATSUMeasureTextImage(layout, kATSUFromTextBeginning, n, 0, 0, &bbox);