/src/poppler/glib/poppler-layer.cc
Line | Count | Source |
1 | | /* poppler-layer.cc: glib interface to poppler |
2 | | * |
3 | | * Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org> |
4 | | * Copyright (C) 2025 Albert Astals Cid <aacid@kde.org> |
5 | | * Copyright (C) 2026 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2, or (at your option) |
10 | | * any later version. |
11 | | * |
12 | | * This program is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License |
18 | | * along with this program; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | */ |
21 | | |
22 | | #include "poppler-layer.h" |
23 | | #include "poppler-private.h" |
24 | | |
25 | | /** |
26 | | * SECTION:poppler-layer |
27 | | * @short_description: Layers |
28 | | * @title: PopplerLayer |
29 | | */ |
30 | | |
31 | | struct _PopplerLayerClass |
32 | | { |
33 | | GObjectClass parent_class; |
34 | | }; |
35 | | using PopplerLayerClass = _PopplerLayerClass; |
36 | | |
37 | 0 | G_DEFINE_TYPE(PopplerLayer, poppler_layer, G_TYPE_OBJECT) |
38 | 0 |
|
39 | 0 | static void poppler_layer_finalize(GObject *object) |
40 | 0 | { |
41 | 0 | PopplerLayer *poppler_layer = POPPLER_LAYER(object); |
42 | |
|
43 | 0 | if (poppler_layer->document) { |
44 | 0 | g_object_unref(poppler_layer->document); |
45 | 0 | poppler_layer->document = nullptr; |
46 | 0 | } |
47 | |
|
48 | 0 | if (poppler_layer->title) { |
49 | 0 | g_free(poppler_layer->title); |
50 | 0 | poppler_layer->title = nullptr; |
51 | 0 | } |
52 | 0 | poppler_layer->layer = nullptr; |
53 | 0 | poppler_layer->rbgroup = nullptr; |
54 | |
|
55 | 0 | G_OBJECT_CLASS(poppler_layer_parent_class)->finalize(object); |
56 | 0 | } |
57 | | |
58 | 0 | static void poppler_layer_init(PopplerLayer * /*layer*/) { } |
59 | | |
60 | | static void poppler_layer_class_init(PopplerLayerClass *klass) |
61 | 0 | { |
62 | 0 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
63 | |
|
64 | 0 | gobject_class->finalize = poppler_layer_finalize; |
65 | 0 | } |
66 | | |
67 | | PopplerLayer *_poppler_layer_new(PopplerDocument *document, Layer *layer, GList *rbgroup) |
68 | 0 | { |
69 | 0 | PopplerLayer *poppler_layer; |
70 | 0 | const GooString *layer_name; |
71 | |
|
72 | 0 | g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL); |
73 | 0 | g_return_val_if_fail(layer != nullptr, NULL); |
74 | | |
75 | 0 | poppler_layer = POPPLER_LAYER(g_object_new(POPPLER_TYPE_LAYER, nullptr)); |
76 | |
|
77 | 0 | poppler_layer->document = static_cast<PopplerDocument *> g_object_ref(document); |
78 | 0 | poppler_layer->layer = layer; |
79 | 0 | poppler_layer->rbgroup = rbgroup; |
80 | 0 | layer_name = layer->oc->getName(); |
81 | 0 | poppler_layer->title = layer_name ? _poppler_goo_string_to_utf8(layer_name->toStr()) : nullptr; |
82 | |
|
83 | 0 | return poppler_layer; |
84 | 0 | } |
85 | | |
86 | | /** |
87 | | * poppler_layer_get_title: |
88 | | * @layer: a #PopplerLayer |
89 | | * |
90 | | * Returns the name of the layer suitable for |
91 | | * presentation as a title in a viewer's GUI |
92 | | * |
93 | | * Return value: a string containing the title of the layer |
94 | | * |
95 | | * Since: 0.12 |
96 | | **/ |
97 | | const gchar *poppler_layer_get_title(PopplerLayer *poppler_layer) |
98 | 0 | { |
99 | 0 | g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), NULL); |
100 | | |
101 | 0 | return poppler_layer->title; |
102 | 0 | } |
103 | | |
104 | | /** |
105 | | * poppler_layer_is_visible: |
106 | | * @layer: a #PopplerLayer |
107 | | * |
108 | | * Returns whether @layer is visible |
109 | | * |
110 | | * Return value: %TRUE if @layer is visible |
111 | | * |
112 | | * Since: 0.12 |
113 | | **/ |
114 | | gboolean poppler_layer_is_visible(PopplerLayer *poppler_layer) |
115 | 0 | { |
116 | 0 | g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE); |
117 | | |
118 | 0 | return poppler_layer->layer->oc->getState() == OptionalContentGroup::On; |
119 | 0 | } |
120 | | |
121 | | /** |
122 | | * poppler_layer_show: |
123 | | * @layer: a #PopplerLayer |
124 | | * |
125 | | * Shows @layer |
126 | | * |
127 | | * Since: 0.12 |
128 | | **/ |
129 | | void poppler_layer_show(PopplerLayer *poppler_layer) |
130 | 0 | { |
131 | 0 | GList *l; |
132 | 0 | Layer *layer; |
133 | |
|
134 | 0 | g_return_if_fail(POPPLER_IS_LAYER(poppler_layer)); |
135 | | |
136 | 0 | layer = poppler_layer->layer; |
137 | |
|
138 | 0 | if (layer->oc->getState() == OptionalContentGroup::On) { |
139 | 0 | return; |
140 | 0 | } |
141 | | |
142 | 0 | layer->oc->setState(OptionalContentGroup::On); |
143 | |
|
144 | 0 | for (l = poppler_layer->rbgroup; l && l->data; l = g_list_next(l)) { |
145 | 0 | auto *oc = static_cast<OptionalContentGroup *>(l->data); |
146 | |
|
147 | 0 | if (oc != layer->oc) { |
148 | 0 | oc->setState(OptionalContentGroup::Off); |
149 | 0 | } |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | | /** |
154 | | * poppler_layer_hide: |
155 | | * @layer: a #PopplerLayer |
156 | | * |
157 | | * Hides @layer. If @layer is the parent of other nested layers, |
158 | | * such layers will be also hidden and will be blocked until @layer |
159 | | * is shown again |
160 | | * |
161 | | * Since: 0.12 |
162 | | **/ |
163 | | void poppler_layer_hide(PopplerLayer *poppler_layer) |
164 | 0 | { |
165 | 0 | Layer *layer; |
166 | |
|
167 | 0 | g_return_if_fail(POPPLER_IS_LAYER(poppler_layer)); |
168 | | |
169 | 0 | layer = poppler_layer->layer; |
170 | |
|
171 | 0 | if (layer->oc->getState() == OptionalContentGroup::Off) { |
172 | 0 | return; |
173 | 0 | } |
174 | | |
175 | 0 | layer->oc->setState(OptionalContentGroup::Off); |
176 | 0 | } |
177 | | |
178 | | /** |
179 | | * poppler_layer_is_parent: |
180 | | * @layer: a #PopplerLayer |
181 | | * |
182 | | * Returns whether @layer is parent of other nested layers. |
183 | | * |
184 | | * Return value: %TRUE if @layer is a parent layer |
185 | | * |
186 | | * Since: 0.12 |
187 | | **/ |
188 | | gboolean poppler_layer_is_parent(PopplerLayer *poppler_layer) |
189 | 0 | { |
190 | 0 | g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE); |
191 | | |
192 | 0 | return poppler_layer->layer->kids != nullptr; |
193 | 0 | } |
194 | | |
195 | | /** |
196 | | * poppler_layer_get_radio_button_group_id: |
197 | | * @layer: a #PopplerLayer |
198 | | * |
199 | | * Returns the numeric ID the radio button group associated with @layer. |
200 | | * |
201 | | * Return value: the ID of the radio button group associated with @layer, |
202 | | * or 0 if the layer is not associated to any radio button group |
203 | | * |
204 | | * Since: 0.12 |
205 | | **/ |
206 | | gint poppler_layer_get_radio_button_group_id(PopplerLayer *poppler_layer) |
207 | 0 | { |
208 | 0 | g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE); |
209 | | |
210 | 0 | return GPOINTER_TO_INT(poppler_layer->rbgroup); |
211 | 0 | } |