Mercurial > emacs
diff src/w32fns.c @ 96133:e7d9b9d2e1ef
[OLD_FONT]: Remove obsolete font code.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Fri, 20 Jun 2008 21:46:05 +0000 |
parents | 0623378cdbca |
children | c3309dba6542 |
line wrap: on
line diff
--- 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;