577
|
1 /**
|
|
2 * Stone of Orthanc
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
|
|
6 *
|
|
7 * This program is free software: you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Affero General Public License
|
|
9 * as published by the Free Software Foundation, either version 3 of
|
|
10 * the License, or (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful, but
|
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Affero General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Affero General Public License
|
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 **/
|
|
20
|
|
21
|
|
22 #include "GlyphBitmapAlphabet.h"
|
|
23
|
|
24 #include "TextBoundingBox.h"
|
|
25 #include "../Toolbox/DynamicBitmap.h"
|
|
26
|
|
27 #include <Core/Images/Image.h>
|
|
28 #include <Core/Images/ImageProcessing.h>
|
|
29
|
|
30 namespace OrthancStone
|
|
31 {
|
|
32 class GlyphBitmapAlphabet::RenderTextVisitor : public GlyphAlphabet::ITextVisitor
|
|
33 {
|
|
34 private:
|
|
35 Orthanc::ImageAccessor& target_;
|
|
36 const GlyphBitmapAlphabet& that_;
|
|
37 int offsetX_;
|
|
38 int offsetY_;
|
|
39
|
|
40 public:
|
|
41 RenderTextVisitor(Orthanc::ImageAccessor& target,
|
|
42 const GlyphBitmapAlphabet& that,
|
|
43 int offsetX,
|
|
44 int offsetY) :
|
|
45 target_(target),
|
|
46 that_(that),
|
|
47 offsetX_(offsetX),
|
|
48 offsetY_(offsetY)
|
|
49 {
|
|
50 }
|
|
51
|
|
52 virtual void Visit(uint32_t unicode,
|
|
53 int x,
|
|
54 int y,
|
|
55 unsigned int width,
|
|
56 unsigned int height,
|
|
57 const Orthanc::IDynamicObject* payload)
|
|
58 {
|
|
59 int left = x + offsetX_;
|
|
60 int top = y + offsetY_;
|
|
61
|
|
62 assert(payload != NULL);
|
|
63 const DynamicBitmap& glyph = *dynamic_cast<const DynamicBitmap*>(payload);
|
|
64
|
|
65 assert(left >= 0 &&
|
|
66 top >= 0 &&
|
|
67 static_cast<unsigned int>(left) + width <= target_.GetWidth() &&
|
|
68 static_cast<unsigned int>(top) + height <= target_.GetHeight() &&
|
|
69 width == glyph.GetBitmap().GetWidth() &&
|
|
70 height == glyph.GetBitmap().GetHeight());
|
|
71
|
|
72 {
|
|
73 Orthanc::ImageAccessor region;
|
|
74 target_.GetRegion(region, left, top, width, height);
|
|
75 Orthanc::ImageProcessing::Copy(region, glyph.GetBitmap());
|
|
76 }
|
|
77 }
|
|
78 };
|
|
79
|
|
80
|
|
81 #if ORTHANC_ENABLE_LOCALE == 1
|
|
82 void GlyphBitmapAlphabet::LoadCodepage(FontRenderer& renderer,
|
|
83 Orthanc::Encoding codepage)
|
|
84 {
|
|
85 for (unsigned int i = 0; i < 256; i++)
|
|
86 {
|
|
87 uint32_t unicode;
|
|
88 if (GlyphAlphabet::GetUnicodeFromCodepage(unicode, i, codepage))
|
|
89 {
|
|
90 AddUnicodeCharacter(renderer, unicode);
|
|
91 }
|
|
92 }
|
|
93 }
|
|
94 #endif
|
|
95
|
|
96
|
|
97 Orthanc::ImageAccessor* GlyphBitmapAlphabet::RenderText(const std::string& utf8) const
|
|
98 {
|
|
99 TextBoundingBox box(alphabet_, utf8);
|
|
100
|
|
101 std::auto_ptr<Orthanc::ImageAccessor> bitmap(
|
|
102 new Orthanc::Image(Orthanc::PixelFormat_Grayscale8,
|
|
103 box.GetWidth(), box.GetHeight(),
|
|
104 true /* force minimal pitch */));
|
|
105
|
|
106 Orthanc::ImageProcessing::Set(*bitmap, 0);
|
|
107
|
|
108 RenderTextVisitor visitor(*bitmap, *this, -box.GetLeft(), -box.GetTop());
|
|
109 alphabet_.Apply(visitor, utf8);
|
|
110
|
|
111 return bitmap.release();
|
|
112 }
|
|
113 }
|