[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:06:55 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 9144d6913a0c13d6de4747c0ae51c14ce1798889
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Nov 22 22:19:21 2002 +0000

            Fixed rendering issues associated with 3100120.
            We now correctly map surrogate pairs in UTF-16.  khtml still has
            issues dealing with characters outside BMP.  These are tracked
            with 3109251 and 3109258.
    
            Surrogate pairs are treated as exceptions and have their own character
            to glyph map.
    
            * Misc.subproj/WebUnicode.h:
            * Misc.subproj/WebUnicode.m:
            (shapedString):
            * WebCoreSupport.subproj/WebTextRenderer.h:
            * WebCoreSupport.subproj/WebTextRenderer.m:
            (glyphForUnicodeCharacter):
            (findLengthOfCharacterCluster):
            (-[WebTextRenderer substituteFontForString:]):
            (-[WebTextRenderer convertUnicodeCharacters:length:toGlyphs:]):
            (-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
            (-[WebTextRenderer extendUnicodeCharacterToGlyphMapToInclude:]):
            (-[WebTextRenderer extendCharacterToGlyphMapToInclude:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2832 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 1273e53..134d714 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,26 @@
+2002-11-22  Richard Williamson   <rjw at apple.com>
+
+        Fixed rendering issues associated with 3100120.
+        We now correctly map surrogate pairs in UTF-16.  khtml still has
+        issues dealing with characters outside BMP.  These are tracked
+        with 3109251 and 3109258.
+        
+        Surrogate pairs are treated as exceptions and have their own character
+        to glyph map.
+        
+        * Misc.subproj/WebUnicode.h:
+        * Misc.subproj/WebUnicode.m:
+        (shapedString):
+        * WebCoreSupport.subproj/WebTextRenderer.h:
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (glyphForUnicodeCharacter):
+        (findLengthOfCharacterCluster):
+        (-[WebTextRenderer substituteFontForString:]):
+        (-[WebTextRenderer convertUnicodeCharacters:length:toGlyphs:]):
+        (-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
+        (-[WebTextRenderer extendUnicodeCharacterToGlyphMapToInclude:]):
+        (-[WebTextRenderer extendCharacterToGlyphMapToInclude:]):
+
 2002-11-22  John Sullivan  <sullivan at apple.com>
 
         * Resources/url_icon.tiff:
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 1273e53..134d714 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,26 @@
+2002-11-22  Richard Williamson   <rjw at apple.com>
+
+        Fixed rendering issues associated with 3100120.
+        We now correctly map surrogate pairs in UTF-16.  khtml still has
+        issues dealing with characters outside BMP.  These are tracked
+        with 3109251 and 3109258.
+        
+        Surrogate pairs are treated as exceptions and have their own character
+        to glyph map.
+        
+        * Misc.subproj/WebUnicode.h:
+        * Misc.subproj/WebUnicode.m:
+        (shapedString):
+        * WebCoreSupport.subproj/WebTextRenderer.h:
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (glyphForUnicodeCharacter):
+        (findLengthOfCharacterCluster):
+        (-[WebTextRenderer substituteFontForString:]):
+        (-[WebTextRenderer convertUnicodeCharacters:length:toGlyphs:]):
+        (-[WebTextRenderer _floatWidthForCharacters:stringLength:fromCharacterPosition:numberOfCharacters:withPadding:applyRounding:attemptFontSubstitution:widths:fonts:glyphs:numGlyphs:letterSpacing:wordSpacing:]):
+        (-[WebTextRenderer extendUnicodeCharacterToGlyphMapToInclude:]):
+        (-[WebTextRenderer extendCharacterToGlyphMapToInclude:]):
+
 2002-11-22  John Sullivan  <sullivan at apple.com>
 
         * Resources/url_icon.tiff:
diff --git a/WebKit/Misc.subproj/WebUnicode.h b/WebKit/Misc.subproj/WebUnicode.h
index 26caeb7..a323cc8 100644
--- a/WebKit/Misc.subproj/WebUnicode.h
+++ b/WebKit/Misc.subproj/WebUnicode.h
@@ -28,3 +28,17 @@ extern UniChar *shapedString(UniChar *uc, int stringLength, int from, int len, i
 #define WK_CELL(ucs) ((unsigned char) ucs & 0xff)
 #define WK_ROW(ucs) ((unsigned char) (ucs>>8)&0xff)
 
+// surrogate ranges
+enum {
+    HighSurrogateRangeStart  = 0xD800,
+    HighSurrogateRangeEnd    = 0xDBFF,
+    LowSurrogateRangeStart   = 0xDC00,
+    LowSurrogateRangeEnd     = 0xDFFF
+};
+
+#define UnicodeValueForSurrogatePair(h,l) (( ( h - HighSurrogateRangeStart ) << 10 ) + ( l - LowSurrogateRangeStart ) + 0x0010000)
+#define HighSurrogatePair(c) (((c - 0x10000)>>10) + 0xd800)
+#define LowSurrogatePair(c) (((c - 0x10000)&0x3ff) + 0xdc00)
+#define IsHighSurrogatePair(c)  (( c & 0xFC00 ) == HighSurrogateRangeStart )
+#define IsLowSurrogatePair(c)  (( c & 0xFC00 ) == LowSurrogateRangeStart )
+
diff --git a/WebKit/Misc.subproj/WebUnicode.m b/WebKit/Misc.subproj/WebUnicode.m
index 4e4db9f..7662223 100644
--- a/WebKit/Misc.subproj/WebUnicode.m
+++ b/WebKit/Misc.subproj/WebUnicode.m
@@ -510,6 +510,16 @@ UniChar *shapedString(UniChar *uc, int stringLength, int from, int len, int dir,
 	return 0;
     }
 
+    // Early out.
+    int i;
+    for (i = from; i < from+len; i++){
+        if (uc[i] < 0x7f)
+            return 0;
+        if (IsHighSurrogatePair(uc[i]))
+            return 0;
+    }
+    
+    
     // we have to ignore NSMs at the beginning and add at the end.
     int num = stringLength - from - len;
     UniChar *ch = uc + from + len;
@@ -540,7 +550,6 @@ UniChar *shapedString(UniChar *uc, int stringLength, int from, int len, int dir,
     if ( dir == RTL )
 	ch += len - 1;
 
-    int i;
     for (i = 0; i < len; i++ ) {
 	UniChar r = WK_ROW(*ch);
 	UniChar c = WK_CELL(*ch);
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.h b/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
index 2e75763..e0e8608 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.h
@@ -7,6 +7,7 @@
 
 typedef struct WidthMap WidthMap;
 typedef struct GlyphMap GlyphMap;
+typedef struct UnicodeGlyphMap UnicodeGlyphMap;
 
 @interface WebTextRenderer : NSObject <WebCoreTextRenderer>
 {
@@ -19,7 +20,8 @@ typedef struct GlyphMap GlyphMap;
     
 @public
     NSFont *font;
-    GlyphMap *characterToGlyphMap;
+    GlyphMap *characterToGlyphMap;			// Used for 16bit clean unicode characters.
+    UnicodeGlyphMap *unicodeCharacterToGlyphMap; 	// Used for surrogates.
     WidthMap *glyphToWidthMap;
     float spaceWidth;
     float adjustedSpaceWidth;
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
index f15818e..6904972 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRenderer.m
@@ -51,8 +51,8 @@
 #define IsHangulConjoiningJamo(X) (X >= JunseongStart && X <= JonseongEnd)
 #define IsNonBaseChar(X) ((CFCharacterSetIsCharacterMember(nonBaseChars, X) || IsHangulConjoiningJamo(X) || (((X) & 0x1FFFF0) == 0xF870)))
 
-
 typedef float WebGlyphWidth;
+typedef UInt32 UnicodeChar;
 
 struct WidthMap {
     ATSGlyphRef startRange;
@@ -68,6 +68,13 @@ struct GlyphMap {
     ATSGlyphRef *glyphs;
 };
 
+struct UnicodeGlyphMap {
+    UnicodeChar startRange;
+    UnicodeChar endRange;
+    UnicodeGlyphMap *next;
+    ATSGlyphRef *glyphs;
+};
+
 
 @interface NSLanguage : NSObject 
 {
@@ -93,6 +100,7 @@ static CFCharacterSetRef nonBaseChars = NULL;
 @interface WebTextRenderer (WebPrivate)
 - (WidthMap *)extendGlyphToWidthMapToInclude:(ATSGlyphRef)glyphID;
 - (ATSGlyphRef)extendCharacterToGlyphMapToInclude:(UniChar) c;
+- (ATSGlyphRef)extendUnicodeCharacterToGlyphMapToInclude: (UnicodeChar)c;
 @end
 
 
@@ -128,17 +136,17 @@ static inline ATSGlyphRef glyphForCharacter (GlyphMap *map, UniChar c)
 }
  
  
-static void setGlyphForCharacter (GlyphMap *map, ATSGlyphRef glyph, UniChar c)
+static inline ATSGlyphRef glyphForUnicodeCharacter (UnicodeGlyphMap *map, UnicodeChar c)
 {
     if (map == 0)
-        return;
+        return nonGlyphID;
         
     if (c >= map->startRange && c <= map->endRange)
-        ((ATSGlyphRef *)map->glyphs)[c-map->startRange] = glyph;
-    else    
-        setGlyphForCharacter (map->next, glyph, c);
+        return ((ATSGlyphRef *)map->glyphs)[c-map->startRange];
+        
+    return glyphForUnicodeCharacter (map->next, c);
 }
-
+ 
 
 #ifdef _TIMING        
 static double totalCGGetAdvancesTime = 0;
@@ -220,9 +228,12 @@ static unsigned int findLengthOfCharacterCluster(const UniChar *characters, unsi
     if (length <= 1)
         return length;
     
+    if (IsHighSurrogatePair(characters[0]))
+        return 2;
+        
     if (IsNonBaseChar(characters[0]))
         return 1;
-                
+    
     // Find all the non base characters after the current character.
     for (k = 1; k < length; k++)
         if (!IsNonBaseChar(characters[k]))
@@ -260,10 +271,10 @@ static BOOL bufferTextDrawing = NO;
     // The character substitute font lookup is currently disabled.  I need to extend
     // the character to glyph map to include a font, so we'll only pay the price for
     // this lookup once, at the expense of replicating information in each WebTextRenderer. 
-#ifdef COMPLETE_SUBSTITUTE_CHECK       
+//#ifdef COMPLETE_SUBSTITUTE_CHECK       
     if (substituteFont == nil && [string length] == 1)
         substituteFont = [NSFont findFontLike:font forCharacter: [string characterAtIndex: 0] inLanguage:[NSLanguage defaultLanguage]];
-#endif
+//#endif
         
     return substituteFont;
 }
@@ -337,6 +348,35 @@ static BOOL bufferTextDrawing = NO;
 }
 
 
+- (void)convertUnicodeCharacters: (const UnicodeChar *)characters length: (unsigned)numCharacters toGlyphs: (ATSGlyphVector *)glyphs
+{
+    unsigned numCharactersInBuffer;
+    UniChar localBuffer[LOCAL_BUFFER_SIZE];
+    UniChar *buffer = localBuffer;
+    OSStatus status;
+    unsigned i, bufPos = 0;
+    
+    if (numCharacters*2 > LOCAL_BUFFER_SIZE) {
+        buffer = (UniChar *)malloc(sizeof(UniChar) * numCharacters * 2);
+    }
+    
+    numCharactersInBuffer = 0;
+    for (i = 0; i < numCharacters; i++) {
+        UnicodeChar c = characters[i];
+        UniChar h = HighSurrogatePair(c);
+        UniChar l = LowSurrogatePair(c);
+        buffer[bufPos++] = h;
+        buffer[bufPos++] = l;
+    }
+        
+    status = ATSUConvertCharToGlyphs(styleGroup, buffer, 0, numCharacters*2, 0, glyphs);
+    
+    if (buffer != localBuffer) {
+        free(buffer);
+    }
+}
+
+
 - initWithFont:(NSFont *)f
 {
     if ([f glyphPacking] != NSNativeShortGlyphPacking &&
@@ -698,6 +738,7 @@ static const char *joiningNames[] = {
     uint numSpaces = 0;
     int padPerSpace = 0;
     int numGlyphs = 0;
+    UniChar high = 0, low = 0;
 
     if (len <= 0){
         if (_numGlyphs)
@@ -770,9 +811,29 @@ static const char *joiningNames[] = {
             break;
         }
 
-        glyphID = glyphForCharacter(characterToGlyphMap, c);
-        if (glyphID == nonGlyphID) {
-            glyphID = [self extendCharacterToGlyphMapToInclude: c];
+        // Deal with surrogate pairs
+        if (c >= HighSurrogateRangeStart && c <= HighSurrogateRangeEnd){
+            high = c;
+
+            // Make sure we have another character and it's a low surrogate.
+            if (i+1 >= stringLength || !IsLowSurrogatePair((low = characters[++i]))){
+                // Error!  Use 0 glyph.
+                glyphID = 0;
+            }
+            else {
+                UnicodeChar uc = UnicodeValueForSurrogatePair(high, low);
+                glyphID = glyphForUnicodeCharacter(unicodeCharacterToGlyphMap, uc);
+                if (glyphID == nonGlyphID) {
+                    glyphID = [self extendUnicodeCharacterToGlyphMapToInclude: uc];
+                }
+            }
+        }
+        // Otherwise we have a valid 16bit unicode character.
+        else {
+            glyphID = glyphForCharacter(characterToGlyphMap, c);
+            if (glyphID == nonGlyphID) {
+                glyphID = [self extendCharacterToGlyphMapToInclude: c];
+            }
         }
 
         // FIXME:  look at next character to determine if it is non-base, then
@@ -786,12 +847,24 @@ static const char *joiningNames[] = {
         // Try to find a substitute font if this font didn't have a glyph for a character in the
         // string.  If one isn't found we end up drawing and measuring the 0 glyph, usually a box.
         if (glyphID == 0 && attemptSubstitution) {
-            clusterLength = findLengthOfCharacterCluster (&characters[i], stringLength - i);
-            substituteFont = [self substituteFontForCharacters: &characters[i] length: clusterLength];
+            const UniChar *_characters;
+            UniChar surrogates[2];
+            
+            if (high && low){
+                clusterLength = 2;
+                surrogates[0] = high;
+                surrogates[1] = low;
+                _characters = &surrogates[0];
+            }
+            else {
+                clusterLength = findLengthOfCharacterCluster (&characters[i], stringLength - i);
+                _characters = &characters[i];
+            }
+            substituteFont = [self substituteFontForCharacters: _characters length: clusterLength];
             if (substituteFont) {
                 int cNumGlyphs;
                 lastWidth = [[[WebTextRendererFactory sharedFactory] rendererWithFont: substituteFont] 
-                                _floatWidthForCharacters: &characters[i] 
+                                _floatWidthForCharacters: _characters 
                                 stringLength: clusterLength 
                                 fromCharacterPosition: 0 numberOfCharacters: clusterLength 
                                 withPadding: 0 applyRounding: NO attemptFontSubstitution: NO 
@@ -899,6 +972,61 @@ static const char *joiningNames[] = {
     return totalWidth;
 }
 
+- (ATSGlyphRef)extendUnicodeCharacterToGlyphMapToInclude: (UnicodeChar)c
+{
+    UnicodeGlyphMap *map = (UnicodeGlyphMap *)calloc (1, sizeof(UnicodeGlyphMap));
+    ATSLayoutRecord *glyphRecord;
+    ATSGlyphVector glyphVector;
+    UnicodeChar end, start;
+    unsigned int blockSize;
+    ATSGlyphRef glyphID;
+    
+    if (unicodeCharacterToGlyphMap == 0)
+        blockSize = INITIAL_BLOCK_SIZE;
+    else
+        blockSize = INCREMENTAL_BLOCK_SIZE;
+    start = (c / blockSize) * blockSize;
+    end = start + (blockSize - 1);
+        
+    LOG(FontCache, "%@ (0x%04x) adding glyphs for 0x%04x to 0x%04x", font, c, start, end);
+
+    map->startRange = start;
+    map->endRange = end;
+    
+    unsigned int i, count = end - start + 1;
+    UnicodeChar buffer[INCREMENTAL_BLOCK_SIZE+2];
+    
+    for (i = 0; i < count; i++){
+        buffer[i] = i+start;
+    }
+
+    ATSInitializeGlyphVector(count*2, 0, &glyphVector);
+    [self convertUnicodeCharacters: &buffer[0] length: count toGlyphs: &glyphVector];
+    if (glyphVector.numGlyphs != count)
+        [NSException raise:NSInternalInconsistencyException format:@"surrogate matching violation:  count and glyphID count not equal - for %@ %f", self, [font displayName], [font pointSize]];
+            
+    map->glyphs = (ATSGlyphRef *)malloc (count * sizeof(ATSGlyphRef));
+    glyphRecord = (ATSLayoutRecord *)glyphVector.firstRecord;
+    for (i = 0; i < count; i++) {
+        map->glyphs[i] = glyphRecord->glyphID;
+        glyphRecord = (ATSLayoutRecord *)((char *)glyphRecord + glyphVector.recordSize);
+    }
+    ATSClearGlyphVector(&glyphVector);
+    
+    if (unicodeCharacterToGlyphMap == 0)
+        unicodeCharacterToGlyphMap = map;
+    else {
+        UnicodeGlyphMap *lastMap = unicodeCharacterToGlyphMap;
+        while (lastMap->next != 0)
+            lastMap = lastMap->next;
+        lastMap->next = map;
+    }
+
+    glyphID = map->glyphs[c - start];
+    
+    return glyphID;
+}
+
 - (ATSGlyphRef)extendCharacterToGlyphMapToInclude:(UniChar) c
 {
     GlyphMap *map = (GlyphMap *)calloc (1, sizeof(GlyphMap));
@@ -952,9 +1080,6 @@ static const char *joiningNames[] = {
         lastMap->next = map;
     }
 
-    if (spaceGlyph == nonGlyphID)
-        spaceGlyph = glyphForCharacter (characterToGlyphMap, SPACE);
-
     glyphID = map->glyphs[c - start];
     
     // Special case for characters 007F-00A0.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list