summaryrefslogtreecommitdiff
path: root/svg/ghostsvg.h
blob: 52d1c322ddd36812f485e3ab0a5b03cf5d9a53a0 (plain)
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
#include "memory_.h"
#include "math_.h"

#include <stdlib.h>
#include <ctype.h> /* for toupper() */

#include "gsgc.h"
#include "gstypes.h"
#include "gsstate.h"
#include "gsmatrix.h"
#include "gscoord.h"
#include "gsmemory.h"
#include "gsparam.h"
#include "gsdevice.h"
#include "scommon.h"
#include "gserror.h"
#include "gserrors.h"
#include "gspaint.h"
#include "gspath.h"
#include "gsimage.h"
#include "gscspace.h"
#include "gsptype1.h"
#include "gscolor2.h"
#include "gscolor3.h"
#include "gsutil.h"
#include "gsicc.h"

#include "gstrans.h"

#include "gxpath.h"     /* gsshade.h depends on it */
#include "gxfixed.h"    /* gsshade.h depends on it */
#include "gxmatrix.h"	/* gxtype1.h depends on it */
#include "gsshade.h"
#include "gsfunc.h"
#include "gsfunc3.h"    /* we use stitching and exponential interp */

#include "gxfont.h"
#include "gxchar.h"
#include "gxtype1.h"
#include "gxfont1.h"
#include "gxfont42.h"
#include "gxfcache.h"
#include "gxistate.h"

#include "gzstate.h"
#include "gzpath.h"

#include "zlib.h"

/* override the debug printfs */
#ifndef DEBUG
#undef _dpl
#define _dpl
#undef dpf
#define dpf
#endif

#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
#ifndef ABS
#define ABS(a) ((a) < 0 ? -(a) : (a))
#endif

/*
 * Forward declarations.
 */

typedef struct svg_context_s svg_context_t;
typedef struct svg_item_s svg_item_t;

/*
 * Context and memory.
 */

#if (defined(_MSC_VER) && _MSC_VER < 1310) || !defined(__GNUC__)
/* Provide a fallback if this symbol is unsupported */
#define __FUNCTION__ "ghostsvg"
#endif

#define svg_alloc(ctx, size) \
    ((void*)gs_alloc_bytes(ctx->memory, size, __FUNCTION__));
#define svg_realloc(ctx, ptr, size) \
    gs_resize_object(ctx->memory, ptr, size, __FUNCTION__);
#define svg_strdup(ctx, str) \
    svg_strdup_imp(ctx, str, __FUNCTION__);
#define svg_free(ctx, ptr) \
    gs_free_object(ctx->memory, ptr, __FUNCTION__);

size_t svg_strlcpy(char *destination, const char *source, size_t size);
size_t svg_strlcat(char *destination, const char *source, size_t size);

char *svg_strdup_imp(svg_context_t *ctx, const char *str, const char *function);
char *svg_clean_path(char *name);
void svg_absolute_path(char *output, char *pwd, char *path);

/* end of page device callback foo */
int svg_show_page(svg_context_t *ctx, int num_copies, int flush);

int svg_utf8_to_ucs(int *p, const char *s, int n);

/*
 * Global context and XML parsing.
 */

int svg_open_xml_parser(svg_context_t *ctx);
int svg_feed_xml_parser(svg_context_t *ctx, char *buf, int len);
svg_item_t * svg_close_xml_parser(svg_context_t *ctx);
int svg_parse_document(svg_context_t *ctx, svg_item_t *root);

svg_item_t * svg_next(svg_item_t *item);
svg_item_t * svg_down(svg_item_t *item);
void svg_free_item(svg_context_t *ctx, svg_item_t *item);
char * svg_tag(svg_item_t *item);
char * svg_att(svg_item_t *item, const char *att);
void svg_debug_item(svg_item_t *item, int level);

struct svg_item_s
{
    char *name;
    char **atts;
    svg_item_t *up;
    svg_item_t *down;
    svg_item_t *next;
};

struct svg_context_s
{
    void *instance;
    gs_memory_t *memory;
    gs_state *pgs;
    gs_font_dir *fontdir;
    gs_color_space *srgb;

    svg_item_t *root;
    svg_item_t *head;
    const char *error;
    void *parser; /* Expat XML_Parser */
};