diff Plugins/Engine/OrthancPlugins.cpp @ 1613:1ec254a7c645

drawing texts on image from plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Sep 2015 17:12:25 +0200
parents 96582230ddcb
children c40fe92a68e7
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Fri Sep 04 16:36:18 2015 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Fri Sep 04 17:12:25 2015 +0200
@@ -1182,6 +1182,39 @@
   }
 
 
+
+  void OrthancPlugins::GetFontInfo(const void* parameters)
+  {
+    const _OrthancPluginGetFontInfo& p = *reinterpret_cast<const _OrthancPluginGetFontInfo*>(parameters);
+
+    const Font& font = Configuration::GetFontRegistry().GetFont(p.fontIndex);
+
+    if (p.name != NULL)
+    {
+      *(p.name) = font.GetName().c_str();
+    }
+    else if (p.size != NULL)
+    {
+      *(p.size) = font.GetSize();
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+  }
+
+
+  void OrthancPlugins::DrawText(const void* parameters)
+  {
+    const _OrthancPluginDrawText& p = *reinterpret_cast<const _OrthancPluginDrawText*>(parameters);
+
+    ImageAccessor& target = *reinterpret_cast<ImageAccessor*>(p.image);
+    const Font& font = Configuration::GetFontRegistry().GetFont(p.fontIndex);
+
+    font.Draw(target, p.utf8Text, p.x, p.y, p.r, p.g, p.b);
+  }
+        
+
   bool OrthancPlugins::InvokeService(_OrthancPluginService service,
                                      const void* parameters)
   {
@@ -1569,6 +1602,22 @@
         ConvertPixelFormat(parameters);
         return true;
 
+      case _OrthancPluginService_GetFontsCount:
+      {
+        const _OrthancPluginReturnSingleValue& p =
+          *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(parameters);
+        *(p.resultUint32) = Configuration::GetFontRegistry().GetSize();
+        return true;
+      }
+
+      case _OrthancPluginService_GetFontInfo:
+        GetFontInfo(parameters);
+        return true;
+
+      case _OrthancPluginService_DrawText:
+        DrawText(parameters);
+        return true;
+
       default:
       {
         // This service is unknown to the Orthanc plugin engine