summaryrefslogtreecommitdiff
path: root/xps/xpsfapi.c
blob: 0d671a87e9cfdca48ca163e59c849e2130dad965 (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
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
/* Copyright (C) 2001-2023 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
   CA 94129, USA, for further information.
*/

/* Font API support  */
#include "memory_.h"
#include "gsmemory.h"
#include "gserrors.h"
#include "gxdevice.h"
#include "gxfont.h"
#include "gzstate.h"
#include "gxchar.h"             /* for st_gs_show_enum */
#include "gdebug.h"
#include "gxfapi.h"

#include "xpsfapi.h"

/* forward declarations for the pl_ff_stub definition */
static int
xps_fapi_get_long(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, unsigned long *ret);

static int
xps_fapi_get_glyph(gs_fapi_font *ff, gs_glyph char_code, byte *buf,
                   int buf_length);

static int
xps_fapi_serialize_tt_font(gs_fapi_font *ff, void *buf, int buf_size);

static int
xps_get_glyphdirectory_data(gs_fapi_font *ff, int char_code,
                            const byte **ptr);

static int
xps_fapi_set_cache(gs_text_enum_t *penum, const gs_font_base *pbfont,
                   const gs_string *char_name, gs_glyph cid,
                   const double pwidth[2], const gs_rect *pbbox,
                   const double Metrics2_sbw_default[4], bool *imagenow);

static int
xps_fapi_get_metrics(gs_fapi_font *ff, gs_string *char_name, gs_glyph cid,
                     double *m, bool vertical);

static const gs_fapi_font pl_ff_stub = {
    0,                          /* server_font_data */
    0,                          /* need_decrypt */
    NULL,                       /* const gs_memory_t */
    0,                          /* font_file_path */
    0,                          /* full_font_buf */
    0,                          /* full_font_buf_len */
    0,                          /* subfont */
    false,                      /* is_type1 */
    false,                      /* is_cid */
    false,                      /* is_outline_font */
    false,                      /* is_mtx_skipped */
    false,                      /* is_vertical */
    false,                      /* metrics_only */
    {
    {3,10}, {3,1},{3,5},{3,4},\
      {3,3},{3,2},{3,0},{1,0},
      {-1,-1}},                 /* ttf_cmap_req */
    {-1, -1},                   /* ttf_cmap_selected */
    0,                          /* client_ctx_p */
    0,                          /* client_font_data */
    0,                          /* client_font_data2 */
    0,                          /* char_data */
    0,                          /* char_data_len */
    0,                          /* embolden */
    NULL,                       /* get_word */
    xps_fapi_get_long,          /* get_long */
    NULL,                       /* get_float */
    NULL,                       /* get_name */
    NULL,                       /* get_proc */
    NULL,                       /* get_gsubr */
    NULL,                       /* get_subr */
    NULL,                       /* get_raw_subr */
    xps_fapi_get_glyph,         /* get_glyph */
    xps_fapi_serialize_tt_font, /* serialize_tt_font */
    NULL,                       /* retrieve_tt_font */
    NULL,                       /* get_charstring */
    NULL,                       /* get_charstring_name */
    xps_get_glyphdirectory_data,        /* get_GlyphDirectory_data_ptr */
    0,                          /* get_glyphname_or_cid */
    xps_fapi_get_metrics,       /* fapi_get_metrics */
    xps_fapi_set_cache          /* fapi_set_cache */
};

static int
xps_fapi_get_long(gs_fapi_font *ff, gs_fapi_font_feature var_id, int index, unsigned long *ret)
{
    ulong value = -1;

    return (value);
}

static int
xps_fapi_get_glyph(gs_fapi_font *ff, gs_glyph char_code, byte *buf,
                   int buf_length)
{
    int size = -1;

    return (size);
}

static int
xps_fapi_serialize_tt_font(gs_fapi_font *ff, void *buf, int buf_size)
{
    int code = -1;

    return (code);
}

static int
xps_get_glyphdirectory_data(gs_fapi_font *ff, int char_code,
                            const byte **ptr)
{
    return (0);
}

static int
xps_fapi_get_metrics(gs_fapi_font *ff, gs_string *char_name, gs_glyph cid,
                     double *m, bool vertical)
{
    return (0);
}

static int
xps_fapi_set_cache(gs_text_enum_t *penum, const gs_font_base *pbfont,
                   const gs_string *char_name, gs_glyph cid,
                   const double pwidth[2], const gs_rect *pbbox,
                   const double Metrics2_sbw_default[4], bool *imagenow)
{
    gs_gstate *pgs = penum->pgs;
    float w2[6];

    w2[0] = pwidth[0];
    w2[1] = pwidth[1];
    w2[2] = pbbox->p.x;
    w2[3] = pbbox->p.y;
    w2[4] = pbbox->q.x;
    w2[5] = pbbox->q.y;
    if (pbfont->PaintType) {
        double expand =
            max(1.415,
                gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2;

        w2[2] -= expand;
        w2[3] -= expand;
        w2[4] += expand;
        w2[5] += expand;
    }
    *imagenow = true;
    return (gs_setcachedevice((gs_show_enum *)penum, pgs, w2));
}

static int
xps_fapi_build_char(gs_show_enum *penum, gs_gstate *pgs, gs_font *pfont,
                    gs_char chr, gs_glyph glyph)
{
    int code;

    code =
        gs_fapi_do_char(pfont, pgs,(gs_text_enum_t *)penum, NULL, false, NULL,
                        NULL, chr, glyph, 0);

    return (code);
}

static void
xps_get_server_param(gs_fapi_server *I, const char *subtype,
                     char **server_param, int *server_param_size)
{
    *server_param = NULL;
    *server_param_size = 0;
}

int
xps_fapi_passfont(gs_font *pfont, char *fapi_request, char *file_name,
                  byte *font_data, int font_data_len)
{
    char *fapi_id = NULL;
    int code = 0;
    gs_string fdata;

    if (!gs_fapi_available(pfont->memory, NULL)) {
        return (code);
    }

    fdata.data = font_data;
    fdata.size = font_data_len;

    /* The plfont should contain everything we need, but setting the client data for the server
     * to pbfont makes as much sense as setting it to NULL.
     */
    gs_fapi_set_servers_client_data(pfont->memory, &pl_ff_stub, pfont);

    code =
        gs_fapi_passfont(pfont, 0, file_name, &fdata, fapi_request, NULL,
                         &fapi_id,
                         (gs_fapi_get_server_param_callback)xps_get_server_param);

    if (code >= 0 && fapi_id == NULL) {
        code = gs_error_invalidfont;
    }

    pfont->procs.build_char = xps_fapi_build_char;
    return (code);
}