[webkit-changes] cvs commit: LayoutTests/fast/dom namednodemap-namelookup-expected.txt

Darin darin at opensource.apple.com
Thu Oct 6 08:46:17 PDT 2005


darin       05/10/06 08:46:16

  Modified:    .        ChangeLog WebCore.exp
               kwq      KWQComboBox.mm KWQFont.h KWQFont.mm
                        KWQFontMetrics.mm KWQLineEdit.mm KWQListBox.mm
                        KWQPainter.mm WebCoreTextRendererFactory.h
                        WebCoreTextRendererFactory.mm
               .        ChangeLog
               Misc.subproj WebKitNSStringExtras.m WebStringTruncator.m
               WebCoreSupport.subproj WebTextRenderer.h WebTextRenderer.m
                        WebTextRendererFactory.h WebTextRendererFactory.m
               WebKit.xcodeproj project.pbxproj
               WebView.subproj WebHTMLView.m WebTextView.m WebView.m
               .        ChangeLog
               editing/pasteboard paste-text-011-expected.checksum
                        paste-text-011-expected.png
                        paste-text-011-expected.txt
               fast/dom namednodemap-namelookup-expected.txt
  Removed:     WebCoreSupport.subproj WebGlyphBuffer.h WebGlyphBuffer.m
  Log:
  LayoutTests:
  
          - updated test result for synthetic bold
  
          * editing/pasteboard/paste-text-011-expected.checksum: Regenerated.
          * editing/pasteboard/paste-text-011-expected.png: Ditto.
          * editing/pasteboard/paste-text-011-expected.txt: Ditto.
  
          - updated test result that was incorrect
  
          * fast/dom/namednodemap-namelookup-expected.txt: Added trailing newlines
  
  WebCore:
  
          Reviewed by Hyatt.
  
          - fixed <rdar://problem/3217793> Monaco bold comes out as Helvetica bold, very bad if you choose Monaco as your fixed-width font
          - fixed <rdar://problem/3256269> CSS1: bold/italic font styles not programmatically created if font doesn't include them (3231)
            also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3231>
  
          * kwq/WebCoreTextRendererFactory.h: Added WebCoreFont structure, and made this header work for
          non-Objective-C compiles. Changed all the methods to take and return WebCoreFont instead of
          NSFont *.
          * kwq/WebCoreTextRendererFactory.mm:
          (WebCoreInitializeFont): Added.
          (-[WebCoreTextRendererFactory fontWithFamilies:traits:size:]): Updated to use ERROR so we notice
          cases where the subclass does not override these methods.
          (-[WebCoreTextRendererFactory isFontFixedPitch:]): Ditto.
          (-[WebCoreTextRendererFactory rendererWithFont:]): Ditto.
  
          * WebCore.exp: Added WebCoreInititalizeFont.
  
          * kwq/KWQFont.h: Added WebCoreFont support.
          * kwq/KWQFont.mm:
          (QFont::QFont): Change to use WebCoreFont.
          (QFont::~QFont): Ditto.
          (QFont::operator=): Ditto.
          (QFont::setFamily): Ditto.
          (QFont::setFirstFamily): Ditto.
          (QFont::setPixelSize): Ditto.
          (QFont::setWeight): Ditto.
          (QFont::setItalic): Ditto.
          (QFont::determinePitch): Ditto.
          (QFont::getWebCoreFont): Added.
  
          * kwq/KWQComboBox.mm: (QComboBox::sizeHint): Pass in WebCoreFont when creating text renderer.
          * kwq/KWQFontMetrics.mm: (QFontMetricsPrivate::getRenderer): Ditto.
          * kwq/KWQLineEdit.mm: (QLineEdit::sizeForCharacterWidth): Ditto.
          * kwq/KWQListBox.mm:
          (itemTextRenderer): Ditto.
          (groupLabelTextRenderer): Ditto.
          (QListBox::sizeForNumberOfLines): Changed non-system-font case to use QFont rather than NSFont
          to add boldness, so that group label fonts are bolded even if it's synthesiized bold.
          (-[KWQTableView drawRow:clipRect:]): Ditto.
          * kwq/KWQPainter.mm: (QPainter::_updateRenderer): Pass in WebCoreFont when creating text renderer.
  
  WebKit:
  
          Reviewed by Hyatt.
  
          - fixed <rdar://problem/3217793> Monaco bold comes out as Helvetica bold, very bad if you choose Monaco as your fixed-width font
          - fixed <rdar://problem/3256269> CSS1: bold/italic font styles not programmatically created if font doesn't include them (3231)
            also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3231>
  
          * WebCoreSupport.subproj/WebTextRenderer.h: Removed public declarations of private structures that are not
          used in the header. Removed the separate 16-bit character map; the difference in code size is only a few
          bytes per page and there's no measurable performance difference by always using the 32-bit character version.
          Removed substitute font width maps altogether, since we now use the width map in the substitute font's renderer.
          Also removed a few more now-unused fields and methods. Changed initWithFont to take WebCoreFont. Changed
          the setAlwaysUseATSU: method to remove the underscore prefix.
  
          * WebCoreSupport.subproj/WebTextRenderer.m:
          (getUncachedWidth): Get font from WebCoreFont directly instead of taking a parameter, since we now use only
          one NSFont per WebTextRenderer.
          (widthFromMap): Removed NSFont parameter for same reason as above; simplified.
          (widthForGlyph): Ditto.
          (overrideLayoutOperation): Updated for change to WebCoreFont.
          (-[WebTextRenderer initWithFont:]): Changed to use WebCoreFont. Removed code to deal with substitute font maps.
          Changed lineGap computation to use floats instead of doubles. Added code to compute a synthetic bold offset.
          Currently this is the font size divided by 24 and then rounded up to an integer.
          (-[WebTextRenderer dealloc]): Updated for change to WebCoreFont and other related changes.
          (-[WebTextRenderer finalize]): Ditto.
          (-[WebTextRenderer xHeight]): Ditto.
          (-[WebTextRenderer drawRun:style:geometry:]): Remove small caps case here; no longer needed. Also updated as above.
          (-[WebTextRenderer floatWidthForRun:style:widths:]): Ditto.
          (-[WebTextRenderer drawHighlightForRun:style:geometry:]): Ditto.
          (-[WebTextRenderer pointToOffset:style:position:reversed:includePartialGlyphs:]): Ditto.
          (+[WebTextRenderer setAlwaysUseATSU:]): Renamed to remove underscore prefix.
          (-[WebTextRenderer smallCapsRenderer]): Ditto. Changed to create a renderer for the smaller sized font.
          (-[WebTextRenderer _substituteFontForString:families:]): Reorganized this to be more readable and to call
          the new rendererForAlternateFont method.
          (-[WebTextRenderer rendererForAlternateFont:]): Added. Used to select an alternate font taking into account
          bold and italic synthesis.
          (-[WebTextRenderer substituteRendererForCharacters:length:families:]): Renamed to remove underscore prefix.
          Updated to use rendererForAlternateFont.
          (-[WebTextRenderer _computeWidthForSpace]): Updated for name changes and to remove unnecessary parameters.
          (-[WebTextRenderer setUpFont]): Renamed to remove underscore prefix. Added code to get printer or screen
          font as specified by WebCoreFont so calers don't need to do this.
          (drawGlyphs): Renamed to remove underscore prefix. Added code for synthetic oblique (14 degree slant), and
          synthetic bold (add offset and draw text a second time).
          (-[WebTextRenderer _CG_drawRun:style:geometry:]): Keep an array of substitute renderers instead of fonts.
          Changed around the loop to reverse the run to be a single loop instead of 3.
          (-[WebTextRenderer floatWidthForRun:style:widths:substituteRenderers:glyphs:startPosition:numGlyphs:]):
          Renamed to remove the underscore prefix.
          (-[WebTextRenderer _CG_floatWidthForRun:style:widths:substituteRenderers:glyphs:startPosition:numGlyphs:]):
          Changed to use subsitute renderers rather than fonts.
          (-[WebTextRenderer updateGlyphEntryForCharacter:glyphID:substituteRenderer:]): Renamed to remove underscore
          prefix and changed to use a substitute renderer rather than a substitute NSFont.
          (-[WebTextRenderer extendCharacterToGlyphMapToInclude:]): Updated to work with all characters, both ones
          that fit into 16-bit and ones that don't.
          (-[WebTextRenderer _extendGlyphToWidthMapToInclude:]): Removed NSFont parameter and simplified. This fixes
          a bug where numberOfGlyphs was accidentally used from the main font instead of "subFont".
          (glyphForCharacter): Changed to use subsitute renderers instead of substitute fonts.
          (widthForNextCharacter): Ditto. Also removed small caps code no longer needed here and replaced it with
          simpler small caps code that no longer assumes glyphs match.
          (shouldUseATSU): Changed the code to check ranges in order to slightly reduce the number of cases and
          to create earlier exit for lower character codes.
  
          * WebCoreSupport.subproj/WebTextRendererFactory.h: Added caches for synthesized font and oblique
          variants so we can still use the NSFont as the dictionary key. Removed coalesceTextDrawing methods.
          Changed methods to use WebCoreFont as the parameters and results instead of NSFont.
          * WebCoreSupport.subproj/WebTextRendererFactory.m:
          (-[WebTextRendererFactory clearCaches]): Clear all 8 caches.
          (-[WebTextRendererFactory isFontFixedPitch:]): Changed code slightly so there's only one call to
          the CFDictionarySetValue function.
          (-[WebTextRendererFactory init]): Create all 8 caches.
          (-[WebTextRendererFactory dealloc]): Release all 8 caches.
          (-[WebTextRendererFactory rendererWithFont:]): Select the appropriate cache based on 3 booleans:
          synthetic bold, synthetic oblique, and printer. Use WebCoreFont instead of NSFont.
          (-[WebTextRendererFactory fontWithFamilies:traits:size:]): Set the synthetic bold and oblique flags
          when returning a WebCoreFont based on requested traits that are not present in the NSFont.
          (acceptableChoice): Ignore the synthesizable traits when deciding if a chosen font is acceptable.
          (betterChoice): Rather than assuming that every font has all the desired traits, implement a rule
          that says a font with an unwanted trait loses out over a font that does not have an unwanted trait.
          This lets us chose a bold font over a non-bold font that could use synthesized bold but treat both
          as candidates.
  
          * WebCoreSupport.subproj/WebGlyphBuffer.h: Removed.
          * WebCoreSupport.subproj/WebGlyphBuffer.m: Removed.
          * WebKit.xcodeproj/project.pbxproj: Removed WebGlyphBuffer source files.
  
          * Misc.subproj/WebKitNSStringExtras.m:
          (-[NSString _web_drawAtPoint:font:textColor:]): Update to use WebCoreFont.
          (-[NSString _web_widthWithFont:]): Ditto.
          * Misc.subproj/WebStringTruncator.m:
          (truncateString): Ditto.
          (+[WebStringTruncator widthOfString:font:]): Ditto.
  
          * WebView.subproj/WebHTMLView.m: (-[WebHTMLView drawRect:]): Removed text drawing coalesce method calls.
          * WebView.subproj/WebTextView.m: (-[WebTextView setFixedWidthFont]): Updated to use cachedFontFromFamily
          method, which we still have, rather than fontWithFamilies method which we don't (since it now uses WebCoreFont).
          * WebView.subproj/WebView.m: (+[WebView _setAlwaysUseATSU:]): Updated for name change to underlying method.
  
  Revision  Changes    Path
  1.207     +44 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.206
  retrieving revision 1.207
  diff -u -r1.206 -r1.207
  --- ChangeLog	6 Oct 2005 06:31:34 -0000	1.206
  +++ ChangeLog	6 Oct 2005 15:45:49 -0000	1.207
  @@ -1,3 +1,47 @@
  +2005-10-06  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Hyatt.
  +
  +        - fixed <rdar://problem/3217793> Monaco bold comes out as Helvetica bold, very bad if you choose Monaco as your fixed-width font
  +        - fixed <rdar://problem/3256269> CSS1: bold/italic font styles not programmatically created if font doesn't include them (3231)
  +          also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3231>
  +
  +        * kwq/WebCoreTextRendererFactory.h: Added WebCoreFont structure, and made this header work for
  +        non-Objective-C compiles. Changed all the methods to take and return WebCoreFont instead of
  +        NSFont *.
  +        * kwq/WebCoreTextRendererFactory.mm:
  +        (WebCoreInitializeFont): Added.
  +        (-[WebCoreTextRendererFactory fontWithFamilies:traits:size:]): Updated to use ERROR so we notice
  +        cases where the subclass does not override these methods.
  +        (-[WebCoreTextRendererFactory isFontFixedPitch:]): Ditto.
  +        (-[WebCoreTextRendererFactory rendererWithFont:]): Ditto.
  +
  +        * WebCore.exp: Added WebCoreInititalizeFont.
  +
  +        * kwq/KWQFont.h: Added WebCoreFont support.
  +        * kwq/KWQFont.mm:
  +        (QFont::QFont): Change to use WebCoreFont.
  +        (QFont::~QFont): Ditto.
  +        (QFont::operator=): Ditto.
  +        (QFont::setFamily): Ditto.
  +        (QFont::setFirstFamily): Ditto.
  +        (QFont::setPixelSize): Ditto.
  +        (QFont::setWeight): Ditto.
  +        (QFont::setItalic): Ditto.
  +        (QFont::determinePitch): Ditto.
  +        (QFont::getWebCoreFont): Added.
  +
  +        * kwq/KWQComboBox.mm: (QComboBox::sizeHint): Pass in WebCoreFont when creating text renderer.
  +        * kwq/KWQFontMetrics.mm: (QFontMetricsPrivate::getRenderer): Ditto.
  +        * kwq/KWQLineEdit.mm: (QLineEdit::sizeForCharacterWidth): Ditto.
  +        * kwq/KWQListBox.mm:
  +        (itemTextRenderer): Ditto.
  +        (groupLabelTextRenderer): Ditto.
  +        (QListBox::sizeForNumberOfLines): Changed non-system-font case to use QFont rather than NSFont
  +        to add boldness, so that group label fonts are bolded even if it's synthesiized bold.
  +        (-[KWQTableView drawRow:clipRect:]): Ditto.
  +        * kwq/KWQPainter.mm: (QPainter::_updateRenderer): Pass in WebCoreFont when creating text renderer.
  +
   2005-10-05  Vicki Murley  <vicki at apple.com>
   
           Reviewed by Maciej.
  
  
  
  1.45      +1 -0      WebCore/WebCore.exp
  
  Index: WebCore.exp
  ===================================================================
  RCS file: /cvs/root/WebCore/WebCore.exp,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- WebCore.exp	30 Jul 2005 09:05:01 -0000	1.44
  +++ WebCore.exp	6 Oct 2005 15:45:51 -0000	1.45
  @@ -131,5 +131,6 @@
   _WebCoreElementTitleKey
   _WebCoreInitializeEmptyTextGeometry
   _WebCoreInitializeEmptyTextStyle
  +_WebCoreInitializeFont
   _WebCoreInitializeTextRun
   _WebCorePageCacheStateKey
  
  
  
  1.68      +10 -6     WebCore/kwq/KWQComboBox.mm
  
  Index: KWQComboBox.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQComboBox.mm,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- KWQComboBox.mm	3 Oct 2005 21:13:02 -0000	1.67
  +++ KWQComboBox.mm	6 Oct 2005 15:45:54 -0000	1.68
  @@ -163,9 +163,11 @@
           QValueListConstIterator<KWQListBoxItem> i = const_cast<const QValueList<KWQListBoxItem> &>(_items).begin();
           QValueListConstIterator<KWQListBoxItem> e = const_cast<const QValueList<KWQListBoxItem> &>(_items).end();
           if (i != e) {
  -            id <WebCoreTextRenderer> itemRenderer = [[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:[button font]
  -                usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  +            WebCoreFont itemFont;
  +            WebCoreInitializeFont(&itemFont);
  +            itemFont.font = [button font];
  +            itemFont.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
  +            id <WebCoreTextRenderer> itemRenderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:itemFont];
               id <WebCoreTextRenderer> labelRenderer = nil;
               WebCoreTextStyle style;
               WebCoreInitializeEmptyTextStyle(&style);
  @@ -183,9 +185,11 @@
                   id <WebCoreTextRenderer> renderer;
                   if (isGroupLabel) {
                       if (labelRenderer == nil) {
  -                        labelRenderer = [[WebCoreTextRendererFactory sharedFactory]
  -                            rendererWithFont:labelFont()
  -                            usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  +                        WebCoreFont labelFont;
  +                        WebCoreInitializeFont(&labelFont);
  +                        labelFont.font = this->labelFont();
  +                        labelFont.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
  +                        labelRenderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:labelFont];
                       }
                       renderer = labelRenderer;
                   } else {
  
  
  
  1.33      +4 -8      WebCore/kwq/KWQFont.h
  
  Index: KWQFont.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQFont.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- KWQFont.h	9 Jul 2005 20:19:25 -0000	1.32
  +++ KWQFont.h	6 Oct 2005 15:45:54 -0000	1.33
  @@ -27,12 +27,7 @@
   #define QFONT_H_
   
   #include "KWQFontFamily.h"
  -
  -#ifdef __OBJC__
  - at class NSFont;
  -#else
  -class NSFont;
  -#endif
  +#include "WebCoreTextRendererFactory.h"
   
   class QFont {
   public:
  @@ -75,7 +70,8 @@
       int getNSTraits() const { return _trait; }
       float getNSSize() const { return _size; }
       
  -    NSFont *getNSFont() const;
  +    NSFont *getNSFont() const { return getWebCoreFont().font; }
  +    const WebCoreFont &getWebCoreFont() const;
   
   private:
       KWQFontFamily _family;
  @@ -83,7 +79,7 @@
       float _size;
       bool _isPrinterFont : 1;
       mutable Pitch _pitch : 2;
  -    mutable NSFont *_NSFont;
  +    mutable WebCoreFont m_webCoreFont;
   };
   
   #endif
  
  
  
  1.50      +30 -29    WebCore/kwq/KWQFont.mm
  
  Index: KWQFont.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQFont.mm,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- KWQFont.mm	3 Oct 2005 21:13:02 -0000	1.49
  +++ KWQFont.mm	6 Oct 2005 15:45:54 -0000	1.50
  @@ -36,13 +36,13 @@
       , _size(12.0)
       , _isPrinterFont(false)
       , _pitch(Unknown)
  -    , _NSFont(0)
   {
  +    m_webCoreFont.font = nil;
   }
   
   QFont::~QFont()
   {
  -    KWQRelease(_NSFont);
  +    KWQRelease(m_webCoreFont.font);
   }
   
   QFont::QFont(const QFont &other)
  @@ -51,8 +51,9 @@
       , _size(other._size)
       , _isPrinterFont(other._isPrinterFont)
       , _pitch(other._pitch)
  -    , _NSFont(KWQRetain(other._NSFont))
  +    , m_webCoreFont(other.m_webCoreFont)
   {
  +    KWQRetain(m_webCoreFont.font);
   }
   
   QFont &QFont::operator=(const QFont &other)
  @@ -62,9 +63,9 @@
       _size = other._size;
       _isPrinterFont = other._isPrinterFont;
       _pitch = other._pitch;
  -    KWQRetain(other._NSFont);
  -    KWQRelease(_NSFont);
  -    _NSFont = other._NSFont;
  +    KWQRetain(other.m_webCoreFont.font);
  +    KWQRelease(m_webCoreFont.font);
  +    m_webCoreFont = other.m_webCoreFont;
       return *this;
   }
   
  @@ -76,24 +77,24 @@
   void QFont::setFamily(const QString &qfamilyName)
   {
       _family.setFamily(qfamilyName);
  -    KWQRelease(_NSFont);
  -    _NSFont = 0;
  +    KWQRelease(m_webCoreFont.font);
  +    m_webCoreFont.font = nil;
       _pitch = Unknown;
   }
   
   void QFont::setFirstFamily(const KWQFontFamily& family) 
   {
       _family = family;
  -    KWQRelease(_NSFont);
  -    _NSFont = 0;
  +    KWQRelease(m_webCoreFont.font);
  +    m_webCoreFont.font = nil;
       _pitch = Unknown;
   }
   
   void QFont::setPixelSize(float s)
   {
       if (_size != s) {
  -        KWQRelease(_NSFont); 
  -        _NSFont = 0;
  +        KWQRelease(m_webCoreFont.font); 
  +        m_webCoreFont.font = nil;
           _pitch = Unknown;
       }
       _size = s;
  @@ -102,16 +103,16 @@
   void QFont::setWeight(int weight)
   {
       if (weight == Bold) {
  -        if (!(_trait & NSBoldFontMask)){
  -            KWQRelease(_NSFont);
  -            _NSFont = 0;
  +        if (!(_trait & NSBoldFontMask)) {
  +            KWQRelease(m_webCoreFont.font);
  +            m_webCoreFont.font = nil;
               _pitch = Unknown;
           }
           _trait |= NSBoldFontMask;
       } else if (weight == Normal) {
           if ((_trait & NSBoldFontMask)){
  -            KWQRelease(_NSFont);
  -            _NSFont = 0;
  +            KWQRelease(m_webCoreFont.font);
  +            m_webCoreFont.font = nil;
               _pitch = Unknown;
           }
           _trait &= ~NSBoldFontMask;
  @@ -132,15 +133,15 @@
   {
       if (flag) {
           if (!(_trait & NSItalicFontMask)){
  -            KWQRelease(_NSFont);
  -            _NSFont = 0;
  +            KWQRelease(m_webCoreFont.font);
  +            m_webCoreFont.font = nil;
               _pitch = Unknown;
           }
           _trait |= NSItalicFontMask;
       } else {
           if ((_trait & NSItalicFontMask)){
  -            KWQRelease(_NSFont);
  -            _NSFont = 0;
  +            KWQRelease(m_webCoreFont.font);
  +            m_webCoreFont.font = nil;
               _pitch = Unknown;
           }
           _trait &= ~NSItalicFontMask;
  @@ -160,7 +161,7 @@
   void QFont::determinePitch() const
   {
       KWQ_BLOCK_EXCEPTIONS;
  -    if ([[WebCoreTextRendererFactory sharedFactory] isFontFixedPitch:getNSFont()])
  +    if ([[WebCoreTextRendererFactory sharedFactory] isFontFixedPitch:getWebCoreFont()])
           _pitch = Fixed;
       else
           _pitch = Variable;
  @@ -176,16 +177,16 @@
           && _pitch == compareFont._pitch;
   }
   
  -NSFont *QFont::getNSFont() const
  +const WebCoreFont &QFont::getWebCoreFont() const
   {
  -    if (!_NSFont) {
  +    if (!m_webCoreFont.font) {
           CREATE_FAMILY_ARRAY(*this, families);
   	KWQ_BLOCK_EXCEPTIONS;
  -        _NSFont = KWQRetain([[WebCoreTextRendererFactory sharedFactory] 
  -            fontWithFamilies:families
  -                      traits:getNSTraits() 
  -                        size:getNSSize()]);
  +        m_webCoreFont = [[WebCoreTextRendererFactory sharedFactory] 
  +            fontWithFamilies:families traits:getNSTraits() size:getNSSize()];
  +        KWQRetain(m_webCoreFont.font);
  +        m_webCoreFont.forPrinter = _isPrinterFont;
   	KWQ_UNBLOCK_EXCEPTIONS;
       }
  -    return _NSFont;
  +    return m_webCoreFont;
   }
  
  
  
  1.91      +2 -5      WebCore/kwq/KWQFontMetrics.mm
  
  Index: KWQFontMetrics.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQFontMetrics.mm,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- KWQFontMetrics.mm	3 Oct 2005 21:13:03 -0000	1.90
  +++ KWQFontMetrics.mm	6 Oct 2005 15:45:54 -0000	1.91
  @@ -51,11 +51,8 @@
       }
       id <WebCoreTextRenderer> getRenderer()
       {
  -        if (!_renderer) {
  -            _renderer = KWQRetain([[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:_font.getNSFont()
  -                usingPrinterFont:_font.isPrinterFont()]);
  -        }
  +        if (!_renderer)
  +            _renderer = KWQRetain([[WebCoreTextRendererFactory sharedFactory] rendererWithFont:_font.getWebCoreFont()]);
           return _renderer;
       }
       
  
  
  
  1.73      +6 -5      WebCore/kwq/KWQLineEdit.mm
  
  Index: KWQLineEdit.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQLineEdit.mm,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- KWQLineEdit.mm	3 Oct 2005 21:13:06 -0000	1.72
  +++ KWQLineEdit.mm	6 Oct 2005 15:45:54 -0000	1.73
  @@ -255,12 +255,13 @@
   
       KWQ_BLOCK_EXCEPTIONS;
   
  -    NSFont *font = [textField font];
  -
  -    size.height += [font defaultLineHeightForFont];
  +    WebCoreFont font;
  +    WebCoreInitializeFont(&font);
  +    font.font = [textField font];
  +    font.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
  +    id <WebCoreTextRenderer> renderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font];
   
  -    id <WebCoreTextRenderer> renderer = [[WebCoreTextRendererFactory sharedFactory]
  -        rendererWithFont:font usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  +    size.height += [font.font defaultLineHeightForFont];
   
       WebCoreTextStyle style;
       WebCoreInitializeEmptyTextStyle(&style);
  
  
  
  1.60      +33 -44    WebCore/kwq/KWQListBox.mm
  
  Index: KWQListBox.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQListBox.mm,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- KWQListBox.mm	3 Oct 2005 21:13:06 -0000	1.59
  +++ KWQListBox.mm	6 Oct 2005 15:45:55 -0000	1.60
  @@ -81,24 +81,23 @@
       return font;
   }
   
  -static NSFont *groupLabelFont()
  -{
  -    static NSFont *font = [[NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]] retain];
  -    return font;
  -}
  -
   static id <WebCoreTextRenderer> itemTextRenderer()
   {
       if ([NSGraphicsContext currentContextDrawingToScreen]) {
           if (itemScreenRenderer == nil) {
  -            itemScreenRenderer = [[[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:itemFont() usingPrinterFont:NO] retain];
  +            WebCoreFont font;
  +            WebCoreInitializeFont(&font);
  +            font.font = itemFont();
  +            itemScreenRenderer = [[[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font] retain];
           }
           return itemScreenRenderer;
       } else {
           if (itemPrinterRenderer == nil) {
  -            itemPrinterRenderer = [[[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:itemFont() usingPrinterFont:YES] retain];
  +            WebCoreFont font;
  +            WebCoreInitializeFont(&font);
  +            font.font = itemFont();
  +            font.forPrinter = YES;
  +            itemPrinterRenderer = [[[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font] retain];
           }
           return itemPrinterRenderer;
       }
  @@ -108,14 +107,19 @@
   {
       if ([NSGraphicsContext currentContextDrawingToScreen]) {
           if (groupLabelScreenRenderer == nil) {
  -            groupLabelScreenRenderer = [[[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:groupLabelFont() usingPrinterFont:NO] retain];
  +            WebCoreFont font;
  +            WebCoreInitializeFont(&font);
  +            font.font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
  +            groupLabelScreenRenderer = [[[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font] retain];
           }
           return groupLabelScreenRenderer;
       } else {
           if (groupLabelPrinterRenderer == nil) {
  -            groupLabelPrinterRenderer = [[[WebCoreTextRendererFactory sharedFactory]
  -                rendererWithFont:groupLabelFont() usingPrinterFont:YES] retain];
  +            WebCoreFont font;
  +            WebCoreInitializeFont(&font);
  +            font.font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
  +            font.forPrinter = YES;
  +            groupLabelPrinterRenderer = [[[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font] retain];
           }
           return groupLabelPrinterRenderer;
       }
  @@ -285,19 +289,11 @@
               if (tableView->isSystemFont) {        
                   renderer = itemTextRenderer();
                   groupLabelRenderer = groupLabelTextRenderer();
  -            }
  -            else {
  -                NSFont *f = font().getNSFont();
  +            } else {
  +                renderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:font().getWebCoreFont()];
                   QFont b = font();
  -                b.setWeight(QFont::Bold);
  -                NSFont *boldFont = b.getNSFont();
  -            
  -            
  -                renderer = [[WebCoreTextRendererFactory sharedFactory]
  -                    rendererWithFont:f usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  -
  -                groupLabelRenderer = [[WebCoreTextRendererFactory sharedFactory]
  -                    rendererWithFont:boldFont usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  +                b.setWeight(QFont::Bold);            
  +                groupLabelRenderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:b.getWebCoreFont()];
               }
               
               do {
  @@ -318,9 +314,8 @@
           _widthGood = true;
       }
       
  -    NSSize nssize = { _width, [tableView rowHeight] * MAX(minLines, lines) };
  -    size = [NSScrollView frameSizeForContentSize:nssize
  -        hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSBezelBorder];
  +    NSSize contentSize = { _width, [tableView rowHeight] * MAX(minLines, lines) };
  +    size = [NSScrollView frameSizeForContentSize:contentSize hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSBezelBorder];
       size.width += [NSScroller scrollerWidthForControlSize:NSSmallControlSize] - [NSScroller scrollerWidth] + leftMargin + rightMargin;
   
       KWQ_UNBLOCK_EXCEPTIONS;
  @@ -627,26 +622,21 @@
           color = [NSColor disabledControlTextColor];
       }
   
  -    bool RTL = _direction == NSWritingDirectionRightToLeft;
  +    bool rtl = _direction == NSWritingDirectionRightToLeft;
   
  -    NSFont *font = _box->font().getNSFont();
  -    
       id <WebCoreTextRenderer> renderer;
       if (isSystemFont) {
           renderer = (item.type == KWQListBoxGroupLabel) ? groupLabelTextRenderer() : itemTextRenderer();
       } else {
  -        if (item.type == KWQListBoxGroupLabel) {
  -            QFont boldFont = _box->font();
  -            boldFont.setWeight(QFont::Bold);
  -            font = boldFont.getNSFont();
  -        }
  -        renderer = [[WebCoreTextRendererFactory sharedFactory]
  -            rendererWithFont:font usingPrinterFont:![NSGraphicsContext currentContextDrawingToScreen]];
  +        QFont itemFont = _box->font();
  +        if (item.type == KWQListBoxGroupLabel)
  +            itemFont.setWeight(QFont::Bold);
  +        renderer = [[WebCoreTextRendererFactory sharedFactory] rendererWithFont:itemFont.getWebCoreFont()];
       }
      
       WebCoreTextStyle style;
       WebCoreInitializeEmptyTextStyle(&style);
  -    style.rtl = RTL;
  +    style.rtl = rtl;
       style.applyRunRounding = NO;
       style.applyWordRounding = NO;
       style.textColor = color;
  @@ -657,12 +647,12 @@
   
       NSRect cellRect = [self frameOfCellAtColumn:0 row:row];
       NSPoint point;
  -    if (!RTL) {
  +    if (!rtl) {
           point.x = NSMinX(cellRect) + leftMargin;
       } else {
           point.x = NSMaxX(cellRect) - rightMargin - [renderer floatWidthForRun:&run style:&style widths:0];
       }
  -    point.y = NSMaxY(cellRect) + [font descender] - bottomMargin;
  +    point.y = NSMaxY(cellRect) - [renderer descent] - bottomMargin;
   
       WebCoreTextGeometry geometry;
       WebCoreInitializeEmptyTextGeometry(&geometry);
  @@ -703,8 +693,7 @@
   - (void)fontChanged
   {
       NSFont *font = _box->font().getNSFont();
  -    isSystemFont = [[font fontName] isEqualToString:[itemFont() fontName]] && ([font pointSize] == [itemFont() pointSize]);
  -    
  +    isSystemFont = [[font fontName] isEqualToString:[itemFont() fontName]] && [font pointSize] == [itemFont() pointSize];
       [self setRowHeight:ceilf([font ascender] - [font descender] + bottomMargin)];
       [self setNeedsDisplay:YES];
   }
  
  
  
  1.145     +3 -4      WebCore/kwq/KWQPainter.mm
  
  Index: KWQPainter.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQPainter.mm,v
  retrieving revision 1.144
  retrieving revision 1.145
  diff -u -r1.144 -r1.145
  --- KWQPainter.mm	3 Oct 2005 21:13:07 -0000	1.144
  +++ KWQPainter.mm	6 Oct 2005 15:45:55 -0000	1.145
  @@ -606,8 +606,7 @@
           id <WebCoreTextRenderer> oldRenderer = data->textRenderer;
   	KWQ_BLOCK_EXCEPTIONS;
           data->textRenderer = KWQRetain([[WebCoreTextRendererFactory sharedFactory]
  -            rendererWithFont:data->textRendererFont.getNSFont()
  -            usingPrinterFont:data->textRendererFont.isPrinterFont()]);
  +            rendererWithFont:data->textRendererFont.getWebCoreFont()]);
           KWQRelease(oldRenderer);
   	KWQ_UNBLOCK_EXCEPTIONS;
       }
  @@ -667,7 +666,7 @@
       WebCoreInitializeEmptyTextStyle(&style);
       style.textColor = nsColor(data->state.pen.color());
       style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
  -    style.rtl = d == RTL ? true : false;
  +    style.rtl = d == RTL;
       style.directionalOverride = visuallyOrdered;
       style.letterSpacing = letterSpacing;
       style.wordSpacing = wordSpacing;
  @@ -706,7 +705,7 @@
       WebCoreInitializeEmptyTextStyle(&style);
       style.textColor = nsColor(data->state.pen.color());
       style.backgroundColor = backgroundColor.isValid() ? nsColor(backgroundColor) : nil;
  -    style.rtl = d == RTL ? true : false;
  +    style.rtl = d == RTL;
       style.directionalOverride = visuallyOrdered;
       style.letterSpacing = letterSpacing;
       style.wordSpacing = wordSpacing;
  
  
  
  1.13      +28 -4     WebCore/kwq/WebCoreTextRendererFactory.h
  
  Index: WebCoreTextRendererFactory.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/WebCoreTextRendererFactory.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- WebCoreTextRendererFactory.h	31 Aug 2004 00:49:17 -0000	1.12
  +++ WebCoreTextRendererFactory.h	6 Oct 2005 15:45:55 -0000	1.13
  @@ -23,18 +23,42 @@
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    */
   
  +#ifdef __OBJC__
   #import <Cocoa/Cocoa.h>
  -
   @protocol WebCoreTextRenderer;
  +#else
  +class NSFont;
  +#endif
  +
  +typedef struct WebCoreFont {
  +    NSFont *font;
  +    unsigned syntheticBold : 1;
  +    unsigned syntheticOblique : 1;
  +    unsigned forPrinter : 1;
  +} WebCoreFont;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +extern void WebCoreInitializeFont(WebCoreFont *font);
  +
  +#ifdef __cplusplus
  +}
  +#endif
  +
  +#ifdef __OBJC__
   
   @interface WebCoreTextRendererFactory : NSObject
   
   + (WebCoreTextRendererFactory *)sharedFactory;
   
  -- (NSFont *)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size;
  -- (BOOL)isFontFixedPitch:(NSFont *)font;
  -- (id <WebCoreTextRenderer>)rendererWithFont:(NSFont *)font usingPrinterFont:(BOOL)usingPrinterFont;
  +- (WebCoreFont)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size;
  +- (BOOL)isFontFixedPitch:(WebCoreFont)font;
  +- (id <WebCoreTextRenderer>)rendererWithFont:(WebCoreFont)font;
   
   - (void)clearCaches;
   
   @end
  +
  +#endif
  
  
  
  1.28      +28 -18    WebCore/kwq/WebCoreTextRendererFactory.mm
  
  Index: WebCoreTextRendererFactory.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/WebCoreTextRendererFactory.mm,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- WebCoreTextRendererFactory.mm	3 Oct 2005 21:13:12 -0000	1.27
  +++ WebCoreTextRendererFactory.mm	6 Oct 2005 15:45:55 -0000	1.28
  @@ -24,13 +24,21 @@
    */
   
   #include "config.h"
  -#import "WebCoreTextRenderer.h"
   #import "WebCoreTextRendererFactory.h"
   
   #import <kxmlcore/Assertions.h>
   #import "KWQKHTMLPart.h"
   #import "KWQListBox.h"
   #import "WebCoreBridge.h"
  +#import "WebCoreTextRenderer.h"
  +
  +void WebCoreInitializeFont(WebCoreFont *font)
  +{
  +    font->font = nil;
  +    font->syntheticBold = NO;
  +    font->syntheticOblique = NO;
  +    font->forPrinter = NO;
  +}
   
   void WebCoreInitializeTextRun(WebCoreTextRun *run, const UniChar *characters, unsigned int length, int from, int to)
   {
  @@ -42,28 +50,25 @@
   
   void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style)
   {
  -    style->padding = 0;
  -//    style->tabWidth = 0.0F;
  -//    style->xpos = 0.0F;
       style->textColor = nil;
       style->backgroundColor = nil;
  -    style->rtl = false;
  -    style->directionalOverride = false;
       style->letterSpacing = 0;
       style->wordSpacing = 0;
  -    style->smallCaps = false;
  -    style->applyRunRounding = true;
  -    style->applyWordRounding = true;
  -    style->attemptFontSubstitution = true;
  +    style->padding = 0;
       style->families = nil;
  +    style->smallCaps = NO;
  +    style->rtl = NO;
  +    style->directionalOverride = NO;
  +    style->applyRunRounding = YES;
  +    style->applyWordRounding = YES;
  +    style->attemptFontSubstitution = YES;
   }
   
   void WebCoreInitializeEmptyTextGeometry(WebCoreTextGeometry *geometry)
   {
  -    geometry->point = NSMakePoint(0,0);
  -    geometry->selectionY = 0;
  -    geometry->selectionHeight = 0;
  -    geometry->useFontMetricsForSelectionYAndHeight = true;
  +    geometry->point.x = 0;
  +    geometry->point.y = 0;
  +    geometry->useFontMetricsForSelectionYAndHeight = YES;
   }
   
   @implementation WebCoreTextRendererFactory
  @@ -85,18 +90,23 @@
       return self;
   }
   
  -- (NSFont *)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size
  +- (WebCoreFont)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size
   {
  -    return nil;
  +    ERROR("fontWithFamilies needs to be implemented in text renderer factory subclass");
  +    WebCoreFont font;
  +    WebCoreInitializeFont(&font);
  +    return font;
   }
   
  -- (BOOL)isFontFixedPitch:(NSFont *)font
  +- (BOOL)isFontFixedPitch:(WebCoreFont)font
   {
  +    ERROR("isFontFixedPitch needs to be implemented in text renderer factory subclass");
       return NO;
   }
   
  -- (id <WebCoreTextRenderer>)rendererWithFont:(NSFont *)font usingPrinterFont:(BOOL)usingPrinterFont
  +- (id <WebCoreTextRenderer>)rendererWithFont:(WebCoreFont)font
   {
  +    ERROR("rendererForFont needs to be implemented in text renderer factory subclass");
       return nil;
   }
   
  
  
  
  1.3340    +97 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3339
  retrieving revision 1.3340
  diff -u -r1.3339 -r1.3340
  --- ChangeLog	5 Oct 2005 21:07:30 -0000	1.3339
  +++ ChangeLog	6 Oct 2005 15:45:57 -0000	1.3340
  @@ -1,3 +1,100 @@
  +2005-10-06  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Hyatt.
  +
  +        - fixed <rdar://problem/3217793> Monaco bold comes out as Helvetica bold, very bad if you choose Monaco as your fixed-width font
  +        - fixed <rdar://problem/3256269> CSS1: bold/italic font styles not programmatically created if font doesn't include them (3231)
  +          also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3231>
  +
  +        * WebCoreSupport.subproj/WebTextRenderer.h: Removed public declarations of private structures that are not
  +        used in the header. Removed the separate 16-bit character map; the difference in code size is only a few
  +        bytes per page and there's no measurable performance difference by always using the 32-bit character version.
  +        Removed substitute font width maps altogether, since we now use the width map in the substitute font's renderer.
  +        Also removed a few more now-unused fields and methods. Changed initWithFont to take WebCoreFont. Changed
  +        the setAlwaysUseATSU: method to remove the underscore prefix.
  +
  +        * WebCoreSupport.subproj/WebTextRenderer.m:
  +        (getUncachedWidth): Get font from WebCoreFont directly instead of taking a parameter, since we now use only
  +        one NSFont per WebTextRenderer.
  +        (widthFromMap): Removed NSFont parameter for same reason as above; simplified.
  +        (widthForGlyph): Ditto.
  +        (overrideLayoutOperation): Updated for change to WebCoreFont.
  +        (-[WebTextRenderer initWithFont:]): Changed to use WebCoreFont. Removed code to deal with substitute font maps.
  +        Changed lineGap computation to use floats instead of doubles. Added code to compute a synthetic bold offset.
  +        Currently this is the font size divided by 24 and then rounded up to an integer.
  +        (-[WebTextRenderer dealloc]): Updated for change to WebCoreFont and other related changes.
  +        (-[WebTextRenderer finalize]): Ditto.
  +        (-[WebTextRenderer xHeight]): Ditto.
  +        (-[WebTextRenderer drawRun:style:geometry:]): Remove small caps case here; no longer needed. Also updated as above.
  +        (-[WebTextRenderer floatWidthForRun:style:widths:]): Ditto.
  +        (-[WebTextRenderer drawHighlightForRun:style:geometry:]): Ditto.
  +        (-[WebTextRenderer pointToOffset:style:position:reversed:includePartialGlyphs:]): Ditto.
  +        (+[WebTextRenderer setAlwaysUseATSU:]): Renamed to remove underscore prefix.
  +        (-[WebTextRenderer smallCapsRenderer]): Ditto. Changed to create a renderer for the smaller sized font.
  +        (-[WebTextRenderer _substituteFontForString:families:]): Reorganized this to be more readable and to call
  +        the new rendererForAlternateFont method.
  +        (-[WebTextRenderer rendererForAlternateFont:]): Added. Used to select an alternate font taking into account
  +        bold and italic synthesis.
  +        (-[WebTextRenderer substituteRendererForCharacters:length:families:]): Renamed to remove underscore prefix.
  +        Updated to use rendererForAlternateFont.
  +        (-[WebTextRenderer _computeWidthForSpace]): Updated for name changes and to remove unnecessary parameters.
  +        (-[WebTextRenderer setUpFont]): Renamed to remove underscore prefix. Added code to get printer or screen
  +        font as specified by WebCoreFont so calers don't need to do this.
  +        (drawGlyphs): Renamed to remove underscore prefix. Added code for synthetic oblique (14 degree slant), and
  +        synthetic bold (add offset and draw text a second time).
  +        (-[WebTextRenderer _CG_drawRun:style:geometry:]): Keep an array of substitute renderers instead of fonts.
  +        Changed around the loop to reverse the run to be a single loop instead of 3.
  +        (-[WebTextRenderer floatWidthForRun:style:widths:substituteRenderers:glyphs:startPosition:numGlyphs:]):
  +        Renamed to remove the underscore prefix.
  +        (-[WebTextRenderer _CG_floatWidthForRun:style:widths:substituteRenderers:glyphs:startPosition:numGlyphs:]):
  +        Changed to use subsitute renderers rather than fonts.
  +        (-[WebTextRenderer updateGlyphEntryForCharacter:glyphID:substituteRenderer:]): Renamed to remove underscore
  +        prefix and changed to use a substitute renderer rather than a substitute NSFont.
  +        (-[WebTextRenderer extendCharacterToGlyphMapToInclude:]): Updated to work with all characters, both ones
  +        that fit into 16-bit and ones that don't.
  +        (-[WebTextRenderer _extendGlyphToWidthMapToInclude:]): Removed NSFont parameter and simplified. This fixes
  +        a bug where numberOfGlyphs was accidentally used from the main font instead of "subFont".
  +        (glyphForCharacter): Changed to use subsitute renderers instead of substitute fonts.
  +        (widthForNextCharacter): Ditto. Also removed small caps code no longer needed here and replaced it with
  +        simpler small caps code that no longer assumes glyphs match.
  +        (shouldUseATSU): Changed the code to check ranges in order to slightly reduce the number of cases and
  +        to create earlier exit for lower character codes.
  +
  +        * WebCoreSupport.subproj/WebTextRendererFactory.h: Added caches for synthesized font and oblique
  +        variants so we can still use the NSFont as the dictionary key. Removed coalesceTextDrawing methods.
  +        Changed methods to use WebCoreFont as the parameters and results instead of NSFont.
  +        * WebCoreSupport.subproj/WebTextRendererFactory.m:
  +        (-[WebTextRendererFactory clearCaches]): Clear all 8 caches.
  +        (-[WebTextRendererFactory isFontFixedPitch:]): Changed code slightly so there's only one call to
  +        the CFDictionarySetValue function.
  +        (-[WebTextRendererFactory init]): Create all 8 caches.
  +        (-[WebTextRendererFactory dealloc]): Release all 8 caches.
  +        (-[WebTextRendererFactory rendererWithFont:]): Select the appropriate cache based on 3 booleans:
  +        synthetic bold, synthetic oblique, and printer. Use WebCoreFont instead of NSFont.
  +        (-[WebTextRendererFactory fontWithFamilies:traits:size:]): Set the synthetic bold and oblique flags
  +        when returning a WebCoreFont based on requested traits that are not present in the NSFont.
  +        (acceptableChoice): Ignore the synthesizable traits when deciding if a chosen font is acceptable.
  +        (betterChoice): Rather than assuming that every font has all the desired traits, implement a rule
  +        that says a font with an unwanted trait loses out over a font that does not have an unwanted trait.
  +        This lets us chose a bold font over a non-bold font that could use synthesized bold but treat both
  +        as candidates.
  +
  +        * WebCoreSupport.subproj/WebGlyphBuffer.h: Removed.
  +        * WebCoreSupport.subproj/WebGlyphBuffer.m: Removed.
  +        * WebKit.xcodeproj/project.pbxproj: Removed WebGlyphBuffer source files.
  +
  +        * Misc.subproj/WebKitNSStringExtras.m:
  +        (-[NSString _web_drawAtPoint:font:textColor:]): Update to use WebCoreFont.
  +        (-[NSString _web_widthWithFont:]): Ditto.
  +        * Misc.subproj/WebStringTruncator.m:
  +        (truncateString): Ditto.
  +        (+[WebStringTruncator widthOfString:font:]): Ditto.
  +
  +        * WebView.subproj/WebHTMLView.m: (-[WebHTMLView drawRect:]): Removed text drawing coalesce method calls.
  +        * WebView.subproj/WebTextView.m: (-[WebTextView setFixedWidthFont]): Updated to use cachedFontFromFamily
  +        method, which we still have, rather than fontWithFamilies method which we don't (since it now uses WebCoreFont).
  +        * WebView.subproj/WebView.m: (+[WebView _setAlwaysUseATSU:]): Updated for name change to underlying method.
  +
   2005-10-05  Maciej Stachowiak  <mjs at apple.com>
   
           Reviewed by Eric.
  
  
  
  1.27      +9 -3      WebKit/Misc.subproj/WebKitNSStringExtras.m
  
  Index: WebKitNSStringExtras.m
  ===================================================================
  RCS file: /cvs/root/WebKit/Misc.subproj/WebKitNSStringExtras.m,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- WebKitNSStringExtras.m	5 Jun 2005 17:54:25 -0000	1.26
  +++ WebKitNSStringExtras.m	6 Oct 2005 15:46:08 -0000	1.27
  @@ -56,8 +56,11 @@
   
       [self getCharacters:buffer];
       
  -    if (canUseFastRenderer(buffer, length)){
  -        WebTextRenderer *renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font usingPrinterFont:NO];
  +    if (canUseFastRenderer(buffer, length)) {
  +        WebCoreFont f;
  +        WebCoreInitializeFont(&f);
  +        f.font = font;
  +        WebTextRenderer *renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:f];
   
           WebCoreTextRun run;
           WebCoreInitializeTextRun (&run, buffer, length, 0, length);
  @@ -112,7 +115,10 @@
       [self getCharacters:buffer];
   
       if (canUseFastRenderer(buffer, length)){
  -        WebTextRenderer *renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font usingPrinterFont:NO];
  +        WebCoreFont f;
  +        WebCoreInitializeFont(&f);
  +        f.font = font;
  +        WebTextRenderer *renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:f];
   
           WebCoreTextRun run;
           WebCoreInitializeTextRun (&run, buffer, length, 0, length);
  
  
  
  1.23      +8 -2      WebKit/Misc.subproj/WebStringTruncator.m
  
  Index: WebStringTruncator.m
  ===================================================================
  RCS file: /cvs/root/WebKit/Misc.subproj/WebStringTruncator.m,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- WebStringTruncator.m	5 Jun 2005 17:54:26 -0000	1.22
  +++ WebStringTruncator.m	6 Oct 2005 15:46:08 -0000	1.23
  @@ -113,7 +113,10 @@
           currentFont = [font retain];
           [currentRenderer release];
           [WebTextRendererFactory createSharedFactory];
  -        currentRenderer = [[[WebTextRendererFactory sharedFactory] rendererWithFont:font usingPrinterFont:NO] retain];
  +        WebCoreFont f;
  +        WebCoreInitializeFont(&f);
  +        f.font = font;
  +        currentRenderer = [[[WebTextRendererFactory sharedFactory] rendererWithFont:f] retain];
           ellipsis = ELLIPSIS_CHARACTER;
           currentEllipsisWidth = stringWidth(currentRenderer, &ellipsis, 1);
       }
  @@ -219,7 +222,10 @@
       unsigned length = [string length];
       unichar *s = malloc(sizeof(unichar) * length);
       [string getCharacters:s];
  -    float width = stringWidth([[WebTextRendererFactory sharedFactory] rendererWithFont:font usingPrinterFont:NO], s, length);
  +    WebCoreFont f;
  +    WebCoreInitializeFont(&f);
  +    f.font = font;
  +    float width = stringWidth([[WebTextRendererFactory sharedFactory] rendererWithFont:f], s, length);
       free(s);
       return width;
   }
  
  
  
  1.39      +7 -25     WebKit/WebCoreSupport.subproj/WebTextRenderer.h
  
  Index: WebTextRenderer.h
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebTextRenderer.h,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- WebTextRenderer.h	12 Jul 2005 17:44:10 -0000	1.38
  +++ WebTextRenderer.h	6 Oct 2005 15:46:09 -0000	1.39
  @@ -27,17 +27,10 @@
    */
   
   #import <WebCore/WebCoreTextRenderer.h>
  +#import <WebCore/WebCoreTextRendererFactory.h>
   
   typedef struct WidthMap WidthMap;
  -typedef struct WidthEntry WidthEntry;
   typedef struct GlyphMap GlyphMap;
  -typedef struct GlyphEntry GlyphEntry;
  -typedef struct UnicodeGlyphMap UnicodeGlyphMap;
  -typedef struct SubstituteFontWidthMap SubstituteFontWidthMap;
  -typedef struct CharacterWidthIterator CharacterWidthIterator;
  -
  -/// Should be more than enough for normal usage.
  -#define NUM_SUBSTITUTE_FONT_MAPS	10
   
   @interface WebTextRenderer : NSObject <WebCoreTextRenderer>
   {
  @@ -49,40 +42,29 @@
       void *styleGroup;
       
   @public
  -    NSFont *font;
  -    GlyphMap *characterToGlyphMap;			// Used for 16bit clean unicode characters.
  -    UnicodeGlyphMap *unicodeCharacterToGlyphMap; 	// Used for surrogates.
  +    WebCoreFont font;
  +    GlyphMap *characterToGlyphMap;
       WidthMap *glyphToWidthMap;
   
       BOOL treatAsFixedPitch;
       ATSGlyphRef spaceGlyph;
       float spaceWidth;
       float adjustedSpaceWidth;
  -
  -    int numSubstituteFontWidthMaps;
  -    int maxSubstituteFontWidthMaps;
  -    SubstituteFontWidthMap *substituteFontWidthMaps;
  -    BOOL usingPrinterFont;
  -    BOOL isSmallCapsRenderer;
  +    float syntheticBoldOffset;
       
   @private
       WebTextRenderer *smallCapsRenderer;
  -    NSFont *smallCapsFont;
  -    ATSUStyle _ATSUSstyle;
  +    ATSUStyle _ATSUStyle;
       BOOL ATSUStyleInitialized;
       BOOL ATSUMirrors;
   }
   
  -+ (BOOL)shouldBufferTextDrawing;
  -
  -- (id)initWithFont:(NSFont *)font usingPrinterFont:(BOOL)usingPrinterFont;
  +- (id)initWithFont:(WebCoreFont)font;
   
   @end
   
  -
   @interface WebTextRenderer (WebPrivate)
   
  -+ (void)_setAlwaysUseATSU:(BOOL)f;
  ++ (void)setAlwaysUseATSU:(BOOL)f;
   
   @end
  -
  
  
  
  1.193     +462 -770  WebKit/WebCoreSupport.subproj/WebTextRenderer.m
  
  Index: WebTextRenderer.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebTextRenderer.m,v
  retrieving revision 1.192
  retrieving revision 1.193
  diff -u -r1.192 -r1.193
  --- WebTextRenderer.m	24 Sep 2005 13:36:53 -0000	1.192
  +++ WebTextRenderer.m	6 Oct 2005 15:46:09 -0000	1.193
  @@ -31,7 +31,6 @@
   #import <ApplicationServices/ApplicationServices.h>
   #import <Cocoa/Cocoa.h>
   
  -#import <WebKit/WebGlyphBuffer.h>
   #import <WebKit/WebGraphicsBridge.h>
   #import <WebKit/WebKitLogging.h>
   #import <WebKit/WebNSObjectExtras.h>
  @@ -46,9 +45,14 @@
   
   // FIXME: FATAL_ALWAYS seems like a bad idea; lets stop using it.
   
  -// SPI from other frameworks.
  +#define SMALLCAPS_FONTSIZE_MULTIPLIER 0.7f
  +
  +// Should be more than enough for normal usage.
  +#define NUM_SUBSTITUTE_FONT_MAPS 10
  +
  +// According to http://www.unicode.org/Public/UNIDATA/UCD.html#Canonical_Combining_Class_Values
  +#define HIRAGANA_KATAKANA_VOICING_MARKS 8
   
  -// Macros
   #define SPACE 0x0020
   #define NO_BREAK_SPACE 0x00A0
   #define ZERO_WIDTH_SPACE 0x200B
  @@ -70,10 +74,7 @@
   
   #define UNINITIALIZED_GLYPH_WIDTH 65535
   
  -#define ATSFontRefFromNSFont(font) (FMGetATSFontRefFromFont((FMFont)WKGetNSFontATSUFontId(font)))
  -
  -#define SMALLCAPS_FONTSIZE_MULTIPLIER 0.7F
  -#define INVALID_WIDTH -(__FLT_MAX__)
  +#define INVALID_WIDTH (-FLT_MAX)
   
   #if !defined(ScaleEmToUnits)
   #define CONTEXT_DPI	(72.0)
  @@ -81,48 +82,29 @@
   #define ScaleEmToUnits(X, U_PER_EM)	(X * ((1.0 * CONTEXT_DPI) / (CONTEXT_DPI * U_PER_EM)))
   #endif
   
  -// Datatypes
   typedef float WebGlyphWidth;
   typedef UInt32 UnicodeChar;
   
  -struct WidthEntry {
  -    WebGlyphWidth width;
  -};
  -
   struct WidthMap {
       ATSGlyphRef startRange;
       ATSGlyphRef endRange;
       WidthMap *next;
  -    WidthEntry *widths;
  +    WebGlyphWidth *widths;
   };
   
  -struct GlyphEntry
  -{
  +typedef struct GlyphEntry {
       ATSGlyphRef glyph;
  -    NSFont *font;
  -};
  +    WebTextRenderer *substituteRenderer;
  +} GlyphEntry;
   
   struct GlyphMap {
  -    UniChar startRange;
  -    UniChar endRange;
  -    GlyphMap *next;
  -    GlyphEntry *glyphs;
  -};
  -
  -struct UnicodeGlyphMap {
       UnicodeChar startRange;
       UnicodeChar endRange;
  -    UnicodeGlyphMap *next;
  +    GlyphMap *next;
       GlyphEntry *glyphs;
   };
   
  -struct SubstituteFontWidthMap {
  -    NSFont *font;
  -    WidthMap *map;
  -};
  -
  -struct CharacterWidthIterator
  -{
  +typedef struct CharacterWidthIterator {
       WebTextRenderer *renderer;
       const WebCoreTextRun *run;
       const WebCoreTextStyle *style;
  @@ -131,9 +113,9 @@
       float widthToStart;
       float padding;
       float padPerSpace;
  -};
  +} CharacterWidthIterator;
   
  -typedef struct
  +typedef struct ATSULayoutParameters
   {
       WebTextRenderer *renderer;
       const WebCoreTextRun *run;
  @@ -141,20 +123,19 @@
       ATSUTextLayout layout;
   } ATSULayoutParameters;
   
  -// Internal API
   @interface WebTextRenderer (WebInternal)
   
  -- (NSFont *)_substituteFontForCharacters: (const unichar *)characters length: (int)numCharacters families: (NSString **)families;
  +- (WebTextRenderer *)substituteRendererForCharacters:(const unichar *)characters length:(int)numCharacters families:(NSString **)families;
  +- (WebTextRenderer *)rendererForAlternateFont:(WebCoreFont)alternateNSFont;
   
  -- (WidthMap *)_extendGlyphToWidthMapToInclude:(ATSGlyphRef)glyphID font:(NSFont *)font;
  -- (ATSGlyphRef)_extendCharacterToGlyphMapToInclude:(UniChar) c;
  -- (ATSGlyphRef)_extendUnicodeCharacterToGlyphMapToInclude: (UnicodeChar)c;
  -- (void)_updateGlyphEntryForCharacter: (UniChar)c glyphID: (ATSGlyphRef)glyphID font: (NSFont *)substituteFont;
  +- (WidthMap *)_extendGlyphToWidthMapToInclude:(ATSGlyphRef)glyphID;
  +- (ATSGlyphRef)extendCharacterToGlyphMapToInclude:(UnicodeChar)c;
  +- (void)updateGlyphEntryForCharacter:(UnicodeChar)c glyphID:(ATSGlyphRef)glyphID substituteRenderer:(WebTextRenderer *)substituteRenderer;
   
  -- (float)_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer fonts:(NSFont **)fontBuffer glyphs:(CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs:(int *)_numGlyphs;
  +- (float)floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer substituteRenderers:(WebTextRenderer **)rendererBuffer glyphs:(CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs:(int *)_numGlyphs;
   
   // Measuring runs.
  -- (float)_CG_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths: (float *)widthBuffer fonts: (NSFont **)fontBuffer glyphs: (CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs: (int *)_numGlyphs;
  +- (float)_CG_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths: (float *)widthBuffer substituteRenderers:(WebTextRenderer **)rendererBuffer glyphs: (CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs: (int *)_numGlyphs;
   - (float)_ATSU_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style;
   
   // Drawing runs.
  @@ -169,19 +150,14 @@
   - (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
   - (void)_ATSU_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry;
   
  -- (BOOL)_setupFont;
  +- (BOOL)setUpFont;
   
   - (ATSUTextLayout)_createATSUTextLayoutForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style;
   
  -// Small caps
  -- (void)_setIsSmallCapsRenderer:(BOOL)flag;
  -- (BOOL)_isSmallCapsRenderer;
  -- (WebTextRenderer *)_smallCapsRenderer;
  -- (NSFont *)_smallCapsFont;
  +- (WebTextRenderer *)smallCapsRenderer;
   
   @end
   
  -
   // Character property functions.
   
   static inline BOOL isSpace(UniChar c)
  @@ -208,18 +184,10 @@
   // Map utility functions
   static void freeWidthMap(WidthMap *map);
   static void freeGlyphMap(GlyphMap *map);
  -static void freeUnicodeGlyphMap(UnicodeGlyphMap *map);
  -static inline ATSGlyphRef glyphForUnicodeCharacter (UnicodeGlyphMap *map, UnicodeChar c, NSFont **font);
  -static inline SubstituteFontWidthMap *mapForSubstituteFont(WebTextRenderer *renderer, NSFont *font);
  -static inline ATSGlyphRef glyphForCharacter (GlyphMap *map, UniChar c, NSFont **font);
  -static inline SubstituteFontWidthMap *mapForSubstituteFont(WebTextRenderer *renderer, NSFont *font);
  -static inline WebGlyphWidth widthFromMap (WebTextRenderer *renderer, WidthMap *map, ATSGlyphRef glyph, NSFont *font);
  -static inline WebGlyphWidth widthForGlyph (WebTextRenderer *renderer, ATSGlyphRef glyph, NSFont *font);
   
  -static WebGlyphWidth getUncachedWidth(WebTextRenderer *renderer, WidthMap *map, ATSGlyphRef glyph, NSFont *font)
  +static WebGlyphWidth getUncachedWidth(WebTextRenderer *renderer, WidthMap *map, ATSGlyphRef glyph)
   {
  -    if (font == NULL)
  -        font = renderer->font;
  +    NSFont *font = renderer->font.font;
   
       float pointSize = [font pointSize];
       CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
  @@ -232,40 +200,28 @@
       return advance.width;
   }
   
  -static inline WebGlyphWidth widthFromMap (WebTextRenderer *renderer, WidthMap *map, ATSGlyphRef glyph, NSFont *font)
  +static inline WebGlyphWidth widthFromMap(WebTextRenderer *renderer, WidthMap *map, ATSGlyphRef glyph)
   {
  -    WebGlyphWidth width = UNINITIALIZED_GLYPH_WIDTH;
  -    
  -    while (1){
  +    while (1) {
           if (map == 0)
  -            map = [renderer _extendGlyphToWidthMapToInclude: glyph font:font];
  +            map = [renderer _extendGlyphToWidthMapToInclude:glyph];
   
  -        if (glyph >= map->startRange && glyph <= map->endRange){
  -            width = map->widths[glyph - map->startRange].width;
  -            if (width == UNINITIALIZED_GLYPH_WIDTH){
  -                width = getUncachedWidth (renderer, map, glyph, font);
  -                map->widths[glyph - map->startRange].width = width;
  +        if (glyph >= map->startRange && glyph <= map->endRange) {
  +            WebGlyphWidth width = map->widths[glyph - map->startRange];
  +            if (width == UNINITIALIZED_GLYPH_WIDTH) {
  +                width = getUncachedWidth(renderer, map, glyph);
  +                map->widths[glyph - map->startRange] = width;
               }
  +            return width;
           }
  -        else {
  -            map = map->next;
  -            continue;
  -        }
  -        
  -        return width;
  +
  +        map = map->next;
       }
   }    
   
  -static inline WebGlyphWidth widthForGlyph (WebTextRenderer *renderer, ATSGlyphRef glyph, NSFont *font)
  +static inline WebGlyphWidth widthForGlyph(WebTextRenderer *renderer, ATSGlyphRef glyph)
   {
  -    WidthMap *map;
  -
  -    if (font && font != renderer->font)
  -        map = mapForSubstituteFont(renderer, font)->map;
  -    else
  -        map = renderer->glyphToWidthMap;
  -
  -    return widthFromMap (renderer, map, glyph, font);
  +    return widthFromMap(renderer, renderer->glyphToWidthMap, glyph) + renderer->syntheticBoldOffset;
   }
   
   static OSStatus overrideLayoutOperation(ATSULayoutOperationSelector iCurrentOperation, ATSULineRef iLineRef, UInt32 iRefCon, void *iOperationCallbackParameterPtr, ATSULayoutOperationCallbackStatus *oCallbackStatus)
  @@ -286,7 +242,7 @@
           // The CoreGraphics interpretation of NSFontAntialiasedIntegerAdvancementsRenderingMode seems
           // to be "round each glyph's width to the nearest integer". This is not the same as ATSUI
           // does in any of its device-metrics modes.
  -        Boolean roundEachGlyph = [params->renderer->font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderingMode;
  +        Boolean roundEachGlyph = [params->renderer->font.font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderingMode;
           Fixed lastNativePos = 0;
           float lastAdjustedPos = 0;
           const WebCoreTextRun *run = params->run;
  @@ -329,24 +285,22 @@
   }
   
   // Iterator functions
  -static void initializeCharacterWidthIterator (CharacterWidthIterator *iterator, WebTextRenderer *renderer, const WebCoreTextRun *run , const WebCoreTextStyle *style);
  -static float widthForNextCharacter (CharacterWidthIterator *iterator, ATSGlyphRef *glyphUsed, NSFont **fontUsed);
  +static void initializeCharacterWidthIterator(CharacterWidthIterator *iterator, WebTextRenderer *renderer, const WebCoreTextRun *run , const WebCoreTextStyle *style);
  +static float widthForNextCharacter(CharacterWidthIterator *iterator, ATSGlyphRef *glyphUsed, WebTextRenderer **rendererUsed);
   
  -
  -// Misc.
   static BOOL fillStyleWithAttributes(ATSUStyle style, NSFont *theFont);
   static BOOL shouldUseATSU(const WebCoreTextRun *run);
  +
  +#if !ERROR_DISABLED
   static NSString *pathFromFont(NSFont *font);
  +#endif
  +
   static void createATSULayoutParameters(ATSULayoutParameters *params, WebTextRenderer *renderer, const WebCoreTextRun *run , const WebCoreTextStyle *style);
   static void disposeATSULayoutParameters(ATSULayoutParameters *params);
   
  -
   // Globals
  -static CFCharacterSetRef nonBaseChars = NULL;
  -static BOOL bufferTextDrawing = NO;
   static BOOL alwaysUseATSU = NO;
   
  -
   @implementation WebTextRenderer
   
   + (NSString *)webFallbackFontFamily
  @@ -357,171 +311,123 @@
       return webFallbackFontFamily;
   }
   
  -+ (BOOL)shouldBufferTextDrawing
  -{
  -    return bufferTextDrawing;
  -}
  -
  -+ (void)initialize
  -{
  -    nonBaseChars = CFCharacterSetGetPredefined(kCFCharacterSetNonBase);
  -    bufferTextDrawing = [[[NSUserDefaults standardUserDefaults] stringForKey:@"BufferTextDrawing"] isEqual: @"YES"];
  -}
  -
  -- initWithFont:(NSFont *)f usingPrinterFont:(BOOL)p
  +- initWithFont:(WebCoreFont)f
   {
       [super init];
       
       // Quartz can only handle fonts with these glyph packings.  Other packings have
       // been deprecated.
  -    if ([f glyphPacking] != NSNativeShortGlyphPacking &&
  -        [f glyphPacking] != NSTwoByteGlyphPacking) {
  -        // Apparantly there are many deprecated fonts out there with unsupported packing types.
  +    if ([f.font glyphPacking] != NSNativeShortGlyphPacking && [f.font glyphPacking] != NSTwoByteGlyphPacking) {
  +        // Apparently there are many deprecated fonts out there with unsupported packing types.
           // Log and use fallback font.
  -        // This change fixes the many crashes reported in 3782533.  Most likely, the
  -        // problem is encountered when people upgrade from OS 9, or have OS 9
  -        // fonts installed on OS X.
  -        NSLog (@"%s:%d  Unable to use deprecated font %@ %f, using system font instead", __FILE__, __LINE__, [f displayName], [f pointSize]);
  -        f = [NSFont systemFontOfSize:[f pointSize]];
  +        // This change fixes the many crashes reported in 3782533.
  +        // Most likely, the problem is encountered when people upgrade from OS 9, or have OS 9 fonts installed on OS X.
  +        NSLog(@"%s:%d  Unable to use deprecated font %@ %f, using system font instead", __FILE__, __LINE__, [f.font displayName], [f.font pointSize]);
  +        f.font = [NSFont systemFontOfSize:[f.font pointSize]];
       }
  -        
  -    maxSubstituteFontWidthMaps = NUM_SUBSTITUTE_FONT_MAPS;
  -    substituteFontWidthMaps = calloc (1, maxSubstituteFontWidthMaps * sizeof(SubstituteFontWidthMap));
  -    font = [(p ? [f printerFont] : [f screenFont]) retain];
  -    usingPrinterFont = p;
  +
  +    font = f;
  +
  +    syntheticBoldOffset = f.syntheticBold ? ceilf([f.font pointSize] / 24.0f) : 0.f;
       
       bool failedSetup = false;
  -    if (![self _setupFont]){
  -        // Ack!  Something very bad happened, like a corrupt font.  Try
  -        // looking for an alternate 'base' font for this renderer.
  -
  -        // Special case hack to use "Times New Roman" in place of "Times".  "Times RO" is a common font
  -        // whose family name is "Times".  It overrides the normal "Times" family font.  It also
  -        // appears to have a corrupt regular variant.
  +    if (![self setUpFont]) {
  +        // Ack! Something very bad happened, like a corrupt font.
  +        // Try looking for an alternate 'base' font for this renderer.
  +
  +        // Special case hack to use "Times New Roman" in place of "Times".
  +        // "Times RO" is a common font whose family name is "Times".
  +        // It overrides the normal "Times" family font.
  +        // It also appears to have a corrupt regular variant.
           NSString *fallbackFontFamily;
  -
  -        if ([[font familyName] isEqual:@"Times"])
  +        if ([[font.font familyName] isEqual:@"Times"])
               fallbackFontFamily = @"Times New Roman";
  -        else {
  +        else
               fallbackFontFamily = [WebTextRenderer webFallbackFontFamily];
  -        }
           
  -        // Try setting up the alternate font.  This is a last ditch effort to use a
  -	// substitute font when something has gone wrong.
  -        NSFont *initialFont = font;
  -        [initialFont autorelease];
  -        NSFont *af = [[NSFontManager sharedFontManager] convertFont:font toFamily:fallbackFontFamily];
  -        font = [(p ? [af printerFont] : [af screenFont]) retain];
  +        // Try setting up the alternate font.
  +        // This is a last ditch effort to use a substitute font when something has gone wrong.
  +        NSFont *initialFont = font.font;
  +        font.font = [[NSFontManager sharedFontManager] convertFont:font.font toFamily:fallbackFontFamily];
  +#if !ERROR_DISABLED
           NSString *filePath = pathFromFont(initialFont);
  -        filePath = filePath ? filePath : (NSString *)@"not known";
  -        if (![self _setupFont]){
  +        if (!filePath)
  +            filePath = @"not known";
  +#endif
  +        if (![self setUpFont]) {
   	    if ([fallbackFontFamily isEqual:@"Times New Roman"]) {
   		// OK, couldn't setup Times New Roman as an alternate to Times, fallback
   		// on the system font.  If this fails we have no alternative left.
  -		af = [[NSFontManager sharedFontManager] convertFont:font toFamily:[WebTextRenderer webFallbackFontFamily]];
  -		font = [(p ? [af printerFont] : [af screenFont]) retain];
  -		if (![self _setupFont]){
  -		    // We tried, Times, Times New Roman, and the system font.  No joy.  We have to give up.
  -		    ERROR ("%@ unable to initialize with font %@ at %@", self, initialFont, filePath);
  +		font.font = [[NSFontManager sharedFontManager] convertFont:font.font toFamily:[WebTextRenderer webFallbackFontFamily]];
  +		if (![self setUpFont]) {
  +		    // We tried, Times, Times New Roman, and the system font. No joy. We have to give up.
  +		    ERROR("%@ unable to initialize with font %@ at %@", self, initialFont, filePath);
                       failedSetup = true;
   		}
  -	    }
  -	    else {
  -		// We tried the requested font and the syste, font.  No joy.  We have to give up.
  -		ERROR ("%@ unable to initialize with font %@ at %@", self, initialFont, filePath);
  +	    } else {
  +		// We tried the requested font and the system font. No joy. We have to give up.
  +		ERROR("%@ unable to initialize with font %@ at %@", self, initialFont, filePath);
                   failedSetup = true;
   	    }
           }
   
           // Report the problem.
  -        ERROR ("Corrupt font detected, using %@ in place of %@ located at \"%@\".", 
  -                    [font familyName], 
  -                    [initialFont familyName],
  -                    filePath);
  +        ERROR("Corrupt font detected, using %@ in place of %@ located at \"%@\".",
  +            [font.font familyName], [initialFont familyName], filePath);
       }
   
  -    // If all else fails try to setup using the system font.  This is probably because
  -    // Times and Times New Roman are both unavailable.
  +    // If all else fails, try to set up using the system font.
  +    // This is probably because Times and Times New Roman are both unavailable.
       if (failedSetup) {
  -        f = [NSFont systemFontOfSize:[f pointSize]];
  -        ERROR ("%@ failed to setup font, using system font %s", self, f);
  -        font = [(p ? [f printerFont] : [f screenFont]) retain];
  -        [self _setupFont];
  +        font.font = [NSFont systemFontOfSize:[font.font pointSize]];
  +        ERROR("%@ failed to set up font, using system font %s", self, font.font);
  +        [self setUpFont];
       }
       
       int iAscent;
       int iDescent;
       int iLineGap;
  -	unsigned unitsPerEm;
  -	WKGetFontMetrics(font, &iAscent, &iDescent, &iLineGap, &unitsPerEm); 
  -    float pointSize = [font pointSize];
  -    float asc = (ScaleEmToUnits(iAscent, unitsPerEm)*pointSize);
  -    float dsc = (-ScaleEmToUnits(iDescent, unitsPerEm)*pointSize);
  -    float _lineGap = ScaleEmToUnits(iLineGap, unitsPerEm)*pointSize;
  -    float adjustment;
  +    unsigned unitsPerEm;
  +    WKGetFontMetrics(font.font, &iAscent, &iDescent, &iLineGap, &unitsPerEm); 
  +    float pointSize = [font.font pointSize];
  +    float asc = ScaleEmToUnits(iAscent, unitsPerEm) * pointSize;
  +    float dsc = -ScaleEmToUnits(iDescent, unitsPerEm) * pointSize;
  +    float _lineGap = ScaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
   
       // We need to adjust Times, Helvetica, and Courier to closely match the
       // vertical metrics of their Microsoft counterparts that are the de facto
       // web standard.  The AppKit adjustment of 20% is too big and is
       // incorrectly added to line spacing, so we use a 15% adjustment instead
       // and add it to the ascent.
  -    if ([[font familyName] isEqualToString:@"Times"] ||
  -        [[font familyName] isEqualToString:@"Helvetica"] ||
  -        [[font familyName] isEqualToString:@"Courier"]) {
  -        adjustment = floor(((asc + dsc) * 0.15) + 0.5);
  -    } else {
  -        adjustment = 0.0;
  -    }
  +    NSString *familyName = [font.font familyName];
  +    if ([familyName isEqualToString:@"Times"] || [familyName isEqualToString:@"Helvetica"] || [familyName isEqualToString:@"Courier"])
  +        asc += floorf(((asc + dsc) * 0.15f) + 0.5f);
   
  -    ascent = ROUND_TO_INT(asc + adjustment);
  +    ascent = ROUND_TO_INT(asc);
       descent = ROUND_TO_INT(dsc);
   
  -    _lineGap = (_lineGap > 0.0 ? floor(_lineGap + 0.5) : 0.0);
  +    _lineGap = _lineGap > 0.0 ? floorf(_lineGap + 0.5f) : 0.0f;
       lineGap = (int)_lineGap;
  -    lineSpacing =  ascent + descent + lineGap;
  +    lineSpacing = ascent + descent + lineGap;
   
  -#ifdef COMPARE_APPKIT_CG_METRICS
  -    printf ("\nCG/Appkit metrics for font %s, %f, lineGap %f, adjustment %f\n", [[font displayName] cString], [font pointSize], lineGap, adjustment);
  -    if (ROUND_TO_INT([font ascender]) != ascent ||
  -        ROUND_TO_INT(-[font descender]) != descent ||
  -        ROUND_TO_INT([font defaultLineHeightForFont]) != lineSpacing){
  -        printf ("\nCG/Appkit mismatched metrics for font %s, %f (%s)\n", [[font displayName] cString], [font pointSize],
  -                ([font screenFont] ? [[[font screenFont] displayName] cString] : "none"));
  -        printf ("ascent(%s), descent(%s), lineSpacing(%s)\n",
  -                (ROUND_TO_INT([font ascender]) != ascent) ? "different" : "same",
  -                (ROUND_TO_INT(-[font descender]) != descent) ? "different" : "same",
  -                (ROUND_TO_INT([font defaultLineHeightForFont]) != lineSpacing) ? "different" : "same");
  -        printf ("CG:  ascent %f, ", asc);
  -        printf ("descent %f, ", dsc);
  -        printf ("lineGap %f, ", lineGap);
  -        printf ("lineSpacing %d\n", lineSpacing);
  -        
  -        printf ("NSFont:  ascent %f, ", [font ascender]);
  -        printf ("descent %f, ", [font descender]);
  -        printf ("lineSpacing %f\n", [font defaultLineHeightForFont]);
  -    }
  -#endif
  -     
  -    isSmallCapsRenderer = NO;
  +    [font.font retain];
       
       return self;
   }
   
   - (void)dealloc
   {
  -    [font release];
  -    [smallCapsFont release];
  +    [font.font release];
       [smallCapsRenderer release];
   
       if (styleGroup)
  -		WKReleaseStyleGroup(styleGroup);
  +        WKReleaseStyleGroup(styleGroup);
   
       freeWidthMap(glyphToWidthMap);
       freeGlyphMap(characterToGlyphMap);
  -    freeUnicodeGlyphMap(unicodeCharacterToGlyphMap);
   
       if (ATSUStyleInitialized)
  -        ATSUDisposeStyle(_ATSUSstyle);
  +        ATSUDisposeStyle(_ATSUStyle);
       
       [super dealloc];
   }
  @@ -533,10 +439,9 @@
   
       freeWidthMap(glyphToWidthMap);
       freeGlyphMap(characterToGlyphMap);
  -    freeUnicodeGlyphMap(unicodeCharacterToGlyphMap);
   
       if (ATSUStyleInitialized)
  -        ATSUDisposeStyle(_ATSUSstyle);
  +        ATSUDisposeStyle(_ATSUStyle);
       
       [super finalize];
   }
  @@ -561,12 +466,11 @@
   
   - (float)xHeight
   {
  -    // Measure the actual character "x", because AppKit synthesizes X height rather
  -    // than getting it from the font. Unfortunately, NSFont will round this for us
  -    // so we don't quite get the right value.
  -    NSGlyph xGlyph = [font glyphWithName:@"x"];
  +    // Measure the actual character "x", because AppKit synthesizes X height rather than getting it from the font.
  +    // Unfortunately, NSFont will round this for us so we don't quite get the right value.
  +    NSGlyph xGlyph = [font.font glyphWithName:@"x"];
       if (xGlyph) {
  -        NSRect xBox = [font boundingRectForGlyph:xGlyph];
  +        NSRect xBox = [font.font boundingRectForGlyph:xGlyph];
           // Use the maximum of either width or height because "x" is nearly square
           // and web pages that foolishly use this metric for width will be laid out
           // poorly if we return an accurate height. Classic case is Times 13 point,
  @@ -574,28 +478,21 @@
           return MAX(NSMaxX(xBox), NSMaxY(xBox));
       }
   
  -    return [font xHeight];
  +    return [font.font xHeight];
   }
   
   - (void)drawRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
   {
  -    if (style->smallCaps && !isSmallCapsRenderer) {
  -        [[self _smallCapsRenderer] drawRun:run style:style geometry:geometry];
  -    }
  -    else {
  -        if (shouldUseATSU(run))
  -            [self _ATSU_drawRun:run style:style geometry:geometry];
  -        else
  -            [self _CG_drawRun:run style:style geometry:geometry];
  -    }
  +    if (shouldUseATSU(run))
  +        [self _ATSU_drawRun:run style:style geometry:geometry];
  +    else
  +        [self _CG_drawRun:run style:style geometry:geometry];
   }
   
   - (float)floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer
   {
  -    if (style->smallCaps && !isSmallCapsRenderer) {
  -        return [[self _smallCapsRenderer] _floatWidthForRun:run style:style widths:widthBuffer fonts:nil glyphs:nil startPosition:nil numGlyphs:nil];
  -    }
  -    return [self _floatWidthForRun:run style:style widths:widthBuffer fonts:nil glyphs:nil startPosition:nil numGlyphs:nil];
  +    return [self floatWidthForRun:run style:style widths:widthBuffer
  +        substituteRenderers:0 glyphs:0 startPosition:0 numGlyphs:0];
   }
   
   - (void)drawLineForCharacters:(NSPoint)point yOffset:(float)yOffset width: (int)width color:(NSColor *)color thickness:(float)thickness
  @@ -653,15 +550,10 @@
   
   - (void)drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
   {
  -    if (style->smallCaps && !isSmallCapsRenderer) {
  -        [[self _smallCapsRenderer] drawHighlightForRun:run style:style geometry:geometry];
  -    }
  -    else {
  -        if (shouldUseATSU(run))
  -            [self _ATSU_drawHighlightForRun:run style:style geometry:geometry];
  -        else
  -            [self _CG_drawHighlightForRun:run style:style geometry:geometry];
  -    }
  +    if (shouldUseATSU(run))
  +        [self _ATSU_drawHighlightForRun:run style:style geometry:geometry];
  +    else
  +        [self _CG_drawHighlightForRun:run style:style geometry:geometry];
   }
   
   - (int)misspellingLineThickness
  @@ -729,10 +621,6 @@
   
   - (int)pointToOffset:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style position:(int)x reversed:(BOOL)reversed includePartialGlyphs:(BOOL)includePartialGlyphs
   {
  -    if (style->smallCaps && !isSmallCapsRenderer) {
  -        return [[self _smallCapsRenderer] pointToOffset:run style:style position:x reversed:reversed includePartialGlyphs:includePartialGlyphs];
  -    }
  -
       if (shouldUseATSU(run))
           return [self _ATSU_pointToOffset:run style:style position:x reversed:reversed includePartialGlyphs:includePartialGlyphs];
       return [self _CG_pointToOffset:run style:style position:x reversed:reversed includePartialGlyphs:includePartialGlyphs];
  @@ -746,139 +634,111 @@
   
   @implementation WebTextRenderer (WebInternal)
   
  -+ (void)_setAlwaysUseATSU:(BOOL)f
  ++ (void)setAlwaysUseATSU:(BOOL)f
   {
       alwaysUseATSU = f;
   }
   
  -- (void)_setIsSmallCapsRenderer:(BOOL)flag
  -{
  -    isSmallCapsRenderer = flag;
  -}
  -
  -- (BOOL)_isSmallCapsRenderer
  -{
  -    return isSmallCapsRenderer;
  -}
  -
  -- (WebTextRenderer *)_smallCapsRenderer
  +- (WebTextRenderer *)smallCapsRenderer
   {
       if (!smallCapsRenderer) {
   	NS_DURING
  -	    smallCapsRenderer = [[WebTextRenderer alloc] initWithFont:font usingPrinterFont:usingPrinterFont];
  +            float size = [font.font pointSize] * SMALLCAPS_FONTSIZE_MULTIPLIER;
  +            WebCoreFont smallCapsFont;
  +            WebCoreInitializeFont(&smallCapsFont);
  +            smallCapsFont.font = [[NSFontManager sharedFontManager] convertFont:font.font toSize:size];
  +	    smallCapsRenderer = [[self rendererForAlternateFont:smallCapsFont] retain];
   	NS_HANDLER
  -	    if (ASSERT_DISABLED) {
  -		NSLog(@"Uncaught exception - %@\n", localException);
  -	    } else {
  -		ASSERT_WITH_MESSAGE(0, "Uncaught exception - %@", localException);
  -	    } 
  +            NSLog(@"uncaught exception selecting font for small caps: %@", localException);
   	NS_ENDHANDLER
  -
  -        [smallCapsRenderer _setIsSmallCapsRenderer:YES];
       }
       return smallCapsRenderer;
   }
   
  -- (NSFont *)_smallCapsFont
  -{
  -    if (!smallCapsFont)
  -        smallCapsFont = [[[NSFontManager sharedFontManager] convertFont:font toSize:([font pointSize] * SMALLCAPS_FONTSIZE_MULTIPLIER)] screenFont];
  -    return usingPrinterFont ? [smallCapsFont printerFont] : smallCapsFont;
  -}
  -
   static inline BOOL fontContainsString(NSFont *font, NSString *string)
   {
       NSCharacterSet *set = [[font coveredCharacterSet] invertedSet];
       return set && [string rangeOfCharacterFromSet:set].location == NSNotFound;
   }
   
  -- (NSFont *)_substituteFontForString: (NSString *)string families: (NSString **)families
  +- (NSFont *)_substituteFontForString:(NSString *)string families:(NSString **)families
   {
       NSFont *substituteFont = nil;
   
  -    // First search the CSS family fallback list.  Start at 1 (2nd font)
  -    // because we've already failed on the first lookup.
  +    // First search the CSS family fallback list.
  +    // Start at 1 (2nd font) because we've already failed on the first lookup.
       NSString *family = nil;
       int i = 1;
  -    while (families && families[i] != 0) {
  +    while (families && families[i]) {
           family = families[i++];
  -        substituteFont = [[WebTextRendererFactory sharedFactory] cachedFontFromFamily: family traits:[[NSFontManager sharedFontManager] traitsOfFont:font] size:[font pointSize]];
  -        if (substituteFont) {
  -            if (fontContainsString(substituteFont, string))
  -                break;
  -            substituteFont = nil; 
  +        NSFont *f = [[WebTextRendererFactory sharedFactory] cachedFontFromFamily:family
  +            traits:[[NSFontManager sharedFontManager] traitsOfFont:font.font] size:[font.font pointSize]];
  +        if (f && fontContainsString(f, string)) {
  +            substituteFont = f; 
  +            break;
           }
       }
       
       // Now do string based lookup.
       if (substituteFont == nil)
  -        substituteFont = WKGetFontInLanguageForRange(font, string, NSMakeRange (0,[string length]));
  -		
  +        substituteFont = WKGetFontInLanguageForRange(font.font, string, NSMakeRange(0, [string length]));
   
       // Now do character based lookup.
       if (substituteFont == nil && [string length] == 1)
  -        substituteFont = WKGetFontInLanguageForCharacter(font, [string characterAtIndex: 0]);
  -
  -    // Get the screen or printer variation of the font.
  -    substituteFont = usingPrinterFont ? [substituteFont printerFont] : [substituteFont screenFont];
  +        substituteFont = WKGetFontInLanguageForCharacter(font.font, [string characterAtIndex:0]);
   
  -    if ([substituteFont isEqual: font])
  +    // Check to make sure this is a distinct font.
  +    if (substituteFont && [[substituteFont screenFont] isEqual:[font.font screenFont]])
           substituteFont = nil;
   
  -    // Now that we have a substitute font, attempt to match it to the best variation.  If we have
  -    // a good match return that, otherwise return the font the AppKit has found.
  -    NSFontManager *manager = [NSFontManager sharedFontManager];
  -    NSFont *substituteFont2 = [manager fontWithFamily:(NSString *)[substituteFont familyName] traits:[manager traitsOfFont:font] weight:[manager weightOfFont:font] size:[font pointSize]];
  -    if (substituteFont2)
  -	substituteFont = substituteFont2;
  -
  -    // Now, finally, get the printer or screen variation.
  -    substituteFont = usingPrinterFont ? [substituteFont printerFont] : [substituteFont screenFont];
  +    // Now that we have a substitute font, attempt to match it to the best variation.
  +    // If we have a good match return that, otherwise return the font the AppKit has found.
  +    if (substituteFont) {
  +        NSFontManager *manager = [NSFontManager sharedFontManager];
  +        NSFont *bestVariation = [manager fontWithFamily:[substituteFont familyName] traits:[manager traitsOfFont:font.font]
  +            weight:[manager weightOfFont:font.font] size:[font.font pointSize]];
  +        if (bestVariation)
  +            substituteFont = bestVariation;
  +    }
   
       return substituteFont;
   }
   
  -- (NSFont *)_substituteFontForCharacters: (const unichar *)characters length: (int)numCharacters families: (NSString **)families
  +- (WebTextRenderer *)rendererForAlternateFont:(WebCoreFont)alternateFont
   {
  -    NSString *string = [[NSString alloc] initWithCharactersNoCopy:(unichar *)characters length: numCharacters freeWhenDone: NO];
  -    NSFont *substituteFont = [self _substituteFontForString: string families: families];
  -    [string release];
  -    return substituteFont;
  +    if (!alternateFont.font)
  +        return nil;
  +
  +    NSFontManager *fontManager = [NSFontManager sharedFontManager];
  +    NSFontTraitMask fontTraits = [fontManager traitsOfFont:font.font];
  +    if (font.syntheticBold)
  +        fontTraits |= NSBoldFontMask;
  +    if (font.syntheticOblique)
  +        fontTraits |= NSItalicFontMask;
  +    NSFontTraitMask alternateFontTraits = [fontManager traitsOfFont:alternateFont.font];
  +
  +    alternateFont.syntheticBold = (fontTraits & NSBoldFontMask) && !(alternateFontTraits & NSBoldFontMask);
  +    alternateFont.syntheticOblique = (fontTraits & NSItalicFontMask) && !(alternateFontTraits & NSItalicFontMask);
  +    alternateFont.forPrinter = font.forPrinter;
  +
  +    return [[WebTextRendererFactory sharedFactory] rendererWithFont:alternateFont];
   }
   
  -- (void)_convertCharacters: (const UniChar *)characters length: (unsigned)numCharacters toGlyphs: (WKGlyphVectorRef)glyphs
  +- (WebTextRenderer *)substituteRendererForCharacters:(const unichar *)characters length:(int)numCharacters families:(NSString **)families
   {
  -    OSStatus status = WKConvertCharToGlyphs(styleGroup, characters, numCharacters, glyphs);
  -    if (status != noErr){
  -        FATAL_ALWAYS ("unable to get glyphsfor %@ %f error = (%d)", self, [font displayName], [font pointSize], status);
  -    }
  +    WebCoreFont substituteFont;
  +    WebCoreInitializeFont(&substituteFont);
  +    NSString *string = [[NSString alloc] initWithCharactersNoCopy:(unichar *)characters length: numCharacters freeWhenDone: NO];
  +    substituteFont.font = [self _substituteFontForString:string families:families];
  +    [string release];
  +    return [self rendererForAlternateFont:substituteFont];
   }
   
  -- (void)_convertUnicodeCharacters: (const UnicodeChar *)characters length: (unsigned)numCharacters toGlyphs: (WKGlyphVectorRef)glyphs
  +- (void)_convertCharacters:(const UniChar *)characters length:(unsigned)numCharacters toGlyphs:(WKGlyphVectorRef)glyphs
   {
  -    UniChar localBuffer[LOCAL_BUFFER_SIZE];
  -    UniChar *buffer = localBuffer;
  -    unsigned i, bufPos = 0;
  -    
  -    if (numCharacters*2 > LOCAL_BUFFER_SIZE) {
  -        buffer = (UniChar *)malloc(sizeof(UniChar) * numCharacters * 2);
  -    }
  -    
  -    for (i = 0; i < numCharacters; i++) {
  -        UnicodeChar c = characters[i];
  -        ASSERT(U16_LENGTH(c) == 2);
  -        buffer[bufPos++] = U16_LEAD(c);
  -        buffer[bufPos++] = U16_TRAIL(c);
  -    }
  -        
  -    OSStatus status = WKConvertCharToGlyphs(styleGroup, buffer, numCharacters*2, glyphs);
  -    if (status != noErr){
  -        FATAL_ALWAYS ("unable to get glyphsfor %@ %f error = (%d)", self, [font displayName], [font pointSize], status);
  -    }
  -    
  -    if (buffer != localBuffer) {
  -        free(buffer);
  -    }
  +    OSStatus status = WKConvertCharToGlyphs(styleGroup, characters, numCharacters, glyphs);
  +    if (status != noErr)
  +        FATAL_ALWAYS("unable to get glyphs for %@ %f error = (%d)", self, [font.font displayName], [font.font pointSize], status);
   }
   
   // Nasty hack to determine if we should round or ceil space widths.
  @@ -886,12 +746,13 @@
   // every character and the space are the same width.  Otherwise we round.
   - (BOOL)_computeWidthForSpace
   {
  -    spaceGlyph = [self _extendCharacterToGlyphMapToInclude:SPACE];
  +    spaceGlyph = [self extendCharacterToGlyphMapToInclude:SPACE];
       if (spaceGlyph == 0) {
           return NO;
       }
   
  -    float width = widthForGlyph(self, spaceGlyph, 0);
  +    float width = widthForGlyph(self, spaceGlyph);
  +
       spaceWidth = width;
   
       treatAsFixedPitch = [[WebTextRendererFactory sharedFactory] isFontFixedPitch:font];
  @@ -900,13 +761,15 @@
       return YES;
   }
   
  -- (BOOL)_setupFont
  +- (BOOL)setUpFont
   {
  +    font.font = font.forPrinter ? [font.font printerFont] : [font.font screenFont];
  +
       ATSUStyle fontStyle;
       if (ATSUCreateStyle(&fontStyle) != noErr)
           return NO;
   
  -    if (!fillStyleWithAttributes(fontStyle, font)) {
  +    if (!fillStyleWithAttributes(fontStyle, font.font)) {
           ATSUDisposeStyle(fontStyle);
           return NO;
       }
  @@ -915,28 +778,28 @@
           ATSUDisposeStyle(fontStyle);
           return NO;
       }
  -    
  +
       ATSUDisposeStyle(fontStyle);
   
       if (![self _computeWidthForSpace]) {
           freeGlyphMap(characterToGlyphMap);
  -        characterToGlyphMap = NULL;
  +        characterToGlyphMap = 0;
           WKReleaseStyleGroup(styleGroup);
  -        styleGroup = NULL;
  +        styleGroup = 0;
           return NO;
       }
       
       return YES;
   }
   
  +#if !ERROR_DISABLED
  +
   static NSString *pathFromFont (NSFont *font)
   {
       UInt8 _filePathBuffer[PATH_MAX];
       NSString *filePath = nil;
       FSSpec oFile;
  -    OSStatus status = ATSFontGetFileSpecification(
  -            ATSFontRefFromNSFont(font),
  -            &oFile);
  +    OSStatus status = ATSFontGetFileSpecification(FMGetATSFontRefFromFont((FMFont)WKGetNSFontATSUFontId(font)), &oFile);
       if (status == noErr){
           OSErr err;
           FSRef fileRef;
  @@ -951,64 +814,56 @@
       return filePath;
   }
   
  +#endif
  +
   // Useful page for testing http://home.att.net/~jameskass
  -static void _drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *advances, float x, float y, int numGlyphs)
  +static void drawGlyphs(NSFont *font, NSColor *color, CGGlyph *glyphs, CGSize *advances, float x, float y, int numGlyphs,
  +    float syntheticBoldOffset, BOOL syntheticOblique)
   {
  -    CGContextRef cgContext;
  +    NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
  +    CGContextRef cgContext = (CGContextRef)[gContext graphicsPort];
   
  -    if ([WebTextRenderer shouldBufferTextDrawing] && [[WebTextRendererFactory sharedFactory] coalesceTextDrawing]){
  -        // Add buffered glyphs and advances
  -        // FIXME:  If we ever use this again, need to add RTL.
  -        WebGlyphBuffer *gBuffer = [[WebTextRendererFactory sharedFactory] glyphBufferForFont: font andColor: color];
  -        [gBuffer addGlyphs: glyphs advances: advances count: numGlyphs at: x : y];
  -    }
  -    else {
  -        NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
  -        cgContext = (CGContextRef)[gContext graphicsPort];
  -        // Setup the color and font.
  -
  -	bool originalShouldUseFontSmoothing;
  -	
  -	originalShouldUseFontSmoothing = WKCGContextGetShouldSmoothFonts (cgContext);
  -	CGContextSetShouldSmoothFonts (cgContext, [WebView _shouldUseFontSmoothing]);
  -        
  -        NSFont *drawFont;
  -        
  -        if ([gContext isDrawingToScreen]){
  -            drawFont = [font screenFont];
  -            if (drawFont != font){
  -                // We are getting this in too many places (3406411); use ERROR so it only prints on
  -                // debug versions for now. (We should debug this also, eventually).
  -                ERROR ("Attempting to set non-screen font (%@) when drawing to screen.  Using screen font anyway, may result in incorrect metrics.", [[[font fontDescriptor] fontAttributes] objectForKey: NSFontNameAttribute]);
  -            }
  -        }
  -        else {
  -            drawFont = [font printerFont];
  -            if (drawFont != font){
  -                NSLog (@"Attempting to set non-printer font (%@) when printing.  Using printer font anyway, may result in incorrect metrics.", [[[font fontDescriptor] fontAttributes] objectForKey: NSFontNameAttribute]);
  -            }
  -        }
  -        
  -	NSView *v = [NSView focusView];
  +    bool originalShouldUseFontSmoothing = WKCGContextGetShouldSmoothFonts(cgContext);
  +    CGContextSetShouldSmoothFonts(cgContext, [WebView _shouldUseFontSmoothing]);
  +    
  +    NSFont *drawFont;
  +    if ([gContext isDrawingToScreen]) {
  +        drawFont = [font screenFont];
  +        if (drawFont != font)
  +            // We are getting this in too many places (3406411); use ERROR so it only prints on debug versions for now. (We should debug this also, eventually).
  +            ERROR("Attempting to set non-screen font (%@) when drawing to screen.  Using screen font anyway, may result in incorrect metrics.",
  +                [[[font fontDescriptor] fontAttributes] objectForKey:NSFontNameAttribute]);
  +    } else {
  +        drawFont = [font printerFont];
  +        if (drawFont != font)
  +            NSLog(@"Attempting to set non-printer font (%@) when printing.  Using printer font anyway, may result in incorrect metrics.",
  +                [[[font fontDescriptor] fontAttributes] objectForKey:NSFontNameAttribute]);
  +    }
  +    
  +    CGContextSetFont(cgContext, WKGetCGFontFromNSFont(drawFont));
  +
  +    CGAffineTransform matrix;
  +    memcpy(&matrix, [drawFont matrix], sizeof(matrix));
  +    matrix.b = -matrix.b;
  +    matrix.d = -matrix.d;
  +    if (syntheticOblique)
  +        matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0)); 
  +    CGContextSetTextMatrix(cgContext, matrix);
   
  -        CGContextSetFont(cgContext, WKGetCGFontFromNSFont(drawFont));
  -        
  -        // Deal with flipping flippyness.
  -        const float *matrix = [drawFont matrix];
  -        float flip = [v isFlipped] ? -1 : 1;
  -        CGContextSetTextMatrix(cgContext, CGAffineTransformMake(matrix[0], matrix[1] * flip, matrix[2], matrix[3] * flip, matrix[4], matrix[5]));
  -        WKSetCGFontRenderingMode(cgContext, drawFont);
  -        CGContextSetFontSize(cgContext, 1.0F);
  +    WKSetCGFontRenderingMode(cgContext, drawFont);
  +    CGContextSetFontSize(cgContext, 1.0f);
   
  -        [color set];
  +    [color set];
   
  -        CGContextSetTextPosition(cgContext, x, y);
  +    CGContextSetTextPosition(cgContext, x, y);
  +    CGContextShowGlyphsWithAdvances(cgContext, glyphs, advances, numGlyphs);
  +    if (syntheticBoldOffset) {
  +        CGContextSetTextPosition(cgContext, x + syntheticBoldOffset, y);
           CGContextShowGlyphsWithAdvances(cgContext, glyphs, advances, numGlyphs);
  -
  -	CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
       }
  -}
   
  +    CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
  +}
   
   - (void)_CG_drawHighlightForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style geometry:(const WebCoreTextGeometry *)geometry
   {
  @@ -1043,15 +898,14 @@
   
           float yPos = geometry->useFontMetricsForSelectionYAndHeight ? geometry->point.y - [self ascent] - (lineGap/2) : geometry->selectionY;
           float height = geometry->useFontMetricsForSelectionYAndHeight ? [self lineSpacing] : geometry->selectionHeight;
  -        if (style->rtl){
  +        if (style->rtl) {
               float completeRunWidth = startPosition + backgroundWidth;
               while (widthIterator.currentCharacter < run->length) {
                   completeRunWidth += widthForNextCharacter(&widthIterator, 0, 0);
               }
   
               [NSBezierPath fillRect:NSMakeRect(geometry->point.x + completeRunWidth - startPosition - backgroundWidth, yPos, backgroundWidth, height)];
  -        }
  -        else {
  +        } else {
               [NSBezierPath fillRect:NSMakeRect(startX, yPos, backgroundWidth, height)];
           }
       }
  @@ -1062,7 +916,7 @@
   {
       float *widthBuffer, localWidthBuffer[LOCAL_BUFFER_SIZE];
       CGGlyph *glyphBuffer, localGlyphBuffer[LOCAL_BUFFER_SIZE];
  -    NSFont **fontBuffer, *localFontBuffer[LOCAL_BUFFER_SIZE];
  +    WebTextRenderer **rendererBuffer, *localRendererBuffer[LOCAL_BUFFER_SIZE];
       CGSize *advances, localAdvanceBuffer[LOCAL_BUFFER_SIZE];
       int numGlyphs = 0, i;
       float startX;
  @@ -1075,18 +929,18 @@
           advances = (CGSize *)calloc(length*MAX_GLYPH_EXPANSION, sizeof(CGSize));
           widthBuffer = (float *)calloc(length*MAX_GLYPH_EXPANSION, sizeof(float));
           glyphBuffer = (CGGlyph *)calloc(length*MAX_GLYPH_EXPANSION, sizeof(ATSGlyphRef));
  -        fontBuffer = (NSFont **)calloc(length*MAX_GLYPH_EXPANSION, sizeof(NSFont *));
  +        rendererBuffer = (WebTextRenderer **)calloc(length*MAX_GLYPH_EXPANSION, sizeof(WebTextRenderer *));
       } else {
           advances = localAdvanceBuffer;
           widthBuffer = localWidthBuffer;
           glyphBuffer = localGlyphBuffer;
  -        fontBuffer = localFontBuffer;
  +        rendererBuffer = localRendererBuffer;
       }
   
  -    [self _floatWidthForRun:run
  +    [self floatWidthForRun:run
           style:style
           widths:widthBuffer 
  -        fonts:fontBuffer
  +        substituteRenderers:rendererBuffer
           glyphs:glyphBuffer
           startPosition:&startX
           numGlyphs: &numGlyphs];
  @@ -1108,77 +962,77 @@
       if (style->backgroundColor != nil)
           [self _CG_drawHighlightForRun:run style:style geometry:geometry];
       
  -    // Finally, draw the glyphs.
  -    int lastFrom = 0;
  -    int pos = 0;
  -
       // Swap the order of the glyphs if right-to-left.
  -    if (style->rtl && numGlyphs > 1){
  +    if (style->rtl) {
           int i;
  -        int end = numGlyphs;
  -        CGGlyph gswap1, gswap2;
  -        CGSize aswap1, aswap2;
  -        NSFont *fswap1, *fswap2;
  -        
  -        for (i = pos, end = numGlyphs; i < (numGlyphs - pos)/2; i++){
  -            gswap1 = glyphBuffer[i];
  -            gswap2 = glyphBuffer[--end];
  +        int mid = numGlyphs / 2;
  +        int end;
  +        for (i = 0, end = numGlyphs - 1; i < mid; ++i, --end) {
  +            CGGlyph gswap1 = glyphBuffer[i];
  +            CGGlyph gswap2 = glyphBuffer[end];
               glyphBuffer[i] = gswap2;
               glyphBuffer[end] = gswap1;
  -        }
  -        for (i = pos, end = numGlyphs; i < (numGlyphs - pos)/2; i++){
  -            aswap1 = advances[i];
  -            aswap2 = advances[--end];
  +
  +            CGSize aswap1 = advances[i];
  +            CGSize aswap2 = advances[end];
               advances[i] = aswap2;
               advances[end] = aswap1;
  -        }
  -        for (i = pos, end = numGlyphs; i < (numGlyphs - pos)/2; i++){
  -            fswap1 = fontBuffer[i];
  -            fswap2 = fontBuffer[--end];
  -            fontBuffer[i] = fswap2;
  -            fontBuffer[end] = fswap1;
  +
  +            WebTextRenderer *rswap1 = rendererBuffer[i];
  +            WebTextRenderer *rswap2 = rendererBuffer[end];
  +            rendererBuffer[i] = rswap2;
  +            rendererBuffer[end] = rswap1;
           }
       }
   
  -    // Draw each contiguous run of glyphs that are included in the same font.
  -    NSFont *currentFont = fontBuffer[pos];
  +    // Finally, draw the glyphs.
  +    int lastFrom = 0;
  +    int pos = 0;
  +
  +    // Draw each contiguous run of glyphs that use the same renderer.
  +    WebTextRenderer *currentRenderer = rendererBuffer[pos];
       float nextX = startX;
       int nextGlyph = pos;
  -
  -    while (nextGlyph < numGlyphs){
  -        if ((fontBuffer[nextGlyph] != 0 && fontBuffer[nextGlyph] != currentFont)){
  -            _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, geometry->point.y, nextGlyph - lastFrom);
  +    while (nextGlyph < numGlyphs) {
  +        WebTextRenderer *nextRenderer = rendererBuffer[nextGlyph];
  +        if (nextRenderer && nextRenderer != currentRenderer) {
  +            drawGlyphs(currentRenderer->font.font, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom],
  +                startX, geometry->point.y, nextGlyph - lastFrom,
  +                currentRenderer->syntheticBoldOffset, currentRenderer->font.syntheticOblique);
               lastFrom = nextGlyph;
  -            currentFont = fontBuffer[nextGlyph];
  +            currentRenderer = nextRenderer;
               startX = nextX;
           }
           nextX += advances[nextGlyph].width;
           nextGlyph++;
       }
  -    _drawGlyphs(currentFont, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom], startX, geometry->point.y, nextGlyph - lastFrom);
  +    drawGlyphs(currentRenderer->font.font, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom],
  +        startX, geometry->point.y, nextGlyph - lastFrom,
  +        currentRenderer->syntheticBoldOffset, currentRenderer->font.syntheticOblique);
   
       if (advances != localAdvanceBuffer) {
           free(advances);
           free(widthBuffer);
           free(glyphBuffer);
  -        free(fontBuffer);
  +        free(rendererBuffer);
       }
   }
   
  -- (float)_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer fonts:(NSFont **)fontBuffer glyphs:(CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs:(int *)_numGlyphs
  +- (float)floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer substituteRenderers:(WebTextRenderer **)rendererBuffer
  +    glyphs:(CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs:(int *)_numGlyphs
   {
       if (shouldUseATSU(run))
           return [self _ATSU_floatWidthForRun:run style:style];
       
  -    return [self _CG_floatWidthForRun:run style:style widths:widthBuffer fonts:fontBuffer glyphs:glyphBuffer startPosition:startPosition numGlyphs:_numGlyphs];
  -
  +    return [self _CG_floatWidthForRun:run style:style widths:widthBuffer substituteRenderers:rendererBuffer glyphs:glyphBuffer startPosition:startPosition numGlyphs:_numGlyphs];
   }
   
  -- (float)_CG_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths: (float *)widthBuffer fonts: (NSFont **)fontBuffer glyphs: (CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs: (int *)_numGlyphs
  +- (float)_CG_floatWidthForRun:(const WebCoreTextRun *)run style:(const WebCoreTextStyle *)style widths:(float *)widthBuffer substituteRenderers:(WebTextRenderer **)rendererBuffer
  +    glyphs:(CGGlyph *)glyphBuffer startPosition:(float *)startPosition numGlyphs:(int *)_numGlyphs
   {
       float _nextWidth;
       CharacterWidthIterator widthIterator;
  -    NSFont *fontUsed = 0;
  +    WebTextRenderer *rendererUsed = nil;
       ATSGlyphRef glyphUsed;
       int numGlyphs = 0;
       
  @@ -1186,11 +1040,11 @@
       if (startPosition)
           *startPosition = widthIterator.widthToStart;
       while (widthIterator.currentCharacter < (unsigned)widthIterator.run->to) {
  -        _nextWidth = widthForNextCharacter(&widthIterator, &glyphUsed, &fontUsed);
  +        _nextWidth = widthForNextCharacter(&widthIterator, &glyphUsed, &rendererUsed);
           if (_nextWidth == INVALID_WIDTH)
               break;
  -        if (fontBuffer)
  -            fontBuffer[numGlyphs] = fontUsed;
  +        if (rendererBuffer)
  +            rendererBuffer[numGlyphs] = rendererUsed;
           if (glyphBuffer)
               glyphBuffer[numGlyphs] = glyphUsed;
           if (widthBuffer)
  @@ -1204,99 +1058,30 @@
       return widthIterator.runWidthSoFar;
   }
   
  -- (ATSGlyphRef)_extendUnicodeCharacterToGlyphMapToInclude:(UnicodeChar)c
  +- (void)updateGlyphEntryForCharacter:(UnicodeChar)c glyphID:(ATSGlyphRef)glyphID substituteRenderer:(WebTextRenderer *)substituteRenderer
   {
  -    UnicodeGlyphMap *map = (UnicodeGlyphMap *)calloc (1, sizeof(UnicodeGlyphMap));
  -    ATSLayoutRecord *glyphRecord;
  -	char glyphVector[WKGlyphVectorSize];
  -    UnicodeChar end, start;
  -    unsigned 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 i, count = end - start + 1;
  -    UnicodeChar buffer[INCREMENTAL_BLOCK_SIZE+2];
  -    
  -    for (i = 0; i < count; i++){
  -        buffer[i] = i+start;
  -    }
  -
  -    OSStatus status;
  -    status = WKInitializeGlyphVector(count*2, &glyphVector);
  -    if (status != noErr){
  -        // This should never happen, indicates a bad font!  If it does the
  -        // font substitution code will find an alternate font.
  -        free(map);
  -        return 0;
  -    }
  -    
  -    [self _convertUnicodeCharacters: &buffer[0] length: count toGlyphs: &glyphVector];
  -    unsigned numGlyphs = WKGetGlyphVectorNumGlyphs(&glyphVector);
  -    if (numGlyphs != count){
  -        // This should never happen, indicates a bad font!  If it does the
  -        // font substitution code will find an alternate font.
  -        free(map);
  -        return 0;
  -    }
  -            
  -    map->glyphs = (GlyphEntry *)malloc (count * sizeof(GlyphEntry));
  -    glyphRecord = WKGetGlyphVectorFirstRecord(&glyphVector);
  -    for (i = 0; i < count; i++) {
  -        map->glyphs[i].glyph = glyphRecord->glyphID;
  -        map->glyphs[i].font = 0;
  -        glyphRecord = (ATSLayoutRecord *)((char *)glyphRecord + WKGetGlyphVectorRecordSize(&glyphVector));
  -    }
  -    WKClearGlyphVector(&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].glyph;
  -    
  -    return glyphID;
  -}
  -
  -- (void)_updateGlyphEntryForCharacter:(UniChar)c glyphID:(ATSGlyphRef)glyphID font:(NSFont *)substituteFont
  -{
  -    GlyphMap *lastMap = characterToGlyphMap;
  -    while (lastMap != 0){
  -        if (c >= lastMap->startRange && c <= lastMap->endRange){
  -            lastMap->glyphs[c - lastMap->startRange].glyph = glyphID;
  -            // This font will leak.  No problem though, it has to stick around
  -            // forever.  Max theoretical retain counts applied here will be
  -            // num_fonts_on_system * num_glyphs_in_font.
  -            lastMap->glyphs[c - lastMap->startRange].font = [substituteFont retain];
  +    GlyphMap *map;
  +    for (map = characterToGlyphMap; map; map = map->next) {
  +        UnicodeChar start = map->startRange;
  +        if (c >= start && c <= map->endRange) {
  +            int i = c - start;
  +            map->glyphs[i].glyph = glyphID;
  +            // This renderer will leak.
  +            // No problem though; we want it to stick around forever.
  +            // Max theoretical retain counts applied here will be num_fonts_on_system * num_glyphs_in_font.
  +            map->glyphs[i].substituteRenderer = [substituteRenderer retain];
               break;
           }
  -        lastMap = lastMap->next;
       }
   }
   
  -- (ATSGlyphRef)_extendCharacterToGlyphMapToInclude:(UniChar) c
  +- (ATSGlyphRef)extendCharacterToGlyphMapToInclude:(UnicodeChar)c
   {
  -    GlyphMap *map = (GlyphMap *)calloc (1, sizeof(GlyphMap));
  +    GlyphMap *map = (GlyphMap *)calloc(1, sizeof(GlyphMap));
       ATSLayoutRecord *glyphRecord;
  -	char glyphVector[WKGlyphVectorSize];
  -    UniChar end, start;
  +    char glyphVector[WKGlyphVectorSize];
  +    UnicodeChar end, start;
       unsigned blockSize;
  -    ATSGlyphRef glyphID;
       
       if (characterToGlyphMap == 0)
           blockSize = INITIAL_BLOCK_SIZE;
  @@ -1310,23 +1095,34 @@
       map->startRange = start;
       map->endRange = end;
       
  -    unsigned i, count = end - start + 1;
  -    short unsigned buffer[INCREMENTAL_BLOCK_SIZE+2];
  -    
  -    for (i = 0; i < count; i++) {
  -        buffer[i] = i+start;
  -    }
  -
  -    if (start == 0) {
  -        // Control characters must not render at all.
  -        for (i = 0; i < 0x20; ++i)
  -            buffer[i] = ZERO_WIDTH_SPACE;
  -        buffer[0x7F] = ZERO_WIDTH_SPACE;
  -
  -        // But \n, \t, and nonbreaking space must render as a space.
  -        buffer['\n'] = ' ';
  -        buffer['\t'] = ' ';
  -        buffer[NO_BREAK_SPACE] = ' ';
  +    unsigned i;
  +    unsigned count = end - start + 1;
  +    unsigned short buffer[INCREMENTAL_BLOCK_SIZE * 2 + 2];
  +    unsigned bufferLength;
  +
  +    if (start < 0x10000) {
  +        bufferLength = count;
  +        for (i = 0; i < count; i++)
  +            buffer[i] = i + start;
  +
  +        if (start == 0) {
  +            // Control characters must not render at all.
  +            for (i = 0; i < 0x20; ++i)
  +                buffer[i] = ZERO_WIDTH_SPACE;
  +            buffer[0x7F] = ZERO_WIDTH_SPACE;
  +
  +            // But \n, \t, and nonbreaking space must render as a space.
  +            buffer['\n'] = ' ';
  +            buffer['\t'] = ' ';
  +            buffer[NO_BREAK_SPACE] = ' ';
  +        }
  +    } else {
  +        bufferLength = count * 2;
  +        for (i = 0; i < count; i++) {
  +            int c = i + start;
  +            buffer[i * 2] = U16_LEAD(c);
  +            buffer[i * 2 + 1] = U16_TRAIL(c);
  +        }
       }
   
       OSStatus status = WKInitializeGlyphVector(count, &glyphVector);
  @@ -1337,20 +1133,19 @@
           return 0;
       }
   
  -    [self _convertCharacters: &buffer[0] length: count toGlyphs: &glyphVector];
  +    [self _convertCharacters:&buffer[0] length:bufferLength toGlyphs:&glyphVector];
       unsigned numGlyphs = WKGetGlyphVectorNumGlyphs(&glyphVector);
  -    if (numGlyphs != count){
  -        // This should never happen, perhaps indicates a bad font!  If it does the
  -        // font substitution code will find an alternate font.
  +    if (numGlyphs != count) {
  +        // This should never happen, perhaps indicates a bad font?
  +        // If it does happen, the font substitution code will find an alternate font.
           free(map);
           return 0;
       }
  -            
  -    map->glyphs = (GlyphEntry *)malloc (count * sizeof(GlyphEntry));
  +
  +    map->glyphs = (GlyphEntry *)calloc(count, sizeof(GlyphEntry));
       glyphRecord = (ATSLayoutRecord *)WKGetGlyphVectorFirstRecord(glyphVector);
       for (i = 0; i < count; i++) {
           map->glyphs[i].glyph = glyphRecord->glyphID;
  -        map->glyphs[i].font = 0;
           glyphRecord = (ATSLayoutRecord *)((char *)glyphRecord + WKGetGlyphVectorRecordSize(glyphVector));
       }
       WKClearGlyphVector(&glyphVector);
  @@ -1364,40 +1159,34 @@
           lastMap->next = map;
       }
   
  -    glyphID = map->glyphs[c - start].glyph;
  -    
  +    ATSGlyphRef glyphID = map->glyphs[c - start].glyph;
  +
       // Special case for characters 007F-00A0.
  -    if (glyphID == 0 && c >= 0x7F && c <= 0xA0){
  -        glyphID = WKGetDefaultGlyphForChar(font, c);
  +    if (glyphID == 0 && c >= 0x7F && c <= 0xA0) {
  +        glyphID = WKGetDefaultGlyphForChar(font.font, c);
           map->glyphs[c - start].glyph = glyphID;
  -        map->glyphs[c - start].font = 0;
       }
   
       return glyphID;
   }
   
  -
  -- (WidthMap *)_extendGlyphToWidthMapToInclude:(ATSGlyphRef)glyphID font:(NSFont *)subFont
  +- (WidthMap *)_extendGlyphToWidthMapToInclude:(ATSGlyphRef)glyphID
   {
  -    WidthMap *map = (WidthMap *)calloc (1, sizeof(WidthMap)), **rootMap;
  +    WidthMap *map = (WidthMap *)calloc(1, sizeof(WidthMap));
       unsigned end;
       ATSGlyphRef start;
       unsigned blockSize;
       unsigned i, count;
       
  -    if (subFont && subFont != font)
  -        rootMap = &mapForSubstituteFont(self,subFont)->map;
  -    else
  -        rootMap = &glyphToWidthMap;
  -        
  -    if (*rootMap == 0){
  -        if ([(subFont ? subFont : font) numberOfGlyphs] < INITIAL_BLOCK_SIZE)
  -            blockSize = [font numberOfGlyphs];
  +    NSFont *f = font.font;
  +    if (glyphToWidthMap == 0) {
  +        if ([f numberOfGlyphs] < INITIAL_BLOCK_SIZE)
  +            blockSize = [f numberOfGlyphs];
            else
               blockSize = INITIAL_BLOCK_SIZE;
  -    }
  -    else
  +    } else {
           blockSize = INCREMENTAL_BLOCK_SIZE;
  +    }
       if (blockSize == 0) {
           start = 0;
       } else {
  @@ -1413,28 +1202,22 @@
       map->endRange = end;
       count = end - start + 1;
   
  -    map->widths = (WidthEntry *)malloc (count * sizeof(WidthEntry));
  -
  -    for (i = 0; i < count; i++){
  -        map->widths[i].width = UNINITIALIZED_GLYPH_WIDTH;
  -    }
  +    map->widths = (WebGlyphWidth *)malloc(count * sizeof(WebGlyphWidth));
  +    for (i = 0; i < count; i++)
  +        map->widths[i] = UNINITIALIZED_GLYPH_WIDTH;
   
  -    if (*rootMap == 0)
  -        *rootMap = map;
  +    if (glyphToWidthMap == 0)
  +        glyphToWidthMap = map;
       else {
  -        WidthMap *lastMap = *rootMap;
  +        WidthMap *lastMap = glyphToWidthMap;
           while (lastMap->next != 0)
               lastMap = lastMap->next;
           lastMap->next = map;
       }
   
  -#ifdef _TIMING
  -    LOG(FontCache, "%@ total time to advances lookup %f seconds", font, totalCGGetAdvancesTime);
  -#endif
       return map;
   }
   
  -
   - (void)_initializeATSUStyle
   {
       // The two NSFont calls in this method (pointSize and _atsFontID)
  @@ -1444,23 +1227,23 @@
           OSStatus status;
           ByteCount propTableSize;
           
  -        status = ATSUCreateStyle(&_ATSUSstyle);
  +        status = ATSUCreateStyle(&_ATSUStyle);
           if(status != noErr)
  -            FATAL_ALWAYS ("ATSUCreateStyle failed (%d)", status);
  +            FATAL_ALWAYS("ATSUCreateStyle failed (%d)", status);
       
  -        ATSUFontID fontID = WKGetNSFontATSUFontId(font);
  -        if (fontID == 0){
  -            ATSUDisposeStyle(_ATSUSstyle);
  -            ERROR ("unable to get ATSUFontID for %@", font);
  +        ATSUFontID fontID = WKGetNSFontATSUFontId(font.font);
  +        if (fontID == 0) {
  +            ATSUDisposeStyle(_ATSUStyle);
  +            ERROR("unable to get ATSUFontID for %@", font.font);
               return;
           }
           
           CGAffineTransform transform = CGAffineTransformMakeScale (1,-1);
  -        Fixed fontSize = FloatToFixed([font pointSize]);
  +        Fixed fontSize = FloatToFixed([font.font pointSize]);
           ATSUAttributeTag styleTags[] = { kATSUSizeTag, kATSUFontTag, kATSUFontMatrixTag};
           ByteCount styleSizes[] = {  sizeof(Fixed), sizeof(ATSUFontID), sizeof(CGAffineTransform) };
           ATSUAttributeValuePtr styleValues[] = { &fontSize, &fontID, &transform  };
  -        status = ATSUSetAttributes (_ATSUSstyle, 3, styleTags, styleSizes, styleValues);
  +        status = ATSUSetAttributes (_ATSUStyle, 3, styleTags, styleSizes, styleValues);
           if(status != noErr)
               FATAL_ALWAYS ("ATSUSetAttributes failed (%d)", status);
           status = ATSFontGetTable(fontID, 'prop', 0, 0, 0, &propTableSize);
  @@ -1490,19 +1273,22 @@
       
       [self _initializeATSUStyle];
       
  -    // FIXME: This is missing the following features that the CoreGraphics code path has:
  -    // - Both \n and nonbreaking space render as a space.
  -    // - All other control characters must not render at all (other code path uses zero-width spaces).
  +    // FIXME: This is currently missing the following required features that the CoreGraphics code path has:
  +    // - \n, \t, and nonbreaking space render as a space.
  +    // - Other control characters do not render (other code path uses zero-width spaces).
  +    // - Small caps.
  +    // - Synthesized bold.
  +    // - Synthesized oblique.
   
       runLength = run->to - run->from;
       status = ATSUCreateTextLayoutWithTextPtr(
               run->characters,
  -            run->from,           // offset
  -            runLength,        // length
  -            run->length,         // total length
  +            run->from,      // offset
  +            runLength,      // length
  +            run->length,    // total length
               1,              // styleRunCount
  -            &runLength,    // length of style run
  -            &_ATSUSstyle, 
  +            &runLength,     // length of style run
  +            &_ATSUStyle, 
               &layout);
       if(status != noErr)
           FATAL_ALWAYS ("ATSUCreateTextLayoutWithTextPtr failed(%d)", status);
  @@ -1526,16 +1312,15 @@
   
       substituteOffset = run->from;
       while ((status = ATSUMatchFontsToText(layout, substituteOffset, kATSUToTextEnd, &ATSUSubstituteFont, &substituteOffset, &substituteLength)) == kATSUFontsMatched || status == kATSUFontsNotMatched) {
  -        NSFont *substituteFont = [self _substituteFontForCharacters:run->characters+substituteOffset length:substituteLength families:style->families];
  -        if (substituteFont) {
  -            WebTextRenderer *substituteRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:substituteFont usingPrinterFont:usingPrinterFont];
  +        WebTextRenderer *substituteRenderer = [self substituteRendererForCharacters:run->characters+substituteOffset length:substituteLength families:style->families];
  +        if (substituteRenderer) {
               [substituteRenderer _initializeATSUStyle];
  -            if (substituteRenderer && substituteRenderer->_ATSUSstyle)
  -                ATSUSetRunStyle(layout, substituteRenderer->_ATSUSstyle, substituteOffset, substituteLength);
  +            if (substituteRenderer && substituteRenderer->_ATSUStyle)
  +                ATSUSetRunStyle(layout, substituteRenderer->_ATSUStyle, substituteOffset, substituteLength);
               // ignoring errors
           }
           substituteOffset += substituteLength;
  -    };
  +    }
       // ignoring errors in font substitution
           
       return layout;
  @@ -1764,7 +1549,6 @@
       // _createATSUTextLayoutForRun:. This is exception-safe.
   
       unsigned offset = 0;
  -    UniCharArrayOffset primaryOffset = 0;
       UniCharArrayOffset secondaryOffset = 0;
       OSStatus status;
       Boolean isLeading;
  @@ -1792,7 +1576,7 @@
       ATSULayoutParameters params;
       createATSULayoutParameters(&params, self, aRun, style);
   
  -    primaryOffset = aRun->from;
  +    UniCharArrayOffset primaryOffset = aRun->from;
       
       // FIXME: No idea how to avoid including partial glyphs.   Not even sure if that's the behavior
       // this yields now.
  @@ -1806,9 +1590,8 @@
          
       disposeATSULayoutParameters(&params);
       
  -    if (style->directionalOverride || (style->rtl && !ATSUMirrors)) {
  +    if (style->directionalOverride || (style->rtl && !ATSUMirrors))
           free ((void *)swappedRun.characters);
  -    }
   
       return offset - aRun->from;
   }
  @@ -1883,7 +1666,6 @@
       }
   }
   
  -
   static void freeGlyphMap(GlyphMap *map)
   {
       while (map) {
  @@ -1894,78 +1676,26 @@
       }
   }
   
  -
  -static void freeUnicodeGlyphMap(UnicodeGlyphMap *map)
  -{
  -    while (map) {
  -        UnicodeGlyphMap *next = map->next;
  -        free(map->glyphs);
  -        free(map);
  -        map = next;
  -    }
  -}
  -
  -
  -static inline ATSGlyphRef glyphForCharacter (GlyphMap *map, UniChar c, NSFont **font)
  +static inline ATSGlyphRef glyphForCharacter(GlyphMap *map, UnicodeChar c, WebTextRenderer **renderer)
   {
       if (map == 0)
           return nonGlyphID;
       
       // this loop is hot, so it is written to avoid LSU stalls
       while (map) {
  -        UniChar start = map->startRange;
  +        UnicodeChar start = map->startRange;
           GlyphMap *nextMap = map->next;
  -        if (c >= start && c <= map->endRange){
  -            GlyphEntry *ge = &map->glyphs[c-start];
  -            *font = ge->font;
  +        if (c >= start && c <= map->endRange) {
  +            GlyphEntry *ge = &map->glyphs[c - start];
  +            WebTextRenderer *substituteRenderer = ge->substituteRenderer;
  +            if (substituteRenderer)
  +                *renderer = substituteRenderer;
               return ge->glyph;
           }
           map = nextMap;
       }
  -    return nonGlyphID;
  -}
  - 
  - 
  -static inline ATSGlyphRef glyphForUnicodeCharacter (UnicodeGlyphMap *map, UnicodeChar c, NSFont **font)
  -{
  -    if (map == 0)
  -        return nonGlyphID;
  -        
  -    while (map) {
  -        if (c >= map->startRange && c <= map->endRange){
  -            *font = map->glyphs[c-map->startRange].font;
  -            return map->glyphs[c-map->startRange].glyph;
  -        }
  -        map = map->next;
  -    }
  -    return nonGlyphID;
  -}
  - 
  -
  -#ifdef _TIMING        
  -static double totalCGGetAdvancesTime = 0;
  -#endif
   
  -static inline SubstituteFontWidthMap *mapForSubstituteFont(WebTextRenderer *renderer, NSFont *font)
  -{
  -    int i;
  -    
  -    for (i = 0; i < renderer->numSubstituteFontWidthMaps; i++){
  -        if (font == renderer->substituteFontWidthMaps[i].font)
  -            return &renderer->substituteFontWidthMaps[i];
  -    }
  -    
  -    if (renderer->numSubstituteFontWidthMaps == renderer->maxSubstituteFontWidthMaps){
  -        renderer->maxSubstituteFontWidthMaps = renderer->maxSubstituteFontWidthMaps * 2;
  -        renderer->substituteFontWidthMaps = realloc (renderer->substituteFontWidthMaps, renderer->maxSubstituteFontWidthMaps * sizeof(SubstituteFontWidthMap));
  -        for (i = renderer->numSubstituteFontWidthMaps; i < renderer->maxSubstituteFontWidthMaps; i++){
  -            renderer->substituteFontWidthMaps[i].font = 0;
  -            renderer->substituteFontWidthMaps[i].map = 0;
  -        }
  -    }
  -    
  -    renderer->substituteFontWidthMaps[renderer->numSubstituteFontWidthMaps].font = font;
  -    return &renderer->substituteFontWidthMaps[renderer->numSubstituteFontWidthMaps++];
  +    return nonGlyphID;
   }
   
   static void initializeCharacterWidthIterator (CharacterWidthIterator *iterator, WebTextRenderer *renderer, const WebCoreTextRun *run , const WebCoreTextStyle *style) 
  @@ -2005,9 +1735,8 @@
           CharacterWidthIterator startPositionIterator;
           initializeCharacterWidthIterator (&startPositionIterator, renderer, &startPositionRun, style);
           
  -        while (startPositionIterator.currentCharacter < (unsigned)startPositionRun.to){
  +        while (startPositionIterator.currentCharacter < (unsigned)startPositionRun.to)
               widthForNextCharacter(&startPositionIterator, 0, 0);
  -        }
           iterator->widthToStart = startPositionIterator.runWidthSoFar;
       }
       else
  @@ -2036,19 +1765,15 @@
       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)
  +static float widthForNextCharacter(CharacterWidthIterator *iterator, ATSGlyphRef *glyphUsed, WebTextRenderer **rendererUsed)
   {
       WebTextRenderer *renderer = iterator->renderer;
       const WebCoreTextRun *run = iterator->run;
       const WebCoreTextStyle *style = iterator->style;
       unsigned currentCharacter = iterator->currentCharacter;
   
  -    NSFont *_fontUsed = nil;
  -    ATSGlyphRef _glyphUsed = nil;
  +    ATSGlyphRef glyph = 0;
       
       // Check for end of run.
       if (currentCharacter >= (unsigned)run->to)
  @@ -2066,46 +1791,27 @@
       unsigned clusterLength = 1;
       if (U16_IS_LEAD(c)) {
           // Make sure we have another character and it's a low surrogate.
  -        UniChar low;
  -        if (currentCharacter + 1 >= run->length || !U16_IS_TRAIL((low = cp[1]))) {
  -            // Error!  The second component of the surrogate pair is missing.
  +        if (currentCharacter + 1 >= run->length)
  +            return INVALID_WIDTH;
  +        UniChar low = cp[1];
  +        if (!U16_IS_TRAIL(low))
               return INVALID_WIDTH;
  -        }
  -
           c = U16_GET_SUPPLEMENTARY(c, low);
           clusterLength = 2;
       }
   
  -    // If small-caps convert lowercase to upper.
  -    BOOL useSmallCapsFont = NO;
  -    if (renderer->isSmallCapsRenderer) {
  -        if (!u_isUUppercase(c)) {
  -            // Only use small cap font if the the uppercase version of the character
  -            // is different than the lowercase.
  -            UnicodeChar newC = u_toupper(c);
  -            if (newC != c) {
  -                useSmallCapsFont = YES;
  -                c = newC;
  -            }
  -        }
  -    }
  -    
  -    // 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?
  +    // 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){
  +                UChar normalizedCharacters[2] = { 0, 0 };
  +                UErrorCode uStatus = 0;                
  +                int32_t 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;
                   }
  @@ -2113,52 +1819,39 @@
           }
       }
   
  -    if (style->rtl) {
  +    if (style->rtl)
           c = u_charMirror(c);
  -    }
       
  -    if (c <= 0xFFFF) {
  -        _glyphUsed = glyphForCharacter(renderer->characterToGlyphMap, c, &_fontUsed);
  -        if (_glyphUsed == nonGlyphID) {
  -            _glyphUsed = [renderer _extendCharacterToGlyphMapToInclude:c];
  -        }
  -    } else {
  -        _glyphUsed = glyphForUnicodeCharacter(renderer->unicodeCharacterToGlyphMap, c, &_fontUsed);
  -        if (_glyphUsed == nonGlyphID) {
  -            _glyphUsed = [renderer _extendUnicodeCharacterToGlyphMapToInclude:c];
  -        }
  -    }
  -
  -    // Check to see if we're rendering in 'small-caps' mode.
  -    // ASSUMPTION:  We assume the same font in a smaller size has
  -    // the same glyphs as the large font.
  -    if (useSmallCapsFont) {
  -        if (_fontUsed == nil)
  -            _fontUsed = [renderer _smallCapsFont];
  -        else {
  -            // Potential for optimization.  This path should only be taken if we're
  -            // using a cached substituted font.
  -            _fontUsed = [[NSFontManager sharedFontManager] convertFont:_fontUsed toSize:[_fontUsed pointSize] * SMALLCAPS_FONTSIZE_MULTIPLIER];
  +    // If small-caps, convert lowercase to upper.
  +    if (style->smallCaps && !u_isUUppercase(c)) {
  +        UnicodeChar newC = u_toupper(c);
  +        if (newC != c) {
  +            c = newC;
  +            renderer = [renderer smallCapsRenderer];
           }
       }
  +    
  +    glyph = glyphForCharacter(renderer->characterToGlyphMap, c, &renderer);
  +    if (glyph == nonGlyphID)
  +        glyph = [renderer extendCharacterToGlyphMapToInclude:c];
   
       // Now that we have glyph and font, get its width.
       WebGlyphWidth width;
       if (style->tabWidth != 0.0F && c == '\t') {
           width = style->tabWidth - fmodf(style->xpos+iterator->runWidthSoFar, style->tabWidth);
       } else {
  -        width = widthForGlyph(renderer, _glyphUsed, _fontUsed);
  +        width = widthForGlyph(renderer, glyph);
           // 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
           // match the width of the space character have the same width as the space character.
  -        if (style->applyWordRounding && (renderer->treatAsFixedPitch ? width == renderer->spaceWidth : _glyphUsed == renderer->spaceGlyph))
  +        if (style->applyWordRounding && (renderer->treatAsFixedPitch ? width == renderer->spaceWidth : glyph == renderer->spaceGlyph))
               width = renderer->adjustedSpaceWidth;
       }
       
       // 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 (_glyphUsed == 0 && style->attemptFontSubstitution) {
  +    if (glyph == 0 && style->attemptFontSubstitution) {
           UniChar characterArray[2];
           unsigned characterArrayLength;
           
  @@ -2171,12 +1864,9 @@
               characterArrayLength = 2;
           }
           
  -        NSFont *substituteFont = [renderer _substituteFontForCharacters:characterArray length:characterArrayLength
  -            families:style->families];
  -        if (substituteFont) {
  -            int cNumGlyphs = 0;
  -            ATSGlyphRef localGlyphBuffer[MAX_GLYPH_EXPANSION];
  -            
  +        WebTextRenderer *substituteRenderer = [renderer substituteRendererForCharacters:characterArray
  +            length:characterArrayLength families:style->families];
  +        if (substituteRenderer) {
               WebCoreTextRun clusterRun;
               WebCoreInitializeTextRun(&clusterRun, characterArray, characterArrayLength, 0, characterArrayLength);
               WebCoreTextStyle clusterStyle = *iterator->style;
  @@ -2184,41 +1874,29 @@
               clusterStyle.applyRunRounding = false;
               clusterStyle.attemptFontSubstitution = false;
               
  -            WebTextRenderer *substituteRenderer;
  -            substituteRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:substituteFont usingPrinterFont:renderer->usingPrinterFont];
  -            width = [substituteRenderer
  -                            _floatWidthForRun:&clusterRun
  -                            style:&clusterStyle 
  -                            widths: nil
  -                            fonts: nil
  -                            glyphs: &localGlyphBuffer[0]
  -                            startPosition:nil
  -                            numGlyphs:&cNumGlyphs];
  -            
  -            _fontUsed = substituteFont;
  -            _glyphUsed = localGlyphBuffer[0];
  -            
  -            if (c <= 0xFFFF && cNumGlyphs == 1 && localGlyphBuffer[0] != 0){
  -                [renderer _updateGlyphEntryForCharacter:c glyphID:localGlyphBuffer[0] font:substituteFont];
  +            int cNumGlyphs;
  +            ATSGlyphRef localGlyphBuffer[MAX_GLYPH_EXPANSION];            
  +            width = [substituteRenderer floatWidthForRun:&clusterRun style:&clusterStyle 
  +                widths:0 substituteRenderers:0 glyphs:localGlyphBuffer startPosition:0 numGlyphs:&cNumGlyphs];
  +            if (cNumGlyphs == 1) {
  +                glyph = localGlyphBuffer[0];
  +                [renderer updateGlyphEntryForCharacter:c glyphID:glyph substituteRenderer:substituteRenderer];
  +                renderer = substituteRenderer;
               }
           }
       }
   
  -    if (!_fontUsed)
  -        _fontUsed = renderer->font;
  -
       // Force characters that are used to determine word boundaries for the rounding hack
       // to be integer width, so following words will start on an integer boundary.
  -    if (style->applyWordRounding && isRoundingHackCharacter(c)) {
  +    if (style->applyWordRounding && isRoundingHackCharacter(c))
           width = ceilf(width);
  -    }
       
       // Account for letter-spacing
       if (style->letterSpacing && width > 0)
           width += style->letterSpacing;
   
  -    // Account for padding.  khtml uses space padding to justify text.  We
  -    // distribute the specified padding over the available spaces in the run.
  +    // Account for padding. WebCore uses space padding to justify text.
  +    // We distribute the specified padding over the available spaces in the run.
       if (isSpace(c)) {
           if (iterator->padding > 0) {
               // Only use left over padding if note evenly divisible by 
  @@ -2226,8 +1904,7 @@
               if (iterator->padding < iterator->padPerSpace){
                   width += iterator->padding;
                   iterator->padding = 0;
  -            }
  -            else {
  +            } else {
                   width += iterator->padPerSpace;
                   iterator->padding -= iterator->padPerSpace;
               }
  @@ -2263,16 +1940,15 @@
           }
       }
   
  -    if (fontUsed)
  -        *fontUsed = _fontUsed;
  +    if (rendererUsed)
  +        *rendererUsed = renderer;
       
       if (glyphUsed)
  -        *glyphUsed = _glyphUsed;
  +        *glyphUsed = glyph;
   
       return width;
   }
   
  -
   static BOOL fillStyleWithAttributes(ATSUStyle style, NSFont *theFont)
   {
       if (theFont) {
  @@ -2300,33 +1976,49 @@
   
   static BOOL shouldUseATSU(const WebCoreTextRun *run)
   {
  -    UniChar c;
  -    const UniChar *characters = run->characters;
  -    int i, from = run->from, to = run->to;
  -    
       if (alwaysUseATSU)
           return YES;
           
  -    for (i = from; i < to; i++){
  -        c = characters[i];
  -        if (c < 0x300)                      // Early continue to avoid other checks for the common case.
  +    const UniChar *characters = run->characters;
  +    int to = run->to;
  +    int i;
  +    for (i = run->from; i < to; i++) {
  +        UniChar c = characters[i];
  +        if (c < 0x300)                      // U+0300 through U+036F Combining diacritical marks
               continue;
  -            
  -        if (c >= 0x300 && c <= 0x36F)       // U+0300 through U+036F Combining diacritical marks
  +        if (c <= 0x36F)
               return YES;
  -        if (c >= 0x20D0 && c <= 0x20FF)     // U+20D0 through U+20FF Combining marks for symbols
  +
  +        if (c < 0x0591)                     // U+0591 through U+1059 Arabic, Hebrew, Syriac, Thaana, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar
  +            continue;
  +        if (c <= 0x1059)
               return YES;
  -        if (c >= 0xFE20 && c <= 0xFE2f)     // U+FE20 through U+FE2F Combining half marks
  +
  +        if (c < 0x1100)                     // U+1100 through U+11FF Hangul Jamo (only Ancient Korean should be left here if you precompose; Modern Korean will be precomposed as a result of step A)
  +            continue;
  +        if (c <= 0x11FF)
               return YES;
  -        if (c >= 0x591 && c <= 0x1059)      // U+0591 through U+1059 Arabic, Hebrew, Syriac, Thaana, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar
  +
  +        if (c < 0x1780)                     // U+1780 through U+18AF Khmer, Mongolian
  +            continue;
  +        if (c <= 0x18AF)
               return YES;
  -        if (c >= 0x1100 && c <= 0x11FF)     // U+1100 through U+11FF Hangul Jamo (only Ancient Korean should be left here if you precompose; Modern Korean will be precomposed as a result of step A)
  +
  +        if (c < 0x1900)                     // U+1900 through U+194F Limbu (Unicode 4.0)
  +            continue;
  +        if (c <= 0x194F)
               return YES;
  -        if (c >= 0x1780 && c <= 0x18AF)     // U+1780 through U+18AF Khmer, Mongolian
  +
  +        if (c < 0x20D0)                     // U+20D0 through U+20FF Combining marks for symbols
  +            continue;
  +        if (c <= 0x20FF)
               return YES;
  -        if (c >= 0x1900 && c <= 0x194F)     // U+1900 through U+194F Limbu (Unicode 4.0)
  +
  +        if (c < 0xFE20)                     // U+FE20 through U+FE2F Combining half marks
  +            continue;
  +        if (c <= 0xFE2F)
               return YES;
       }
  -    
  +
       return NO;
   }
  
  
  
  1.17      +5 -15     WebKit/WebCoreSupport.subproj/WebTextRendererFactory.h
  
  Index: WebTextRendererFactory.h
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.h,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- WebTextRendererFactory.h	5 Jun 2005 17:54:41 -0000	1.16
  +++ WebTextRendererFactory.h	6 Oct 2005 15:46:09 -0000	1.17
  @@ -27,33 +27,23 @@
    */
   
   #import <WebCore/WebCoreTextRendererFactory.h>
  -#import <WebKit/WebGlyphBuffer.h>
   
   @class WebTextRenderer;
   
  +#define WEB_TEXT_RENDERER_FACTORY_NUM_CACHES 8
  +
   @interface WebTextRendererFactory : WebCoreTextRendererFactory
   {
  -    NSMutableDictionary *cacheForScreen;
  -    NSMutableDictionary *cacheForPrinter;
  +    NSMutableDictionary *caches[WEB_TEXT_RENDERER_FACTORY_NUM_CACHES];
       NSMutableDictionary *viewBuffers;
       NSMutableArray *viewStack;
   }
   
   + (void)createSharedFactory;
   + (WebTextRendererFactory *)sharedFactory;
  -- (NSFont *)cachedFontFromFamily:(NSString *)family traits:(NSFontTraitMask)traits size:(float)size;
  -
  -- (WebTextRenderer *)rendererWithFont:(NSFont *)font usingPrinterFont:(BOOL)usingPrinterFont;
  -
  -- (BOOL)coalesceTextDrawing;
  -- (void)endCoalesceTextDrawing;
  -- (void)startCoalesceTextDrawing;
   
  -- (WebGlyphBuffer *)glyphBufferForFont:(NSFont *)font andColor:(NSColor *)color;
  +- (NSFont *)cachedFontFromFamily:(NSString *)family traits:(NSFontTraitMask)traits size:(float)size;
   
  - at end
  +- (WebTextRenderer *)rendererWithFont:(WebCoreFont)font;
   
  - at interface NSFont (WebPrivateExtensions)
  -- (BOOL)_web_isFakeFixedPitch;
   @end
  -
  
  
  
  1.47      +106 -173  WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m
  
  Index: WebTextRendererFactory.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- WebTextRendererFactory.m	6 Jun 2005 13:26:16 -0000	1.46
  +++ WebTextRendererFactory.m	6 Oct 2005 15:46:09 -0000	1.47
  @@ -37,6 +37,8 @@
   
   #import <mach-o/dyld.h>
   
  +#define SYNTHESIZED_FONT_TRAITS (NSBoldFontMask | NSItalicFontMask)
  +
   #define IMPORTANT_FONT_TRAITS (0 \
       | NSBoldFontMask \
       | NSCompressedFontMask \
  @@ -60,87 +62,26 @@
   
   @implementation WebTextRendererFactory
   
  -- (BOOL)coalesceTextDrawing
  -{
  -    return [viewStack objectAtIndex: [viewStack count]-1] == [NSView focusView] ? YES : NO;
  -}
  -
  -- (void)startCoalesceTextDrawing
  -{
  -    if (!viewStack)
  -        viewStack = [[NSMutableArray alloc] init];
  -    if (!viewBuffers)
  -        viewBuffers = [[NSMutableDictionary alloc] init];
  -    [viewStack addObject: [NSView focusView]];
  -}
  -
  -- (void)endCoalesceTextDrawing
  -{
  -    ASSERT([self coalesceTextDrawing]);
  -    
  -    NSView *targetView = [viewStack objectAtIndex: [viewStack count]-1];
  -    [viewStack removeLastObject];
  -    NSValue *viewKey = [NSValue valueWithNonretainedObject: targetView];
  -    NSMutableSet *glyphBuffers = [viewBuffers objectForKey:viewKey];
  -
  -    [glyphBuffers makeObjectsPerformSelector: @selector(drawInView:) withObject: targetView];
  -    [glyphBuffers makeObjectsPerformSelector: @selector(reset)];
  -    [viewBuffers removeObjectForKey: viewKey];
  -}
  -
  -- (WebGlyphBuffer *)glyphBufferForFont: (NSFont *)font andColor: (NSColor *)color
  -{
  -    ASSERT([self coalesceTextDrawing]);
  -
  -    NSMutableSet *glyphBuffers;
  -    WebGlyphBuffer *glyphBuffer = nil;
  -    NSValue *viewKey = [NSValue valueWithNonretainedObject: [NSView focusView]];
  -    
  -    glyphBuffers = [viewBuffers objectForKey:viewKey];
  -    if (glyphBuffers == nil){
  -        glyphBuffers = [[NSMutableSet alloc] init];
  -        [viewBuffers setObject: glyphBuffers forKey: viewKey];
  -        [glyphBuffers release];
  -    }
  -    
  -    NSEnumerator *enumerator = [glyphBuffers objectEnumerator];
  -    id value;
  -    
  -    // Could use a dictionary w/ font/color key for faster lookup.
  -    while ((value = [enumerator nextObject])) {
  -        if ([value font] == font && [[value color] isEqual: color])
  -            glyphBuffer = value;
  -    }
  -    if (glyphBuffer == nil){
  -        glyphBuffer = [[WebGlyphBuffer alloc] initWithFont: font color: color];
  -        [glyphBuffers addObject: glyphBuffer];
  -        [glyphBuffer release];
  -    }
  -        
  -    return glyphBuffer;
  -}
  -
  -static bool
  -getAppDefaultValue(CFStringRef key, int *v)
  +static bool getAppDefaultValue(CFStringRef key, int *v)
   {
       CFPropertyListRef value;
   
       value = CFPreferencesCopyValue(key, kCFPreferencesCurrentApplication,
                                      kCFPreferencesAnyUser,
                                      kCFPreferencesAnyHost);
  -    if (value == NULL) {
  +    if (value == 0) {
           value = CFPreferencesCopyValue(key, kCFPreferencesCurrentApplication,
                                          kCFPreferencesCurrentUser,
                                          kCFPreferencesAnyHost);
  -        if (value == NULL)
  +        if (value == 0)
               return false;
       }
   
       if (CFGetTypeID(value) == CFNumberGetTypeID()) {
  -        if (v != NULL)
  +        if (v != 0)
               CFNumberGetValue(value, kCFNumberIntType, v);
       } else if (CFGetTypeID(value) == CFStringGetTypeID()) {
  -        if (v != NULL)
  +        if (v != 0)
               *v = CFStringGetIntValue(value);
       } else {
           CFRelease(value);
  @@ -151,22 +92,21 @@
       return true;
   }
   
  -static bool
  -getUserDefaultValue(CFStringRef key, int *v)
  +static bool getUserDefaultValue(CFStringRef key, int *v)
   {
       CFPropertyListRef value;
   
       value = CFPreferencesCopyValue(key, kCFPreferencesAnyApplication,
                                      kCFPreferencesCurrentUser,
                                      kCFPreferencesCurrentHost);
  -    if (value == NULL)
  +    if (value == 0)
           return false;
   
       if (CFGetTypeID(value) == CFNumberGetTypeID()) {
  -        if (v != NULL)
  +        if (v != 0)
               CFNumberGetValue(value, kCFNumberIntType, v);
       } else if (CFGetTypeID(value) == CFStringGetTypeID()) {
  -        if (v != NULL)
  +        if (v != 0)
               *v = CFStringGetIntValue(value);
       } else {
           CFRelease(value);
  @@ -188,10 +128,9 @@
               return 1;
       }
   
  -	if (WKFontSmoothingModeIsLCD(mode))
  -		return 4;
  -	else
  -		return 1;
  +    if (WKFontSmoothingModeIsLCD(mode))
  +        return 4;
  +    return 1;
   }
   
   static CFMutableDictionaryRef fontCache;
  @@ -199,18 +138,16 @@
   
   - (void)clearCaches
   {
  -    [cacheForScreen release];
  -    [cacheForPrinter release];
  -    
  -    cacheForScreen = [[NSMutableDictionary alloc] init];
  -    cacheForPrinter = [[NSMutableDictionary alloc] init];
  +    int i;
  +    for (i = 0; i < WEB_TEXT_RENDERER_FACTORY_NUM_CACHES; ++i)
  +        [caches[i] removeAllObjects];
   
       if (fontCache)
           CFRelease(fontCache);
  -    fontCache = NULL;
  +    fontCache = 0;
       
       if (fixedPitchFonts) {
  -        CFRelease (fixedPitchFonts);
  +        CFRelease(fixedPitchFonts);
           fixedPitchFonts = 0;
       }
           
  @@ -236,19 +173,19 @@
       if (![self sharedFactory]) {
           [[[self alloc] init] release];
   
  -	size_t s;
  -	if (WebSystemMainMemory() > 128 * 1024 * 1024)
  -		s = MINIMUM_GLYPH_CACHE_SIZE*getLCDScaleParameters();
  -	else
  -		s = MINIMUM_GLYPH_CACHE_SIZE;
  +        size_t s;
  +        if (WebSystemMainMemory() > 128 * 1024 * 1024)
  +            s = MINIMUM_GLYPH_CACHE_SIZE*getLCDScaleParameters();
  +        else
  +            s = MINIMUM_GLYPH_CACHE_SIZE;
   #ifndef NDEBUG
  -	LOG (CacheSizes, "Glyph cache size set to %d bytes.", s);
  +        LOG(CacheSizes, "Glyph cache size set to %d bytes.", s);
   #endif
  -	WKSetUpFontCache(s);
  +        WKSetUpFontCache(s);
   
           // Ignore errors returned from ATSFontNotificationSubscribe.  If we can't subscribe then we
           // won't be told about changes to fonts.
  -	ATSFontNotificationSubscribe( fontsChanged, kATSFontNotifyOptionDefault, (void *)[super sharedFactory], nil );
  +        ATSFontNotificationSubscribe( fontsChanged, kATSFontNotifyOptionDefault, (void *)[super sharedFactory], nil );
       }
       ASSERT([[self sharedFactory] isKindOfClass:self]);
   }
  @@ -258,34 +195,33 @@
       return (WebTextRendererFactory *)[super sharedFactory];
   }
   
  -- (BOOL)isFontFixedPitch: (NSFont *)font
  +- (BOOL)isFontFixedPitch:(WebCoreFont)font
   {
  -    BOOL ret = NO;
  -    
  -    if (!fixedPitchFonts) {
  -        fixedPitchFonts = CFDictionaryCreateMutable (0, 0, &kCFTypeDictionaryKeyCallBacks, 0);
  -    }
  -    
  -    CFBooleanRef val = CFDictionaryGetValue (fixedPitchFonts, font);
  +    NSFont *f = font.font;
  +
  +    if (!fixedPitchFonts)
  +        fixedPitchFonts = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, 0);
  +    CFBooleanRef val = CFDictionaryGetValue(fixedPitchFonts, f);
  +
  +    BOOL ret;    
       if (val) {
           ret = (val == kCFBooleanTrue);
  +    } else {
  +        // Special case Osaka-Mono.
  +        // According to <rdar://problem/3999467>, we should treat Osaka-Mono as fixed pitch.
  +        // Note that the AppKit does not report Osaka-Mono as fixed pitch.
  +
  +        // Special case MS-PGothic.
  +        // According to <rdar://problem/4032938, we should not treat MS-PGothic as fixed pitch.
  +        // Note that AppKit does report MS-PGothic as fixed pitch.
  +
  +        NSString *name = [f fontName];
  +        ret = ([f isFixedPitch] || [f _isFakeFixedPitch] || [name caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame)
  +            && ![name caseInsensitiveCompare:@"MS-PGothic"] == NSOrderedSame;
  +
  +        CFDictionarySetValue(fixedPitchFonts, f, ret ? kCFBooleanTrue : kCFBooleanFalse);
       }
  -    else {
  -        // Special case Osaka-Mono.  According to <rdar://problem/3999467>, we should treat Osaka-Mono
  -        // as fixed pitch. Note that the AppKit does not report MS-PGothic as fixed pitch.
  -
  -        // Special case MS PGothic.  According to <rdar://problem/4032938, we should not treat MS-PGothic
  -        // as fixed pitch.  Note that AppKit does report MS-PGothic as fixed pitch.
  -        if (([font isFixedPitch] || [font _isFakeFixedPitch] || [[font fontName] caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame) && 
  -                ![[font fontName] caseInsensitiveCompare:@"MS-PGothic"] == NSOrderedSame) {
  -            CFDictionarySetValue (fixedPitchFonts, font, kCFBooleanTrue);
  -            ret = YES;
  -        }
  -        else {
  -            CFDictionarySetValue (fixedPitchFonts, font, kCFBooleanFalse);
  -            ret = NO;
  -        }
  -    }
  +
       return ret;    
   }
   
  @@ -293,29 +229,32 @@
   {
       [super init];
       
  -    cacheForScreen = [[NSMutableDictionary alloc] init];
  -    cacheForPrinter = [[NSMutableDictionary alloc] init];
  +    int i;
  +    for (i = 0; i < WEB_TEXT_RENDERER_FACTORY_NUM_CACHES; ++i)
  +        caches[i] = [[NSMutableDictionary alloc] init];
       
       return self;
   }
   
   - (void)dealloc
   {
  -    [cacheForScreen release];
  -    [cacheForPrinter release];
  +    int i;
  +    for (i = 0; i < WEB_TEXT_RENDERER_FACTORY_NUM_CACHES; ++i)
  +        [caches[i] release];
  +
       [viewBuffers release];
       [viewStack release];
       
       [super dealloc];
   }
   
  -- (WebTextRenderer *)rendererWithFont:(NSFont *)font usingPrinterFont:(BOOL)usingPrinterFont
  +- (WebTextRenderer *)rendererWithFont:(WebCoreFont)font
   {
  -    NSMutableDictionary *cache = usingPrinterFont ? cacheForPrinter : cacheForScreen;
  -    WebTextRenderer *renderer = [cache objectForKey:font];
  +    NSMutableDictionary *cache = caches[(font.syntheticBold << 2) | (font.syntheticOblique << 1) | font.forPrinter];
  +    WebTextRenderer *renderer = [cache objectForKey:font.font];
       if (renderer == nil) {
  -        renderer = [[WebTextRenderer alloc] initWithFont:font usingPrinterFont:usingPrinterFont];
  -        [cache setObject:renderer forKey:font];
  +        renderer = [[WebTextRenderer alloc] initWithFont:font];
  +        [cache setObject:renderer forKey:font.font];
           [renderer release];
       }
       return renderer;
  @@ -336,55 +275,57 @@
       return font;
   }
   
  -        
  -
  -- (NSFont *)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size
  +- (WebCoreFont)fontWithFamilies:(NSString **)families traits:(NSFontTraitMask)traits size:(float)size
   {
       NSFont *font = nil;
  -    NSString *family;
  -    int i = 0;
       
  -    while (families && families[i] != 0 && font == nil){
  -        family = families[i++];
  +    int i = 0;
  +    while (families && families[i] != 0 && font == nil) {
  +        NSString *family = families[i++];
           if ([family length] != 0)
  -            font = [self cachedFontFromFamily: family traits:traits size:size];
  +            font = [self cachedFontFromFamily:family traits:traits size:size];
       }
  +
       if (font == nil) {
  -        // We didn't find a font.  Use a fallback font.
  -        static int matchCount = 3;
  -        static NSString *matchWords[] = { @"Arabic", @"Pashto", @"Urdu" };
  -        static NSString *matchFamilies[] = { @"Geeza Pro", @"Geeza Pro", @"Geeza Pro" };
  +        // We didn't find a font. Use a fallback font.
           
           // First we'll attempt to find an appropriate font using a match based on 
           // the presence of keywords in the the requested names.  For example, we'll
           // match any name that contains "Arabic" to Geeza Pro.
  -        int j;
           i = 0;
           while (families && families[i] != 0 && font == nil) {
  -            family = families[i++];
  +            NSString *family = families[i++];
               if ([family length] != 0) {
  -                j = 0;
  -                while (j < matchCount && font == nil) {
  -                    if ([family rangeOfString:matchWords[j] options:NSCaseInsensitiveSearch].location != NSNotFound) {
  +                static NSString * const matchWords[3] = { @"Arabic", @"Pashto", @"Urdu" };
  +                static NSString * const matchFamilies[3] = { @"Geeza Pro", @"Geeza Pro", @"Geeza Pro" };
  +                int j;
  +                for (j = 0; j < 3 && font == nil; ++j)
  +                    if ([family rangeOfString:matchWords[j] options:NSCaseInsensitiveSearch].location != NSNotFound)
                           font = [self cachedFontFromFamily:matchFamilies[j] traits:traits size:size];
  -                    }
  -                    j++;
  -                }
               }
           }
           
           // Still nothing found, use the final fallback.
  -        if (font == nil) {
  +        if (font == nil)
               font = [self fallbackFontWithTraits:traits size:size];
  -        }
       }
   
  -    return font;
  +    NSFontTraitMask actualTraits = 0;
  +    if (traits & (NSItalicFontMask | NSBoldFontMask))
  +        actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:font];
  +
  +    WebCoreFont result;
  +    result.font = font;
  +    result.syntheticBold = (traits & NSBoldFontMask) && !(actualTraits & NSBoldFontMask);
  +    result.syntheticOblique = (traits & NSItalicFontMask) && !(actualTraits & NSItalicFontMask);
  +    result.forPrinter = NO;
  +    return result;
   }
   
   static BOOL acceptableChoice(NSFontTraitMask desiredTraits, int desiredWeight,
       NSFontTraitMask candidateTraits, int candidateWeight)
   {
  +    desiredTraits &= ~SYNTHESIZED_FONT_TRAITS;
       return (candidateTraits & desiredTraits) == desiredTraits;
   }
   
  @@ -412,19 +353,13 @@
       int i = 0;
       NSFontTraitMask mask;
       while ((mask = masks[i++])) {
  -        if ((desiredTraits & mask) != 0) {
  -            ASSERT((chosenTraits & mask) != 0);
  -            ASSERT((candidateTraits & mask) != 0);
  -            continue;
  -        }
  -        BOOL chosenHasUnwantedTrait = (chosenTraits & mask) != 0;
  -        BOOL candidateHasUnwantedTrait = (candidateTraits & mask) != 0;
  -        if (!candidateHasUnwantedTrait && chosenHasUnwantedTrait) {
  +        BOOL desired = (desiredTraits & mask) != 0;
  +        BOOL chosenHasUnwantedTrait = desired != ((chosenTraits & mask) != 0);
  +        BOOL candidateHasUnwantedTrait = desired != ((candidateTraits & mask) != 0);
  +        if (!candidateHasUnwantedTrait && chosenHasUnwantedTrait)
               return YES;
  -        }
  -        if (!chosenHasUnwantedTrait && candidateHasUnwantedTrait) {
  +        if (!chosenHasUnwantedTrait && candidateHasUnwantedTrait)
               return NO;
  -        }
       }
       
       int chosenWeightDelta = chosenWeight - desiredWeight;
  @@ -462,14 +397,14 @@
       while ((availableFont = [availableFonts nextObject])) {
           if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrderedSame) {
               NSFont *nameMatchedFont = [NSFont fontWithName:availableFont size:size];
  -	    
  -	    // Special case Osaka-Mono.  According to <rdar://problem/3999467>, we need to 
  -	    // treat Osaka-Mono as fixed pitch.
  -	    if ([desiredFamily caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame && desiredTraits == 0) {
  -		LOG (FontSelection, "found exact match for Osaka-Mono\n");
  -		return nameMatchedFont;
  -	    }
  -	    
  +    
  +            // Special case Osaka-Mono.  According to <rdar://problem/3999467>, we need to 
  +            // treat Osaka-Mono as fixed pitch.
  +            if ([desiredFamily caseInsensitiveCompare:@"Osaka-Mono"] == NSOrderedSame && desiredTraits == 0) {
  +                LOG (FontSelection, "found exact match for Osaka-Mono\n");
  +                return nameMatchedFont;
  +            }
  +
               NSFontTraitMask traits = [fontManager traitsOfFont:nameMatchedFont];
               
               if ((traits & desiredTraits) == desiredTraits){
  @@ -509,12 +444,10 @@
           NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValue];
           
           BOOL newWinner;
  -        
           if (!choseFont) {
               newWinner = acceptableChoice(desiredTraits, DESIRED_WEIGHT, fontTraits, fontWeight);
           } else {
  -            newWinner = betterChoice(desiredTraits, DESIRED_WEIGHT,
  -                chosenTraits, chosenWeight, fontTraits, fontWeight);
  +            newWinner = betterChoice(desiredTraits, DESIRED_WEIGHT, chosenTraits, chosenWeight, fontTraits, fontWeight);
           }
   
           if (newWinner) {
  @@ -579,7 +512,7 @@
   
   static const void *FontCacheValueRetain(CFAllocatorRef allocator, const void *value)
   {
  -    if (value != NULL) {
  +    if (value != 0) {
           CFRetain(value);
       }
       return value;
  @@ -587,7 +520,7 @@
   
   static void FontCacheValueRelease(CFAllocatorRef allocator, const void *value)
   {
  -    if (value != NULL) {
  +    if (value != 0) {
           CFRelease(value);
       }
   }
  @@ -597,9 +530,9 @@
       ASSERT(family);
       
       if (!fontCache) {
  -        static const CFDictionaryKeyCallBacks fontCacheKeyCallBacks = { 0, FontCacheKeyCopy, FontCacheKeyFree, NULL, FontCacheKeyEqual, FontCacheKeyHash };
  -        static const CFDictionaryValueCallBacks fontCacheValueCallBacks = { 0, FontCacheValueRetain, FontCacheValueRelease, NULL, NULL };
  -        fontCache = CFDictionaryCreateMutable(NULL, 0, &fontCacheKeyCallBacks, &fontCacheValueCallBacks);
  +        static const CFDictionaryKeyCallBacks fontCacheKeyCallBacks = { 0, FontCacheKeyCopy, FontCacheKeyFree, 0, FontCacheKeyEqual, FontCacheKeyHash };
  +        static const CFDictionaryValueCallBacks fontCacheValueCallBacks = { 0, FontCacheValueRetain, FontCacheValueRelease, 0, 0 };
  +        fontCache = CFDictionaryCreateMutable(0, 0, &fontCacheKeyCallBacks, &fontCacheValueCallBacks);
       }
   
       const FontCacheKey fontKey = { family, traits, size };
  
  
  
  1.11      +0 -8      WebKit/WebKit.xcodeproj/project.pbxproj
  
  Index: project.pbxproj
  ===================================================================
  RCS file: /cvs/root/WebKit/WebKit.xcodeproj/project.pbxproj,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- project.pbxproj	28 Sep 2005 18:43:14 -0000	1.10
  +++ project.pbxproj	6 Oct 2005 15:46:11 -0000	1.11
  @@ -70,7 +70,6 @@
   		9398103C0824BF01008DF038 /* WebBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = F5AFB45E02B94DC8018635CA /* WebBridge.h */; };
   		9398103D0824BF01008DF038 /* WebCookieAdapter.h in Headers */ = {isa = PBXBuildFile; fileRef = F5488CF402CB04EE01FF6274 /* WebCookieAdapter.h */; };
   		9398103E0824BF01008DF038 /* WebFileButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 9311022803667CF1008635CE /* WebFileButton.h */; };
  -		9398103F0824BF01008DF038 /* WebGlyphBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = F5E7B24503025CE801A80180 /* WebGlyphBuffer.h */; };
   		939810400824BF01008DF038 /* WebImageRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 9CE1F8A002A5C6F30ECA2ACD /* WebImageRenderer.h */; };
   		939810410824BF01008DF038 /* WebImageRendererFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 9CE1F8A202A5C6F30ECA2ACD /* WebImageRendererFactory.h */; };
   		939810420824BF01008DF038 /* WebJavaScriptTextInputPanel.h in Headers */ = {isa = PBXBuildFile; fileRef = 9345D4EA0365C5B2008635CE /* WebJavaScriptTextInputPanel.h */; settings = {ATTRIBUTES = (Private, ); }; };
  @@ -210,7 +209,6 @@
   		939810DE0824BF01008DF038 /* WebBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = F5AFB45F02B94DC8018635CA /* WebBridge.m */; };
   		939810DF0824BF01008DF038 /* WebCookieAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = F5488CF502CB04EE01FF6274 /* WebCookieAdapter.m */; };
   		939810E00824BF01008DF038 /* WebFileButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 9311022903667CF1008635CE /* WebFileButton.m */; };
  -		939810E10824BF01008DF038 /* WebGlyphBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E7B24603025CE801A80180 /* WebGlyphBuffer.m */; };
   		939810E20824BF01008DF038 /* WebImageRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CE1F8A102A5C6F30ECA2ACD /* WebImageRenderer.m */; };
   		939810E30824BF01008DF038 /* WebImageRendererFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 9CE1F8A302A5C6F30ECA2ACD /* WebImageRendererFactory.m */; };
   		939810E40824BF01008DF038 /* WebJavaScriptTextInputPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9345D4EB0365C5B2008635CE /* WebJavaScriptTextInputPanel.m */; };
  @@ -584,8 +582,6 @@
   		F5E0A76F02B8FEE401C1A525 /* WebURLsWithTitles.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = WebURLsWithTitles.m; sourceTree = "<group>"; };
   		F5E0E10802BC45F8018635CA /* WebSubresourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSubresourceLoader.h; sourceTree = "<group>"; };
   		F5E0E10902BC45F8018635CA /* WebSubresourceLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebSubresourceLoader.m; sourceTree = "<group>"; };
  -		F5E7B24503025CE801A80180 /* WebGlyphBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGlyphBuffer.h; sourceTree = "<group>"; };
  -		F5E7B24603025CE801A80180 /* WebGlyphBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebGlyphBuffer.m; sourceTree = "<group>"; };
   		F5EBC45502134BC301CA1520 /* WebBaseNetscapePluginView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBaseNetscapePluginView.h; sourceTree = "<group>"; };
   		F5EBC45602134BC301CA1520 /* WebBaseNetscapePluginView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebBaseNetscapePluginView.m; sourceTree = "<group>"; };
   		F5F7171E0288493C018635CA /* WebNetscapePluginPackage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginPackage.h; sourceTree = "<group>"; };
  @@ -999,8 +995,6 @@
   				9305892A070868B300E79D96 /* WebDashboardRegion.h */,
   				9311022803667CF1008635CE /* WebFileButton.h */,
   				9311022903667CF1008635CE /* WebFileButton.m */,
  -				F5E7B24503025CE801A80180 /* WebGlyphBuffer.h */,
  -				F5E7B24603025CE801A80180 /* WebGlyphBuffer.m */,
   				BE26F18D05517E0800BFA0C3 /* WebGraphicsBridge.h */,
   				BE26F18E05517E0800BFA0C3 /* WebGraphicsBridge.m */,
   				514C4C2A075E7DE500B89CAD /* WebImageDecodeItem.h */,
  @@ -1156,7 +1150,6 @@
   				9398103C0824BF01008DF038 /* WebBridge.h in Headers */,
   				9398103D0824BF01008DF038 /* WebCookieAdapter.h in Headers */,
   				9398103E0824BF01008DF038 /* WebFileButton.h in Headers */,
  -				9398103F0824BF01008DF038 /* WebGlyphBuffer.h in Headers */,
   				939810400824BF01008DF038 /* WebImageRenderer.h in Headers */,
   				939810410824BF01008DF038 /* WebImageRendererFactory.h in Headers */,
   				939810420824BF01008DF038 /* WebJavaScriptTextInputPanel.h in Headers */,
  @@ -1731,7 +1724,6 @@
   				939810DE0824BF01008DF038 /* WebBridge.m in Sources */,
   				939810DF0824BF01008DF038 /* WebCookieAdapter.m in Sources */,
   				939810E00824BF01008DF038 /* WebFileButton.m in Sources */,
  -				939810E10824BF01008DF038 /* WebGlyphBuffer.m in Sources */,
   				939810E20824BF01008DF038 /* WebImageRenderer.m in Sources */,
   				939810E30824BF01008DF038 /* WebImageRendererFactory.m in Sources */,
   				939810E40824BF01008DF038 /* WebJavaScriptTextInputPanel.m in Sources */,
  
  
  
  1.472     +0 -12     WebKit/WebView.subproj/WebHTMLView.m
  
  Index: WebHTMLView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebHTMLView.m,v
  retrieving revision 1.471
  retrieving revision 1.472
  diff -u -r1.471 -r1.472
  --- WebHTMLView.m	24 Sep 2005 10:58:19 -0000	1.471
  +++ WebHTMLView.m	6 Oct 2005 15:46:11 -0000	1.472
  @@ -2406,24 +2406,12 @@
       [(WebClipView *)[self superview] setAdditionalClip:rect];
   
       NS_DURING {
  -        WebTextRendererFactory *textRendererFactoryIfCoalescing = nil;
  -        if ([WebTextRenderer shouldBufferTextDrawing] && [NSView focusView]) {
  -            textRendererFactoryIfCoalescing = [WebTextRendererFactory sharedFactory];
  -            [textRendererFactoryIfCoalescing startCoalesceTextDrawing];
  -        }
  -
           if ([self _transparentBackground]) {
               [[NSColor clearColor] set];
               NSRectFill (rect);
           }
           
  -        //double start = CFAbsoluteTimeGetCurrent();
           [[self _bridge] drawRect:rect];
  -        //LOG(Timing, "draw time %e", CFAbsoluteTimeGetCurrent() - start);
  -
  -        if (textRendererFactoryIfCoalescing != nil) {
  -            [textRendererFactoryIfCoalescing endCoalesceTextDrawing];
  -        }
   
           [(WebClipView *)[self superview] resetAdditionalClip];
   
  
  
  
  1.64      +2 -6      WebKit/WebView.subproj/WebTextView.m
  
  Index: WebTextView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebTextView.m,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- WebTextView.m	26 Sep 2005 19:07:00 -0000	1.63
  +++ WebTextView.m	6 Oct 2005 15:46:12 -0000	1.64
  @@ -130,12 +130,8 @@
   - (void)setFixedWidthFont
   {
       WebPreferences *preferences = [self _preferences];
  -    NSString *families[2];
  -    families[0] = [preferences fixedFontFamily];
  -    families[1] = nil;
  -    NSFont *font = [[WebTextRendererFactory sharedFactory] fontWithFamilies:families 
  -                                                                     traits:0 
  -                                                                       size:[preferences defaultFixedFontSize]*_textSizeMultiplier];
  +    NSFont *font = [[WebTextRendererFactory sharedFactory] cachedFontFromFamily:[preferences fixedFontFamily]
  +        traits:0 size:[preferences defaultFixedFontSize] * _textSizeMultiplier];
       if (font) {
           [self setFont:font];
       }
  
  
  
  1.310     +1 -1      WebKit/WebView.subproj/WebView.m
  
  Index: WebView.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebView.m,v
  retrieving revision 1.309
  retrieving revision 1.310
  diff -u -r1.309 -r1.310
  --- WebView.m	28 Sep 2005 18:43:14 -0000	1.309
  +++ WebView.m	6 Oct 2005 15:46:12 -0000	1.310
  @@ -404,7 +404,7 @@
   
   + (void)_setAlwaysUseATSU:(BOOL)f
   {
  -    [WebTextRenderer _setAlwaysUseATSU:f];
  +    [WebTextRenderer setAlwaysUseATSU:f];
   }
   
   + (BOOL)canShowFile:(NSString *)path
  
  
  
  1.14      +12 -0     LayoutTests/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/LayoutTests/ChangeLog,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ChangeLog	6 Oct 2005 06:38:24 -0000	1.13
  +++ ChangeLog	6 Oct 2005 15:46:14 -0000	1.14
  @@ -1,3 +1,15 @@
  +2005-10-06  Darin Adler  <darin at apple.com>
  +
  +        - updated test result for synthetic bold
  +
  +        * editing/pasteboard/paste-text-011-expected.checksum: Regenerated.
  +        * editing/pasteboard/paste-text-011-expected.png: Ditto.
  +        * editing/pasteboard/paste-text-011-expected.txt: Ditto.
  +
  +        - updated test result that was incorrect
  +
  +        * fast/dom/namednodemap-namelookup-expected.txt: Added trailing newlines
  +
   2005-10-05  Vicki Murley  <vicki at apple.com>
   
   	Test cases for <rdar://problem/4288829> repro crash on isIndex tag with no attributes
  
  
  
  1.2       +1 -1      LayoutTests/editing/pasteboard/paste-text-011-expected.checksum
  
  Index: paste-text-011-expected.checksum
  ===================================================================
  RCS file: /cvs/root/LayoutTests/editing/pasteboard/paste-text-011-expected.checksum,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- paste-text-011-expected.checksum	29 Aug 2005 05:56:07 -0000	1.1
  +++ paste-text-011-expected.checksum	6 Oct 2005 15:46:15 -0000	1.2
  @@ -1 +1 @@
  -4129dceda11749c53b5ae323a57200bb
  \ No newline at end of file
  +b68acb271b7283bf1a768ac305b97bdd
  \ No newline at end of file
  
  
  
  1.2       +11 -4     LayoutTests/editing/pasteboard/paste-text-011-expected.png
  
  	<<Binary file>>
  
  
  1.13      +20 -20    LayoutTests/editing/pasteboard/paste-text-011-expected.txt
  
  Index: paste-text-011-expected.txt
  ===================================================================
  RCS file: /cvs/root/LayoutTests/editing/pasteboard/paste-text-011-expected.txt,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- paste-text-011-expected.txt	15 Aug 2005 03:39:55 -0000	1.12
  +++ paste-text-011-expected.txt	6 Oct 2005 15:46:15 -0000	1.13
  @@ -15,24 +15,24 @@
   layer at (0,0) size 800x600
     RenderBlock {HTML} at (0,0) size 800x600
       RenderBody {BODY} at (8,8) size 784x576
  -      RenderBlock {P} at (0,0) size 784x18
  -        RenderInline {FONT} at (0,0) size 37x18
  -          RenderInline {B} at (0,0) size 37x18
  -            RenderText {TEXT} at (0,0) size 37x18
  -              text run at (0,0) width 37: "hello"
  -      RenderBlock {P} at (0,34) size 784x18
  -        RenderInline {FONT} at (0,0) size 39x18
  -          RenderInline {B} at (0,0) size 39x18
  -            RenderText {TEXT} at (0,0) size 39x18
  -              text run at (0,0) width 39: "there"
  -      RenderBlock {P} at (0,68) size 784x18
  -        RenderInline {FONT} at (0,0) size 37x18
  -          RenderInline {B} at (0,0) size 37x18
  -            RenderText {TEXT} at (0,0) size 37x18
  -              text run at (0,0) width 37: "hello"
  -      RenderBlock {P} at (0,102) size 784x18
  -        RenderInline {FONT} at (0,0) size 39x18
  -          RenderInline {B} at (0,0) size 39x18
  -            RenderText {TEXT} at (0,0) size 39x18
  -              text run at (0,0) width 39: "there"
  +      RenderBlock {P} at (0,0) size 784x21
  +        RenderInline {FONT} at (0,0) size 55x20
  +          RenderInline {B} at (0,0) size 55x20
  +            RenderText {TEXT} at (0,0) size 55x21
  +              text run at (0,0) width 55: "hello"
  +      RenderBlock {P} at (0,37) size 784x21
  +        RenderInline {FONT} at (0,0) size 55x20
  +          RenderInline {B} at (0,0) size 55x20
  +            RenderText {TEXT} at (0,0) size 55x21
  +              text run at (0,0) width 55: "there"
  +      RenderBlock {P} at (0,74) size 784x21
  +        RenderInline {FONT} at (0,0) size 55x20
  +          RenderInline {B} at (0,0) size 55x20
  +            RenderText {TEXT} at (0,0) size 55x21
  +              text run at (0,0) width 55: "hello"
  +      RenderBlock {P} at (0,111) size 784x21
  +        RenderInline {FONT} at (0,0) size 55x20
  +          RenderInline {B} at (0,0) size 55x20
  +            RenderText {TEXT} at (0,0) size 55x21
  +              text run at (0,0) width 55: "there"
   caret: position 5 of child 0 {TEXT} of child 0 {B} of child 0 {FONT} of child 5 {P} of child 1 {BODY} of child 0 {HTML} of document
  
  
  
  1.2       +2 -0      LayoutTests/fast/dom/namednodemap-namelookup-expected.txt
  
  Index: namednodemap-namelookup-expected.txt
  ===================================================================
  RCS file: /cvs/root/LayoutTests/fast/dom/namednodemap-namelookup-expected.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- namednodemap-namelookup-expected.txt	5 Oct 2005 06:09:12 -0000	1.1
  +++ namednodemap-namelookup-expected.txt	6 Oct 2005 15:46:16 -0000	1.2
  @@ -1 +1,3 @@
   Success
  +
  +
  
  
  



More information about the webkit-changes mailing list