Changeset 172723 in webkit
- Timestamp:
- Aug 18, 2014 1:58:26 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r172721 r172723 1 2014-08-18 Vivek Galatage <vivek.vg@samsung.com> 2 3 Implement CanvasRenderingContext2D direction attribute 4 https://bugs.webkit.org/show_bug.cgi?id=135878 5 6 Reviewed by Darin Adler. 7 8 * fast/canvas/canvas-direction-expected.txt: Added. 9 * fast/canvas/canvas-direction.html: Added. 10 1 11 2014-08-18 Benjamin Poulain <benjamin@webkit.org> 2 12 -
trunk/Source/WebCore/ChangeLog
r172721 r172723 1 2014-08-18 Vivek Galatage <vivek.vg@samsung.com> 2 3 Implement CanvasRenderingContext2D direction attribute 4 https://bugs.webkit.org/show_bug.cgi?id=135878 5 6 Reviewed by Darin Adler. 7 8 The attribute, 'direction', represents the text directionality. 9 This is an important attribute for the bi-directional text within the CanvasRenderingContext2D. 10 The allowed set of values are 'rtl', 'ltr' and 'inherit'. 11 12 Specification URL: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting.html#dom-context-2d-direction 13 14 Test: fast/canvas/canvas-direction.html 15 16 * html/canvas/CanvasRenderingContext2D.cpp: 17 (WebCore::inheritedDirection): 18 (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D): 19 (WebCore::CanvasRenderingContext2D::reset): 20 (WebCore::CanvasRenderingContext2D::State::State): 21 (WebCore::CanvasRenderingContext2D::State::operator=): 22 (WebCore::CanvasRenderingContext2D::direction): 23 (WebCore::CanvasRenderingContext2D::setDirection): 24 (WebCore::CanvasRenderingContext2D::drawTextInternal): 25 * html/canvas/CanvasRenderingContext2D.h: 26 * html/canvas/CanvasRenderingContext2D.idl: 27 1 28 2014-08-18 Benjamin Poulain <benjamin@webkit.org> 2 29 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r169534 r172723 105 105 }; 106 106 107 static inline TextDirection inheritedDirection(HTMLCanvasElement& canvasElement) 108 { 109 canvasElement.document().updateStyleIfNeeded(); 110 RenderStyle* computedStyle = canvasElement.computedStyle(); 111 return computedStyle ? computedStyle->direction() : LTR; 112 } 113 107 114 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode) 108 115 : CanvasRenderingContext(canvas) … … 114 121 #endif 115 122 { 123 m_stateStack.first().m_direction = inheritedDirection(*canvas); 116 124 #if !ENABLE(DASHBOARD_SUPPORT) 117 125 ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMode); … … 155 163 unwindStateStack(); 156 164 m_stateStack.resize(1); 157 m_stateStack.first() = State( );165 m_stateStack.first() = State(inheritedDirection(*canvas())); 158 166 m_path.clear(); 159 167 m_unrealizedSaveCount = 0; 160 168 } 161 169 162 CanvasRenderingContext2D::State::State( )170 CanvasRenderingContext2D::State::State(TextDirection direction) 163 171 : m_strokeStyle(Color::black) 164 172 , m_fillStyle(Color::black) … … 177 185 , m_textAlign(StartTextAlign) 178 186 , m_textBaseline(AlphabeticTextBaseline) 187 , m_direction(direction) 179 188 , m_unparsedFont(defaultFont) 180 189 , m_realizedFont(false) … … 204 213 , m_textAlign(other.m_textAlign) 205 214 , m_textBaseline(other.m_textBaseline) 215 , m_direction(other.m_direction) 206 216 , m_unparsedFont(other.m_unparsedFont) 207 217 , m_font(other.m_font) … … 239 249 m_textAlign = other.m_textAlign; 240 250 m_textBaseline = other.m_textBaseline; 251 m_direction = other.m_direction; 241 252 m_unparsedFont = other.m_unparsedFont; 242 253 m_font = other.m_font; … … 2153 2164 } 2154 2165 2166 String CanvasRenderingContext2D::direction() const 2167 { 2168 return state().m_direction == RTL ? ASCIILiteral("rtl") : ASCIILiteral("ltr"); 2169 } 2170 2171 void CanvasRenderingContext2D::setDirection(const String& directionString) 2172 { 2173 TextDirection direction; 2174 if (directionString == "inherit") 2175 direction = inheritedDirection(*canvas()); 2176 else if (directionString == "rtl") 2177 direction = RTL; 2178 else if (directionString == "ltr") 2179 direction = LTR; 2180 else 2181 return; 2182 2183 if (state().m_direction == direction) 2184 return; 2185 2186 realizeSaves(); 2187 modifiableState().m_direction = direction; 2188 } 2189 2155 2190 void CanvasRenderingContext2D::fillText(const String& text, float x, float y) 2156 2191 { … … 2250 2285 2251 2286 RenderStyle* computedStyle = canvas()->computedStyle(); 2252 TextDirection direction = computedStyle ? computedStyle->direction() : LTR; 2253 bool isRTL = direction == RTL; 2287 bool isRTL = state().m_direction == RTL; 2254 2288 bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : false; 2255 2289 2256 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direction, override, true, TextRun::NoRounding);2290 TextRun textRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, state().m_direction, override, true, TextRun::NoRounding); 2257 2291 // Draw the item text at the correct point. 2258 2292 FloatPoint location(x, y); … … 2275 2309 } 2276 2310 2277 float fontWidth = font.width(TextRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, direction, override));2311 float fontWidth = font.width(TextRun(normalizedText, 0, 0, TextRun::AllowTrailingExpansion, state().m_direction, override)); 2278 2312 2279 2313 useMaxWidth = (useMaxWidth && maxWidth < fontWidth); -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
r168476 r172723 39 39 #include "Path.h" 40 40 #include "PlatformLayer.h" 41 #include "TextDirection.h" 41 42 #include <wtf/Vector.h> 42 43 #include <wtf/text/WTFString.h> … … 212 213 void setTextBaseline(const String&); 213 214 215 String direction() const; 216 void setDirection(const String&); 217 214 218 void fillText(const String& text, float x, float y); 215 219 void fillText(const String& text, float x, float y, float maxWidth); … … 226 230 private: 227 231 struct State : FontSelectorClient { 228 State();232 explicit State(TextDirection = LTR); 229 233 virtual ~State(); 230 234 … … 257 261 TextAlign m_textAlign; 258 262 TextBaseline m_textBaseline; 263 TextDirection m_direction; 259 264 260 265 String m_unparsedFont; -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl
r168476 r172723 98 98 attribute DOMString textAlign; 99 99 attribute DOMString textBaseline; 100 attribute DOMString direction; 100 101 101 102 TextMetrics measureText(DOMString text);
Note: See TracChangeset
for help on using the changeset viewer.