# HG changeset patch # User Sebastien Jodogne # Date 1541069745 -3600 # Node ID a7de01c8fd29509cea9c59a3529d52419bb0dd12 # Parent ef31240a73f6d799fa95e1a55ace3145c0a68e4a new enum BitmapAnchor diff -r ef31240a73f6 -r a7de01c8fd29 Applications/Samples/SimpleViewerApplicationSingleFile.h --- a/Applications/Samples/SimpleViewerApplicationSingleFile.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Applications/Samples/SimpleViewerApplicationSingleFile.h Thu Nov 01 11:55:45 2018 +0100 @@ -172,6 +172,14 @@ widget.FitContent(); break; + case 'l': + application_.currentTool_ = Tools_LineMeasure; + break; + + case 'c': + application_.currentTool_ = Tools_CircleMeasure; + break; + default: break; } diff -r ef31240a73f6 -r a7de01c8fd29 Framework/Layers/CircleMeasureTracker.cpp --- a/Framework/Layers/CircleMeasureTracker.cpp Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/Layers/CircleMeasureTracker.cpp Thu Nov 01 11:55:45 2018 +0100 @@ -71,8 +71,7 @@ cairo_stroke(cr); cairo_restore(cr); - //context.SetSourceColor(0, 255, 0); - context.DrawText(font_, FormatRadius(), x, y); + context.DrawText(font_, FormatRadius(), x, y, BitmapAnchor_Center); } diff -r ef31240a73f6 -r a7de01c8fd29 Framework/StoneEnumerations.cpp --- a/Framework/StoneEnumerations.cpp Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/StoneEnumerations.cpp Thu Nov 01 11:55:45 2018 +0100 @@ -72,4 +72,66 @@ throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); } } + + + void ComputeAnchorTranslation(double& deltaX, + double& deltaY, + BitmapAnchor anchor, + unsigned int bitmapWidth, + unsigned int bitmapHeight) + { + double dw = static_cast(bitmapWidth); + double dh = static_cast(bitmapHeight); + + switch (anchor) + { + case BitmapAnchor_TopLeft: + deltaX = 0; + deltaY = 0; + break; + + case BitmapAnchor_TopCenter: + deltaX = -dw / 2.0; + deltaY = 0; + break; + + case BitmapAnchor_TopRight: + deltaX = -dw; + deltaY = 0; + break; + + case BitmapAnchor_CenterLeft: + deltaX = 0; + deltaY = -dh / 2.0; + break; + + case BitmapAnchor_Center: + deltaX = -dw / 2.0; + deltaY = -dh / 2.0; + break; + + case BitmapAnchor_CenterRight: + deltaX = -dw; + deltaY = -dh / 2.0; + break; + + case BitmapAnchor_BottomLeft: + deltaX = 0; + deltaY = -dh; + break; + + case BitmapAnchor_BottomCenter: + deltaX = -dw / 2.0; + deltaY = -dh; + break; + + case BitmapAnchor_BottomRight: + deltaX = -dw; + deltaY = -dh; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } } diff -r ef31240a73f6 -r a7de01c8fd29 Framework/StoneEnumerations.h --- a/Framework/StoneEnumerations.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/StoneEnumerations.h Thu Nov 01 11:55:45 2018 +0100 @@ -102,6 +102,19 @@ SopClassUid_RTDose }; + enum BitmapAnchor + { + BitmapAnchor_BottomLeft, + BitmapAnchor_BottomCenter, + BitmapAnchor_BottomRight, + BitmapAnchor_CenterLeft, + BitmapAnchor_Center, + BitmapAnchor_CenterRight, + BitmapAnchor_TopLeft, + BitmapAnchor_TopCenter, + BitmapAnchor_TopRight + }; + bool StringToSopClassUid(SopClassUid& result, const std::string& source); @@ -110,4 +123,10 @@ ImageWindowing windowing, float defaultCenter, float defaultWidth); + + void ComputeAnchorTranslation(double& deltaX /* out */, + double& deltaY /* out */, + BitmapAnchor anchor, + unsigned int bitmapWidth, + unsigned int bitmapHeight); } diff -r ef31240a73f6 -r a7de01c8fd29 Framework/Viewport/CairoContext.cpp --- 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_); } } diff -r ef31240a73f6 -r a7de01c8fd29 Framework/Viewport/CairoContext.h --- a/Framework/Viewport/CairoContext.h Wed Oct 31 18:10:29 2018 +0100 +++ b/Framework/Viewport/CairoContext.h Thu Nov 01 11:55:45 2018 +0100 @@ -22,6 +22,7 @@ #pragma once #include "CairoSurface.h" +#include "../StoneEnumerations.h" #include @@ -69,6 +70,7 @@ void DrawText(const Orthanc::Font& font, const std::string& text, double x, - double y); + double y, + BitmapAnchor anchor); }; }