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

source code of poppler/glib/poppler-layer.cc