gdiplus: Don't settle on a font size until absolutely necessary.
When we create a new font, we should store its height in a REAL field so we don't have to round it. Further, when we calculate the width, we should base the calculation on the metrics of a font at the height we will use, to prevent rounding errors when the graphics transform will enlarge the font.
This commit is contained in:
parent
be0af56be3
commit
11f0662c60
|
@ -126,27 +126,27 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
|
||||||
{
|
{
|
||||||
case UnitWorld:
|
case UnitWorld:
|
||||||
/* FIXME: Figure out when World != Pixel */
|
/* FIXME: Figure out when World != Pixel */
|
||||||
lfw->lfHeight = emSize; break;
|
(*font)->pixel_size = emSize; break;
|
||||||
case UnitDisplay:
|
case UnitDisplay:
|
||||||
FIXME("Unknown behavior for UnitDisplay! Please report!\n");
|
FIXME("Unknown behavior for UnitDisplay! Please report!\n");
|
||||||
/* FIXME: Figure out how this works...
|
/* FIXME: Figure out how this works...
|
||||||
* MSDN says that if "DISPLAY" is a monitor, then pixel should be
|
* MSDN says that if "DISPLAY" is a monitor, then pixel should be
|
||||||
* used. That's not what I got. Tests on Windows revealed no output,
|
* used. That's not what I got. Tests on Windows revealed no output,
|
||||||
* and the tests in tests/font crash windows */
|
* and the tests in tests/font crash windows */
|
||||||
lfw->lfHeight = 0; break;
|
(*font)->pixel_size = 0; break;
|
||||||
case UnitPixel:
|
case UnitPixel:
|
||||||
lfw->lfHeight = emSize; break;
|
(*font)->pixel_size = emSize; break;
|
||||||
case UnitPoint:
|
case UnitPoint:
|
||||||
lfw->lfHeight = point_to_pixel(emSize); break;
|
(*font)->pixel_size = point_to_pixel(emSize); break;
|
||||||
case UnitInch:
|
case UnitInch:
|
||||||
lfw->lfHeight = inch_to_pixel(emSize); break;
|
(*font)->pixel_size = inch_to_pixel(emSize); break;
|
||||||
case UnitDocument:
|
case UnitDocument:
|
||||||
lfw->lfHeight = document_to_pixel(emSize); break;
|
(*font)->pixel_size = document_to_pixel(emSize); break;
|
||||||
case UnitMillimeter:
|
case UnitMillimeter:
|
||||||
lfw->lfHeight = mm_to_pixel(emSize); break;
|
(*font)->pixel_size = mm_to_pixel(emSize); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfw->lfHeight *= -1;
|
lfw->lfHeight = (*font)->pixel_size * -1;
|
||||||
|
|
||||||
lfw->lfWeight = style & FontStyleBold ? 700 : 400;
|
lfw->lfWeight = style & FontStyleBold ? 700 : 400;
|
||||||
lfw->lfItalic = style & FontStyleItalic;
|
lfw->lfItalic = style & FontStyleItalic;
|
||||||
|
@ -190,7 +190,7 @@ GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
|
||||||
(*font)->lfw.lfUnderline = logfont->lfUnderline;
|
(*font)->lfw.lfUnderline = logfont->lfUnderline;
|
||||||
(*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
|
(*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
|
||||||
|
|
||||||
(*font)->emSize = logfont->lfHeight;
|
(*font)->pixel_size = (*font)->emSize = logfont->lfHeight;
|
||||||
(*font)->unit = UnitPixel;
|
(*font)->unit = UnitPixel;
|
||||||
|
|
||||||
hfont = CreateFontIndirectW(&(*font)->lfw);
|
hfont = CreateFontIndirectW(&(*font)->lfw);
|
||||||
|
|
|
@ -323,6 +323,7 @@ struct GpImageAttributes{
|
||||||
struct GpFont{
|
struct GpFont{
|
||||||
LOGFONTW lfw;
|
LOGFONTW lfw;
|
||||||
REAL emSize;
|
REAL emSize;
|
||||||
|
REAL pixel_size;
|
||||||
UINT height;
|
UINT height;
|
||||||
LONG line_spacing;
|
LONG line_spacing;
|
||||||
Unit unit;
|
Unit unit;
|
||||||
|
|
|
@ -1677,14 +1677,16 @@ void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, HFONT *hfont)
|
||||||
rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
|
rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
|
||||||
(pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
|
(pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
|
||||||
|
|
||||||
unscaled_font = CreateFontIndirectW(&font->lfw);
|
lfw = font->lfw;
|
||||||
|
lfw.lfHeight = roundr(-font->pixel_size * rel_height);
|
||||||
|
unscaled_font = CreateFontIndirectW(&lfw);
|
||||||
|
|
||||||
SelectObject(hdc, unscaled_font);
|
SelectObject(hdc, unscaled_font);
|
||||||
GetTextMetricsW(hdc, &textmet);
|
GetTextMetricsW(hdc, &textmet);
|
||||||
|
|
||||||
lfw = font->lfw;
|
lfw = font->lfw;
|
||||||
lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
|
lfw.lfHeight = roundr(-font->pixel_size * rel_height);
|
||||||
lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
|
lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width / rel_height);
|
||||||
lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
|
lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
|
||||||
|
|
||||||
*hfont = CreateFontIndirectW(&lfw);
|
*hfont = CreateFontIndirectW(&lfw);
|
||||||
|
|
Loading…
Reference in New Issue