📄 cafont_cfont.c
字号:
** if the desired can be obtained by pairing the current with some other font ** then PAIRING_FALL_BACK ** If cannot be obtained, but there is a valid BLOB, then CSET fault and BLOB_FALL_BACK ** If cannot be obtained, and ther is no valid blob, then CSET fault and NO_BLOB_FALL_BACK */ if (cfont_cur->cfa_cset == cfont_des->cfa_cset) { cfont_g->cfg_cset = EXACT_MATCH; } else { if (des_pair & fdp_ptr->fdp_paired_font_flag) { cfont_g->cfg_cset = PAIRING_FALL_BACK; } else { cfont_g->cfg_fault_flags |= FLT_CSET; cfont_g->cfg_cset = (fdp_ptr->fdp_valid_blob_flag) ? BLOB_FALL_BACK : NO_BLOB_FALL_BACK; } } /* Now do type size */ /* If the desired and current type size are the same, then exact match ** If the desired is larger than current, then value grading ** If the desired is smaller, then spacing fault and value grading */ cfont_g->cfg_type_size = ABS(cfont_cur->cfa_type_size - cfont_des->cfa_type_size); if (cfont_cur->cfa_type_size> cfont_des->cfa_type_size) { cfont_g->cfg_fault_flags |= FLT_TYPE_SIZE; } /* Now do scale factor */ /* At this point we ignore the scale factor, for lack of guidelines ** on how to use it */ cfont_g->cfg_scale_factor = EXACT_MATCH; /* Now do style */ /* If the desired and current styles are the same, exact match ** If a bit is set in current, but not in desired, then STYLE_FAULT ** If a bit is set in desired but not in current, ALG_ATT_FALL_BACK */ /* Preload the grade, with no need for algorithmic attributes */ cfont_g->cfg_style = EXACT_MATCH; if (cfont_cur->cfa_style != cfont_des->cfa_style) { /* little explanation here. ** cfont_cur->cfa_style XOR cfont_des->cfa_style is the list of differences ** cfont_cur->cfa_style AND list of differences, is the list of bits set in ** current, but not in desired, therefore the attributes that should be erased ** if there is any, this is a fault as we cannot erase. ** */ if (cfont_cur->cfa_style & (cfont_cur->cfa_style ^ cfont_des->cfa_style)) { cfont_g->cfg_fault_flags |= FLT_STYLE; } if (cfont_des->cfa_style & (cfont_cur->cfa_style ^ cfont_des->cfa_style)) { cfont_g->cfg_style = ALG_ATT_FALL_BACK; } } /* Now do weight*/ /* Determine how closely the font file comes to the desired weight attribute. * * commanded bolding * * 16 25 * font weight temp * weight value value * 4 A- 26 A- 42 * 5 A- 24 A- 40 * 6 A- 22 A- 38 * 7 A- 20 A- 36 * 8 A- 18 A- 34 * 9 A- 16 A- 32 * 10 A- 14 A- 30 * 11 A- 12 A- 28 * 12 A- 10 A- 26 * 13 A- 8 A- 24 * 14 A- 6 A- 22 * 15 A- 4 A- 20 * 16 best 0 A- 18 * 17 A+ 1 A- 16 * 18 A+ 3 A- 14 * 19 A+ 5 A- 12 * 20 A+ 7 A- 10 * 21 A+ 9 A- 8 * 22 A+ 11 A- 6 * 23 A+ 13 A- 4 * 24 A+ 15 A- 2 * 25 A+ 17 best 0 * 26 A+ 19 A+ 1 * 27 A+ 21 A+ 3 * 28 A+ 23 A+ 5 * 29 A+ 25 A+ 7 * 30 A+ 27 A+ 9 * 31 A+ 29 A+ 11 * * A = accept; +/- indicates, for two weights equi-distant from a desired * weight, which should be taken as preferable. * * NOTE: If, when bolding is commanded, the selected font has a weight of * less than 22 it will be algorithmically bolded. * * The value of weight is subtracted from MAX_WEIGHT_VALUE (63) so that the * smallest weight value becomes the largest [i.e., most desireable] value and * accordingly aids in the over-all scoring of each font. */ if (cfont_cur->cfa_weight == cfont_des->cfa_weight) { cfont_g->cfg_weight = EXACT_MATCH; } else { if (cfont_des->cfa_style & BOLD) { /* Bold desired */ /* Select the font the weight of which is closest to '25', * according to the SPRM; but in the case where two fonts are equi-distant * from '25' it favors the more bold font. (The PSRM does not consider ties * with respect to '25'.) */ if (cfont_cur->cfa_weight > BOLD_WEIGHT_CODE) { cfont_g->cfg_weight = ( (cfont_cur->cfa_weight - BOLD_WEIGHT_CODE) * 2 ) - 1; } else { cfont_g->cfg_weight = (BOLD_WEIGHT_CODE - cfont_cur->cfa_weight) * 2; } } else { /* bolding is NOT requested */ /* Select the font the weight of which is closest to '17', * according to the SPRM; it seems to me (nv) that this is a typo or a * mistake (and should be '16') because it tends to favor bold fonts when * the command is for non-bolded fonts. The following code, however, does * what the PSRM calls for; but in the case where two fonts are equi-distant * from '17' it favors the less bold font. (The PSRM does not consider ties * with respect to '17'.) */ if (cfont_cur->cfa_weight > REGULAR_WEIGHT_CODE) { cfont_g->cfg_weight = ( (cfont_cur->cfa_weight - REGULAR_WEIGHT_CODE) * 2 ) - 1; } else { cfont_g->cfg_weight = (REGULAR_WEIGHT_CODE + 1 - cfont_cur->cfa_weight) * 2; } } /* End else for if bold required */ } /*End else for if weight are the same */ /* Now do proportion */ /* If the desired and current proportion are the same, then exact match ** If the desired is larger than current, then value grading ** If the desired is smaller, then proportion fault and value grading */ cfont_g->cfg_proportion = ABS(cfont_cur->cfa_proportion - cfont_des->cfa_proportion); if (cfont_cur->cfa_proportion > cfont_des->cfa_proportion) { cfont_g->cfg_fault_flags |= FLT_PROPORTION; } /* Now do rotation */ /* At this point we ignore the rotation, fonts that are rotated are ** thrown out */ cfont_g->cfg_rotation = EXACT_MATCH;} /* End grade_font subroutine *//***** cfont_comp_grade () ********************************************* * Compare two grades * ************************************************************************//* Returns TRUE if font 2 is better than font 1, FALSE othewise*/BOOL cfont_comp_grade (cfont_g_best, cfont_g)PTR_CFG cfont_g;PTR_CFG cfont_g_best;{ /* First compare fault flags */ /* If it rates worse in fault flags, forget it */ /* if it rates better in fault flag, then it is better */ /* if it rates equal in font flags, then the other items get counted */ if (cfont_g->cfg_fault_flags > cfont_g_best->cfg_fault_flags) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_fault_flags < cfont_g_best->cfg_fault_flags) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_type_family > cfont_g_best->cfg_type_family) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_type_family < cfont_g_best->cfg_type_family) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_cset > cfont_g_best->cfg_cset) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_cset < cfont_g_best->cfg_cset) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_type_size > cfont_g_best->cfg_type_size) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_type_size < cfont_g_best->cfg_type_size) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_spacing_criterion > cfont_g_best->cfg_spacing_criterion) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_spacing_criterion < cfont_g_best->cfg_spacing_criterion) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_spacing_value > cfont_g_best->cfg_spacing_value) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_spacing_value < cfont_g_best->cfg_spacing_value) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_scale_factor > cfont_g_best->cfg_scale_factor) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_scale_factor < cfont_g_best->cfg_scale_factor) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_style > cfont_g_best->cfg_style) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_style < cfont_g_best->cfg_style) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_weight > cfont_g_best->cfg_weight) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_weight < cfont_g_best->cfg_weight) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_proportion > cfont_g_best->cfg_proportion) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_proportion < cfont_g_best->cfg_proportion) { return (TRUE); /*Better, let's say it */ } if (cfont_g->cfg_rotation > cfont_g_best->cfg_rotation) { return (FALSE); /*Worse, forget it */ } if (cfont_g->cfg_rotation < cfont_g_best->cfg_rotation) { return (TRUE); /*Better, let's say it */ } return (FALSE); }/***** cfont_update_best () ******************************************** * Update best font so far * ************************************************************************/VOID cfont_update_best (cfont_d_best, cfont_g_best, cfont_g, cur_font, cfont_att)PTR_CFB cfont_d_best;PTR_CFG cfont_g;PTR_CFG cfont_g_best;PTR_FDP cur_font;PTR_CFA cfont_att;{ /* Better, update best so far */ cfont_d_best->cfb_index = cur_font->fdp_font_index; cfont_d_best->cfb_scale.xval = 1; cfont_d_best->cfb_scale.yval = 1; cfont_d_best->cfb_pair_type = cur_font->fdp_paired_font_flag; cfont_d_best->cfb_spacing_crit = cfont_att->cfa_spacing_criterion; cfont_d_best->cfb_spacing_value = cfont_att->cfa_spacing_value; cfont_d_best->cfb_attr = cfont_att->cfa_style; if (cfont_att->cfa_weight > REGULAR_WEIGHT_CODE) { cfont_d_best->cfb_attr |= BOLD; } cfont_g_best->cfg_fault_flags = cfont_g->cfg_fault_flags; cfont_g_best->cfg_type_family = cfont_g->cfg_type_family; cfont_g_best->cfg_cset = cfont_g->cfg_cset; cfont_g_best->cfg_type_size = cfont_g->cfg_type_size; cfont_g_best->cfg_spacing_criterion = cfont_g->cfg_spacing_criterion; cfont_g_best->cfg_spacing_value = cfont_g->cfg_spacing_value; cfont_g_best->cfg_scale_factor = cfont_g->cfg_scale_factor; cfont_g_best->cfg_style = cfont_g->cfg_style; cfont_g_best->cfg_weight = cfont_g->cfg_weight; cfont_g_best->cfg_proportion = cfont_g->cfg_proportion; cfont_g_best->cfg_rotation = cfont_g->cfg_rotation; }/***** cfont_pairing () ************************************************ * Setup pairing data * ************************************************************************/VOID cfont_pairing (g_table_entry, cfont_data_best_ptr)WORD g_table_entry;PTR_CFB cfont_data_best_ptr; { PUB byte_source; PTR_FN font_number_source; WORD i; FONT_NUMBER cfont_pair_left, cfont_pair_right; /* Assume for now that we have pairing, ans set upp left and right accordingly */ cfont_pair_right = cfont_data_best_ptr->cfb_index; cfont_pair_left = cfont_data_best_ptr->cfb_pair_index; switch (cfont_data_best_ptr->cfb_pair_type) { case DEC_MCS_PAIR: byte_source = nrcs_tables [0+cfont_data_best_ptr->cfb_nrc_type]; break; case ISO_LAT_PAIR: byte_source = nrcs_tables [16+cfont_data_best_ptr->cfb_nrc_type]; break; case DEC_TEC_PAIR: byte_source = nrcs_tables [32+cfont_data_best_ptr->cfb_nrc_type]; break; case DEC_PUB_PAIR: byte_source = nrcs_tables [48+cfont_data_best_ptr->cfb_nrc_type]; break; case NO_DESIRED_PAIR: default: byte_source = nrcs_tables [0]; cfont_pair_left = cfont_data_best_ptr->cfb_index; cfont_pair_right = cfont_data_best_ptr->cfb_index; } for (i = 0; i <= 127; i++) { xl_st.g_table[g_table_entry].gset_map[i].char_code = ((byte_source[i]) & CP_7BIT_MASK); xl_st.g_table[g_table_entry].gset_map[i].char_font = (((byte_source[i]) & BIT7) == 0) ? (cfont_pair_left) : (cfont_pair_right); } }/***** compute_font_for_g_set() **************************************** * Compute Font For G Set * ************************************************************************/VOID compute_font_for_g_set (g_table_entry)WORD g_table_entry;{/* These local variables are used to store the desired attributes of the font*/ORIENTATION cfont_des_orientation; /* Desired orientation */CFONT_FNT_ATTR cfont_des; /* Structure containing the attributes of the desired font */WORD cfont_selection_type; /* selection_type, (by Type Family, Font_12, Font_16) */PTR_FONT_ID cfont_requested_id; /* This points to the selection string of the current SGR in case of a selection by type family, it points to the same 7 characters as cfont_type_family in case of a selection by font, it points to 16 characters (same 7 plus 9 additional selection characters) in case of a selection by xxx, it points to 12 characters (same 7 plus 5 additional selection characters) */FONT_ID cfont_perfect_id; /* What would the ID of the perfect font be */UBYTE desired_pair; /* What pairs can we used to make CSET */WORD MCS_pairing_table_index; /* What is the index in the DEC MCS pairing table */WORD ISO_pairing_table_index; /* What is the index in the ISO MCS pairing table */WORD TEC_pairing_table_index; /* What is the index in the DEC TEChnical pairing table */WORD PUB_pairing_table_index; /* What is the index in the DEC PUBlishing pairing table *//* These local variables are used to store the attributes of the font under** consideration*/CFONT_FNT_ATTR cfont_cur; /* Structure contining the attributes of the font under consideration *//* These local variables are used to store the grades of the font under** consideration.*/CFONT_GRADE_STRUCT cfont_grade; /* structure containing the grade of the font currently under considereration *//* These local variables are used to dialogue with the font dictionary*/FONT_DICT_PARAM current_font; /* Structure used by Dictionary to return parameters *//* These variables are used to memorize the best font*/CFONT_GRADE_STRUCT cfont_grade_best; /* structure contining the grade of the best font so far */CFONT_BEST_STRUCT cfont_data_best; /* This structure memorizes the necessary information, fallbacks and adjustments required to use the best font *//* The first step is to gather the selection criteria, to define which font we** want to use**** orientation** type_family** spacing ** type_size ** scale_factor ** style** weight** proportion** rotation ** cset***//* First, point to the currently selected FONT SGR.*/cfont_requested_id = (PTR_FONT_ID)(xl_st.sgr_tbl[xl_st.cur_sgr].id_string);cfont_selection_type = xl_st.sgr_tbl[xl_st.cur_sgr].selection_type;/* Find the current orientation*/cfont_des_orientation = xl_st.orientation;/* Gather the Type family** by making cfont_des.cfa_type_family point to the id_string of the selected sgr*/strncpy (cfont_des.cfa_type_family, cfont_requested_id, FIDS_TYPE_FAMILY);/* Find the proper kind of spacing*//* If assign by type family, then get it from xl_st, else get it from SGR *//* If the translator is in proportional mode as opposed to monospaced * mode, we do not have a critrion for evaluating font files based upon their * spacing attributes. Such a critrion is synthesized below basically by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -