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, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 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 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 | 2074 |
2075 serializedFont.append(' '); | 2075 serializedFont.append(' '); |
2076 serializedFont.append(family); | 2076 serializedFont.append(family); |
2077 } | 2077 } |
2078 | 2078 |
2079 return serializedFont.toString(); | 2079 return serializedFont.toString(); |
2080 } | 2080 } |
2081 | 2081 |
2082 void CanvasRenderingContext2D::setFont(const String& newFont) | 2082 void CanvasRenderingContext2D::setFont(const String& newFont) |
2083 { | 2083 { |
| 2084 // The style resolution required for rendering text is not available in fram
e-less documents. |
| 2085 if (!canvas()->document().frame()) |
| 2086 return; |
| 2087 |
2084 MutableStylePropertyMap::iterator i = m_fetchedFonts.find(newFont); | 2088 MutableStylePropertyMap::iterator i = m_fetchedFonts.find(newFont); |
2085 RefPtr<MutableStylePropertySet> parsedStyle = i != m_fetchedFonts.end() ? i-
>value : nullptr; | 2089 RefPtr<MutableStylePropertySet> parsedStyle = i != m_fetchedFonts.end() ? i-
>value : nullptr; |
2086 | 2090 |
2087 if (!parsedStyle) { | 2091 if (!parsedStyle) { |
2088 parsedStyle = MutableStylePropertySet::create(); | 2092 parsedStyle = MutableStylePropertySet::create(); |
2089 CSSParserMode mode = m_usesCSSCompatibilityParseMode ? HTMLQuirksMode :
HTMLStandardMode; | 2093 CSSParserMode mode = m_usesCSSCompatibilityParseMode ? HTMLQuirksMode :
HTMLStandardMode; |
2090 BisonCSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont,
true, mode, 0); | 2094 BisonCSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont,
true, mode, 0); |
2091 m_fetchedFonts.add(newFont, parsedStyle); | 2095 m_fetchedFonts.add(newFont, parsedStyle); |
2092 } | 2096 } |
2093 if (parsedStyle->isEmpty()) | 2097 if (parsedStyle->isEmpty()) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 drawTextInternal(text, x, y, false); | 2196 drawTextInternal(text, x, y, false); |
2193 } | 2197 } |
2194 | 2198 |
2195 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
float maxWidth) | 2199 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
float maxWidth) |
2196 { | 2200 { |
2197 drawTextInternal(text, x, y, false, maxWidth, true); | 2201 drawTextInternal(text, x, y, false, maxWidth, true); |
2198 } | 2202 } |
2199 | 2203 |
2200 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text
) | 2204 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text
) |
2201 { | 2205 { |
| 2206 RefPtr<TextMetrics> metrics = TextMetrics::create(); |
| 2207 |
| 2208 // The style resolution required for rendering text is not available in fram
e-less documents. |
| 2209 if (!canvas()->document().frame()) |
| 2210 return metrics.release(); |
| 2211 |
2202 FontCachePurgePreventer fontCachePurgePreventer; | 2212 FontCachePurgePreventer fontCachePurgePreventer; |
2203 RefPtr<TextMetrics> metrics = TextMetrics::create(); | |
2204 canvas()->document().updateStyleIfNeeded(); | 2213 canvas()->document().updateStyleIfNeeded(); |
2205 metrics->setWidth(accessFont().width(TextRun(text))); | 2214 metrics->setWidth(accessFont().width(TextRun(text))); |
2206 return metrics.release(); | 2215 return metrics.release(); |
2207 } | 2216 } |
2208 | 2217 |
2209 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt
r matchFunction, const String& replacement) | 2218 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt
r matchFunction, const String& replacement) |
2210 { | 2219 { |
2211 const size_t replacementLength = replacement.length(); | 2220 const size_t replacementLength = replacement.length(); |
2212 size_t index = 0; | 2221 size_t index = 0; |
2213 while ((index = text.find(matchFunction, index)) != kNotFound) { | 2222 while ((index = text.find(matchFunction, index)) != kNotFound) { |
2214 text.replace(index, 1, replacement); | 2223 text.replace(index, 1, replacement); |
2215 index += replacementLength; | 2224 index += replacementLength; |
2216 } | 2225 } |
2217 } | 2226 } |
2218 | 2227 |
2219 void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
at y, bool fill, float maxWidth, bool useMaxWidth) | 2228 void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
at y, bool fill, float maxWidth, bool useMaxWidth) |
2220 { | 2229 { |
| 2230 // The style resolution required for rendering text is not available in fram
e-less documents. |
| 2231 if (!canvas()->document().frame()) |
| 2232 return; |
| 2233 |
2221 // accessFont needs the style to be up to date, but updating style can cause
script to run, | 2234 // accessFont needs the style to be up to date, but updating style can cause
script to run, |
2222 // (e.g. due to autofocus) which can free the GraphicsContext, so update sty
le before grabbing | 2235 // (e.g. due to autofocus) which can free the GraphicsContext, so update sty
le before grabbing |
2223 // the GraphicsContext. | 2236 // the GraphicsContext. |
2224 canvas()->document().updateStyleIfNeeded(); | 2237 canvas()->document().updateStyleIfNeeded(); |
2225 | 2238 |
2226 GraphicsContext* c = drawingContext(); | 2239 GraphicsContext* c = drawingContext(); |
2227 if (!c) | 2240 if (!c) |
2228 return; | 2241 return; |
2229 if (!state().m_invertibleCTM) | 2242 if (!state().m_invertibleCTM) |
2230 return; | 2243 return; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 const int focusRingWidth = 5; | 2482 const int focusRingWidth = 5; |
2470 const int focusRingOutline = 0; | 2483 const int focusRingOutline = 0; |
2471 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2484 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2472 | 2485 |
2473 c->restore(); | 2486 c->restore(); |
2474 | 2487 |
2475 didDraw(dirtyRect); | 2488 didDraw(dirtyRect); |
2476 } | 2489 } |
2477 | 2490 |
2478 } // namespace WebCore | 2491 } // namespace WebCore |
OLD | NEW |