Chromium Code Reviews| 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 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2058 // between the EM box's top and bottom and the font's ascend and desc end | 2058 // between the EM box's top and bottom and the font's ascend and desc end |
| 2059 metrics->setEmHeightAscent(0); | 2059 metrics->setEmHeightAscent(0); |
| 2060 metrics->setEmHeightDescent(0); | 2060 metrics->setEmHeightDescent(0); |
| 2061 | 2061 |
| 2062 metrics->setHangingBaseline(-0.8f * ascent + baselineY); | 2062 metrics->setHangingBaseline(-0.8f * ascent + baselineY); |
| 2063 metrics->setAlphabeticBaseline(baselineY); | 2063 metrics->setAlphabeticBaseline(baselineY); |
| 2064 metrics->setIdeographicBaseline(descent + baselineY); | 2064 metrics->setIdeographicBaseline(descent + baselineY); |
| 2065 return metrics.release(); | 2065 return metrics.release(); |
| 2066 } | 2066 } |
| 2067 | 2067 |
| 2068 static inline bool isSpaceCharacters(UChar c) | |
| 2069 { | |
| 2070 // According to specification all space characters should be replaced with 0 x0020 space character. | |
| 2071 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-el ement.html#text-preparation-algorithm | |
| 2072 // The space characters according to specification are : U+0020, U+0009, U+0 00A, U+000C, and U+000D. | |
| 2073 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-micros yntaxes.html#space-character | |
| 2074 // This function returns true for 0x000B also, so that this is backward comp atible. | |
| 2075 // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.space.co llapse.space.html will fail | |
| 2076 return c == 0x0009 || c == 0x000A || c == 0x000B || c == 0x000C || c == 0x00 0D; | |
| 2077 } | |
| 2078 | |
| 2068 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt r matchFunction, const String& replacement) | 2079 static void replaceCharacterInString(String& text, WTF::CharacterMatchFunctionPt r matchFunction, const String& replacement) |
| 2069 { | 2080 { |
| 2070 const size_t replacementLength = replacement.length(); | 2081 const size_t replacementLength = replacement.length(); |
| 2071 size_t index = 0; | 2082 size_t index = 0; |
| 2072 while ((index = text.find(matchFunction, index)) != kNotFound) { | 2083 while ((index = text.find(matchFunction, index)) != kNotFound) { |
| 2073 text.replace(index, 1, replacement); | 2084 text.replace(index, 1, replacement); |
| 2074 index += replacementLength; | 2085 index += replacementLength; |
| 2075 } | 2086 } |
| 2076 } | 2087 } |
| 2077 | 2088 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2104 gradient = c->fillGradient(); | 2115 gradient = c->fillGradient(); |
| 2105 if (fill && gradient && gradient->isZeroSize()) | 2116 if (fill && gradient && gradient->isZeroSize()) |
| 2106 return; | 2117 return; |
| 2107 | 2118 |
| 2108 FontCachePurgePreventer fontCachePurgePreventer; | 2119 FontCachePurgePreventer fontCachePurgePreventer; |
| 2109 | 2120 |
| 2110 const Font& font = accessFont(); | 2121 const Font& font = accessFont(); |
| 2111 const FontMetrics& fontMetrics = font.fontMetrics(); | 2122 const FontMetrics& fontMetrics = font.fontMetrics(); |
| 2112 // According to spec, all the space characters must be replaced with U+0020 SPACE characters. | 2123 // According to spec, all the space characters must be replaced with U+0020 SPACE characters. |
| 2113 String normalizedText = text; | 2124 String normalizedText = text; |
| 2114 replaceCharacterInString(normalizedText, isSpaceOrNewline, " "); | 2125 replaceCharacterInString(normalizedText, isSpaceCharacters, " "); |
|
Justin Novosad
2014/05/20 18:29:50
What exactly is wrong with isSpaceOrNewline? Why a
| |
| 2115 | 2126 |
| 2116 // FIXME: Need to turn off font smoothing. | 2127 // FIXME: Need to turn off font smoothing. |
| 2117 | 2128 |
| 2118 RenderStyle* computedStyle = canvas()->computedStyle(); | 2129 RenderStyle* computedStyle = canvas()->computedStyle(); |
| 2119 TextDirection direction = computedStyle ? computedStyle->direction() : LTR; | 2130 TextDirection direction = computedStyle ? computedStyle->direction() : LTR; |
| 2120 bool isRTL = direction == RTL; | 2131 bool isRTL = direction == RTL; |
| 2121 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f alse; | 2132 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : f alse; |
| 2122 | 2133 |
| 2123 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direc tion, override, true, TextRun::NoRounding); | 2134 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direc tion, override, true, TextRun::NoRounding); |
| 2124 // Draw the item text at the correct point. | 2135 // Draw the item text at the correct point. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2370 c->setAlphaAsFloat(1.0); | 2381 c->setAlphaAsFloat(1.0); |
| 2371 c->clearShadow(); | 2382 c->clearShadow(); |
| 2372 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2383 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
| 2373 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2384 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
| 2374 c->restore(); | 2385 c->restore(); |
| 2375 | 2386 |
| 2376 didDraw(dirtyRect); | 2387 didDraw(dirtyRect); |
| 2377 } | 2388 } |
| 2378 | 2389 |
| 2379 } // namespace WebCore | 2390 } // namespace WebCore |
| OLD | NEW |