Stuck trying to draw horizontal line in console emulator

Viewed 185

Windows, using Win32 API calls directly.

I am trying to create a windows app that emulates the behavior of a console app. So I am using Cascadia Mono, the nice new font that comes with Windows Terminal (makes no difference to my problem if I use Courier New or Consolas). The app that is asking me to write things is trying to draw a box using the line drawing characters. The horizontal line char it uses is u2500, the standard light horizontal line

enter image description here

In my app I have calculated the width and height for the font and draw each character one at a time in my WM_PAINT message handling

        for row in 0..ws.rows {
            for col in 0..ws.cols {
                let ch = sb.buffer[offset];
                trace!("paint {:?}", ch);
                offset += 1;
                if ch.ch != ' ' {
                    if ch.fg == Color::Reset {
                        SetTextColor(hdc, RGB(255, 255, 255));
                    } else {
                        let rgb = color(ch.fg);
                        SetTextColor(hdc, rgb);
                    }

                    let u = ch.ch.encode_utf16(&mut b);
                    trace!("ch = {0:0x} ", u[0]);
                    assert!(
                        TextOutW(hdc, col * ws.ch_width, row * ws.ch_height, u.as_ptr(), 1)
                            != 0
                    );
                }
            }
        }

(sorry that this is rust , not C++, but you can see what calls I am making). All works fine but the horizontal lines come out wrong. Here is a screen shot of 3 screens stack on top of each other.

  • Top is my app,
  • next is the original console app in windows terminal
  • Last a cut and paste of the text from Windows terminal into notepad.

enter image description here

You can see that in my app the dashes are chopped off at either end so I get a dashed line. You can also see that the top left corner abuts right up to the first 'k' in the real things but in mine there is a definite gap. Also note that the right hand side of the last 'k' on mine is chopped off by the invisible bounding box of the first dash.

I cannot reduce the character pitch in my code to squash the dashes together because then the other characters will overlap.

I am very much a novice at font and character handling so I am at a loss. I have checked and I am for sure emitting 0x2500 as the character. My naive expectation is that all the characters in a fixed pitch font are the same and that they all stay nicely inside that bounding box.

NOTE : that rust utf16 call is taking the character thats in utf32 format (rusts standard char internal representation) and converting it to utf16.

EDIT: here is a simple no code winforms c# app screen, the same text is copied from the console app and pasted into the text box. Note that the glyphs are full width

enter image description here

And here is chrome displaying the same chars, full width \e2\94\80 is utf8 for 2500. Seem everybody knows a trick I dont enter image description here

0 Answers
Related