Prevent ugly kerning when using DrawText

时间:2018-08-22 13:42:30

标签: windows winapi fonts gdi drawtext

I use simple GDI DrawText to output blocks of text to a printer.

The font used in the sample is Segoe UI. But you can use Arial or others too. It doesn't matter.

The algorithm for large text blocks is simple. DrawText is called with DT_CALCRECT with a kind of binary search for the length to get the largest possible text to print. Than DrawText is called without DT_CALCRECT to print the block.

Simple one line text column text is written with one call to DrawText with the given coordinates of the rectangle.

The result is real strange and can be seen in this sample PDF. Just look on the first line after the header. You can see the text "Test, Test" and you can see the strange kerning here perfectly. The kerning os sometimes so bad, that you can't even read the words.

How to get around this? Is it a problem with the used printer? Is it a problem with DrawText?

The distance between some chars in a word seem to be random in some case. Some spacing are wide other to narrow. The letter combination looks strange unreadable and ugly.

I tried different fonts and printers but the problem just varies but it is always present.

I know about ExTextOut and the capabilities to define the distance/kerning between all chars, but frankly I don't want to care about this. I just want that DrawText behaves on the printer like on the screen. The stuff works on the screen perfectly.

  • Added 2018-08-23 08:49 GMT+2* To the code (it is a complex printing engine).

1.Fonts to print are created simply with CFont::CreatePointFont, so the LOGFONT structure is cleared to zero and no additional flags are used except point and face.

2.The mapping mode is MM_ANISOTROPIC. To scale what is seen on the screen and what is to be printed I just use the size of a komparable object (textblock) on the printer and the same size on the screen. The real values for the sample printout to the Microsoft PDF Printer are as follows, the real way I calculate them is not of interest:

m_pDC->SetMapMode(MM_ANISOTROPIC);
m_pDC->SetViewportExt(2363,100);
m_pDC->SetWindowExt(355,13);

This has the effect that the height of a line in LPs is 13, the average character width in LPs is 6...

0 个答案:

没有答案
相关问题