~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/glib/poppler-layer.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
38
poppler_layer_finalize (GObject *object)
 
39
{
 
40
  PopplerLayer *poppler_layer = POPPLER_LAYER (object);
 
41
 
 
42
  if (poppler_layer->document)
 
43
    {
 
44
      g_object_unref (poppler_layer->document);
 
45
      poppler_layer->document = NULL;
 
46
    }
 
47
 
 
48
  if (poppler_layer->title)
 
49
    {
 
50
      g_free (poppler_layer->title);
 
51
      poppler_layer->title = NULL;
 
52
    }
 
53
  poppler_layer->layer = NULL;
 
54
  poppler_layer->rbgroup = NULL;
 
55
 
 
56
  G_OBJECT_CLASS (poppler_layer_parent_class)->finalize (object);
 
57
}
 
58
 
 
59
static void
 
60
poppler_layer_init (PopplerLayer *layer)
 
61
{
 
62
}
 
63
 
 
64
static void
 
65
poppler_layer_class_init (PopplerLayerClass *klass)
 
66
{
 
67
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
68
 
 
69
  gobject_class->finalize = poppler_layer_finalize;
 
70
}
 
71
 
 
72
PopplerLayer *
 
73
_poppler_layer_new (PopplerDocument *document,
 
74
                    Layer           *layer,
 
75
                    GList           *rbgroup)
 
76
{
 
77
  PopplerLayer *poppler_layer;
 
78
  GooString    *layer_name;
 
79
 
 
80
  g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), NULL);
 
81
  g_return_val_if_fail (layer != NULL, NULL);
 
82
 
 
83
  poppler_layer = POPPLER_LAYER (g_object_new (POPPLER_TYPE_LAYER, NULL));
 
84
 
 
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;
 
90
  
 
91
  return poppler_layer;
 
92
}
 
93
 
 
94
/**
 
95
 * poppler_layer_get_title
 
96
 * @layer: a #PopplerLayer
 
97
 *
 
98
 * Returns the name of the layer suitable for
 
99
 * presentation as a title in a viewer's GUI
 
100
 *
 
101
 * Return value: a string containing the title of the layer
 
102
 *
 
103
 * Since: 0.12
 
104
 **/
 
105
const gchar *
 
106
poppler_layer_get_title (PopplerLayer *poppler_layer)
 
107
{
 
108
  g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), NULL);
 
109
 
 
110
  return poppler_layer->title;
 
111
}
 
112
 
 
113
/**
 
114
 * poppler_layer_is_visible
 
115
 * @layer: a #PopplerLayer
 
116
 *
 
117
 * Returns whether @layer is visible
 
118
 *
 
119
 * Return value: %TRUE if @layer is visible
 
120
 *
 
121
 * Since: 0.12
 
122
 **/
 
123
gboolean
 
124
poppler_layer_is_visible (PopplerLayer *poppler_layer)
 
125
{
 
126
  g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
 
127
 
 
128
  return poppler_layer->layer->oc->getState () == OptionalContentGroup::On;
 
129
}
 
130
 
 
131
/**
 
132
 * poppler_layer_show
 
133
 * @layer: a #PopplerLayer
 
134
 *
 
135
 * Shows @layer
 
136
 *
 
137
 * Since: 0.12
 
138
 **/
 
139
void
 
140
poppler_layer_show (PopplerLayer *poppler_layer)
 
141
{
 
142
  GList *l;
 
143
  Layer *layer;
 
144
  
 
145
  g_return_if_fail (POPPLER_IS_LAYER (poppler_layer));
 
146
 
 
147
  layer = poppler_layer->layer;
 
148
 
 
149
  if (layer->oc->getState () == OptionalContentGroup::On)
 
150
    return;
 
151
  
 
152
  layer->oc->setState (OptionalContentGroup::On);
 
153
  
 
154
  for (l = poppler_layer->rbgroup; l && l->data; l = g_list_next (l)) {
 
155
    OptionalContentGroup *oc = (OptionalContentGroup *)l->data;
 
156
 
 
157
    if (oc != layer->oc)
 
158
      oc->setState (OptionalContentGroup::Off);
 
159
  }
 
160
}
 
161
 
 
162
/**
 
163
 * poppler_layer_hide
 
164
 * @layer: a #PopplerLayer
 
165
 *
 
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
 
168
 * is shown again
 
169
 *
 
170
 * Since: 0.12
 
171
 **/
 
172
void
 
173
poppler_layer_hide (PopplerLayer *poppler_layer)
 
174
{
 
175
  Layer *layer;
 
176
  
 
177
  g_return_if_fail (POPPLER_IS_LAYER (poppler_layer));
 
178
 
 
179
  layer = poppler_layer->layer;
 
180
  
 
181
  if (layer->oc->getState () == OptionalContentGroup::Off)
 
182
    return;
 
183
  
 
184
  layer->oc->setState (OptionalContentGroup::Off);
 
185
}
 
186
 
 
187
 
 
188
/**
 
189
 * poppler_layer_is_parent
 
190
 * @layer: a #PopplerLayer
 
191
 *
 
192
 * Returns whether @layer is parent of other nested layers.
 
193
 *
 
194
 * Return value: %TRUE if @layer is a parent layer
 
195
 *
 
196
 * Since: 0.12
 
197
 **/
 
198
gboolean
 
199
poppler_layer_is_parent (PopplerLayer *poppler_layer)
 
200
{
 
201
  g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
 
202
 
 
203
  return poppler_layer->layer->kids != NULL;
 
204
}
 
205
 
 
206
/**
 
207
 * poppler_layer_get_radio_button_group_id
 
208
 * @layer: a #PopplerLayer
 
209
 *
 
210
 * Returns the numeric ID the radio button group associated with @layer.
 
211
 *
 
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
 
214
 *
 
215
 * Since: 0.12
 
216
 **/
 
217
gint 
 
218
poppler_layer_get_radio_button_group_id (PopplerLayer *poppler_layer)
 
219
{
 
220
  g_return_val_if_fail (POPPLER_IS_LAYER (poppler_layer), FALSE);
 
221
 
 
222
  return GPOINTER_TO_INT (poppler_layer->rbgroup);
 
223
}