OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 } | 2093 } |
2094 | 2094 |
2095 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
float maxWidth) | 2095 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
float maxWidth) |
2096 { | 2096 { |
2097 drawTextInternal(text, x, y, false, maxWidth, true); | 2097 drawTextInternal(text, x, y, false, maxWidth, true); |
2098 } | 2098 } |
2099 | 2099 |
2100 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text
) | 2100 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text
) |
2101 { | 2101 { |
2102 FontCachePurgePreventer fontCachePurgePreventer; | 2102 FontCachePurgePreventer fontCachePurgePreventer; |
2103 | |
2104 RefPtr<TextMetrics> metrics = TextMetrics::create(); | 2103 RefPtr<TextMetrics> metrics = TextMetrics::create(); |
2105 | |
2106 #if PLATFORM(QT) | |
2107 // We always use complex text shaping since it can't be turned off for QPain
terPath::addText(). | |
2108 Font::CodePath oldCodePath = Font::codePath(); | |
2109 Font::setCodePath(Font::Complex); | |
2110 #endif | |
2111 | |
2112 metrics->setWidth(accessFont().width(TextRun(text.characters(), text.length(
)))); | 2104 metrics->setWidth(accessFont().width(TextRun(text.characters(), text.length(
)))); |
2113 | |
2114 #if PLATFORM(QT) | |
2115 Font::setCodePath(oldCodePath); | |
2116 #endif | |
2117 | |
2118 return metrics.release(); | 2105 return metrics.release(); |
2119 } | 2106 } |
2120 | 2107 |
2121 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt
r matchFunction, const String& replacement) | 2108 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt
r matchFunction, const String& replacement) |
2122 { | 2109 { |
2123 const size_t replacementLength = replacement.length(); | 2110 const size_t replacementLength = replacement.length(); |
2124 size_t index = 0; | 2111 size_t index = 0; |
2125 while ((index = text.find(matchFunction, index)) != notFound) { | 2112 while ((index = text.find(matchFunction, index)) != notFound) { |
2126 text.replace(index, 1, replacement); | 2113 text.replace(index, 1, replacement); |
2127 index += replacementLength; | 2114 index += replacementLength; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 | 2230 |
2244 GraphicsContextStateSaver stateSaver(*c); | 2231 GraphicsContextStateSaver stateSaver(*c); |
2245 c->clipToImageBuffer(maskImage.get(), maskRect); | 2232 c->clipToImageBuffer(maskImage.get(), maskRect); |
2246 drawStyle->applyFillColor(c); | 2233 drawStyle->applyFillColor(c); |
2247 c->fillRect(maskRect); | 2234 c->fillRect(maskRect); |
2248 return; | 2235 return; |
2249 } | 2236 } |
2250 #endif | 2237 #endif |
2251 | 2238 |
2252 c->setTextDrawingMode(fill ? TextModeFill : TextModeStroke); | 2239 c->setTextDrawingMode(fill ? TextModeFill : TextModeStroke); |
2253 | |
2254 #if PLATFORM(QT) | |
2255 // We always use complex text shaping since it can't be turned off for QPain
terPath::addText(). | |
2256 Font::CodePath oldCodePath = Font::codePath(); | |
2257 Font::setCodePath(Font::Complex); | |
2258 #endif | |
2259 | |
2260 if (useMaxWidth) { | 2240 if (useMaxWidth) { |
2261 GraphicsContextStateSaver stateSaver(*c); | 2241 GraphicsContextStateSaver stateSaver(*c); |
2262 c->translate(location.x(), location.y()); | 2242 c->translate(location.x(), location.y()); |
2263 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o
p) still work. | 2243 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o
p) still work. |
2264 c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1)); | 2244 c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1)); |
2265 c->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFont
NotReady); | 2245 c->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFont
NotReady); |
2266 } else | 2246 } else |
2267 c->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady
); | 2247 c->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady
); |
2268 | 2248 |
2269 didDraw(textRect); | 2249 didDraw(textRect); |
2270 | |
2271 #if PLATFORM(QT) | |
2272 Font::setCodePath(oldCodePath); | |
2273 #endif | |
2274 } | 2250 } |
2275 | 2251 |
2276 void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const | 2252 void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const |
2277 { | 2253 { |
2278 // Fast approximation of the stroke's bounding rect. | 2254 // Fast approximation of the stroke's bounding rect. |
2279 // This yields a slightly oversized rect but is very fast | 2255 // This yields a slightly oversized rect but is very fast |
2280 // compared to Path::strokeBoundingRect(). | 2256 // compared to Path::strokeBoundingRect(). |
2281 static const float root2 = sqrtf(2); | 2257 static const float root2 = sqrtf(2); |
2282 float delta = state().m_lineWidth / 2; | 2258 float delta = state().m_lineWidth / 2; |
2283 if (state().m_lineJoin == MiterJoin) | 2259 if (state().m_lineJoin == MiterJoin) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 return; | 2291 return; |
2316 | 2292 |
2317 realizeSaves(); | 2293 realizeSaves(); |
2318 modifiableState().m_imageSmoothingEnabled = enabled; | 2294 modifiableState().m_imageSmoothingEnabled = enabled; |
2319 GraphicsContext* c = drawingContext(); | 2295 GraphicsContext* c = drawingContext(); |
2320 if (c) | 2296 if (c) |
2321 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality :
InterpolationNone); | 2297 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality :
InterpolationNone); |
2322 } | 2298 } |
2323 | 2299 |
2324 } // namespace WebCore | 2300 } // namespace WebCore |
OLD | NEW |