diff Framework/Viewport/CairoContext.cpp @ 366:a7de01c8fd29 am-2

new enum BitmapAnchor
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Nov 2018 11:55:45 +0100
parents ef31240a73f6
children b70e9be013e4
line wrap: on
line diff
--- a/Framework/Viewport/CairoContext.cpp	Wed Oct 31 18:10:29 2018 +0100
+++ b/Framework/Viewport/CairoContext.cpp	Thu Nov 01 11:55:45 2018 +0100
@@ -100,7 +100,7 @@
                             cairo_image_surface_get_data(surface_));
     }
 
-    void Fill(cairo_t* cr,
+    void Blit(cairo_t* cr,
               double x,
               double y)
     {
@@ -114,8 +114,10 @@
   void CairoContext::DrawText(const Orthanc::Font& font,
                               const std::string& text,
                               double x,
-                              double y)
+                              double y,
+                              BitmapAnchor anchor)
   {
+    // Render a bitmap containing the text
     unsigned int width, height;
     font.ComputeTextExtent(width, height, text);
     
@@ -125,6 +127,11 @@
     surface.GetAccessor(accessor);
     font.Draw(accessor, text, 0, 0, 255);
 
+    // Correct the text location given the anchor location
+    double deltaX, deltaY;
+    ComputeAnchorTranslation(deltaX, deltaY, anchor, width, height);
+
+    // Cancel zoom/rotation before blitting the text onto the surface
     double pixelX = x;
     double pixelY = y;
     cairo_user_to_device(context_, &pixelX, &pixelY);
@@ -132,8 +139,8 @@
     cairo_save(context_);
     cairo_identity_matrix(context_);
 
-    surface.Fill(context_, pixelX, pixelY);
-
+    // Blit the text bitmap
+    surface.Blit(context_, pixelX + deltaX, pixelY + deltaY);
     cairo_restore(context_);
   }
 }