BerndGabriel/HtmlViewer

Creating Metafile/EMF with japanese, korean or chinese text contains wrong rclBounds

Opened this issue · 1 comments

We are rendering HTML content into a metafile/EMF (see THtmlViewer.PrintPreview) to simple display and print them. With easy latin text or arabic characters we do not have any problems. But with japanese, korean or chinese text we went into an issue inside of the created metafile.

In general, you receive in EMRTEXTTEXTOUT a bouncing rectangle of the text (rclBounds) when you are playing it. We use this rclBounds for calculating the correct height of the text to remove unused white-area of the metafile at its end. This works fine for a lot of years we are using this component. But if the HTML contains japanese, korean or chinese text we receive an invalid rclBounds rectangle - it is only 0, 0, -1, -1 for these ExtTextOuts, so we cannot calculate the used height of the text and our playing of the metafile fails. Attached you can find the used HTML for reproducing it.
text.html.txt

It seems also calling TextOutW in HTMLSubs.pas is creating for these kind of text a lot of EMF codes like:
...
hObj[5]=CreateFont(-100,0,0,0,400,0,0,0,0,0,0,0,0,"Microsoft Sans Serif");
SelectObject(hDC, hObj[5]);
hObj[6]=CreateFont(112,0,0,0,400,0,0,0,0,0,0,0,0,"Microsoft Sans Serif");
SelectObject(hDC, hObj[6]);
SelectObject(hDC, hObj[4]);
DeleteObject(hObj[5]);
DeleteObject(hObj[6]);
hObj[6]=CreateFont(-100,0,0,0,400,0,0,0,0,0,0,0,0,"Microsoft Sans Serif");
SelectObject(hDC, hObj[6]);
hObj[5]=CreateFont(112,0,0,0,400,0,0,0,0,0,0,0,0,"Microsoft Sans Serif");
...

Maybe this could also be a problem in this direction?

It would be nice to find a solution for that. If more information are needed, please let me know and I will try to support you.

Thanks in advanced,
Daniel

@BerndGabriel Is it possible to have a short look at this behavior to classify this issue in detail?