Mercurial > hg > orthanc
annotate Core/Images/Font.cpp @ 3951:5fe8c6d3212e transcoding
removed useless information "hasSopInstanceUidChanged"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 May 2020 21:06:53 +0200 |
parents | 2a170a8f1faf |
children | 058b5ade8acd |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
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 * 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
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "Font.h" |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
37 #if !defined(ORTHANC_ENABLE_LOCALE) |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
38 # 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
|
39 #endif |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
40 |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
41 #if ORTHANC_SANDBOXED == 0 |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
42 # include "../SystemToolbox.h" |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
43 #endif |
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
44 |
2900 | 45 #include "../OrthancException.h" |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 #include "../Toolbox.h" |
2900 | 47 #include "Image.h" |
48 #include "ImageProcessing.h" | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 #include <stdio.h> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 #include <memory> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 #include <boost/lexical_cast.hpp> |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 namespace Orthanc |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 Font::~Font() |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 for (Characters::iterator it = characters_.begin(); |
1616 | 59 it != characters_.end(); ++it) |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 delete it->second; |
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 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 void Font::LoadFromMemory(const std::string& font) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 Json::Value v; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 Json::Reader reader; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 if (!reader.parse(font, v) || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 v.type() != Json::objectValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 !v.isMember("Name") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 !v.isMember("Size") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 !v.isMember("Characters") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 v["Name"].type() != Json::stringValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 v["Size"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 v["Characters"].type() != Json::objectValue) |
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 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 name_ = v["Name"].asString(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 size_ = v["Size"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 maxHeight_ = 0; |
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 Json::Value::Members characters = v["Characters"].getMemberNames(); |
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 for (size_t i = 0; i < characters.size(); i++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 const Json::Value& info = v["Characters"][characters[i]]; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 if (info.type() != Json::objectValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 !info.isMember("Advance") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 !info.isMember("Bitmap") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 !info.isMember("Height") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 !info.isMember("Top") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 !info.isMember("Width") || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 info["Advance"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 info["Bitmap"].type() != Json::arrayValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 info["Height"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 info["Top"].type() != Json::intValue || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 info["Width"].type() != Json::intValue) |
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 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
106 std::unique_ptr<Character> c(new Character); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 c->advance_ = info["Advance"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 c->height_ = info["Height"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 c->top_ = info["Top"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 c->width_ = info["Width"].asUInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 c->bitmap_.resize(info["Bitmap"].size()); |
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 if (c->height_ > maxHeight_) |
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 maxHeight_ = c->height_; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 } |
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 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
|
120 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 if (info["Bitmap"][j].type() != Json::intValue) |
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 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 int value = info["Bitmap"][j].asInt(); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 if (value < 0 || value > 255) |
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 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
132 c->bitmap_[j] = static_cast<uint8_t>(value); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 int index = boost::lexical_cast<int>(characters[i]); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 if (index < 0 || index > 255) |
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 throw OrthancException(ErrorCode_BadFont); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 } |
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 characters_[static_cast<char>(index)] = c.release(); |
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 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
146 #if ORTHANC_SANDBOXED == 0 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 void Font::LoadFromFile(const std::string& path) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 std::string font; |
2140 | 150 SystemToolbox::ReadFile(font, path); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 LoadFromMemory(font); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 } |
2407
5edec967055e
fix sandboxed builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2379
diff
changeset
|
153 #endif |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 |
2913
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
156 #if ORTHANC_HAS_EMBEDDED_RESOURCES == 1 |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
157 void Font::LoadFromResource(EmbeddedResources::FileResourceId resource) |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
158 { |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
159 std::string content; |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
160 EmbeddedResources::GetFileResource(content, resource); |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
161 LoadFromMemory(content); |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
162 } |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
163 #endif |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
164 |
058851941abe
Font::LoadFromResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2901
diff
changeset
|
165 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 static unsigned int MyMin(unsigned int a, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 unsigned int 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 return a < b ? a : b; |
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 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 void Font::DrawCharacter(ImageAccessor& target, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 const Character& character, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 int x, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 int y, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 const uint8_t color[4]) const |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 // Compute the bounds of the character |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 if (x >= static_cast<int>(target.GetWidth()) || |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 y >= static_cast<int>(target.GetHeight())) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 // The character is out of the image |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 return; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 unsigned int left = x < 0 ? -x : 0; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 unsigned int top = y < 0 ? -y : 0; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 unsigned int width = MyMin(character.width_, target.GetWidth() - x); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 unsigned int height = MyMin(character.height_, target.GetHeight() - y); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
192 unsigned int bpp = target.GetBytesPerPixel(); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 // Blit the font bitmap OVER the target image |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 // https://en.wikipedia.org/wiki/Alpha_compositing |
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 for (unsigned int cy = top; cy < height; cy++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 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
|
200 unsigned int pos = cy * character.width_ + left; |
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 switch (target.GetFormat()) |
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 case PixelFormat_Grayscale8: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 assert(bpp == 1); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
207 for (unsigned int cx = left; cx < width; cx++, pos++, p++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 uint16_t alpha = character.bitmap_[pos]; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
210 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
|
211 *p = static_cast<uint8_t>(value >> 8); |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 } |
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 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 } |
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 case PixelFormat_RGB24: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 assert(bpp == 3); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 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
|
221 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 uint16_t alpha = character.bitmap_[pos]; |
1654
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
223 for (uint8_t i = 0; i < 3; i++) |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
224 { |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
225 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
|
226 p[i] = static_cast<uint8_t>(value >> 8); |
3727a09e7b53
fix some icc warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1616
diff
changeset
|
227 } |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 } |
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 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 case PixelFormat_RGBA32: |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
234 case PixelFormat_BGRA32: |
1610
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 assert(bpp == 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 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
|
239 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 float alpha = static_cast<float>(character.bitmap_[pos]) / 255.0f; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 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
|
242 float denom = 1.0f / (alpha + beta); |
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 for (uint8_t i = 0; i < 3; i++) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 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
|
247 beta * static_cast<float>(p[i])) * denom); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 } |
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 p[3] = static_cast<uint8_t>(255.0f * (alpha + beta)); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 } |
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 break; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 default: |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 throw OrthancException(ErrorCode_NotImplemented); |
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 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 void Font::DrawInternal(ImageAccessor& target, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 const std::string& utf8, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 int x, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 int y, |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 const uint8_t color[4]) const |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 if (target.GetFormat() != PixelFormat_Grayscale8 && |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 target.GetFormat() != PixelFormat_RGB24 && |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
272 target.GetFormat() != PixelFormat_RGBA32 && |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
273 target.GetFormat() != PixelFormat_BGRA32) |
1610
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 throw OrthancException(ErrorCode_NotImplemented); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 int a = x; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
280 #if ORTHANC_ENABLE_LOCALE == 1 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 std::string s = Toolbox::ConvertFromUtf8(utf8, Encoding_Latin1); |
2379
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
282 #else |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
283 // If the locale support is disabled, simply drop non-ASCII |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
284 // characters from the source UTF-8 string |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
285 std::string s = Toolbox::ConvertToAscii(utf8); |
4900688827a8
reorganization in CMake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
286 #endif |
1610
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 for (size_t i = 0; i < s.size(); i++) |
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 if (s[i] == '\n') |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 // Go to the next line |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 a = x; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 y += maxHeight_ + 1; |
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 else |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 Characters::const_iterator c = characters_.find(s[i]); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 if (c != characters_.end()) |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 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
|
302 a += c->second->advance_; |
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 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 |
1611
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
309 void Font::Draw(ImageAccessor& target, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
310 const std::string& utf8, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
311 int x, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
312 int y, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
313 uint8_t grayscale) const |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 { |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 uint8_t color[4] = { grayscale, grayscale, grayscale, 255 }; |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 DrawInternal(target, utf8, x, y, color); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 |
1611
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
320 void Font::Draw(ImageAccessor& target, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
321 const std::string& utf8, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
322 int x, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
323 int y, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
324 uint8_t r, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
325 uint8_t g, |
5e9b2aac8b89
fix for visual studio
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1610
diff
changeset
|
326 uint8_t b) const |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 { |
2853
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
328 uint8_t color[4]; |
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 switch (target.GetFormat()) |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
331 { |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
332 case PixelFormat_BGRA32: |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
333 color[0] = b; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
334 color[1] = g; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
335 color[2] = r; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
336 color[3] = 255; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
337 break; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
338 |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
339 default: |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
340 color[0] = r; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
341 color[1] = g; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
342 color[2] = b; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
343 color[3] = 255; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
344 break; |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
345 } |
52b017d22a4f
New URI: "/studies/.../merge" to merge a study
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
346 |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 DrawInternal(target, utf8, x, y, color); |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 } |
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 |
2900 | 350 |
351 void Font::ComputeTextExtent(unsigned int& width, | |
352 unsigned int& height, | |
353 const std::string& utf8) const | |
354 { | |
355 width = 0; | |
2914 | 356 height = 0; |
2900 | 357 |
358 #if ORTHANC_ENABLE_LOCALE == 1 | |
359 std::string s = Toolbox::ConvertFromUtf8(utf8, Encoding_Latin1); | |
360 #else | |
361 // If the locale support is disabled, simply drop non-ASCII | |
362 // characters from the source UTF-8 string | |
363 std::string s = Toolbox::ConvertToAscii(utf8); | |
364 #endif | |
365 | |
366 // Compute the text extent | |
367 unsigned int x = 0; | |
2901 | 368 unsigned int y = 0; |
2900 | 369 |
370 for (size_t i = 0; i < s.size(); i++) | |
371 { | |
372 if (s[i] == '\n') | |
373 { | |
374 // Go to the next line | |
375 x = 0; | |
2901 | 376 y += (maxHeight_ + 1); |
2900 | 377 } |
378 else | |
379 { | |
380 Characters::const_iterator c = characters_.find(s[i]); | |
381 if (c != characters_.end()) | |
382 { | |
383 x += c->second->advance_; | |
384 | |
2901 | 385 unsigned int bottom = y + c->second->top_ + c->second->height_; |
386 if (bottom > height) | |
2900 | 387 { |
2901 | 388 height = bottom; |
2900 | 389 } |
390 | |
391 if (x > width) | |
392 { | |
393 width = x; | |
394 } | |
395 } | |
396 } | |
397 } | |
398 } | |
399 | |
400 | |
401 ImageAccessor* Font::Render(const std::string& utf8, | |
402 PixelFormat format, | |
403 uint8_t r, | |
404 uint8_t g, | |
405 uint8_t b) const | |
406 { | |
407 unsigned int width, height; | |
408 ComputeTextExtent(width, height, utf8); | |
409 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
410 std::unique_ptr<ImageAccessor> target(new Image(format, width, height, false)); |
2900 | 411 ImageProcessing::Set(*target, 0, 0, 0, 255); |
412 Draw(*target, utf8, 0, 0, r, g, b); | |
413 | |
414 return target.release(); | |
415 } | |
416 | |
417 | |
418 ImageAccessor* Font::RenderAlpha(const std::string& utf8) const | |
419 { | |
420 unsigned int width, height; | |
421 ComputeTextExtent(width, height, utf8); | |
422 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
423 std::unique_ptr<ImageAccessor> target(new Image(PixelFormat_Grayscale8, width, height, false)); |
2900 | 424 ImageProcessing::Set(*target, 0); |
425 Draw(*target, utf8, 0, 0, 255); | |
426 | |
427 return target.release(); | |
428 } | |
1610
2dff2bdffdb8
font support within Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 } |