Fixed <rdar://problem/4000962> 8A375: Help Viewer displays voiced sound and semi...
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Feb 2005 20:54:19 +0000 (20:54 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Feb 2005 20:54:19 +0000 (20:54 +0000)
Added special case for voiced marks.

        Reviewed by John.

        * WebCoreSupport.subproj/WebTextRenderer.m:
        (widthForNextCharacter):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8701 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebCoreSupport.subproj/WebTextRenderer.m

index 2368c87fd923b8299fd0c1a318c66f60227a675f..94755ff23d1b29ccdda92ea34e2f4427e8aeed98 100644 (file)
@@ -1,3 +1,14 @@
+2005-02-25  Richard Williamson   <rjw@apple.com>
+
+       Fixed <rdar://problem/4000962> 8A375: Help Viewer displays voiced sound and semi-voiced characters strangely (characters don't seem to be composed)
+
+       Added special case for voiced marks.
+
+        Reviewed by John.
+
+        * WebCoreSupport.subproj/WebTextRenderer.m:
+        (widthForNextCharacter):
+
 2005-02-25  Darin Adler  <darin@apple.com>
 
         Reviewed by John.
index 73ce637bd0fa527b583aa85bbb8ee6e8d1f09ee6..968961ae049874724c7857b67e2f15024e70dbfa 100644 (file)
@@ -25,6 +25,7 @@
 #import <float.h>
 
 #import <unicode/uchar.h>
+#import <unicode/unorm.h>
 
 // FIXME: FATAL_ALWAYS seems like a bad idea; lets stop using it.
 
@@ -1952,6 +1953,9 @@ static inline float ceilCurrentWidth (CharacterWidthIterator *iterator)
     return delta;
 }
 
+// According to http://www.unicode.org/Public/UNIDATA/UCD.html#Canonical_Combining_Class_Values
+#define HIRAGANA_KATAKANA_VOICING_MARKS 8
+
 // Return INVALID_WIDTH if an error is encountered or we're at the end of the range in the run.
 static float widthForNextCharacter(CharacterWidthIterator *iterator, ATSGlyphRef *glyphUsed, NSFont **fontUsed)
 {
@@ -2007,10 +2011,34 @@ static float widthForNextCharacter(CharacterWidthIterator *iterator, ATSGlyphRef
             }
         }
     }
+    
+    // Deal with Hiragana and Katakana voiced and semi-voiced syllables.  Normalize into
+    // composed form, and then look for glyph with base + combined mark.
+    if (c >= 0x3041 && c <= 0x30FE) { // Early out to minimize performance impact.  Do we have a Hiragana/Katakana character?
+        if (currentCharacter < (unsigned)run->to) {
+            UnicodeChar nextCharacter = run->characters[currentCharacter+1];
+            if (u_getCombiningClass(nextCharacter) == HIRAGANA_KATAKANA_VOICING_MARKS) {
+                UChar normalizedCharacters[2] = { 0, 0 };
+                UErrorCode uStatus = 0;
+                int32_t resultLength;
+                
+                // Normalize into composed form using 3.2 rules.
+                resultLength = unorm_normalize(&run->characters[currentCharacter], 2,
+                                UNORM_NFC, UNORM_UNICODE_3_2,
+                                &normalizedCharacters[0], 2,
+                                &uStatus);
+                if (resultLength == 1 && uStatus == 0){
+                    c = normalizedCharacters[0];
+                    clusterLength = 2;
+                }
+            }
+        }
+    }
 
     if (style->rtl) {
         c = u_charMirror(c);
     }
+    
     if (c <= 0xFFFF) {
         *glyphUsed = glyphForCharacter(renderer->characterToGlyphMap, c, fontUsed);
         if (*glyphUsed == nonGlyphID) {
@@ -2038,7 +2066,7 @@ static float widthForNextCharacter(CharacterWidthIterator *iterator, ATSGlyphRef
 
     // Now that we have glyph and font, get its width.
     WebGlyphWidth width = widthForGlyph(renderer, *glyphUsed, *fontUsed);
-
+    
     // We special case spaces in two ways when applying word rounding.
     // First, we round spaces to an adjusted width in all fonts.
     // Second, in fixed-pitch fonts we ensure that all characters that