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