Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Images/Font.cpp @ 5853:4d932683049d get-scu tip
very first implementation of C-Get SCU
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Tue, 29 Oct 2024 17:25:49 +0100 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5468
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 **/ |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../PrecompiledHeaders.h" |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "Font.h" |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
28 #if !defined(ORTHANC_ENABLE_LOCALE) |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
29 # error ORTHANC_ENABLE_LOCALE must be defined to use this file |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
30 #endif |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
31 |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
32 #if ORTHANC_SANDBOXED == 0 |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
33 # include "../SystemToolbox.h" |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
34 #endif |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
35 |
2900 | 36 #include "../OrthancException.h" |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include "../Toolbox.h" |
2900 | 38 #include "Image.h" |
39 #include "ImageProcessing.h" | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
5468
47334eeaaa1a
fix build on opensuse
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
41 #include <cassert> |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 #include <stdio.h> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 #include <memory> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 #include <boost/lexical_cast.hpp> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 namespace Orthanc |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
4297 | 48 Font::Font() : |
49 size_(0), | |
50 maxHeight_(0) | |
51 { | |
52 } | |
53 | |
54 | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 Font::~Font() |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 for (Characters::iterator it = characters_.begin(); |
1616 | 58 it != characters_.end(); ++it) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 delete it->second; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 void Font::LoadFromMemory(const std::string& font) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 Json::Value v; |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4297
diff
changeset
|
68 if (!Toolbox::ReadJson(v, font) || |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 v.type() != Json::objectValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 !v.isMember("Name") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 !v.isMember("Size") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 !v.isMember("Characters") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 v["Name"].type() != Json::stringValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 v["Size"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 v["Characters"].type() != Json::objectValue) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 name_ = v["Name"].asString(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 size_ = v["Size"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 maxHeight_ = 0; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 Json::Value::Members characters = v["Characters"].getMemberNames(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 for (size_t i = 0; i < characters.size(); i++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 const Json::Value& info = v["Characters"][characters[i]]; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 if (info.type() != Json::objectValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 !info.isMember("Advance") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 !info.isMember("Bitmap") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 !info.isMember("Height") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 !info.isMember("Top") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 !info.isMember("Width") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 info["Advance"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 info["Bitmap"].type() != Json::arrayValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 info["Height"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 info["Top"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 info["Width"].type() != Json::intValue) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
104 std::unique_ptr<Character> c(new Character); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 c->advance_ = info["Advance"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 c->height_ = info["Height"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 c->top_ = info["Top"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 c->width_ = info["Width"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 c->bitmap_.resize(info["Bitmap"].size()); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 if (c->height_ > maxHeight_) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 maxHeight_ = c->height_; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 for (Json::Value::ArrayIndex j = 0; j < info["Bitmap"].size(); j++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 if (info["Bitmap"][j].type() != Json::intValue) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 int value = info["Bitmap"][j].asInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 if (value < 0 || value > 255) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
130 c->bitmap_[j] = static_cast<uint8_t>(value); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 int index = boost::lexical_cast<int>(characters[i]); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 if (index < 0 || index > 255) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 characters_[static_cast<char>(index)] = c.release(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
144 #if ORTHANC_SANDBOXED == 0 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 void Font::LoadFromFile(const std::string& path) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 std::string font; |
2140 | 148 SystemToolbox::ReadFile(font, path); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 LoadFromMemory(font); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 } |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
151 #endif |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
4297 | 153 const std::string &Font::GetName() const |
154 { | |
155 return name_; | |
156 } | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
4297 | 158 unsigned int Font::GetSize() const |
159 { | |
160 return size_; | |
161 } | |
162 | |
163 | |
164 static unsigned int MyMin(unsigned int a, | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 unsigned int b) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 return a < b ? a : b; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 void Font::DrawCharacter(ImageAccessor& target, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 const Character& character, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 int x, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 int y, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 const uint8_t color[4]) const |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 // Compute the bounds of the character |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 if (x >= static_cast<int>(target.GetWidth()) || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 y >= static_cast<int>(target.GetHeight())) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 // The character is out of the image |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 unsigned int left = x < 0 ? -x : 0; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 unsigned int top = y < 0 ? -y : 0; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 unsigned int width = MyMin(character.width_, target.GetWidth() - x); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 unsigned int height = MyMin(character.height_, target.GetHeight() - y); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
190 unsigned int bpp = target.GetBytesPerPixel(); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 // Blit the font bitmap OVER the target image |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 // https://en.wikipedia.org/wiki/Alpha_compositing |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 for (unsigned int cy = top; cy < height; cy++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 uint8_t* p = reinterpret_cast<uint8_t*>(target.GetRow(y + cy)) + (x + left) * bpp; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 unsigned int pos = cy * character.width_ + left; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 switch (target.GetFormat()) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 case PixelFormat_Grayscale8: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 assert(bpp == 1); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 for (unsigned int cx = left; cx < width; cx++, pos++, p++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 uint16_t alpha = character.bitmap_[pos]; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
208 uint16_t value = alpha * static_cast<uint16_t>(color[0]) + (255 - alpha) * static_cast<uint16_t>(*p); |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
209 *p = static_cast<uint8_t>(value >> 8); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 case PixelFormat_RGB24: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 assert(bpp == 3); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 for (unsigned int cx = left; cx < width; cx++, pos++, p += 3) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 uint16_t alpha = character.bitmap_[pos]; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
221 for (uint8_t i = 0; i < 3; i++) |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
222 { |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
223 uint16_t value = alpha * static_cast<uint16_t>(color[i]) + (255 - alpha) * static_cast<uint16_t>(p[i]); |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
224 p[i] = static_cast<uint8_t>(value >> 8); |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
225 } |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 case PixelFormat_RGBA32: |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 case PixelFormat_BGRA32: |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 assert(bpp == 4); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 for (unsigned int cx = left; cx < width; cx++, pos++, p += 4) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 float alpha = static_cast<float>(character.bitmap_[pos]) / 255.0f; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 float beta = (1.0f - alpha) * static_cast<float>(p[3]) / 255.0f; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 float denom = 1.0f / (alpha + beta); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 for (uint8_t i = 0; i < 3; i++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 p[i] = static_cast<uint8_t>((alpha * static_cast<float>(color[i]) + |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 beta * static_cast<float>(p[i])) * denom); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 p[3] = static_cast<uint8_t>(255.0f * (alpha + beta)); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 default: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 throw OrthancException(ErrorCode_NotImplemented); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 void Font::DrawInternal(ImageAccessor& target, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 const std::string& utf8, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 int x, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 int y, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 const uint8_t color[4]) const |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 if (target.GetFormat() != PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 target.GetFormat() != PixelFormat_RGB24 && |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
270 target.GetFormat() != PixelFormat_RGBA32 && |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
271 target.GetFormat() != PixelFormat_BGRA32) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 throw OrthancException(ErrorCode_NotImplemented); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 int a = x; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
278 #if ORTHANC_ENABLE_LOCALE == 1 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 std::string s = Toolbox::ConvertFromUtf8(utf8, Encoding_Latin1); |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
280 #else |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
281 // If the locale support is disabled, simply drop non-ASCII |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
282 // characters from the source UTF-8 string |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
283 std::string s = Toolbox::ConvertToAscii(utf8); |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
284 #endif |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 for (size_t i = 0; i < s.size(); i++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 if (s[i] == '\n') |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 // Go to the next line |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 a = x; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 y += maxHeight_ + 1; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 else |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 Characters::const_iterator c = characters_.find(s[i]); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 if (c != characters_.end()) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 DrawCharacter(target, *c->second, a, y + static_cast<int>(c->second->top_), color); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 a += c->second->advance_; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 |
1611
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
307 void Font::Draw(ImageAccessor& target, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
308 const std::string& utf8, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
309 int x, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
310 int y, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
311 uint8_t grayscale) const |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 uint8_t color[4] = { grayscale, grayscale, grayscale, 255 }; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 DrawInternal(target, utf8, x, y, color); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 |
1611
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
318 void Font::Draw(ImageAccessor& target, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
319 const std::string& utf8, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
320 int x, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
321 int y, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
322 uint8_t r, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
323 uint8_t g, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
324 uint8_t b) const |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 { |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
326 uint8_t color[4]; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
327 |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
328 switch (target.GetFormat()) |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
329 { |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
330 case PixelFormat_BGRA32: |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
331 color[0] = b; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
332 color[1] = g; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
333 color[2] = r; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
334 color[3] = 255; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
335 break; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
336 |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
337 default: |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
338 color[0] = r; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
339 color[1] = g; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
340 color[2] = b; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
341 color[3] = 255; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
342 break; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
343 } |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
344 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
345 DrawInternal(target, utf8, x, y, color); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 |
2900 | 348 |
349 void Font::ComputeTextExtent(unsigned int& width, | |
350 unsigned int& height, | |
351 const std::string& utf8) const | |
352 { | |
353 width = 0; | |
2914 | 354 height = 0; |
2900 | 355 |
356 #if ORTHANC_ENABLE_LOCALE == 1 | |
357 std::string s = Toolbox::ConvertFromUtf8(utf8, Encoding_Latin1); | |
358 #else | |
359 // If the locale support is disabled, simply drop non-ASCII | |
360 // characters from the source UTF-8 string | |
361 std::string s = Toolbox::ConvertToAscii(utf8); | |
362 #endif | |
363 | |
364 // Compute the text extent | |
365 unsigned int x = 0; | |
2901 | 366 unsigned int y = 0; |
2900 | 367 |
368 for (size_t i = 0; i < s.size(); i++) | |
369 { | |
370 if (s[i] == '\n') | |
371 { | |
372 // Go to the next line | |
373 x = 0; | |
2901 | 374 y += (maxHeight_ + 1); |
2900 | 375 } |
376 else | |
377 { | |
378 Characters::const_iterator c = characters_.find(s[i]); | |
379 if (c != characters_.end()) | |
380 { | |
381 x += c->second->advance_; | |
382 | |
2901 | 383 unsigned int bottom = y + c->second->top_ + c->second->height_; |
384 if (bottom > height) | |
2900 | 385 { |
2901 | 386 height = bottom; |
2900 | 387 } |
388 | |
389 if (x > width) | |
390 { | |
391 width = x; | |
392 } | |
393 } | |
394 } | |
395 } | |
396 } | |
397 | |
398 | |
399 ImageAccessor* Font::Render(const std::string& utf8, | |
400 PixelFormat format, | |
401 uint8_t r, | |
402 uint8_t g, | |
403 uint8_t b) const | |
404 { | |
405 unsigned int width, height; | |
406 ComputeTextExtent(width, height, utf8); | |
407 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
408 std::unique_ptr<ImageAccessor> target(new Image(format, width, height, false)); |
2900 | 409 ImageProcessing::Set(*target, 0, 0, 0, 255); |
410 Draw(*target, utf8, 0, 0, r, g, b); | |
411 | |
412 return target.release(); | |
413 } | |
414 | |
415 | |
416 ImageAccessor* Font::RenderAlpha(const std::string& utf8) const | |
417 { | |
418 unsigned int width, height; | |
419 ComputeTextExtent(width, height, utf8); | |
420 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
421 std::unique_ptr<ImageAccessor> target(new Image(PixelFormat_Grayscale8, width, height, false)); |
2900 | 422 ImageProcessing::Set(*target, 0); |
423 Draw(*target, utf8, 0, 0, 255); | |
424 | |
425 return target.release(); | |
426 } | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 } |