comparison Framework/Toolbox/TextRenderer.cpp @ 1471:28c64c246312

working on a shared library
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Jun 2020 12:57:54 +0200
parents 182bf3106ee2
children
comparison
equal deleted inserted replaced
1470:390b0c30ba19 1471:28c64c246312
33 #include <Images/PngWriter.h> 33 #include <Images/PngWriter.h>
34 #include <Toolbox.h> 34 #include <Toolbox.h>
35 35
36 namespace OrthancStone 36 namespace OrthancStone
37 { 37 {
38 Orthanc::ImageAccessor* TextRenderer::Render(Orthanc::EmbeddedResources::FileResourceId font, 38 Orthanc::ImageAccessor* TextRenderer::Render(const std::string& ttf,
39 unsigned int fontSize, 39 unsigned int fontSize,
40 const std::string& utf8String 40 const std::string& utf8String)
41 )
42 { 41 {
43 FontRenderer renderer; 42 FontRenderer renderer;
44 renderer.LoadFont(font, fontSize); 43 renderer.LoadFont(ttf, fontSize);
45 44
46 // add each char to be rendered to the alphabet 45 // add each char to be rendered to the alphabet
47 std::unique_ptr<GlyphBitmapAlphabet> alphabet(new GlyphBitmapAlphabet); 46 std::unique_ptr<GlyphBitmapAlphabet> alphabet(new GlyphBitmapAlphabet);
48 47
49 size_t posInString = 0; 48 size_t posInString = 0;
74 73
75 return renderedTextExtended.release(); 74 return renderedTextExtended.release();
76 } 75 }
77 76
78 77
79 Orthanc::ImageAccessor* TextRenderer::RenderWithAlpha(Orthanc::EmbeddedResources::FileResourceId resource, 78 Orthanc::ImageAccessor* TextRenderer::RenderWithAlpha(const std::string& ttf,
80 unsigned int fontSize, 79 unsigned int fontSize,
81 const std::string& utf8String, 80 const std::string& utf8String,
82 uint8_t foreground) 81 uint8_t foreground)
83 { 82 {
84 std::unique_ptr<Orthanc::ImageAccessor> renderedText8(Render(resource, fontSize, utf8String)); 83 std::unique_ptr<Orthanc::ImageAccessor> renderedText8(Render(ttf, fontSize, utf8String));
85 std::unique_ptr<Orthanc::Image> target(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, renderedText8->GetWidth(), renderedText8->GetHeight(), true)); 84 std::unique_ptr<Orthanc::Image> target(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, renderedText8->GetWidth(), renderedText8->GetHeight(), true));
86 85
87 Orthanc::ImageProcessing::Set(*target, foreground, foreground, foreground, *renderedText8); 86 Orthanc::ImageProcessing::Set(*target, foreground, foreground, foreground, *renderedText8);
88 return target.release(); 87 return target.release();
89 } 88 }
90 89
91 90
92 // currently disabled because the background is actually not transparent once we use the Cairo Compositor ! 91 // currently disabled because the background is actually not transparent once we use the Cairo Compositor !
93 // 92 //
94 // // renders text in color + a border with alpha in a RGBA32 image 93 // // renders text in color + a border with alpha in a RGBA32 image
95 // Orthanc::ImageAccessor* TextRenderer::RenderWithAlpha(Orthanc::EmbeddedResources::FileResourceId resource, 94 // Orthanc::ImageAccessor* TextRenderer::RenderWithAlpha(const std::string& ttf,
96 // unsigned int fontSize, 95 // unsigned int fontSize,
97 // const std::string& utf8String, 96 // const std::string& utf8String,
98 // uint8_t foreground, 97 // uint8_t foreground,
99 // uint8_t borderColor) 98 // uint8_t borderColor)
100 // { 99 // {
101 // std::unique_ptr<Orthanc::ImageAccessor> renderedBorderAlpha(RenderWithAlpha(resource, fontSize, utf8String, borderColor)); 100 // std::unique_ptr<Orthanc::ImageAccessor> renderedBorderAlpha(RenderWithAlpha(ttf, fontSize, utf8String, borderColor));
102 // std::unique_ptr<Orthanc::ImageAccessor> renderedTextAlpha(RenderWithAlpha(resource, fontSize, utf8String, foreground)); 101 // std::unique_ptr<Orthanc::ImageAccessor> renderedTextAlpha(RenderWithAlpha(ttf, fontSize, utf8String, foreground));
103 102
104 // unsigned int textWidth = renderedBorderAlpha->GetWidth(); 103 // unsigned int textWidth = renderedBorderAlpha->GetWidth();
105 // unsigned int textHeight = renderedBorderAlpha->GetHeight(); 104 // unsigned int textHeight = renderedBorderAlpha->GetHeight();
106 105
107 // Scene2D targetScene; 106 // Scene2D targetScene;