[svg] Deferred text position adjustments

Upcoming textPath changes require position adjustments (relative offset,
rotation) to be applied after mapping to path, at chunk flush time.

Bug: skia:10840
Change-Id: Ifccea2983d5d5c57876d0a25e1da113e4c9cd51a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/350018
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 79ac161..65bbeb1 100644
--- a/modules/svg/src/SkSVGText.cpp
+++ b/modules/svg/src/SkSVGText.cpp
@@ -328,9 +328,11 @@
         const auto& buf = blobBuilder.allocRunRSXform(run.font, SkToInt(run.glyphCount));
         std::copy(run.glyphs.get(), run.glyphs.get() + run.glyphCount, buf.glyphs);
         for (size_t i = 0; i < run.glyphCount; ++i) {
-            const auto& pos = run.glyphPos[i];
+            const auto& pos_adjust = run.glyhPosAdjust[i];
+
+            const auto pos = run.glyphPos[i] + pos_adjust.offset;
             buf.xforms()[i] = SkRSXform::MakeFromRadians(/*scale=*/ 1,
-                                                         SkDegreesToRadians(run.glyphRot[i]),
+                                                         SkDegreesToRadians(pos_adjust.rotation),
                                                          pos.fX, pos.fY, 0, 0);
         }
 
@@ -359,9 +361,9 @@
         ri.fFont,
         fCurrentFill   ? std::make_unique<SkPaint>(*fCurrentFill)   : nullptr,
         fCurrentStroke ? std::make_unique<SkPaint>(*fCurrentStroke) : nullptr,
-        std::make_unique<SkGlyphID[]>(ri.glyphCount),
-        std::make_unique<SkPoint[]  >(ri.glyphCount),
-        std::make_unique<float[]    >(ri.glyphCount),
+        std::make_unique<SkGlyphID[]         >(ri.glyphCount),
+        std::make_unique<SkPoint[]           >(ri.glyphCount),
+        std::make_unique<PositionAdjustment[]>(ri.glyphCount),
         ri.glyphCount,
         ri.fAdvance,
     });
@@ -381,16 +383,13 @@
 void SkSVGTextContext::commitRunBuffer(const RunInfo& ri) {
     const auto& current_run = fRuns.back();
 
-    // apply position adjustments
+    // stash position adjustments
     for (size_t i = 0; i < ri.glyphCount; ++i) {
         const auto utf8_index = fShapeClusterBuffer[i];
-        const auto& pos = fShapeBuffer.fUtf8PosAdjust[SkToInt(utf8_index)];
-
-        current_run.glyphPos[i] += pos.offset;
-        current_run.glyphRot[i]  = pos.rotation;
+        current_run.glyhPosAdjust[i] = fShapeBuffer.fUtf8PosAdjust[SkToInt(utf8_index)];
     }
 
-    // Position adjustments are cumulative - we only need to advance the current chunk
+    // Offset adjustments are cumulative - we only need to advance the current chunk
     // with the last value.
     fChunkAdvance += ri.fAdvance + fShapeBuffer.fUtf8PosAdjust.back().offset;
 }