_A PORTABLE FONT SPECIFICATION_ by Ronald G. White and John Biard Listing One typedef struct { char* family; /* font family */ long size; /* font size in points */ unsigned long style; /* font style bitfield */ char* native_desc; /* native font descriptor */ char is_print; /* window is a print window */ char is_mapped; /* mapped flag */ void* plat_font_data; /* pointer to platform font info */ . . } FONT_OBJ; typedef struct { long far * dummy; } *XVT_FNTID; Listing Two static void font_fabricate_map(XVT_FNTID font_id) { int i; int count = 0; const char* family; unsigned long style; long size; char **mlist = NULL; char* native_desc = NULL; int best_fit = -1; int best_score, cur_score; char *X_attr; int attr_length; long ptsize; char result[MAX_FONTNAME_SIZE]; char xlfd[MAX_FONTNAME_SIZE]; BOOLEAN scalable; PLAT_FONT_DATA *plat_font_data; family = xvtv_font_get_family(font_id); style = xvtv_font_get_style(font_id); size = xvtv_font_get_size(font_id); plat_font_data = FONT_GET_PLAT_DATA(font_id); /* Start with a score of 0 indicating no match */ best_score = 0; /* build an XLFD that brings up the font families that match */ strcpy(xlfd, "-*-"); strcat(xlfd, family); strcat(xlfd, "-*-*-*-*-*-*-*-*-*-*-*-*"); if ((mlist = XListFonts(xvt_display, xlfd, 100, &count)) != NULL) { /* loop through the list of XLFD's, weighing the components of * size, boldness, and italics. */ for (i = 0; i < count; i++) { /* Start at 200 points for matching on family */ cur_score = 200; /* Measure XLFD weight against font style. Note that * the X weight can be "bold" or "demibold"*/ X_attr = get_xlfd_token(mlist[i], X_TOKEN_WEIGHT, &attr_length); if (style & XVT_FS_BOLD) { if (strstr(X_attr, "bold")) cur_score += 100; } else { if (strstr(X_attr, "medium")) cur_score += 100; } /* Measure XLFD slant against font style. Note that * the X slant can be "o" or "i" */ X_attr = get_xlfd_token(mlist[i], X_TOKEN_SLANT, &attr_length); if (style & XVT_FS_ITALIC) { if (strstr(X_attr, "o") || strstr(X_attr, "i")) cur_score += 100; } else { if (strstr(X_attr, "r")) cur_score += 100; } /* Measure XLFD size against font size. If size match * is exact, add 100, else add less than 100. */ X_attr = get_xlfd_token(mlist[i], X_TOKEN_POINTSIZE, &attr_length); ptsize = (strtol(X_attr, NULL, 10)) / 10; if (ptsize == 0 || ptsize == size) cur_score += 100; else cur_score += (min((int)size, (int)ptsize) * 100 / max((int)size, (int)ptsize)); /* Subtract points if this is not an iso8859 font (helps avoid * jis & other fonts). Use 150 to weight matching ISO fonts higher * than, say, an exact size match. */ X_attr = get_xlfd_token(mlist[i], X_TOKEN_REGISTRY, &attr_length); if (!strstr(X_attr, "iso8859")) cur_score -= 150; /* Is this the best font fit we have seen? */ if (cur_score > best_score) { best_score = cur_score; best_fit = i; if (ptsize == 0) scalable = TRUE; else scalable = FALSE; } /* If we have found the perfect match, quit looking */ if (best_score == 500) break; } /* Slip the correct point size in if font is scalable */ if (scalable) { make_font_name(mlist[best_fit], (int)size, result); native_desc = xvtk_font_XLFD_cvt(result); } else native_desc = xvtk_font_XLFD_cvt(mlist[best_fit]); XFreeFontNames(mlist); } else { /* There was not even a native font match against the font * family. Use the system font */ if (scratch_font_id == NULL_FNTID) { scratch_font_id = xvtv_font_create(); xvtv_font_set_family(scratch_font_id, "system"); font_database_map(scratch_font_id); } native_desc=xvtv_font_get_native_desc(scratch_font_id, FALSE); } xvtv_font_set_native_desc(font_id, native_desc); return; } Example 1: (a) "X1101////// ///// ///" (b) "MAC01///"