File: fo-libfo-context.c

package info (click to toggle)
xmlroff 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 36,456 kB
  • ctags: 25,964
  • sloc: ansic: 178,200; xml: 109,155; sh: 8,973; makefile: 1,331; perl: 30
file content (553 lines) | stat: -rw-r--r-- 14,589 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/* Fo
 * fo-libfo-context.c: 'FoLibfoContext' object type
 *
 * Copyright (C) 2003 Sun Microsystems
 * Copyright (C) 2007-2008 Menteith Consulting Ltd
 *
 * See COPYING for the status of this software.
 */

#include <string.h>
#include "libfo/fo-utils.h"
#include "libfo/fo-libfo-context.h"
#include "fo-object.h"

/**
 * SECTION:fo-libfo-context
 * @short_description: Collected information about the processing context
 *
 * Collected information about the processing context in which to do the formatting.
 *
 * This context contains parameters that are not part of the XML for
 * the FO, e.g., whether or not to validate the input and whether or
 * not to embed fonts in the output.
 */

GType
fo_flags_format_get_type (void)
{
  static GType ftype = 0;
  if (ftype == 0)
    {
      static const GFlagsValue values[] = {
        { FO_FLAG_FORMAT_UNKNOWN, "FO_FLAG_FORMAT_UNKNOWN", "unknown" },
        { FO_FLAG_FORMAT_AUTO, "FO_FLAG_FORMAT_AUTO", "auto" },
        { FO_FLAG_FORMAT_PDF, "FO_FLAG_FORMAT_PDF", "PDF" },
        { FO_FLAG_FORMAT_POSTSCRIPT, "FO_FLAG_FORMAT_POSTSCRIPT", "PostScript" },
        { FO_FLAG_FORMAT_SVG, "FO_FLAG_FORMAT_SVG", "SVG" },
        { 0, NULL, NULL }
      };
      ftype = g_flags_register_static ("FoFlagsFormat", values);
    }
  return ftype;
}

GType
fo_enum_font_embed_get_type (void)
{
  static GType etype = 0;
  if (etype == 0)
    {
      static const GEnumValue values[] = {
        { FO_ENUM_FONT_EMBED_INVALID, "FO_ENUM_FONT_EMBED_INVALID", "invalid" },
        { FO_ENUM_FONT_EMBED_ALL, "FO_ENUM_FONT_EMBED_ALL", "all" },
        { FO_ENUM_FONT_EMBED_NONBASE, "FO_ENUM_FONT_EMBED_NONBASE", "nonbase" },
        { FO_ENUM_FONT_EMBED_NONE, "FO_ENUM_FONT_EMBED_NONE", "none" },
        { 0, NULL, NULL }
      };
      etype = g_enum_register_static ("FoEnumFontEmbed", values);
    }
  return etype;
}

struct _FoLibfoContext
{
  FoObject parent_instance;

  gboolean        validation;
  FoFlagsFormat   format;
  FoEnumFontEmbed font_embed;
  FoWarningFlag   warning_mode;
  gboolean        continue_after_error;
  FoDebugFlag     debug_mode;
};

struct _FoLibfoContextClass
{
  FoObjectClass parent_class;
};

enum {
  PROP_0,
  PROP_XML,
  PROP_XSLT,
  PROP_FO_TREE,
  PROP_AREA_TREE,
  PROP_OUTPUT,
  PROP_FORMAT,
  PROP_FONT_EMBED,
  PROP_VALIDATION,
  PROP_CONTINUE,
  PROP_DEBUG_MODE,
  PROP_WARNING_MODE
};

static void fo_libfo_context_init (FoLibfoContext      *libfo_context);
static void fo_libfo_context_class_init   (FoLibfoContextClass *klass);
static void fo_libfo_context_get_property (GObject         *object,
					   guint            prop_id,
					   GValue          *value,
					   GParamSpec      *pspec);
static void fo_libfo_context_set_property (GObject         *object,
					   guint            prop_id,
					   const GValue    *value,
					   GParamSpec      *pspec);

static gpointer parent_class;

/**
 * fo_libfo_context_get_type:
 * 
 * Register the #FoLibfoContext type if not already registered and
 * return its #GType value.
 * 
 * Return value: #GType of #FoLibfoContext.
 **/
GType
fo_libfo_context_get_type (void)
{
  static GType object_type = 0;

  if (!object_type)
    {
      static const GTypeInfo object_info =
      {
        sizeof (FoLibfoContextClass),
        NULL,           /* base_init */
        NULL,           /* base_finalize */
        (GClassInitFunc) fo_libfo_context_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (FoLibfoContext),
        0,              /* n_preallocs */
	(GInstanceInitFunc) fo_libfo_context_init,
	NULL		/* value_table */
      };

      object_type = g_type_register_static (FO_TYPE_OBJECT,
                                            "FoLibfoContext",
                                            &object_info, 0);
    }

  return object_type;
}

/**
 * fo_libfo_context_init:
 * @libfo_context: #FoLibfoContext object to initialise.
 * 
 * Implements #GInstanceInitFunc for #FoLibfoContext.
 *
 * Initialises format to %FO_FLAG_FORMAT_AUTO.
 **/
void
fo_libfo_context_init (FoLibfoContext *libfo_context)
{
  libfo_context->format = FO_FLAG_FORMAT_AUTO;
}

/**
 * fo_libfo_context_class_init:
 * @klass: #FoLibfoContextClass object to initialise.
 * 
 * Implements #GClassInitFunc for #FoLibfoContextClass.
 **/
void
fo_libfo_context_class_init (FoLibfoContextClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  parent_class = g_type_class_peek_parent (klass);

  object_class->get_property = fo_libfo_context_get_property;
  object_class->set_property = fo_libfo_context_set_property;

  g_object_class_install_property
    (object_class,
     PROP_FORMAT,
     g_param_spec_flags ("format",
			 _("Output format"),
			 _("Output file format"),
			 FO_TYPE_FLAGS_FORMAT,
			 FO_FLAG_FORMAT_PDF,
			 G_PARAM_READWRITE));

  g_object_class_install_property
    (object_class,
     PROP_FORMAT,
     g_param_spec_enum ("font-embed",
			_("Font embed"),
			_("Font embedding mode"),
			FO_TYPE_ENUM_FONT_EMBED,
			FO_ENUM_FONT_EMBED_NONBASE,
			G_PARAM_READWRITE));

  g_object_class_install_property
    (object_class,
     PROP_VALIDATION,
     g_param_spec_boolean ("validation",
			   _("Validation enabled?"),
			   _("Is validation of the input XML source enabled?"),
			   TRUE,
			   G_PARAM_READWRITE));

  g_object_class_install_property
    (object_class,
     PROP_VALIDATION,
     g_param_spec_boolean ("continue",
			   _("Continue after error?"),
			   _("Continue formatting after any formatting errors?"),
			   FALSE,
			   G_PARAM_READWRITE));

  g_object_class_install_property
    (object_class,
     PROP_DEBUG_MODE,
     g_param_spec_int ("debug-mode",
		       _("Debug mode"),
		       _("Debugging mode"),
		       0,
		       FO_DEBUG_MAX,
		       0,
		       G_PARAM_READWRITE));

  g_object_class_install_property
    (object_class,
     PROP_WARNING_MODE,
     g_param_spec_int ("warning-mode",
		       _("Warning mode"),
		       _("Warning mode"),
		       0,
		       FO_WARNING_MAX,
		       0,
		       G_PARAM_READWRITE));
}

/**
 * fo_libfo_context_get_property:
 * @object:  #GObject whose property will be retreived
 * @prop_id: Property ID assigned when property registered
 * @value:   #GValue to set with property value
 * @pspec:   Parameter specification for this property type
 * 
 * Implements #GObjectGetPropertyFunc for #FoLibfoContext
 **/
void
fo_libfo_context_get_property (GObject        *object,
			       guint           param_id,
			       GValue         *value,
			       GParamSpec     *pspec)
{
  FoLibfoContext *libfo_context = FO_LIBFO_CONTEXT (object);
  
  switch (param_id)
    {
    case PROP_FORMAT:
      g_value_set_enum (value, libfo_context->format);
      break;
    case PROP_FONT_EMBED:
      g_value_set_enum (value, libfo_context->font_embed);
      break;
    case PROP_VALIDATION:
      g_value_set_boolean (value, libfo_context->validation);
      break;
    case PROP_CONTINUE:
      g_value_set_boolean (value, libfo_context->continue_after_error);
      break;
    case PROP_DEBUG_MODE:
      g_value_set_int (value, libfo_context->debug_mode);
      break;
    case PROP_WARNING_MODE:
      g_value_set_int (value, libfo_context->warning_mode);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

/**
 * fo_libfo_context_set_property:
 * @object:  #GObject whose property will be set
 * @prop_id: Property ID assigned when property registered
 * @value:   New value for property
 * @pspec:   Parameter specification for this property type
 * 
 * Implements #GObjectSetPropertyFunc for #FoLibfoContext
 **/
void
fo_libfo_context_set_property (GObject      *object,
			       guint         param_id,
			       const GValue *value,
			       GParamSpec   *pspec)
{
  FoLibfoContext *fo_libfo_context;

  fo_libfo_context = FO_LIBFO_CONTEXT (object);

  switch (param_id)
    {
    case PROP_FORMAT:
      fo_libfo_context_set_format (fo_libfo_context,
				   g_value_get_enum (value));
      break;
    case PROP_FONT_EMBED:
      fo_libfo_context_set_font_embed (fo_libfo_context,
				       g_value_get_enum (value));
      break;
    case PROP_VALIDATION:
      fo_libfo_context_set_validation (fo_libfo_context,
				       g_value_get_boolean (value));
      break;
    case PROP_CONTINUE:
      fo_libfo_context_set_continue_after_error (fo_libfo_context,
						 g_value_get_boolean (value));
      break;
    case PROP_DEBUG_MODE:
      fo_libfo_context_set_debug_mode (fo_libfo_context,
				       g_value_get_int (value));
      break;
    case PROP_WARNING_MODE:
      fo_libfo_context_set_warning_mode (fo_libfo_context,
					 g_value_get_int (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
      break;
    }
}

/**
 * fo_libfo_context_new:
 * 
 * Creates a new #FoLibfoContext initialized to default value.
 * 
 * Return value: The new #FoLibfoContext.
 **/
FoLibfoContext *
fo_libfo_context_new (void)
{
  FoLibfoContext* libfo_context;

  libfo_context =
    g_object_new (fo_libfo_context_get_type (),
		  NULL);

  return libfo_context;
}

/**
 * fo_libfo_context_get_format:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'format' property of @libfo_context.
 *
 * Return value: Value of the 'format' property of @libfo_context.
 **/
FoFlagsFormat
fo_libfo_context_get_format (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context),
			FO_FLAG_FORMAT_UNKNOWN);

  return libfo_context->format;
}


/**
 * fo_libfo_context_set_format:
 * @libfo_context: #FoLibfoContext.
 * @format:        New 'format' value for @libfo_context.
 * 
 * Set the 'format' property of @libfo_context.
 *
 * If more that one flag value is set in @format, only the first
 * (lowest) set value will be used.
 **/
void
fo_libfo_context_set_format (FoLibfoContext *libfo_context,
			     FoFlagsFormat   format)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));
  g_return_if_fail (g_flags_get_first_value (g_type_class_peek (FO_TYPE_FLAGS_FORMAT),
					     format) != NULL);

  libfo_context->format =
    g_flags_get_first_value (g_type_class_peek (FO_TYPE_FLAGS_FORMAT),
			     format)->value;
}

/**
 * fo_libfo_context_get_font_embed:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'font-embed' property of @libfo_context.
 *
 * Return value: Value of the 'font-embed' property of @libfo_context.
 **/
FoEnumFontEmbed
fo_libfo_context_get_font_embed (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context),
			FO_ENUM_FONT_EMBED_INVALID);

  return libfo_context->font_embed;
}


/**
 * fo_libfo_context_set_font_embed:
 * @libfo_context: #FoLibfoContext.
 * @font_embed:    New 'font-embed' value for @libfo_context.
 * 
 * Set the 'font-embed' property of @libfo_context.
 **/
void
fo_libfo_context_set_font_embed (FoLibfoContext *libfo_context,
				 FoEnumFontEmbed font_embed)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));
  g_return_if_fail (g_enum_get_value (g_type_class_peek (FO_TYPE_ENUM_FONT_EMBED),
				      font_embed) != NULL);

  libfo_context->font_embed = font_embed;
}

/**
 * fo_libfo_context_get_validation:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'validation' property of @libfo_context.
 *
 * Return value: Value of the 'validation' property of @libfo_context.
 **/
gboolean
fo_libfo_context_get_validation (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context), FALSE);

  return libfo_context->validation;
}

/**
 * fo_libfo_context_set_validation:
 * @libfo_context: #FoLibfoContext.
 * @validation:    New 'validation' value for @libfo_context.
 * 
 * Set the 'validation' property of @libfo_context.
 **/
void
fo_libfo_context_set_validation (FoLibfoContext *libfo_context,
				 gboolean        validation)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));

  libfo_context->validation = validation;
}

/**
 * fo_libfo_context_get_continue_after_error:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'continue' property of @libfo_context.
 *
 * Return value: Value of the 'continue' property of @libfo_context.
 **/
gboolean
fo_libfo_context_get_continue_after_error (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context), FALSE);

  return libfo_context->continue_after_error;
}

/**
 * fo_libfo_context_set_continue_after_error:
 * @libfo_context:     #FoLibfoContext.
 * @continue_after_error: New 'continue' value for @libfo_context.
 * 
 * Set the 'continue' property of @libfo_context.
 **/
void
fo_libfo_context_set_continue_after_error (FoLibfoContext *libfo_context,
					   gboolean        continue_after_error)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));

  libfo_context->continue_after_error = continue_after_error;
}

/**
 * fo_libfo_context_get_warning_mode:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'warning_mode' property of @libfo_context.
 *
 * Return value: Value of the 'warning_mode' property of @libfo_context.
 **/
FoWarningFlag
fo_libfo_context_get_warning_mode (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context), 0);

  return libfo_context->warning_mode;
}

/**
 * fo_libfo_context_set_warning_mode:
 * @libfo_context: #FoLibfoContext.
 * @warning_mode:    New 'warning-mode' value for @libfo_context.
 * 
 * Set the 'warning-mode' property of @libfo_context.
 **/
void
fo_libfo_context_set_warning_mode (FoLibfoContext *libfo_context,
				   FoWarningFlag   warning_mode)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));
  g_return_if_fail (warning_mode <= FO_WARNING_MAX);

  libfo_context->warning_mode = warning_mode;
}

/**
 * fo_libfo_context_get_debug_mode:
 * @libfo_context: #FoLibfoContext.
 * 
 * Get the 'debug_mode' property of @libfo_context.
 *
 * Return value: Value of the 'debug_mode' property of @libfo_context.
 **/
FoDebugFlag
fo_libfo_context_get_debug_mode (FoLibfoContext *libfo_context)
{
  g_return_val_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context), 0);

  return libfo_context->debug_mode;
}

/**
 * fo_libfo_context_set_debug_mode:
 * @libfo_context: #FoLibfoContext.
 * @debug_mode:    New 'debug-mode' value for @libfo_context.
 * 
 * Set the 'debug-mode' property of @libfo_context.
 **/
void
fo_libfo_context_set_debug_mode (FoLibfoContext *libfo_context,
				 FoDebugFlag     debug_mode)
{
  g_return_if_fail (FO_IS_LIBFO_CONTEXT (libfo_context));

  libfo_context->debug_mode = debug_mode;
}