Support font variations in async text 30/321530/1
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 25 Mar 2025 01:19:26 +0000 (10:19 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 25 Mar 2025 01:22:54 +0000 (10:22 +0900)
Change-Id: I98335054c3ccabfd3ec29de593806cf110d1e9b3
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextLabel-Async.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp
dali-toolkit/internal/text/async-text/async-text-loader.h

index 8826eb96246fbb731559b695f0bf750eb37d9db2..1ac6b243ec44b4e79437f829fd086e436d5571fb 100644 (file)
@@ -2824,5 +2824,64 @@ int UtcDaliToolkitTextLabelAsyncTextEllipsisMode(void)
   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, ASYNC_TEXT_THREAD_TIMEOUT), true, TEST_LOCATION);
   DALI_TEST_CHECK(label.GetProperty<bool>(DevelTextLabel::Property::IS_SCROLLING));
 
+  END_TEST;
+}
+
+int UtcDaliToolkitTextLabelAsyncFontVariations(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliToolkitTextLabelAsyncFontVariations");
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
+
+  TextLabel label = TextLabel::New();
+  DALI_TEST_CHECK(label);
+
+  float expectedWidth  = 300.0f;
+  float expectedHeight = 300.0f;
+
+  label.SetProperty(DevelTextLabel::Property::RENDER_MODE, DevelTextLabel::Render::ASYNC_AUTO);
+  label.SetProperty(TextLabel::Property::TEXT, "Hello world Hello world");
+  label.SetProperty(Actor::Property::SIZE, Vector2(expectedWidth, expectedHeight));
+  label.SetProperty(TextLabel::Property::POINT_SIZE, 12);
+  label.SetProperty(TextLabel::Property::MULTI_LINE, true);
+  application.GetScene().Add(label);
+
+  std::string WGHT_KEY = "wght";
+  const float WGHT_VALUE = 100.f;
+
+  auto fontVariationsIndex = DevelTextLabel::RegisterFontVariationProperty(label, WGHT_KEY.data());
+  label.SetProperty(fontVariationsIndex, WGHT_VALUE);
+
+  DALI_TEST_CHECK(label.GetProperty(fontVariationsIndex).Get<float>() == WGHT_VALUE);
+
+  // Connect to the async text rendered signal.
+  ConnectionTracker* testTracker = new ConnectionTracker();
+  DevelTextLabel::AsyncTextRenderedSignal(label).Connect(&TestAsyncTextRendered);
+
+  bool asyncTextRendered = false;
+  label.ConnectSignal(testTracker, "asyncTextRendered", CallbackFunctor(&asyncTextRendered));
+
+  gAsyncTextRenderedCalled = false;
+  gAsyncTextRenderedWidth  = 0.0f;
+  gAsyncTextRenderedHeight = 0.0f;
+
+  // Request render automatically.
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, ASYNC_TEXT_THREAD_TIMEOUT), true, TEST_LOCATION);
+
+  DALI_TEST_CHECK(gAsyncTextRenderedCalled);
+  DALI_TEST_CHECK(asyncTextRendered);
+
+  DALI_TEST_EQUALS(expectedWidth, gAsyncTextRenderedWidth, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
+  DALI_TEST_EQUALS(expectedHeight, gAsyncTextRenderedHeight, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
+  DALI_TEST_EQUALS(false, label.GetProperty<bool>(DevelTextLabel::Property::MANUAL_RENDERED), TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
   END_TEST;
 }
\ No newline at end of file
index a60bbb7bf35c8948740dcc1c09f5ebc49a398fb7..561fc3751d089f00445a1f10cbcfbc2209cebcac 100644 (file)
@@ -1642,6 +1642,10 @@ AsyncTextParameters TextLabel::GetAsyncTextParameters(const Async::RequestType r
   parameters.backgroundWithCutoutEnabled = mController->IsBackgroundWithCutoutEnabled();
   parameters.backgroundColorWithCutout   = mController->GetBackgroundColorWithCutout();
 
+  Property::Map variationsMap;
+  mController->GetVariationsMap(variationsMap);
+  parameters.variationsMap = variationsMap;
+
   return parameters;
 }
 
@@ -2159,6 +2163,7 @@ void TextLabel::OnVariationPropertyNotify(PropertyNotification& source)
 
   // Full Variation Update.
   mController->SetVariationsMap(map);
+  mIsAsyncRenderNeeded = true;
 }
 
 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
index 519e72ed63c3112b59092474bda5f1ac4e8f5d2a..460e3f4fb4e4f88af81e009cefd90fd804c05639 100644 (file)
@@ -167,6 +167,7 @@ void AsyncTextLoader::ClearTextModelData()
   mTextModel->mLogicalModel->ClearUnderlineRuns();
   mTextModel->mLogicalModel->ClearEmbeddedImages();
   mTextModel->mLogicalModel->ClearAnchors();
+  mTextModel->mLogicalModel->mVariationsMap.Clear();
 
   // Free the allocated memory used to store the conversion table in the bidirectional line info run.
   for(Vector<BidirectionalLineInfoRun>::Iterator it    = mTextModel->mLogicalModel->mBidirectionalLineInfo.Begin(),
@@ -232,6 +233,7 @@ void AsyncTextLoader::Update(AsyncTextParameters& parameters)
   mTextModel->mVerticalAlignment     = parameters.verticalAlignment;
   mTextModel->mVerticalLineAlignment = parameters.verticalLineAlignment;
 
+  mTextModel->mLogicalModel->mVariationsMap = parameters.variationsMap;
 
   ////////////////////////////////////////////////////////////////////////////////
   // Update visual model.
@@ -411,6 +413,12 @@ void AsyncTextLoader::Update(AsyncTextParameters& parameters)
 
   defaultPointSize = parameters.fontSize * scale * numberOfPointsPerOneUnitOfPointSize;
 
+  Property::Map *variationsMapPtr = nullptr;
+  if(!mTextModel->mLogicalModel->mVariationsMap.Empty())
+  {
+    variationsMapPtr = &mTextModel->mLogicalModel->mVariationsMap;
+  }
+
   // Validates the fonts. If there is a character with no assigned font it sets a default one.
   // After this call, fonts are validated.
   mModule.GetMultilanguageSupport().ValidateFonts(mModule.GetFontClient(),
@@ -422,7 +430,8 @@ void AsyncTextLoader::Update(AsyncTextParameters& parameters)
                                                   scale,
                                                   0u,
                                                   numberOfCharacters,
-                                                  validFonts);
+                                                  validFonts,
+                                                  variationsMapPtr);
 
 
   ////////////////////////////////////////////////////////////////////////////////
@@ -492,12 +501,6 @@ void AsyncTextLoader::Update(AsyncTextParameters& parameters)
 
   const Vector<Character>& textToShape = mIsTextMirrored ? mirroredUtf32Characters : utf32Characters;
 
-  Property::Map *variationsMapPtr = nullptr;
-  if(!mTextModel->mLogicalModel->mVariationsMap.Empty())
-  {
-    variationsMapPtr = &mTextModel->mLogicalModel->mVariationsMap;
-  }
-
   // Shapes the text.
   ShapeText(mModule.GetShaping(),
             mModule.GetFontClient(),
index f3d8ef4614860d4b76c3cddf10df132c9e7323b8..4b8df0b56843eb0391816e0334e852767277c185 100644 (file)
@@ -128,7 +128,8 @@ struct AsyncTextParameters
     isAutoScrollMaxTextureExceeded{false},
     cutout{false},
     backgroundWithCutoutEnabled{false},
-    backgroundColorWithCutout{Color::TRANSPARENT}
+    backgroundColorWithCutout{Color::TRANSPARENT},
+    variationsMap{}
   {
   }
 
@@ -210,9 +211,11 @@ struct AsyncTextParameters
   int                                    autoScrollGap;
   bool                                   isAutoScrollMaxTextureExceeded : 1;
 
-  bool cutout                      : 1; ///< Cutout enabled flag
-  bool backgroundWithCutoutEnabled : 1; ///< Background with cutout enabled flag.
-  Vector4 backgroundColorWithCutout;    ///< Background color with cutout.
+  bool          cutout                      : 1; ///< Cutout enabled flag
+  bool          backgroundWithCutoutEnabled : 1; ///< Background with cutout enabled flag.
+  Vector4       backgroundColorWithCutout;    ///< Background color with cutout.
+
+  Property::Map variationsMap;          ///< The map for variable fonts. it might be replaced by variable map run.
 };
 
 struct AsyncTextRenderInfo