gdiplus: Create 'const' friendly internal entries for font APIs.

This commit is contained in:
Dmitry Timoshkov 2012-05-12 15:23:12 +09:00 committed by Alexandre Julliard
parent fecde1ead8
commit 5e4d64d18e
4 changed files with 70 additions and 42 deletions

View File

@ -116,6 +116,8 @@ typedef struct
#define MS_OS2_TAG MS_MAKE_TAG('O','S','/','2')
#define MS_HHEA_TAG MS_MAKE_TAG('h','h','e','a')
static GpStatus clone_font_family(const GpFontFamily *, GpFontFamily **);
static const REAL mm_per_inch = 25.4;
static const REAL inch_per_point = 1.0/72.0;
@ -216,7 +218,7 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
(*font)->emSize = emSize;
(*font)->otm = otm;
stat = GdipCloneFontFamily((GpFontFamily *)fontFamily, &(*font)->family);
stat = clone_font_family(fontFamily, &(*font)->family);
if (stat != Ok)
{
GdipFree(*font);
@ -355,6 +357,11 @@ GpStatus WINGDIPAPI GdipGetFamily(GpFont *font, GpFontFamily **family)
return GdipCloneFontFamily(font->family, family);
}
static REAL get_font_size(const GpFont *font)
{
return font->emSize;
}
/******************************************************************************
* GdipGetFontSize [GDIPLUS.@]
*
@ -377,12 +384,30 @@ GpStatus WINGDIPAPI GdipGetFontSize(GpFont *font, REAL *size)
if (!(font && size)) return InvalidParameter;
*size = font->emSize;
*size = get_font_size(font);
TRACE("%s,%d => %f\n", debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *size);
return Ok;
}
static INT get_font_style(const GpFont *font)
{
INT style;
if (font->otm.otmTextMetrics.tmWeight > FW_REGULAR)
style = FontStyleBold;
else
style = FontStyleRegular;
if (font->otm.otmTextMetrics.tmItalic)
style |= FontStyleItalic;
if (font->otm.otmTextMetrics.tmUnderlined)
style |= FontStyleUnderline;
if (font->otm.otmTextMetrics.tmStruckOut)
style |= FontStyleStrikeout;
return style;
}
/*******************************************************************************
* GdipGetFontStyle [GDIPLUS.@]
*
@ -403,16 +428,8 @@ GpStatus WINGDIPAPI GdipGetFontStyle(GpFont *font, INT *style)
if (!(font && style))
return InvalidParameter;
if (font->otm.otmTextMetrics.tmWeight > FW_REGULAR)
*style = FontStyleBold;
else
*style = FontStyleRegular;
if (font->otm.otmTextMetrics.tmItalic)
*style |= FontStyleItalic;
if (font->otm.otmTextMetrics.tmUnderlined)
*style |= FontStyleUnderline;
if (font->otm.otmTextMetrics.tmStruckOut)
*style |= FontStyleStrikeout;
*style = get_font_style(font);
TRACE("%s,%d => %d\n", debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *style);
return Ok;
}
@ -463,6 +480,25 @@ GpStatus WINGDIPAPI GdipGetLogFontA(GpFont *font, GpGraphics *graphics,
return Ok;
}
void get_log_fontW(const GpFont *font, GpGraphics *graphics, LOGFONTW *lf)
{
/* FIXME: use graphics */
lf->lfHeight = -font->otm.otmTextMetrics.tmAscent;
lf->lfWidth = 0;
lf->lfEscapement = 0;
lf->lfOrientation = 0;
lf->lfWeight = font->otm.otmTextMetrics.tmWeight;
lf->lfItalic = font->otm.otmTextMetrics.tmItalic ? 1 : 0;
lf->lfUnderline = font->otm.otmTextMetrics.tmUnderlined ? 1 : 0;
lf->lfStrikeOut = font->otm.otmTextMetrics.tmStruckOut ? 1 : 0;
lf->lfCharSet = font->otm.otmTextMetrics.tmCharSet;
lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf->lfQuality = DEFAULT_QUALITY;
lf->lfPitchAndFamily = 0;
strcpyW(lf->lfFaceName, font->family->FamilyName);
}
/*******************************************************************************
* GdipGetLogFontW [GDIPLUS.@]
*/
@ -471,25 +507,10 @@ GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
{
TRACE("(%p, %p, %p)\n", font, graphics, lfw);
/* FIXME: use graphics */
if(!font || !graphics || !lfw)
return InvalidParameter;
lfw->lfHeight = -font->otm.otmTextMetrics.tmAscent;
lfw->lfWidth = 0;
lfw->lfEscapement = 0;
lfw->lfOrientation = 0;
lfw->lfWeight = font->otm.otmTextMetrics.tmWeight;
lfw->lfItalic = font->otm.otmTextMetrics.tmItalic ? 1 : 0;
lfw->lfUnderline = font->otm.otmTextMetrics.tmUnderlined ? 1 : 0;
lfw->lfStrikeOut = font->otm.otmTextMetrics.tmStruckOut ? 1 : 0;
lfw->lfCharSet = font->otm.otmTextMetrics.tmCharSet;
lfw->lfOutPrecision = OUT_DEFAULT_PRECIS;
lfw->lfClipPrecision = CLIP_DEFAULT_PRECIS;
lfw->lfQuality = DEFAULT_QUALITY;
lfw->lfPitchAndFamily = 0;
strcpyW(lfw->lfFaceName, font->family->FamilyName);
get_log_fontW(font, graphics, lfw);
TRACE("=> %s,%d\n", debugstr_w(lfw->lfFaceName), lfw->lfHeight);
return Ok;
@ -576,10 +597,8 @@ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi,
TRACE("%p (%s), %f, %p\n", font,
debugstr_w(font->family->FamilyName), dpi, height);
stat = GdipGetFontSize((GpFont *)font, &font_size);
if (stat != Ok) return stat;
stat = GdipGetFontStyle((GpFont *)font, &style);
if (stat != Ok) return stat;
font_size = get_font_size(font);
style = get_font_style(font);
stat = GdipGetLineSpacing(font->family, style, &line_spacing);
if (stat != Ok) return stat;
stat = GdipGetEmHeight(font->family, style, &em_height);
@ -764,6 +783,16 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
return Ok;
}
static GpStatus clone_font_family(const GpFontFamily *family, GpFontFamily **clone)
{
*clone = GdipAlloc(sizeof(GpFontFamily));
if (!*clone) return OutOfMemory;
**clone = *family;
return Ok;
}
/*******************************************************************************
* GdipCloneFontFamily [GDIPLUS.@]
*
@ -778,16 +807,15 @@ GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
*/
GpStatus WINGDIPAPI GdipCloneFontFamily(GpFontFamily* FontFamily, GpFontFamily** clonedFontFamily)
{
GpStatus status;
if (!(FontFamily && clonedFontFamily)) return InvalidParameter;
TRACE("%p (%s), %p\n", FontFamily,
debugstr_w(FontFamily->FamilyName), clonedFontFamily);
*clonedFontFamily = GdipAlloc(sizeof(GpFontFamily));
if (!*clonedFontFamily) return OutOfMemory;
**clonedFontFamily = *FontFamily;
lstrcpyW((*clonedFontFamily)->FamilyName, FontFamily->FamilyName);
status = clone_font_family(FontFamily, clonedFontFamily);
if (status != Ok) return status;
TRACE("<-- %p\n", *clonedFontFamily);

View File

@ -436,4 +436,6 @@ GpStatus gdip_format_string(HDC hdc,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
#endif

View File

@ -2136,7 +2136,7 @@ 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)+
(pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
GdipGetLogFontW((GpFont *)font, graphics, &lfw);
get_log_fontW(font, graphics, &lfw);
lfw.lfHeight = roundr(lfw.lfHeight * rel_height);
unscaled_font = CreateFontIndirectW(&lfw);
@ -4931,8 +4931,7 @@ GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
if (regionCount < stringFormat->range_count)
return InvalidParameter;
stat = GdipGetLogFontW((GpFont *)font, graphics, &lfw);
if (stat != Ok) return stat;
get_log_fontW(font, graphics, &lfw);
if(!graphics->hdc)
{

View File

@ -957,8 +957,7 @@ GpStatus WINGDIPAPI GdipAddPathString(GpPath* path, GDIPCONST WCHAR* string, INT
if (status != Ok)
return status;
status = GdipGetLogFontW((GpFont *)font, NULL, &lfw);
if (status != Ok) return status;
get_log_fontW(font, NULL, &lfw);
hfont = CreateFontIndirectW(&lfw);
if (!hfont)
{