This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cygwin fails to utilize Unicode replacement character


On Sep  3 21:14, Corinna Vinschen wrote:
> On Sep  3 20:20, Thomas Wolff wrote:
> > Am 03.09.2018 um 19:56 schrieb Thomas Wolff:
> > > Am 03.09.2018 um 19:16 schrieb Corinna Vinschen:
> > > > On Sep  3 18:34, Thomas Wolff wrote:
> > > > > Am 03.09.2018 um 16:59 schrieb Corinna Vinschen:
> > > > > > Does anybody have an idea what I'm doing wrong?
> > > > > This works in mintty, just uploaded a patch. Maybe somehow the
> > > > > GetConsole
> > > > > "dc" does not support this usage?
> > > > ¯\_(ツ)_/¯
> > > Dito; hold on, sorry, your code does *not* work inside mintty.
> > > Mine looks a bit different and I thought to have manually verified it's
> > > functionally equivalent, but indeed there must be something fishy...
> > You still need to
> >   SelectObject(cdc, f);
> > where f is the HFONT of the font you want to check.
> > To compare, you may check out function win_check_glyphs in file wintext.c in
> > mintty.
> 
> Thanks but I don't know how to get a HFONT for the current console font.
> 
> In the meantime I figured out why my GetCurrentConsoleFontEx call
> failed with error 87:
> 
> When looking again I realized there's a member called cbSize.  The MSDN
> docs neglect to tell that the cbSize member has to be primed with
> sizeof(CONSOLE_FONT_INFOEX).  As soon as I tried that, the function
> succeeded.
> 
> Well, it's a start.  I now have the actual font name.  No idea how to
> get a HFONT from there, though.  From what I can tell ATM, I'd have to
> call CreateFont to get a new HFONT and then destroy it again after
> usage.  This looks pretty wasteful.

Well, it still doesn't work for me.  I now have the following code:

===================== SNIP ======================
#include <windows.h>
#include <stdio.h>
#include <wchar.h>

int
main ()
{
  static const wchar_t replacement_char[2] =
    {
      0xfffd, /* REPLACEMENT CHARACTER */
      0x2592  /* MEDIUM SHADE */
    };

  CONSOLE_FONT_INFOEX cfi;
  HWND cwnd = GetConsoleWindow ();
  HDC cdc = GetDC (cwnd);
  int rp_idx = 1;
  WORD gi[2] = { 0, 0 };

  memset (&cfi, 0, sizeof cfi);
  cfi.cbSize = sizeof cfi;
  if (GetCurrentConsoleFontEx (GetStdHandle (STD_OUTPUT_HANDLE), FALSE, &cfi))
    {
      printf ("font %ls\n", cfi.FaceName);
      HFONT hf = CreateFontW (cfi.dwFontSize.Y, cfi.dwFontSize.X,
			      0, 0, cfi.FontWeight, FALSE, FALSE, FALSE,
			      DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
			      CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			      FIXED_PITCH | FF_DONTCARE, cfi.FaceName);
      if (hf)
      	{
	  HFONT old_f = SelectObject(cdc, hf);
	  if (GetGlyphIndicesW (cdc, replacement_char, 2, gi,
				GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR)
	    {
	      printf ("gi = %d %d\n", gi[0], gi[1]);
	      if (gi[0] != 0xffff)
		rp_idx = 0;
	    }
	  if (old_f)
	    old_f = SelectObject (cdc, old_f);
	  DeleteObject (hf);
	}
    }

  printf ("rp_idx = %d\n", rp_idx);
  return 0;
}
===================== SNAP ======================

Supposedly none of the fonts support 0xfffd:

  $ gcc -g -o cons cons.c -lgdi32
  $ ./cons
  font Consolas
  gi = 65535 879
  rp_idx = 1
  $ ./cons
  font Lucida Console
  gi = 65535 620
  rp_idx = 1
  $ ./cons
  font Courier New
  gi = 65535 372
  rp_idx = 1

So I'm still doing something wrong, apparently.  Any hint?


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]