diff Framework/Radiography/RadiographyScene.cpp @ 1224:37bc7f115f81 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 07 Dec 2019 18:45:37 +0100
parents 21c2b0eee53c 9ee6b28f53e8
children 0ca50d275b9a
line wrap: on
line diff
--- a/Framework/Radiography/RadiographyScene.cpp	Sat Dec 07 18:18:07 2019 +0100
+++ b/Framework/Radiography/RadiographyScene.cpp	Sat Dec 07 18:45:37 2019 +0100
@@ -295,11 +295,12 @@
 
   RadiographyLayer& RadiographyScene::UpdateText(size_t layerIndex,
                                                  const std::string& utf8,
+                                                 const std::string& font,
                                                  unsigned int fontSize,
                                                  uint8_t foreground)
   {
     RadiographyTextLayer& textLayer = dynamic_cast<RadiographyTextLayer&>(GetLayer(layerIndex));
-    textLayer.SetText(utf8, fontSize, foreground);
+    textLayer.SetText(utf8, font, fontSize, foreground);
 
     BroadcastMessage(RadiographyScene::ContentChangedMessage(*this, textLayer));
     BroadcastMessage(RadiographyScene::LayerEditedMessage(*this, textLayer));
@@ -308,15 +309,27 @@
 
 
   RadiographyLayer& RadiographyScene::LoadText(const std::string& utf8,
+                                               const std::string& font,
                                                unsigned int fontSize,
                                                uint8_t foreground,
-                                               RadiographyLayer::Geometry* geometry)
+                                               RadiographyLayer::Geometry* centerGeometry,
+                                               bool isCenterGeometry)
   {
     std::auto_ptr<RadiographyTextLayer>  alpha(new RadiographyTextLayer(*this));
-    alpha->SetText(utf8, fontSize, foreground);
-    if (geometry != NULL)
+    alpha->SetText(utf8, font, fontSize, foreground);
+    if (centerGeometry != NULL)
     {
-      alpha->SetGeometry(*geometry);
+      if (isCenterGeometry)
+      {
+        // modify geometry to reference the top left corner
+        double tlx = centerGeometry->GetPanX();
+        double tly = centerGeometry->GetPanY();
+        Extent2D textExtent = alpha->GetExtent();
+        tlx = tlx - (textExtent.GetWidth() / 2) * centerGeometry->GetPixelSpacingX();
+        tly = tly - (textExtent.GetHeight() / 2) * centerGeometry->GetPixelSpacingY();
+        centerGeometry->SetPan(tlx, tly);
+      }
+      alpha->SetGeometry(*centerGeometry);
     }
 
     RadiographyLayer& registeredLayer = RegisterLayer(alpha.release());