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