Board index » delphi » Char by char WYSIWYG output

Char by char WYSIWYG output

I already posted this question in WinAPI newsgroup but there was no
response, so I decided to give this group a try.

Could someone explain to me what would be the best (and I mean
THE best) way to precisely output characters to a DC so that the text would
look the same on screen and printer.

What I'm looking for is a way to output text in a character-by-character
way, so that the result would be the same as if I output the string as a
whole.

Currently, I'm using GetCharABCWidthsFloat, GetKerningPairs and TextOut APIs
to accomplish the task.
The problem is, however, that char-by-char output doesn't match the string
output. Some of the character pairs are too far apart. This happens
regardless of kerning.

I'm using very high "virtual" resolution for calculations and then rounding
down to the actual DC resolution to achieve WYSIWYG. But with some
characters, the returned and rounded width is somewhat off which results in
undesired gaps in words.

If I make a comparison between a string output char-by-char and the same
string output as a whole, there is a noticable difference in widths.

How can I overcome this? I thought I was doing everything right...

Regards, Aleksander

 

Re:Char by char WYSIWYG output


Hi Aleksander,

I'm using the code from Feng Yuan's book "Windows Graphics" with my own
modifications to meet my needs. Its written in clean C++ so its not too
difficult to convert. It uses GetOutlineTextMetrics to find the
EM-Square size and uses that for sizing purposes. It also requires using
a logical pixel size.

function PointSizetoLogical ;
var
   P : array [0..1] of TPoint ;
begin
   p[0] := Point ( 0 , 0 ) ;
   P[1] := Point ( 0 , GetDeviceCaps ( dc , LOGPIXELSY ) * points ) ;
   DPtoLP ( dc , p , 2 ) ;
   result := abs ( P[1].y - P[0].Y ) div 72 div divisor ;
end ;

It works well for my purposes. Get the book, its well worth it.

Mitch Wolberg,
RockWare, Inc.

Quote
Aleksander Oven wrote:
> Hi!

> I already posted this question in WinAPI newsgroup but there was no
> response, so I decided to give this group a try.

> Could someone explain to me what would be the best (and I mean
> THE best) way to precisely output characters to a DC so that the text would
> look the same on screen and printer.

> What I'm looking for is a way to output text in a character-by-character
> way, so that the result would be the same as if I output the string as a
> whole.

> Currently, I'm using GetCharABCWidthsFloat, GetKerningPairs and TextOut APIs
> to accomplish the task.
> The problem is, however, that char-by-char output doesn't match the string
> output. Some of the character pairs are too far apart. This happens
> regardless of kerning.

> I'm using very high "virtual" resolution for calculations and then rounding
> down to the actual DC resolution to achieve WYSIWYG. But with some
> characters, the returned and rounded width is somewhat off which results in
> undesired gaps in words.

> If I make a comparison between a string output char-by-char and the same
> string output as a whole, there is a noticable difference in widths.

> How can I overcome this? I thought I was doing everything right...

> Regards, Aleksander

Other Threads