Dot-matrix printing in PCem

Discussion of development and patch submission.
Post Reply
EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Dot-matrix printing in PCem

Post by EluanCM » Sun 02 Feb, 2020 5:05 pm

Anyone else interested in this?

I've taken an old unfinished patch for DOSBox from the middle 2000's and began reworking it. Fixed numerous issues with the interface, drawing and printer logic and I think I've achieved a milestone. It can print correctly everything that I throw at it under DOS, Win 3.1 and Win 95. I've adapted it (ESC/P commands resolution, mainly) to emulate the Epson LX-810, which is the printer that I have.

Dependencies: Freetype (until I have a dump of the character ROM - or maybe I keep it for an inaccurate "high-res" output?)
Output: Postscript, BMP. (Haven't ported the Windows printer forwarding and PNG output yet.)

-Bitmap printing emulates the pins but can optionally keep the old behaviour from the DOSBox patch and output continuously.
-Draft printing uses freely redistributable fonts that imitate the Epson FX Printers, they look almost the same as the LX-810. Not all extended characters are available and sometimes a combination of styles and effects isn't available, so it will fallback to a similar one (in this case the dots can potentially have slightly different dimensions.)
-Provide your own monospace Roman and Sans Serif truetype or opentype fonts.

Next big thing is the built-in font emulation. I also need to integrate it with the PCem configuration.

Attached are some screenshots of the current state.
Attachments
Screenshot_2020-02-02_11-15-04.png
Screenshot_2020-02-02_11-15-04.png (130.5 KiB) Viewed 1096 times
Screenshot_2020-02-02_00-23-04.png
Screenshot_2020-02-02_00-23-04.png (128.45 KiB) Viewed 1096 times

User avatar
omarsis81
Posts: 783
Joined: Thu 17 Dec, 2015 6:20 pm

Re: Dot-matrix printing in PCem

Post by omarsis81 » Sun 02 Feb, 2020 7:25 pm

So... you print something in PCem and the emulator outputs an image file? Did I get it right?

User avatar
te_lanus
Posts: 100
Joined: Tue 28 Jul, 2015 4:47 am

Re: Dot-matrix printing in PCem

Post by te_lanus » Sun 02 Feb, 2020 9:14 pm

omarsis81 wrote:
Sun 02 Feb, 2020 7:25 pm
So... you print something in PCem and the emulator outputs an image file? Did I get it right?
Looks like it

EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: Dot-matrix printing in PCem

Post by EluanCM » Sun 02 Feb, 2020 9:27 pm

omarsis81 wrote:
Sun 02 Feb, 2020 7:25 pm
So... you print something in PCem and the emulator outputs an image file? Did I get it right?
That is correct. It can also be easily redirected to a real printer.

SA1988
Posts: 259
Joined: Wed 30 Apr, 2014 9:38 am

Re: Dot-matrix printing in PCem

Post by SA1988 » Sun 02 Feb, 2020 10:02 pm

I'm greatly interested into this! :)

ecksemmess
Posts: 165
Joined: Wed 18 Mar, 2015 5:27 am

Re: Dot-matrix printing in PCem

Post by ecksemmess » Mon 03 Feb, 2020 12:24 am

As am I. Really excellent work! Hope to see this merged into mainline PCem sometime soon. :)

shermanp
Posts: 130
Joined: Sat 18 Feb, 2017 2:09 am

Re: Dot-matrix printing in PCem

Post by shermanp » Mon 03 Feb, 2020 11:50 am

Are you just using Freetype for font rasterization?

If so, another potential font rasterizer is [url]https://github.com/nothings/stb/blob/master/stb_truetype.h[/url]. It's a portable, single-header opentype font rasterizer library. I've used it to create a rudimentary text layout program on an eink device. It's pretty quick and easy to figure out. Quality is fine if you don't require features like hinting etc.

It might be a bit easier to integrate with PCem, without needing to include and link freetype as a separate library.

EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: Dot-matrix printing in PCem

Post by EluanCM » Fri 07 Feb, 2020 10:10 pm

Just for rasterization. Thanks for the tip, this looks nice!
I hope to post a patch with a useable version in a few weeks at most.

In the meantime, does anyone have any tips on monospaced Roman and Sans Serif fonts that look like the Epson fonts and have a nice license? :-)

shermanp
Posts: 130
Joined: Sat 18 Feb, 2017 2:09 am

Re: Dot-matrix printing in PCem

Post by shermanp » Sat 08 Feb, 2020 9:48 pm

I don't know how much experience you have rendering fonts, but one thing I learned was: don't trust the fonts own metrics.

I once made that mistake. The code worked properly with the fonts I was using. Someone else tested with broken font metrics, and started getting segfaults. I quickly learned that one must do glyph size calculations based on the bitmap bounding box, and not the horizontal/vertical metrics.

EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: Dot-matrix printing in PCem

Post by EluanCM » Sat 08 Feb, 2020 10:32 pm

No experience at all, I'm a backend person. I've noticed that some fonts can have a negative left/top so I currently handle this. Can they get *more* broken than this?

shermanp
Posts: 130
Joined: Sat 18 Feb, 2017 2:09 am

Re: Dot-matrix printing in PCem

Post by shermanp » Sat 08 Feb, 2020 10:43 pm

Yeah, stuff like line height can be modified. But stuff like negative left bearings is quite normal, especially for proportional fonts. Use the metrics to determine WHERE to place glyphs. Just don't rely on them to determine your buffer sizes.

If you end up using STB_Truetype, you should be safe to use stbtt_GetCodepointBitmapBox() to get required glyph dimensions. Or, if performance isn't a big deal and/or you're caching the bitmaps, stbtt_GetCodepointBitmap() might be an easier option.

EDIT: Just to let you know, I'm not an expert in this either. I've written one implementation, which, looking at it today, is rather messy, but somehow gets the job done. For... inspiration, you could probably look at https://github.com/NiLuJe/FBInk/blob/master/fbink.c#L3915 if your brave enough. It's my original implementation, with enhancements by the original project creator. The original PR is here: https://github.com/NiLuJe/FBInk/pull/20

EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: Dot-matrix printing in PCem

Post by EluanCM » Tue 11 Feb, 2020 10:57 pm

Thanks for all your tips!

I was halfway through converting from FreeType to stb_truetype when I realized that it doesn't expose transformation matrices (just x and y scale). This code uses it for italics on Roman and Sans Serif fonts. The easy alternative would be depending on two more files for these variations. :(

Since I last posted here, I've converted the image output to use PCem's wx-utils (so now PNG, TIFF and JPG outputs are available), started handling proportional fonts to make them look nice as monospaced, completed some charset variations, integrated the configuration to PCem and fixed more printing logic bugs. Should be in a presentable state soon. :)
Attachments
Screenshot_2020-02-11_17-53-59.png
Screenshot_2020-02-11_17-53-59.png (76.98 KiB) Viewed 657 times

User avatar
omarsis81
Posts: 783
Joined: Thu 17 Dec, 2015 6:20 pm

Re: Dot-matrix printing in PCem

Post by omarsis81 » Tue 11 Feb, 2020 11:04 pm

great stuff man!

shermanp
Posts: 130
Joined: Sat 18 Feb, 2017 2:09 am

Re: Dot-matrix printing in PCem

Post by shermanp » Wed 12 Feb, 2020 2:01 am

Oh, hadn't thought about creating italics from standard fonts. Mainly because my font experience comes from the ebook sphere, and IMHO, autogenerated italics is a crime against humanity. (I had to suffer this in the early days of epub, because Adobe and/or Sony were too cheap to include italics variants)

Do you know if the printer originally included proper italics? If so, then you will want to use a proper italics truetype/opentype font as well. Autogenerated "italics" is NOT true italics.

EluanCM
Posts: 94
Joined: Tue 27 Oct, 2015 2:07 pm
Location: Brazil
Contact:

Re: Dot-matrix printing in PCem

Post by EluanCM » Wed 12 Feb, 2020 1:09 pm

I already use separate fonts for the draft styles (the code will try to load using the naming pattern from these freely redistributable fonts: http://const-iterator.de/fxmatrix/ ). Unfortunately this nice font does not have many extended characters available.

Modern Roman and Sans Serif fonts have much less variations, so some styles/modes will still have to be done by hand. I don't know how the italics are made on the printer (I've skipped the printer when dumping my ROMs!) But there is documentation on how bold, etc, are done.

I will probably just have separate normal/italics fonts for these two high quality fonts and be done with it.

Post Reply