Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/gsfont0.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 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.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Composite font operations for Ghostscript library */
18
#include "memory_.h"
19
#include "gx.h"
20
#include "gserrors.h"
21
#include "gsstruct.h"
22
#include "gxfixed.h"
23
#include "gsmatrix.h"
24
#include "gxdevice.h"
25
#include "gxdevmem.h"
26
#include "gxfcache.h"   /* gs_font_dir */
27
#include "gxfont.h"
28
#include "gxfont0.h"
29
30
/* Structure descriptor */
31
static struct_proc_enum_ptrs(font_type0_enum_ptrs);
32
static struct_proc_reloc_ptrs(font_type0_reloc_ptrs);
33
34
public_st_gs_font_type0();
35
static
36
0
ENUM_PTRS_WITH(font_type0_enum_ptrs, gs_font_type0 *pfont)
37
0
ENUM_PREFIX(st_gs_font, gs_type0_data_max_ptrs);
38
0
ENUM_PTR(0, gs_font_type0, data.Encoding);
39
0
ENUM_PTR(1, gs_font_type0, data.FDepVector);
40
0
case 2:
41
0
switch (pfont->data.FMapType)
42
0
{
43
0
    case fmap_SubsVector:
44
0
        ENUM_RETURN_CONST_STRING_PTR(gs_font_type0,
45
0
                                     data.SubsVector);
46
0
    case fmap_CMap:
47
0
        ENUM_RETURN_PTR(gs_font_type0, data.CMap);
48
0
    default:
49
0
        ENUM_RETURN(0);
50
0
}
51
0
ENUM_PTRS_END
52
0
static RELOC_PTRS_WITH(font_type0_reloc_ptrs, gs_font_type0 *pfont)
53
0
RELOC_PREFIX(st_gs_font);
54
0
RELOC_PTR(gs_font_type0, data.Encoding);
55
0
RELOC_PTR(gs_font_type0, data.FDepVector);
56
0
switch (pfont->data.FMapType)
57
0
{
58
0
    case fmap_SubsVector:
59
0
RELOC_CONST_STRING_PTR(gs_font_type0, data.SubsVector);
60
0
break;
61
0
    case fmap_CMap:
62
0
RELOC_PTR(gs_font_type0, data.CMap);
63
0
break;
64
0
    default:
65
0
;
66
0
}
67
0
RELOC_PTRS_END
68
69
/* Adjust a composite font by concatenating a given matrix */
70
/* to the FontMatrix of all descendant composite fonts. */
71
static int
72
gs_type0_adjust_matrix(gs_font_dir * pdir, gs_font_type0 * pfont,
73
                       const gs_matrix * pmat)
74
0
{
75
0
    gs_font **pdep = pfont->data.FDepVector;
76
0
    uint fdep_size = pfont->data.fdep_size;
77
0
    gs_font **ptdep;
78
0
    uint i;
79
80
    /* Check for any descendant composite fonts. */
81
0
    for (i = 0; i < fdep_size; i++)
82
0
        if (pdep[i]->FontType == ft_composite)
83
0
            break;
84
0
    if (i == fdep_size)
85
0
        return 0;
86
0
    ptdep = gs_alloc_struct_array(pfont->memory, fdep_size, gs_font *,
87
0
                                  &st_gs_font_ptr_element,
88
0
                                  "gs_type0_adjust_font(FDepVector)");
89
0
    if (ptdep == 0)
90
0
        return_error(gs_error_VMerror);
91
0
    memcpy(ptdep, pdep, sizeof(gs_font *) * fdep_size);
92
0
    for (; i < fdep_size; i++)
93
0
        if (pdep[i]->FontType == ft_composite) {
94
0
            int code = gs_makefont(pdir, pdep[i], pmat, &ptdep[i]);
95
96
0
            if (code < 0)
97
0
                return code;
98
0
        }
99
0
    pfont->data.FDepVector = ptdep;
100
0
    return 0;
101
0
}
102
103
/* Finish defining a composite font, */
104
/* by adjusting its descendants' FontMatrices. */
105
int
106
gs_type0_define_font(gs_font_dir * pdir, gs_font * pfont)
107
0
{
108
0
    const gs_matrix *pmat = &pfont->FontMatrix;
109
110
    /* Check for the identity matrix, which is common in root fonts. */
111
0
    if (pmat->xx == 1.0 && pmat->yy == 1.0 &&
112
0
        pmat->xy == 0.0 && pmat->yx == 0.0 &&
113
0
        pmat->tx == 0.0 && pmat->ty == 0.0
114
0
        )
115
0
        return 0;
116
0
    return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) pfont, pmat);
117
0
}
118
119
/* Finish scaling a composite font similarly. */
120
int
121
gs_type0_make_font(gs_font_dir * pdir, const gs_font * pfont,
122
                   const gs_matrix * pmat, gs_font ** ppfont)
123
0
{
124
0
    return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) * ppfont, pmat);
125
0
}