You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by js...@apache.org on 2014/03/28 10:34:48 UTC

svn commit: r1582651 - /openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx

Author: jsc
Date: Fri Mar 28 09:34:48 2014
New Revision: 1582651

URL: http://svn.apache.org/r1582651
Log:
#i124516# handle bad surrogate pairs gracefully

Patch By: hdu

Modified:
    openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx

Modified: openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx?rev=1582651&r1=1582650&r2=1582651&view=diff
==============================================================================
--- openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx (original)
+++ openoffice/branches/AOO410/main/vcl/win/source/gdi/winlayout.cxx Fri Mar 28 09:34:48 2014
@@ -415,12 +415,19 @@ bool SimpleWinLayout::LayoutText( ImplLa
         bool bSurrogate = ((nCharCode >= 0xD800) && (nCharCode <= 0xDFFF));
         if( bSurrogate )
         {
-            if( nCharCode >= 0xDC00 ) // this part of a surrogate pair was already processed
+            // ignore high surrogates, they were already processed with their low surrogates
+            if( nCharCode >= 0xDC00 )
                 continue;
-            nCharCode = 0x10000 + ((pCodes[0] - 0xD800) << 10) + (pCodes[1] - 0xDC00);
-	}
+            // check the second half of the surrogate pair
+            bSurrogate &= (0xDC00 <= pCodes[1]) && (pCodes[1] <= 0xDFFF);
+            // calculate the UTF-32 code of valid surrogate pairs
+            if( bSurrogate )
+                nCharCode = 0x10000 + ((pCodes[0] - 0xD800) << 10) + (pCodes[1] - 0xDC00);
+            else // or fall back to a replacement character
+                nCharCode = '?';
+        }
 
-        // get the advance width for the current UCS-4 code point
+        // get the advance width for the current UTF-32 code point
         int nGlyphWidth = mrWinFontEntry.GetCachedGlyphWidth( nCharCode );
         if( nGlyphWidth == -1 )
         {
@@ -438,7 +445,7 @@ bool SimpleWinLayout::LayoutText( ImplLa
         mpGlyphAdvances[ i ] = nGlyphWidth;
         mnWidth += nGlyphWidth;
 
-        // remaining codes of surrogate pair get a zero width
+        // the second half of surrogate pair gets a zero width
         if( bSurrogate && ((i+1) < mnGlyphCount) )
             mpGlyphAdvances[ i+1 ] = 0;