Bug 8877. Change form controls and the bridge entry points from the
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 23:28:21 +0000 (23:28 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 23:28:21 +0000 (23:28 +0000)
        Safari UI to use Font instead of FontData.

        Reviewed by mjs

        * bridge/mac/WebCoreStringTruncator.mm:
        (stringWidth):
        (truncateString):
        (+[WebCoreStringTruncator widthOfString:font:]):
        (+[WebCoreStringTruncator clear]):
        * kwq/KWQComboBox.mm:
        (QComboBox::sizeHint):
        * kwq/KWQLineEdit.mm:
        (QLineEdit::sizeForCharacterWidth):
        * kwq/KWQListBox.mm:
        (itemTextRenderer):
        (groupLabelTextRenderer):
        (QListBox::sizeForNumberOfLines):
        (QListBox::clearCachedTextRenderers):
        (-[KWQTableView drawRow:clipRect:]):
        * platform/Font.cpp:
        (WebCore::Font::drawSimpleText):
        (WebCore::Font::drawText):
        * platform/Font.h:
        (WebCore::TextStyle::disableRoundingHacks):
        (WebCore::TextStyle::setRTL):
        * platform/FontData.h:
        * platform/FontFallbackList.h:
        * platform/FontPlatformData.h:
        (WebCore::FontPlatformData::syntheticOblique):
        * platform/Pen.h:
        * platform/mac/FontData.mm:
        (WebCore::FontData::smallCapsFontData):
        (WebCore::findSubstituteRenderer):
        * platform/mac/FontMac.mm:
        (WebCore::FontFallbackList::setPlatformFont):
        (WebCore::m_wordSpacing):
        (WebCore::Font::drawComplexText):
        * platform/mac/WebCoreTextRenderer.mm:
        (WebCoreDrawTextAtPoint):
        (WebCoreTextFloatWidth):
        * platform/win/FontWin.cpp:
        (WebCore::Font::drawText):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::positionForOffset):

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

15 files changed:
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreStringTruncator.mm
WebCore/kwq/KWQComboBox.mm
WebCore/kwq/KWQLineEdit.mm
WebCore/kwq/KWQListBox.mm
WebCore/platform/Font.cpp
WebCore/platform/Font.h
WebCore/platform/FontData.h
WebCore/platform/FontFallbackList.h
WebCore/platform/FontPlatformData.h
WebCore/platform/Pen.h
WebCore/platform/mac/FontData.mm
WebCore/platform/mac/FontMac.mm
WebCore/platform/mac/WebCoreTextRenderer.mm
WebCore/platform/win/FontWin.cpp

index f8e22117c7d244d525febd6c9797c64716040a44..defd0e0a29df21950968e4077aec330c028da7a5 100644 (file)
@@ -1,3 +1,51 @@
+2006-05-12  David Hyatt  <hyatt@apple.com>
+
+        Bug 8877.  Change form controls and the bridge entry points from the
+        Safari UI to use Font instead of FontData.
+
+        Reviewed by mjs
+
+        * bridge/mac/WebCoreStringTruncator.mm:
+        (stringWidth):
+        (truncateString):
+        (+[WebCoreStringTruncator widthOfString:font:]):
+        (+[WebCoreStringTruncator clear]):
+        * kwq/KWQComboBox.mm:
+        (QComboBox::sizeHint):
+        * kwq/KWQLineEdit.mm:
+        (QLineEdit::sizeForCharacterWidth):
+        * kwq/KWQListBox.mm:
+        (itemTextRenderer):
+        (groupLabelTextRenderer):
+        (QListBox::sizeForNumberOfLines):
+        (QListBox::clearCachedTextRenderers):
+        (-[KWQTableView drawRow:clipRect:]):
+        * platform/Font.cpp:
+        (WebCore::Font::drawSimpleText):
+        (WebCore::Font::drawText):
+        * platform/Font.h:
+        (WebCore::TextStyle::disableRoundingHacks):
+        (WebCore::TextStyle::setRTL):
+        * platform/FontData.h:
+        * platform/FontFallbackList.h:
+        * platform/FontPlatformData.h:
+        (WebCore::FontPlatformData::syntheticOblique):
+        * platform/Pen.h:
+        * platform/mac/FontData.mm:
+        (WebCore::FontData::smallCapsFontData):
+        (WebCore::findSubstituteRenderer):
+        * platform/mac/FontMac.mm:
+        (WebCore::FontFallbackList::setPlatformFont):
+        (WebCore::m_wordSpacing):
+        (WebCore::Font::drawComplexText):
+        * platform/mac/WebCoreTextRenderer.mm:
+        (WebCoreDrawTextAtPoint):
+        (WebCoreTextFloatWidth):
+        * platform/win/FontWin.cpp:
+        (WebCore::Font::drawText):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::positionForOffset):
+
 2006-05-12  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by kevin.
index 595be80a04194c1a635d70796cd34f3dfb8a62ab..fa3a4b91e3d097a92475252df76cdca24afa253f 100644 (file)
@@ -33,7 +33,7 @@
 
 #import <wtf/Assertions.h>
 #import "WebTextRendererFactory.h"
-#import "FontData.h"
+#import "Font.h"
 
 #define STRING_BUFFER_SIZE 2048
 #define ELLIPSIS_CHARACTER 0x2026
@@ -41,7 +41,7 @@
 using namespace WebCore;
 
 static NSFont *currentFont;
-static FontData* currentRenderer;
+static Font* currentRenderer = 0;
 static float currentEllipsisWidth;
 
 typedef unsigned TruncationFunction(NSString *string, unsigned length, unsigned keepCount, unichar *buffer);
@@ -81,15 +81,12 @@ static unsigned rightTruncateToBuffer(NSString *string, unsigned length, unsigne
     return keepRange.length + 1;
 }
 
-static float stringWidth(FontData* renderer, const unichar *characters, unsigned length)
+static float stringWidth(Font* renderer, const unichar *characters, unsigned length)
 {
-    WebCoreTextRun run;
-    WebCoreInitializeTextRun(&run, characters, length, 0, length);
-    WebCoreTextStyle style;
-    WebCoreInitializeEmptyTextStyle(&style);
-    style.applyRunRounding = NO;
-    style.applyWordRounding = NO;
-    return renderer->floatWidthForRun(&run, &style);
+    TextRun run(characters, length);
+    TextStyle style;
+    style.disableRoundingHacks();
+    return renderer->floatWidth(run, style);
 }
 
 static NSString *truncateString(NSString *string, float maxWidth, NSFont *font, TruncationFunction truncateToBuffer)
@@ -114,10 +111,9 @@ static NSString *truncateString(NSString *string, float maxWidth, NSFont *font,
     if (![currentFont isEqual:font]) {
         [currentFont release];
         currentFont = [font retain];
-        FontPlatformData f;
-        WebCoreInitializeFont(&f);
-        f.font = font;
-        currentRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:f];
+        FontPlatformData f(font);
+        delete currentRenderer;
+        currentRenderer = new Font(f);
         ellipsis = ELLIPSIS_CHARACTER;
         currentEllipsisWidth = stringWidth(currentRenderer, &ellipsis, 1);
     }
@@ -223,17 +219,19 @@ static NSFont *defaultMenuFont(void)
     unsigned length = [string length];
     unichar *s = static_cast<unichar*>(malloc(sizeof(unichar) * length));
     [string getCharacters:s];
-    FontPlatformData f;
-    WebCoreInitializeFont(&f);
-    f.font = font;
-    float width = stringWidth([[WebTextRendererFactory sharedFactory] rendererWithFont:f], s, length);
+    FontPlatformData f(font);
+    Font fontRenderer(f);
+    float width = stringWidth(&fontRenderer, s, length);
     free(s);
     return width;
 }
 
 + (void)clear
 {
+    delete currentRenderer;
     currentRenderer = 0;
+    [currentFont release];
+    currentFont = nil;
 }
 
 @end
index c1728ed340207989da6d3bc1e37e60727d4907cd..2c8d3ab3347e106daab291e18c89017aaf8dde6e 100644 (file)
@@ -35,6 +35,7 @@
 #import "WebTextRendererFactory.h"
 #import "WebCoreWidgetHolder.h"
 #import "render_form.h"
+#import "Font.h"
 
 using namespace WebCore;
 
@@ -165,39 +166,20 @@ IntSize QComboBox::sizeHint() const
         DeprecatedValueListConstIterator<KWQListBoxItem> i = const_cast<const DeprecatedValueList<KWQListBoxItem> &>(_items).begin();
         DeprecatedValueListConstIterator<KWQListBoxItem> e = const_cast<const DeprecatedValueList<KWQListBoxItem> &>(_items).end();
         if (i != e) {
-            FontPlatformData itemFont;
-            WebCoreInitializeFont(&itemFont);
-            itemFont.font = [button font];
-            itemFont.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
-            FontData* itemRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:itemFont];
-            FontData* labelRenderer = nil;
-            WebCoreTextStyle style;
-            WebCoreInitializeEmptyTextStyle(&style);
-            style.applyRunRounding = NO;
-            style.applyWordRounding = NO;
+            FontPlatformData itemFont([button font], ![NSGraphicsContext currentContextDrawingToScreen]);
+            FontPlatformData labelFont(this->labelFont(), ![NSGraphicsContext currentContextDrawingToScreen]);
+            Font itemRenderer(itemFont);
+            Font labelRenderer(labelFont);
             do {
                 const DeprecatedString &s = (*i).string;
                 bool isGroupLabel = ((*i).type == KWQListBoxGroupLabel);
                 ++i;
 
-                WebCoreTextRun run;
-                int length = s.length();
-                WebCoreInitializeTextRun(&run, reinterpret_cast<const UniChar *>(s.unicode()), length, 0, length);
-
-                FontData* renderer;
-                if (isGroupLabel) {
-                    if (labelRenderer == nil) {
-                        FontPlatformData labelFont;
-                        WebCoreInitializeFont(&labelFont);
-                        labelFont.font = this->labelFont();
-                        labelFont.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
-                        labelRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:labelFont];
-                    }
-                    renderer = labelRenderer;
-                } else {
-                    renderer = itemRenderer;
-                }
-                float textWidth = renderer->floatWidthForRun(&run, &style);
+                TextRun run(reinterpret_cast<const UniChar *>(s.unicode()), s.length());
+                WebCore::TextStyle style;
+                style.disableRoundingHacks();
+                Font* renderer = isGroupLabel ? &labelRenderer : &itemRenderer;
+                float textWidth = renderer->floatWidth(run, style);
                 width = max(width, textWidth);
             } while (i != e);
         }
index ae3fd5b0f13562f41d62fbde829fd752605f5650..49bf78beea46c1bd3754011c596e3be60522fe73 100644 (file)
@@ -261,26 +261,20 @@ IntSize QLineEdit::sizeForCharacterWidth(int numCharacters) const
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    FontPlatformData font;
-    WebCoreInitializeFont(&font);
-    font.font = [textField font];
-    font.forPrinter = ![NSGraphicsContext currentContextDrawingToScreen];
-    FontData* renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
+    FontPlatformData font([textField font], ![NSGraphicsContext currentContextDrawingToScreen]);
+    Font renderer(font);
 
     NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
     size.height += [layoutManager defaultLineHeightForFont:font.font];
     [layoutManager release];
 
-    WebCoreTextStyle style;
-    WebCoreInitializeEmptyTextStyle(&style);
-    style.applyRunRounding = NO;
-    style.applyWordRounding = NO;
+    WebCore::TextStyle style;
+    style.disableRoundingHacks();
 
     const UniChar zero = '0';
-    WebCoreTextRun run;
-    WebCoreInitializeTextRun(&run, &zero, 1, 0, 1);
+    TextRun run(&zero, 1);
 
-    size.width += ceilf(renderer->floatWidthForRun(&run, &style) * numCharacters);
+    size.width += ceilf(renderer.floatWidth(run, style) * numCharacters);
 
     return IntSize(size);
     END_BLOCK_OBJC_EXCEPTIONS;
index 5222c12db4530728e08b6e0d9ff032447ae22d69..b6b5fc77054cc0d9f85dfba7f10a0ab3cce3ff56 100644 (file)
@@ -35,6 +35,7 @@
 #import <wtf/Assertions.h>
 
 #import "render_form.h"
+#import "GraphicsContext.h"
 
 using namespace WebCore;
 
@@ -66,10 +67,10 @@ const float rightMargin = 2;
 - (void)fontChanged;
 @end
 
-static FontData* itemScreenRenderer;
-static FontData* itemPrinterRenderer;
-static FontData* groupLabelScreenRenderer;
-static FontData* groupLabelPrinterRenderer;
+static Font* itemScreenRenderer = 0;
+static Font* itemPrinterRenderer = 0;
+static Font* groupLabelScreenRenderer = 0;
+static Font* groupLabelPrinterRenderer = 0;
 
 static NSFont *itemFont()
 {
@@ -77,45 +78,35 @@ static NSFont *itemFont()
     return font;
 }
 
-static FontData* itemTextRenderer()
+static Font* itemTextRenderer()
 {
     if ([NSGraphicsContext currentContextDrawingToScreen]) {
         if (itemScreenRenderer == nil) {
-            FontPlatformData font;
-            WebCoreInitializeFont(&font);
-            font.font = itemFont();
-            itemScreenRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
+            FontPlatformData font(itemFont());
+            itemScreenRenderer = new Font(font);
         }
         return itemScreenRenderer;
     } else {
         if (itemPrinterRenderer == nil) {
-            FontPlatformData font;
-            WebCoreInitializeFont(&font);
-            font.font = itemFont();
-            font.forPrinter = YES;
-            itemPrinterRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
+            FontPlatformData font(itemFont(), true);
+            itemPrinterRenderer = new Font(font);
         }
         return itemPrinterRenderer;
     }
 }
 
-static FontData* groupLabelTextRenderer()
+static Font* groupLabelTextRenderer()
 {
     if ([NSGraphicsContext currentContextDrawingToScreen]) {
         if (groupLabelScreenRenderer == nil) {
-            FontPlatformData font;
-            WebCoreInitializeFont(&font);
-            font.font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
-            groupLabelScreenRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
+            FontPlatformData font([NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]);
+            groupLabelScreenRenderer = new Font(font);
         }
         return groupLabelScreenRenderer;
     } else {
         if (groupLabelPrinterRenderer == nil) {
-            FontPlatformData font;
-            WebCoreInitializeFont(&font);
-            font.font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]];
-            font.forPrinter = YES;
-            groupLabelPrinterRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font];
+            FontPlatformData font([NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]], true);
+            groupLabelPrinterRenderer = new Font(font);
         }
         return groupLabelPrinterRenderer;
     }
@@ -273,40 +264,37 @@ IntSize QListBox::sizeForNumberOfLines(int lines) const
         DeprecatedValueListConstIterator<KWQListBoxItem> i = const_cast<const DeprecatedValueList<KWQListBoxItem> &>(_items).begin();
         DeprecatedValueListConstIterator<KWQListBoxItem> e = const_cast<const DeprecatedValueList<KWQListBoxItem> &>(_items).end();
         if (i != e) {
-            WebCoreTextStyle style;
-            WebCoreInitializeEmptyTextStyle(&style);
-            style.rtl = [tableView baseWritingDirection] == NSWritingDirectionRightToLeft;
-            style.applyRunRounding = NO;
-            style.applyWordRounding = NO;
-            
-            FontData* renderer;
-            FontData* groupLabelRenderer;
+            WebCore::TextStyle style;
+            style.disableRoundingHacks();
+            style.setRTL([tableView baseWritingDirection] == NSWritingDirectionRightToLeft);
+
+            const Font* renderer;
+            const Font* groupLabelRenderer;
             
+            bool needToDeleteLabel = false;
             if (tableView->isSystemFont) {        
                 renderer = itemTextRenderer();
                 groupLabelRenderer = groupLabelTextRenderer();
             } else {
-                renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:font().platformFont()];
+                renderer = &font();
                 FontDescription boldDesc = font().fontDescription();
                 boldDesc.setWeight(cBoldWeight);
-                Font b = Font(boldDesc, font().letterSpacing(), font().wordSpacing());
-                b.update();
-                groupLabelRenderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:b.platformFont()];
+                groupLabelRenderer = new Font(boldDesc, font().letterSpacing(), font().wordSpacing());
+                groupLabelRenderer->update();
+                needToDeleteLabel = true;
             }
             
             do {
                 const DeprecatedString &s = (*i).string;
-
-                WebCoreTextRun run;
-                int length = s.length();
-                WebCoreInitializeTextRun(&run, reinterpret_cast<const UniChar *>(s.unicode()), length, 0, length);
-
-                float textWidth = (((*i).type == KWQListBoxGroupLabel) ? groupLabelRenderer : renderer)->floatWidthForRun(&run, &style);
+                TextRun run(reinterpret_cast<const UniChar *>(s.unicode()), s.length(), 0, s.length());
+                float textWidth = (((*i).type == KWQListBoxGroupLabel) ? groupLabelRenderer : renderer)->floatWidth(run, style);
                 width = max(width, textWidth);
-                
                 ++i;
             
             } while (i != e);
+            
+            if (needToDeleteLabel)
+                delete groupLabelRenderer;
         }
         _width = ceilf(width);
         _widthGood = true;
@@ -349,9 +337,16 @@ void QListBox::setWritingDirection(TextDirection d)
 
 void QListBox::clearCachedTextRenderers()
 {
+    delete itemScreenRenderer;
     itemScreenRenderer = 0;
+    
+    delete itemPrinterRenderer;
     itemPrinterRenderer = 0;
+    
+    delete groupLabelScreenRenderer;
     groupLabelScreenRenderer = 0;
+    
+    delete groupLabelPrinterRenderer;
     groupLabelPrinterRenderer = 0;
 }
 
@@ -680,46 +675,42 @@ static Boolean KWQTableViewTypeSelectCallback(UInt32 index, void *listDataPtr, v
 
     bool rtl = _direction == NSWritingDirectionRightToLeft;
 
-    FontData* renderer;
+    bool deleteRenderer = false;
+    const Font* renderer;
     if (isSystemFont) {
         renderer = (item.type == KWQListBoxGroupLabel) ? groupLabelTextRenderer() : itemTextRenderer();
     } else {
         if (item.type == KWQListBoxGroupLabel) {
+            deleteRenderer = true;
             FontDescription boldDesc = _box->font().fontDescription();
             boldDesc.setWeight(cBoldWeight);
-            Font b = Font(boldDesc, _box->font().letterSpacing(), _box->font().wordSpacing());
-            b.update();
-            renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:b.platformFont()];
+            renderer = new Font(boldDesc, _box->font().letterSpacing(), _box->font().wordSpacing());
+            renderer->update();
         }
         else
-            renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:_box->font().platformFont()];
+            renderer = &_box->font();
     }
    
-    WebCoreTextStyle style;
-    WebCoreInitializeEmptyTextStyle(&style);
-    style.rtl = rtl;
-    style.applyRunRounding = NO;
-    style.applyWordRounding = NO;
-    style.textColor = color;
-
-    WebCoreTextRun run;
-    int length = item.string.length();
-    WebCoreInitializeTextRun(&run, reinterpret_cast<const UniChar *>(item.string.unicode()), length, 0, length);
+    WebCore::TextStyle style;
+    style.setRTL(rtl);
+    style.disableRoundingHacks();
 
+    TextRun run(reinterpret_cast<const UniChar *>(item.string.unicode()), item.string.length());
+    
     NSRect cellRect = [self frameOfCellAtColumn:0 row:row];
-    NSPoint point;
-    if (!rtl) {
-        point.x = NSMinX(cellRect) + leftMargin;
-    } else {
-        point.x = NSMaxX(cellRect) - rightMargin - renderer->floatWidthForRun(&run, &style);
-    }
-    point.y = NSMaxY(cellRect) - renderer->descent() - bottomMargin;
-
-    WebCoreTextGeometry geometry;
-    WebCoreInitializeEmptyTextGeometry(&geometry);
-    geometry.point = point;
-
-    renderer->drawRun(&run, &style, &geometry);
+    FloatPoint point;
+    if (!rtl)
+        point.setX(NSMinX(cellRect) + leftMargin);
+    else
+        point.setX(NSMaxX(cellRect) - rightMargin - renderer->floatWidth(run, style));
+    point.setY(NSMaxY(cellRect) - renderer->descent() - bottomMargin);
+
+    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+    GraphicsContext graphicsContext(context);
+    float red, green, blue, alpha;
+    [[color colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
+    graphicsContext.setPen(makeRGBA((int)(red * 255), (int)(green * 255), (int)(blue * 255), (int)(alpha * 255)));
+    renderer->drawText(&graphicsContext, run, style, point);
 }
 
 - (void)_KWQ_setKeyboardFocusRingNeedsDisplay
index 2081f5de0cf74948d729c3bc12675cb98b8ed980..6e84ee22ae295c86496b2b45036bd1c2b062d0b6 100644 (file)
@@ -446,7 +446,7 @@ bool Font::canUseGlyphCache(const TextRun& run) const
 
 }
 
-void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const TextStyle& style, const IntPoint& point) const
+void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
 {
     // This glyph buffer holds our glyphs+advances+font data for each glyph.
     GlyphBuffer glyphBuffer;
@@ -488,7 +488,7 @@ void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Te
     drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
 }
 
-void Font::drawText(GraphicsContext* context, const TextRun& run, const TextStyle& style, const IntPoint& point) const
+void Font::drawText(GraphicsContext* context, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
 {
     if (canUseGlyphCache(run))
         drawSimpleText(context, run, style, point);
index 21f39290dd45564a93fcd1aadab065d4a6dc2b6d..404ef0e3130e9a9395b41017330d75ffa323c339 100644 (file)
@@ -99,6 +99,9 @@ public:
     bool applyWordRounding() const { return m_applyWordRounding; }
     bool attemptFontSubstitution() const { return m_attemptFontSubstitution; }
 
+    void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = false; }
+    void setRTL(bool b) { m_rtl = b; }
+    
 private:
     int m_tabWidth;
     int m_xpos;
@@ -114,6 +117,9 @@ class Font {
 public:
     Font();
     Font(const FontDescription&, short letterSpacing, short wordSpacing);
+#if __APPLE__
+    Font(const FontPlatformData& fontPlatformData); // This constructor is only used by Mac-specific code that already has a native font.
+#endif
     ~Font();
     
     Font(const Font&);
@@ -138,7 +144,7 @@ public:
     
     void update() const;
 
-    void drawText(GraphicsContext*, const TextRun&, const TextStyle&, const IntPoint&) const;
+    void drawText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
 
     int width(const TextRun&, const TextStyle& = TextStyle()) const;
     float floatWidth(const TextRun&, const TextStyle& = TextStyle()) const;
@@ -182,9 +188,9 @@ private:
 #if __APPLE__
     // FIXME: This will eventually be cross-platform, but we want to keep Windows compiling for now.
     bool canUseGlyphCache(const TextRun&) const;
-    void drawSimpleText(GraphicsContext*, const TextRun&, const TextStyle&, const IntPoint&) const;
+    void drawSimpleText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
     void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
-    void drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const IntPoint&) const;
+    void drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&) const;
     float floatWidthForSimpleText(const TextRun&, const TextStyle&, const FontData* substituteFont, float* startX, GlyphBuffer*) const;
     float floatWidthForComplexText(const TextRun&, const TextStyle&) const;
 
index 89b6ef8614642e4a84e94b230fd938d4b5303d30..0a53b5d5ffe9cbb2b494a4da63a045937bbe6050 100644 (file)
@@ -83,7 +83,6 @@ struct WebCoreTextGeometry
 void WebCoreInitializeTextRun(WebCoreTextRun *run, const UniChar *characters, unsigned int length, int from, int to);
 void WebCoreInitializeEmptyTextStyle(WebCoreTextStyle *style);
 void WebCoreInitializeEmptyTextGeometry(WebCoreTextGeometry *geometry);
-void WebCoreInitializeFont(FontPlatformData *font);
 
 typedef struct WidthMap WidthMap;
 typedef struct GlyphMap GlyphMap;
@@ -106,11 +105,7 @@ public:
 
     float xHeight() const;
 
-    // horizontal metrics
-    float floatWidthForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style);
-
     // drawing
-    void drawRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry);
     FloatRect selectionRectForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry);
 
     // selection point check 
index f0b59e2fe43c7e727eb4deda8fd9cf6a8550bb45..60c9d6b96ebfc12a56b64d551745f462afca7dcc 100644 (file)
@@ -57,6 +57,7 @@ private:
     mutable FontPlatformData m_platformFont;
 
     const FontPlatformData& platformFont(const FontDescription&) const;
+    void setPlatformFont(const FontPlatformData&);
 #else
     mutable Vector<FontData*> m_fontList;
 #endif
index d4447164f96fb3d024763e753050626d5fae3e70..9c8c88b3edb74162921e2de20f5b754330d0be64 100644 (file)
@@ -35,10 +35,14 @@ class NSFont;
 namespace WebCore {
 
 struct FontPlatformData {
+    FontPlatformData(NSFont* f = 0, bool p = false, bool b = false, bool o = false)
+    :font(f), forPrinter(p), syntheticBold(b), syntheticOblique(o)
+    {}
+
     NSFont *font;
+    bool forPrinter;
     bool syntheticBold;
     bool syntheticOblique;
-    bool forPrinter;
 };
 
 }
index f7da724a9263e1bde2d9b5613c932206ee556505..48fc500c0d6b1cfd8b7a924926600fa758ed02f4 100644 (file)
@@ -54,7 +54,7 @@ public:
 
 private:
     PenStyle  m_style;
-    unsigned      m_width;
+    unsigned  m_width;
     Color     m_color;
 };
 
index ffeac4513c7db4db112abae8da0e4fd6f1fcfb31..d095bac84847d7edada96fb7257222a44cb373ba 100644 (file)
@@ -149,11 +149,6 @@ static void freeGlyphMap(GlyphMap *);
 // Measuring runs.
 static float CG_floatWidthForRun(FontData *, const WebCoreTextRun *, const WebCoreTextStyle *,
     float *widthBuffer, FontData **rendererBuffer, CGGlyph *glyphBuffer, float *startPosition, int *numGlyphsResult);
-static float ATSU_floatWidthForRun(FontData *, const WebCoreTextRun *, const WebCoreTextStyle *);
-
-// Drawing runs.
-static void CG_draw(FontData *, const WebCoreTextRun *, const WebCoreTextStyle *, const WebCoreTextGeometry *);
-static void ATSU_draw(FontData *, const WebCoreTextRun *, const WebCoreTextStyle *, const WebCoreTextGeometry *);
 
 // Selection point detection in runs.
 static int CG_pointToOffset(FontData *, const WebCoreTextRun *, const WebCoreTextStyle *,
@@ -183,14 +178,6 @@ static void disposeATSULayoutParameters(ATSULayoutParameters *params);
 
 // Character property functions.
 
-void WebCoreInitializeFont(FontPlatformData *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)
 {
     run->characters = characters;
@@ -497,21 +484,6 @@ float FontData::xHeight() const
     return [m_font.font xHeight];
 }
 
-void FontData::drawRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry)
-{
-    if (shouldUseATSU(run))
-        ATSU_draw(this, run, style, geometry);
-    else
-        CG_draw(this, run, style, geometry);
-}
-
-float FontData::floatWidthForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style)
-{
-    if (shouldUseATSU(run))
-        return ATSU_floatWidthForRun(this, run, style);
-    return CG_floatWidthForRun(this, run, style, 0, 0, 0, 0, 0);
-}
-
 FloatRect FontData::selectionRectForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry)
 {
     if (shouldUseATSU(run))
@@ -532,9 +504,7 @@ FontData* FontData::smallCapsFontData() const
     if (!m_smallCapsFontData) {
        NS_DURING
             float size = [m_font.font pointSize] * SMALLCAPS_FONTSIZE_MULTIPLIER;
-            FontPlatformData smallCapsFont;
-            WebCoreInitializeFont(&smallCapsFont);
-            smallCapsFont.font = [[NSFontManager sharedFontManager] convertFont:m_font.font toSize:size];
+            FontPlatformData smallCapsFont([[NSFontManager sharedFontManager] convertFont:m_font.font toSize:size]);
            m_smallCapsFontData = (FontData*)rendererForAlternateFont(this, smallCapsFont);
        NS_HANDLER
             NSLog(@"uncaught exception selecting font for small caps: %@", localException);
@@ -617,10 +587,8 @@ static const FontData *rendererForAlternateFont(const FontData *renderer, FontPl
 
 static const FontData *findSubstituteRenderer(const FontData *renderer, const unichar *characters, int numCharacters, NSString **families)
 {
-    FontPlatformData substituteFont;
-    WebCoreInitializeFont(&substituteFont);
     NSString *string = [[NSString alloc] initWithCharactersNoCopy:(unichar *)characters length: numCharacters freeWhenDone: NO];
-    substituteFont.font = findSubstituteFont(renderer, string, families);
+    FontPlatformData substituteFont(findSubstituteFont(renderer, string, families));
     [string release];
     return rendererForAlternateFont(renderer, substituteFont);
 }
@@ -703,57 +671,6 @@ static NSString *pathFromFont(NSFont *font)
 
 #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,
-    float syntheticBoldOffset, bool syntheticOblique)
-{
-    NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
-    CGContextRef cgContext = (CGContextRef)[gContext graphicsPort];
-
-    bool originalShouldUseFontSmoothing = wkCGContextGetShouldSmoothFonts(cgContext);
-    CGContextSetShouldSmoothFonts(cgContext, WebCoreShouldUseFontSmoothing());
-    
-    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).
-            LOG_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));
-    if ([gContext isFlipped]) {
-        matrix.b = -matrix.b;
-        matrix.d = -matrix.d;
-    }
-    if (syntheticOblique)
-        matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, -tanf(SYNTHETIC_OBLIQUE_ANGLE * acosf(0) / 90), 1, 0, 0)); 
-    CGContextSetTextMatrix(cgContext, matrix);
-
-    wkSetCGFontRenderingMode(cgContext, drawFont);
-    CGContextSetFontSize(cgContext, 1.0f);
-
-    [color set];
-
-    CGContextSetTextPosition(cgContext, x, y);
-    CGContextShowGlyphsWithAdvances(cgContext, glyphs, advances, numGlyphs);
-    if (syntheticBoldOffset) {
-        CGContextSetTextPosition(cgContext, x + syntheticBoldOffset, y);
-        CGContextShowGlyphsWithAdvances(cgContext, glyphs, advances, numGlyphs);
-    }
-
-    CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
-}
-
 static NSRect CG_selectionRect(FontData *renderer, const WebCoreTextRun * run, const WebCoreTextStyle *style, const WebCoreTextGeometry *geometry)
 {
     float yPos = geometry->useFontMetricsForSelectionYAndHeight
@@ -782,100 +699,6 @@ static NSRect CG_selectionRect(FontData *renderer, const WebCoreTextRun * run, c
     }
 }
 
-static void CG_draw(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style, const WebCoreTextGeometry *geometry)
-{
-    float *widthBuffer, localWidthBuffer[LOCAL_BUFFER_SIZE];
-    CGGlyph *glyphBuffer, localGlyphBuffer[LOCAL_BUFFER_SIZE];
-    FontData **rendererBuffer, *localRendererBuffer[LOCAL_BUFFER_SIZE];
-    CGSize *advances, localAdvanceBuffer[LOCAL_BUFFER_SIZE];
-    int numGlyphs = 0, i;
-    float startX;
-    unsigned length = run->length;
-    
-    if (run->length == 0)
-        return;
-
-    if (length * MAX_GLYPH_EXPANSION > LOCAL_BUFFER_SIZE) {
-        advances = new CGSize[length * MAX_GLYPH_EXPANSION];
-        widthBuffer = new float[length * MAX_GLYPH_EXPANSION];
-        glyphBuffer = new CGGlyph[length * MAX_GLYPH_EXPANSION];
-        rendererBuffer = new FontData*[length * MAX_GLYPH_EXPANSION];
-    } else {
-        advances = localAdvanceBuffer;
-        widthBuffer = localWidthBuffer;
-        glyphBuffer = localGlyphBuffer;
-        rendererBuffer = localRendererBuffer;
-    }
-
-    CG_floatWidthForRun(renderer, run, style, widthBuffer, rendererBuffer, glyphBuffer, &startX, &numGlyphs);
-        
-    // Eek.  We couldn't generate ANY glyphs for the run.
-    if (numGlyphs <= 0)
-        return;
-        
-    // Fill the advances array.
-    for (i = 0; i < numGlyphs; i++) {
-        advances[i].width = widthBuffer[i];
-        advances[i].height = 0;
-    }
-
-    // Calculate the starting point of the glyphs to be displayed by adding
-    // all the advances up to the first glyph.
-    startX += geometry->point.x();
-    
-    // Swap the order of the glyphs if right-to-left.
-    if (style->rtl) {
-        int i;
-        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;
-
-            CGSize aswap1 = advances[i];
-            CGSize aswap2 = advances[end];
-            advances[i] = aswap2;
-            advances[end] = aswap1;
-
-            FontData *rswap1 = rendererBuffer[i];
-            FontData *rswap2 = rendererBuffer[end];
-            rendererBuffer[i] = rswap2;
-            rendererBuffer[end] = rswap1;
-        }
-    }
-
-    // Draw each contiguous run of glyphs that use the same renderer.
-    FontData *currentRenderer = rendererBuffer[0];
-    float nextX = startX;
-    int lastFrom = 0;
-    int nextGlyph = 0;
-    while (nextGlyph < numGlyphs) {
-        FontData *nextRenderer = rendererBuffer[nextGlyph];
-        if (nextRenderer != currentRenderer) {
-            drawGlyphs(currentRenderer->m_font.font, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom],
-                startX, geometry->point.y(), nextGlyph - lastFrom,
-                currentRenderer->m_syntheticBoldOffset, currentRenderer->m_font.syntheticOblique);
-            lastFrom = nextGlyph;
-            currentRenderer = nextRenderer;
-            startX = nextX;
-        }
-        nextX += advances[nextGlyph].width;
-        nextGlyph++;
-    }
-    drawGlyphs(currentRenderer->m_font.font, style->textColor, &glyphBuffer[lastFrom], &advances[lastFrom],
-        startX, geometry->point.y(), nextGlyph - lastFrom,
-        currentRenderer->m_syntheticBoldOffset, currentRenderer->m_font.syntheticOblique);
-
-    if (advances != localAdvanceBuffer) {
-        delete []advances;
-        delete []widthBuffer;
-        delete []glyphBuffer;
-        delete []rendererBuffer;
-    }
-}
-
 static float CG_floatWidthForRun(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style, float *widthBuffer, FontData **rendererBuffer, CGGlyph *glyphBuffer, float *startPosition, int *numGlyphsResult)
 {
     WidthIterator it;
@@ -1266,38 +1089,6 @@ static void disposeATSULayoutParameters(ATSULayoutParameters *params)
     delete []params->renderers;
 }
 
-static ATSTrapezoid getTextBounds(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style, NSPoint p)
-{
-    OSStatus status;
-    
-    if (run->to - run->from <= 0) {
-        ATSTrapezoid nilTrapezoid = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
-        return nilTrapezoid;
-    }
-
-    ATSULayoutParameters params;
-    createATSULayoutParameters(&params, renderer, run, style);
-
-    ATSTrapezoid firstGlyphBounds;
-    ItemCount actualNumBounds;
-    status = ATSUGetGlyphBounds(params.layout, FloatToFixed(p.x), FloatToFixed(p.y), run->from, run->to - run->from, kATSUseFractionalOrigins, 1, &firstGlyphBounds, &actualNumBounds);    
-    if (status != noErr)
-        LOG_ERROR("ATSUGetGlyphBounds() failed(%d)", status);
-    if (actualNumBounds != 1)
-        LOG_ERROR("unexpected result from ATSUGetGlyphBounds(): actualNumBounds(%d) != 1", actualNumBounds);
-
-    disposeATSULayoutParameters(&params);
-
-    return firstGlyphBounds;
-}
-
-static float ATSU_floatWidthForRun(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style)
-{
-    ATSTrapezoid oGlyphBounds = getTextBounds(renderer, run, style, NSZeroPoint);
-    return MAX(FixedToFloat(oGlyphBounds.upperRight.x), FixedToFloat(oGlyphBounds.lowerRight.x)) -
-        MIN(FixedToFloat(oGlyphBounds.upperLeft.x), FixedToFloat(oGlyphBounds.lowerLeft.x));
-}
-
 // Be sure to free the run.characters allocated by this function.
 static WebCoreTextRun addDirectionalOverride(const WebCoreTextRun *run, bool rtl)
 {
@@ -1375,69 +1166,6 @@ static NSRect ATSU_selectionRect(FontData *renderer, const WebCoreTextRun *run,
     return rect;
 }
 
-
-static void ATSU_draw(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style, const WebCoreTextGeometry *geometry)
-{
-    // The only Cocoa calls made here are to NSColor and NSGraphicsContext, and they do not raise exceptions.
-
-    OSStatus status;
-    int from, to;
-    const WebCoreTextRun *aRun = run;
-    WebCoreTextRun swappedRun;
-    
-    if (style->directionalOverride) {
-        swappedRun = addDirectionalOverride(run, style->rtl);
-        aRun = &swappedRun;
-    }
-
-    from = aRun->from;
-    to = aRun->to;
-    if (from == -1)
-        from = 0;
-    if (to == -1)
-        to = run->length;
-
-    int runLength = to - from;
-    if (runLength <= 0)
-        return;
-
-    WebCoreTextRun completeRun = *aRun;
-    completeRun.from = 0;
-    completeRun.to = aRun->length;
-    ATSULayoutParameters params;
-    createATSULayoutParameters(&params, renderer, &completeRun, style);
-
-    [style->textColor set];
-
-    // ATSUI can't draw beyond -32768 to +32767 so we translate the CTM and tell ATSUI to draw at (0, 0).
-    NSGraphicsContext *gContext = [NSGraphicsContext currentContext];
-    CGContextRef context = (CGContextRef)[gContext graphicsPort];
-    CGContextTranslateCTM(context, geometry->point.x(), geometry->point.y());
-    bool flipped = [gContext isFlipped];
-    if (!flipped)
-        CGContextScaleCTM(context, 1.0, -1.0);
-    status = ATSUDrawText(params.layout, aRun->from, runLength, 0, 0);
-    if (status == noErr && params.hasSyntheticBold) {
-        // Force relayout for the bold pass
-        ATSUClearLayoutCache(params.layout, 0);
-        params.syntheticBoldPass = true;
-        status = ATSUDrawText(params.layout, aRun->from, runLength, 0, 0);
-    }
-    if (!flipped)
-        CGContextScaleCTM(context, 1.0, -1.0);
-    CGContextTranslateCTM(context, -geometry->point.x(), -geometry->point.y());
-
-    if (status != noErr) {
-        // Nothing to do but report the error (dev build only).
-        LOG_ERROR("ATSUDrawText() failed(%d)", status);
-    }
-
-    disposeATSULayoutParameters(&params);
-    
-    if (style->directionalOverride)
-        delete []swappedRun.characters;
-}
-
 static int ATSU_pointToOffset(FontData *renderer, const WebCoreTextRun *run, const WebCoreTextStyle *style,
     int x, bool includePartialGlyphs)
 {
index 157773d1ea992557475191a497bc0a67e264f6c8..6f22049bb7f4267b8c47a6e3c63ceb600f769e37 100644 (file)
@@ -82,6 +82,12 @@ const FontPlatformData& FontFallbackList::platformFont(const FontDescription& fo
     return m_platformFont;
 }
 
+void FontFallbackList::setPlatformFont(const FontPlatformData& platformData)
+{
+    m_platformFont = platformData;
+    KWQRetain(m_platformFont.font);
+}
+
 FontData* FontFallbackList::primaryFont(const FontDescription& fontDescription) const
 {
     if (!m_font)
@@ -466,6 +472,13 @@ static void disposeATSULayoutParameters(ATSULayoutParameters *params)
     delete []params->m_fonts;
 }
 
+Font::Font(const FontPlatformData& fontData)
+:m_letterSpacing(0), m_wordSpacing(0)
+{
+    m_fontList = new FontFallbackList();
+    m_fontList->setPlatformFont(fontData);
+}
+
 const FontPlatformData& Font::platformFont() const
 {
     return m_fontList->platformFont(fontDescription());
@@ -499,7 +512,7 @@ FloatRect Font::selectionRectForText(const TextRun& textRun, const TextStyle& te
     return m_fontList->primaryFont(fontDescription())->selectionRectForRun(&run, &style, &geometry);
 }
 
-void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run, const TextStyle& style, const IntPoint& point) const
+void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run, const TextStyle& style, const FloatPoint& point) const
 {
     OSStatus status;
     
index 728a066f51c87f394a1ea5ffa918baaec20cc86d..9c01c99fa30959f3155b08f2d625401e8ebc87e8 100644 (file)
 #import "Font.h"
 #import "FontData.h"
 #import "WebTextRendererFactory.h"
+#import "IntPoint.h"
+#import "GraphicsContext.h"
 
 using namespace WebCore;
 
 void WebCoreDrawTextAtPoint(const UniChar* buffer, unsigned length, NSPoint point, NSFont* font, NSColor* textColor)
 {
-    FontPlatformData f;
-    WebCoreInitializeFont(&f);
-    f.font = font;
-    FontData* renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:f];
-
-    WebCoreTextRun run;
-    WebCoreInitializeTextRun(&run, buffer, length, 0, length);
-    WebCoreTextStyle style;
-    WebCoreInitializeEmptyTextStyle(&style);
-    style.applyRunRounding = NO;
-    style.applyWordRounding = NO;
-    style.textColor = textColor;
-    WebCoreTextGeometry geometry;
-    WebCoreInitializeEmptyTextGeometry(&geometry);
-    geometry.point = point;
-    renderer->drawRun(&run, &style, &geometry);
+    FontPlatformData f(font);
+    Font renderer(f);
+    TextRun run(buffer, length);
+    TextStyle style;
+    style.disableRoundingHacks();
+    float red, green, blue, alpha;
+    [[textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace] getRed:&red green:&green blue:&blue alpha:&alpha];
+    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+    GraphicsContext graphicsContext(context);
+    graphicsContext.setPen(makeRGBA((int)(red * 255), (int)(green * 255), (int)(blue * 255), (int)(alpha * 255)));
+    renderer.drawText(&graphicsContext, run, style, FloatPoint(point.x, point.y));
 }
 
 float WebCoreTextFloatWidth(const UniChar* buffer, unsigned length , NSFont* font)
 {
-    FontPlatformData f;
-    WebCoreInitializeFont(&f);
-    f.font = font;
-    FontData* renderer = [[WebTextRendererFactory sharedFactory] rendererWithFont:f];
-
-    WebCoreTextRun run;
-    WebCoreInitializeTextRun(&run, buffer, length, 0, length);
-    WebCoreTextStyle style;
-    WebCoreInitializeEmptyTextStyle(&style);
-    style.applyRunRounding = NO;
-    style.applyWordRounding = NO;
-    return renderer->floatWidthForRun(&run, &style);
+    FontPlatformData f(font);
+    Font renderer(f);
+    TextRun run(buffer, length);
+    TextStyle style;
+    style.disableRoundingHacks();
+    return renderer.floatWidth(run, style);
 }
 
 static bool gShouldUseFontSmoothing = true;
index 5a1f2a07d064c808f96742f43175695c2672b879..8569f9323944e290447031baa7c3348104d45fb4 100644 (file)
@@ -188,7 +188,7 @@ float Font::floatWidth(const TextRun& run, int tabWidth, int xpos, bool runRound
     return runSize.width();
 }
 
-void Font::drawText(GraphicsContext* context, const TextRun& run, const IntPoint& point, int tabWidth, int xpos,
+void Font::drawText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int tabWidth, int xpos,
                     int toAdd, TextDirection d, bool visuallyOrdered) const
 {
     FontData* font = m_fontList->primaryFont(fontDescription());
@@ -201,8 +201,8 @@ void Font::drawText(GraphicsContext* context, const TextRun& run, const IntPoint
     SaveDC(dc);
     SelectObject(dc, font->platformData().hfont());
 
-    int x = point.x();
-    int y = point.y();
+    int x = (int)point.x();
+    int y = (int)point.y();
     y -= font->ascent();
 
     SetBkMode(dc, TRANSPARENT);