Coverage Report

Created: 2025-07-23 08:13

/src/poppler/glib/poppler-layer.cc
Line
Count
Source (jump to first uncovered line)
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
29
typedef struct _PopplerLayerClass PopplerLayerClass;
30
struct _PopplerLayerClass
31
{
32
    GObjectClass parent_class;
33
};
34
35
G_DEFINE_TYPE(PopplerLayer, poppler_layer, G_TYPE_OBJECT)
36
37
static void poppler_layer_finalize(GObject *object)
38
0
{
39
0
    PopplerLayer *poppler_layer = POPPLER_LAYER(object);
40
41
0
    if (poppler_layer->document) {
42
0
        g_object_unref(poppler_layer->document);
43
0
        poppler_layer->document = nullptr;
44
0
    }
45
46
0
    if (poppler_layer->title) {
47
0
        g_free(poppler_layer->title);
48
0
        poppler_layer->title = nullptr;
49
0
    }
50
0
    poppler_layer->layer = nullptr;
51
0
    poppler_layer->rbgroup = nullptr;
52
53
0
    G_OBJECT_CLASS(poppler_layer_parent_class)->finalize(object);
54
0
}
55
56
0
static void poppler_layer_init(PopplerLayer *layer) { }
57
58
static void poppler_layer_class_init(PopplerLayerClass *klass)
59
0
{
60
0
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
61
62
0
    gobject_class->finalize = poppler_layer_finalize;
63
0
}
64
65
PopplerLayer *_poppler_layer_new(PopplerDocument *document, Layer *layer, GList *rbgroup)
66
0
{
67
0
    PopplerLayer *poppler_layer;
68
0
    const GooString *layer_name;
69
70
0
    g_return_val_if_fail(POPPLER_IS_DOCUMENT(document), NULL);
71
0
    g_return_val_if_fail(layer != nullptr, NULL);
72
73
0
    poppler_layer = POPPLER_LAYER(g_object_new(POPPLER_TYPE_LAYER, nullptr));
74
75
0
    poppler_layer->document = (PopplerDocument *)g_object_ref(document);
76
0
    poppler_layer->layer = layer;
77
0
    poppler_layer->rbgroup = rbgroup;
78
0
    layer_name = layer->oc->getName();
79
0
    poppler_layer->title = layer_name ? _poppler_goo_string_to_utf8(layer_name) : nullptr;
80
81
0
    return poppler_layer;
82
0
}
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
 **/
95
const gchar *poppler_layer_get_title(PopplerLayer *poppler_layer)
96
0
{
97
0
    g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), NULL);
98
99
0
    return poppler_layer->title;
100
0
}
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
 **/
112
gboolean poppler_layer_is_visible(PopplerLayer *poppler_layer)
113
0
{
114
0
    g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE);
115
116
0
    return poppler_layer->layer->oc->getState() == OptionalContentGroup::On;
117
0
}
118
119
/**
120
 * poppler_layer_show:
121
 * @layer: a #PopplerLayer
122
 *
123
 * Shows @layer
124
 *
125
 * Since: 0.12
126
 **/
127
void poppler_layer_show(PopplerLayer *poppler_layer)
128
0
{
129
0
    GList *l;
130
0
    Layer *layer;
131
132
0
    g_return_if_fail(POPPLER_IS_LAYER(poppler_layer));
133
134
0
    layer = poppler_layer->layer;
135
136
0
    if (layer->oc->getState() == OptionalContentGroup::On) {
137
0
        return;
138
0
    }
139
140
0
    layer->oc->setState(OptionalContentGroup::On);
141
142
0
    for (l = poppler_layer->rbgroup; l && l->data; l = g_list_next(l)) {
143
0
        OptionalContentGroup *oc = (OptionalContentGroup *)l->data;
144
145
0
        if (oc != layer->oc) {
146
0
            oc->setState(OptionalContentGroup::Off);
147
0
        }
148
0
    }
149
0
}
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
 **/
161
void poppler_layer_hide(PopplerLayer *poppler_layer)
162
0
{
163
0
    Layer *layer;
164
165
0
    g_return_if_fail(POPPLER_IS_LAYER(poppler_layer));
166
167
0
    layer = poppler_layer->layer;
168
169
0
    if (layer->oc->getState() == OptionalContentGroup::Off) {
170
0
        return;
171
0
    }
172
173
0
    layer->oc->setState(OptionalContentGroup::Off);
174
0
}
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
 **/
186
gboolean poppler_layer_is_parent(PopplerLayer *poppler_layer)
187
0
{
188
0
    g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE);
189
190
0
    return poppler_layer->layer->kids != nullptr;
191
0
}
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
 **/
204
gint poppler_layer_get_radio_button_group_id(PopplerLayer *poppler_layer)
205
0
{
206
0
    g_return_val_if_fail(POPPLER_IS_LAYER(poppler_layer), FALSE);
207
208
0
    return GPOINTER_TO_INT(poppler_layer->rbgroup);
209
0
}