diff --git a/modules/skottie/src/text/SkottieShaper.cpp b/modules/skottie/src/text/SkottieShaper.cpp index 175e68c844..69165a8625 100644 --- a/modules/skottie/src/text/SkottieShaper.cpp +++ b/modules/skottie/src/text/SkottieShaper.cpp @@ -146,24 +146,27 @@ public: const auto ascent = this->ascent(); - auto extent_box = [&](bool include_typographical_extent = false) { + // For visual VAlign modes, we use a hybrid extent box computed as the union of + // actual visual bounds and the vertical typographical extent. + // + // This ensures that + // + // a) text doesn't visually overflow the alignment boundaries + // + // b) leading/trailing empty lines are still taken into account for alignment purposes + + auto extent_box = [&]() { auto box = fResult.computeVisualBounds(); -#ifdef SKOTTIE_DEPRECATED_VERTICAL_ALIGNMENT - include_typographical_extent = true; -#endif - // Deprecated visual alignment mode, based on typographical extent. - if (include_typographical_extent) { - // By default, first line is vertically-aligned on a baseline of 0. - // The typographical height considered for vertical alignment is the distance - // between the first line top (ascent) to the last line bottom (descent). - const auto typographical_top = fBox.fTop + ascent, - typographical_bottom = fBox.fTop + fLastLineDescent + - fDesc.fLineHeight*(fLineCount > 0 ? fLineCount - 1 : 0ul); + // By default, first line is vertically-aligned on a baseline of 0. + // The typographical height considered for vertical alignment is the distance between + // the first line top (ascent) to the last line bottom (descent). + const auto typographical_top = fBox.fTop + ascent, + typographical_bottom = fBox.fTop + fLastLineDescent + fDesc.fLineHeight * + (fLineCount > 0 ? fLineCount - 1 : 0ul); - box.fTop = std::min(box.fTop, typographical_top); - box.fBottom = std::max(box.fBottom, typographical_bottom); - } + box.fTop = std::min(box.fTop, typographical_top); + box.fBottom = std::max(box.fBottom, typographical_bottom); return box; }; @@ -186,8 +189,7 @@ public: v_offset += fBox.fTop - ebox->fTop; break; case Shaper::VAlign::kVisualCenter: - case Shaper::VAlign::kDeprecatedVisualCenter: - ebox.init(extent_box(fDesc.fVAlign == Shaper::VAlign::kDeprecatedVisualCenter)); + ebox.init(extent_box()); v_offset += fBox.centerY() - ebox->centerY(); break; case Shaper::VAlign::kVisualBottom: diff --git a/modules/skottie/src/text/SkottieShaper.h b/modules/skottie/src/text/SkottieShaper.h index 3477b906aa..cd9fbe72fa 100644 --- a/modules/skottie/src/text/SkottieShaper.h +++ b/modules/skottie/src/text/SkottieShaper.h @@ -47,14 +47,7 @@ public: // Align the first line typographical baseline with the text box top (AE point text). kTopBaseline, - // Skottie vertical alignment extensions: - kVisualTop, // visual top -> text box top - kVisualCenter, // visual center -> text box center - kVisualBottom, // visual bottom -> text box bottom - - // Deprecated/historical alignment mode. Do not use. - // - // Based on an extent box defined (in Y) as + // Skottie vertical alignment extensions: these are based on an extent box defined (in Y) as // // ------------------------------------------------------ // MIN(visual_top_extent , typographical_top_extent ) @@ -63,7 +56,13 @@ public: // // MAX(visual_bottom_extent, typographical_bottom_extent) // ------------------------------------------------------ - kDeprecatedVisualCenter, // extent box center -> text box center + + // extent box top -> text box top + kVisualTop, + // extent box center -> text box center + kVisualCenter, + // extent box bottom -> text box bottom + kVisualBottom, }; enum class ResizePolicy : uint8_t { diff --git a/modules/skottie/src/text/TextValue.cpp b/modules/skottie/src/text/TextValue.cpp index 800820f1a6..f92514e620 100644 --- a/modules/skottie/src/text/TextValue.cpp +++ b/modules/skottie/src/text/TextValue.cpp @@ -121,12 +121,12 @@ bool Parse(const skjson::Value& jv, const internal::AnimationBuilder& abuilder, switch (vj) { case 3: // 'sk_vj': 3 -> kVisualCenter/kScaleToFit - v->fVAlign = Shaper::VAlign::kDeprecatedVisualCenter; + v->fVAlign = Shaper::VAlign::kVisualCenter; v->fResize = Shaper::ResizePolicy::kScaleToFit; break; case 4: // 'sk_vj': 4 -> kVisualCenter/kDownscaleToFit - v->fVAlign = Shaper::VAlign::kDeprecatedVisualCenter; + v->fVAlign = Shaper::VAlign::kVisualCenter; v->fResize = Shaper::ResizePolicy::kDownscaleToFit; break; default: