comparison Framework/Radiography/RadiographyTextLayer.cpp @ 1220:9ee6b28f53e8

RadiographyTextLayer: support multiple fonts
author Alain Mazy <alain@mazy.be>
date Sat, 07 Dec 2019 17:47:23 +0100
parents ab958fd99b07
children 1c7ae79c426d
comparison
equal deleted inserted replaced
1219:f8bff27f1314 1220:9ee6b28f53e8
24 #include "RadiographyScene.h" 24 #include "RadiographyScene.h"
25 #include "Framework/Toolbox/TextRenderer.h" 25 #include "Framework/Toolbox/TextRenderer.h"
26 26
27 namespace OrthancStone 27 namespace OrthancStone
28 { 28 {
29 bool RadiographyTextLayer::fontHasBeenConfigured_ = false; 29 std::map<std::string, Orthanc::EmbeddedResources::FileResourceId> RadiographyTextLayer::fonts_;
30 Orthanc::EmbeddedResources::FileResourceId RadiographyTextLayer::fontResourceId_;
31 30
32 void RadiographyTextLayer::SetText(const std::string& utf8, 31 void RadiographyTextLayer::SetText(const std::string& utf8,
33 unsigned int fontSize, 32 const std::string& font,
34 uint8_t foreground) 33 unsigned int fontSize,
34 uint8_t foregroundGreyLevel)
35 { 35 {
36 if (!fontHasBeenConfigured_) 36 if (fonts_.find(font) == fonts_.end())
37 { 37 {
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "No font has been loaded"); 38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, "The font has not been registered");
39 } 39 }
40 40
41 text_ = utf8; 41 text_ = utf8;
42 font_ = font;
42 fontSize_ = fontSize; 43 fontSize_ = fontSize;
43 foreground_ = foreground; 44 foregroundGreyLevel_ = foregroundGreyLevel;
44 45
45 SetAlpha(TextRenderer::Render(fontResourceId_, 46 SetAlpha(TextRenderer::Render(fonts_[font_],
46 fontSize_, 47 fontSize_,
47 text_)); 48 text_));
48 49
49 SetForegroundValue(foreground * 256.0f); 50 SetForegroundValue(foregroundGreyLevel * 256.0f);
50 } 51 }
51 52
52 } 53 }