1 /* Copyright (C) 2001-2012 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., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, 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 Load_TrueType_MaxProfile(PFace face)66 TT_Error Load_TrueType_MaxProfile( PFace face ) 67 { 68 ttfReader *r = face->r; 69 ttfFont *font = face->font; 70 PMaxProfile maxProfile = &face->maxProfile; 71 72 r->Seek(r, font->t_maxp.nPos); 73 74 DebugTrace(font, "MaxProfile " ); 75 76 /* read frame data into face table */ 77 maxProfile->version = GET_ULong(); 78 79 maxProfile->numGlyphs = GET_UShort(); 80 81 maxProfile->maxPoints = GET_UShort(); 82 maxProfile->maxContours = GET_UShort(); 83 maxProfile->maxCompositePoints = GET_UShort(); 84 maxProfile->maxCompositeContours = GET_UShort(); 85 86 maxProfile->maxZones = GET_UShort(); 87 maxProfile->maxTwilightPoints = GET_UShort(); 88 89 maxProfile->maxStorage = GET_UShort(); 90 maxProfile->maxFunctionDefs = GET_UShort(); 91 maxProfile->maxInstructionDefs = GET_UShort(); 92 maxProfile->maxStackElements = GET_UShort(); 93 maxProfile->maxSizeOfInstructions = GET_UShort(); 94 maxProfile->maxComponentElements = GET_UShort(); 95 maxProfile->maxComponentDepth = GET_UShort(); 96 97 face->numGlyphs = maxProfile->numGlyphs; 98 99 face->maxPoints = MAX( maxProfile->maxCompositePoints, 100 maxProfile->maxPoints ); 101 face->maxContours = MAX( maxProfile->maxCompositeContours, 102 maxProfile->maxContours ); 103 face->maxComponents = maxProfile->maxComponentElements + 104 maxProfile->maxComponentDepth; 105 106 DebugTrace(font, "loaded\n"); 107 108 return TT_Err_Ok; 109 } 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 Load_TrueType_CVT(PFace face)123 TT_Error Load_TrueType_CVT( PFace face ) 124 { 125 long n; 126 Int limit; 127 128 ttfReader *r = face->r; 129 ttfFont *font = face->font; 130 ttfMemory *mem = font->tti->ttf_memory; 131 r->Seek(r, font->t_cvt_.nPos); 132 133 face->cvt=NULL; 134 135 DebugTrace(font, "CVT "); 136 137 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 if(face->cvtSize > 0) { /* allow fonts with a CVT table */ 145 face->cvt = mem->alloc_bytes(mem, face->cvtSize * sizeof(Short), "Load_TrueType_CVT"); 146 if (!face->cvt) 147 return TT_Err_Out_Of_Memory; 148 } 149 150 limit = face->cvtSize; 151 152 for ( n = 0; n < limit && !r->Eof(r); n++ ) 153 face->cvt[n] = GET_Short(); 154 155 DebugTrace(font, "loaded\n"); 156 157 return TT_Err_Ok; 158 } 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 Load_TrueType_Programs(PFace face)173 TT_Error Load_TrueType_Programs( PFace face ) 174 { 175 ttfReader *r = face->r; 176 ttfFont *font = face->font; 177 ttfMemory *mem = font->tti->ttf_memory; 178 179 face->fontProgram = NULL; 180 face->cvtProgram = NULL; 181 182 DebugTrace(font, "Font program "); 183 184 /* The font program is optional */ 185 if(!font->t_fpgm.nPos) 186 { 187 face->fontProgram = (Byte*)NULL; 188 face->fontPgmSize = 0; 189 190 DebugTrace(font, "is absent.\n"); 191 } 192 else 193 { 194 face->fontPgmSize = font->t_fpgm.nLen; 195 r->Seek(r, font->t_fpgm.nPos); 196 face->fontProgram = mem->alloc_bytes(mem, face->fontPgmSize, "Load_TrueType_Programs"); 197 198 if (!face->fontProgram) 199 return TT_Err_Out_Of_Memory; 200 r->Read(r, face->fontProgram,face->fontPgmSize ); 201 DebugTrace1(font, "loaded, %12d bytes\n", face->fontPgmSize); 202 } 203 204 DebugTrace(font, "Prep program "); 205 206 if (!font->t_prep.nPos) 207 { 208 face->cvtProgram = (Byte*)NULL; 209 face->cvtPgmSize = 0; 210 211 DebugTrace(font, "is missing!\n"); 212 } 213 else 214 { face->cvtPgmSize=font->t_prep.nLen; 215 r->Seek(r, font->t_prep.nPos); 216 face->cvtProgram = mem->alloc_bytes(mem, face->cvtPgmSize, "Load_TrueType_Programs"); 217 if (!face->cvtProgram) 218 return TT_Err_Out_Of_Memory; 219 r->Read(r, face->cvtProgram,face->cvtPgmSize ); 220 DebugTrace1(font, "loaded, %12d bytes\n", face->cvtPgmSize ); 221 } 222 223 return TT_Err_Ok; 224 } 225