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

« back to all changes in this revision

Viewing changes to tests/poppler/glib/poppler-annot.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-annot.cc: glib interface to poppler
 
2
 *
 
3
 * Copyright (C) 2007 Inigo Martinez <inigomartinez@gmail.com>
 
4
 * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2, or (at your option)
 
9
 * any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "poppler.h"
 
22
#include "poppler-private.h"
 
23
 
 
24
/**
 
25
 * SECTION:poppler-annot
 
26
 * @short_description: Annotations
 
27
 * @title: PopplerAnnot
 
28
 */
 
29
 
 
30
typedef struct _PopplerAnnotClass               PopplerAnnotClass;
 
31
typedef struct _PopplerAnnotMarkupClass         PopplerAnnotMarkupClass;
 
32
typedef struct _PopplerAnnotFreeTextClass       PopplerAnnotFreeTextClass;
 
33
typedef struct _PopplerAnnotTextClass           PopplerAnnotTextClass;
 
34
typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass;
 
35
typedef struct _PopplerAnnotMovieClass          PopplerAnnotMovieClass;
 
36
typedef struct _PopplerAnnotScreenClass         PopplerAnnotScreenClass;
 
37
 
 
38
struct _PopplerAnnotClass
 
39
{
 
40
  GObjectClass parent_class;
 
41
};
 
42
 
 
43
struct _PopplerAnnotMarkup
 
44
{
 
45
  PopplerAnnot parent_instance;
 
46
};
 
47
 
 
48
struct _PopplerAnnotMarkupClass
 
49
{
 
50
  PopplerAnnotClass parent_class;
 
51
};
 
52
 
 
53
struct _PopplerAnnotText
 
54
{
 
55
  PopplerAnnotMarkup parent_instance;
 
56
};
 
57
 
 
58
struct _PopplerAnnotTextClass
 
59
{
 
60
  PopplerAnnotMarkupClass parent_class;
 
61
};
 
62
 
 
63
struct _PopplerAnnotFreeText
 
64
{
 
65
  PopplerAnnotMarkup parent_instance;
 
66
};
 
67
 
 
68
struct _PopplerAnnotFreeTextClass
 
69
{
 
70
  PopplerAnnotMarkupClass parent_class;
 
71
};
 
72
 
 
73
struct _PopplerAnnotFileAttachment
 
74
{
 
75
  PopplerAnnotMarkup parent_instance;
 
76
};
 
77
 
 
78
struct _PopplerAnnotFileAttachmentClass
 
79
{
 
80
  PopplerAnnotMarkupClass parent_class;
 
81
};
 
82
 
 
83
struct _PopplerAnnotMovie
 
84
{
 
85
  PopplerAnnot  parent_instance;
 
86
 
 
87
  PopplerMovie *movie;
 
88
};
 
89
 
 
90
struct _PopplerAnnotMovieClass
 
91
{
 
92
  PopplerAnnotClass parent_class;
 
93
};
 
94
 
 
95
struct _PopplerAnnotScreen
 
96
{
 
97
  PopplerAnnot  parent_instance;
 
98
 
 
99
  PopplerAction *action;
 
100
};
 
101
 
 
102
struct _PopplerAnnotScreenClass
 
103
{
 
104
  PopplerAnnotClass parent_class;
 
105
};
 
106
 
 
107
 
 
108
G_DEFINE_TYPE (PopplerAnnot, poppler_annot, G_TYPE_OBJECT)
 
109
G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT)
 
110
G_DEFINE_TYPE (PopplerAnnotText, poppler_annot_text, POPPLER_TYPE_ANNOT_MARKUP)
 
111
G_DEFINE_TYPE (PopplerAnnotFreeText, poppler_annot_free_text, POPPLER_TYPE_ANNOT_MARKUP)
 
112
G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLER_TYPE_ANNOT_MARKUP)
 
113
G_DEFINE_TYPE (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT)
 
114
G_DEFINE_TYPE (PopplerAnnotScreen, poppler_annot_screen, POPPLER_TYPE_ANNOT)
 
115
 
 
116
static void
 
117
poppler_annot_finalize (GObject *object)
 
118
{
 
119
  PopplerAnnot *poppler_annot = POPPLER_ANNOT (object);
 
120
 
 
121
  poppler_annot->annot = NULL;
 
122
 
 
123
  G_OBJECT_CLASS (poppler_annot_parent_class)->finalize (object);
 
124
}
 
125
 
 
126
static void
 
127
poppler_annot_init (PopplerAnnot *poppler_annot)
 
128
{
 
129
}
 
130
 
 
131
static void
 
132
poppler_annot_class_init (PopplerAnnotClass *klass)
 
133
{
 
134
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
135
 
 
136
  gobject_class->finalize = poppler_annot_finalize;
 
137
}
 
138
 
 
139
PopplerAnnot *
 
140
_poppler_annot_new (Annot *annot)
 
141
{
 
142
  PopplerAnnot *poppler_annot;
 
143
 
 
144
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT, NULL));
 
145
  poppler_annot->annot = annot;
 
146
 
 
147
  return poppler_annot;
 
148
}
 
149
 
 
150
static void
 
151
poppler_annot_markup_init (PopplerAnnotMarkup *poppler_annot)
 
152
{
 
153
}
 
154
 
 
155
static void
 
156
poppler_annot_markup_class_init (PopplerAnnotMarkupClass *klass)
 
157
{
 
158
}
 
159
 
 
160
static void
 
161
poppler_annot_text_init (PopplerAnnotText *poppler_annot)
 
162
{
 
163
}
 
164
 
 
165
static void
 
166
poppler_annot_text_class_init (PopplerAnnotTextClass *klass)
 
167
{
 
168
}
 
169
 
 
170
PopplerAnnot *
 
171
_poppler_annot_text_new (Annot *annot)
 
172
{
 
173
  PopplerAnnot *poppler_annot;
 
174
 
 
175
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_TEXT, NULL));
 
176
  poppler_annot->annot = annot;
 
177
 
 
178
  return poppler_annot;
 
179
}
 
180
 
 
181
/**
 
182
 * poppler_annot_text_new:
 
183
 * @doc: a #PopplerDocument
 
184
 * @rect: a #PopplerRectangle
 
185
 *
 
186
 * Creates a new Text annotation that will be
 
187
 * located on @rect when added to a page. See
 
188
 * poppler_page_add_annot()
 
189
 *
 
190
 * Return value: A newly created #PopplerAnnotText annotation
 
191
 *
 
192
 * Since: 0.16
 
193
 */
 
194
PopplerAnnot *
 
195
poppler_annot_text_new (PopplerDocument  *doc,
 
196
                        PopplerRectangle *rect)
 
197
{
 
198
  Annot *annot;
 
199
  PDFRectangle pdf_rect(rect->x1, rect->y1,
 
200
                        rect->x2, rect->y2);
 
201
 
 
202
  annot = new AnnotText (doc->doc->getXRef(), &pdf_rect, doc->doc->getCatalog());
 
203
 
 
204
  return _poppler_annot_text_new (annot);
 
205
}
 
206
 
 
207
static void
 
208
poppler_annot_free_text_init (PopplerAnnotFreeText *poppler_annot)
 
209
{
 
210
}
 
211
 
 
212
static void
 
213
poppler_annot_free_text_class_init (PopplerAnnotFreeTextClass *klass)
 
214
{
 
215
}
 
216
 
 
217
PopplerAnnot *
 
218
_poppler_annot_free_text_new (Annot *annot)
 
219
{
 
220
  PopplerAnnot *poppler_annot;
 
221
 
 
222
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_FREE_TEXT, NULL));
 
223
  poppler_annot->annot = annot;
 
224
 
 
225
  return poppler_annot;
 
226
}
 
227
 
 
228
static void
 
229
poppler_annot_file_attachment_init (PopplerAnnotFileAttachment *poppler_annot)
 
230
{
 
231
}
 
232
 
 
233
static void
 
234
poppler_annot_file_attachment_class_init (PopplerAnnotFileAttachmentClass *klass)
 
235
{
 
236
}
 
237
 
 
238
PopplerAnnot *
 
239
_poppler_annot_file_attachment_new (Annot *annot)
 
240
{
 
241
  PopplerAnnot *poppler_annot;
 
242
 
 
243
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_FILE_ATTACHMENT, NULL));
 
244
  poppler_annot->annot = annot;
 
245
 
 
246
  return poppler_annot;
 
247
}
 
248
 
 
249
 
 
250
static void
 
251
poppler_annot_movie_finalize (GObject *object)
 
252
{
 
253
  PopplerAnnotMovie *annot_movie = POPPLER_ANNOT_MOVIE (object);
 
254
 
 
255
  if (annot_movie->movie) {
 
256
    g_object_unref (annot_movie->movie);
 
257
    annot_movie->movie = NULL;
 
258
  }
 
259
 
 
260
  G_OBJECT_CLASS (poppler_annot_movie_parent_class)->finalize (object);
 
261
}
 
262
 
 
263
static void
 
264
poppler_annot_movie_init (PopplerAnnotMovie *poppler_annot)
 
265
{
 
266
}
 
267
 
 
268
static void
 
269
poppler_annot_movie_class_init (PopplerAnnotMovieClass *klass)
 
270
{
 
271
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
272
 
 
273
  gobject_class->finalize = poppler_annot_movie_finalize;
 
274
}
 
275
 
 
276
PopplerAnnot *
 
277
_poppler_annot_movie_new (Annot *annot)
 
278
{
 
279
  PopplerAnnot *poppler_annot;
 
280
  AnnotMovie   *annot_movie;
 
281
 
 
282
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_MOVIE, NULL));
 
283
  poppler_annot->annot = annot;
 
284
 
 
285
  annot_movie = static_cast<AnnotMovie *>(poppler_annot->annot);
 
286
  POPPLER_ANNOT_MOVIE (poppler_annot)->movie = _poppler_movie_new (annot_movie->getMovie());
 
287
 
 
288
  return poppler_annot;
 
289
}
 
290
 
 
291
static void
 
292
poppler_annot_screen_finalize (GObject *object)
 
293
{
 
294
  PopplerAnnotScreen *annot_screen = POPPLER_ANNOT_SCREEN (object);
 
295
 
 
296
  if (annot_screen->action) {
 
297
    poppler_action_free (annot_screen->action);
 
298
    annot_screen->action = NULL;
 
299
  }
 
300
 
 
301
  G_OBJECT_CLASS (poppler_annot_screen_parent_class)->finalize (object);
 
302
}
 
303
 
 
304
static void
 
305
poppler_annot_screen_init (PopplerAnnotScreen *poppler_annot)
 
306
{
 
307
}
 
308
 
 
309
static void
 
310
poppler_annot_screen_class_init (PopplerAnnotScreenClass *klass)
 
311
{
 
312
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
313
 
 
314
  gobject_class->finalize = poppler_annot_screen_finalize;
 
315
}
 
316
 
 
317
PopplerAnnot *
 
318
_poppler_annot_screen_new (Annot *annot)
 
319
{
 
320
  PopplerAnnot *poppler_annot;
 
321
  AnnotScreen  *annot_screen;
 
322
  LinkAction   *action;
 
323
 
 
324
  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_SCREEN, NULL));
 
325
  poppler_annot->annot = annot;
 
326
 
 
327
  annot_screen = static_cast<AnnotScreen *>(poppler_annot->annot);
 
328
  action = annot_screen->getAction();
 
329
  if (action)
 
330
    POPPLER_ANNOT_SCREEN (poppler_annot)->action = _poppler_action_new (NULL, action, NULL);
 
331
 
 
332
  return poppler_annot;
 
333
}
 
334
 
 
335
 
 
336
/* Public methods */
 
337
/**
 
338
 * poppler_annot_get_annot_type:
 
339
 * @poppler_annot: a #PopplerAnnot
 
340
 *
 
341
 * Gets the type of @poppler_annot
 
342
 *
 
343
 * Return value: #PopplerAnnotType of @poppler_annot.
 
344
 **/ 
 
345
PopplerAnnotType
 
346
poppler_annot_get_annot_type (PopplerAnnot *poppler_annot)
 
347
{
 
348
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), POPPLER_ANNOT_UNKNOWN);
 
349
 
 
350
  switch (poppler_annot->annot->getType ())
 
351
    {
 
352
    case Annot::typeText:
 
353
      return POPPLER_ANNOT_TEXT;
 
354
    case Annot::typeLink:
 
355
      return POPPLER_ANNOT_LINK;
 
356
    case Annot::typeFreeText:
 
357
      return POPPLER_ANNOT_FREE_TEXT;
 
358
    case Annot::typeLine:
 
359
      return POPPLER_ANNOT_LINE;
 
360
    case Annot::typeSquare:
 
361
      return POPPLER_ANNOT_SQUARE;
 
362
    case Annot::typeCircle:
 
363
      return POPPLER_ANNOT_CIRCLE;
 
364
    case Annot::typePolygon:
 
365
      return POPPLER_ANNOT_POLYGON;
 
366
    case Annot::typePolyLine:
 
367
      return POPPLER_ANNOT_POLY_LINE;
 
368
    case Annot::typeHighlight:
 
369
      return POPPLER_ANNOT_HIGHLIGHT;
 
370
    case Annot::typeUnderline:
 
371
      return POPPLER_ANNOT_UNDERLINE;
 
372
    case Annot::typeSquiggly:
 
373
      return POPPLER_ANNOT_SQUIGGLY;
 
374
    case Annot::typeStrikeOut:
 
375
      return POPPLER_ANNOT_STRIKE_OUT;
 
376
    case Annot::typeStamp:
 
377
      return POPPLER_ANNOT_STAMP;
 
378
    case Annot::typeCaret:
 
379
      return POPPLER_ANNOT_CARET;
 
380
    case Annot::typeInk:
 
381
      return POPPLER_ANNOT_INK;
 
382
    case Annot::typePopup:
 
383
      return POPPLER_ANNOT_POPUP;
 
384
    case Annot::typeFileAttachment:
 
385
      return POPPLER_ANNOT_FILE_ATTACHMENT;
 
386
    case Annot::typeSound:
 
387
      return POPPLER_ANNOT_SOUND;
 
388
    case Annot::typeMovie:
 
389
      return POPPLER_ANNOT_MOVIE;
 
390
    case Annot::typeWidget:
 
391
      return POPPLER_ANNOT_WIDGET;
 
392
    case Annot::typeScreen:
 
393
      return POPPLER_ANNOT_SCREEN;
 
394
    case Annot::typePrinterMark:
 
395
      return POPPLER_ANNOT_PRINTER_MARK;
 
396
    case Annot::typeTrapNet:
 
397
      return POPPLER_ANNOT_TRAP_NET;
 
398
    case Annot::typeWatermark:
 
399
      return POPPLER_ANNOT_WATERMARK;
 
400
    case Annot::type3D:
 
401
      return POPPLER_ANNOT_3D;
 
402
    default:
 
403
      g_warning ("Unsupported Annot Type");
 
404
    }
 
405
 
 
406
  return POPPLER_ANNOT_UNKNOWN;
 
407
}
 
408
 
 
409
/**
 
410
 * poppler_annot_get_contents:
 
411
 * @poppler_annot: a #PopplerAnnot
 
412
 *
 
413
 * Retrieves the contents of @poppler_annot.
 
414
 *
 
415
 * Return value: a new allocated string with the contents of @poppler_annot. It
 
416
 *               must be freed with g_free() when done.
 
417
 **/
 
418
gchar *
 
419
poppler_annot_get_contents (PopplerAnnot *poppler_annot)
 
420
{
 
421
  GooString *contents;
 
422
 
 
423
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
 
424
 
 
425
  contents = poppler_annot->annot->getContents ();
 
426
 
 
427
  return contents ? _poppler_goo_string_to_utf8 (contents) : NULL;
 
428
}
 
429
 
 
430
/**
 
431
 * poppler_annot_set_contents:
 
432
 * @poppler_annot: a #PopplerAnnot
 
433
 * @contents: a text string containing the new contents
 
434
 *
 
435
 * Sets the contents of @poppler_annot to the given value,
 
436
 * replacing the current contents.
 
437
 *
 
438
 * Since: 0.12
 
439
 **/
 
440
void
 
441
poppler_annot_set_contents (PopplerAnnot *poppler_annot,
 
442
                            const gchar  *contents)
 
443
{
 
444
  GooString *goo_tmp;
 
445
  gchar *tmp;
 
446
  gsize length = 0;
 
447
  
 
448
  g_return_if_fail (POPPLER_IS_ANNOT (poppler_annot));
 
449
 
 
450
  tmp = contents ? g_convert (contents, -1, "UTF-16BE", "UTF-8", NULL, &length, NULL) : NULL;
 
451
  goo_tmp = new GooString (tmp, length);
 
452
  g_free (tmp);
 
453
  poppler_annot->annot->setContents (goo_tmp);
 
454
  delete (goo_tmp);
 
455
}
 
456
 
 
457
/**
 
458
 * poppler_annot_get_name:
 
459
 * @poppler_annot: a #PopplerAnnot
 
460
 *
 
461
 * Retrieves the name of @poppler_annot.
 
462
 *
 
463
 * Return value: a new allocated string with the name of @poppler_annot. It must
 
464
 *               be freed with g_free() when done.
 
465
 **/
 
466
gchar *
 
467
poppler_annot_get_name (PopplerAnnot *poppler_annot)
 
468
{
 
469
  GooString *name;
 
470
 
 
471
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
 
472
 
 
473
  name = poppler_annot->annot->getName ();
 
474
 
 
475
  return name ? _poppler_goo_string_to_utf8 (name) : NULL;
 
476
}
 
477
 
 
478
/**
 
479
 * poppler_annot_get_modified:
 
480
 * @poppler_annot: a #PopplerAnnot
 
481
 *
 
482
 * Retrieves the last modification data of @poppler_annot. The returned
 
483
 * string will be either a PDF format date or a text string.
 
484
 * See also #poppler_date_parse()
 
485
 *
 
486
 * Return value: a new allocated string with the last modification data of
 
487
 *               @poppler_annot. It must be freed with g_free() when done.
 
488
 **/
 
489
gchar *
 
490
poppler_annot_get_modified (PopplerAnnot *poppler_annot)
 
491
{
 
492
  GooString *text;
 
493
 
 
494
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
 
495
 
 
496
  text = poppler_annot->annot->getModified ();
 
497
 
 
498
  return text ? _poppler_goo_string_to_utf8 (text) : NULL;
 
499
}
 
500
 
 
501
/**
 
502
 * poppler_annot_get_flags
 
503
 * @poppler_annot: a #PopplerAnnot
 
504
 *
 
505
 * Retrieves the flag field specifying various characteristics of the
 
506
 * @poppler_annot.
 
507
 *
 
508
 * Return value: the flag field of @poppler_annot.
 
509
 **/
 
510
PopplerAnnotFlag
 
511
poppler_annot_get_flags (PopplerAnnot *poppler_annot)
 
512
{
 
513
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), (PopplerAnnotFlag) 0);
 
514
 
 
515
  return (PopplerAnnotFlag) poppler_annot->annot->getFlags ();
 
516
}
 
517
 
 
518
/**
 
519
 * poppler_annot_get_color:
 
520
 * @poppler_annot: a #PopplerAnnot
 
521
 *
 
522
 * Retrieves the color of @poppler_annot.
 
523
 *
 
524
 * Return value: a new allocated #PopplerColor with the color values of
 
525
 *               @poppler_annot, or %NULL. It must be freed with g_free() when done.
 
526
 **/
 
527
PopplerColor *
 
528
poppler_annot_get_color (PopplerAnnot *poppler_annot)
 
529
{
 
530
  AnnotColor *color;
 
531
  PopplerColor *poppler_color = NULL;
 
532
 
 
533
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), NULL);
 
534
 
 
535
  color = poppler_annot->annot->getColor ();
 
536
 
 
537
  if (color) {
 
538
    const double *values = color->getValues ();
 
539
 
 
540
    switch (color->getSpace ())
 
541
      {
 
542
      case AnnotColor::colorGray:
 
543
        poppler_color = g_new (PopplerColor, 1);
 
544
        
 
545
        poppler_color->red = (guint16) (values[0] * 65535);
 
546
        poppler_color->green = poppler_color->red;
 
547
        poppler_color->blue = poppler_color->red;
 
548
 
 
549
        break;
 
550
      case AnnotColor::colorRGB:
 
551
        poppler_color = g_new (PopplerColor, 1);
 
552
        
 
553
        poppler_color->red = (guint16) (values[0] * 65535);
 
554
        poppler_color->green = (guint16) (values[1] * 65535);
 
555
        poppler_color->blue = (guint16) (values[2] * 65535);
 
556
 
 
557
        break;
 
558
      case AnnotColor::colorCMYK:
 
559
        g_warning ("Unsupported Annot Color: colorCMYK");
 
560
      case AnnotColor::colorTransparent:
 
561
        break;
 
562
      }
 
563
  }
 
564
 
 
565
  return poppler_color;
 
566
}
 
567
 
 
568
/**
 
569
 * poppler_annot_set_color:
 
570
 * @poppler_annot: a #PopplerAnnot
 
571
 * @poppler_color: (allow-none): a #PopplerColor, or %NULL
 
572
 *
 
573
 * Sets the color of @poppler_annot.
 
574
 *
 
575
 * Since: 0.16
 
576
 */
 
577
void
 
578
poppler_annot_set_color (PopplerAnnot *poppler_annot,
 
579
                         PopplerColor *poppler_color)
 
580
{
 
581
  AnnotColor *color = NULL;
 
582
 
 
583
  if (poppler_color) {
 
584
    color = new AnnotColor ((double)poppler_color->red / 65535,
 
585
                            (double)poppler_color->green / 65535,
 
586
                            (double)poppler_color->blue / 65535);
 
587
  }
 
588
 
 
589
  /* Annot takes ownership of the color */
 
590
  poppler_annot->annot->setColor (color);
 
591
}
 
592
 
 
593
/**
 
594
 * poppler_annot_get_page_index:
 
595
 * @poppler_annot: a #PopplerAnnot
 
596
 *
 
597
 * Returns the page index to which @poppler_annot is associated, or -1 if unknown
 
598
 *
 
599
 * Return value: page index or -1
 
600
 *
 
601
 * Since: 0.14
 
602
 **/
 
603
gint
 
604
poppler_annot_get_page_index (PopplerAnnot *poppler_annot)
 
605
{
 
606
  gint page_num;
 
607
 
 
608
  g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), -1);
 
609
 
 
610
  page_num = poppler_annot->annot->getPageNum();
 
611
  return page_num <= 0 ? -1 : page_num - 1;
 
612
}
 
613
 
 
614
/* PopplerAnnotMarkup */
 
615
/**
 
616
 * poppler_annot_markup_get_label:
 
617
 * @poppler_annot: a #PopplerAnnotMarkup
 
618
 *
 
619
 * Retrieves the label text of @poppler_annot.
 
620
 *
 
621
 * Return value: the label text of @poppler_annot.
 
622
 */
 
623
gchar *
 
624
poppler_annot_markup_get_label (PopplerAnnotMarkup *poppler_annot)
 
625
{
 
626
  AnnotMarkup *annot;
 
627
  GooString *text;
 
628
 
 
629
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), NULL);
 
630
 
 
631
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
632
 
 
633
  text = annot->getLabel ();
 
634
 
 
635
  return text ? _poppler_goo_string_to_utf8 (text) : NULL;
 
636
}
 
637
 
 
638
/**
 
639
 * poppler_annot_markup_set_label:
 
640
 * @poppler_annot: a #PopplerAnnotMarkup
 
641
 * @label: (allow-none): a text string containing the new label, or %NULL
 
642
 *
 
643
 * Sets the label text of @poppler_annot, replacing the current one
 
644
 *
 
645
 * Since: 0.16
 
646
 */
 
647
void
 
648
poppler_annot_markup_set_label (PopplerAnnotMarkup *poppler_annot,
 
649
                                const gchar        *label)
 
650
{
 
651
  AnnotMarkup *annot;
 
652
  GooString *goo_tmp;
 
653
  gchar *tmp;
 
654
  gsize length = 0;
 
655
 
 
656
  g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot));
 
657
 
 
658
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
659
 
 
660
  tmp = label ? g_convert (label, -1, "UTF-16BE", "UTF-8", NULL, &length, NULL) : NULL;
 
661
  goo_tmp = new GooString (tmp, length);
 
662
  g_free (tmp);
 
663
  annot->setLabel (goo_tmp);
 
664
  delete goo_tmp;
 
665
}
 
666
 
 
667
/**
 
668
 * poppler_annot_markup_has_popup:
 
669
 * @poppler_annot: a #PopplerAnnotMarkup
 
670
 *
 
671
 * Return %TRUE if the markup annotation has a popup window associated
 
672
 *
 
673
 * Return value: %TRUE, if @poppler_annot has popup, %FALSE otherwise
 
674
 *
 
675
 * Since: 0.12
 
676
 **/
 
677
gboolean
 
678
poppler_annot_markup_has_popup (PopplerAnnotMarkup *poppler_annot)
 
679
{
 
680
  AnnotMarkup *annot;
 
681
 
 
682
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), FALSE);
 
683
 
 
684
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
685
 
 
686
  return annot->getPopup () != NULL;
 
687
}
 
688
 
 
689
/**
 
690
 * poppler_annot_markup_set_popup:
 
691
 * @poppler_annot: a #PopplerAnnotMarkup
 
692
 * @popup_rect: a #PopplerRectangle
 
693
 *
 
694
 * Associates a new popup window for editing contents of @poppler_annot.
 
695
 * Popup window shall be displayed by viewers at @popup_rect on the page.
 
696
 *
 
697
 * Since: 0.16
 
698
 */
 
699
void
 
700
poppler_annot_markup_set_popup (PopplerAnnotMarkup *poppler_annot,
 
701
                                PopplerRectangle   *popup_rect)
 
702
{
 
703
  AnnotMarkup *annot;
 
704
  AnnotPopup  *popup;
 
705
  PDFRectangle pdf_rect(popup_rect->x1, popup_rect->y1,
 
706
                        popup_rect->x2, popup_rect->y2);
 
707
 
 
708
  g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot));
 
709
 
 
710
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
711
  popup = new AnnotPopup (annot->getXRef(), &pdf_rect, (Catalog *)NULL);
 
712
  annot->setPopup (popup);
 
713
}
 
714
 
 
715
/**
 
716
 * poppler_annot_markup_get_popup_is_open:
 
717
 * @poppler_annot: a #PopplerAnnotMarkup
 
718
 *
 
719
 * Retrieves the state of the popup window related to @poppler_annot.
 
720
 *
 
721
 * Return value: the state of @poppler_annot. %TRUE if it's open, %FALSE in
 
722
 *               other case.
 
723
 **/
 
724
gboolean
 
725
poppler_annot_markup_get_popup_is_open (PopplerAnnotMarkup *poppler_annot)
 
726
{
 
727
  AnnotMarkup *annot;
 
728
  AnnotPopup *annot_popup;
 
729
 
 
730
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), FALSE);
 
731
 
 
732
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
733
 
 
734
  if ((annot_popup = annot->getPopup ()))
 
735
    return annot_popup->getOpen ();
 
736
 
 
737
  return FALSE;
 
738
}
 
739
 
 
740
/**
 
741
 * poppler_annot_markup_set_popup_is_open:
 
742
 * @poppler_annot: a #PopplerAnnotMarkup
 
743
 * @is_open: whether popup window should initially be displayed open
 
744
 *
 
745
 * Sets the state of the popup window related to @poppler_annot.
 
746
 *
 
747
 * Since: 0.16
 
748
 **/
 
749
void
 
750
poppler_annot_markup_set_popup_is_open (PopplerAnnotMarkup *poppler_annot,
 
751
                                        gboolean            is_open)
 
752
{
 
753
  AnnotMarkup *annot;
 
754
  AnnotPopup *annot_popup;
 
755
 
 
756
  g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot));
 
757
 
 
758
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
759
 
 
760
  annot_popup = annot->getPopup ();
 
761
  if (!annot_popup)
 
762
    return;
 
763
 
 
764
  if (annot_popup->getOpen () != is_open)
 
765
    annot_popup->setOpen (is_open);
 
766
}
 
767
 
 
768
/**
 
769
 * poppler_annot_markup_get_popup_rectangle:
 
770
 * @poppler_annot: a #PopplerAnnotMarkup
 
771
 * @poppler_rect: (out): a #PopplerRectangle to store the popup rectangle
 
772
 *
 
773
 * Retrieves the rectangle of the popup window related to @poppler_annot.
 
774
 *
 
775
 * Return value: %TRUE if #PopplerRectangle was correctly filled, %FALSE otherwise
 
776
 *
 
777
 * Since: 0.12
 
778
 **/
 
779
gboolean
 
780
poppler_annot_markup_get_popup_rectangle (PopplerAnnotMarkup *poppler_annot,
 
781
                                          PopplerRectangle   *poppler_rect)
 
782
{
 
783
  AnnotMarkup *annot;
 
784
  Annot *annot_popup;
 
785
  PDFRectangle *annot_rect;
 
786
 
 
787
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), FALSE);
 
788
  g_return_val_if_fail (poppler_rect != NULL, FALSE);
 
789
 
 
790
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
791
  annot_popup = annot->getPopup ();
 
792
  if (!annot_popup)
 
793
    return FALSE;
 
794
 
 
795
  annot_rect = annot_popup->getRect ();
 
796
  poppler_rect->x1 = annot_rect->x1;
 
797
  poppler_rect->x2 = annot_rect->x2;
 
798
  poppler_rect->y1 = annot_rect->y1;
 
799
  poppler_rect->y2 = annot_rect->y2;
 
800
 
 
801
  return TRUE;
 
802
}
 
803
 
 
804
/**
 
805
 * poppler_annot_markup_get_opacity:
 
806
 * @poppler_annot: a #PopplerAnnotMarkup
 
807
 *
 
808
 * Retrieves the opacity value of @poppler_annot.
 
809
 *
 
810
 * Return value: the opacity value of @poppler_annot,
 
811
 *               between 0 (transparent) and 1 (opaque)
 
812
 */
 
813
gdouble
 
814
poppler_annot_markup_get_opacity (PopplerAnnotMarkup *poppler_annot)
 
815
{
 
816
  AnnotMarkup *annot;
 
817
 
 
818
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), 0);
 
819
 
 
820
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
821
  
 
822
  return annot->getOpacity ();
 
823
}
 
824
 
 
825
/**
 
826
 * poppler_annot_markup_set_opacity:
 
827
 * @poppler_annot: a #PopplerAnnotMarkup
 
828
 * @opacity: a constant opacity value, between 0 (transparent) and 1 (opaque)
 
829
 *
 
830
 * Sets the opacity of @poppler_annot. This value applies to
 
831
 * all visible elements of @poppler_annot in its closed state,
 
832
 * but not to the pop-up window that appears when it's openened
 
833
 *
 
834
 * Since: 0.16
 
835
 */
 
836
void
 
837
poppler_annot_markup_set_opacity (PopplerAnnotMarkup *poppler_annot,
 
838
                                  gdouble             opacity)
 
839
{
 
840
  AnnotMarkup *annot;
 
841
 
 
842
  g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot));
 
843
 
 
844
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
845
  annot->setOpacity(opacity);
 
846
}
 
847
 
 
848
/**
 
849
 * poppler_annot_markup_get_date:
 
850
 * @poppler_annot: a #PopplerAnnotMarkup
 
851
 *
 
852
 * Returns the date and time when the annotation was created
 
853
 *
 
854
 * Return value: (transfer full): a #GDate representing the date and time
 
855
 *               when the annotation was created, or %NULL
 
856
 */
 
857
GDate *
 
858
poppler_annot_markup_get_date (PopplerAnnotMarkup *poppler_annot)
 
859
{
 
860
  AnnotMarkup *annot;
 
861
  GooString *annot_date;
 
862
  time_t timet;
 
863
 
 
864
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), NULL);
 
865
 
 
866
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
867
  annot_date = annot->getDate ();
 
868
  if (!annot_date)
 
869
    return NULL;
 
870
 
 
871
  if (_poppler_convert_pdf_date_to_gtime (annot_date, &timet)) {
 
872
    GDate *date;
 
873
 
 
874
    date = g_date_new ();
 
875
    g_date_set_time_t (date, timet);
 
876
 
 
877
    return date;
 
878
  }
 
879
 
 
880
  return NULL;
 
881
}
 
882
 
 
883
/**
 
884
* poppler_annot_markup_get_subject:
 
885
* @poppler_annot: a #PopplerAnnotMarkup
 
886
*
 
887
* Retrives the subject text of @poppler_annot.
 
888
*
 
889
* Return value: the subject text of @poppler_annot.
 
890
*/
 
891
gchar *
 
892
poppler_annot_markup_get_subject (PopplerAnnotMarkup *poppler_annot)
 
893
{
 
894
  AnnotMarkup *annot;
 
895
  GooString *text;
 
896
 
 
897
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), NULL);
 
898
 
 
899
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
900
 
 
901
  text = annot->getSubject ();
 
902
 
 
903
  return text ? _poppler_goo_string_to_utf8 (text) : NULL;
 
904
}
 
905
 
 
906
/**
 
907
* poppler_annot_markup_get_reply_to:
 
908
* @poppler_annot: a #PopplerAnnotMarkup
 
909
*
 
910
* Gets the reply type of @poppler_annot.
 
911
*
 
912
* Return value: #PopplerAnnotMarkupReplyType of @poppler_annot.
 
913
*/
 
914
PopplerAnnotMarkupReplyType
 
915
poppler_annot_markup_get_reply_to (PopplerAnnotMarkup *poppler_annot)
 
916
{
 
917
  AnnotMarkup *annot;
 
918
 
 
919
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), POPPLER_ANNOT_MARKUP_REPLY_TYPE_R);
 
920
 
 
921
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
922
  
 
923
  switch (annot->getReplyTo ())
 
924
  {
 
925
    case AnnotMarkup::replyTypeR:
 
926
      return POPPLER_ANNOT_MARKUP_REPLY_TYPE_R;
 
927
    case AnnotMarkup::replyTypeGroup:
 
928
      return POPPLER_ANNOT_MARKUP_REPLY_TYPE_GROUP;
 
929
    default:
 
930
      g_warning ("Unsupported Annot Markup Reply To Type");
 
931
  }
 
932
 
 
933
  return POPPLER_ANNOT_MARKUP_REPLY_TYPE_R;
 
934
}
 
935
 
 
936
/**
 
937
* poppler_annot_markup_get_external_data:
 
938
* @poppler_annot: a #PopplerAnnotMarkup
 
939
*
 
940
* Gets the external data type of @poppler_annot.
 
941
*
 
942
* Return value: #PopplerAnnotExternalDataType of @poppler_annot.
 
943
*/
 
944
PopplerAnnotExternalDataType
 
945
poppler_annot_markup_get_external_data (PopplerAnnotMarkup *poppler_annot)
 
946
{
 
947
  AnnotMarkup *annot;
 
948
 
 
949
  g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN);
 
950
 
 
951
  annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
 
952
 
 
953
  switch (annot->getExData ())
 
954
    {
 
955
    case annotExternalDataMarkup3D:
 
956
      return POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_3D;
 
957
    case annotExternalDataMarkupUnknown:
 
958
      return POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN;
 
959
    default:
 
960
      g_warning ("Unsupported Annot Markup External Data");
 
961
    }
 
962
 
 
963
  return POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN;
 
964
}
 
965
 
 
966
/* PopplerAnnotText */
 
967
/**
 
968
 * poppler_annot_text_get_is_open:
 
969
 * @poppler_annot: a #PopplerAnnotText
 
970
 *
 
971
 * Retrieves the state of @poppler_annot.
 
972
 *
 
973
 * Return value: the state of @poppler_annot. %TRUE if it's open, %FALSE in
 
974
 *               other case.
 
975
 **/
 
976
gboolean
 
977
poppler_annot_text_get_is_open (PopplerAnnotText *poppler_annot)
 
978
{
 
979
  AnnotText *annot;
 
980
 
 
981
  g_return_val_if_fail (POPPLER_IS_ANNOT_TEXT (poppler_annot), FALSE);
 
982
 
 
983
  annot = static_cast<AnnotText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
984
 
 
985
  return annot->getOpen ();
 
986
}
 
987
 
 
988
/**
 
989
 * poppler_annot_text_set_is_open:
 
990
 * @poppler_annot: a #PopplerAnnotText
 
991
 * @is_open: whether annotation should initially be displayed open
 
992
 *
 
993
 * Sets whether @poppler_annot should initially be displayed open
 
994
 *
 
995
 * Since: 0.16
 
996
 */
 
997
void
 
998
poppler_annot_text_set_is_open (PopplerAnnotText *poppler_annot,
 
999
                                gboolean          is_open)
 
1000
{
 
1001
  AnnotText *annot;
 
1002
 
 
1003
  g_return_if_fail (POPPLER_IS_ANNOT_TEXT (poppler_annot));
 
1004
 
 
1005
  annot = static_cast<AnnotText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1006
  annot->setOpen(is_open);
 
1007
}
 
1008
 
 
1009
/**
 
1010
 * poppler_annot_text_get_icon:
 
1011
 * @poppler_annot: a #PopplerAnnotText
 
1012
 *
 
1013
 * Gets name of the icon of @poppler_annot.
 
1014
 *
 
1015
 * Return value: a new allocated string containing the icon name
 
1016
 */
 
1017
gchar *
 
1018
poppler_annot_text_get_icon (PopplerAnnotText *poppler_annot)
 
1019
{
 
1020
  AnnotText *annot;
 
1021
  GooString *text;
 
1022
 
 
1023
  g_return_val_if_fail (POPPLER_IS_ANNOT_TEXT (poppler_annot), NULL);
 
1024
 
 
1025
  annot = static_cast<AnnotText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1026
 
 
1027
  text = annot->getIcon ();
 
1028
 
 
1029
  return text ? _poppler_goo_string_to_utf8 (text) : NULL;
 
1030
}
 
1031
 
 
1032
/**
 
1033
 * poppler_annot_text_set_icon:
 
1034
 * @poppler_annot: a #PopplerAnnotText
 
1035
 * @icon: the name of an icon
 
1036
 *
 
1037
 * Sets the icon of @poppler_annot. The following predefined
 
1038
 * icons are currently supported:
 
1039
 * <variablelist>
 
1040
 *  <varlistentry>
 
1041
 *   <term>#POPPLER_ANNOT_TEXT_ICON_NOTE</term>
 
1042
 *  </varlistentry>
 
1043
 *  <varlistentry>
 
1044
 *   <term>#POPPLER_ANNOT_TEXT_ICON_COMMENT</term>
 
1045
 *  </varlistentry>
 
1046
 *  <varlistentry>
 
1047
 *   <term>#POPPLER_ANNOT_TEXT_ICON_KEY</term>
 
1048
 *  </varlistentry>
 
1049
 *  <varlistentry>
 
1050
 *   <term>#POPPLER_ANNOT_TEXT_ICON_HELP</term>
 
1051
 *  </varlistentry>
 
1052
 *  <varlistentry>
 
1053
 *   <term>#POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH</term>
 
1054
 *  </varlistentry>
 
1055
 *  <varlistentry>
 
1056
 *   <term>#POPPLER_ANNOT_TEXT_ICON_PARAGRAPH</term>
 
1057
 *  </varlistentry>
 
1058
 *  <varlistentry>
 
1059
 *   <term>#POPPLER_ANNOT_TEXT_ICON_INSERT</term>
 
1060
 *  </varlistentry>
 
1061
 *  <varlistentry>
 
1062
 *   <term>#POPPLER_ANNOT_TEXT_ICON_CROSS</term>
 
1063
 *  </varlistentry>
 
1064
 *  <varlistentry>
 
1065
 *   <term>#POPPLER_ANNOT_TEXT_ICON_CIRCLE</term>
 
1066
 *  </varlistentry>
 
1067
 * </variablelist>
 
1068
 *
 
1069
 * Since: 0.16
 
1070
 */
 
1071
void
 
1072
poppler_annot_text_set_icon (PopplerAnnotText *poppler_annot,
 
1073
                             const gchar      *icon)
 
1074
{
 
1075
  AnnotText *annot;
 
1076
  GooString *text;
 
1077
 
 
1078
  g_return_if_fail (POPPLER_IS_ANNOT_TEXT (poppler_annot));
 
1079
 
 
1080
  annot = static_cast<AnnotText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1081
 
 
1082
  text = new GooString(icon);
 
1083
  annot->setIcon(text);
 
1084
  delete text;
 
1085
}
 
1086
 
 
1087
/**
 
1088
 * poppler_annot_text_get_state:
 
1089
 * @poppler_annot: a #PopplerAnnotText
 
1090
 *
 
1091
 * Retrieves the state of @poppler_annot.
 
1092
 *
 
1093
 * Return value: #PopplerAnnotTextState of @poppler_annot.
 
1094
 **/ 
 
1095
PopplerAnnotTextState
 
1096
poppler_annot_text_get_state (PopplerAnnotText *poppler_annot)
 
1097
{
 
1098
  AnnotText *annot;
 
1099
 
 
1100
  g_return_val_if_fail (POPPLER_IS_ANNOT_TEXT (poppler_annot), POPPLER_ANNOT_TEXT_STATE_UNKNOWN);
 
1101
 
 
1102
  annot = static_cast<AnnotText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1103
 
 
1104
  switch (annot->getState ())
 
1105
    {
 
1106
    case AnnotText::stateUnknown:
 
1107
      return POPPLER_ANNOT_TEXT_STATE_UNKNOWN;
 
1108
    case AnnotText::stateMarked:
 
1109
      return POPPLER_ANNOT_TEXT_STATE_MARKED;
 
1110
    case AnnotText::stateUnmarked:
 
1111
      return POPPLER_ANNOT_TEXT_STATE_UNMARKED;
 
1112
    case AnnotText::stateAccepted:
 
1113
      return POPPLER_ANNOT_TEXT_STATE_ACCEPTED;
 
1114
    case AnnotText::stateRejected:
 
1115
      return POPPLER_ANNOT_TEXT_STATE_REJECTED;
 
1116
    case AnnotText::stateCancelled:
 
1117
      return POPPLER_ANNOT_TEXT_STATE_CANCELLED;
 
1118
    case AnnotText::stateCompleted:
 
1119
      return POPPLER_ANNOT_TEXT_STATE_COMPLETED;
 
1120
    case AnnotText::stateNone:
 
1121
      return POPPLER_ANNOT_TEXT_STATE_NONE;
 
1122
    default:
 
1123
      g_warning ("Unsupported Annot Text State");
 
1124
    }
 
1125
 
 
1126
  return POPPLER_ANNOT_TEXT_STATE_UNKNOWN;
 
1127
}
 
1128
 
 
1129
/* PopplerAnnotFreeText */
 
1130
/**
 
1131
 * poppler_annot_free_text_get_quadding:
 
1132
 * @poppler_annot: a #PopplerAnnotFreeText
 
1133
 *
 
1134
 * Retrieves the justification of the text of @poppler_annot.
 
1135
 *
 
1136
 * Return value: #PopplerAnnotFreeTextQuadding of @poppler_annot.
 
1137
 **/ 
 
1138
PopplerAnnotFreeTextQuadding
 
1139
poppler_annot_free_text_get_quadding (PopplerAnnotFreeText *poppler_annot)
 
1140
{
 
1141
  AnnotFreeText *annot;
 
1142
 
 
1143
  g_return_val_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot), POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED);
 
1144
 
 
1145
  annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1146
 
 
1147
  switch (annot->getQuadding ())
 
1148
  {
 
1149
    case AnnotFreeText::quaddingLeftJustified:
 
1150
      return POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED;
 
1151
    case AnnotFreeText::quaddingCentered:
 
1152
      return POPPLER_ANNOT_FREE_TEXT_QUADDING_CENTERED;
 
1153
    case AnnotFreeText::quaddingRightJustified:
 
1154
      return POPPLER_ANNOT_FREE_TEXT_QUADDING_RIGHT_JUSTIFIED;
 
1155
    default:
 
1156
      g_warning ("Unsupported Annot Free Text Quadding");
 
1157
  }
 
1158
 
 
1159
  return POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED;
 
1160
}
 
1161
 
 
1162
/**
 
1163
 * poppler_annot_free_text_get_callout_line:
 
1164
 * @poppler_annot: a #PopplerAnnotFreeText
 
1165
 *
 
1166
 * Retrieves a #PopplerCalloutLine of four or six numbers specifying a callout
 
1167
 * line attached to the @poppler_annot.
 
1168
 *
 
1169
 * Return value: a new allocated #PopplerCalloutLine if the annot has a callout
 
1170
 *               line, NULL in other case. It must be freed with g_free() when
 
1171
 *               done.
 
1172
 **/
 
1173
PopplerAnnotCalloutLine *
 
1174
poppler_annot_free_text_get_callout_line (PopplerAnnotFreeText *poppler_annot)
 
1175
{
 
1176
  AnnotFreeText *annot;
 
1177
  AnnotCalloutLine *line;
 
1178
 
 
1179
  g_return_val_if_fail (POPPLER_IS_ANNOT_FREE_TEXT (poppler_annot), NULL);
 
1180
 
 
1181
  annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1182
 
 
1183
  if ((line = annot->getCalloutLine ())) {
 
1184
    AnnotCalloutMultiLine *multiline;
 
1185
    PopplerAnnotCalloutLine *callout = g_new0 (PopplerAnnotCalloutLine, 1);
 
1186
 
 
1187
    callout->x1 = line->getX1();
 
1188
    callout->y1 = line->getY1();
 
1189
    callout->x2 = line->getX2();
 
1190
    callout->y2 = line->getY2();
 
1191
 
 
1192
    if ((multiline = static_cast<AnnotCalloutMultiLine *>(line))) {
 
1193
      callout->multiline = TRUE;
 
1194
      callout->x3 = multiline->getX3();
 
1195
      callout->y3 = multiline->getY3();
 
1196
      return callout;
 
1197
    }
 
1198
 
 
1199
    callout->multiline = FALSE;
 
1200
    return callout;
 
1201
  }
 
1202
 
 
1203
  return NULL;
 
1204
}
 
1205
 
 
1206
/* PopplerAnnotFileAttachment */
 
1207
/**
 
1208
 * poppler_annot_file_attachment_get_attachment:
 
1209
 * @poppler_annot: a #PopplerAnnotFileAttachment
 
1210
 *
 
1211
 * Creates a #PopplerAttachment for the file of the file attachment annotation @annot.
 
1212
 * The #PopplerAttachment must be unrefed with g_object_unref by the caller.
 
1213
 *
 
1214
 * Return value: @PopplerAttachment
 
1215
 *
 
1216
 * Since: 0.14
 
1217
 **/
 
1218
PopplerAttachment *
 
1219
poppler_annot_file_attachment_get_attachment (PopplerAnnotFileAttachment *poppler_annot)
 
1220
{
 
1221
  AnnotFileAttachment *annot;
 
1222
  PopplerAttachment *attachment;
 
1223
 
 
1224
  g_return_val_if_fail (POPPLER_IS_ANNOT_FILE_ATTACHMENT (poppler_annot), NULL);
 
1225
 
 
1226
  annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1227
 
 
1228
  EmbFile *emb_file = new EmbFile (annot->getFile(), annot->getContents());
 
1229
  attachment = _poppler_attachment_new (emb_file);
 
1230
  delete emb_file;
 
1231
 
 
1232
  return attachment;
 
1233
}
 
1234
 
 
1235
/**
 
1236
 * poppler_annot_file_attachment_get_name:
 
1237
 * @poppler_annot: a #PopplerAnnotFileAttachment
 
1238
 *
 
1239
 * Retrieves the name of @poppler_annot.
 
1240
 *
 
1241
 * Return value: a new allocated string with the name of @poppler_annot. It must
 
1242
 *               be freed with g_free() when done.
 
1243
 * Since: 0.14
 
1244
 **/
 
1245
gchar *
 
1246
poppler_annot_file_attachment_get_name (PopplerAnnotFileAttachment *poppler_annot)
 
1247
{
 
1248
  AnnotFileAttachment *annot;
 
1249
  GooString *name;
 
1250
 
 
1251
  g_return_val_if_fail (POPPLER_IS_ANNOT_FILE_ATTACHMENT (poppler_annot), NULL);
 
1252
 
 
1253
  annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1254
  name = annot->getName ();
 
1255
 
 
1256
  return name ? _poppler_goo_string_to_utf8 (name) : NULL;
 
1257
}
 
1258
 
 
1259
/* PopplerAnnotCalloutLine */
 
1260
POPPLER_DEFINE_BOXED_TYPE (PopplerAnnotCalloutLine, poppler_annot_callout_line,
 
1261
                           poppler_annot_callout_line_copy,
 
1262
                           poppler_annot_callout_line_free)
 
1263
 
 
1264
/**
 
1265
 * poppler_annot_callout_line_new:
 
1266
 *
 
1267
 * Creates a new empty #PopplerAnnotCalloutLine.
 
1268
 *
 
1269
 * Return value: a new allocated #PopplerAnnotCalloutLine, NULL in other case.
 
1270
 *               It must be freed when done.
 
1271
 **/
 
1272
PopplerAnnotCalloutLine *
 
1273
poppler_annot_callout_line_new (void)
 
1274
{
 
1275
  return g_new0 (PopplerAnnotCalloutLine, 1);
 
1276
}
 
1277
 
 
1278
/**
 
1279
 * poppler_annot_callout_line_copy:
 
1280
 * @callout: the #PopplerAnnotCalloutline to be copied.
 
1281
 *
 
1282
 * It does copy @callout to a new #PopplerAnnotCalloutLine.
 
1283
 *
 
1284
 * Return value: a new allocated #PopplerAnnotCalloutLine as exact copy of
 
1285
 *               @callout, NULL in other case. It must be freed when done.
 
1286
 **/
 
1287
PopplerAnnotCalloutLine *
 
1288
poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *callout)
 
1289
{
 
1290
  PopplerAnnotCalloutLine *new_callout;
 
1291
 
 
1292
  g_return_val_if_fail (callout != NULL, NULL);
 
1293
  
 
1294
  new_callout = g_new0 (PopplerAnnotCalloutLine, 1);
 
1295
  *new_callout = *callout;
 
1296
 
 
1297
  return new_callout;
 
1298
}
 
1299
 
 
1300
/**
 
1301
 * poppler_annot_callout_line_free:
 
1302
 * @callout: a #PopplerAnnotCalloutLine
 
1303
 *
 
1304
 * Frees the memory used by #PopplerAnnotCalloutLine.
 
1305
 **/
 
1306
void
 
1307
poppler_annot_callout_line_free (PopplerAnnotCalloutLine *callout)
 
1308
{
 
1309
  g_free (callout);
 
1310
}
 
1311
 
 
1312
 
 
1313
/* PopplerAnnotMovie */
 
1314
/**
 
1315
 * poppler_annot_movie_get_title:
 
1316
 * @poppler_annot: a #PopplerAnnotMovie
 
1317
 *
 
1318
 * Retrieves the movie title of @poppler_annot.
 
1319
 *
 
1320
 * Return value: the title text of @poppler_annot.
 
1321
 *
 
1322
 * Since: 0.14
 
1323
 */
 
1324
gchar *
 
1325
poppler_annot_movie_get_title (PopplerAnnotMovie *poppler_annot)
 
1326
{
 
1327
  AnnotMovie *annot;
 
1328
  GooString *title;
 
1329
 
 
1330
  g_return_val_if_fail (POPPLER_IS_ANNOT_MOVIE (poppler_annot), NULL);
 
1331
 
 
1332
  annot = static_cast<AnnotMovie *>(POPPLER_ANNOT (poppler_annot)->annot);
 
1333
 
 
1334
  title = annot->getTitle ();
 
1335
 
 
1336
  return title ? _poppler_goo_string_to_utf8 (title) : NULL;
 
1337
}
 
1338
 
 
1339
/**
 
1340
 * poppler_annot_movie_get_movie:
 
1341
 * @poppler_annot: a #PopplerAnnotMovie
 
1342
 *
 
1343
 * Retrieves the movie object (PopplerMovie) stored in the @poppler_annot.
 
1344
 *
 
1345
 * Return value: (transfer none): the movie object stored in the @poppler_annot. The returned
 
1346
 *               object is owned by #PopplerAnnotMovie and should not be freed
 
1347
 *
 
1348
 * Since: 0.14
 
1349
 */
 
1350
PopplerMovie *
 
1351
poppler_annot_movie_get_movie (PopplerAnnotMovie *poppler_annot)
 
1352
{
 
1353
  return poppler_annot->movie;
 
1354
}
 
1355
 
 
1356
/* PopplerAnnotScreen */
 
1357
/**
 
1358
 * poppler_annot_screen_get_action:
 
1359
 * @poppler_annot: a #PopplerAnnotScreen
 
1360
 *
 
1361
 * Retrieves the action (#PopplerAction) that shall be performed when @poppler_annot is activated
 
1362
 *
 
1363
 * Return value: (transfer none): the action to perform. The returned
 
1364
 *               object is owned by @poppler_annot and should not be freed
 
1365
 *
 
1366
 * Since: 0.14
 
1367
 */
 
1368
PopplerAction *
 
1369
poppler_annot_screen_get_action (PopplerAnnotScreen *poppler_annot)
 
1370
{
 
1371
  return poppler_annot->action;
 
1372
}