[svg] Convert text-anchor to a presentation attribute

https://www.w3.org/TR/SVG11/text.html#TextAnchorProperty

Bug: skia:10840
Change-Id: Iff647b62243c42150e873f06215401b5e33705fd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/330125
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
diff --git a/modules/svg/src/SkSVGText.cpp b/modules/svg/src/SkSVGText.cpp
index 4dde8b8..6cbf5d6 100644
--- a/modules/svg/src/SkSVGText.cpp
+++ b/modules/svg/src/SkSVGText.cpp
@@ -16,22 +16,6 @@
 
 SkSVGText::SkSVGText() : INHERITED(SkSVGTag::kText) {}
 
-void SkSVGText::setX(const SkSVGLength& x) { fX = x; }
-
-void SkSVGText::setY(const SkSVGLength& y) { fY = y; }
-
-void SkSVGText::setText(const SkSVGStringType& text) { fText = text; }
-
-void SkSVGText::setTextAnchor(const SkSVGStringType& text_anchor) {
-  if (strcmp(text_anchor.c_str(), "start") == 0) {
-    fTextAlign = SkTextUtils::Align::kLeft_Align;
-  } else if (strcmp(text_anchor.c_str(), "middle") == 0) {
-    fTextAlign = SkTextUtils::Align::kCenter_Align;
-  } else if (strcmp(text_anchor.c_str(), "end") == 0) {
-    fTextAlign = SkTextUtils::Align::kRight_Align;
-  }
-}
-
 SkFont SkSVGText::resolveFont(const SkSVGRenderContext& ctx) const {
     auto weight = [](const SkSVGFontWeight& w) {
         switch (w.type()) {
@@ -92,14 +76,27 @@
 void SkSVGText::onRender(const SkSVGRenderContext& ctx) const {
     const auto font = this->resolveFont(ctx);
 
+    const auto text_align = [](const SkSVGTextAnchor& anchor) {
+        switch (anchor.type()) {
+            case SkSVGTextAnchor::Type::kStart : return SkTextUtils::Align::kLeft_Align;
+            case SkSVGTextAnchor::Type::kMiddle: return SkTextUtils::Align::kCenter_Align;
+            case SkSVGTextAnchor::Type::kEnd   : return SkTextUtils::Align::kRight_Align;
+            case SkSVGTextAnchor::Type::kInherit:
+                SkASSERT(false);
+                return SkTextUtils::Align::kLeft_Align;
+        }
+        SkUNREACHABLE;
+    };
+
+    const auto align = text_align(*ctx.presentationContext().fInherited.fTextAnchor);
     if (const SkPaint* fillPaint = ctx.fillPaint()) {
         SkTextUtils::DrawString(ctx.canvas(), fText.c_str(), fX.value(), fY.value(), font,
-                                *fillPaint, fTextAlign);
+                                *fillPaint, align);
     }
 
     if (const SkPaint* strokePaint = ctx.strokePaint()) {
         SkTextUtils::DrawString(ctx.canvas(), fText.c_str(), fX.value(), fY.value(), font,
-                                *strokePaint, fTextAlign);
+                                *strokePaint, align);
     }
 }
 
@@ -129,12 +126,6 @@
         this->setText(*text);
       }
       break;
-    case SkSVGAttribute::kTextAnchor:
-      if (const auto* text_anchor = v.as<SkSVGStringValue>()) {
-        this->setTextAnchor(*text_anchor);
-      }
-      break;
-      break;
     default:
       this->INHERITED::onSetAttribute(attr, v);
   }