changeset 1792:373d7f7e796e

ICompositor::ComputeTextBoundingBox()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 May 2021 16:59:03 +0200
parents 9b650ab68d4c
children c5e6379b9cd0
files OrthancStone/Sources/Scene2D/CairoCompositor.cpp OrthancStone/Sources/Scene2D/CairoCompositor.h OrthancStone/Sources/Scene2D/ICompositor.h OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp OrthancStone/Sources/Scene2D/OpenGLCompositor.h
diffstat 5 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Scene2D/CairoCompositor.cpp	Mon May 17 16:11:17 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/CairoCompositor.cpp	Mon May 17 16:59:03 2021 +0200
@@ -190,4 +190,24 @@
       return found->second->RenderText(utf8);
     }
   }
+
+  
+#if ORTHANC_ENABLE_LOCALE == 1
+  TextBoundingBox* CairoCompositor::ComputeTextBoundingBox(size_t fontIndex,
+                                                           const std::string& utf8)
+  {
+    Fonts::const_iterator found = fonts_.find(fontIndex);
+
+    if (found == fonts_.end())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
+                                      "No such font: " + boost::lexical_cast<std::string>(fontIndex));
+    }
+    else
+    {
+      assert(found->second != NULL);
+      return new TextBoundingBox(found->second->GetAlphabet(), utf8);
+    }
+  }
+#endif
 }
--- a/OrthancStone/Sources/Scene2D/CairoCompositor.h	Mon May 17 16:11:17 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/CairoCompositor.h	Mon May 17 16:59:03 2021 +0200
@@ -92,5 +92,10 @@
 
     Orthanc::ImageAccessor* RenderText(size_t fontIndex,
                                        const std::string& utf8) const;
+
+#if ORTHANC_ENABLE_LOCALE == 1
+    virtual TextBoundingBox* ComputeTextBoundingBox(size_t fontIndex,
+                                                    const std::string& utf8) ORTHANC_OVERRIDE;
+#endif
   };
 }
--- a/OrthancStone/Sources/Scene2D/ICompositor.h	Mon May 17 16:11:17 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/ICompositor.h	Mon May 17 16:59:03 2021 +0200
@@ -25,6 +25,10 @@
 #include "Scene2D.h"
 #include "ScenePoint2D.h"
 
+#if ORTHANC_ENABLE_LOCALE == 1
+#  include "../Fonts/TextBoundingBox.h"
+#endif
+
 namespace OrthancStone
 {
   class ICompositor : public boost::noncopyable
@@ -69,5 +73,10 @@
     {
       scene.FitContent(GetCanvasWidth(), GetCanvasHeight());
     }
+
+#if ORTHANC_ENABLE_LOCALE == 1
+    virtual TextBoundingBox* ComputeTextBoundingBox(size_t fontIndex,
+                                                    const std::string& utf8) = 0;
+#endif
   };
 }
--- a/OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp	Mon May 17 16:11:17 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/OpenGLCompositor.cpp	Mon May 17 16:59:03 2021 +0200
@@ -253,4 +253,24 @@
     canvasWidth_ = canvasWidth;
     canvasHeight_ = canvasHeight;
   }
+  
+
+#if ORTHANC_ENABLE_LOCALE == 1
+  TextBoundingBox* OpenGLCompositor::ComputeTextBoundingBox(size_t fontIndex,
+                                                            const std::string& utf8)
+  {
+    Fonts::const_iterator found = fonts_.find(fontIndex);
+
+    if (found == fonts_.end())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
+                                      "No such font: " + boost::lexical_cast<std::string>(fontIndex));
+    }
+    else
+    {
+      assert(found->second != NULL);
+      return new TextBoundingBox(found->second->GetAlphabet().GetAlphabet(), utf8);
+    }
+  }
+#endif
 }
--- a/OrthancStone/Sources/Scene2D/OpenGLCompositor.h	Mon May 17 16:11:17 2021 +0200
+++ b/OrthancStone/Sources/Scene2D/OpenGLCompositor.h	Mon May 17 16:59:03 2021 +0200
@@ -85,5 +85,10 @@
     {
       return canvasHeight_;
     }
+
+#if ORTHANC_ENABLE_LOCALE == 1
+    virtual TextBoundingBox* ComputeTextBoundingBox(size_t fontIndex,
+                                                    const std::string& utf8) ORTHANC_OVERRIDE;
+#endif
   };
 }