cf2_getStdHW( CFF_Decoder* decoder ) { FT_ASSERT( decoder && decoder->current_subfont ); return cf2_intToFixed( decoder->current_subfont->private_dict.standard_width ); }
/* get scaling and hint flag from GlyphSlot */ static void cf2_getScaleAndHintFlag( CFF_Decoder* decoder, CF2_Fixed* x_scale, CF2_Fixed* y_scale, FT_Bool* hinted, FT_Bool* scaled ) { FT_ASSERT( decoder && decoder->builder.glyph ); /* note: FreeType scale includes a factor of 64 */ *hinted = decoder->builder.glyph->hint; *scaled = decoder->builder.glyph->scaled; if ( *hinted ) { *x_scale = FT_DivFix( decoder->builder.glyph->x_scale, cf2_intToFixed( 64 ) ); *y_scale = FT_DivFix( decoder->builder.glyph->y_scale, cf2_intToFixed( 64 ) ); } else { /* for unhinted outlines, `cff_slot_load' does the scaling, */ /* thus render at `unity' scale */ *x_scale = 0x0400; /* 1/64 as 16.16 */ *y_scale = 0x0400; } }
static int32_t _ft_keydetector_safa_init(struct ft_electrode_data *electrode) { FT_ASSERT(electrode->rom->keydetector_interface == &ft_keydetector_safa_interface); const struct ft_keydetector_safa *rom = electrode->rom->keydetector_params.safa; if(_ft_keydetector_safa_rom_check(rom) != FT_SUCCESS) { return FT_FAILURE; } electrode->keydetector_data.safa = (struct ft_keydetector_safa_data *) _ft_mem_alloc(sizeof(struct ft_keydetector_safa_data)); if(electrode->keydetector_data.safa == NULL) { return FT_OUT_OF_MEMORY; } electrode->keydetector_data.safa->recovery_cnt = 0; electrode->keydetector_data.safa->base_avrg_init = rom->base_avrg; electrode->keydetector_data.safa->noise_avrg_init = rom->base_avrg; electrode->keydetector_data.safa->noise_avrg_init.n2_order += 2; electrode->keydetector_data.safa->predicted_signal_avrg_init = rom->base_avrg; if(electrode->keydetector_data.safa->predicted_signal_avrg_init.n2_order > 2) electrode->keydetector_data.safa->predicted_signal_avrg_init.n2_order -= 2; _ft_electrode_set_status(electrode, FT_ELECTRODE_STATE_INIT); return FT_SUCCESS; }
T1_Face_Done( T1_Face face ) { FT_Memory memory; T1_Font type1; if ( !face ) return; memory = face->root.memory; type1 = &face->type1; #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT /* release multiple masters information */ FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) ); if ( face->buildchar ) { FT_FREE( face->buildchar ); face->buildchar = NULL; face->len_buildchar = 0; } T1_Done_Blend( face ); face->blend = 0; #endif /* release font info strings */ { PS_FontInfo info = &type1->font_info; FT_FREE( info->version ); FT_FREE( info->notice ); FT_FREE( info->full_name ); FT_FREE( info->family_name ); FT_FREE( info->weight ); } /* release top dictionary */ FT_FREE( type1->charstrings_len ); FT_FREE( type1->charstrings ); FT_FREE( type1->glyph_names ); FT_FREE( type1->subrs ); FT_FREE( type1->subrs_len ); FT_FREE( type1->subrs_block ); FT_FREE( type1->charstrings_block ); FT_FREE( type1->glyph_names_block ); FT_FREE( type1->encoding.char_index ); FT_FREE( type1->encoding.char_name ); FT_FREE( type1->font_name ); #ifndef T1_CONFIG_OPTION_NO_AFM /* release afm data if present */ if ( face->afm_data )
t1_cmap_custom_init( T1_CMapCustom cmap, FT_Pointer init_data ) { T1_Face face = (T1_Face)FT_CMAP_FACE( cmap ); T1_Encoding encoding = &face->type1.encoding; FT_UNUSED( init_data ); cmap->first = encoding->code_first; cmap->count = (FT_UInt)( encoding->code_last - cmap->first ); cmap->indices = encoding->char_index; FT_ASSERT( cmap->indices != NULL ); FT_ASSERT( encoding->code_first <= encoding->code_last ); return 0; }
FT_Stream_EnterFrame( FT_Stream stream, FT_ULong count ) { FT_Error error = FT_Err_Ok; FT_ULong read_bytes; /* check for nested frame access */ FT_ASSERT( stream && stream->cursor == 0 ); if ( stream->read ) { /* allocate the frame in memory */ FT_Memory memory = stream->memory; if ( FT_QALLOC( stream->base, count ) ) goto Exit; /* read it */ read_bytes = stream->read( stream, stream->pos, stream->base, count ); if ( read_bytes < count ) { FT_ERROR(( "FT_Stream_EnterFrame:" )); FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n", count, read_bytes )); FT_FREE( stream->base ); error = FT_Err_Invalid_Stream_Operation; } stream->cursor = stream->base; stream->limit = stream->cursor + count; stream->pos += read_bytes; } else { /* check current and new position */ if ( stream->pos >= stream->size || stream->pos + count > stream->size ) { FT_ERROR(( "FT_Stream_EnterFrame:" )); FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n", stream->pos, count, stream->size )); error = FT_Err_Invalid_Stream_Operation; goto Exit; } /* set cursor */ stream->cursor = stream->base + stream->pos; stream->limit = stream->cursor + count; stream->pos += count; } Exit: return error; }
cf2_freeSeacComponent( CFF_Decoder* decoder, CF2_Buffer buf ) { FT_ASSERT( decoder ); cff_free_glyph_data( decoder->builder.face, (FT_Byte**)&buf->start, (FT_ULong)( buf->end - buf->start ) ); }
T1_Compute_Max_Advance( T1_Face face, FT_Pos* max_advance ) { FT_Error error; T1_DecoderRec decoder; FT_Int glyph_index; T1_Font type1 = &face->type1; PSAux_Service psaux = (PSAux_Service)face->psaux; FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) ); *max_advance = 0; /* initialize load decoder */ error = psaux->t1_decoder_funcs->init( &decoder, (FT_Face)face, 0, /* size */ 0, /* glyph slot */ (FT_Byte**)type1->glyph_names, face->blend, 0, FT_RENDER_MODE_NORMAL, T1_Parse_Glyph ); if ( error ) return error; decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; decoder.num_subrs = type1->num_subrs; decoder.subrs = type1->subrs; decoder.subrs_len = type1->subrs_len; decoder.subrs_hash = type1->subrs_hash; decoder.buildchar = face->buildchar; decoder.len_buildchar = face->len_buildchar; *max_advance = 0; /* for each glyph, parse the glyph charstring and extract */ /* the advance width */ for ( glyph_index = 0; glyph_index < type1->num_glyphs; glyph_index++ ) { /* now get load the unscaled outline */ (void)T1_Parse_Glyph( &decoder, (FT_UInt)glyph_index ); if ( glyph_index == 0 || decoder.builder.advance.x > *max_advance ) *max_advance = decoder.builder.advance.x; /* ignore the error if one occurred - skip to next glyph */ } psaux->t1_decoder_funcs->done( &decoder ); return FT_Err_Ok; }
static int32_t _ft_control_slider_init(struct ft_control_data *control) { FT_ASSERT(control != NULL); FT_ASSERT(control->rom->interface == &ft_control_slider_interface); control->data.slider = _ft_mem_alloc(sizeof(struct ft_control_slider_data)); if(control->data.slider == NULL) { return FT_OUT_OF_MEMORY; } if (_ft_control_check_data(control) != FT_SUCCESS) { return FT_FAILURE; } return FT_SUCCESS; }
cf2_getBlueValues( CFF_Decoder* decoder, size_t* count, FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_blue_values; *data = (FT_Pos*) &decoder->current_subfont->private_dict.blue_values; }
cf2_getFamilyOtherBlues( CFF_Decoder* decoder, size_t* count, FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_family_other_blues; *data = (FT_Pos*) &decoder->current_subfont->private_dict.family_other_blues; }
/* return false on memory error */ static FT_Bool cf2_arrstack_setNumElements( CF2_ArrStack arrstack, size_t numElements ) { FT_ASSERT( arrstack != NULL ); { FT_Error error = FT_Err_Ok; /* for FT_REALLOC */ FT_Memory memory = arrstack->memory; /* for FT_REALLOC */ FT_Long newSize = numElements * arrstack->sizeItem; if ( numElements > LONG_MAX / arrstack->sizeItem ) goto exit; FT_ASSERT( newSize > 0 ); /* avoid realloc with zero size */ if ( !FT_REALLOC( arrstack->ptr, arrstack->totalSize, newSize ) ) { arrstack->allocated = numElements; arrstack->totalSize = newSize; if ( arrstack->count > numElements ) { /* we truncated the list! */ CF2_SET_ERROR( arrstack->error, Stack_Overflow ); arrstack->count = numElements; return FALSE; } return TRUE; /* success */ } } exit: /* if there's not already an error, store this one */ CF2_SET_ERROR( arrstack->error, Out_Of_Memory ); return FALSE; }
static void cf2_setGlyphWidth( CF2_Outline outline, CF2_Fixed width ) { CFF_Decoder* decoder = outline->decoder; FT_ASSERT( decoder ); decoder->glyph_width = cf2_fixedToInt( width ); }
cf2_initLocalRegionBuffer( CFF_Decoder* decoder, CF2_UInt idx, CF2_Buffer buf ) { FT_ASSERT( decoder ); FT_ZERO( buf ); idx += decoder->locals_bias; if ( idx >= decoder->num_locals ) return TRUE; /* error */ FT_ASSERT( decoder->locals ); buf->start = buf->ptr = decoder->locals[idx]; buf->end = decoder->locals[idx + 1]; return FALSE; /* success */ }
cf2_outline_close( CF2_Outline outline ) { CFF_Decoder* decoder = outline->decoder; FT_ASSERT( decoder ); cff_builder_close_contour( &decoder->builder ); FT_GlyphLoader_Add( decoder->builder.loader ); }
static void cf2_builder_moveTo( CF2_OutlineCallbacks callbacks, const CF2_CallbackParams params ) { /* downcast the object pointer */ CF2_Outline outline = (CF2_Outline)callbacks; CFF_Builder* builder; (void)params; /* only used in debug mode */ FT_ASSERT( outline && outline->decoder ); FT_ASSERT( params->op == CF2_PathOpMoveTo ); builder = &outline->decoder->builder; /* note: two successive moves simply close the contour twice */ cff_builder_close_contour( builder ); builder->path_begun = 0; }
cf2_outline_reset( CF2_Outline outline ) { CFF_Decoder* decoder = outline->decoder; FT_ASSERT( decoder ); outline->root.windingMomentum = 0; FT_GlyphLoader_Rewind( decoder->builder.loader ); }
ft_mem_qrealloc( FT_Memory memory, FT_Long item_size, FT_Long cur_count, FT_Long new_count, void* block, FT_Error *p_error ) { FT_Error error = FT_Err_Ok; /* Note that we now accept `item_size == 0' as a valid parameter, in * order to cover very weird cases where an ALLOC_MULT macro would be * called. */ if ( cur_count < 0 || new_count < 0 || item_size < 0 ) { /* may help catch/prevent nasty security issues */ error = FT_THROW( Invalid_Argument ); } else if ( new_count == 0 || item_size == 0 ) { ft_mem_free( memory, block ); block = NULL; } else if ( new_count > FT_INT_MAX / item_size ) { error = FT_THROW( Array_Too_Large ); } else if ( cur_count == 0 ) { FT_ASSERT( !block ); block = memory->alloc( memory, new_count * item_size ); if ( block == NULL ) error = FT_THROW( Out_Of_Memory ); } else { FT_Pointer block2; FT_Long cur_size = cur_count * item_size; FT_Long new_size = new_count * item_size; block2 = memory->realloc( memory, cur_size, new_size, block ); if ( !block2 ) error = FT_THROW( Out_Of_Memory ); else block = block2; } *p_error = error; return block; }
static void _ft_control_slider_invoke_callback(const struct ft_control_data *control, enum ft_control_slider_event event, uint32_t position) { struct ft_control_slider_data *ram = control->data.slider; FT_ASSERT(ram != NULL); if (ram->callback != NULL) { ram->callback(control->rom, event, position); } }
/* pointer */ static void cf2_hintmask_read( CF2_HintMask hintmask, CF2_Buffer charstring, size_t bitCount ) { size_t i; #ifndef CF2_NDEBUG /* these are the bits in the final mask byte that should be zero */ /* Note: this variable is only used in an assert expression below */ /* and then only if CF2_NDEBUG is not defined */ CF2_UInt mask = ( 1 << ( -(CF2_Int)bitCount & 7 ) ) - 1; #endif /* initialize counts and isValid */ if ( cf2_hintmask_setCounts( hintmask, bitCount ) == 0 ) return; FT_ASSERT( hintmask->byteCount > 0 ); FT_TRACE4(( " (maskbytes:" )); /* set mask and advance interpreter's charstring pointer */ for ( i = 0; i < hintmask->byteCount; i++ ) { hintmask->mask[i] = (FT_Byte)cf2_buf_readByte( charstring ); FT_TRACE4(( " 0x%02X", hintmask->mask[i] )); } FT_TRACE4(( ")\n" )); /* assert any unused bits in last byte are zero unless there's a prior */ /* error */ /* bitCount -> mask, 0 -> 0, 1 -> 7f, 2 -> 3f, ... 6 -> 3, 7 -> 1 */ #ifndef CF2_NDEBUG FT_ASSERT( ( hintmask->mask[hintmask->byteCount - 1] & mask ) == 0 || *hintmask->error ); #endif }
static int32_t _ft_control_slider_process(struct ft_control_data *control) { FT_ASSERT(control != NULL); FT_ASSERT(control->rom->interface == &ft_control_slider_interface); if (!_ft_control_get_flag(control, FT_CONTROL_EN_FLAG) || !_ft_control_get_flag(control, FT_CONTROL_NEW_DATA_FLAG)) { return FT_FAILURE; /* control disabled or data not ready */ } struct ft_control_slider_data *ram = control->data.slider; uint32_t elec_state = _ft_control_get_electrodes_state(control); if (!elec_state) { /* all released */ if (_ft_control_get_flag(control, FT_SLIDER_TOUCH_FLAG)) { /* if none is touched & touch was reported, allreleased event */ _ft_control_clear_flag(control, FT_SLIDER_TOUCH_FLAG); _ft_control_clear_flag(control, FT_SLIDER_MOVEMENT_FLAG); _ft_control_slider_invoke_callback(control, FT_SLIDER_ALL_RELEASE, (uint32_t)ram->position); } _ft_control_clear_flag(control, FT_CONTROL_NEW_DATA_FLAG); /* data processed */ return FT_SUCCESS; /* no touch on the control's electrodes */ } uint32_t last_elec = _ft_control_get_last_elec_touched(elec_state); uint32_t first_elec = _ft_control_get_first_elec_touched(elec_state); uint32_t touch_count = _ft_control_get_touch_count(elec_state); _ft_control_slider_calc_position(control, first_elec, last_elec, touch_count); if (!_ft_control_get_flag(control, FT_SLIDER_TOUCH_FLAG)) { _ft_control_slider_invoke_callback(control, FT_SLIDER_INITIAL_TOUCH, (uint32_t)ram->position); } _ft_control_set_flag(control, FT_SLIDER_TOUCH_FLAG); _ft_control_clear_flag(control, FT_CONTROL_NEW_DATA_FLAG); /* data processed */ return FT_SUCCESS; }
FT_Stream_GetChar( FT_Stream stream ) { FT_Char result; FT_ASSERT( stream && stream->cursor ); result = 0; if ( stream->cursor < stream->limit ) result = *stream->cursor++; return result; }
uint32_t ft_mem_get_free_size(void) { struct ft_kernel * system = _ft_system_get(); struct ft_mem * mem = &system->memory; int32_t size = mem->pool_size; size -= mem->free_pointer - mem->pool; FT_ASSERT(size >= 0); return size; }
static void _ft_keydetector_afid_process(struct ft_electrode_data *electrode) { FT_ASSERT(electrode->rom->keydetector_interface == &ft_keydetector_afid_interface); struct ft_keydetector_afid_data *ram = electrode->keydetector_data.afid; const struct ft_keydetector_afid *rom = electrode->rom->keydetector_params.afid; struct ft_kernel *system = _ft_system_get(); switch (_ft_electrode_get_last_status(electrode)) { case FT_ELECTRODE_STATE_INIT: /* manage switch from init to run phase */ if (_ft_electrode_get_time_offset(electrode) >= system->rom->init_time) { _ft_keydetector_afid_asc_track(rom, ram); _ft_keydetector_afid_asc_process(rom, ram); if(_ft_electrode_get_flag(electrode, FT_ELECTRODE_AFTER_INIT_TOUCH_FLAG)) _ft_electrode_set_status(electrode, FT_ELECTRODE_STATE_TOUCH); else _ft_electrode_set_status(electrode, FT_ELECTRODE_STATE_RELEASE); _ft_electrode_clear_flag(electrode, FT_ELECTRODE_AFTER_INIT_TOUCH_FLAG); } break; case FT_ELECTRODE_STATE_TOUCH: if (ram->release_reset_counter > 0U) { _ft_electrode_set_status(electrode, FT_ELECTRODE_STATE_RELEASE); } else { _ft_keydetector_afid_asc_track(rom, ram); if (ram->touch_reset_counter < rom->asc.resets_for_touch / 2) { ram->touch_reset_counter = 0; } } break; case FT_ELECTRODE_STATE_RELEASE: if (ram->touch_reset_counter > rom->asc.resets_for_touch) { _ft_electrode_set_status(electrode, FT_ELECTRODE_STATE_TOUCH); } else { _ft_keydetector_afid_asc_process(rom, ram); } break; default: break; } }
cf2_arrstack_setCount( CF2_ArrStack arrstack, size_t numElements ) { FT_ASSERT( arrstack != NULL ); if ( numElements > arrstack->allocated ) { /* expand the allocation first */ if ( !cf2_arrstack_setNumElements( arrstack, numElements ) ) return; } arrstack->count = numElements; }
cf2_arrstack_finalize( CF2_ArrStack arrstack ) { FT_Memory memory = arrstack->memory; /* for FT_FREE */ FT_ASSERT( arrstack != NULL ); arrstack->allocated = 0; arrstack->count = 0; arrstack->totalSize = 0; /* free the data buffer */ FT_FREE( arrstack->ptr ); }
cf2_hintmask_setAll( CF2_HintMask hintmask, size_t bitCount ) { size_t i; CF2_UInt mask = ( 1 << ( -(CF2_Int)bitCount & 7 ) ) - 1; /* initialize counts and isValid */ if ( cf2_hintmask_setCounts( hintmask, bitCount ) == 0 ) return; FT_ASSERT( hintmask->byteCount > 0 ); FT_ASSERT( hintmask->byteCount <= sizeof ( hintmask->mask ) / sizeof ( hintmask->mask[0] ) ); /* set mask to all ones */ for ( i = 0; i < hintmask->byteCount; i++ ) hintmask->mask[i] = 0xFF; /* clear unused bits */ /* bitCount -> mask, 0 -> 0, 1 -> 7f, 2 -> 3f, ... 6 -> 3, 7 -> 1 */ hintmask->mask[hintmask->byteCount - 1] &= ~mask; }
/* * This check should avoid most internal overflow cases. Clients should * generally respond to `Glyph_Too_Big' by getting a glyph outline * at EM size, scaling it and filling it as a graphics operation. * */ static FT_Error cf2_checkTransform( const CF2_Matrix* transform, CF2_Int unitsPerEm ) { CF2_Fixed maxScale; FT_ASSERT( unitsPerEm > 0 ); FT_ASSERT( transform->a > 0 && transform->d > 0 ); FT_ASSERT( transform->b == 0 && transform->c == 0 ); FT_ASSERT( transform->tx == 0 && transform->ty == 0 ); if ( unitsPerEm > 0x7FFF ) return FT_THROW( Glyph_Too_Big ); maxScale = FT_DivFix( CF2_MAX_SIZE, cf2_intToFixed( unitsPerEm ) ); if ( transform->a > maxScale || transform->d > maxScale ) return FT_THROW( Glyph_Too_Big ); return FT_Err_Ok; }
static void cf2_builder_cubeTo( CF2_OutlineCallbacks callbacks, const CF2_CallbackParams params ) { /* downcast the object pointer */ CF2_Outline outline = (CF2_Outline)callbacks; CFF_Builder* builder; FT_ASSERT( outline && outline->decoder ); FT_ASSERT( params->op == CF2_PathOpCubeTo ); builder = &outline->decoder->builder; if ( !builder->path_begun ) { /* record the move before the line; also check points and set */ /* `path_begun' */ cff_builder_start_point( builder, params->pt0.x, params->pt0.y ); } /* prepare room for 3 points: 2 off-curve, 1 on-curve */ cff_check_points( builder, 3 ); cff_builder_add_point( builder, params->pt1.x, params->pt1.y, 0 ); cff_builder_add_point( builder, params->pt2.x, params->pt2.y, 0 ); cff_builder_add_point( builder, params->pt3.x, params->pt3.y, 1 ); }
cf2_getBlueMetrics( CFF_Decoder* decoder, CF2_Fixed* blueScale, CF2_Fixed* blueShift, CF2_Fixed* blueFuzz ) { FT_ASSERT( decoder && decoder->current_subfont ); *blueScale = FT_DivFix( decoder->current_subfont->private_dict.blue_scale, cf2_intToFixed( 1000 ) ); *blueShift = cf2_intToFixed( decoder->current_subfont->private_dict.blue_shift ); *blueFuzz = cf2_intToFixed( decoder->current_subfont->private_dict.blue_fuzz ); }