/src/libreoffice/sd/source/ui/inc/SlideshowLayerRenderer.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <rtl/string.hxx> |
13 | | #include <sal/log.hxx> |
14 | | #include <sddllapi.h> |
15 | | #include <svx/unoapi.hxx> |
16 | | #include <tools/gen.hxx> |
17 | | #include <tools/helpers.hxx> |
18 | | |
19 | | #include <CustomAnimationEffect.hxx> |
20 | | |
21 | | #include <deque> |
22 | | #include <vector> |
23 | | #include <optional> |
24 | | #include <unordered_map> |
25 | | #include <unordered_set> |
26 | | #include <drawinglayer/primitive2d/CommonTypes.hxx> |
27 | | #include <drawinglayer/primitive2d/baseprimitive2d.hxx> |
28 | | |
29 | | #include <frozen/bits/defines.h> |
30 | | #include <frozen/bits/elsa_std.h> |
31 | | #include <frozen/unordered_set.h> |
32 | | #include <tools/color.hxx> |
33 | | |
34 | | class SdrPage; |
35 | | class SdrModel; |
36 | | class SdrObject; |
37 | | |
38 | | namespace sdr::contact |
39 | | { |
40 | | class ViewObjectContactRedirector; |
41 | | } |
42 | | |
43 | | namespace sd |
44 | | { |
45 | | constexpr auto constNonValidEffectsForGroupSet = frozen::make_unordered_set<std::string_view>({ |
46 | | "ooo-emphasis-fill-color", |
47 | | "ooo-emphasis-font-color", |
48 | | "ooo-emphasis-line-color", |
49 | | "ooo-emphasis-color-blend", |
50 | | "ooo-emphasis-complementary-color", |
51 | | "ooo-emphasis-complementary-color-2", |
52 | | "ooo-emphasis-contrasting-color", |
53 | | "ooo-emphasis-darken", |
54 | | "ooo-emphasis-desaturate", |
55 | | "ooo-emphasis-flash-bulb", |
56 | | "ooo-emphasis-lighten", |
57 | | "ooo-emphasis-grow-with-color", |
58 | | }); |
59 | | |
60 | | class RenderContext; |
61 | | |
62 | | enum class RenderStage |
63 | | { |
64 | | Background = 0, |
65 | | Master = 1, |
66 | | Slide = 2, |
67 | | TextFields = 3, |
68 | | }; |
69 | | |
70 | | struct AnimationLayerInfo |
71 | | { |
72 | | OString msHash; |
73 | | std::optional<bool> moInitiallyVisible; |
74 | | }; |
75 | | |
76 | | struct AnimationRenderInfo |
77 | | { |
78 | | std::optional<AnimationLayerInfo> moObjectInfo; |
79 | | std::vector<sal_Int32> maParagraphs; |
80 | | std::unordered_map<sal_Int32, AnimationLayerInfo> maParagraphInfos; |
81 | | }; |
82 | | |
83 | | // Holds information used when doing one rendering pass |
84 | | struct RenderPass |
85 | | { |
86 | | RenderStage meStage = RenderStage::Background; |
87 | | std::unordered_map<SdrObject*, std::deque<sal_Int32>> maObjectsAndParagraphs; |
88 | | bool mbRenderObjectBackground = false; |
89 | | |
90 | | bool mbAnimation = false; |
91 | | SdrObject* mpObject = nullptr; |
92 | | sal_Int32 mnParagraph = -1; |
93 | | bool mbPlaceholder = false; |
94 | | OUString maFieldType; |
95 | | |
96 | | Color maFontColor = COL_AUTO; |
97 | | |
98 | 0 | bool isEmpty() { return maObjectsAndParagraphs.empty(); } |
99 | | }; |
100 | | |
101 | | /** Holds rendering state, properties and switches through all rendering passes */ |
102 | | struct RenderState |
103 | | { |
104 | | std::deque<RenderPass> maRenderPasses; |
105 | | std::vector<RenderPass> maTextFields; |
106 | | |
107 | | RenderStage meStage = RenderStage::Background; |
108 | | |
109 | | std::unordered_map<SdrObject*, AnimationRenderInfo> maAnimationRenderInfoList; |
110 | | |
111 | | std::array<sal_Int32, 4> maIndices = { 0, 0, 0, 0 }; |
112 | | |
113 | | std::vector<drawinglayer::primitive2d::Primitive2DReference> maPrimitivesToUnhide; |
114 | | |
115 | | bool mbShowMasterPageObjects = false; |
116 | | bool mbFooterEnabled = false; |
117 | | bool mbDateTimeEnabled = false; |
118 | | bool mbSlideNumberEnabled = false; |
119 | | |
120 | | /// increments index depending on the current render stage |
121 | 0 | void incrementIndex() { maIndices[size_t(meStage)]++; } |
122 | | |
123 | | /// returns the current stage as string |
124 | | OString stageString() const |
125 | 0 | { |
126 | 0 | if (meStage == RenderStage::Master) |
127 | 0 | return "MasterPage"_ostr; |
128 | 0 | else if (meStage == RenderStage::Background) |
129 | 0 | return "Background"_ostr; |
130 | 0 | else if (meStage == RenderStage::TextFields) |
131 | 0 | return "TextFields"_ostr; |
132 | 0 | return "DrawPage"_ostr; |
133 | 0 | } |
134 | | |
135 | | /// returns the current index depending on the current render stage |
136 | 0 | sal_Int32 currentIndex() const { return maIndices[size_t(meStage)]; } |
137 | | |
138 | | /// should include background in rendering |
139 | 0 | bool includeBackground() const { return meStage == RenderStage::Background; } |
140 | | }; |
141 | | |
142 | | /** Renders a slide */ |
143 | | class SD_DLLPUBLIC SlideshowLayerRenderer |
144 | | { |
145 | | private: |
146 | | SdrPage& mrPage; |
147 | | OString msSlideHash; |
148 | | SdrModel& mrModel; |
149 | | Size maSlideSize; |
150 | | RenderState maRenderState; |
151 | | bool mbRenderBackground; |
152 | | bool mbRenderMasterPage; |
153 | | |
154 | | void createViewAndDraw(const RenderContext& rRenderContext, |
155 | | sdr::contact::ViewObjectContactRedirector* pRedirector); |
156 | | void writeBackgroundJSON(OString& rJsonMsg); |
157 | | void writeJSON(OString& rJsonMsg, RenderPass const& rRenderPass); |
158 | | |
159 | | void setupAnimations(); |
160 | | void setupMasterPageFields(); |
161 | | void resolveEffect(CustomAnimationEffectPtr const& rEffect); |
162 | | void cleanup(); |
163 | | |
164 | | public: |
165 | | SlideshowLayerRenderer(SdrPage& rPage, const OString& rSlideHash, bool bRenderBackground, |
166 | | bool bRenderMasterPage); |
167 | | |
168 | | /** Calculate and set the slide size depending on input desired size (in pixels) |
169 | | * |
170 | | * Input the desired size in pixels, and the actual size pixels will be calculated |
171 | | * depending on the size of the slide and the desired size. The size can differ, |
172 | | * because the it must match the slide aspect ratio. |
173 | | **/ |
174 | | Size calculateAndSetSizePixel(Size const& rDesiredSizePixel); |
175 | | |
176 | | /** Renders one layer |
177 | | * |
178 | | * The slide layer is rendered into the input buffer, which must be the byte size |
179 | | * of the calculated size in pixels * 4 (RGBA). |
180 | | * The properties of the layer are written to the input string in JSON format. |
181 | | * |
182 | | * @returns false, if nothing was rendered and rendering is done */ |
183 | | bool render(unsigned char* pBuffer, bool& bIsBitmapLayer, double& scale, OString& rJsonMsg); |
184 | | }; |
185 | | |
186 | | } // end of namespace sd |
187 | | |
188 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |