| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 float WebFontImpl::xHeight() const | 86 float WebFontImpl::xHeight() const |
| 87 { | 87 { |
| 88 return m_font.fontMetrics().xHeight(); | 88 return m_font.fontMetrics().xHeight(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void WebFontImpl::drawText(WebCanvas* canvas, const WebTextRun& run, const WebFl
oatPoint& leftBaseline, | 91 void WebFontImpl::drawText(WebCanvas* canvas, const WebTextRun& run, const WebFl
oatPoint& leftBaseline, |
| 92 WebColor color, const WebRect& clip, bool canvasIsOpa
que, | 92 WebColor color, const WebRect& clip, bool canvasIsOpa
que, |
| 93 int from, int to) const | 93 int from, int to) const |
| 94 { | 94 { |
| 95 FontCachePurgePreventer fontCachePurgePreventer; | 95 FontCachePurgePreventer fontCachePurgePreventer; |
| 96 WebCore::FloatRect textClipRect(clip); |
| 97 TextRunPaintInfo runInfo(run); |
| 98 runInfo.from = from; |
| 99 runInfo.to = to; |
| 100 runInfo.bounds = textClipRect; |
| 96 GraphicsContext gc(canvas); | 101 GraphicsContext gc(canvas); |
| 97 | 102 |
| 98 gc.save(); | 103 gc.save(); |
| 99 gc.setShouldSmoothFonts(canvasIsOpaque); | 104 gc.setShouldSmoothFonts(canvasIsOpaque); |
| 100 gc.setFillColor(color, ColorSpaceDeviceRGB); | 105 gc.setFillColor(color, ColorSpaceDeviceRGB); |
| 101 gc.clip(WebCore::FloatRect(clip)); | 106 gc.clip(textClipRect); |
| 102 m_font.drawText(&gc, run, leftBaseline, from, to); | 107 m_font.drawText(&gc, runInfo, leftBaseline); |
| 103 gc.restore(); | 108 gc.restore(); |
| 104 | 109 |
| 105 #if defined(WIN32) | 110 #if defined(WIN32) |
| 106 if (canvasIsOpaque && SkColorGetA(color) == 0xFF && !canvas->isDrawingToLaye
r()) { | 111 if (canvasIsOpaque && SkColorGetA(color) == 0xFF && !canvas->isDrawingToLaye
r()) { |
| 107 // The text drawing logic on Windows ignores the alpha component | 112 // The text drawing logic on Windows ignores the alpha component |
| 108 // intentionally, for performance reasons. | 113 // intentionally, for performance reasons. |
| 109 // (Please see TransparencyAwareFontPainter::initializeForGDI in | 114 // (Please see TransparencyAwareFontPainter::initializeForGDI in |
| 110 // FontChromiumWin.cpp.) | 115 // FontChromiumWin.cpp.) |
| 111 const SkBitmap& bitmap = canvas->getTopDevice()->accessBitmap(true); | 116 const SkBitmap& bitmap = canvas->getTopDevice()->accessBitmap(true); |
| 112 IntRect textBounds = estimateTextBounds(run, leftBaseline); | 117 IntRect textBounds = estimateTextBounds(run, leftBaseline); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 FontCachePurgePreventer fontCachePurgePreventer; | 149 FontCachePurgePreventer fontCachePurgePreventer; |
| 145 int totalWidth = m_font.width(run, 0); | 150 int totalWidth = m_font.width(run, 0); |
| 146 const WebCore::FontMetrics& fontMetrics = m_font.fontMetrics(); | 151 const WebCore::FontMetrics& fontMetrics = m_font.fontMetrics(); |
| 147 return WebRect(leftBaseline.x - (fontMetrics.ascent() + fontMetrics.descent(
)) / 2, | 152 return WebRect(leftBaseline.x - (fontMetrics.ascent() + fontMetrics.descent(
)) / 2, |
| 148 leftBaseline.y - fontMetrics.ascent() - fontMetrics.lineGap()
, | 153 leftBaseline.y - fontMetrics.ascent() - fontMetrics.lineGap()
, |
| 149 totalWidth + fontMetrics.ascent() + fontMetrics.descent(), | 154 totalWidth + fontMetrics.ascent() + fontMetrics.descent(), |
| 150 fontMetrics.lineSpacing()); | 155 fontMetrics.lineSpacing()); |
| 151 } | 156 } |
| 152 | 157 |
| 153 } // namespace WebKit | 158 } // namespace WebKit |
| OLD | NEW |