Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/zcfont.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, for further information.
14
*/
15
16
17
/* Composite font-related character operators */
18
#include "ghost.h"
19
#include "oper.h"
20
#include "gsmatrix.h"   /* for gxfont.h */
21
#include "gxfixed.h"    /* for gxfont.h */
22
#include "gxfont.h"
23
#include "gxtext.h"
24
#include "estack.h"
25
#include "ichar.h"
26
#include "ifont.h"
27
#include "igstate.h"
28
#include "store.h"
29
30
/* Forward references */
31
static int cshow_continue(i_ctx_t *);
32
static int cshow_restore_font(i_ctx_t *);
33
34
/* <proc> <string> cshow - */
35
static int
36
zcshow(i_ctx_t *i_ctx_p)
37
9
{
38
9
    os_ptr op = osp;
39
9
    os_ptr proc_op = op - 1;
40
9
    os_ptr str_op = op;
41
9
    gs_text_enum_t *penum;
42
9
    int code;
43
44
    /*
45
     * Even though this is not documented anywhere by Adobe,
46
     * some Adobe interpreters apparently allow the string and
47
     * the procedure to be provided in either order!
48
     */
49
9
    if (r_is_proc(proc_op))
50
0
        ;
51
9
    else if (r_is_proc(op)) { /* operands reversed */
52
0
        proc_op = op;
53
0
        str_op = op - 1;
54
9
    } else {
55
9
        check_op(2);
56
9
        return_error(gs_error_typecheck);
57
9
    }
58
0
    if ((code = op_show_setup(i_ctx_p, str_op)) != 0 ||
59
0
        (code = gs_cshow_begin(igs, str_op->value.bytes, r_size(str_op),
60
0
                               imemory, &penum)) < 0)
61
0
        return code;
62
0
    if ((code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
63
0
        ifree_object(penum, "op_show_enum_setup");
64
0
        return code;
65
0
    }
66
0
    sslot = *proc_op;    /* save kerning proc */
67
0
    ref_stack_pop(&o_stack, 2);
68
0
    return cshow_continue(i_ctx_p);
69
0
}
70
static int
71
cshow_continue(i_ctx_t *i_ctx_p)
72
0
{
73
0
    os_ptr op = osp;
74
0
    gs_text_enum_t *penum = senum;
75
0
    int code;
76
77
0
    check_estack(4);   /* in case we call the procedure */
78
0
    code = gs_text_process(penum);
79
0
    if (code != TEXT_PROCESS_INTERVENE) {
80
0
        code = op_show_continue_dispatch(i_ctx_p, 0, code);
81
0
        if (code == o_push_estack) /* must be TEXT_PROCESS_RENDER */
82
0
            make_op_estack(esp - 1, cshow_continue);
83
0
        return code;
84
0
    }
85
    /* Push the character code and width, and call the procedure. */
86
0
    {
87
0
        ref *pslot = &sslot;
88
0
        gs_point wpt;
89
0
        gs_font *font = gs_text_current_font(penum);
90
0
        gs_font *root_font = gs_rootfont(igs);
91
0
        gs_font *scaled_font;
92
0
        uint font_space = r_space(pfont_dict(font));
93
0
        uint root_font_space = r_space(pfont_dict(root_font));
94
0
        int fdepth = penum->fstack.depth;
95
96
0
        gs_text_current_width(penum, &wpt);
97
0
        if (font == root_font)
98
0
            scaled_font = font;
99
0
        else if (fdepth > 0) {
100
          /* Construct a scaled version of the leaf font.
101
             If font stack is deep enough, get the matrix for scaling
102
             from the immediate parent of current font.
103
             (The font matrix of root font is not good for the purpose
104
             in some case.)
105
             assert_(penum->fstack.items[fdepth].font == font
106
                     && penum->fstack.items[0].font == root_font); */
107
0
          uint save_space = idmemory->current_space;
108
0
          gs_font * immediate_parent = penum->fstack.items[fdepth - 1].font;
109
110
0
          ialloc_set_space(idmemory, font_space);
111
0
          code = gs_makefont(font->dir, font,
112
0
                             &immediate_parent->FontMatrix,
113
0
                             &scaled_font);
114
0
          ialloc_set_space(idmemory, save_space);
115
0
          if (code < 0)
116
0
            return code;
117
0
        }
118
0
        else {
119
            /* Construct a scaled version of the leaf font. */
120
0
            uint save_space = idmemory->current_space;
121
122
0
            ialloc_set_space(idmemory, font_space);
123
0
            code = gs_makefont(font->dir, font, &root_font->FontMatrix,
124
0
                               &scaled_font);
125
0
            ialloc_set_space(idmemory, save_space);
126
0
            if (code < 0)
127
0
                return code;
128
0
        }
129
0
        push(3);
130
0
        make_int(op - 2, gs_text_current_char(penum) & 0xff);
131
0
        make_real(op - 1, wpt.x);
132
0
        make_real(op, wpt.y);
133
0
        make_struct(&ssfont, font_space, font);
134
0
        make_struct(&srfont, root_font_space, root_font);
135
0
        push_op_estack(cshow_restore_font);
136
        /* cshow does not change rootfont for user procedure */
137
0
        gs_set_currentfont(igs, scaled_font);
138
0
        *++esp = *pslot;  /* user procedure */
139
0
    }
140
0
    return o_push_estack;
141
0
}
142
static int
143
cshow_restore_font(i_ctx_t *i_ctx_p)
144
0
{
145
    /* We must restore both the root font and the current font. */
146
0
    gs_setfont(igs, r_ptr(&srfont, gs_font));
147
0
    gs_set_currentfont(igs, r_ptr(&ssfont, gs_font));
148
0
    return cshow_continue(i_ctx_p);
149
0
}
150
151
/* - rootfont <font> */
152
static int
153
zrootfont(i_ctx_t *i_ctx_p)
154
6
{
155
6
    os_ptr op = osp;
156
157
6
    push(1);
158
6
    *op = *pfont_dict(gs_rootfont(igs));
159
6
    return 0;
160
6
}
161
162
/* ------ Initialization procedure ------ */
163
164
const op_def zcfont_op_defs[] =
165
{
166
    {"2cshow", zcshow},
167
    {"0rootfont", zrootfont},
168
                /* Internal operators */
169
    {"0%cshow_continue", cshow_continue},
170
    {"0%cshow_restore_font", cshow_restore_font},
171
    op_def_end(0)
172
};