Mercurial > hg > orthanc-stone
comparison Framework/Layers/LineMeasureTracker.cpp @ 367:face7b7008de am-2
line and circle measure tools are now compatible with WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 01 Nov 2018 12:09:11 +0100 |
parents | 50e5ec1bdd46 |
children | b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
366:a7de01c8fd29 | 367:face7b7008de |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "LineMeasureTracker.h" | 22 #include "LineMeasureTracker.h" |
23 | 23 |
24 #include "../Viewport/CairoFont.h" | |
25 | |
26 #include <stdio.h> | 24 #include <stdio.h> |
27 | 25 |
28 namespace OrthancStone | 26 namespace OrthancStone |
29 { | 27 { |
30 LineMeasureTracker::LineMeasureTracker(IStatusBar* statusBar, | 28 LineMeasureTracker::LineMeasureTracker(IStatusBar* statusBar, |
32 double x, | 30 double x, |
33 double y, | 31 double y, |
34 uint8_t red, | 32 uint8_t red, |
35 uint8_t green, | 33 uint8_t green, |
36 uint8_t blue, | 34 uint8_t blue, |
37 unsigned int fontSize) : | 35 const Orthanc::Font& font) : |
38 statusBar_(statusBar), | 36 statusBar_(statusBar), |
39 slice_(slice), | 37 slice_(slice), |
40 x1_(x), | 38 x1_(x), |
41 y1_(y), | 39 y1_(y), |
42 x2_(x), | 40 x2_(x), |
43 y2_(y), | 41 y2_(y), |
44 fontSize_(fontSize) | 42 font_(font) |
45 { | 43 { |
46 color_[0] = red; | 44 color_[0] = red; |
47 color_[1] = green; | 45 color_[1] = green; |
48 color_[2] = blue; | 46 color_[2] = blue; |
49 } | 47 } |
58 cairo_set_line_width(cr, 2.0 / zoom); | 56 cairo_set_line_width(cr, 2.0 / zoom); |
59 cairo_move_to(cr, x1_, y1_); | 57 cairo_move_to(cr, x1_, y1_); |
60 cairo_line_to(cr, x2_, y2_); | 58 cairo_line_to(cr, x2_, y2_); |
61 cairo_stroke(cr); | 59 cairo_stroke(cr); |
62 | 60 |
63 if (fontSize_ != 0) | 61 if (y2_ - y1_ < 0) |
64 { | 62 { |
65 cairo_move_to(cr, x2_, y2_ - static_cast<double>(fontSize_) / zoom); | 63 context.DrawText(font_, FormatLength(), x2_, y2_ - 5, BitmapAnchor_BottomCenter); |
66 #if ORTHANC_ENABLE_NATIVE==1 // text rendering currently fails in wasm | 64 } |
67 CairoFont font("sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | 65 else |
68 font.Draw(context, FormatLength(), static_cast<double>(fontSize_) / zoom); | 66 { |
69 #endif | 67 context.DrawText(font_, FormatLength(), x2_, y2_ + 5, BitmapAnchor_TopCenter); |
70 } | 68 } |
71 } | 69 } |
72 | 70 |
73 | 71 |
74 double LineMeasureTracker::GetLength() const // In millimeters | 72 double LineMeasureTracker::GetLength() const // In millimeters |