2007-08-14 03:34:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2007-08-14 03:34:57 +02:00
|
|
|
#include "winnls.h"
|
2008-06-21 19:02:53 +02:00
|
|
|
#include "winreg.h"
|
2008-06-21 19:02:47 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL (gdiplus);
|
2007-08-14 03:34:51 +02:00
|
|
|
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "gdiplus_private.h"
|
|
|
|
|
2008-06-28 02:06:24 +02:00
|
|
|
static const REAL mm_per_inch = 25.4;
|
|
|
|
static const REAL inch_per_point = 1.0/72.0;
|
2008-06-21 19:02:53 +02:00
|
|
|
|
2009-04-27 23:24:47 +02:00
|
|
|
static GpFontCollection installedFontCollection = {0};
|
|
|
|
|
2008-06-21 19:02:53 +02:00
|
|
|
static inline REAL get_dpi (void)
|
|
|
|
{
|
|
|
|
REAL dpi;
|
|
|
|
GpGraphics *graphics;
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
GdipCreateFromHDC (hdc, &graphics);
|
|
|
|
GdipGetDpiX(graphics, &dpi);
|
2008-06-26 22:13:29 +02:00
|
|
|
GdipDeleteGraphics(graphics);
|
2008-06-21 19:02:53 +02:00
|
|
|
ReleaseDC (0, hdc);
|
|
|
|
|
|
|
|
return dpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline REAL point_to_pixel (REAL point)
|
|
|
|
{
|
2008-06-28 02:06:24 +02:00
|
|
|
return point * get_dpi() * inch_per_point;
|
2008-06-21 19:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline REAL inch_to_pixel (REAL inch)
|
|
|
|
{
|
|
|
|
return inch * get_dpi();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline REAL document_to_pixel (REAL doc)
|
|
|
|
{
|
|
|
|
return doc * (get_dpi() / 300.0); /* Per MSDN */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline REAL mm_to_pixel (REAL mm)
|
|
|
|
{
|
2008-06-28 02:06:24 +02:00
|
|
|
return mm * (get_dpi() / mm_per_inch);
|
2008-06-21 19:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCreateFont [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Create a new font based off of a FontFamily
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* *fontFamily [I] Family to base the font off of
|
|
|
|
* emSize [I] Size of the font
|
|
|
|
* style [I] Bitwise OR of FontStyle enumeration
|
|
|
|
* unit [I] Unit emSize is measured in
|
|
|
|
* **font [I] the resulting Font object
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter if fontfamily or font is NULL.
|
|
|
|
* FAILURE: FontFamilyNotFound if an invalid FontFamily is given
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* UnitDisplay is unsupported.
|
|
|
|
* emSize is stored separately from lfHeight, to hold the fraction.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
|
|
|
|
REAL emSize, INT style, Unit unit, GpFont **font)
|
|
|
|
{
|
|
|
|
WCHAR facename[LF_FACESIZE];
|
|
|
|
LOGFONTW* lfw;
|
2008-07-03 20:26:50 +02:00
|
|
|
const NEWTEXTMETRICW* tmw;
|
2008-06-21 19:02:53 +02:00
|
|
|
GpStatus stat;
|
|
|
|
|
2008-07-07 14:53:10 +02:00
|
|
|
if (!fontFamily || !font)
|
2008-06-21 19:02:53 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
TRACE("%p (%s), %f, %d, %d, %p\n", fontFamily,
|
|
|
|
debugstr_w(fontFamily->FamilyName), emSize, style, unit, font);
|
|
|
|
|
|
|
|
stat = GdipGetFamilyName (fontFamily, facename, 0);
|
|
|
|
if (stat != Ok) return stat;
|
|
|
|
*font = GdipAlloc(sizeof(GpFont));
|
|
|
|
|
2008-06-26 22:25:28 +02:00
|
|
|
tmw = &fontFamily->tmw;
|
2008-06-21 19:02:53 +02:00
|
|
|
lfw = &((*font)->lfw);
|
|
|
|
ZeroMemory(&(*lfw), sizeof(*lfw));
|
|
|
|
|
|
|
|
lfw->lfWeight = tmw->tmWeight;
|
|
|
|
lfw->lfItalic = tmw->tmItalic;
|
|
|
|
lfw->lfUnderline = tmw->tmUnderlined;
|
|
|
|
lfw->lfStrikeOut = tmw->tmStruckOut;
|
|
|
|
lfw->lfCharSet = tmw->tmCharSet;
|
|
|
|
lfw->lfPitchAndFamily = tmw->tmPitchAndFamily;
|
2008-07-07 14:53:10 +02:00
|
|
|
lstrcpynW(lfw->lfFaceName, facename, LF_FACESIZE);
|
2008-06-21 19:02:53 +02:00
|
|
|
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case UnitWorld:
|
|
|
|
/* FIXME: Figure out when World != Pixel */
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = emSize; break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitDisplay:
|
|
|
|
FIXME("Unknown behavior for UnitDisplay! Please report!\n");
|
|
|
|
/* FIXME: Figure out how this works...
|
|
|
|
* 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,
|
|
|
|
* and the tests in tests/font crash windows */
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = 0; break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitPixel:
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = emSize; break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitPoint:
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = point_to_pixel(emSize); break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitInch:
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = inch_to_pixel(emSize); break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitDocument:
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = document_to_pixel(emSize); break;
|
2008-06-21 19:02:53 +02:00
|
|
|
case UnitMillimeter:
|
2011-04-05 00:18:23 +02:00
|
|
|
(*font)->pixel_size = mm_to_pixel(emSize); break;
|
2008-06-21 19:02:53 +02:00
|
|
|
}
|
|
|
|
|
2011-04-05 00:18:23 +02:00
|
|
|
lfw->lfHeight = (*font)->pixel_size * -1;
|
2008-06-21 19:02:53 +02:00
|
|
|
|
|
|
|
lfw->lfWeight = style & FontStyleBold ? 700 : 400;
|
|
|
|
lfw->lfItalic = style & FontStyleItalic;
|
|
|
|
lfw->lfUnderline = style & FontStyleUnderline;
|
|
|
|
lfw->lfStrikeOut = style & FontStyleStrikeout;
|
|
|
|
|
|
|
|
(*font)->unit = unit;
|
|
|
|
(*font)->emSize = emSize;
|
2008-11-28 17:30:48 +01:00
|
|
|
(*font)->height = tmw->ntmSizeEM;
|
|
|
|
(*font)->line_spacing = tmw->tmAscent + tmw->tmDescent + tmw->tmExternalLeading;
|
2008-06-21 19:02:53 +02:00
|
|
|
|
2009-12-18 22:04:56 +01:00
|
|
|
TRACE("<-- %p\n", *font);
|
|
|
|
|
2008-06-21 19:02:53 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCreateFontFromLogfontW [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-14 03:34:51 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
|
|
|
|
GDIPCONST LOGFONTW *logfont, GpFont **font)
|
|
|
|
{
|
2007-08-15 03:59:08 +02:00
|
|
|
HFONT hfont, oldfont;
|
|
|
|
TEXTMETRICW textmet;
|
|
|
|
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", hdc, logfont, font);
|
|
|
|
|
2007-08-14 03:34:51 +02:00
|
|
|
if(!logfont || !font)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-08-27 23:22:12 +02:00
|
|
|
if (logfont->lfFaceName[0] == 0)
|
|
|
|
return NotTrueTypeFont;
|
|
|
|
|
2007-08-14 03:34:51 +02:00
|
|
|
*font = GdipAlloc(sizeof(GpFont));
|
|
|
|
if(!*font) return OutOfMemory;
|
|
|
|
|
2008-07-11 00:08:52 +02:00
|
|
|
memcpy((*font)->lfw.lfFaceName, logfont->lfFaceName, LF_FACESIZE *
|
2007-08-15 03:59:08 +02:00
|
|
|
sizeof(WCHAR));
|
|
|
|
(*font)->lfw.lfHeight = logfont->lfHeight;
|
2007-08-15 03:59:35 +02:00
|
|
|
(*font)->lfw.lfItalic = logfont->lfItalic;
|
|
|
|
(*font)->lfw.lfUnderline = logfont->lfUnderline;
|
|
|
|
(*font)->lfw.lfStrikeOut = logfont->lfStrikeOut;
|
2007-08-15 03:59:08 +02:00
|
|
|
|
|
|
|
hfont = CreateFontIndirectW(&(*font)->lfw);
|
|
|
|
oldfont = SelectObject(hdc, hfont);
|
|
|
|
GetTextMetricsW(hdc, &textmet);
|
|
|
|
|
2009-05-01 18:09:23 +02:00
|
|
|
(*font)->lfw.lfHeight = -(textmet.tmHeight-textmet.tmInternalLeading);
|
2007-08-15 03:59:08 +02:00
|
|
|
(*font)->lfw.lfWeight = textmet.tmWeight;
|
2008-12-16 03:10:48 +01:00
|
|
|
(*font)->lfw.lfCharSet = textmet.tmCharSet;
|
2007-08-15 03:59:08 +02:00
|
|
|
|
2012-04-19 14:43:51 +02:00
|
|
|
(*font)->pixel_size = (*font)->emSize = textmet.tmHeight;
|
|
|
|
(*font)->unit = UnitPixel;
|
2008-11-28 17:30:48 +01:00
|
|
|
(*font)->height = 1; /* FIXME: need NEWTEXTMETRIC.ntmSizeEM here */
|
|
|
|
(*font)->line_spacing = textmet.tmAscent + textmet.tmDescent + textmet.tmExternalLeading;
|
|
|
|
|
2007-08-15 03:59:08 +02:00
|
|
|
SelectObject(hdc, oldfont);
|
|
|
|
DeleteObject(hfont);
|
2007-08-14 03:34:51 +02:00
|
|
|
|
2009-12-18 22:04:56 +01:00
|
|
|
TRACE("<-- %p\n", *font);
|
|
|
|
|
2007-08-14 03:34:51 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
2007-08-14 03:34:57 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCreateFontFromLogfontA [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-14 03:34:57 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateFontFromLogfontA(HDC hdc,
|
|
|
|
GDIPCONST LOGFONTA *lfa, GpFont **font)
|
|
|
|
{
|
|
|
|
LOGFONTW lfw;
|
|
|
|
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", hdc, lfa, font);
|
|
|
|
|
2007-08-14 03:34:57 +02:00
|
|
|
if(!lfa || !font)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-05-12 23:46:46 +02:00
|
|
|
memcpy(&lfw, lfa, FIELD_OFFSET(LOGFONTA,lfFaceName) );
|
2007-08-14 03:34:57 +02:00
|
|
|
|
|
|
|
if(!MultiByteToWideChar(CP_ACP, 0, lfa->lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE))
|
|
|
|
return GenericError;
|
|
|
|
|
2009-04-23 21:20:11 +02:00
|
|
|
return GdipCreateFontFromLogfontW(hdc, &lfw, font);
|
2007-08-14 03:34:57 +02:00
|
|
|
}
|
2007-08-15 03:58:52 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipDeleteFont [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-15 03:59:15 +02:00
|
|
|
GpStatus WINGDIPAPI GdipDeleteFont(GpFont* font)
|
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p)\n", font);
|
|
|
|
|
2007-08-15 03:59:15 +02:00
|
|
|
if(!font)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
GdipFree(font);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCreateFontFromDC [GDIPLUS.@]
|
|
|
|
*/
|
2008-04-30 16:19:42 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateFontFromDC(HDC hdc, GpFont **font)
|
|
|
|
{
|
|
|
|
HFONT hfont;
|
|
|
|
LOGFONTW lfw;
|
|
|
|
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p)\n", hdc, font);
|
|
|
|
|
2008-04-30 16:19:42 +02:00
|
|
|
if(!font)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-12-05 07:53:04 +01:00
|
|
|
hfont = GetCurrentObject(hdc, OBJ_FONT);
|
2008-04-30 16:19:42 +02:00
|
|
|
if(!hfont)
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
if(!GetObjectW(hfont, sizeof(LOGFONTW), &lfw))
|
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
return GdipCreateFontFromLogfontW(hdc, &lfw, font);
|
|
|
|
}
|
|
|
|
|
2008-08-27 23:21:34 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFamily [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Returns the FontFamily for the specified Font
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* font [I] Font to request from
|
|
|
|
* family [O] Resulting FontFamily object
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: An element of GpStatus
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFamily(GpFont *font, GpFontFamily **family)
|
|
|
|
{
|
2008-08-27 23:21:56 +02:00
|
|
|
TRACE("%p %p\n", font, family);
|
2008-08-27 23:21:34 +02:00
|
|
|
|
2008-08-27 23:21:56 +02:00
|
|
|
if (!(font && family))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return GdipCreateFontFamilyFromName(font->lfw.lfFaceName, NULL, family);
|
2008-08-27 23:21:34 +02:00
|
|
|
}
|
|
|
|
|
2008-06-21 19:02:55 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GdipGetFontSize [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Returns the size of the font in Units
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* *font [I] The font to retrieve size from
|
|
|
|
* *size [O] Pointer to hold retrieved value
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
2009-04-20 14:47:23 +02:00
|
|
|
* FAILURE: InvalidParameter (font or size was NULL)
|
2008-06-21 19:02:55 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Size returned is actually emSize -- not internal size used for drawing.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFontSize(GpFont *font, REAL *size)
|
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p)\n", font, size);
|
|
|
|
|
2008-06-21 19:02:55 +02:00
|
|
|
if (!(font && size)) return InvalidParameter;
|
|
|
|
|
|
|
|
*size = font->emSize;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-08-27 23:22:00 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFontStyle [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Gets the font's style, returned in bitwise OR of FontStyle enumeration
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* font [I] font to request from
|
|
|
|
* style [O] resulting pointer to a FontStyle enumeration
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter
|
|
|
|
*/
|
2008-08-27 23:21:39 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetFontStyle(GpFont *font, INT *style)
|
|
|
|
{
|
2008-08-27 23:22:00 +02:00
|
|
|
TRACE("%p %p\n", font, style);
|
|
|
|
|
|
|
|
if (!(font && style))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (font->lfw.lfWeight > 400)
|
|
|
|
*style = FontStyleBold;
|
|
|
|
else
|
|
|
|
*style = 0;
|
|
|
|
if (font->lfw.lfItalic)
|
|
|
|
*style |= FontStyleItalic;
|
|
|
|
if (font->lfw.lfUnderline)
|
|
|
|
*style |= FontStyleUnderline;
|
|
|
|
if (font->lfw.lfStrikeOut)
|
|
|
|
*style |= FontStyleStrikeout;
|
2008-08-27 23:21:39 +02:00
|
|
|
|
2008-08-27 23:22:00 +02:00
|
|
|
return Ok;
|
2008-08-27 23:21:39 +02:00
|
|
|
}
|
|
|
|
|
2008-06-21 19:02:54 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFontUnit [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* font [I] Font to retrieve from
|
|
|
|
* unit [O] Return value
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* FAILURE: font or unit was NULL
|
|
|
|
* OK: otherwise
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFontUnit(GpFont *font, Unit *unit)
|
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p)\n", font, unit);
|
|
|
|
|
2008-06-21 19:02:54 +02:00
|
|
|
if (!(font && unit)) return InvalidParameter;
|
|
|
|
|
|
|
|
*unit = font->unit;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2009-02-04 09:57:04 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetLogFontA [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetLogFontA(GpFont *font, GpGraphics *graphics,
|
|
|
|
LOGFONTA *lfa)
|
|
|
|
{
|
|
|
|
GpStatus status;
|
|
|
|
LOGFONTW lfw;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", font, graphics, lfa);
|
|
|
|
|
|
|
|
status = GdipGetLogFontW(font, graphics, &lfw);
|
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
memcpy(lfa, &lfw, FIELD_OFFSET(LOGFONTA,lfFaceName) );
|
|
|
|
|
2009-04-23 21:24:54 +02:00
|
|
|
if(!WideCharToMultiByte(CP_ACP, 0, lfw.lfFaceName, -1, lfa->lfFaceName, LF_FACESIZE, NULL, NULL))
|
2009-02-04 09:57:04 +01:00
|
|
|
return GenericError;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetLogFontW [GDIPLUS.@]
|
|
|
|
*/
|
2007-08-15 03:58:52 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics,
|
|
|
|
LOGFONTW *lfw)
|
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", font, graphics, lfw);
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/* FIXME: use graphics */
|
2007-08-15 03:58:52 +02:00
|
|
|
if(!font || !graphics || !lfw)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-02-29 23:06:47 +01:00
|
|
|
*lfw = font->lfw;
|
2007-08-15 03:58:52 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-04-22 23:12:59 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCloneFont [GDIPLUS.@]
|
|
|
|
*/
|
2008-04-22 23:12:59 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCloneFont(GpFont *font, GpFont **cloneFont)
|
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %p)\n", font, cloneFont);
|
|
|
|
|
2008-04-22 23:12:59 +02:00
|
|
|
if(!font || !cloneFont)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*cloneFont = GdipAlloc(sizeof(GpFont));
|
|
|
|
if(!*cloneFont) return OutOfMemory;
|
|
|
|
|
|
|
|
**cloneFont = *font;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-06-21 19:02:47 +02:00
|
|
|
|
2008-08-27 23:22:04 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFontHeight [GDIPLUS.@]
|
|
|
|
* PARAMS
|
|
|
|
* font [I] Font to retrieve height from
|
|
|
|
* graphics [I] The current graphics context
|
|
|
|
* height [O] Resulting height
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: Another element of GpStatus
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Forwards to GdipGetFontHeightGivenDPI
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFontHeight(GDIPCONST GpFont *font,
|
|
|
|
GDIPCONST GpGraphics *graphics, REAL *height)
|
|
|
|
{
|
|
|
|
REAL dpi;
|
2010-10-30 20:19:48 +02:00
|
|
|
GpStatus stat;
|
2008-08-27 23:22:04 +02:00
|
|
|
|
|
|
|
TRACE("%p %p %p\n", font, graphics, height);
|
|
|
|
|
2010-10-30 20:19:48 +02:00
|
|
|
stat = GdipGetDpiY((GpGraphics*)graphics, &dpi);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
stat = GdipGetFontHeightGivenDPI(font, dpi, height);
|
2008-08-27 23:22:04 +02:00
|
|
|
|
2010-10-30 20:19:48 +02:00
|
|
|
return stat;
|
2008-08-27 23:22:04 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 20:26:41 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFontHeightGivenDPI [GDIPLUS.@]
|
|
|
|
* PARAMS
|
|
|
|
* font [I] Font to retrieve DPI from
|
|
|
|
* dpi [I] DPI to assume
|
|
|
|
* height [O] Return value
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter if font or height is NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
|
|
|
|
* (for anything other than unit Pixel)
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
|
|
|
|
{
|
2008-11-28 17:30:48 +01:00
|
|
|
REAL font_height;
|
|
|
|
|
2008-08-27 23:22:22 +02:00
|
|
|
TRACE("%p (%s), %f, %p\n", font,
|
|
|
|
debugstr_w(font->lfw.lfFaceName), dpi, height);
|
|
|
|
|
2008-07-03 20:26:41 +02:00
|
|
|
if (!(font && height)) return InvalidParameter;
|
|
|
|
|
2008-11-28 17:30:48 +01:00
|
|
|
font_height = font->line_spacing * (font->emSize / font->height);
|
|
|
|
|
2008-08-27 23:22:22 +02:00
|
|
|
switch (font->unit)
|
|
|
|
{
|
|
|
|
case UnitPixel:
|
2010-03-26 01:27:21 +01:00
|
|
|
case UnitWorld:
|
2008-11-28 17:30:48 +01:00
|
|
|
*height = font_height;
|
|
|
|
break;
|
|
|
|
case UnitPoint:
|
|
|
|
*height = font_height * dpi * inch_per_point;
|
|
|
|
break;
|
|
|
|
case UnitInch:
|
|
|
|
*height = font_height * dpi;
|
|
|
|
break;
|
|
|
|
case UnitDocument:
|
|
|
|
*height = font_height * (dpi / 300.0);
|
|
|
|
break;
|
|
|
|
case UnitMillimeter:
|
|
|
|
*height = font_height * (dpi / mm_per_inch);
|
2008-08-27 23:22:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled unit type: %d\n", font->unit);
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2008-07-03 20:26:41 +02:00
|
|
|
|
2008-08-27 23:22:22 +02:00
|
|
|
return Ok;
|
2008-07-03 20:26:41 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 20:26:50 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Borrowed from GDI32:
|
|
|
|
*
|
|
|
|
* Elf is really an ENUMLOGFONTEXW, and ntm is a NEWTEXTMETRICEXW.
|
|
|
|
* We have to use other types because of the FONTENUMPROCW definition.
|
|
|
|
*/
|
2008-06-21 19:02:47 +02:00
|
|
|
static INT CALLBACK is_font_installed_proc(const LOGFONTW *elf,
|
|
|
|
const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
|
|
|
|
{
|
2010-04-15 18:49:20 +02:00
|
|
|
if (!ntm || type == RASTER_FONTTYPE)
|
2008-07-03 20:26:50 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(NEWTEXTMETRICW*)lParam = *(const NEWTEXTMETRICW*)ntm;
|
|
|
|
|
2008-06-21 19:02:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-03 20:26:50 +02:00
|
|
|
static BOOL find_installed_font(const WCHAR *name, NEWTEXTMETRICW *ntm)
|
2008-06-21 19:02:47 +02:00
|
|
|
{
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2008-07-03 20:26:50 +02:00
|
|
|
if(!EnumFontFamiliesW(hdc, name, is_font_installed_proc, (LPARAM)ntm))
|
2008-06-21 19:02:47 +02:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCreateFontFamilyFromName [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Creates a font family object based on a supplied name
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* name [I] Name of the font
|
|
|
|
* fontCollection [I] What font collection (if any) the font belongs to (may be NULL)
|
|
|
|
* FontFamily [O] Pointer to the resulting FontFamily object
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: FamilyNotFound if the requested FontFamily does not exist on the system
|
|
|
|
* FAILURE: Invalid parameter if FontFamily or name is NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If fontCollection is NULL then the object is not part of any collection
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipCreateFontFamilyFromName(GDIPCONST WCHAR *name,
|
|
|
|
GpFontCollection *fontCollection,
|
|
|
|
GpFontFamily **FontFamily)
|
|
|
|
{
|
|
|
|
GpFontFamily* ffamily;
|
2008-07-03 20:26:50 +02:00
|
|
|
NEWTEXTMETRICW ntm;
|
2008-06-21 19:02:47 +02:00
|
|
|
|
|
|
|
TRACE("%s, %p %p\n", debugstr_w(name), fontCollection, FontFamily);
|
|
|
|
|
|
|
|
if (!(name && FontFamily))
|
|
|
|
return InvalidParameter;
|
|
|
|
if (fontCollection)
|
|
|
|
FIXME("No support for FontCollections yet!\n");
|
2008-07-03 20:26:50 +02:00
|
|
|
|
|
|
|
if (!find_installed_font(name, &ntm))
|
2008-06-21 19:02:47 +02:00
|
|
|
return FontFamilyNotFound;
|
|
|
|
|
|
|
|
ffamily = GdipAlloc(sizeof (GpFontFamily));
|
|
|
|
if (!ffamily) return OutOfMemory;
|
|
|
|
|
2008-07-03 20:26:50 +02:00
|
|
|
ffamily->tmw = ntm;
|
2008-07-07 14:53:10 +02:00
|
|
|
lstrcpynW(ffamily->FamilyName, name, LF_FACESIZE);
|
2008-06-21 19:02:47 +02:00
|
|
|
|
|
|
|
*FontFamily = ffamily;
|
|
|
|
|
2009-12-18 22:04:56 +01:00
|
|
|
TRACE("<-- %p\n", ffamily);
|
|
|
|
|
2008-06-21 19:02:47 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
2008-06-21 19:02:48 +02:00
|
|
|
|
2008-07-03 20:26:06 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipCloneFontFamily [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Creates a deep copy of a Font Family object
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* FontFamily [I] Font to clone
|
|
|
|
* clonedFontFamily [O] The resulting cloned font
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipCloneFontFamily(GpFontFamily* FontFamily, GpFontFamily** clonedFontFamily)
|
|
|
|
{
|
|
|
|
if (!(FontFamily && clonedFontFamily)) return InvalidParameter;
|
|
|
|
|
2008-07-03 20:26:22 +02:00
|
|
|
TRACE("stub: %p (%s), %p\n", FontFamily,
|
2008-07-03 20:26:06 +02:00
|
|
|
debugstr_w(FontFamily->FamilyName), clonedFontFamily);
|
|
|
|
|
2008-07-03 20:26:22 +02:00
|
|
|
*clonedFontFamily = GdipAlloc(sizeof(GpFontFamily));
|
|
|
|
if (!*clonedFontFamily) return OutOfMemory;
|
|
|
|
|
2008-07-07 14:53:10 +02:00
|
|
|
(*clonedFontFamily)->tmw = FontFamily->tmw;
|
|
|
|
lstrcpyW((*clonedFontFamily)->FamilyName, FontFamily->FamilyName);
|
2008-07-03 20:26:22 +02:00
|
|
|
|
2009-12-18 22:04:56 +01:00
|
|
|
TRACE("<-- %p\n", *clonedFontFamily);
|
|
|
|
|
2008-07-03 20:26:22 +02:00
|
|
|
return Ok;
|
2008-07-03 20:26:06 +02:00
|
|
|
}
|
|
|
|
|
2008-06-21 19:02:49 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetFamilyName [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Returns the family name into name
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* *family [I] Family to retrieve from
|
|
|
|
* *name [O] WCHARS of the family name
|
|
|
|
* LANGID [I] charset
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter if family is NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If name is a NULL ptr, then both XP and Vista will crash (so we do as well)
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetFamilyName (GDIPCONST GpFontFamily *family,
|
|
|
|
WCHAR *name, LANGID language)
|
|
|
|
{
|
2010-04-09 17:34:52 +02:00
|
|
|
static int lang_fixme;
|
|
|
|
|
2008-06-21 19:02:49 +02:00
|
|
|
if (family == NULL)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
TRACE("%p, %p, %d\n", family, name, language);
|
|
|
|
|
2010-04-09 17:34:52 +02:00
|
|
|
if (language != LANG_NEUTRAL && !lang_fixme++)
|
2008-06-21 19:02:49 +02:00
|
|
|
FIXME("No support for handling of multiple languages!\n");
|
|
|
|
|
|
|
|
lstrcpynW (name, family->FamilyName, LF_FACESIZE);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-06-21 19:02:48 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipDeleteFontFamily [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Removes the specified FontFamily
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* *FontFamily [I] The family to delete
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter if FontFamily is NULL.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipDeleteFontFamily(GpFontFamily *FontFamily)
|
|
|
|
{
|
|
|
|
if (!FontFamily)
|
|
|
|
return InvalidParameter;
|
|
|
|
TRACE("Deleting %p (%s)\n", FontFamily, debugstr_w(FontFamily->FamilyName));
|
|
|
|
|
|
|
|
GdipFree (FontFamily);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-06-21 19:02:50 +02:00
|
|
|
|
2008-07-03 20:26:53 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetCellAscent(GDIPCONST GpFontFamily *family,
|
|
|
|
INT style, UINT16* CellAscent)
|
2008-07-03 20:26:33 +02:00
|
|
|
{
|
|
|
|
if (!(family && CellAscent)) return InvalidParameter;
|
|
|
|
|
2008-07-03 20:26:53 +02:00
|
|
|
*CellAscent = family->tmw.tmAscent;
|
2008-07-03 20:26:33 +02:00
|
|
|
|
2008-07-03 20:26:53 +02:00
|
|
|
return Ok;
|
2008-07-03 20:26:33 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 20:26:57 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetCellDescent(GDIPCONST GpFontFamily *family,
|
|
|
|
INT style, UINT16* CellDescent)
|
2008-07-03 20:26:37 +02:00
|
|
|
{
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p, %d, %p)\n", family, style, CellDescent);
|
|
|
|
|
2008-07-03 20:26:37 +02:00
|
|
|
if (!(family && CellDescent)) return InvalidParameter;
|
|
|
|
|
2008-07-03 20:26:57 +02:00
|
|
|
*CellDescent = family->tmw.tmDescent;
|
2008-07-03 20:26:37 +02:00
|
|
|
|
2008-07-03 20:26:57 +02:00
|
|
|
return Ok;
|
2008-07-03 20:26:37 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 20:26:30 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetEmHeight [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Gets the height of the specified family in EmHeights
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* family [I] Family to retrieve from
|
|
|
|
* style [I] (optional) style
|
|
|
|
* EmHeight [O] return value
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetEmHeight(GDIPCONST GpFontFamily *family, INT style, UINT16* EmHeight)
|
|
|
|
{
|
|
|
|
if (!(family && EmHeight)) return InvalidParameter;
|
|
|
|
|
2008-11-24 10:21:44 +01:00
|
|
|
TRACE("%p (%s), %d, %p\n", family, debugstr_w(family->FamilyName), style, EmHeight);
|
2008-07-03 20:26:30 +02:00
|
|
|
|
2008-07-03 20:27:02 +02:00
|
|
|
*EmHeight = family->tmw.ntmSizeEM;
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-03 20:26:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 20:26:27 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* GdipGetLineSpacing [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Returns the line spacing in design units
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* family [I] Family to retrieve from
|
|
|
|
* style [I] (Optional) font style
|
|
|
|
* LineSpacing [O] Return value
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter (family or LineSpacing was NULL)
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetLineSpacing(GDIPCONST GpFontFamily *family,
|
|
|
|
INT style, UINT16* LineSpacing)
|
|
|
|
{
|
2008-11-24 10:21:44 +01:00
|
|
|
TRACE("%p, %d, %p\n", family, style, LineSpacing);
|
2008-07-03 20:26:27 +02:00
|
|
|
|
2008-11-24 10:21:44 +01:00
|
|
|
if (!(family && LineSpacing))
|
|
|
|
return InvalidParameter;
|
2008-07-03 20:26:27 +02:00
|
|
|
|
2008-11-24 10:21:44 +01:00
|
|
|
if (style) FIXME("ignoring style\n");
|
|
|
|
|
|
|
|
*LineSpacing = family->tmw.tmAscent + family->tmw.tmDescent + family->tmw.tmExternalLeading;
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-03 20:26:27 +02:00
|
|
|
}
|
|
|
|
|
2010-05-08 22:36:02 +02:00
|
|
|
static INT CALLBACK font_has_style_proc(const LOGFONTW *elf,
|
|
|
|
const TEXTMETRICW *ntm, DWORD type, LPARAM lParam)
|
|
|
|
{
|
|
|
|
INT fontstyle=0;
|
|
|
|
|
|
|
|
if (!ntm) return 1;
|
|
|
|
|
|
|
|
if (ntm->tmWeight >= FW_BOLD) fontstyle |= FontStyleBold;
|
|
|
|
if (ntm->tmItalic) fontstyle |= FontStyleItalic;
|
|
|
|
if (ntm->tmUnderlined) fontstyle |= FontStyleUnderline;
|
|
|
|
if (ntm->tmStruckOut) fontstyle |= FontStyleStrikeout;
|
|
|
|
|
|
|
|
return (INT)lParam != fontstyle;
|
|
|
|
}
|
|
|
|
|
2008-07-25 03:29:55 +02:00
|
|
|
GpStatus WINGDIPAPI GdipIsStyleAvailable(GDIPCONST GpFontFamily* family,
|
|
|
|
INT style, BOOL* IsStyleAvailable)
|
|
|
|
{
|
2010-05-08 22:36:02 +02:00
|
|
|
HDC hdc;
|
|
|
|
|
|
|
|
TRACE("%p %d %p\n", family, style, IsStyleAvailable);
|
2008-07-25 03:29:55 +02:00
|
|
|
|
|
|
|
if (!(family && IsStyleAvailable))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2010-05-08 22:36:02 +02:00
|
|
|
*IsStyleAvailable = FALSE;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
|
|
|
|
if(!EnumFontFamiliesW(hdc, family->FamilyName, font_has_style_proc, (LPARAM)style))
|
|
|
|
*IsStyleAvailable = TRUE;
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-25 03:29:55 +02:00
|
|
|
}
|
|
|
|
|
2008-06-21 19:02:50 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetGenericFontFamilyMonospace [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Obtains a serif family (Courier New on Windows)
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* **nativeFamily [I] Where the font will be stored
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* InvalidParameter if nativeFamily is NULL.
|
|
|
|
* Ok otherwise.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetGenericFontFamilyMonospace(GpFontFamily **nativeFamily)
|
|
|
|
{
|
|
|
|
static const WCHAR CourierNew[] = {'C','o','u','r','i','e','r',' ','N','e','w','\0'};
|
2011-09-13 01:47:27 +02:00
|
|
|
static const WCHAR LiberationMono[] = {'L','i','b','e','r','a','t','i','o','n',' ','M','o','n','o','\0'};
|
|
|
|
GpStatus stat;
|
2008-06-21 19:02:50 +02:00
|
|
|
|
|
|
|
if (nativeFamily == NULL) return InvalidParameter;
|
|
|
|
|
2011-09-13 01:47:27 +02:00
|
|
|
stat = GdipCreateFontFamilyFromName(CourierNew, NULL, nativeFamily);
|
|
|
|
|
|
|
|
if (stat == FontFamilyNotFound)
|
|
|
|
stat = GdipCreateFontFamilyFromName(LiberationMono, NULL, nativeFamily);
|
|
|
|
|
|
|
|
if (stat == FontFamilyNotFound)
|
|
|
|
ERR("Missing 'Courier New' font\n");
|
|
|
|
|
|
|
|
return stat;
|
2008-06-21 19:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetGenericFontFamilySerif [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Obtains a serif family (Times New Roman on Windows)
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* **nativeFamily [I] Where the font will be stored
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* InvalidParameter if nativeFamily is NULL.
|
|
|
|
* Ok otherwise.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetGenericFontFamilySerif(GpFontFamily **nativeFamily)
|
|
|
|
{
|
|
|
|
static const WCHAR TimesNewRoman[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n','\0'};
|
2011-03-29 20:11:53 +02:00
|
|
|
static const WCHAR LiberationSerif[] = {'L','i','b','e','r','a','t','i','o','n',' ','S','e','r','i','f','\0'};
|
|
|
|
GpStatus stat;
|
2008-06-21 19:02:50 +02:00
|
|
|
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p)\n", nativeFamily);
|
|
|
|
|
2008-06-21 19:02:50 +02:00
|
|
|
if (nativeFamily == NULL) return InvalidParameter;
|
|
|
|
|
2011-03-29 20:11:53 +02:00
|
|
|
stat = GdipCreateFontFamilyFromName(TimesNewRoman, NULL, nativeFamily);
|
|
|
|
|
|
|
|
if (stat == FontFamilyNotFound)
|
|
|
|
stat = GdipCreateFontFamilyFromName(LiberationSerif, NULL, nativeFamily);
|
|
|
|
|
|
|
|
if (stat == FontFamilyNotFound)
|
|
|
|
ERR("Missing 'Times New Roman' font\n");
|
|
|
|
|
|
|
|
return stat;
|
2008-06-21 19:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Obtains a serif family (Microsoft Sans Serif on Windows)
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* **nativeFamily [I] Where the font will be stored
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* InvalidParameter if nativeFamily is NULL.
|
|
|
|
* Ok otherwise.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily **nativeFamily)
|
|
|
|
{
|
2010-04-15 18:40:21 +02:00
|
|
|
GpStatus stat;
|
|
|
|
static const WCHAR MicrosoftSansSerif[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
|
|
|
|
static const WCHAR Tahoma[] = {'T','a','h','o','m','a','\0'};
|
2008-06-21 19:02:50 +02:00
|
|
|
|
2008-09-02 22:33:58 +02:00
|
|
|
TRACE("(%p)\n", nativeFamily);
|
|
|
|
|
2008-06-21 19:02:50 +02:00
|
|
|
if (nativeFamily == NULL) return InvalidParameter;
|
|
|
|
|
2010-04-15 18:40:21 +02:00
|
|
|
stat = GdipCreateFontFamilyFromName(MicrosoftSansSerif, NULL, nativeFamily);
|
|
|
|
|
|
|
|
if (stat == FontFamilyNotFound)
|
|
|
|
/* FIXME: Microsoft Sans Serif is not installed on Wine. */
|
|
|
|
stat = GdipCreateFontFamilyFromName(Tahoma, NULL, nativeFamily);
|
|
|
|
|
|
|
|
return stat;
|
2008-06-21 19:02:50 +02:00
|
|
|
}
|
2008-07-23 05:07:20 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetGenericFontFamilySansSerif [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-23 05:07:20 +02:00
|
|
|
GpStatus WINGDIPAPI GdipNewPrivateFontCollection(GpFontCollection** fontCollection)
|
|
|
|
{
|
2008-11-24 10:21:55 +01:00
|
|
|
TRACE("%p\n", fontCollection);
|
2008-07-23 05:07:20 +02:00
|
|
|
|
|
|
|
if (!fontCollection)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-24 10:21:55 +01:00
|
|
|
*fontCollection = GdipAlloc(sizeof(GpFontCollection));
|
|
|
|
if (!*fontCollection) return OutOfMemory;
|
|
|
|
|
|
|
|
(*fontCollection)->FontFamilies = NULL;
|
|
|
|
(*fontCollection)->count = 0;
|
2009-04-28 01:56:56 +02:00
|
|
|
(*fontCollection)->allocated = 0;
|
2009-12-18 22:04:56 +01:00
|
|
|
|
|
|
|
TRACE("<-- %p\n", *fontCollection);
|
|
|
|
|
2008-11-24 10:21:55 +01:00
|
|
|
return Ok;
|
2008-07-23 05:07:20 +02:00
|
|
|
}
|
2008-07-23 05:07:31 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipDeletePrivateFontCollection [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-23 05:07:31 +02:00
|
|
|
GpStatus WINGDIPAPI GdipDeletePrivateFontCollection(GpFontCollection **fontCollection)
|
|
|
|
{
|
2008-11-24 10:21:55 +01:00
|
|
|
INT i;
|
|
|
|
|
|
|
|
TRACE("%p\n", fontCollection);
|
2008-07-23 05:07:31 +02:00
|
|
|
|
|
|
|
if (!fontCollection)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-24 10:21:55 +01:00
|
|
|
for (i = 0; i < (*fontCollection)->count; i++) GdipFree((*fontCollection)->FontFamilies[i]);
|
|
|
|
GdipFree(*fontCollection);
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-23 05:07:31 +02:00
|
|
|
}
|
2008-07-23 05:07:37 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipPrivateAddFontFile [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-23 05:07:37 +02:00
|
|
|
GpStatus WINGDIPAPI GdipPrivateAddFontFile(GpFontCollection* fontCollection,
|
|
|
|
GDIPCONST WCHAR* filename)
|
|
|
|
{
|
|
|
|
FIXME("stub: %p, %s\n", fontCollection, debugstr_w(filename));
|
|
|
|
|
|
|
|
if (!(fontCollection && filename))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
2008-07-23 05:07:41 +02:00
|
|
|
|
2011-02-16 19:09:15 +01:00
|
|
|
/* Copied from msi/font.c */
|
|
|
|
|
|
|
|
typedef struct _tagTT_OFFSET_TABLE {
|
|
|
|
USHORT uMajorVersion;
|
|
|
|
USHORT uMinorVersion;
|
|
|
|
USHORT uNumOfTables;
|
|
|
|
USHORT uSearchRange;
|
|
|
|
USHORT uEntrySelector;
|
|
|
|
USHORT uRangeShift;
|
|
|
|
} TT_OFFSET_TABLE;
|
|
|
|
|
|
|
|
typedef struct _tagTT_TABLE_DIRECTORY {
|
|
|
|
char szTag[4]; /* table name */
|
|
|
|
ULONG uCheckSum; /* Check sum */
|
|
|
|
ULONG uOffset; /* Offset from beginning of file */
|
|
|
|
ULONG uLength; /* length of the table in bytes */
|
|
|
|
} TT_TABLE_DIRECTORY;
|
|
|
|
|
|
|
|
typedef struct _tagTT_NAME_TABLE_HEADER {
|
|
|
|
USHORT uFSelector; /* format selector. Always 0 */
|
|
|
|
USHORT uNRCount; /* Name Records count */
|
|
|
|
USHORT uStorageOffset; /* Offset for strings storage,
|
|
|
|
* from start of the table */
|
|
|
|
} TT_NAME_TABLE_HEADER;
|
|
|
|
|
|
|
|
#define NAME_ID_FULL_FONT_NAME 4
|
|
|
|
#define NAME_ID_VERSION 5
|
|
|
|
|
|
|
|
typedef struct _tagTT_NAME_RECORD {
|
|
|
|
USHORT uPlatformID;
|
|
|
|
USHORT uEncodingID;
|
|
|
|
USHORT uLanguageID;
|
|
|
|
USHORT uNameID;
|
|
|
|
USHORT uStringLength;
|
|
|
|
USHORT uStringOffset; /* from start of storage area */
|
|
|
|
} TT_NAME_RECORD;
|
|
|
|
|
|
|
|
#define SWAPWORD(x) MAKEWORD(HIBYTE(x), LOBYTE(x))
|
|
|
|
#define SWAPLONG(x) MAKELONG(SWAPWORD(HIWORD(x)), SWAPWORD(LOWORD(x)))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code based off of code located here
|
|
|
|
* http://www.codeproject.com/gdi/fontnamefromfile.asp
|
|
|
|
*/
|
2011-03-16 08:26:11 +01:00
|
|
|
static WCHAR *load_ttf_name_id( const char *mem, DWORD_PTR size, DWORD id, WCHAR *ret, DWORD len )
|
2011-02-16 19:09:15 +01:00
|
|
|
{
|
|
|
|
const TT_TABLE_DIRECTORY *tblDir;
|
|
|
|
TT_OFFSET_TABLE ttOffsetTable;
|
|
|
|
TT_NAME_TABLE_HEADER ttNTHeader;
|
|
|
|
TT_NAME_RECORD ttRecord;
|
|
|
|
DWORD ofs, pos;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (sizeof(TT_OFFSET_TABLE) > size)
|
|
|
|
return NULL;
|
|
|
|
ttOffsetTable = *(TT_OFFSET_TABLE*)mem;
|
|
|
|
ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
|
|
|
|
ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
|
|
|
|
ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
|
|
|
|
|
|
|
|
if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pos = sizeof(ttOffsetTable);
|
|
|
|
for (i = 0; i < ttOffsetTable.uNumOfTables; i++)
|
|
|
|
{
|
|
|
|
tblDir = (const TT_TABLE_DIRECTORY*)&mem[pos];
|
|
|
|
pos += sizeof(*tblDir);
|
|
|
|
if (memcmp(tblDir->szTag,"name",4)==0)
|
|
|
|
{
|
|
|
|
ofs = SWAPLONG(tblDir->uOffset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= ttOffsetTable.uNumOfTables)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pos = ofs + sizeof(ttNTHeader);
|
|
|
|
if (pos > size)
|
|
|
|
return NULL;
|
|
|
|
ttNTHeader = *(TT_NAME_TABLE_HEADER*)&mem[ofs];
|
|
|
|
ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
|
|
|
|
ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
|
|
|
|
for(i=0; i<ttNTHeader.uNRCount; i++)
|
|
|
|
{
|
|
|
|
ttRecord = *(TT_NAME_RECORD*)&mem[pos];
|
|
|
|
pos += sizeof(ttRecord);
|
|
|
|
if (pos > size)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
|
|
|
|
if (ttRecord.uNameID == id)
|
|
|
|
{
|
|
|
|
const char *buf;
|
|
|
|
|
|
|
|
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
|
|
|
|
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
|
|
|
|
if (ofs + ttRecord.uStringOffset + ttNTHeader.uStorageOffset + ttRecord.uStringLength > size)
|
|
|
|
return NULL;
|
|
|
|
buf = mem + ofs + ttRecord.uStringOffset + ttNTHeader.uStorageOffset;
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, buf, ttRecord.uStringLength, ret, len-1);
|
|
|
|
ret[len] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT CALLBACK add_font_proc(const LOGFONTW *lfw, const TEXTMETRICW *ntm, DWORD type, LPARAM lParam);
|
|
|
|
|
2008-11-24 10:22:06 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipPrivateAddMemoryFont [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipPrivateAddMemoryFont(GpFontCollection* fontCollection,
|
|
|
|
GDIPCONST void* memory, INT length)
|
|
|
|
{
|
2011-02-16 19:09:15 +01:00
|
|
|
WCHAR buf[32], *name;
|
|
|
|
DWORD count = 0;
|
|
|
|
HANDLE font;
|
|
|
|
TRACE("%p, %p, %d\n", fontCollection, memory, length);
|
2008-11-24 10:22:06 +01:00
|
|
|
|
2011-02-16 19:09:15 +01:00
|
|
|
if (!fontCollection || !memory || !length)
|
2008-11-24 10:22:06 +01:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2011-02-16 19:09:15 +01:00
|
|
|
name = load_ttf_name_id(memory, length, NAME_ID_FULL_FONT_NAME, buf, sizeof(buf)/sizeof(*buf));
|
|
|
|
if (!name)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
|
|
|
font = AddFontMemResourceEx((void*)memory, length, NULL, &count);
|
|
|
|
TRACE("%s: %p/%u\n", debugstr_w(name), font, count);
|
|
|
|
if (!font || !count)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
LOGFONTW lfw;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
|
|
|
|
lfw.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
lstrcpyW(lfw.lfFaceName, name);
|
|
|
|
lfw.lfPitchAndFamily = 0;
|
|
|
|
|
|
|
|
if (!EnumFontFamiliesExW(hdc, &lfw, add_font_proc, (LPARAM)fontCollection, 0))
|
|
|
|
{
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
2008-11-24 10:22:06 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetFontCollectionFamilyCount [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-23 05:07:41 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetFontCollectionFamilyCount(
|
|
|
|
GpFontCollection* fontCollection, INT* numFound)
|
|
|
|
{
|
2008-11-24 10:22:17 +01:00
|
|
|
TRACE("%p, %p\n", fontCollection, numFound);
|
2008-07-23 05:07:41 +02:00
|
|
|
|
|
|
|
if (!(fontCollection && numFound))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-24 10:22:17 +01:00
|
|
|
*numFound = fontCollection->count;
|
|
|
|
return Ok;
|
2008-07-23 05:07:41 +02:00
|
|
|
}
|
2008-07-23 05:07:45 +02:00
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetFontCollectionFamilyList [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-23 05:07:45 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetFontCollectionFamilyList(
|
|
|
|
GpFontCollection* fontCollection, INT numSought,
|
|
|
|
GpFontFamily* gpfamilies[], INT* numFound)
|
|
|
|
{
|
2008-11-24 10:22:17 +01:00
|
|
|
INT i;
|
2010-06-20 00:50:00 +02:00
|
|
|
GpStatus stat=Ok;
|
2008-11-24 10:22:17 +01:00
|
|
|
|
|
|
|
TRACE("%p, %d, %p, %p\n", fontCollection, numSought, gpfamilies, numFound);
|
2008-07-23 05:07:45 +02:00
|
|
|
|
|
|
|
if (!(fontCollection && gpfamilies && numFound))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2010-06-20 00:50:00 +02:00
|
|
|
memset(gpfamilies, 0, sizeof(*gpfamilies) * numSought);
|
|
|
|
|
|
|
|
for (i = 0; i < numSought && i < fontCollection->count && stat == Ok; i++)
|
2008-11-24 10:22:17 +01:00
|
|
|
{
|
2010-06-20 00:50:00 +02:00
|
|
|
stat = GdipCloneFontFamily(fontCollection->FontFamilies[i], &gpfamilies[i]);
|
2008-11-24 10:22:17 +01:00
|
|
|
}
|
2010-06-20 00:50:00 +02:00
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
*numFound = i;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int numToFree=i;
|
|
|
|
for (i=0; i<numToFree; i++)
|
|
|
|
{
|
|
|
|
GdipDeleteFontFamily(gpfamilies[i]);
|
|
|
|
gpfamilies[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
2008-07-23 05:07:45 +02:00
|
|
|
}
|
2008-11-03 18:39:16 +01:00
|
|
|
|
2009-04-28 01:56:56 +02:00
|
|
|
void free_installed_fonts(void)
|
|
|
|
{
|
|
|
|
while (installedFontCollection.count)
|
|
|
|
GdipDeleteFontFamily(installedFontCollection.FontFamilies[--installedFontCollection.count]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, installedFontCollection.FontFamilies);
|
|
|
|
installedFontCollection.FontFamilies = NULL;
|
|
|
|
installedFontCollection.allocated = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT CALLBACK add_font_proc(const LOGFONTW *lfw, const TEXTMETRICW *ntm,
|
|
|
|
DWORD type, LPARAM lParam)
|
|
|
|
{
|
|
|
|
GpFontCollection* fonts = (GpFontCollection*)lParam;
|
|
|
|
int i;
|
|
|
|
|
2010-04-15 18:49:20 +02:00
|
|
|
if (type == RASTER_FONTTYPE)
|
|
|
|
return 1;
|
|
|
|
|
2009-04-28 01:56:56 +02:00
|
|
|
/* skip duplicates */
|
|
|
|
for (i=0; i<fonts->count; i++)
|
|
|
|
if (strcmpiW(lfw->lfFaceName, fonts->FontFamilies[i]->FamilyName) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (fonts->allocated == fonts->count)
|
|
|
|
{
|
|
|
|
INT new_alloc_count = fonts->allocated+50;
|
|
|
|
GpFontFamily** new_family_list = HeapAlloc(GetProcessHeap(), 0, new_alloc_count*sizeof(void*));
|
|
|
|
|
|
|
|
if (!new_family_list)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memcpy(new_family_list, fonts->FontFamilies, fonts->count*sizeof(void*));
|
|
|
|
HeapFree(GetProcessHeap(), 0, fonts->FontFamilies);
|
|
|
|
fonts->FontFamilies = new_family_list;
|
|
|
|
fonts->allocated = new_alloc_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GdipCreateFontFamilyFromName(lfw->lfFaceName, NULL, &fonts->FontFamilies[fonts->count]) == Ok)
|
|
|
|
fonts->count++;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-03 18:39:16 +01:00
|
|
|
GpStatus WINGDIPAPI GdipNewInstalledFontCollection(
|
|
|
|
GpFontCollection** fontCollection)
|
|
|
|
{
|
2009-04-28 01:56:56 +02:00
|
|
|
TRACE("(%p)\n",fontCollection);
|
2008-11-03 18:39:16 +01:00
|
|
|
|
|
|
|
if (!fontCollection)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-04-28 01:56:56 +02:00
|
|
|
if (installedFontCollection.count == 0)
|
|
|
|
{
|
|
|
|
HDC hdc;
|
|
|
|
LOGFONTW lfw;
|
|
|
|
|
|
|
|
hdc = GetDC(0);
|
|
|
|
|
|
|
|
lfw.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
lfw.lfFaceName[0] = 0;
|
|
|
|
lfw.lfPitchAndFamily = 0;
|
|
|
|
|
|
|
|
if (!EnumFontFamiliesExW(hdc, &lfw, add_font_proc, (LPARAM)&installedFontCollection, 0))
|
|
|
|
{
|
|
|
|
free_installed_fonts();
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
|
|
|
|
2009-04-27 23:24:47 +02:00
|
|
|
*fontCollection = &installedFontCollection;
|
|
|
|
|
|
|
|
return Ok;
|
2008-11-03 18:39:16 +01:00
|
|
|
}
|