Changeset 94961 in webkit


Ignore:
Timestamp:
Sep 12, 2011 10:31:05 AM (13 years ago)
Author:
reed@google.com
Message:

[skia] remove dead code, no functionality change
https://bugs.webkit.org/show_bug.cgi?id=67844

Reviewed by Kenneth Russell.

No new tests. just removing dead-code, existing tests apply

  • platform/graphics/chromium/FontChromiumWin.cpp:

(WebCore::Font::drawGlyphs):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r94958 r94961  
     12011-09-12  Mike Reed  <reed@google.com>
     2
     3        [skia] remove dead code, no functionality change
     4        https://bugs.webkit.org/show_bug.cgi?id=67844
     5
     6        Reviewed by Kenneth Russell.
     7
     8        No new tests. just removing dead-code, existing tests apply
     9
     10        * platform/graphics/chromium/FontChromiumWin.cpp:
     11        (WebCore::Font::drawGlyphs):
     12
    1132011-09-12  Pavel Feldman  <pfeldman@google.com>
    214
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r94589 r94961  
    4040#include "SimpleFontData.h"
    4141#include "SkiaFontWin.h"
    42 #include "SkiaUtils.h"
    43 #include "TransparencyWin.h"
    4442#include "UniscribeHelperTextRun.h"
    45 
    46 #include "skia/ext/platform_canvas.h"
    47 #include "skia/ext/skia_utils_win.h"  // FIXME: remove this dependency.
    4843
    4944#include <windows.h>
    5045
    5146namespace WebCore {
    52 
    53 namespace {
    54 
    55 bool canvasHasMultipleLayers(const SkCanvas* canvas)
    56 {
    57     SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false);
    58     iter.next();  // There is always at least one layer.
    59     return !iter.done();  // There is > 1 layer if the the iterator can stil advance.
    60 }
    61 
    62 class TransparencyAwareFontPainter {
    63 public:
    64     TransparencyAwareFontPainter(GraphicsContext*, const FloatPoint&);
    65 
    66 protected:
    67     virtual IntRect estimateTextBounds() = 0;
    68 
    69     // Use the context from the transparency helper when drawing with GDI. It
    70     // may point to a temporary one.
    71     GraphicsContext* m_graphicsContext;
    72     PlatformGraphicsContext* m_platformContext;
    73 
    74     FloatPoint m_point;
    75 };
    76 
    77 TransparencyAwareFontPainter::TransparencyAwareFontPainter(GraphicsContext* context,
    78                                                            const FloatPoint& point)
    79     : m_graphicsContext(context)
    80     , m_platformContext(context->platformContext())
    81     , m_point(point)
    82 {
    83 }
    84 
    85 // Specialization for simple GlyphBuffer painting.
    86 class TransparencyAwareGlyphPainter : public TransparencyAwareFontPainter {
    87  public:
    88     TransparencyAwareGlyphPainter(GraphicsContext*,
    89                                   const SimpleFontData*,
    90                                   const GlyphBuffer&,
    91                                   int from, int numGlyphs,
    92                                   const FloatPoint&);
    93 
    94     // Draws the partial string of glyphs, starting at |startAdvance| to the
    95     // left of m_point.
    96     void drawGlyphs(int numGlyphs, const WORD* glyphs, const int* advances, float startAdvance) const;
    97 
    98  private:
    99     virtual IntRect estimateTextBounds();
    100 
    101     const SimpleFontData* m_font;
    102     const GlyphBuffer& m_glyphBuffer;
    103     int m_from;
    104     int m_numGlyphs;
    105 };
    106 
    107 TransparencyAwareGlyphPainter::TransparencyAwareGlyphPainter(
    108     GraphicsContext* context,
    109     const SimpleFontData* font,
    110     const GlyphBuffer& glyphBuffer,
    111     int from, int numGlyphs,
    112     const FloatPoint& point)
    113     : TransparencyAwareFontPainter(context, point)
    114     , m_font(font)
    115     , m_glyphBuffer(glyphBuffer)
    116     , m_from(from)
    117     , m_numGlyphs(numGlyphs)
    118 {
    119 }
    120 
    121 // Estimates the bounding box of the given text. This is copied from
    122 // FontCGWin.cpp, it is possible, but a lot more work, to get the precide
    123 // bounds.
    124 IntRect TransparencyAwareGlyphPainter::estimateTextBounds()
    125 {
    126     int totalWidth = 0;
    127     for (int i = 0; i < m_numGlyphs; i++)
    128         totalWidth += lroundf(m_glyphBuffer.advanceAt(m_from + i));
    129 
    130     const FontMetrics& fontMetrics = m_font->fontMetrics();
    131     return IntRect(m_point.x() - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
    132                    m_point.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
    133                    totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
    134                    fontMetrics.lineSpacing());
    135 }
    136 
    137 void TransparencyAwareGlyphPainter::drawGlyphs(int numGlyphs,
    138                                                const WORD* glyphs,
    139                                                const int* advances,
    140                                                float startAdvance) const
    141 {
    142     SkPoint origin = m_point;
    143     origin.fX += SkFloatToScalar(startAdvance);
    144     paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
    145                   numGlyphs, glyphs, advances, 0, &origin);
    146 }
    147 
    148 class TransparencyAwareUniscribePainter : public TransparencyAwareFontPainter {
    149  public:
    150     TransparencyAwareUniscribePainter(GraphicsContext*,
    151                                       const Font*,
    152                                       const TextRun&,
    153                                       int from, int to,
    154                                       const FloatPoint&);
    155 
    156  private:
    157     virtual IntRect estimateTextBounds();
    158 
    159     const Font* m_font;
    160     const TextRun& m_run;
    161     int m_from;
    162     int m_to;
    163 };
    164 
    165 TransparencyAwareUniscribePainter::TransparencyAwareUniscribePainter(
    166     GraphicsContext* context,
    167     const Font* font,
    168     const TextRun& run,
    169     int from, int to,
    170     const FloatPoint& point)
    171     : TransparencyAwareFontPainter(context, point)
    172     , m_font(font)
    173     , m_run(run)
    174     , m_from(from)
    175     , m_to(to)
    176 {
    177 }
    178 
    179 IntRect TransparencyAwareUniscribePainter::estimateTextBounds()
    180 {
    181     // This case really really sucks. There is no convenient way to estimate
    182     // the bounding box. So we run Uniscribe twice. If we find this happens a
    183     // lot, the way to fix it is to make the extra layer after the
    184     // UniscribeHelper has measured the text.
    185     IntPoint intPoint(lroundf(m_point.x()),
    186                       lroundf(m_point.y()));
    187 
    188     UniscribeHelperTextRun state(m_run, *m_font);
    189     int left = lroundf(m_point.x()) + state.characterToX(m_from);
    190     int right = lroundf(m_point.x()) + state.characterToX(m_to);
    191    
    192     // Adjust for RTL script since we just want to know the text bounds.
    193     if (left > right)
    194         std::swap(left, right);
    195 
    196     // This algorithm for estimating how much extra space we need (the text may
    197     // go outside the selection rect) is based roughly on
    198     // TransparencyAwareGlyphPainter::estimateTextBounds above.
    199     const FontMetrics& fontMetrics = m_font->fontMetrics();
    200     return IntRect(left - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
    201                    m_point.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
    202                    (right - left) + fontMetrics.ascent() + fontMetrics.descent(),
    203                    fontMetrics.lineSpacing());
    204 }
    205 
    206 }  // namespace
    20747
    20848bool Font::canReturnFallbackFontsForComplexText()
     
    21656}
    21757
    218 static void drawGlyphsWin(GraphicsContext* graphicsContext,
    219                           const SimpleFontData* font,
    220                           const GlyphBuffer& glyphBuffer,
    221                           int from,
    222                           int numGlyphs,
    223                           const FloatPoint& point) {
    224     TransparencyAwareGlyphPainter painter(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
     58void Font::drawGlyphs(GraphicsContext* graphicsContext,
     59                      const SimpleFontData* font,
     60                      const GlyphBuffer& glyphBuffer,
     61                      int from,
     62                      int numGlyphs,
     63                      const FloatPoint& point) const
     64{
     65    SkColor color = graphicsContext->platformContext()->effectiveFillColor();
     66    unsigned char alpha = SkColorGetA(color);
     67    // Skip 100% transparent text; no need to draw anything.
     68    if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow())
     69        return;
     70
     71    HFONT hfont = font->platformData().hfont();
    22572
    22673    // We draw the glyphs in chunks to avoid having to do a heap allocation for
    227     // the arrays of characters and advances. Since ExtTextOut is the
    228     // lowest-level text output function on Windows, there should be little
    229     // penalty for splitting up the text. On the other hand, the buffer cannot
    230     // be bigger than 4094 or the function will fail.
     74    // the arrays of characters and advances.
    23175    const int kMaxBufferLength = 256;
    23276    Vector<WORD, kMaxBufferLength> glyphs;
     
    265109        }
    266110
    267         painter.drawGlyphs(curLen, &glyphs[0], &advances[0], horizontalOffset - point.x() - currentWidth);
     111        SkPoint origin = point;
     112        origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth);
     113        paintSkiaText(graphicsContext, hfont, curLen, &glyphs[0], &advances[0], 0, &origin);
    268114    }
    269 }
    270 
    271 void Font::drawGlyphs(GraphicsContext* graphicsContext,
    272                       const SimpleFontData* font,
    273                       const GlyphBuffer& glyphBuffer,
    274                       int from,
    275                       int numGlyphs,
    276                       const FloatPoint& point) const
    277 {
    278     SkColor color = graphicsContext->platformContext()->effectiveFillColor();
    279     unsigned char alpha = SkColorGetA(color);
    280     // Skip 100% transparent text; no need to draw anything.
    281     if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow())
    282         return;
    283 
    284     drawGlyphsWin(graphicsContext, font, glyphBuffer, from, numGlyphs, point);
    285115}
    286116
Note: See TracChangeset for help on using the changeset viewer.