Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/ttload.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
18
/* Changes after FreeType: cut out the TrueType instruction interpreter. */
19
20
/*******************************************************************
21
 *
22
 *  ttload.c                                                    1.0
23
 *
24
 *    TrueType Tables Loader.
25
 *
26
 *  Copyright 1996-1998 by
27
 *  David Turner, Robert Wilhelm, and Werner Lemberg.
28
 *
29
 *  This file is part of the FreeType project, and may only be used
30
 *  modified and distributed under the terms of the FreeType project
31
 *  license, LICENSE.TXT.  By continuing to use, modify, or distribute
32
 *  this file you indicate that you have read the license and
33
 *  understand and accept it fully.
34
 *
35
 ******************************************************************/
36
37
#include "ttmisc.h"
38
39
#include "ttfoutl.h"
40
#include "tttypes.h"
41
#include "ttcalc.h"
42
#include "ttobjs.h"
43
#include "ttload.h"
44
#include "ttfinp.h"
45
46
#ifdef DEBUG
47
#  define DebugTrace( font, fmt )  (void)(!font->DebugPrint ? 0 : font->DebugPrint(font, fmt))
48
#  define DebugTrace1( font, fmt, x)  (void)(!font->DebugPrint ? 0 : font->DebugPrint(font, fmt, x))
49
#else
50
#  define DebugTrace( font, fmt )
51
#  define DebugTrace1( font, fmt, x)
52
#endif
53
54
/*******************************************************************
55
 *
56
 *  Function    :  Load_TrueType_MaxProfile
57
 *
58
 *  Description :  Loads the maxp table into face table.
59
 *
60
 *  Input  :  face     face table to look for
61
 *
62
 *  Output :  Error code.
63
 *
64
 ******************************************************************/
65
66
  TT_Error  Load_TrueType_MaxProfile( PFace  face )
67
2.40k
  {
68
2.40k
    ttfReader *r = face->r;
69
2.40k
    ttfFont *font = face->font;
70
2.40k
    PMaxProfile  maxProfile = &face->maxProfile;
71
72
2.40k
    r->Seek(r, font->t_maxp.nPos);
73
74
2.40k
    DebugTrace(font, "MaxProfile " );
75
76
    /* read frame data into face table */
77
2.40k
    maxProfile->version               = GET_ULong();
78
79
2.40k
    maxProfile->numGlyphs             = GET_UShort();
80
81
2.40k
    maxProfile->maxPoints             = GET_UShort();
82
2.40k
    maxProfile->maxContours           = GET_UShort();
83
2.40k
    maxProfile->maxCompositePoints    = GET_UShort();
84
2.40k
    maxProfile->maxCompositeContours  = GET_UShort();
85
86
2.40k
    maxProfile->maxZones              = GET_UShort();
87
2.40k
    maxProfile->maxTwilightPoints     = GET_UShort();
88
89
2.40k
    maxProfile->maxStorage            = GET_UShort();
90
2.40k
    maxProfile->maxFunctionDefs       = GET_UShort();
91
2.40k
    maxProfile->maxInstructionDefs    = GET_UShort();
92
2.40k
    maxProfile->maxStackElements      = GET_UShort();
93
2.40k
    maxProfile->maxSizeOfInstructions = GET_UShort();
94
2.40k
    maxProfile->maxComponentElements  = GET_UShort();
95
2.40k
    maxProfile->maxComponentDepth     = GET_UShort();
96
97
2.40k
    face->numGlyphs     = maxProfile->numGlyphs;
98
99
2.40k
    face->maxPoints     = MAX( maxProfile->maxCompositePoints,
100
2.40k
                               maxProfile->maxPoints );
101
2.40k
    face->maxContours   = MAX( maxProfile->maxCompositeContours,
102
2.40k
                               maxProfile->maxContours );
103
2.40k
    face->maxComponents = maxProfile->maxComponentElements +
104
2.40k
                          maxProfile->maxComponentDepth;
105
106
2.40k
    DebugTrace(font, "loaded\n");
107
108
2.40k
    return TT_Err_Ok;
109
2.40k
  }
110
111
/*******************************************************************
112
 *
113
 *  Function    :  Load_TrueType_CVT
114
 *
115
 *  Description :  Loads cvt table into resident table.
116
 *
117
 *  Input  :  face     face table to look for
118
 *
119
 *  Output :  Error code.
120
 *
121
 ******************************************************************/
122
123
  TT_Error  Load_TrueType_CVT( PFace  face )
124
2.40k
  {
125
2.40k
    long  n;
126
2.40k
    Int  limit;
127
128
2.40k
    ttfReader *r = face->r;
129
2.40k
    ttfFont *font = face->font;
130
2.40k
    ttfMemory *mem = font->tti->ttf_memory;
131
2.40k
    r->Seek(r, font->t_cvt_.nPos);
132
133
2.40k
    face->cvt=NULL;
134
135
2.40k
    DebugTrace(font, "CVT ");
136
137
2.40k
    face->cvtSize = font->t_cvt_.nLen / 2;
138
139
#   if 0
140
    if(face->cvtSize < 300)
141
      face->cvtSize = 300; /* Work around DynaLab bug in DingBat1. */
142
#   endif
143
144
2.40k
    if(face->cvtSize > 0) {  /* allow fonts with a CVT table */
145
2.35k
        face->cvt = mem->alloc_bytes(mem, face->cvtSize * sizeof(Short), "Load_TrueType_CVT");
146
2.35k
        if (!face->cvt)
147
0
            return TT_Err_Out_Of_Memory;
148
2.35k
    }
149
150
2.40k
    limit = face->cvtSize;
151
152
1.66M
    for ( n = 0; n < limit && !r->Eof(r); n++ )
153
1.66M
      face->cvt[n] = GET_Short();
154
155
2.40k
    DebugTrace(font, "loaded\n");
156
157
2.40k
    return TT_Err_Ok;
158
2.40k
  }
159
160
/*******************************************************************
161
 *
162
 *  Function    :  Load_TrueType_Programs
163
 *
164
 *  Description :  Loads the font (fpgm) and cvt programs into the
165
 *                 face table.
166
 *
167
 *  Input  :  face
168
 *
169
 *  Output :  Error code.
170
 *
171
 ******************************************************************/
172
173
  TT_Error  Load_TrueType_Programs( PFace  face )
174
2.40k
  {
175
2.40k
    ttfReader *r = face->r;
176
2.40k
    ttfFont *font = face->font;
177
2.40k
    ttfMemory *mem = font->tti->ttf_memory;
178
179
2.40k
    face->fontProgram = NULL;
180
2.40k
    face->cvtProgram = NULL;
181
182
2.40k
    DebugTrace(font, "Font program ");
183
184
    /* The font program is optional */
185
2.40k
    if(!font->t_fpgm.nPos)
186
47
    {
187
47
      face->fontProgram = (Byte*)NULL;
188
47
      face->fontPgmSize = 0;
189
190
47
      DebugTrace(font, "is absent.\n");
191
47
    }
192
2.36k
    else
193
2.36k
    {
194
2.36k
      face->fontPgmSize = font->t_fpgm.nLen;
195
2.36k
      r->Seek(r, font->t_fpgm.nPos);
196
2.36k
      face->fontProgram = mem->alloc_bytes(mem, face->fontPgmSize, "Load_TrueType_Programs");
197
198
2.36k
      if (!face->fontProgram)
199
0
        return TT_Err_Out_Of_Memory;
200
2.36k
      r->Read(r, face->fontProgram,face->fontPgmSize );
201
2.36k
      DebugTrace1(font, "loaded, %12d bytes\n", face->fontPgmSize);
202
2.36k
    }
203
204
2.40k
    DebugTrace(font, "Prep program ");
205
206
2.40k
    if (!font->t_prep.nPos)
207
46
    {
208
46
      face->cvtProgram = (Byte*)NULL;
209
46
      face->cvtPgmSize = 0;
210
211
46
      DebugTrace(font, "is missing!\n");
212
46
    }
213
2.36k
    else
214
2.36k
    { face->cvtPgmSize=font->t_prep.nLen;
215
2.36k
      r->Seek(r, font->t_prep.nPos);
216
2.36k
      face->cvtProgram = mem->alloc_bytes(mem, face->cvtPgmSize, "Load_TrueType_Programs");
217
2.36k
      if (!face->cvtProgram)
218
0
        return TT_Err_Out_Of_Memory;
219
2.36k
      r->Read(r, face->cvtProgram,face->cvtPgmSize );
220
2.36k
      DebugTrace1(font, "loaded, %12d bytes\n", face->cvtPgmSize );
221
2.36k
    }
222
223
2.40k
    return TT_Err_Ok;
224
2.40k
  }