# HG changeset patch # User Jason Rumney # Date 1213998365 0 # Node ID e7d9b9d2e1ef6e33f369d2d49d0031f84b70ea27 # Parent 94707ef525110a2f2b2b93f8a5bfb44f43977a60 [OLD_FONT]: Remove obsolete font code. diff -r 94707ef52511 -r e7d9b9d2e1ef src/ChangeLog --- a/src/ChangeLog Fri Jun 20 20:00:14 2008 +0000 +++ b/src/ChangeLog Fri Jun 20 21:46:05 2008 +0000 @@ -1,5 +1,8 @@ 2008-06-20 Jason Rumney + * w32fns.c, w32term.c, w32term.h, w32gui.h [OLD_FONT]: Remove + obsolete font code. + * w32font.c (font_matches_spec): Use csb bitfield from font signature to determine language support. diff -r 94707ef52511 -r e7d9b9d2e1ef src/w32fns.c --- a/src/w32fns.c Fri Jun 20 20:00:14 2008 +0000 +++ b/src/w32fns.c Fri Jun 20 21:46:05 2008 +0000 @@ -71,9 +71,6 @@ extern int w32_console_toggle_lock_key P_ ((int, Lisp_Object)); extern void w32_menu_display_help P_ ((HWND, HMENU, UINT, UINT)); extern void w32_free_menu_strings P_ ((HWND)); -#if OLD_FONT -extern XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int)); -#endif extern int quit_char; @@ -4647,335 +4644,6 @@ } -#if OLD_FONT - -/* Return the charset portion of a font name. */ -char * -xlfd_charset_of_font (char * fontname) -{ - char *charset, *encoding; - - encoding = strrchr (fontname, '-'); - if (!encoding || encoding == fontname) - return NULL; - - for (charset = encoding - 1; charset >= fontname; charset--) - if (*charset == '-') - break; - - if (charset == fontname || strcmp (charset, "-*-*") == 0) - return NULL; - - return charset + 1; -} - -struct font_info *w32_load_bdf_font (struct frame *f, char *fontname, - int size, char* filename); -static Lisp_Object w32_list_bdf_fonts (Lisp_Object pattern, int max_names); -static BOOL w32_to_x_font (LOGFONT * lplf, char * lpxstr, int len, - char * charset); -static BOOL x_to_w32_font (char *lpxstr, LOGFONT *lplogfont); - -static struct font_info * -w32_load_system_font (f, fontname, size) - struct frame *f; - char * fontname; - int size; -{ - struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); - Lisp_Object font_names; - - /* Get a list of all the fonts that match this name. Once we - have a list of matching fonts, we compare them against the fonts - we already have loaded by comparing names. */ - font_names = w32_list_fonts (f, build_string (fontname), size, 100); - - if (!NILP (font_names)) - { - Lisp_Object tail; - int i; - - /* First check if any are already loaded, as that is cheaper - than loading another one. */ - for (i = 0; i < dpyinfo->n_fonts; i++) - for (tail = font_names; CONSP (tail); tail = XCDR (tail)) - if (dpyinfo->font_table[i].name - && (!strcmp (dpyinfo->font_table[i].name, - SDATA (XCAR (tail))) - || !strcmp (dpyinfo->font_table[i].full_name, - SDATA (XCAR (tail))))) - return (dpyinfo->font_table + i); - - fontname = (char *) SDATA (XCAR (font_names)); - } - else if (w32_strict_fontnames) - { - /* If EnumFontFamiliesEx was available, we got a full list of - fonts back so stop now to avoid the possibility of loading a - random font. If we had to fall back to EnumFontFamilies, the - list is incomplete, so continue whether the font we want was - listed or not. */ - HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); - FARPROC enum_font_families_ex - = GetProcAddress (gdi32, "EnumFontFamiliesExA"); - if (enum_font_families_ex) - return NULL; - } - - /* Load the font and add it to the table. */ - { - char *full_name, *encoding, *charset; - XFontStruct *font; - struct font_info *fontp; - LOGFONT lf; - BOOL ok; - int codepage; - int i; - - if (!fontname || !x_to_w32_font (fontname, &lf)) - return (NULL); - - if (!*lf.lfFaceName) - /* If no name was specified for the font, we get a random font - from CreateFontIndirect - this is not particularly - desirable, especially since CreateFontIndirect does not - fill out the missing name in lf, so we never know what we - ended up with. */ - return NULL; - - lf.lfQuality = DEFAULT_QUALITY; - - font = (XFontStruct *) xmalloc (sizeof (XFontStruct)); - bzero (font, sizeof (*font)); - - /* Set bdf to NULL to indicate that this is a Windows font. */ - font->bdf = NULL; - - BLOCK_INPUT; - - font->hfont = CreateFontIndirect (&lf); - - if (font->hfont == NULL) - { - ok = FALSE; - } - else - { - HDC hdc; - HANDLE oldobj; - - codepage = w32_codepage_for_font (fontname); - - hdc = GetDC (dpyinfo->root_window); - oldobj = SelectObject (hdc, font->hfont); - - ok = GetTextMetrics (hdc, &font->tm); - if (codepage == CP_UNICODE) - font->double_byte_p = 1; - else - { - /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font) - don't report themselves as double byte fonts, when - patently they are. So instead of trusting - GetFontLanguageInfo, we check the properties of the - codepage directly, since that is ultimately what we are - working from anyway. */ - /* font->double_byte_p = GetFontLanguageInfo (hdc) & GCP_DBCS; */ - CPINFO cpi = {0}; - GetCPInfo (codepage, &cpi); - font->double_byte_p = cpi.MaxCharSize > 1; - } - - SelectObject (hdc, oldobj); - ReleaseDC (dpyinfo->root_window, hdc); - /* Fill out details in lf according to the font that was - actually loaded. */ - lf.lfHeight = font->tm.tmInternalLeading - font->tm.tmHeight; - lf.lfWidth = font->tm.tmMaxCharWidth; - lf.lfWeight = font->tm.tmWeight; - lf.lfItalic = font->tm.tmItalic; - lf.lfCharSet = font->tm.tmCharSet; - lf.lfPitchAndFamily = ((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) - ? VARIABLE_PITCH : FIXED_PITCH); - lf.lfOutPrecision = ((font->tm.tmPitchAndFamily & TMPF_VECTOR) - ? OUT_STROKE_PRECIS : OUT_STRING_PRECIS); - - w32_cache_char_metrics (font); - } - - UNBLOCK_INPUT; - - if (!ok) - { - w32_unload_font (dpyinfo, font); - return (NULL); - } - - /* Find a free slot in the font table. */ - for (i = 0; i < dpyinfo->n_fonts; ++i) - if (dpyinfo->font_table[i].name == NULL) - break; - - /* If no free slot found, maybe enlarge the font table. */ - if (i == dpyinfo->n_fonts - && dpyinfo->n_fonts == dpyinfo->font_table_size) - { - int sz; - dpyinfo->font_table_size = max (16, 2 * dpyinfo->font_table_size); - sz = dpyinfo->font_table_size * sizeof *dpyinfo->font_table; - dpyinfo->font_table - = (struct font_info *) xrealloc (dpyinfo->font_table, sz); - } - - fontp = dpyinfo->font_table + i; - if (i == dpyinfo->n_fonts) - ++dpyinfo->n_fonts; - - /* Now fill in the slots of *FONTP. */ - BLOCK_INPUT; - bzero (fontp, sizeof (*fontp)); - fontp->font = font; - fontp->font_idx = i; - fontp->name = (char *) xmalloc (strlen (fontname) + 1); - bcopy (fontname, fontp->name, strlen (fontname) + 1); - - if ((lf.lfPitchAndFamily & 0x03) == FIXED_PITCH) - { - /* Fixed width font. */ - fontp->average_width = fontp->space_width = FONT_AVG_WIDTH (font); - } - else - { - wchar_t space = 32; - XCharStruct* pcm; - pcm = w32_per_char_metric (font, &space, ANSI_FONT); - if (pcm) - fontp->space_width = pcm->width; - else - fontp->space_width = FONT_AVG_WIDTH (font); - - fontp->average_width = font->tm.tmAveCharWidth; - } - - fontp->charset = -1; - charset = xlfd_charset_of_font (fontname); - - /* Cache the W32 codepage for a font. This makes w32_encode_char - (called for every glyph during redisplay) much faster. */ - fontp->codepage = codepage; - - /* Work out the font's full name. */ - full_name = (char *)xmalloc (100); - if (full_name && w32_to_x_font (&lf, full_name, 100, charset)) - fontp->full_name = full_name; - else - { - /* If all else fails - just use the name we used to load it. */ - xfree (full_name); - fontp->full_name = fontp->name; - } - - fontp->size = FONT_WIDTH (font); - fontp->height = FONT_HEIGHT (font); - - /* The slot `encoding' specifies how to map a character - code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to - the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or - (0:0x20..0x7F, 1:0xA0..0xFF, - (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, - 2:0xA020..0xFF7F). For the moment, we don't know which charset - uses this font. So, we set information in fontp->encoding_type - which is never used by any charset. If mapping can't be - decided, set FONT_ENCODING_NOT_DECIDED. */ - - /* SJIS fonts need to be set to type 4, all others seem to work as - type FONT_ENCODING_NOT_DECIDED. */ - encoding = strrchr (fontp->name, '-'); - if (encoding && strnicmp (encoding+1, "sjis", 4) == 0) - fontp->encoding_type = 4; - else - fontp->encoding_type = FONT_ENCODING_NOT_DECIDED; - - /* The following three values are set to 0 under W32, which is - what they get set to if XGetFontProperty fails under X. */ - fontp->baseline_offset = 0; - fontp->relative_compose = 0; - fontp->default_ascent = 0; - - /* Set global flag fonts_changed_p to non-zero if the font loaded - has a character with a smaller width than any other character - before, or if the font loaded has a smaller height than any - other font loaded before. If this happens, it will make a - glyph matrix reallocation necessary. */ - fonts_changed_p |= x_compute_min_glyph_bounds (f); - UNBLOCK_INPUT; - return fontp; - } -} - -/* Load font named FONTNAME of size SIZE for frame F, and return a - pointer to the structure font_info while allocating it dynamically. - If loading fails, return NULL. */ -struct font_info * -w32_load_font (f, fontname, size) - struct frame *f; - char * fontname; - int size; -{ - Lisp_Object bdf_fonts; - struct font_info *retval = NULL; - struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); - - bdf_fonts = w32_list_bdf_fonts (build_string (fontname), 1); - - while (!retval && CONSP (bdf_fonts)) - { - char *bdf_name, *bdf_file; - Lisp_Object bdf_pair; - int i; - - bdf_name = SDATA (XCAR (bdf_fonts)); - bdf_pair = Fassoc (XCAR (bdf_fonts), Vw32_bdf_filename_alist); - bdf_file = SDATA (XCDR (bdf_pair)); - - /* If the font is already loaded, do not load it again. */ - for (i = 0; i < dpyinfo->n_fonts; i++) - { - if ((dpyinfo->font_table[i].name - && !strcmp (dpyinfo->font_table[i].name, bdf_name)) - || (dpyinfo->font_table[i].full_name - && !strcmp (dpyinfo->font_table[i].full_name, bdf_name))) - return dpyinfo->font_table + i; - } - - retval = w32_load_bdf_font (f, bdf_name, size, bdf_file); - - bdf_fonts = XCDR (bdf_fonts); - } - - if (retval) - return retval; - - return w32_load_system_font (f, fontname, size); -} - - -void -w32_unload_font (dpyinfo, font) - struct w32_display_info *dpyinfo; - XFontStruct * font; -{ - if (font) - { - xfree (font->per_char); - if (font->bdf) w32_free_bdf_font (font->bdf); - - if (font->hfont) DeleteObject (font->hfont); - xfree (font); - } -} -#endif /* OLD_FONT */ - /* The font conversion stuff between x and w32 */ /* X font string is as follows (from faces.el) @@ -5473,65 +5141,6 @@ } } -#if OLD_FONT - -/* Get the Windows codepage corresponding to the specified font. The - charset info in the font name is used to look up - w32-charset-to-codepage-alist. */ -int -w32_codepage_for_font (char *fontname) -{ - Lisp_Object codepage, entry; - char *charset_str, *charset, *end; - - /* Extract charset part of font string. */ - charset = xlfd_charset_of_font (fontname); - - if (!charset) - return CP_UNKNOWN; - - charset_str = (char *) alloca (strlen (charset) + 1); - strcpy (charset_str, charset); - -#if 0 - /* Remove leading "*-". */ - if (strncmp ("*-", charset_str, 2) == 0) - charset = charset_str + 2; - else -#endif - charset = charset_str; - - /* Stop match at wildcard (including preceding '-'). */ - if (end = strchr (charset, '*')) - { - if (end > charset && *(end-1) == '-') - end--; - *end = '\0'; - } - - if (!strcmp (charset, "iso10646")) - return CP_UNICODE; - - if (NILP (Vw32_charset_info_alist)) - return CP_DEFAULT; - - entry = Fassoc (build_string(charset), Vw32_charset_info_alist); - if (NILP (entry)) - return CP_UNKNOWN; - - codepage = Fcdr (Fcdr (entry)); - - if (NILP (codepage)) - return CP_8BIT; - else if (XFASTINT (codepage) == XFASTINT (Qt)) - return CP_UNICODE; - else if (INTEGERP (codepage)) - return XINT (codepage); - else - return CP_UNKNOWN; -} -#endif /* OLD_FONT */ - static BOOL w32_to_x_font (lplogfont, lpxstr, len, specific_charset) LOGFONT * lplogfont; @@ -5816,780 +5425,6 @@ return (TRUE); } -#if OLD_FONT - -/* Strip the pixel height and point height from the given xlfd, and - return the pixel height. If no pixel height is specified, calculate - one from the point height, or if that isn't defined either, return - 0 (which usually signifies a scalable font). -*/ -static int -xlfd_strip_height (char *fontname) -{ - int pixel_height, field_number; - char *read_from, *write_to; - - xassert (fontname); - - pixel_height = field_number = 0; - write_to = NULL; - - /* Look for height fields. */ - for (read_from = fontname; *read_from; read_from++) - { - if (*read_from == '-') - { - field_number++; - if (field_number == 7) /* Pixel height. */ - { - read_from++; - write_to = read_from; - - /* Find end of field. */ - for (;*read_from && *read_from != '-'; read_from++) - ; - - /* Split the fontname at end of field. */ - if (*read_from) - { - *read_from = '\0'; - read_from++; - } - pixel_height = atoi (write_to); - /* Blank out field. */ - if (read_from > write_to) - { - *write_to = '-'; - write_to++; - } - /* If the pixel height field is at the end (partial xlfd), - return now. */ - else - return pixel_height; - - /* If we got a pixel height, the point height can be - ignored. Just blank it out and break now. */ - if (pixel_height) - { - /* Find end of point size field. */ - for (; *read_from && *read_from != '-'; read_from++) - ; - - if (*read_from) - read_from++; - - /* Blank out the point size field. */ - if (read_from > write_to) - { - *write_to = '-'; - write_to++; - } - else - return pixel_height; - - break; - } - /* If the point height is already blank, break now. */ - if (*read_from == '-') - { - read_from++; - break; - } - } - else if (field_number == 8) - { - /* If we didn't get a pixel height, try to get the point - height and convert that. */ - int point_size; - char *point_size_start = read_from++; - - /* Find end of field. */ - for (; *read_from && *read_from != '-'; read_from++) - ; - - if (*read_from) - { - *read_from = '\0'; - read_from++; - } - - point_size = atoi (point_size_start); - - /* Convert to pixel height. */ - pixel_height = point_size - * one_w32_display_info.height_in / 720; - - /* Blank out this field and break. */ - *write_to = '-'; - write_to++; - break; - } - } - } - - /* Shift the rest of the font spec into place. */ - if (write_to && read_from > write_to) - { - for (; *read_from; read_from++, write_to++) - *write_to = *read_from; - *write_to = '\0'; - } - - return pixel_height; -} - -/* Assume parameter 1 is fully qualified, no wildcards. */ -static BOOL -w32_font_match (fontname, pattern) - char * fontname; - char * pattern; -{ - char *ptr; - char *font_name_copy; - char *regex = alloca (strlen (pattern) * 2 + 3); - - font_name_copy = alloca (strlen (fontname) + 1); - strcpy (font_name_copy, fontname); - - ptr = regex; - *ptr++ = '^'; - - /* Turn pattern into a regexp and do a regexp match. */ - for (; *pattern; pattern++) - { - if (*pattern == '?') - *ptr++ = '.'; - else if (*pattern == '*') - { - *ptr++ = '.'; - *ptr++ = '*'; - } - else - *ptr++ = *pattern; - } - *ptr = '$'; - *(ptr + 1) = '\0'; - - /* Strip out font heights and compare them seperately, since - rounding error can cause mismatches. This also allows a - comparison between a font that declares only a pixel height and a - pattern that declares the point height. - */ - { - int font_height, pattern_height; - - font_height = xlfd_strip_height (font_name_copy); - pattern_height = xlfd_strip_height (regex); - - /* Compare now, and don't bother doing expensive regexp matching - if the heights differ. */ - if (font_height && pattern_height && (font_height != pattern_height)) - return FALSE; - } - - return (fast_string_match_ignore_case (build_string (regex), - build_string (font_name_copy)) >= 0); -} - -/* Callback functions, and a structure holding info they need, for - listing system fonts on W32. We need one set of functions to do the - job properly, but these don't work on NT 3.51 and earlier, so we - have a second set which don't handle character sets properly to - fall back on. - - In both cases, there are two passes made. The first pass gets one - font from each family, the second pass lists all the fonts from - each family. */ - -typedef struct enumfont_t -{ - HDC hdc; - int numFonts; - LOGFONT logfont; - XFontStruct *size_ref; - Lisp_Object pattern; - Lisp_Object list; -} enumfont_t; - - -static void -enum_font_maybe_add_to_list (enumfont_t *, LOGFONT *, char *, Lisp_Object); - - -static int CALLBACK -enum_font_cb2 (lplf, lptm, FontType, lpef) - ENUMLOGFONT * lplf; - NEWTEXTMETRIC * lptm; - int FontType; - enumfont_t * lpef; -{ - /* Ignore struck out and underlined versions of fonts. */ - if (lplf->elfLogFont.lfStrikeOut || lplf->elfLogFont.lfUnderline) - return 1; - - /* Only return fonts with names starting with @ if they were - explicitly specified, since Microsoft uses an initial @ to - denote fonts for vertical writing, without providing a more - convenient way of identifying them. */ - if (lplf->elfLogFont.lfFaceName[0] == '@' - && lpef->logfont.lfFaceName[0] != '@') - return 1; - - /* Check that the character set matches if it was specified */ - if (lpef->logfont.lfCharSet != DEFAULT_CHARSET && - lplf->elfLogFont.lfCharSet != lpef->logfont.lfCharSet) - return 1; - - if (FontType == RASTER_FONTTYPE) - { - /* DBCS raster fonts have problems displaying, so skip them. */ - int charset = lplf->elfLogFont.lfCharSet; - if (charset == SHIFTJIS_CHARSET - || charset == HANGEUL_CHARSET - || charset == CHINESEBIG5_CHARSET - || charset == GB2312_CHARSET -#ifdef JOHAB_CHARSET - || charset == JOHAB_CHARSET -#endif - ) - return 1; - } - - { - char buf[100]; - Lisp_Object width = Qnil; - Lisp_Object charset_list = Qnil; - char *charset = NULL; - - /* Truetype fonts do not report their true metrics until loaded */ - if (FontType != RASTER_FONTTYPE) - { - if (!NILP (lpef->pattern)) - { - /* Scalable fonts are as big as you want them to be. */ - lplf->elfLogFont.lfHeight = lpef->logfont.lfHeight; - lplf->elfLogFont.lfWidth = lpef->logfont.lfWidth; - width = make_number (lpef->logfont.lfWidth); - } - else - { - lplf->elfLogFont.lfHeight = 0; - lplf->elfLogFont.lfWidth = 0; - } - } - - /* Make sure the height used here is the same as everywhere - else (ie character height, not cell height). */ - if (lplf->elfLogFont.lfHeight > 0) - { - /* lptm can be trusted for RASTER fonts, but not scalable ones. */ - if (FontType == RASTER_FONTTYPE) - lplf->elfLogFont.lfHeight = lptm->tmInternalLeading - lptm->tmHeight; - else - lplf->elfLogFont.lfHeight = -lplf->elfLogFont.lfHeight; - } - - if (!NILP (lpef->pattern)) - { - charset = xlfd_charset_of_font (SDATA (lpef->pattern)); - - /* We already checked charsets above, but DEFAULT_CHARSET - slipped through. So only allow exact matches for DEFAULT_CHARSET. */ - if (charset - && strncmp (charset, "*-*", 3) != 0 - && lpef->logfont.lfCharSet == DEFAULT_CHARSET - && strcmp (charset, w32_to_x_charset (DEFAULT_CHARSET, NULL)) != 0) - return 1; - - /* Reject raster fonts if we are looking for a unicode font. */ - if (charset - && FontType == RASTER_FONTTYPE - && strncmp (charset, "iso10646", 8) == 0) - return 1; - } - - if (charset) - charset_list = Fcons (build_string (charset), Qnil); - else - /* Always prefer unicode. */ - charset_list - = Fcons (build_string ("iso10646-1"), - w32_to_all_x_charsets (lplf->elfLogFont.lfCharSet)); - - /* Loop through the charsets. */ - for ( ; CONSP (charset_list); charset_list = Fcdr (charset_list)) - { - Lisp_Object this_charset = Fcar (charset_list); - charset = SDATA (this_charset); - - /* Don't list raster fonts as unicode. */ - if (charset - && FontType == RASTER_FONTTYPE - && strncmp (charset, "iso10646", 8) == 0) - continue; - - enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), - charset, width); - - /* List bold and italic variations if w32-enable-synthesized-fonts - is non-nil and this is a plain font. */ - if (w32_enable_synthesized_fonts - && lplf->elfLogFont.lfWeight == FW_NORMAL - && lplf->elfLogFont.lfItalic == FALSE) - { - /* bold. */ - lplf->elfLogFont.lfWeight = FW_BOLD; - enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), - charset, width); - /* bold italic. */ - lplf->elfLogFont.lfItalic = TRUE; - enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), - charset, width); - /* italic. */ - lplf->elfLogFont.lfWeight = FW_NORMAL; - enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), - charset, width); - } - } - } - - return 1; -} - -static void -enum_font_maybe_add_to_list (lpef, logfont, match_charset, width) - enumfont_t * lpef; - LOGFONT * logfont; - char * match_charset; - Lisp_Object width; -{ - char buf[100]; - - if (!w32_to_x_font (logfont, buf, 100, match_charset)) - return; - - if (NILP (lpef->pattern) - || w32_font_match (buf, SDATA (lpef->pattern))) - { - /* Check if we already listed this font. This may happen if - w32_enable_synthesized_fonts is non-nil, and there are real - bold and italic versions of the font. */ - Lisp_Object font_name = build_string (buf); - if (NILP (Fmember (font_name, lpef->list))) - { - Lisp_Object entry = Fcons (font_name, width); - lpef->list = Fcons (entry, lpef->list); - lpef->numFonts++; - } - } -} - - -static int CALLBACK -enum_font_cb1 (lplf, lptm, FontType, lpef) - ENUMLOGFONT * lplf; - NEWTEXTMETRIC * lptm; - int FontType; - enumfont_t * lpef; -{ - return EnumFontFamilies (lpef->hdc, - lplf->elfLogFont.lfFaceName, - (FONTENUMPROC) enum_font_cb2, - (LPARAM) lpef); -} - - -static int CALLBACK -enum_fontex_cb2 (lplf, lptm, font_type, lpef) - ENUMLOGFONTEX * lplf; - NEWTEXTMETRICEX * lptm; - int font_type; - enumfont_t * lpef; -{ - /* We are not interested in the extra info we get back from the 'Ex - version - only the fact that we get character set variations - enumerated seperately. */ - return enum_font_cb2 ((ENUMLOGFONT *) lplf, (NEWTEXTMETRIC *) lptm, - font_type, lpef); -} - -static int CALLBACK -enum_fontex_cb1 (lplf, lptm, font_type, lpef) - ENUMLOGFONTEX * lplf; - NEWTEXTMETRICEX * lptm; - int font_type; - enumfont_t * lpef; -{ - HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); - FARPROC enum_font_families_ex - = GetProcAddress ( gdi32, "EnumFontFamiliesExA"); - /* We don't really expect EnumFontFamiliesEx to disappear once we - get here, so don't bother handling it gracefully. */ - if (enum_font_families_ex == NULL) - error ("gdi32.dll has disappeared!"); - return enum_font_families_ex (lpef->hdc, - &lplf->elfLogFont, - (FONTENUMPROC) enum_fontex_cb2, - (LPARAM) lpef, 0); -} - -/* Interface to fontset handler. (adapted from mw32font.c in Meadow - and xterm.c in Emacs 20.3) */ - -static Lisp_Object -w32_list_bdf_fonts (Lisp_Object pattern, int max_names) -{ - char *fontname, *ptnstr; - Lisp_Object list, tem, newlist = Qnil; - int n_fonts = 0; - - list = Vw32_bdf_filename_alist; - ptnstr = SDATA (pattern); - - for ( ; CONSP (list); list = XCDR (list)) - { - tem = XCAR (list); - if (CONSP (tem)) - fontname = SDATA (XCAR (tem)); - else if (STRINGP (tem)) - fontname = SDATA (tem); - else - continue; - - if (w32_font_match (fontname, ptnstr)) - { - newlist = Fcons (XCAR (tem), newlist); - n_fonts++; - if (max_names >= 0 && n_fonts >= max_names) - break; - } - } - - return newlist; -} - - -/* Return a list of names of available fonts matching PATTERN on frame - F. If SIZE is not 0, it is the size (maximum bound width) of fonts - to be listed. Frame F NULL means we have not yet created any - frame, which means we can't get proper size info, as we don't have - a device context to use for GetTextMetrics. - MAXNAMES sets a limit on how many fonts to match. If MAXNAMES is - negative, then all matching fonts are returned. */ - -Lisp_Object -w32_list_fonts (f, pattern, size, maxnames) - struct frame *f; - Lisp_Object pattern; - int size; - int maxnames; -{ - Lisp_Object patterns, key = Qnil, tem, tpat; - Lisp_Object list = Qnil, newlist = Qnil, second_best = Qnil; - struct w32_display_info *dpyinfo = &one_w32_display_info; - int n_fonts = 0; - - patterns = Fassoc (pattern, Valternate_fontname_alist); - if (NILP (patterns)) - patterns = Fcons (pattern, Qnil); - - for (; CONSP (patterns); patterns = XCDR (patterns)) - { - enumfont_t ef; - int codepage; - - tpat = XCAR (patterns); - - if (!STRINGP (tpat)) - continue; - - /* Avoid expensive EnumFontFamilies functions if we are not - going to be able to output one of these anyway. */ - codepage = w32_codepage_for_font (SDATA (tpat)); - if (codepage != CP_8BIT && codepage != CP_UNICODE - && codepage != CP_DEFAULT && codepage != CP_UNKNOWN - && !IsValidCodePage (codepage)) - continue; - - /* See if we cached the result for this particular query. - The cache is an alist of the form: - ((PATTERN (FONTNAME . WIDTH) ...) ...) - */ - if (tem = XCDR (dpyinfo->name_list_element), - !NILP (list = Fassoc (tpat, tem))) - { - list = Fcdr_safe (list); - /* We have a cached list. Don't have to get the list again. */ - goto label_cached; - } - - BLOCK_INPUT; - /* At first, put PATTERN in the cache. */ - ef.pattern = tpat; - ef.list = Qnil; - ef.numFonts = 0; - - /* Use EnumFontFamiliesEx where it is available, as it knows - about character sets. Fall back to EnumFontFamilies for - older versions of NT that don't support the 'Ex function. */ - x_to_w32_font (SDATA (tpat), &ef.logfont); - { - LOGFONT font_match_pattern; - HMODULE gdi32 = GetModuleHandle ("gdi32.dll"); - FARPROC enum_font_families_ex - = GetProcAddress ( gdi32, "EnumFontFamiliesExA"); - - /* We do our own pattern matching so we can handle wildcards. */ - font_match_pattern.lfFaceName[0] = 0; - font_match_pattern.lfPitchAndFamily = 0; - /* We can use the charset, because if it is a wildcard it will - be DEFAULT_CHARSET anyway. */ - font_match_pattern.lfCharSet = ef.logfont.lfCharSet; - - ef.hdc = GetDC (dpyinfo->root_window); - - if (enum_font_families_ex) - enum_font_families_ex (ef.hdc, - &font_match_pattern, - (FONTENUMPROC) enum_fontex_cb1, - (LPARAM) &ef, 0); - else - EnumFontFamilies (ef.hdc, NULL, (FONTENUMPROC) enum_font_cb1, - (LPARAM)&ef); - - ReleaseDC (dpyinfo->root_window, ef.hdc); - } - - UNBLOCK_INPUT; - list = ef.list; - - /* Make a list of the fonts we got back. - Store that in the font cache for the display. */ - XSETCDR (dpyinfo->name_list_element, - Fcons (Fcons (tpat, list), - XCDR (dpyinfo->name_list_element))); - - label_cached: - if (NILP (list)) continue; /* Try the remaining alternatives. */ - - newlist = second_best = Qnil; - - /* Make a list of the fonts that have the right width. */ - for (; CONSP (list); list = XCDR (list)) - { - int found_size; - tem = XCAR (list); - - if (!CONSP (tem)) - continue; - if (NILP (XCAR (tem))) - continue; - if (!size) - { - newlist = Fcons (XCAR (tem), newlist); - n_fonts++; - if (maxnames >= 0 && n_fonts >= maxnames) - break; - else - continue; - } - if (!INTEGERP (XCDR (tem))) - { - /* Since we don't yet know the size of the font, we must - load it and try GetTextMetrics. */ - W32FontStruct thisinfo; - LOGFONT lf; - HDC hdc; - HANDLE oldobj; - - if (!x_to_w32_font (SDATA (XCAR (tem)), &lf)) - continue; - - BLOCK_INPUT; - thisinfo.bdf = NULL; - thisinfo.hfont = CreateFontIndirect (&lf); - if (thisinfo.hfont == NULL) - continue; - - hdc = GetDC (dpyinfo->root_window); - oldobj = SelectObject (hdc, thisinfo.hfont); - if (GetTextMetrics (hdc, &thisinfo.tm)) - XSETCDR (tem, make_number (FONT_AVG_WIDTH (&thisinfo))); - else - XSETCDR (tem, make_number (0)); - SelectObject (hdc, oldobj); - ReleaseDC (dpyinfo->root_window, hdc); - DeleteObject (thisinfo.hfont); - UNBLOCK_INPUT; - } - found_size = XINT (XCDR (tem)); - if (found_size == size) - { - newlist = Fcons (XCAR (tem), newlist); - n_fonts++; - if (maxnames >= 0 && n_fonts >= maxnames) - break; - } - /* keep track of the closest matching size in case - no exact match is found. */ - else if (found_size > 0) - { - if (NILP (second_best)) - second_best = tem; - - else if (found_size < size) - { - if (XINT (XCDR (second_best)) > size - || XINT (XCDR (second_best)) < found_size) - second_best = tem; - } - else - { - if (XINT (XCDR (second_best)) > size - && XINT (XCDR (second_best)) > - found_size) - second_best = tem; - } - } - } - - if (!NILP (newlist)) - break; - else if (!NILP (second_best)) - { - newlist = Fcons (XCAR (second_best), Qnil); - break; - } - } - - /* Include any bdf fonts. */ - if (n_fonts < maxnames || maxnames < 0) - { - Lisp_Object combined[2]; - combined[0] = w32_list_bdf_fonts (pattern, maxnames - n_fonts); - combined[1] = newlist; - newlist = Fnconc (2, combined); - } - - return newlist; -} - - -/* Return a pointer to struct font_info of font FONT_IDX of frame F. */ -struct font_info * -w32_get_font_info (f, font_idx) - FRAME_PTR f; - int font_idx; -{ - return (FRAME_W32_FONT_TABLE (f) + font_idx); -} - - -struct font_info* -w32_query_font (struct frame *f, char *fontname) -{ - int i; - struct font_info *pfi; - - pfi = FRAME_W32_FONT_TABLE (f); - - for (i = 0; i < one_w32_display_info.n_fonts ;i++, pfi++) - { - if (xstrcasecmp (pfi->name, fontname) == 0) return pfi; - } - - return NULL; -} - -/* Find a CCL program for a font specified by FONTP, and set the member - `encoder' of the structure. */ - -void -w32_find_ccl_program (fontp) - struct font_info *fontp; -{ - Lisp_Object list, elt; - - for (list = Vfont_ccl_encoder_alist; CONSP (list); list = XCDR (list)) - { - elt = XCAR (list); - if (CONSP (elt) - && STRINGP (XCAR (elt)) - && (fast_c_string_match_ignore_case (XCAR (elt), fontp->name) - >= 0)) - break; - } - if (! NILP (list)) - { - struct ccl_program *ccl - = (struct ccl_program *) xmalloc (sizeof (struct ccl_program)); - - if (setup_ccl_program (ccl, XCDR (elt)) < 0) - xfree (ccl); - else - fontp->font_encoder = ccl; - } -} - -#endif /* OLD_FONT */ - -/* directory-files from dired.c. */ -Lisp_Object Fdirectory_files P_ ((Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)); - - -#if OLD_FONT - -/* Find BDF files in a specified directory. (use GCPRO when calling, - as this calls lisp to get a directory listing). */ -static Lisp_Object -w32_find_bdf_fonts_in_dir (Lisp_Object directory) -{ - Lisp_Object filelist, list = Qnil; - char fontname[100]; - - if (!STRINGP (directory)) - return Qnil; - - filelist = Fdirectory_files (directory, Qt, - build_string (".*\\.[bB][dD][fF]"), Qt); - - for ( ; CONSP (filelist); filelist = XCDR (filelist)) - { - Lisp_Object filename = XCAR (filelist); - if (w32_BDF_to_x_font (SDATA (filename), fontname, 100)) - store_in_alist (&list, build_string (fontname), filename); - } - return list; -} - -DEFUN ("w32-find-bdf-fonts", Fw32_find_bdf_fonts, Sw32_find_bdf_fonts, - 1, 1, 0, - doc: /* Return a list of BDF fonts in DIRECTORY. -The list is suitable for appending to `w32-bdf-filename-alist'. -Fonts which do not contain an xlfd description will not be included -in the list. DIRECTORY may be a list of directories. */) - (directory) - Lisp_Object directory; -{ - Lisp_Object list = Qnil; - struct gcpro gcpro1, gcpro2; - - if (!CONSP (directory)) - return w32_find_bdf_fonts_in_dir (directory); - - for ( ; CONSP (directory); directory = XCDR (directory)) - { - Lisp_Object pair[2]; - pair[0] = list; - pair[1] = Qnil; - GCPRO2 (directory, list); - pair[1] = w32_find_bdf_fonts_in_dir ( XCAR (directory) ); - list = Fnconc ( 2, pair ); - UNGCPRO; - } - return list; -} -#endif /* OLD_FONT */ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, @@ -7060,17 +5895,6 @@ error ("Display still has frames on it"); BLOCK_INPUT; -#if OLD_FONT - /* Free the fonts in the font table. */ - for (i = 0; i < dpyinfo->n_fonts; i++) - if (dpyinfo->font_table[i].name) - { - if (dpyinfo->font_table[i].name != dpyinfo->font_table[i].full_name) - xfree (dpyinfo->font_table[i].full_name); - xfree (dpyinfo->font_table[i].name); - w32_unload_font (dpyinfo, dpyinfo->font_table[i].font); - } -#endif x_destroy_all_bitmaps (dpyinfo); x_delete_display (dpyinfo); @@ -9276,29 +8100,11 @@ defsubr (&Sw32_reconstruct_hot_key); defsubr (&Sw32_toggle_lock_key); defsubr (&Sw32_window_exists_p); -#if OLD_FONT - defsubr (&Sw32_find_bdf_fonts); -#endif defsubr (&Sw32_battery_status); defsubr (&Sfile_system_info); defsubr (&Sdefault_printer_name); -#if OLD_FONT - /* Setting callback functions for fontset handler. */ - get_font_info_func = w32_get_font_info; - -#if 0 /* This function pointer doesn't seem to be used anywhere. - And the pointer assigned has the wrong type, anyway. */ - list_fonts_func = w32_list_fonts; -#endif - - load_font_func = w32_load_font; - find_ccl_program_func = w32_find_ccl_program; - query_font_func = w32_query_font; - set_frame_fontset_func = x_set_font; - get_font_repertory_func = x_get_font_repertory; -#endif check_window_system_func = check_w32; diff -r 94707ef52511 -r e7d9b9d2e1ef src/w32gui.h --- a/src/w32gui.h Fri Jun 20 20:00:14 2008 +0000 +++ b/src/w32gui.h Fri Jun 20 21:46:05 2008 +0000 @@ -129,9 +129,6 @@ { COLORREF foreground; COLORREF background; -#if OLD_FONT - XFontStruct * font; -#endif struct font *font; } XGCValues; diff -r 94707ef52511 -r e7d9b9d2e1ef src/w32term.c --- a/src/w32term.c Fri Jun 20 20:00:14 2008 +0000 +++ b/src/w32term.c Fri Jun 20 21:46:05 2008 +0000 @@ -892,596 +892,6 @@ /* Function prototypes of this page. */ -#if OLD_FONT - -XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int)); -static int w32_encode_char P_ ((int, wchar_t *, struct font_info *, - struct charset *, int *)); - - -/* Get metrics of character CHAR2B in FONT. Value is always non-null. - If CHAR2B is not contained in FONT, the font's default character - metric is returned. */ - -static int -w32_bdf_per_char_metric (font, char2b, dim, pcm) - XFontStruct *font; - wchar_t *char2b; - int dim; - XCharStruct * pcm; -{ - glyph_metric * bdf_metric; - char buf[2]; - - if (dim == 1) - buf[0] = (char)(*char2b); - else - { - buf[0] = XCHAR2B_BYTE1 (char2b); - buf[1] = XCHAR2B_BYTE2 (char2b); - } - - bdf_metric = w32_BDF_TextMetric (font->bdf, buf, dim); - - if (bdf_metric) - { - pcm->width = bdf_metric->dwidth; - pcm->lbearing = bdf_metric->bbox; - pcm->rbearing = bdf_metric->dwidth - - (bdf_metric->bbox + bdf_metric->bbw); - pcm->ascent = bdf_metric->bboy + bdf_metric->bbh; - pcm->descent = -bdf_metric->bboy; - - return 1; - } - return 0; -} - - -static int -w32_native_per_char_metric (font, char2b, font_type, pcm) - XFontStruct *font; - wchar_t *char2b; - enum w32_char_font_type font_type; - XCharStruct * pcm; -{ - HDC hdc = GetDC (NULL); - HFONT old_font; - BOOL retval = FALSE; - - xassert (font && char2b); - xassert (font->hfont); - xassert (font_type == UNICODE_FONT || font_type == ANSI_FONT); - - old_font = SelectObject (hdc, font->hfont); - - if ((font->tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0) - { - ABC char_widths; - - if (font_type == UNICODE_FONT) - retval = GetCharABCWidthsW (hdc, *char2b, *char2b, &char_widths); - else - retval = GetCharABCWidthsA (hdc, *char2b, *char2b, &char_widths); - - if (retval) - { -#if 0 - /* Disabled until we can find a way to get the right results - on all versions of Windows. */ - - /* Don't trust the ABC widths. For synthesized fonts they are - wrong, and so is the result of GetCharWidth()! */ - int real_width; - GetCharWidth (hdc, *char2b, *char2b, &real_width); -#endif - if (cleartype_active) - { - /* Cleartype antialiasing causes characters to overhang - by a pixel on each side compared with what GetCharABCWidths - reports. */ - char_widths.abcA -= 1; - char_widths.abcC -= 1; - char_widths.abcB += 2; - } - - pcm->width = char_widths.abcA + char_widths.abcB + char_widths.abcC; -#if 0 - /* As far as I can tell, this is the best way to determine what - ExtTextOut will do with the broken font. */ - if (pcm->width != real_width) - pcm->width = (pcm->width + real_width) / 2; -#endif - pcm->lbearing = char_widths.abcA; - pcm->rbearing = char_widths.abcA + char_widths.abcB; - pcm->ascent = FONT_BASE (font); - pcm->descent = FONT_DESCENT (font); - } - } - - if (!retval) - { - /* Either font is not a True-type font, or GetCharABCWidthsW - failed (it is not supported on Windows 9x for instance), so we - can't determine the full info we would like. All is not lost - though - we can call GetTextExtentPoint32 to get rbearing and - deduce width based on the font's per-string overhang. lbearing - is assumed to be zero. */ - - /* TODO: Some Thai characters (and other composites if Windows - supports them) do have lbearing, and report their total width - as zero. Need some way of handling them when - GetCharABCWidthsW fails. */ - SIZE sz; - - if (font_type == UNICODE_FONT) - retval = GetTextExtentPoint32W (hdc, char2b, 1, &sz); - else - retval = GetTextExtentPoint32A (hdc, (char*)char2b, 1, &sz); - - if (retval) - { - pcm->width = sz.cx; - pcm->rbearing = sz.cx + font->tm.tmOverhang; - pcm->lbearing = 0; - pcm->ascent = FONT_BASE (font); - pcm->descent = FONT_DESCENT (font); - } - } - - - if (pcm->width == 0 && (pcm->rbearing - pcm->lbearing) == 0) - { - retval = FALSE; - } - - SelectObject (hdc, old_font); - ReleaseDC (NULL, hdc); - - return retval; -} - - -XCharStruct * -w32_per_char_metric (font, char2b, font_type) - XFontStruct *font; - wchar_t *char2b; - int /* enum w32_char_font_type */ font_type; -{ - /* The result metric information. */ - XCharStruct *pcm; - BOOL retval; - - xassert (font && char2b); - - /* TODO: This function is currently called through the RIF, and in - some cases font_type is UNKNOWN_FONT. We currently allow the - cached metrics to be used, which seems to work, but in cases - where font_type is UNKNOWN_FONT, we probably haven't encoded - char2b appropriately. All callers need checking to see what they - are passing. This is most likely to affect variable width fonts - outside the Latin-1 range, particularly in languages like Thai - that rely on rbearing and lbearing to provide composition. I - don't think that is working currently anyway, but we don't seem - to have anyone testing such languages on Windows. */ - - /* Handle the common cases quickly. */ - if (!font->bdf && font->per_char == NULL) - /* TODO: determine whether char2b exists in font? */ - return &font->max_bounds; - else if (!font->bdf && *char2b < 128) - return &font->per_char[*char2b]; - - xassert (font_type != UNKNOWN_FONT); - - pcm = &font->scratch; - - if (font_type == BDF_1D_FONT) - retval = w32_bdf_per_char_metric (font, char2b, 1, pcm); - else if (font_type == BDF_2D_FONT) - retval = w32_bdf_per_char_metric (font, char2b, 2, pcm); - else - retval = w32_native_per_char_metric (font, char2b, font_type, pcm); - - if (retval) - return pcm; - - return NULL; -} - -void -w32_cache_char_metrics (font) - XFontStruct *font; -{ - wchar_t char2b = L'x'; - - /* Cache char metrics for the common cases. */ - if (font->bdf) - { - /* TODO: determine whether font is fixed-pitch. */ - if (!w32_bdf_per_char_metric (font, &char2b, 1, &font->max_bounds)) - { - /* Use the font width and height as max bounds, as not all BDF - fonts contain the letter 'x'. */ - font->max_bounds.width = FONT_WIDTH (font); - font->max_bounds.lbearing = -font->bdf->llx; - font->max_bounds.rbearing = FONT_WIDTH (font) - font->bdf->urx; - font->max_bounds.ascent = FONT_BASE (font); - font->max_bounds.descent = FONT_DESCENT (font); - } - } - else - { - if (((font->tm.tmPitchAndFamily & TMPF_FIXED_PITCH) != 0) - /* Some fonts (eg DBCS fonts) are marked as fixed width even - though they contain characters of different widths. */ - || (font->tm.tmMaxCharWidth != font->tm.tmAveCharWidth)) - { - /* Font is not fixed pitch, so cache per_char info for the - ASCII characters. It would be much more work, and probably - not worth it, to cache other chars, since we may change - between using Unicode and ANSI text drawing functions at - run-time. */ - int i; - - font->per_char = xmalloc (128 * sizeof(XCharStruct)); - for (i = 0; i < 128; i++) - { - char2b = i; - w32_native_per_char_metric (font, &char2b, ANSI_FONT, - &font->per_char[i]); - } - } - else - w32_native_per_char_metric (font, &char2b, ANSI_FONT, - &font->max_bounds); - } -} - -/* Determine if a font is double byte. */ -static int -w32_font_is_double_byte (XFontStruct *font) -{ - return font->double_byte_p; -} - - -static BOOL -w32_use_unicode_for_codepage (codepage) - int codepage; -{ - /* If the current codepage is supported, use Unicode for output. */ - return (w32_enable_unicode_output - && codepage != CP_8BIT - && (codepage == CP_UNICODE || IsValidCodePage (codepage))); -} - -/* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is - the two-byte form of C. Encoding is returned in *CHAR2B. */ - -static int /* enum w32_char_font_type */ -w32_encode_char (c, char2b, font_info, charset, two_byte_p) - int c; - wchar_t *char2b; - struct font_info *font_info; - struct charset *charset; - int * two_byte_p; -{ - int codepage; - int unicode_p = 0; - int internal_two_byte_p = 0; - - XFontStruct *font = font_info->font; - - internal_two_byte_p = w32_font_is_double_byte (font); - codepage = font_info->codepage; - - /* If font can output unicode, use the original unicode character. */ - if ( font && !font->bdf && w32_use_unicode_for_codepage (codepage) - && c >= 0x100) - { - *char2b = c; - unicode_p = 1; - internal_two_byte_p = 1; - } - - /* FONT_INFO may define a scheme by which to encode byte1 and byte2. - This may be either a program in a special encoder language or a - fixed encoding. */ - else if (font_info->font_encoder) - { - /* It's a program. */ - struct ccl_program *ccl = font_info->font_encoder; - - if (CHARSET_DIMENSION (charset) == 1) - { - ccl->reg[0] = CHARSET_ID (charset); - ccl->reg[1] = XCHAR2B_BYTE2 (char2b); - ccl->reg[2] = -1; - } - else - { - ccl->reg[0] = CHARSET_ID (charset); - ccl->reg[1] = XCHAR2B_BYTE1 (char2b); - ccl->reg[2] = XCHAR2B_BYTE2 (char2b); - } - - ccl_driver (ccl, NULL, NULL, 0, 0, Qnil); - - /* We assume that MSBs are appropriately set/reset by CCL - program. */ - if (!internal_two_byte_p) /* 1-byte font */ - STORE_XCHAR2B (char2b, 0, ccl->reg[1]); - else - STORE_XCHAR2B (char2b, ccl->reg[1], ccl->reg[2]); - } - else if (font_info->encoding_type) - { - /* Fixed encoding scheme. See fontset.h for the meaning of the - encoding numbers. */ - unsigned char enc = font_info->encoding_type; - - if ((enc == 1 || enc == 2) - && CHARSET_DIMENSION (charset) == 2) - STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b) | 0x80, XCHAR2B_BYTE2 (char2b)); - - if (enc == 1 || enc == 3 || (enc == 4 && CHARSET_DIMENSION (charset) == 1)) - STORE_XCHAR2B (char2b, XCHAR2B_BYTE1 (char2b), XCHAR2B_BYTE2 (char2b) | 0x80); - else if (enc == 4) - { - int code = (int) (*char2b); - - JIS_TO_SJIS (code); - STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF)); - } - } - - if (two_byte_p) - *two_byte_p = internal_two_byte_p; - - if (!font) - return UNKNOWN_FONT; - else if (font->bdf && CHARSET_DIMENSION (charset) == 1) - return BDF_1D_FONT; - else if (font->bdf) - return BDF_2D_FONT; - else if (unicode_p) - return UNICODE_FONT; - else - return ANSI_FONT; -} - - -/* Return a char-table whose elements are t if the font FONT_INFO - contains a glyph for the corresponding character, and nil if not. - - Fixme: For the moment, this function works only for fonts whose - glyph encoding is the same as Unicode (e.g. ISO10646-1 fonts). */ - -Lisp_Object -x_get_font_repertory (f, font_info) - FRAME_PTR f; - struct font_info *font_info; -{ - XFontStruct *font = (XFontStruct *) font_info->font; - Lisp_Object table; - int min_byte1, max_byte1, min_byte2, max_byte2; - int c; - struct charset *charset = CHARSET_FROM_ID (font_info->charset); - int offset = CHARSET_OFFSET (charset); - - table = Fmake_char_table (Qnil, Qnil); - - if (!font->bdf && pfnGetFontUnicodeRanges) - { - GLYPHSET *glyphset; - DWORD glyphset_size; - HDC display = get_frame_dc (f); - HFONT prev_font; - int i; - - prev_font = SelectObject (display, font->hfont); - - /* First call GetFontUnicodeRanges to find out how big a structure - we need. */ - glyphset_size = pfnGetFontUnicodeRanges (display, NULL); - if (glyphset_size) - { - glyphset = (GLYPHSET *) alloca (glyphset_size); - glyphset->cbThis = glyphset_size; - - /* Now call it again to get the ranges. */ - glyphset_size = pfnGetFontUnicodeRanges (display, glyphset); - - if (glyphset_size) - { - /* Store the ranges in TABLE. */ - for (i = 0; i < glyphset->cRanges; i++) - { - int from = glyphset->ranges[i].wcLow; - int to = from + glyphset->ranges[i].cGlyphs - 1; - char_table_set_range (table, from, to, Qt); - } - } - } - - SelectObject (display, prev_font); - release_frame_dc (f, display); - - /* If we got the information we wanted above, then return it. */ - if (glyphset_size) - return table; - } - -#if 0 /* TODO: Convert to work on Windows so BDF and older platforms work. */ - /* When GetFontUnicodeRanges is not available or does not work, - work it out manually. */ - min_byte1 = font->min_byte1; - max_byte1 = font->max_byte1; - min_byte2 = font->min_char_or_byte2; - max_byte2 = font->max_char_or_byte2; - if (min_byte1 == 0 && max_byte1 == 0) - { - if (! font->per_char || font->all_chars_exist == True) - { - if (offset >= 0) - char_table_set_range (table, offset + min_byte2, - offset + max_byte2, Qt); - else - for (; min_byte2 <= max_byte2; min_byte2++) - { - c = DECODE_CHAR (charset, min_byte2); - CHAR_TABLE_SET (table, c, Qt); - } - } - else - { - XCharStruct *pcm = font->per_char; - int from = -1; - int i; - - for (i = min_byte2; i <= max_byte2; i++, pcm++) - { - if (pcm->width == 0 && pcm->rbearing == pcm->lbearing) - { - if (from >= 0) - { - if (offset >= 0) - char_table_set_range (table, offset + from, - offset + i - 1, Qt); - else - for (; from < i; from++) - { - c = DECODE_CHAR (charset, from); - CHAR_TABLE_SET (table, c, Qt); - } - from = -1; - } - } - else if (from < 0) - from = i; - } - if (from >= 0) - { - if (offset >= 0) - char_table_set_range (table, offset + from, offset + i - 1, - Qt); - else - for (; from < i; from++) - { - c = DECODE_CHAR (charset, from); - CHAR_TABLE_SET (table, c, Qt); - } - } - } - } - else - { - if (! font->per_char || font->all_chars_exist == True) - { - int i, j; - - if (offset >= 0) - for (i = min_byte1; i <= max_byte1; i++) - char_table_set_range - (table, offset + ((i << 8) | min_byte2), - offset + ((i << 8) | max_byte2), Qt); - else - for (i = min_byte1; i <= max_byte1; i++) - for (j = min_byte2; j <= max_byte2; j++) - { - unsiged code = (i << 8) | j; - c = DECODE_CHAR (charset, code); - CHAR_TABLE_SET (table, c, Qt); - } - } - else - { - XCharStruct *pcm = font->per_char; - int i; - - for (i = min_byte1; i <= max_byte1; i++) - { - int from = -1; - int j; - - for (j = min_byte2; j <= max_byte2; j++, pcm++) - { - if (pcm->width == 0 && pcm->rbearing == pcm->lbearing) - { - if (from >= 0) - { - if (offset >= 0) - char_table_set_range - (table, offset + ((i << 8) | from), - offset + ((i << 8) | (j - 1)), Qt); - else - { - for (; from < j; from++) - { - unsigned code = (i << 8) | from; - c = ENCODE_CHAR (charset, code); - CHAR_TABLE_SET (table, c, Qt); - } - } - from = -1; - } - } - else if (from < 0) - from = j; - } - if (from >= 0) - { - if (offset >= 0) - char_table_set_range - (table, offset + ((i << 8) | from), - offset + ((i << 8) | (j - 1)), Qt); - else - { - for (; from < j; from++) - { - unsigned code = (i << 8) | from; - c = DECODE_CHAR (charset, code); - CHAR_TABLE_SET (table, c, Qt); - } - } - } - } - } - } -#endif - return table; -} - - -/*********************************************************************** - Glyph display - ***********************************************************************/ - - -/* Encapsulate the different ways of displaying text under W32. */ - -static void -w32_text_out (s, x, y,chars,nchars) - struct glyph_string * s; - int x, y; - wchar_t * chars; - int nchars; -{ - int charset_dim = w32_font_is_double_byte (s->font) ? 2 : 1; - if (s->font->bdf) - w32_BDF_TextOut (s->font->bdf, s->hdc, - x, y, (char *) chars, charset_dim, - nchars * charset_dim, 0); - else if (s->first_glyph->font_type == UNICODE_FONT) - ExtTextOutW (s->hdc, x, y, 0, NULL, chars, nchars, NULL); - else - ExtTextOutA (s->hdc, x, y, 0, NULL, (char *) chars, - nchars * charset_dim, NULL); -} - -#endif /* OLD_FONT */ - static void x_set_glyph_string_clipping P_ ((struct glyph_string *)); static void x_set_glyph_string_gc P_ ((struct glyph_string *)); static void x_draw_glyph_string_background P_ ((struct glyph_string *, @@ -1509,10 +919,6 @@ static void w32_draw_box_rect P_ ((struct glyph_string *, int, int, int, int, int, int, int, RECT *)); -#if GLYPH_DEBUG -static void x_check_font P_ ((struct frame *, XFontStruct *)); -#endif - /* Set S->gc to a suitable GC for drawing glyph string S in cursor face. */ @@ -1722,17 +1128,6 @@ r.bottom = r.top + src->height; dst->clip[0] = r; dst->num_clips = 1; -#if OLD_FONT - { - struct glyph_string *clip_head = src->clip_head; - struct glyph_string *clip_tail = src->clip_tail; - - /* This foces clipping just this glyph string. */ - src->clip_head = src->clip_tail = src; - get_glyph_string_clip_rect (src, &r); - src->clip_head = clip_head, src->clip_tail = clip_tail; - } -#endif /* OLD_FONT */ w32_set_clip_rectangle (dst->hdc, &r); } @@ -5770,109 +5165,6 @@ /* Changing the font of the frame. */ -#if OLD_FONT - -/* Give frame F the font named FONTNAME as its default font, and - return the full name of that font. FONTNAME may be a wildcard - pattern; in that case, we choose some font that fits the pattern. - The return value shows which font we chose. */ - -Lisp_Object -x_new_font (f, fontname) - struct frame *f; - register char *fontname; -{ - struct font_info *fontp - = FS_LOAD_FONT (f, fontname); - - if (!fontp) - return Qnil; - - if (FRAME_FONT (f) == (XFontStruct *) (fontp->font)) - /* This font is already set in frame F. There's nothing more to - do. */ - return build_string (fontp->full_name); - - FRAME_FONT (f) = (XFontStruct *) (fontp->font); - FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset; - FRAME_FONTSET (f) = -1; - - FRAME_COLUMN_WIDTH (f) = fontp->average_width; - FRAME_SPACE_WIDTH (f) = fontp->space_width; - FRAME_LINE_HEIGHT (f) = FONT_HEIGHT (FRAME_FONT (f)); - - compute_fringe_widths (f, 1); - - /* Compute the scroll bar width in character columns. */ - if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0) - { - int wid = FRAME_COLUMN_WIDTH (f); - FRAME_CONFIG_SCROLL_BAR_COLS (f) - = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) + wid-1) / wid; - } - else - { - int wid = FRAME_COLUMN_WIDTH (f); - FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid; - } - - /* Now make the frame display the given font. */ - if (FRAME_W32_WINDOW (f) != 0) - { - if (NILP (tip_frame) || XFRAME (tip_frame) != f) - x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f)); - } - - return build_string (fontp->full_name); -} - -/* Give frame F the fontset named FONTSETNAME as its default fontset, - and return the full name of that fontset. FONTSETNAME may be a - wildcard pattern; in that case, we choose some fontset that fits - the pattern. FONTSETNAME may be a font name for ASCII characters; - in that case, we create a fontset from that font name. - - The return value shows which fontset we chose. - If FONTSETNAME specifies the default fontset, return Qt. - If an ASCII font in the specified fontset can't be loaded, return - Qnil. */ - -Lisp_Object -x_new_fontset (f, fontsetname) - struct frame *f; - Lisp_Object fontsetname; -{ - int fontset = fs_query_fontset (fontsetname, 0); - Lisp_Object result; - - if (fontset > 0 && FRAME_FONTSET(f) == fontset) - /* This fontset is already set in frame F. There's nothing more - to do. */ - return fontset_name (fontset); - else if (fontset == 0) - /* The default fontset can't be the default font. */ - return Qt; - - if (fontset > 0) - result = x_new_font (f, (SDATA (fontset_ascii (fontset)))); - else - result = x_new_font (f, SDATA (fontsetname)); - - if (!STRINGP (result)) - /* Can't load ASCII font. */ - return Qnil; - - if (fontset < 0) - fontset = new_fontset_from_font_name (result); - - /* Since x_new_font doesn't update any fontset information, do it now. */ - FRAME_FONTSET(f) = fontset; - - return fontset_name (fontset); -} -#endif /* OLD_FONT */ - - Lisp_Object x_new_font (f, font_object, fontset) struct frame *f; @@ -6601,118 +5893,6 @@ /*********************************************************************** - Fonts - ***********************************************************************/ - -#if OLD_FONT - -/* The following functions are listed here to help diff stay in step - with xterm.c. See w32fns.c for definitions. - -x_get_font_info (f, font_idx) -x_list_fonts (f, pattern, size, maxnames) - - */ - -#if GLYPH_DEBUG - -/* Check that FONT is valid on frame F. It is if it can be found in F's - font table. */ - -static void -x_check_font (f, font) - struct frame *f; - XFontStruct *font; -{ - int i; - struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); - - xassert (font != NULL); - - for (i = 0; i < dpyinfo->n_fonts; i++) - if (dpyinfo->font_table[i].name - && font == dpyinfo->font_table[i].font) - break; - - xassert (i < dpyinfo->n_fonts); -} - -#endif /* GLYPH_DEBUG != 0 */ - -/* Set *W to the minimum width, *H to the minimum font height of FONT. - Note: There are (broken) X fonts out there with invalid XFontStruct - min_bounds contents. For example, handa@etl.go.jp reports that - "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts - have font->min_bounds.width == 0. */ - -static INLINE void -x_font_min_bounds (font, w, h) - XFontStruct *font; - int *w, *h; -{ - /* - * TODO: Windows does not appear to offer min bound, only - * average and maximum width, and maximum height. - */ - *h = FONT_HEIGHT (font); - *w = FONT_AVG_WIDTH (font); -} - - -/* Compute the smallest character width and smallest font height over - all fonts available on frame F. Set the members smallest_char_width - and smallest_font_height in F's x_display_info structure to - the values computed. Value is non-zero if smallest_font_height or - smallest_char_width become smaller than they were before. */ - -int -x_compute_min_glyph_bounds (f) - struct frame *f; -{ - int i; - struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); - XFontStruct *font; - int old_width = dpyinfo->smallest_char_width; - int old_height = dpyinfo->smallest_font_height; - - dpyinfo->smallest_font_height = 100000; - dpyinfo->smallest_char_width = 100000; - - for (i = 0; i < dpyinfo->n_fonts; ++i) - if (dpyinfo->font_table[i].name) - { - struct font_info *fontp = dpyinfo->font_table + i; - int w, h; - - font = (XFontStruct *) fontp->font; - xassert (font != (XFontStruct *) ~0); - x_font_min_bounds (font, &w, &h); - - dpyinfo->smallest_font_height = min (dpyinfo->smallest_font_height, h); - dpyinfo->smallest_char_width = min (dpyinfo->smallest_char_width, w); - } - - xassert (dpyinfo->smallest_char_width > 0 - && dpyinfo->smallest_font_height > 0); - - return (dpyinfo->n_fonts == 1 - || dpyinfo->smallest_char_width < old_width - || dpyinfo->smallest_font_height < old_height); -} - -/* The following functions are listed here to help diff stay in step - with xterm.c. See w32fns.c for definitions. - -x_load_font (f, fontname, size) -x_query_font (f, fontname) -x_find_ccl_program (fontp) - -*/ - -#endif /* OLD_FONT */ - - -/*********************************************************************** Initialization ***********************************************************************/ @@ -6844,10 +6024,6 @@ w32_draw_fringe_bitmap, w32_define_fringe_bitmap, w32_destroy_fringe_bitmap, -#if OLD_FONT - w32_per_char_metric, - w32_encode_char, -#endif w32_compute_glyph_string_overhangs, x_draw_glyph_string, w32_define_frame_cursor, @@ -6935,14 +6111,6 @@ return; BLOCK_INPUT; -#if OLD_FONT - /* Free the fonts in the font table. */ - for (i = 0; i < dpyinfo->n_fonts; i++) - if (dpyinfo->font_table[i].name) - { - DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont); - } -#endif x_delete_display (dpyinfo); UNBLOCK_INPUT; @@ -7071,9 +6239,6 @@ if (dpyinfo->palette) DeleteObject(dpyinfo->palette); } -#if OLD_FONT - xfree (dpyinfo->font_table); -#endif xfree (dpyinfo->w32_id_name); w32_reset_fringes (); diff -r 94707ef52511 -r e7d9b9d2e1ef src/w32term.h --- a/src/w32term.h Fri Jun 20 20:00:14 2008 +0000 +++ b/src/w32term.h Fri Jun 20 21:46:05 2008 +0000 @@ -145,14 +145,6 @@ received; value is reset after key is received. */ int faked_key; -#if OLD_FONT - /* A table of all the fonts we have already loaded. */ - struct font_info *font_table; - - /* The current capacity of font_table. */ - int font_table_size; -#endif - /* Minimum width over all characters in all fonts in font_table. */ int smallest_char_width; @@ -251,15 +243,6 @@ extern struct w32_display_info *w32_term_init (); -#if OLD_FONT -extern Lisp_Object w32_list_fonts P_ ((struct frame *, Lisp_Object, int, int)); -extern struct font_info *w32_get_font_info (), *w32_query_font (); -extern void w32_cache_char_metrics (XFontStruct *font); -extern void w32_find_ccl_program(); -extern Lisp_Object x_get_font_repertory P_ ((struct frame *, - struct font_info *)); -#endif - #define PIX_TYPE COLORREF /* Each W32 frame object points to its own struct w32_display object @@ -321,9 +304,6 @@ Window parent_desc; /* Default ASCII font of this frame. */ -#if OLD_FONT - XFontStruct *font; -#endif struct font *font; /* The baseline offset of the default ASCII font. */ @@ -419,11 +399,6 @@ /* This is the `Display *' which frame F is on. */ #define FRAME_X_DISPLAY(f) (0) -#if OLD_FONT -/* This is the 'font_info *' which frame F has. */ -#define FRAME_W32_FONT_TABLE(f) (FRAME_W32_DISPLAY_INFO (f)->font_table) -#endif - /* Value is the smallest width of any character in any font on frame F. */ #define FRAME_SMALLEST_CHAR_WIDTH(F) \ @@ -593,11 +568,6 @@ #define w32_clear_area(f,hdc,px,py,nx,ny) \ w32_fill_area (f, hdc, FRAME_BACKGROUND_PIXEL (f), px, py, nx, ny) -#if OLD_FONT -extern struct font_info *w32_load_font (); -extern void w32_unload_font (); -#endif - /* Define for earlier versions of Visual C */ #ifndef WM_MOUSEWHEEL #define WM_MOUSEWHEEL (WM_MOUSELAST + 1)