1
/* poppler-layer.cc: glib interface to poppler
3
* Copyright (C) 2008 Carlos Garcia Campos <carlosgc@gnome.org>
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)
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.
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.
20
#include "poppler-layer.h"
21
#include "poppler-private.h"
24
* SECTION:poppler-layer
25
* @short_description: Layers
26
* @title: PopplerLayer
29
typedef struct _PopplerLayerClass PopplerLayerClass;
30
struct _PopplerLayerClass
32
GObjectClass parent_class;
35
G_DEFINE_TYPE (PopplerLayer, poppler_layer, G_TYPE_OBJECT)
38
poppler_layer_finalize (GObject *object)
40
PopplerLayer *poppler_layer = POPPLER_LAYER (object);
42
if (poppler_layer->document)
44
g_object_unref (poppler_layer->document);
45
poppler_layer->document = NULL;
48
if (poppler_layer->title)
50
g_free (poppler_layer->title);
51
poppler_layer->title = NULL;
53
poppler_layer->layer = NULL;
54
poppler_layer->rbgroup = NULL;
56
G_OBJECT_CLASS (poppler_layer_parent_class)->finalize (object);
60
poppler_layer_init (PopplerLayer *layer)
65
poppler_layer_class_init (PopplerLayerClass *klass)
67
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
69
gobject_class->finalize = poppler_layer_finalize;
73
_poppler_layer_new (PopplerDocument *document,
77
PopplerLayer *poppler_layer;
78
GooString *layer_name;
80
g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
81
g_return_val_if_fail (layer != NULL, NULL);
83
poppler_layer = POPPLER_LAYER (g_object_new (POPPLER_TYPE_LAYER, NULL));
85
poppler_layer->document = (PopplerDocument *)g_object_ref (document);
86
poppler_layer->layer = layer;
87
poppler_layer->rbgroup = rbgroup;
88
layer_name = layer->oc->getName ();
89
poppler_layer->title = layer_name ? _poppler_goo_string_to_utf8 (layer_name) : NULL;
95
* poppler_layer_get_title
96
* @layer: a #PopplerLayer
98
* Returns the name of the layer suitable for
99
* presentation as a title in a viewer's GUI
101
* Return value: a string containing the title of the layer
106
poppler_layer_get_title (PopplerLayer *poppler_layer)
108
g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), NULL);
110
return poppler_layer->title;
114
* poppler_layer_is_visible
115
* @layer: a #PopplerLayer
117
* Returns whether @layer is visible
119
* Return value: %TRUE if @layer is visible
124
poppler_layer_is_visible (PopplerLayer *poppler_layer)
126
g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
128
return poppler_layer->layer->oc->getState () == OptionalContentGroup::On;
133
* @layer: a #PopplerLayer
140
poppler_layer_show (PopplerLayer *poppler_layer)
145
g_return_if_fail (POPPLER_IS_LAYER (poppler_layer));
147
layer = poppler_layer->layer;
149
if (layer->oc->getState () == OptionalContentGroup::On)
152
layer->oc->setState (OptionalContentGroup::On);
154
for (l = poppler_layer->rbgroup; l && l->data; l = g_list_next (l)) {
155
OptionalContentGroup *oc = (OptionalContentGroup *)l->data;
158
oc->setState (OptionalContentGroup::Off);
164
* @layer: a #PopplerLayer
166
* Hides @layer. If @layer is the parent of other nested layers,
167
* such layers will be also hidden and will be blocked until @layer
173
poppler_layer_hide (PopplerLayer *poppler_layer)
177
g_return_if_fail (POPPLER_IS_LAYER (poppler_layer));
179
layer = poppler_layer->layer;
181
if (layer->oc->getState () == OptionalContentGroup::Off)
184
layer->oc->setState (OptionalContentGroup::Off);
189
* poppler_layer_is_parent
190
* @layer: a #PopplerLayer
192
* Returns whether @layer is parent of other nested layers.
194
* Return value: %TRUE if @layer is a parent layer
199
poppler_layer_is_parent (PopplerLayer *poppler_layer)
201
g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
203
return poppler_layer->layer->kids != NULL;
207
* poppler_layer_get_radio_button_group_id
208
* @layer: a #PopplerLayer
210
* Returns the numeric ID the radio button group associated with @layer.
212
* Return value: the ID of the radio button group associated with @layer,
213
* or 0 if the layer is not associated to any radio button group
218
poppler_layer_get_radio_button_group_id (PopplerLayer *poppler_layer)
220
g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
222
return GPOINTER_TO_INT (poppler_layer->rbgroup);