Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp |
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
index 68441e75ec978269515f7c29620e4b80a70b64b0..0e6857286b4b217fb400483bc274f61c0b4d8bce 100644 |
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp |
@@ -75,6 +75,9 @@ namespace blink { |
static const int defaultFontSize = 10; |
static const char defaultFontFamily[] = "sans-serif"; |
static const char defaultFont[] = "10px sans-serif"; |
+static const char inherit[] = "inherit"; |
+static const char rtl[] = "rtl"; |
+static const char ltr[] = "ltr"; |
static const double TryRestoreContextInterval = 0.5; |
static const unsigned MaxTryRestoreContextAttempts = 4; |
@@ -257,6 +260,7 @@ CanvasRenderingContext2D::State::State() |
, m_imageSmoothingEnabled(true) |
, m_textAlign(StartTextAlign) |
, m_textBaseline(AlphabeticTextBaseline) |
+ , m_direction(DirectionInherit) |
, m_unparsedFont(defaultFont) |
, m_realizedFont(false) |
, m_hasClip(false) |
@@ -286,6 +290,7 @@ CanvasRenderingContext2D::State::State(const State& other) |
, m_imageSmoothingEnabled(other.m_imageSmoothingEnabled) |
, m_textAlign(other.m_textAlign) |
, m_textBaseline(other.m_textBaseline) |
+ , m_direction(other.m_direction) |
, m_unparsedFont(other.m_unparsedFont) |
, m_font(other.m_font) |
, m_realizedFont(other.m_realizedFont) |
@@ -325,6 +330,7 @@ CanvasRenderingContext2D::State& CanvasRenderingContext2D::State::operator=(cons |
m_imageSmoothingEnabled = other.m_imageSmoothingEnabled; |
m_textAlign = other.m_textAlign; |
m_textBaseline = other.m_textBaseline; |
+ m_direction = other.m_direction; |
m_unparsedFont = other.m_unparsedFont; |
m_font = other.m_font; |
m_realizedFont = other.m_realizedFont; |
@@ -2017,6 +2023,49 @@ void CanvasRenderingContext2D::setTextBaseline(const String& s) |
modifiableState().m_textBaseline = baseline; |
} |
+inline TextDirection CanvasRenderingContext2D::toTextDirection(Direction direction, RenderStyle** computedStyle) const |
+{ |
+ RenderStyle* style = (computedStyle || direction == DirectionInherit) ? canvas()->computedStyle() : nullptr; |
+ if (computedStyle) |
+ *computedStyle = style; |
+ switch (direction) { |
+ case DirectionInherit: |
+ return style ? style->direction() : LTR; |
+ case DirectionRTL: |
+ return RTL; |
+ case DirectionLTR: |
+ return LTR; |
+ } |
+ ASSERT_NOT_REACHED(); |
+ return LTR; |
+} |
+ |
+String CanvasRenderingContext2D::direction() const |
+{ |
+ if (state().m_direction == DirectionInherit) |
+ canvas()->document().updateRenderTreeIfNeeded(); |
+ return toTextDirection(state().m_direction) == RTL ? rtl : ltr; |
+} |
+ |
+void CanvasRenderingContext2D::setDirection(const String& directionString) |
+{ |
+ Direction direction; |
+ if (directionString == inherit) |
+ direction = DirectionInherit; |
+ else if (directionString == rtl) |
+ direction = DirectionRTL; |
+ else if (directionString == ltr) |
+ direction = DirectionLTR; |
+ else |
+ return; |
+ |
+ if (state().m_direction == direction) |
+ return; |
+ |
+ realizeSaves(); |
+ modifiableState().m_direction = direction; |
+} |
+ |
void CanvasRenderingContext2D::fillText(const String& text, float x, float y) |
{ |
drawTextInternal(text, x, y, true); |
@@ -2143,8 +2192,8 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo |
// FIXME: Need to turn off font smoothing. |
- RenderStyle* computedStyle = canvas()->computedStyle(); |
- TextDirection direction = computedStyle ? computedStyle->direction() : LTR; |
+ RenderStyle* computedStyle; |
+ TextDirection direction = toTextDirection(state().m_direction, &computedStyle); |
bool isRTL = direction == RTL; |
bool override = computedStyle ? isOverride(computedStyle->unicodeBidi()) : false; |