annotate Framework/Scene2D/CairoCompositor.cpp @ 1089:998d9e4402e0 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Oct 2019 11:04:47 +0200
parents 1091b2adeb5a
children d10d2acb8a02 2d8ab34c8c91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "CairoCompositor.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "Internals/CairoColorTextureRenderer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "Internals/CairoFloatTextureRenderer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "Internals/CairoInfoPanelRenderer.h"
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
27 #include "Internals/CairoLookupTableTextureRenderer.h"
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "Internals/CairoPolylineRenderer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "Internals/CairoTextRenderer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <Core/OrthancException.h>
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 cairo_t* CairoCompositor::GetCairoContext()
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (context_.get() == NULL)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 return context_->GetObject();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 Internals::CompositorHelper::ILayerRenderer* CairoCompositor::Create(const ISceneLayer& layer)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 switch (layer.GetType())
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 case ISceneLayer::Type_Polyline:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return new Internals::CairoPolylineRenderer(*this, layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 case ISceneLayer::Type_InfoPanel:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return new Internals::CairoInfoPanelRenderer(*this, layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 case ISceneLayer::Type_ColorTexture:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return new Internals::CairoColorTextureRenderer(*this, layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 case ISceneLayer::Type_FloatTexture:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return new Internals::CairoFloatTextureRenderer(*this, layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
768
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
63 case ISceneLayer::Type_LookupTableTexture:
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
64 return new Internals::CairoLookupTableTextureRenderer(*this, layer);
55411e7da2f7 LookupTableTextureSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 600
diff changeset
65
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 case ISceneLayer::Type_Text:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 const TextSceneLayer& l = dynamic_cast<const TextSceneLayer&>(layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 Fonts::const_iterator found = fonts_.find(l.GetFontIndex());
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if (found == fonts_.end())
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return NULL;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 assert(found->second != NULL);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return new Internals::CairoTextRenderer(*this, *found->second, l);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 default:
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 return NULL;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
600
6129b1e5ba42 BasicScene SDL sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 598
diff changeset
88 CairoCompositor::CairoCompositor(const Scene2D& scene,
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 unsigned int canvasWidth,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 unsigned int canvasHeight) :
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 helper_(scene, *this)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
909
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
93 UpdateSize(canvasWidth, canvasHeight);
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
94 }
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
95
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
96 void CairoCompositor::UpdateSize(unsigned int canvasWidth,
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
97 unsigned int canvasHeight)
7a7e4e1f558f SdlCairo resizable
Alain Mazy <alain@mazy.be>
parents: 768
diff changeset
98 {
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 canvas_.SetSize(canvasWidth, canvasHeight, false);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 CairoCompositor::~CairoCompositor()
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 for (Fonts::iterator it = fonts_.begin(); it != fonts_.end(); ++it)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 assert(it->second != NULL);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 delete it->second;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 void CairoCompositor::SetFont(size_t index,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 GlyphBitmapAlphabet* dict) // Takes ownership
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 if (dict == NULL)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 std::auto_ptr<GlyphBitmapAlphabet> protection(dict);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 Fonts::iterator found = fonts_.find(index);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 if (found == fonts_.end())
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 fonts_[index] = protection.release();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 assert(found->second != NULL);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 delete found->second;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 found->second = protection.release();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 #if ORTHANC_ENABLE_LOCALE == 1
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 void CairoCompositor::SetFont(size_t index,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 Orthanc::EmbeddedResources::FileResourceId resource,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 unsigned int fontSize,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 Orthanc::Encoding codepage)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 FontRenderer renderer;
598
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 597
diff changeset
147 renderer.LoadFont(resource, fontSize);
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 std::auto_ptr<GlyphBitmapAlphabet> alphabet(new GlyphBitmapAlphabet);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 alphabet->LoadCodepage(renderer, codepage);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 SetFont(index, alphabet.release());
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 #endif
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 void CairoCompositor::Refresh()
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 context_.reset(new CairoContext(canvas_));
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 // https://www.cairographics.org/FAQ/#clear_a_surface
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 cairo_set_source_rgba(context_->GetObject(), 0, 0, 0, 255);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 cairo_paint(context_->GetObject());
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 helper_.Refresh(canvas_.GetWidth(), canvas_.GetHeight());
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 context_.reset();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 Orthanc::ImageAccessor* CairoCompositor::RenderText(size_t fontIndex,
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 const std::string& utf8) const
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 Fonts::const_iterator found = fonts_.find(fontIndex);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 if (found == fonts_.end())
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 return NULL;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 assert(found->second != NULL);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 return found->second->RenderText(utf8);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }