Remove drawLineForText from the Font API. Implement it natively in
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 00:04:39 +0000 (00:04 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 May 2006 00:04:39 +0000 (00:04 +0000)
        the two GraphicsContexts (CG and Cairo) instead.

        Reviewed by maciej

        * platform/Font.h:
        * platform/FontData.h:
        * platform/GraphicsContext.cpp:
        * platform/GraphicsContext.h:
        * platform/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::drawLineForText):
        * platform/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::drawLineForText):
        * platform/mac/FontData.mm:
        * platform/mac/FontMac.mm:
        * platform/win/FontWin.cpp:
        (WebCore::Font::drawLineForText):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::paintDecoration):
        (WebCore::InlineTextBox::paintMarkedTextUnderline):
        * rendering/render_line.cpp:
        (WebCore::InlineFlowBox::paintDecorations):

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

12 files changed:
WebCore/ChangeLog
WebCore/platform/Font.h
WebCore/platform/FontData.h
WebCore/platform/GraphicsContext.cpp
WebCore/platform/GraphicsContext.h
WebCore/platform/cairo/GraphicsContextCairo.cpp
WebCore/platform/cg/GraphicsContextCG.cpp
WebCore/platform/mac/FontData.mm
WebCore/platform/mac/FontMac.mm
WebCore/platform/win/FontWin.cpp
WebCore/rendering/InlineTextBox.cpp
WebCore/rendering/render_line.cpp

index 52de274..c8b953a 100644 (file)
@@ -1,3 +1,28 @@
+2006-05-11  David Hyatt  <hyatt@apple.com>
+
+        Remove drawLineForText from the Font API.  Implement it natively in
+        the two GraphicsContexts (CG and Cairo) instead.
+
+        Reviewed by maciej
+
+        * platform/Font.h:
+        * platform/FontData.h:
+        * platform/GraphicsContext.cpp:
+        * platform/GraphicsContext.h:
+        * platform/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::drawLineForText):
+        * platform/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::drawLineForText):
+        * platform/mac/FontData.mm:
+        * platform/mac/FontMac.mm:
+        * platform/win/FontWin.cpp:
+        (WebCore::Font::drawLineForText):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paintDecoration):
+        (WebCore::InlineTextBox::paintMarkedTextUnderline):
+        * rendering/render_line.cpp:
+        (WebCore::InlineFlowBox::paintDecorations):
+
 2006-05-11  Steve Falkenburg  <sfalken@apple.com>
 
         Reviewed by eric.
index 480140b..2e77d7f 100644 (file)
@@ -110,7 +110,6 @@ public:
 
     void drawText(GraphicsContext*, const TextRun&, const IntPoint&, int tabWidth, int xpos,
                   int toAdd, TextDirection, bool visuallyOrdered) const;
-    void drawLineForText(GraphicsContext*, const IntPoint&, int yOffset, int width) const;
     void drawLineForMisspelling(GraphicsContext*, const IntPoint&, int width) const;
     int misspellingLineThickness(GraphicsContext*) const;
 
index 6ce379f..81b835e 100644 (file)
@@ -112,7 +112,6 @@ public:
     // drawing
     void drawRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry);
     FloatRect selectionRectForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry);
-    void drawLineForCharacters(const FloatPoint& point, float yOffset, int width, const Color& color, float thickness);
     void drawLineForMisspelling(const FloatPoint& point, int width);
     int misspellingLineThickness() const { return 3; }
 
index 7c080a4..a1be8cb 100644 (file)
@@ -210,15 +210,6 @@ void GraphicsContext::drawHighlightForText(const TextRun& run, const IntPoint& p
     fillRect(font().selectionRectForText(run, point, h, tabWidth, xpos, toAdd, d == RTL, visuallyOrdered), backgroundColor);
 }
 
-void GraphicsContext::drawLineForText(const IntPoint& point, int yOffset, int width)
-{
-    if (paintingDisabled())
-        return;
-
-    return font().drawLineForText(this, point, yOffset, width);
-}
-
-
 void GraphicsContext::drawLineForMisspelling(const IntPoint& point, int width)
 {
     if (paintingDisabled())
index bdf7946..ed5d16c 100644 (file)
@@ -114,7 +114,7 @@ namespace WebCore {
                                   int tabWidth, int xpos, int toAdd, TextDirection, bool visuallyOrdered, const Color& backgroundColor);
                                   
         
-        void drawLineForText(const IntPoint&, int yOffset, int width);
+        void drawLineForText(const IntPoint&, int yOffset, int width, bool printing);
         void drawLineForMisspelling(const IntPoint&, int width);
         int misspellingLineThickness();
 
index 12d0e7c..9865c27 100644 (file)
@@ -394,4 +394,14 @@ void GraphicsContext::clearFocusRingClip()
 {
 }
 
+void GraphicsContext::drawLineForText(const IntPoint& point, int yOffset, int width, bool printing)
+{
+    if (paintingDisabled())
+        return;
+
+    IntPoint origin = point + IntSize(0, yOffset + 1);
+    IntPoint endPoint = origin + IntSize(width, 0);
+    drawLine(origin, endPoint);
+}
+
 }
index 62d8f92..fdcb96c 100644 (file)
@@ -539,4 +539,65 @@ void GraphicsContext::translate(const FloatSize& size)
     CGContextTranslateCTM(platformContext(), size.width(), size.height());
 }
 
+void GraphicsContext::drawLineForText(const IntPoint& point, int yOffset, int width, bool printing)
+{
+    if (paintingDisabled())
+        return;
+    
+    // Note: This function assumes that point.x and point.y are integers (and that's currently always the case).
+    float x = point.x();
+    float y = point.y() + yOffset;
+
+    // Leave 1.0 in user space between the baseline of the text and the top of the underline.
+    // FIXME: Is this the right distance for space above the underline? Even for thick underlines on large sized text?
+    y += 1;
+
+    float thickness = pen().width();
+    if (printing) {
+        // When printing, use a minimum thickness of 0.5 in user space.
+        // See bugzilla bug 4255 for details of why 0.5 is the right minimum thickness to use while printing.
+        if (thickness < 0.5)
+            thickness = 0.5;
+
+        // When printing, use antialiasing instead of putting things on integral pixel boundaries.
+    } else {
+        // On screen, use a minimum thickness of 1.0 in user space (later rounded to an integral number in device space).
+        if (thickness < 1)
+            thickness = 1;
+
+        // On screen, round all parameters to integer boundaries in device space.
+        CGRect lineRect = CGContextConvertRectToDeviceSpace(platformContext(), CGRectMake(x, y, width, thickness));
+        lineRect.origin.x = roundf(lineRect.origin.x);
+        lineRect.origin.y = roundf(lineRect.origin.y);
+        lineRect.size.width = roundf(lineRect.size.width);
+        lineRect.size.height = roundf(lineRect.size.height);
+        if (lineRect.size.height == 0) // don't let thickness round down to 0 pixels
+            lineRect.size.height = 1;
+        lineRect = CGContextConvertRectToUserSpace(platformContext(), lineRect);
+        x = lineRect.origin.x;
+        y = lineRect.origin.y;
+        width = (int)(lineRect.size.width);
+        thickness = lineRect.size.height;
+    }
+
+    // FIXME: How about using a rectangle fill instead of drawing a line?
+    CGContextSaveGState(platformContext());
+
+    setCGStrokeColor(platformContext(), pen().color());
+    
+    CGContextSetLineWidth(platformContext(), thickness);
+    CGContextSetShouldAntialias(platformContext(), printing);
+
+    float halfThickness = thickness / 2;
+
+    CGPoint linePoints[2];
+    linePoints[0].x = x + halfThickness;
+    linePoints[0].y = y + halfThickness;
+    linePoints[1].x = x + width - halfThickness;
+    linePoints[1].y = y + halfThickness;
+    CGContextStrokeLineSegments(platformContext(), linePoints, 2);
+
+    CGContextRestoreGState(platformContext());
+}
+
 }
index dedaeea..3a382d7 100644 (file)
@@ -512,76 +512,6 @@ float FontData::floatWidthForRun(const WebCoreTextRun* run, const WebCoreTextSty
     return CG_floatWidthForRun(this, run, style, 0, 0, 0, 0, 0);
 }
 
-static void drawHorizontalLine(float x, float y, float width, NSColor *color, float thickness, bool shouldAntialias)
-{
-    NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
-    CGContextRef cgContext = (CGContextRef)[graphicsContext graphicsPort];
-
-    CGContextSaveGState(cgContext);
-
-    [color set];
-    CGContextSetLineWidth(cgContext, thickness);
-    CGContextSetShouldAntialias(cgContext, shouldAntialias);
-
-    float halfThickness = thickness / 2;
-
-    CGPoint linePoints[2];
-    linePoints[0].x = x + halfThickness;
-    linePoints[0].y = y + halfThickness;
-    linePoints[1].x = x + width - halfThickness;
-    linePoints[1].y = y + halfThickness;
-    CGContextStrokeLineSegments(cgContext, linePoints, 2);
-
-    CGContextRestoreGState(cgContext);
-}
-
-void FontData::drawLineForCharacters(const FloatPoint& point, float yOffset, int width, const Color& color, float thickness)
-{
-    // Note: This function assumes that point.x and point.y are integers (and that's currently always the case).
-
-    NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext];
-    CGContextRef cgContext = (CGContextRef)[graphicsContext graphicsPort];
-
-    bool printing = ![graphicsContext isDrawingToScreen];
-
-    float x = point.x();
-    float y = point.y() + yOffset;
-
-    // Leave 1.0 in user space between the baseline of the text and the top of the underline.
-    // FIXME: Is this the right distance for space above the underline? Even for thick underlines on large sized text?
-    y += 1;
-
-    if (printing) {
-        // When printing, use a minimum thickness of 0.5 in user space.
-        // See bugzilla bug 4255 for details of why 0.5 is the right minimum thickness to use while printing.
-        if (thickness < 0.5)
-            thickness = 0.5;
-
-        // When printing, use antialiasing instead of putting things on integral pixel boundaries.
-    } else {
-        // On screen, use a minimum thickness of 1.0 in user space (later rounded to an integral number in device space).
-        if (thickness < 1)
-            thickness = 1;
-
-        // On screen, round all parameters to integer boundaries in device space.
-        CGRect lineRect = CGContextConvertRectToDeviceSpace(cgContext, CGRectMake(x, y, width, thickness));
-        lineRect.origin.x = roundf(lineRect.origin.x);
-        lineRect.origin.y = roundf(lineRect.origin.y);
-        lineRect.size.width = roundf(lineRect.size.width);
-        lineRect.size.height = roundf(lineRect.size.height);
-        if (lineRect.size.height == 0) // don't let thickness round down to 0 pixels
-            lineRect.size.height = 1;
-        lineRect = CGContextConvertRectToUserSpace(cgContext, lineRect);
-        x = lineRect.origin.x;
-        y = lineRect.origin.y;
-        width = (int)(lineRect.size.width);
-        thickness = lineRect.size.height;
-    }
-
-    // FIXME: How about using a rectangle fill instead of drawing a line?
-    drawHorizontalLine(x, y, width, nsColor(color), thickness, printing);
-}
-
 FloatRect FontData::selectionRectForRun(const WebCoreTextRun* run, const WebCoreTextStyle* style, const WebCoreTextGeometry* geometry)
 {
     if (shouldUseATSU(run))
index b063f28..2934f9f 100644 (file)
@@ -544,11 +544,6 @@ void Font::drawComplexText(GraphicsContext* graphicsContext, const TextRun& run,
         delete []adjustedRun.characters();
 }
 
-void Font::drawLineForText(GraphicsContext* context, const IntPoint& point, int yOffset, int width) const
-{
-    m_fontList->primaryFont(fontDescription())->drawLineForCharacters(point, yOffset, width, context->pen().color(), context->pen().width());
-}
-
 void Font::drawLineForMisspelling(GraphicsContext* context, const IntPoint& point, int width) const
 {
     m_fontList->primaryFont(fontDescription())->drawLineForMisspelling(point, width);
index d523882..e54063d 100644 (file)
@@ -261,9 +261,6 @@ int Font::checkSelectionPoint(const TextRun& run, int toAdd, int tabWidth, int x
 
 void Font::drawLineForText(GraphicsContext* context, const IntPoint& point, int yOffset, int width) const
 {
-    IntPoint origin = point + IntSize(0, yOffset + 1);
-    IntPoint endPoint = origin + IntSize(width, 0);
-    const_cast<GraphicsContext*>(context)->drawLine(origin, endPoint);
 }
 
 void Font::drawLineForMisspelling(GraphicsContext* context, const IntPoint& point, int width) const
index 249959f..bf9b4c1 100644 (file)
@@ -493,17 +493,18 @@ void InlineTextBox::paintDecoration(GraphicsContext *pt, int _tx, int _ty, int d
     object()->getTextDecorationColors(deco, underline, overline, linethrough, true);
     
     // Use a special function for underlines to get the positioning exactly right.
+    bool isPrinting = textObject()->document()->printing();
     if (deco & UNDERLINE) {
         pt->setPen(underline);
-        pt->drawLineForText(IntPoint(_tx, _ty), m_baseline, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), m_baseline, width, isPrinting);
     }
     if (deco & OVERLINE) {
         pt->setPen(overline);
-        pt->drawLineForText(IntPoint(_tx, _ty), 0, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), 0, width, isPrinting);
     }
     if (deco & LINE_THROUGH) {
         pt->setPen(linethrough);
-        pt->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, width);
+        pt->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, width, isPrinting);
     }
 }
 
@@ -648,7 +649,7 @@ void InlineTextBox::paintMarkedTextUnderline(GraphicsContext* pt, int _tx, int _
 
     int underlineOffset = m_height - 3;
     pt->setPen(Pen(underline.color, underline.thick ? 2 : 0));
-    pt->drawLineForText(IntPoint(_tx + start, _ty), underlineOffset, width);
+    pt->drawLineForText(IntPoint(_tx + start, _ty), underlineOffset, width, textObject()->document()->printing());
 }
 
 int InlineTextBox::caretMinOffset() const
index 7934000..9b14d4d 100644 (file)
@@ -988,17 +988,18 @@ void InlineFlowBox::paintDecorations(RenderObject::PaintInfo& i, int _tx, int _t
         if (styleToUse->font() != p->font())
             p->setFont(styleToUse->font());
 
+        bool isPrinting = object()->document()->printing();
         if (deco & UNDERLINE && !paintedChildren) {
             p->setPen(underline);
-            p->drawLineForText(IntPoint(_tx, _ty), m_baseline, w);
+            p->drawLineForText(IntPoint(_tx, _ty), m_baseline, w, isPrinting);
         }
         if (deco & OVERLINE && !paintedChildren) {
             p->setPen(overline);
-            p->drawLineForText(IntPoint(_tx, _ty), 0, w);
+            p->drawLineForText(IntPoint(_tx, _ty), 0, w, isPrinting);
         }
         if (deco & LINE_THROUGH && paintedChildren) {
             p->setPen(linethrough);
-            p->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, w);
+            p->drawLineForText(IntPoint(_tx, _ty), 2*m_baseline/3, w, isPrinting);
         }
 
         if (setShadow)