Subject: RE: Getting italic fonts (was Re: fonts in Info mode)

From: "George V. Reilly" <[email-masked]>
Date: Wed, 28 Aug 96 16:44:00 PDT

) >I dimly recall someone remarking in the past that the problem was that
) >Bold and Italic faces don't necessarily have the same width as their
) >Regular counterparts in Windows, but they do in X.  Can't you just
) >override the lfWidth of the LOGFONT to force the Bold, Italic, and
) >Bold-Italic variants to have the same width, or use a character cell
) >grid which is as wide as the widest font?
)
) Well, I suppose we could change the NT Emacs text output functions to
) draw individual characters at the spacing of the bold-italic variation,
) but for most fonts it would look wrong (each char would be 2-3 pixels
) too wide, which is very noticeable).

I've done this in the past and it's not really that noticeable
in practice, unless you're using very small fonts, where the
extra pixel or two in width are a large proportion of the
overall width of a character cell.  It's not all that wonderful
either, but then anything involving monospaced fonts rarely is.

) Because the italic variation for most fonts is synthesized (and hence
) the characters extend outside the bounding box for normal characters,
) leaving flotsom on the screen when you scroll or move the cursor over
) text), the generation of italic faces is disabled by default.

The way to handle this is to calculate the maximum italic
overhang (see below).  When you're calculating the bounding box
of invalidated characters, you need to add this to the
right-hand edge of the RECT.  Your WM_PAINT handler should then
automatically repaint the character immediately to the right of
the invalid ones.  Your paint handler will have to paint in all
of the background colours first and then paint the text over the
background with the background mode set to TRANSPARENT.  By
default, text is painted in OPAQUE, but that will cause the
overhanging italics characters to be clipped.

To paint the text, you should use something like:
    ExtTextOut(hdc, rc.left, rc.top, 0, NULL, atchRow + iFirst,
               cch, adxWidths + iFirst);
adxWidths is an array of INTs, each initialized to m_uCellWidth.

/* This code was quickly ripped out of MFC and crudely adapted to
 * use SDK calls so it probably won't compile */
void
GetCharCellGridSize()
{
    HWND  hwnd = GetDesktopWindow();
    HDC   hdc = GetWindowDC(hwnd);

    m_uCellWidth = m_uCellHeight = m_nItalicOverhang = 0;

    for (hfnt in all active fonts)
    {
        static const char ach[] = {'W', 'f', 'g', 'M'};
        SIZE  siz;
        TEXTMETRIC tm;
        ABC abc;
        HFONT hfntOld = SelectFont(hdc, hfnt);

        GetTextMetrics(hdc, &tm);
        GetCharABCWidths(hdc, 'W', 'W', &abc);

        // I find this gives more accurate results for cell size
        // than GetTextMetrics does
        GetTextExtentPoint(hdc, ach, sizeof(ach), &siz);

        SelectFont(hdc, hfntOld);

        m_uCellWidth = max(m_uCellWidth, siz.cx / sizeof(ach));
        m_uCellHeight = max(m_uCellHeight, siz.cy);
        m_nItalicOverhang = max(m_nItalicOverhang, -abc.abcC);
    }

    ReleaseDC(hwnd, hdc);
}

The width of the client area of the frame is (Columns * m_uCellWidth
+ m_nItalicOverhang) and the height is (Rows * m_uCellHeight).

I can send you MFC code that implements all of this, if you like.
 --
/George V. Reilly   <[email-masked]>   <[email-masked]>
MicroCrafts, Inc., 17371 NE 67th Ct #205, Redmond, WA 98052, USA.
Tel: +1 206/250-0014  Fax: 206/250-0100  Web: www.microcrafts.com
Vim 4 (vi clone) for NT & Windows 95: http://www.halcyon.com/gvr/
pgp fingerprint: e2 b4 83 64 11 52 21 ea  bf d8 51 c2 11 00 78 fc

---

From: Jerry Liebelson <[email-masked]>
Date: Tue, 27 Aug 1996 15:54:41 -0400

At 05:44 PM 8/27/96 +0100, Andrew Innes wrote:
>
>
>Lucida Console doesn't appear to have explicitly designed bold or italic
>variations though, because Emacs certainly does ask for the bold
>variation at least.  I suspect the bold variation is not returned
>because it is wider than the normal face.

  I can see bold and italic variants of Lucida Console (via set-default-font,
for example), but emacs reports an error when you try to set the bold Lucida
Console variant for the 'bold face (using set-face-font) is
 
   "No matching fonts are the same height as the frame default font"

(assuming that you previously set the default font with normal Lucida Console)

On the other hand, if I try to do the same thing using Lucida Sans Typewriter

   (set-default-font
         "-*-Lucida Sans Typewriter-normal-r-*-*-13-97-*-*-c-*-*-ansi-")

   (set-face-font 'bold  
       "-*-Lucida Sans Typewriter-semibold-r-*-*-13-97-*-*-c-*-*-ansi-")

 I don't get the error message, but the bold face still isn't bold.

>The only font I know of where the italic and bold variations are the
>same width as the normal face is Courier New...

  Yes, Courier New seems to work fine. My problem with Courier New, however, is
that it's too widely spaced, making my emacs window wider than desired. I prefer
the look of courier to Lucida Sans Typewriter but the latter is more closely
spaced and I can see more text for the given window width.

 DOES ANYBODY KNOW OF A COURIER TRUETYPE FONT THAT IS MORE CLOSELY SPACED THAN
THE COURIER NEW THAT COMES WITH WINDOWS?

 OR FOR THAT MATTER, DOES ANYBODY KNOW OF ANY ALTERNATIVE FIXED-WIDTH FONTS TO
USE IN NT EMACS INSTEAD OF Courier, Lucida Console, and Lucida Sans Typewriter?

-jl

>
>Because the italic variation for most fonts is synthesized (and hence
>the characters extend outside the bounding box for normal characters,
>leaving flotsom on the screen when you scroll or move the cursor over
>text), the generation of italic faces is disabled by default.
>
>To enable it (ie. if you are using Courier New), add this line to your
>.emacs:
>
>  (setq win32-enable-italics t)
>
>AndrewI
>
>
>