📄 ttobjs.c
字号:
*maxContours = newContours; } return TT_Err_Ok; } LOCAL_FUNC TT_Error Context_Load( PExecution_Context exec, PFace face, PInstance ins ) { Int i; TMaxProfile* maxp; TT_Error error; exec->face = face; maxp = &face->maxProfile; exec->instance = ins; if ( ins ) { exec->numFDefs = ins->numFDefs; exec->numIDefs = ins->numIDefs; exec->maxFDefs = ins->maxFDefs; exec->maxIDefs = ins->maxIDefs; exec->FDefs = ins->FDefs; exec->IDefs = ins->IDefs; exec->metrics = ins->metrics; exec->maxFunc = ins->maxFunc; exec->maxIns = ins->maxIns; for ( i = 0; i < MAX_CODE_RANGES; i++ ) exec->codeRangeTable[i] = ins->codeRangeTable[i]; /* set graphics state */ exec->GS = ins->GS; exec->cvtSize = ins->cvtSize; exec->cvt = ins->cvt; exec->storeSize = ins->storeSize; exec->storage = ins->storage; exec->twilight = ins->twilight; } error = Update_Max( &exec->loadSize, sizeof ( TSubglyph_Record ), (void**)&exec->loadStack, face->maxComponents + 1 ); if ( error ) return error; error = Update_Max( &exec->stackSize, sizeof ( TT_F26Dot6 ), (void**)&exec->stack, maxp->maxStackElements + 32 ); /* XXX : We reserve a little more elements on the stack to deal safely */ /* with broken fonts like arialbs, courbs, timesbs... */ if ( error ) return error; error = Update_Max( &exec->glyphSize, sizeof ( Byte ), (void**)&exec->glyphIns, maxp->maxSizeOfInstructions ); if ( error ) return error; error = Update_Zone( &exec->pts, &exec->maxPoints, &exec->maxContours, exec->face->maxPoints + 2, exec->face->maxContours ); /* XXX : We reserve two positions for the phantom points! */ if ( error ) return error; exec->pts.n_points = 0; exec->pts.n_contours = 0; exec->instruction_trap = FALSE; return TT_Err_Ok; }/******************************************************************* * * Function : Context_Save * *****************************************************************/ LOCAL_FUNC TT_Error Context_Save( PExecution_Context exec, PInstance ins ) { Int i; /* XXXX : Will probably disappear soon with all the coderange */ /* management, which is now rather obsolete. */ ins->numFDefs = exec->numFDefs; ins->numIDefs = exec->numIDefs; ins->maxFunc = exec->maxFunc; ins->maxIns = exec->maxIns; for ( i = 0; i < MAX_CODE_RANGES; i++ ) ins->codeRangeTable[i] = exec->codeRangeTable[i]; return TT_Err_Ok; }/******************************************************************* * * Function : Context_Run * *****************************************************************/ LOCAL_FUNC TT_Error Context_Run( PExecution_Context exec, Bool debug ) { TT_Error error; if ( (error = Goto_CodeRange( exec, TT_CodeRange_Glyph, 0 )) != TT_Err_Ok ) return error; exec->zp0 = exec->pts; exec->zp1 = exec->pts; exec->zp2 = exec->pts; exec->GS.gep0 = 1; exec->GS.gep1 = 1; exec->GS.gep2 = 1; exec->GS.projVector.x = 0x4000; exec->GS.projVector.y = 0x0000; exec->GS.freeVector = exec->GS.projVector; exec->GS.dualVector = exec->GS.projVector; exec->GS.round_state = 1; exec->GS.loop = 1; /* some glyphs leave something on the stack. so we clean it */ /* before a new execution. */ exec->top = 0; exec->callTop = 0; if ( !debug ) return RunIns( exec ); else return TT_Err_Ok; } LOCAL_FUNC const TGraphicsState Default_GraphicsState = { 0, 0, 0, { 0x4000, 0 }, { 0x4000, 0 }, { 0x4000, 0 }, 1, 64, 1, TRUE, 68, 0, 0, 9, 3, 0, FALSE, 2, 1, 1, 1 };/******************************************************************* * * * INSTANCE FUNCTIONS * * * * * *******************************************************************//******************************************************************* * * Function : Instance_Destroy * * Description : * * Input : _instance the instance object to destroy * * Output : error code. * ******************************************************************/ LOCAL_FUNC TT_Error Instance_Destroy( void* _instance ) { PInstance ins = (PInstance)_instance; if ( !_instance ) return TT_Err_Ok; if ( ins->debug ) { /* the debug context must be deleted by the debugger itself */ ins->context = NULL; ins->debug = FALSE; } FREE( ins->cvt ); ins->cvtSize = 0; /* free storage area */ FREE( ins->storage ); ins->storeSize = 0; /* twilight zone */ Done_Glyph_Zone( &ins->twilight ); FREE( ins->FDefs ); FREE( ins->IDefs ); ins->numFDefs = 0; ins->numIDefs = 0; ins->maxFDefs = 0; ins->maxIDefs = 0; ins->maxFunc = -1; ins->maxIns = -1; ins->owner = NULL; ins->valid = FALSE; return TT_Err_Ok; }/******************************************************************* * * Function : Instance_Create * * Description : * * Input : _instance instance record to initialize * _face parent face object * * Output : Error code. All partially built subtables are * released on error. * ******************************************************************/ LOCAL_FUNC TT_Error Instance_Create( void* _instance, void* _face ) { PInstance ins = (PInstance)_instance; PFace face = (PFace)_face; TT_Error error; Int i; UShort n_twilight; PMaxProfile maxp = &face->maxProfile; ins->owner = face; ins->valid = FALSE; ins->maxFDefs = maxp->maxFunctionDefs; ins->maxIDefs = maxp->maxInstructionDefs; ins->cvtSize = face->cvtSize; ins->storeSize = maxp->maxStorage; /* Set default metrics */ { PIns_Metrics metrics = &ins->metrics; metrics->pointSize = 10 * 64; /* default pointsize = 10pts */ metrics->x_resolution = 96; /* default resolution = 96dpi */ metrics->y_resolution = 96; metrics->x_ppem = 0; metrics->y_ppem = 0; metrics->rotated = FALSE; metrics->stretched = FALSE; /* set default compensation ( all 0 ) */ for ( i = 0; i < 4; i++ ) metrics->compensations[i] = 0; } /* allocate function defs, instruction defs, cvt and storage area */ if ( ALLOC_ARRAY( ins->FDefs, ins->maxFDefs, TDefRecord ) || ALLOC_ARRAY( ins->IDefs, ins->maxIDefs, TDefRecord ) || ALLOC_ARRAY( ins->cvt, ins->cvtSize, Long ) || ALLOC_ARRAY( ins->storage, ins->storeSize, Long ) ) goto Fail_Memory; /* reserve twilight zone */ n_twilight = maxp->maxTwilightPoints; error = New_Glyph_Zone( &ins->twilight, n_twilight, 0 ); if (error) goto Fail_Memory; ins->twilight.n_points = n_twilight; return TT_Err_Ok; Fail_Memory: Instance_Destroy( ins ); return error; }/******************************************************************* * * Function : Instance_Init * * Description : Initialize a fresh new instance. * Executes the font program if any is found. * * Input : _instance the instance object to destroy * * Output : Error code. * ******************************************************************/ LOCAL_FUNC TT_Error Instance_Init( PInstance ins ) { PExecution_Context exec; TT_Error error; PFace face = ins->owner; if ( ins->debug ) exec = ins->context; else exec = New_Context( face ); /* debugging instances have their own context */ if ( !exec ) return TT_Err_Could_Not_Find_Context; ins->GS = Default_GraphicsState; ins->numFDefs = 0; ins->numIDefs = 0; ins->maxFunc = -1; ins->maxIns = -1; Context_Load( exec, face, ins ); exec->callTop = 0; exec->top = 0; exec->period = 64; exec->phase = 0; exec->threshold = 0; { PIns_Metrics metrics = &exec->metrics; metrics->x_ppem = 0; metrics->y_ppem = 0; metrics->pointSize = 0; metrics->x_scale1 = 0; metrics->x_scale2 = 1; metrics->y_scale1 = 0; metrics->y_scale2 = 1; metrics->ppem = 0; metrics->scale1 = 0; metrics->scale2 = 1; metrics->ratio = 1L << 16; } exec->instruction_trap = FALSE; exec->cvtSize = ins->cvtSize; exec->cvt = ins->cvt; exec->F_dot_P = 0x10000; /* allow font program execution */ Set_CodeRange( exec, TT_CodeRange_Font, face->fontProgram, face->fontPgmSize ); /* disable CVT and glyph programs coderange */ Clear_CodeRange( exec, TT_CodeRange_Cvt ); Clear_CodeRange( exec, TT_CodeRange_Glyph ); if ( face->fontPgmSize > 0 ) { error = Goto_CodeRange( exec, TT_CodeRange_Font, 0 ); if ( error ) goto Fin; error = RunIns( exec ); } else error = TT_Err_Ok; Fin: Context_Save( exec, ins ); if ( !ins->debug ) Done_Context( exec ); /* debugging instances keep their context */ ins->valid = FALSE; return error; }/******************************************************************* * * Function : Instance_Reset * * Description : Resets an instance to a new pointsize/transform. * Executes the cvt program if any is found. * * Input : _instance the instance object to destroy * * Output : Error code. * ******************************************************************/ LOCAL_FUNC TT_Error Instance_Reset( PInstance ins ) { PExecution_Context exec; TT_Error error; ULong i; UShort j; PFace face; if ( !ins ) return TT_Err_Invalid_Instance_Handle; if ( ins->valid ) return TT_Err_Ok; face = ins->owner; if ( ins->metrics.x_ppem < 1 || ins->metrics.y_ppem < 1 ) return TT_Err_Invalid_PPem; /* compute new transformation */ if ( ins->metrics.x_ppem >= ins->metrics.y_ppem ) { ins->metrics.scale1 = ins->metrics.x_scale1; ins->metrics.scale2 = ins->metrics.x_scale2; ins->metrics.ppem = ins->metrics.x_ppem; ins->metrics.x_ratio = 1L << 16; ins->metrics.y_ratio = TT_MulDiv( ins->metrics.y_ppem, 0x10000, ins->metrics.x_ppem ); } else { ins->metrics.scale1 = ins->metrics.y_scale1; ins->metrics.scale2 = ins->metrics.y_scale2; ins->metrics.ppem = ins->metrics.y_ppem; ins->metrics.x_ratio = TT_MulDiv( ins->metrics.x_ppem, 0x10000, ins->metrics.y_ppem ); ins->metrics.y_ratio = 1L << 16; } /* Scale the cvt values to the new ppem. */ /* We use by default the y ppem to scale the CVT. */ for ( i = 0; i < ins->cvtSize; i++ ) ins->cvt[i] = TT_MulDiv( face->cvt[i], ins->metrics.scale1, ins->metrics.scale2 ); /* All twilight points are originally zero */ for ( j = 0; j < ins->twilight.n_points; j++ ) { ins->twilight.org[j].x = 0; ins->twilight.org[j].y = 0; ins->twilight.cur[j].x = 0; ins->twilight.cur[j].y = 0; } /* clear storage area */ for ( i = 0; i < ins->storeSize; i++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -