comparison 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
comparison
equal deleted inserted replaced
365:ef31240a73f6 366:a7de01c8fd29
98 cairo_image_surface_get_height(surface_), 98 cairo_image_surface_get_height(surface_),
99 cairo_image_surface_get_stride(surface_), 99 cairo_image_surface_get_stride(surface_),
100 cairo_image_surface_get_data(surface_)); 100 cairo_image_surface_get_data(surface_));
101 } 101 }
102 102
103 void Fill(cairo_t* cr, 103 void Blit(cairo_t* cr,
104 double x, 104 double x,
105 double y) 105 double y)
106 { 106 {
107 cairo_surface_mark_dirty(surface_); 107 cairo_surface_mark_dirty(surface_);
108 cairo_mask_surface(cr, surface_, x, y); 108 cairo_mask_surface(cr, surface_, x, y);
112 112
113 113
114 void CairoContext::DrawText(const Orthanc::Font& font, 114 void CairoContext::DrawText(const Orthanc::Font& font,
115 const std::string& text, 115 const std::string& text,
116 double x, 116 double x,
117 double y) 117 double y,
118 BitmapAnchor anchor)
118 { 119 {
120 // Render a bitmap containing the text
119 unsigned int width, height; 121 unsigned int width, height;
120 font.ComputeTextExtent(width, height, text); 122 font.ComputeTextExtent(width, height, text);
121 123
122 AlphaSurface surface(width, height); 124 AlphaSurface surface(width, height);
123 125
124 Orthanc::ImageAccessor accessor; 126 Orthanc::ImageAccessor accessor;
125 surface.GetAccessor(accessor); 127 surface.GetAccessor(accessor);
126 font.Draw(accessor, text, 0, 0, 255); 128 font.Draw(accessor, text, 0, 0, 255);
127 129
130 // Correct the text location given the anchor location
131 double deltaX, deltaY;
132 ComputeAnchorTranslation(deltaX, deltaY, anchor, width, height);
133
134 // Cancel zoom/rotation before blitting the text onto the surface
128 double pixelX = x; 135 double pixelX = x;
129 double pixelY = y; 136 double pixelY = y;
130 cairo_user_to_device(context_, &pixelX, &pixelY); 137 cairo_user_to_device(context_, &pixelX, &pixelY);
131 138
132 cairo_save(context_); 139 cairo_save(context_);
133 cairo_identity_matrix(context_); 140 cairo_identity_matrix(context_);
134 141
135 surface.Fill(context_, pixelX, pixelY); 142 // Blit the text bitmap
136 143 surface.Blit(context_, pixelX + deltaX, pixelY + deltaY);
137 cairo_restore(context_); 144 cairo_restore(context_);
138 } 145 }
139 } 146 }