Changeset 82541 in webkit
- Timestamp:
- Mar 30, 2011 8:46:54 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r82536 r82541 1 2011-03-30 Ryuan Choi <ryuan.choi@samsung.com> 2 3 Reviewed by Martin Robinson. 4 5 [GTK] Fix leaked pointer in FontGtk.cpp 6 https://bugs.webkit.org/show_bug.cgi?id=57307 7 8 Fix a memory leak. 9 10 No new functionality, so no new tests. 11 12 * platform/graphics/gtk/FontGtk.cpp: 13 (WebCore::utf16ToUtf8): Rename utf16_to_utf8 and fix indentation. 14 (WebCore::convertUniCharToUTF8): 15 1 16 2011-03-30 Dominic Cooney <dominicc@google.com> 2 17 -
trunk/Source/WebCore/platform/graphics/gtk/FontGtk.cpp
r82496 r82541 36 36 #include "CairoUtilities.h" 37 37 #include "ContextShadow.h" 38 #include " PlatformContextCairo.h"38 #include "GOwnPtr.h" 39 39 #include "GraphicsContext.h" 40 40 #include "NotImplemented.h" 41 #include "PlatformContextCairo.h" 41 42 #include "SimpleFontData.h" 42 43 #include "TextRun.h" … … 85 86 #define IS_LOW_SURROGATE(u) ((UChar)(u) >= (UChar)0xdc00 && (UChar)(u) <= (UChar)0xdfff) 86 87 87 static void utf16_to_utf8(const UChar* aText, gint aLength, char* &text, gint &length)88 { 89 gboolean need_copy = FALSE;90 int i; 91 92 for (i = 0; i < aLength; i++) {93 if (!aText[i] || IS_LOW_SURROGATE(aText[i])) {94 need_copy = TRUE;95 break;96 } 97 elseif (IS_HIGH_SURROGATE(aText[i])) {98 if (i < aLength - 1 && IS_LOW_SURROGATE(aText[i+1]))99 i++;100 else {101 need_copy = TRUE;102 break;103 }104 }105 }106 107 if (need_copy) {108 109 /* Pango doesn't correctly handle nuls. We convert them to 0xff. */110 /* Also "validate" UTF-16 text to make sure conversion doesn't fail. */111 112 UChar* p = (UChar*)g_memdup(aText, aLength * sizeof(aText[0]));113 114 /* don't need to reset i */ 115 for (i = 0; i < aLength; i++) {116 if (!p[i] || IS_LOW_SURROGATE(p[i]))117 p[i] = 0xFFFD;118 else if (IS_HIGH_SURROGATE(p[i])) {119 if (i < aLength - 1 && IS_LOW_SURROGATE(aText[i+1]))120 i++;121 else122 p[i] = 0xFFFD;123 }124 }125 126 aText = p; 127 }128 129 glong items_written; 130 text = g_utf16_to_utf8(reinterpret_cast<const gunichar2*>(aText), aLength, NULL, &items_written, NULL);131 length = items_written;132 133 if (need_copy)134 g_free((gpointer)aText); 135 88 static gchar* utf16ToUtf8(const UChar* aText, gint aLength, gint &length) 89 { 90 gboolean needCopy = FALSE; 91 92 for (int i = 0; i < aLength; i++) { 93 if (!aText[i] || IS_LOW_SURROGATE(aText[i])) { 94 needCopy = TRUE; 95 break; 96 } 97 98 if (IS_HIGH_SURROGATE(aText[i])) { 99 if (i < aLength - 1 && IS_LOW_SURROGATE(aText[i+1])) 100 i++; 101 else { 102 needCopy = TRUE; 103 break; 104 } 105 } 106 } 107 108 GOwnPtr<UChar> copiedString; 109 if (needCopy) { 110 /* Pango doesn't correctly handle nuls. We convert them to 0xff. */ 111 /* Also "validate" UTF-16 text to make sure conversion doesn't fail. */ 112 113 copiedString.set(static_cast<UChar*>(g_memdup(aText, aLength * sizeof(aText[0])))); 114 UChar* p = copiedString.get(); 115 116 /* don't need to reset i */ 117 for (int i = 0; i < aLength; i++) { 118 if (!p[i] || IS_LOW_SURROGATE(p[i])) 119 p[i] = 0xFFFD; 120 else if (IS_HIGH_SURROGATE(p[i])) { 121 if (i < aLength - 1 && IS_LOW_SURROGATE(aText[i+1])) 122 i++; 123 else 124 p[i] = 0xFFFD; 125 } 126 } 127 128 aText = p; 129 } 130 131 gchar* utf8Text; 132 glong itemsWritten; 133 utf8Text = g_utf16_to_utf8(static_cast<const gunichar2*>(aText), aLength, 0, &itemsWritten, 0); 134 length = itemsWritten; 135 136 return utf8Text; 136 137 } 137 138 138 139 static gchar* convertUniCharToUTF8(const UChar* characters, gint length, int from, int to) 139 140 { 140 g char* utf8= 0;141 gint new_length = 0;142 utf16_to_utf8(characters, length, utf8, new_length);143 if (!utf8)144 return NULL; 145 141 gint newLength = 0; 142 GOwnPtr<gchar> utf8Text(utf16ToUtf8(characters, length, newLength)); 143 if (!utf8Text) 144 return 0; 145 146 gchar* pos = utf8Text.get(); 146 147 if (from > 0) { 147 148 // discard the first 'from' characters 148 149 // FIXME: we should do this before the conversion probably 149 gchar* str_left = g_utf8_offset_to_pointer(utf8, from); 150 gchar* tmp = g_strdup(str_left); 151 g_free(utf8); 152 utf8 = tmp; 153 } 154 155 gchar* pos = utf8; 150 pos = g_utf8_offset_to_pointer(utf8Text.get(), from); 151 } 152 156 153 gint len = strlen(pos); 157 154 GString* ret = g_string_new_len(NULL, len);
Note: See TracChangeset
for help on using the changeset viewer.