Subject: bug#8562: Emacs 23.1 and later don't work in windows 98

From: Eli Zaretskii <[email-masked]>
Date: Fri, 27 May 2011 17:04:23 +0300

> Date: Thu, 26 May 2011 03:50:24 +0200
> From: oslsachem <[email-masked]>
> Cc: [email-masked]
> 
> > After you determine which font is being picked up in the above loop,
> > please put a breakpoint in uniscribe_open and see if it and especially
> > w32font_open_internal that it calls succeed to open the font
> 
> http://www.speedyshare.com/files/28648981/Emacs-23.3GDBuniscribe.txt

Here's what I see in this transcript:

> Breakpoint 3, uniscribe_open (f=0x37f3000, font_entity=58707461, 
>     pixel_size=13) at w32uniscribe.c:124
> 124	  Lisp_Object font_object
> (gdb) n
> 128	    = (struct uniscribe_font_info *) XFONT_OBJECT (font_object);
> (gdb) 
> 127	  struct uniscribe_font_info *uniscribe_font
> (gdb) finish
> Run till exit from #0  uniscribe_open (f=0x37f3000, font_entity=58707461, 
>     pixel_size=13) at w32uniscribe.c:127
> 0x01289daa in font_open_entity (f=0x37f3000, entity=58707461, pixel_size=13)
>     at font.c:3074
> 3074	  font_object = driver_list->driver->open (f, entity, scaled_pixel_size);
> Value returned is $1 = 52252165

> Breakpoint 4, w32font_open_internal (f=0x37f3000, font_entity=58707461, 
>     pixel_size=13, font_object=52252165) at w32font.c:816
> 816	  OUTLINETEXTMETRICW* metrics = NULL;
> (gdb) n
> 818	  w32_font = (struct w32font_info *) XFONT_OBJECT (font_object);
> (gdb) finish
> Run till exit from #0  w32font_open_internal (f=0x37f3000, 
>     font_entity=58707461, pixel_size=13, font_object=52252165)
>     at w32font.c:818
> 0x0131e6b1 in uniscribe_open (f=0x37f3000, font_entity=58707461, 
>     pixel_size=13) at w32uniscribe.c:132
> 132	  if (!w32font_open_internal (f, font_entity, pixel_size, font_object))
> Value returned is $2 = 1

So both functions think they are succeeding.  But I think something
abnormal must be happening inside w32font_open_internal, because
that's where the font object's contents is being filled, and we
already saw that the font winds up garbled in most of its fields in
x_new_font.

So please step through w32font_open_internal and print some of the
important values there, as I did in the session reproduced below.
(Note: the output of the "pp" command does not get written to the GDB
log, so if you use "pp", please either manually add its output into
the log or copy it to your mail response, where I could see it.)

> > Finally, if you start Emacs with "emacs -Q -xrm Emacs.fontBackend:gdi",
> > does it also aborts in the same way, i.e. inside window_box_height?
> 
> http://www.speedyshare.com/files/28648982/Emacs-23.3GDBfontBackend.txt

Same thing.  So the problem is not in the Uniscribe font backend, but
rather in some code that is common to both Uniscribe and GDI font
backends.

Here's the GDB session on Windows XP that shows how the font object is
initialized and what are its values just before w32font_open_internal
is about to return:

GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\usr\test\emacs-23.3\src/./oo/i386/emacs.exe...done.
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) [answered Y; input not from termina
l]
Environment variable "DISPLAY" not defined.
Environment variable "TERM" not defined.
Breakpoint 1 at 0x131219c: file w32fns.c, line 7365.
Temporary breakpoint 2 at 0x113de7a: file sysdep.c, line 1132.
(gdb) break w32font_open_internal
Breakpoint 3 at 0x133c56a: file w32font.c, line 816.
(gdb) r -Q
Starting program: D:\usr\test\emacs-23.3\src/./oo/i386/emacs.exe -Q
[New Thread 5360.0x2d4]
Warning: arch-dependent data dir (d:/usr/test/emacs-23.3/bin/) does not exist.
[New Thread 5360.0x6f0]

Breakpoint 3, w32font_open_internal (f=0x101f3000, font_entity=270458373,
    pixel_size=13, font_object=52391429) at w32font.c:816
816       OUTLINETEXTMETRICW* metrics = NULL;
(gdb) n
818       w32_font = (struct w32font_info *) XFONT_OBJECT (font_object);
(gdb) pp font_entity
#<font-entity uniscribe outline Courier\ New mono iso8859-1 normal normal normal 0 nil 110 nil ((:format . opentype) (:script nko arabic hebrew cyrillic greek latin))>
(gdb) pp font_object
#<font-object nil>
(gdb) n
819       font = (struct font *) w32_font;
(gdb) n
821       if (!font)
(gdb) n
824       bzero (&logfont, sizeof (logfont));
(gdb) p w32_font
$1 = (struct w32font_info *) 0x31f6e00
(gdb) p *w32_font
$2 = {
  font = {
    size = 1075838994,
    next = 0x101ed800,
    props = {48349354, 48349618, 50593634, 48349570, 48343306, 102720,
      102528, 102656, 52, 48130050, 440, 48130050, 48395694, 48130050,
      48130050, 48130050, 48130050, 48130050},
    max_width = 33562893,
    pixel_size = 75378178,
    height = 8,
    space_width = -16777216,
    average_width = 856579,
    min_width = 2052,
    ascent = 0,
    descent = -267582465,
    underline_thickness = 2113995519,
    underline_position = 218890759,
    vertical_centering = 269352976,
    encoding_type = 0 '\000',
    baseline_offset = 242901620,
    relative_compose = 16908291,
    default_ascent = 220204082,
    font_encoder = 0x2e0102f2,
    driver = 0x200080e,
    encoding_charset = 2053600259,
    repertory_charset = 234883341
  },
  metrics = {
    tmHeight = 67239945,
    tmAscent = 2053600883,
    tmDescent = 33555981,
    tmInternalLeading = 1718186756,
    tmExternalLeading = 3018362,
    tmAveCharWidth = 101581574,
    tmMaxCharWidth = 2113995264,
    tmWeight = 33562893,
    tmOverhang = 75378178,
    tmDigitizedAspectX = 8,
    tmDigitizedAspectY = -16777216,
    tmFirstChar = 4611 L'<error reading variable>,
    tmLastChar = 13 L'<error reading variable>,
    tmDefaultChar = 2052 L'<error reading variable>,
    tmBreakChar = 0 L'<error reading variable>,
    tmItalic = 0 '\000',
    tmUnderlined = 0 '\000',
    tmStruckOut = 0 '\000',
    tmPitchAndFamily = 0 '\000',
    tmCharSet = 255 '\377'
  },
  glyph_idx = 2113995519,
  cached_metrics = 0xc0307,
  n_cache_blocks = 1685217636,
  hfont = 0x6e6f662d
}
(gdb) p Qnil
$3 = 48130050
(gdb) n
825       fill_in_logfont (f, &logfont, font_entity);
(gdb) n
829       val = AREF (font_entity, FONT_FOUNDRY_INDEX);
(gdb) n
830       if (!EQ (val, Qraster))
(gdb) pp val
outline
(gdb) n
831         logfont.lfOutPrecision = OUT_TT_PRECIS;
(gdb) n
833       size = XINT (AREF (font_entity, FONT_SIZE_INDEX));
(gdb) n
834       if (!size)
(gdb) p size
$4 = 0
(gdb) n
835         size = pixel_size;
(gdb) n
837       logfont.lfHeight = -size;
(gdb) p size
$6 = 13
(gdb) n
838       hfont = CreateFontIndirect (&logfont);
(gdb) n
840       if (hfont == NULL)
(gdb) n
844       dc = get_frame_dc (f);
(gdb) n
845       old_font = SelectObject (dc, hfont);
(gdb) n
848       len = GetOutlineTextMetricsW (dc, 0, NULL);
(gdb) p old_font
$7 = (HFONT) 0x18a0021
(gdb) n
849       if (len)
(gdb) p len
$8 = 372
(gdb) n
851           metrics = (OUTLINETEXTMETRICW *) alloca (len);
(gdb) n
852           if (GetOutlineTextMetricsW (dc, len, metrics))
(gdb) n
853             bcopy (&metrics->otmTextMetrics, &w32_font->metrics,
(gdb) n
859       if (!metrics)
(gdb) n
862       w32_font->cached_metrics = NULL;
(gdb) p *metrics
$9 = {
  otmSize = 372,
  otmTextMetrics = {
    tmHeight = 16,
    tmAscent = 12,
    tmDescent = 4,
    tmInternalLeading = 3,
    tmExternalLeading = 0,
    tmAveCharWidth = 8,
    tmMaxCharWidth = 9,
    tmWeight = 400,
    tmOverhang = 0,
    tmDigitizedAspectX = 96,
    tmDigitizedAspectY = 96,
    tmFirstChar = 32 L'<error reading variable>,
    tmLastChar = 65532 L'<error reading variable>,
    tmDefaultChar = 31 L'<error reading variable>,
    tmBreakChar = 32 L'<error reading variable>,
    tmItalic = 0 '\000',
    tmUnderlined = 0 '\000',
    tmStruckOut = 0 '\000',
    tmPitchAndFamily = 54 '6',
    tmCharSet = 0 '\000'
  },
  otmFiller = 82 'R',
  otmPanoseNumber = {
    bFamilyType = 2 '\002',
    bSerifStyle = 7 '\a',
    bWeight = 3 '\003',
    bProportion = 9 '   ',
    bContrast = 2 '\002',
    bStrokeVariation = 2 '\002',
    bArmStyle = 5 '\005',
    bLetterform = 2 '\002',
    bMidline = 4 '\004',
    bXHeight = 4 '\004'
  },
  otmfsSelection = 64,
  otmfsType = 0,
  otmsCharSlopeRise = 1,
  otmsCharSlopeRun = 0,
  otmItalicAngle = 0,
  otmEMSquare = 2048,
  otmAscent = 8,
  otmDescent = -2,
  otmLineGap = 0,
  otmsCapEmHeight = 7,
  otmsXHeight = 3,
  otmrcFontBox = {
    left = 0,
    top = 13,
    right = 8,
    bottom = -9
  },
  otmMacAscent = 11,
  otmMacDescent = -4,
  otmMacLineGap = 0,
  otmusMinimumPPEM = 9,
  otmptSubscriptSize = {
    x = 9,
    y = 8
  },
  otmptSubscriptOffset = {
    x = 0,
    y = 2
  },
  otmptSuperscriptSize = {
    x = 9,
    y = 8
  },
  otmptSuperscriptOffset = {
    x = 0,
    y = 5
  },
  otmsStrikeoutSize = 1,
  otmsStrikeoutPosition = 3,
  otmsUnderscoreSize = 1,
  otmsUnderscorePosition = -3,
  otmpFamilyName = 0xd8 <Address 0xd8 out of bounds>,
  otmpFaceName = 0xf0 <Address 0xf0 out of bounds>,
  otmpStyleName = 0x108 <Address 0x108 out of bounds>,
  otmpFullName = 0x118 <Address 0x118 out of bounds>
}
(gdb) n
863       w32_font->n_cache_blocks = 0;
(gdb) n
865       SelectObject (dc, old_font);
(gdb) n
866       release_frame_dc (f, dc);
(gdb) n
868       w32_font->hfont = hfont;
(gdb) n
875         len = 96;
(gdb) n
876         name = alloca (len);
(gdb) n
877         while (name && w32font_full_name (&logfont, font_entity, pixel_size,
(gdb) n
883         if (name)
(gdb) n
884           font->props[FONT_FULLNAME_INDEX]
(gdb) n
891       font->max_width = w32_font->metrics.tmMaxCharWidth;
(gdb) n
898       font->space_width = font->average_width = w32_font->metrics.tmAveCharWidth;
(gdb) n
900       font->vertical_centering = 0;
(gdb) n
901       font->encoding_type = 0;
(gdb) n
902       font->baseline_offset = 0;
(gdb) n
903       font->relative_compose = 0;
(gdb) n
904       font->default_ascent = w32_font->metrics.tmAscent;
(gdb) n
905       font->font_encoder = NULL;
(gdb) n
906       font->pixel_size = size;
(gdb) n
907       font->driver = &w32font_driver;
(gdb) n
910       extra = AREF (font_entity, FONT_EXTRA_INDEX);
(gdb) n
911       if (CONSP (extra))
(gdb) n
913           val = assq_no_quit (QCformat, extra);
(gdb) n
914           if (CONSP (val))
(gdb) n
915             font->props[FONT_FORMAT_INDEX] = XCDR (val);
(gdb) n
922       font->props[FONT_FILE_INDEX] = Qnil;
(gdb) n
923       font->encoding_charset = -1;
(gdb) n
924       font->repertory_charset = -1;
(gdb) n
926       font->min_width = font->space_width;
(gdb) n
927       font->ascent = w32_font->metrics.tmAscent;
(gdb) n
928       font->descent = w32_font->metrics.tmDescent;
(gdb) n
929       font->height = font->ascent + font->descent;
(gdb) n
931       if (metrics)
(gdb) n
933           font->underline_thickness = metrics->otmsUnderscoreSize;
(gdb) n
934           font->underline_position = -metrics->otmsUnderscorePosition;
(gdb) n
946       font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil);
(gdb) n
948       return 1;
(gdb) p *font
$10 = {
  size = 1075838994,
  next = 0x101ed800,
  props = {48349354, 48349618, 50593634, 48349570, 48343306, 102720, 102528,
    102656, 52, 48130050, 440, 48130050, 48395694, 48130050, 50523505,
    50523521, 48130050, 48343258},
  max_width = 9,
  pixel_size = 13,
  height = 16,
  space_width = 8,
  average_width = 8,
  min_width = 8,
  ascent = 12,
  descent = 4,
  underline_thickness = 1,
  underline_position = 3,
  vertical_centering = 0,
  encoding_type = 0 '\000',
  baseline_offset = 0,
  relative_compose = 0,
  default_ascent = 12,
  font_encoder = 0x0,
  driver = 0x153c260,
  encoding_charset = -1,
  repertory_charset = -1
}
(gdb) n
949     }
(gdb)
uniscribe_open (f=0x101f3000, font_entity=270458373, pixel_size=13)
    at w32uniscribe.c:138
138       uniscribe_font->cache = NULL;
(gdb) p font_object
$18 = 52391429
(gdb) xtype
Lisp_Vectorlike
PVEC_FONT
(gdb) xfont
$19 = (struct font *) 0x31f6e00
(gdb) p $->props[14]
$20 = 50523505
(gdb) xstring
$21 = (struct Lisp_String *) 0x302ed70
"-outline-Courier New-normal-normal-normal-mono-13-*-*-*-c-*-iso8859-1"
(gdb) p font_object
$23 = 52391429
(gdb) xfont
$24 = (struct font *) 0x31f6e00
(gdb) p $->props[15]
$25 = 50523521
(gdb) xstring
$26 = (struct Lisp_String *) 0x302ed80
"Courier New-10.0"
(gdb)