annotate Framework/Fonts/FontRenderer.cpp @ 1290:7def6ab2929f bugs/2020-02-invisible-slice

Removal of debugging logs
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 21 Feb 2020 15:20:29 +0100
parents 2d8ab34c8c91
children 8a0a62189f46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
576
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
576
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "FontRenderer.h"
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../Toolbox/DynamicBitmap.h"
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/OrthancException.h>
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <ft2build.h>
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include FT_FREETYPE_H
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include FT_GLYPH_H
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 // https://stackoverflow.com/questions/31161284/how-can-i-get-the-corresponding-error-string-from-an-ft-error-code
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static std::string GetErrorMessage(FT_Error err)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #undef __FTERRORS_H__
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #define FT_ERRORDEF( e, v, s ) case e: return s;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #define FT_ERROR_START_LIST switch (err) {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #define FT_ERROR_END_LIST }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include FT_ERRORS_H
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 return "(Unknown error)";
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static void CheckError(FT_Error err)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if (err != 0)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 "Error in FreeType: " + GetErrorMessage(err));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 namespace OrthancStone
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 class FontRenderer::PImpl : public boost::noncopyable
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 private:
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 std::string fontContent_;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 FT_Library library_;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 FT_Face face_;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 void Clear()
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (face_ != NULL)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 FT_Done_Face(face_);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 face_ = NULL;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 fontContent_.clear();
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 public:
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 PImpl() :
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 library_(NULL),
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 face_(NULL)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 CheckError(FT_Init_FreeType(&library_));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 ~PImpl()
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 Clear();
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 FT_Done_FreeType(library_);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 void LoadFont(const std::string& fontContent,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 unsigned int fontSize)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 Clear();
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 // It is necessary to make a private copy of the font, as
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // Freetype makes the assumption that the buffer containing the
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 // font is never deleted
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 fontContent_.assign(fontContent);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const FT_Byte* data = reinterpret_cast<const FT_Byte*>(fontContent_.c_str());
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 576
diff changeset
104 CheckError(FT_New_Memory_Face(
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 576
diff changeset
105 library_, data, static_cast<FT_Long>(fontContent_.size()), 0, &face_));
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 576
diff changeset
106
576
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 CheckError(FT_Set_Char_Size(face_, // handle to face object
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 0, // char_width in 1/64th of points
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 fontSize * 64, // char_height in 1/64th of points
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 72, // horizontal device resolution
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 72)); // vertical device resolution
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 CheckError(FT_Select_Charmap(face_, FT_ENCODING_UNICODE));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 Glyph* Render(uint32_t unicode)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 if (face_ == NULL)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 "First call LoadFont()");
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 else if (FT_Load_Char(face_, unicode, FT_LOAD_RENDER) != 0)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 // This character is not available
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 return NULL;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 else
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 if (face_->glyph->format != FT_GLYPH_FORMAT_BITMAP)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 //CheckError(FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 Orthanc::ImageAccessor bitmap;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 bitmap.AssignReadOnly(Orthanc::PixelFormat_Grayscale8,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 face_->glyph->bitmap.width,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 face_->glyph->bitmap.rows,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 face_->glyph->bitmap.pitch,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 face_->glyph->bitmap.buffer);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 std::auto_ptr<Glyph> glyph(
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 new Glyph(bitmap.GetWidth(),
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 bitmap.GetHeight(),
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 face_->glyph->bitmap_left,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 -face_->glyph->bitmap_top, // Positive for an upwards vertical distance
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 face_->glyph->advance.x >> 6,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 face_->glyph->metrics.vertAdvance >> 6));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 glyph->SetPayload(new DynamicBitmap(bitmap));
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 return glyph.release();
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 };
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 FontRenderer::FontRenderer() :
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 pimpl_(new PImpl)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 void FontRenderer::LoadFont(const std::string& fontContent,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 unsigned int fontSize)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 pimpl_->LoadFont(fontContent, fontSize);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 void FontRenderer::LoadFont(Orthanc::EmbeddedResources::FileResourceId resource,
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 unsigned int fontSize)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 std::string content;
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 Orthanc::EmbeddedResources::GetFileResource(content, resource);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 LoadFont(content, fontSize);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 Glyph* FontRenderer::Render(uint32_t unicode)
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return pimpl_->Render(unicode);
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
529c9617654b FontRenderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }