📄 olefont.c
字号:
/************************************************************************
* OLEFontImpl_put_Underline (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Underline(
IFont* iface,
BOOL underline)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, underline);
this->description.fUnderline = underline;
OLEFont_SendNotify(this, DISPID_FONT_UNDER);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Strikethrough (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Strikethrough(
IFont* iface,
BOOL* pstrikethrough)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pstrikethrough);
/*
* Sanity check
*/
if (pstrikethrough==0)
return E_POINTER;
*pstrikethrough = this->description.fStrikethrough;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Strikethrough (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Strikethrough(
IFont* iface,
BOOL strikethrough)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, strikethrough);
this->description.fStrikethrough = strikethrough;
OLEFont_SendNotify(this, DISPID_FONT_STRIKE);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Weight (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Weight(
IFont* iface,
short* pweight)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pweight);
/*
* Sanity check
*/
if (pweight==0)
return E_POINTER;
*pweight = this->description.sWeight;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Weight (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Weight(
IFont* iface,
short weight)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, weight);
this->description.sWeight = weight;
OLEFont_SendNotify(this, DISPID_FONT_WEIGHT);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Charset (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Charset(
IFont* iface,
short* pcharset)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pcharset);
/*
* Sanity check
*/
if (pcharset==0)
return E_POINTER;
*pcharset = this->description.sCharset;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Charset (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Charset(
IFont* iface,
short charset)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, charset);
this->description.sCharset = charset;
OLEFont_SendNotify(this, DISPID_FONT_CHARSET);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_hFont (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_hFont(
IFont* iface,
HFONT* phfont)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, phfont);
if (phfont==NULL)
return E_POINTER;
/*
* Realize the font if necessary
*/
if (this->gdiFont==0)
{
LOGFONTW logFont;
INT fontHeight;
CY cySize;
/*
* The height of the font returned by the get_Size property is the
* height of the font in points multiplied by 10000... Using some
* simple conversions and the ratio given by the application, it can
* be converted to a height in pixels.
*/
IFont_get_Size(iface, &cySize);
/* Standard ratio is 72 / 2540, or 18 / 635 in lowest terms. */
/* Ratio is applied here relative to the standard. */
fontHeight = MulDiv( cySize.s.Lo, this->cyLogical*635, this->cyHimetric*18 );
memset(&logFont, 0, sizeof(LOGFONTW));
logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
(-fontHeight/10000L);
logFont.lfItalic = this->description.fItalic;
logFont.lfUnderline = this->description.fUnderline;
logFont.lfStrikeOut = this->description.fStrikethrough;
logFont.lfWeight = this->description.sWeight;
logFont.lfCharSet = this->description.sCharset;
logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = DEFAULT_QUALITY;
logFont.lfPitchAndFamily = DEFAULT_PITCH;
strcpyW(logFont.lfFaceName,this->description.lpstrName);
this->gdiFont = CreateFontIndirectW(&logFont);
}
*phfont = this->gdiFont;
TRACE("Returning %p\n", *phfont);
return S_OK;
}
/************************************************************************
* OLEFontImpl_Clone (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_Clone(
IFont* iface,
IFont** ppfont)
{
OLEFontImpl* newObject = 0;
LOGFONTW logFont;
INT fontHeight;
CY cySize;
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, ppfont);
if (ppfont == NULL)
return E_POINTER;
*ppfont = NULL;
/*
* Allocate space for the object.
*/
newObject = HeapAlloc(GetProcessHeap(), 0, sizeof(OLEFontImpl));
if (newObject==NULL)
return E_OUTOFMEMORY;
*newObject = *this;
/* We need to alloc new memory for the string, otherwise
* we free memory twice.
*/
newObject->description.lpstrName = HeapAlloc(
GetProcessHeap(),0,
(1+strlenW(this->description.lpstrName))*2
);
strcpyW(newObject->description.lpstrName, this->description.lpstrName);
/* We need to clone the HFONT too. This is just cut & paste from above */
IFont_get_Size(iface, &cySize);
fontHeight = MulDiv(cySize.s.Lo, this->cyLogical*635,this->cyHimetric*18);
memset(&logFont, 0, sizeof(LOGFONTW));
logFont.lfHeight = ((fontHeight%10000L)>5000L) ? (-fontHeight/10000L)-1 :
(-fontHeight/10000L);
logFont.lfItalic = this->description.fItalic;
logFont.lfUnderline = this->description.fUnderline;
logFont.lfStrikeOut = this->description.fStrikethrough;
logFont.lfWeight = this->description.sWeight;
logFont.lfCharSet = this->description.sCharset;
logFont.lfOutPrecision = OUT_CHARACTER_PRECIS;
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont.lfQuality = DEFAULT_QUALITY;
logFont.lfPitchAndFamily = DEFAULT_PITCH;
strcpyW(logFont.lfFaceName,this->description.lpstrName);
newObject->gdiFont = CreateFontIndirectW(&logFont);
/* create new connection points */
newObject->pPropertyNotifyCP = NULL;
newObject->pFontEventsCP = NULL;
CreateConnectionPoint((IUnknown*)newObject, &IID_IPropertyNotifySink, &newObject->pPropertyNotifyCP);
CreateConnectionPoint((IUnknown*)newObject, &IID_IFontEventsDisp, &newObject->pFontEventsCP);
if (!newObject->pPropertyNotifyCP || !newObject->pFontEventsCP)
{
OLEFontImpl_Destroy(newObject);
return E_OUTOFMEMORY;
}
/* The cloned object starts with a reference count of 1 */
newObject->ref = 1;
*ppfont = (IFont*)newObject;
return S_OK;
}
/************************************************************************
* OLEFontImpl_IsEqual (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_IsEqual(
IFont* iface,
IFont* pFontOther)
{
FIXME("(%p, %p), stub!\n",iface,pFontOther);
return E_NOTIMPL;
}
/************************************************************************
* OLEFontImpl_SetRatio (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_SetRatio(
IFont* iface,
LONG cyLogical,
LONG cyHimetric)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%ld, %ld)\n", this, cyLogical, cyHimetric);
this->cyLogical = cyLogical;
this->cyHimetric = cyHimetric;
return S_OK;
}
/************************************************************************
* OLEFontImpl_QueryTextMetrics (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_QueryTextMetrics(
IFont* iface,
TEXTMETRICOLE* ptm)
{
HDC hdcRef;
HFONT hOldFont, hNewFont;
hdcRef = GetDC(0);
OLEFontImpl_get_hFont(iface, &hNewFont);
hOldFont = SelectObject(hdcRef, hNewFont);
GetTextMetricsW(hdcRef, ptm);
SelectObject(hdcRef, hOldFont);
ReleaseDC(0, hdcRef);
return S_OK;
}
/************************************************************************
* OLEFontImpl_AddRefHfont (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_AddRefHfont(
IFont* iface,
HFONT hfont)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
if ( (hfont == 0) ||
(hfont != this->gdiFont) )
return E_INVALIDARG;
this->fontLock++;
return S_OK;
}
/************************************************************************
* OLEFontImpl_ReleaseHfont (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_ReleaseHfont(
IFont* iface,
HFONT hfont)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p) (lock=%ld)\n", this, hfont, this->fontLock);
if ( (hfont == 0) ||
(hfont != this->gdiFont) )
return E_INVALIDARG;
this->fontLock--;
/*
* If we just released our last font reference, destroy it.
*/
if (this->fontLock==0)
{
DeleteObject(this->gdiFont);
this->gdiFont = 0;
}
return S_OK;
}
/************************************************************************
* OLEFontImpl_SetHdc (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_SetHdc(
IFont* iface,
HDC hdc)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
FIXME("(%p)->(%p): Stub\n", this, hdc);
return E_NOTIMPL;
}
/************************************************************************
* OLEFontImpl_IDispatch_QueryInterface (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static HRESULT WINAPI OLEFontImpl_IDispatch_QueryInterface(
IDispatch* iface,
REFIID riid,
VOID** ppvoid)
{
OLEFontImpl *this = impl_from_IDispatch(iface);
return IFont_QueryInterface((IFont *)this, riid, ppvoid);
}
/************************************************************************
* OLEFontImpl_IDispatch_Release (IUnknown)
*
* See Windows documentation for more details on IUnknown methods.
*/
static ULONG WINAPI OLEFontImpl_IDispatch_Release(
IDispatch* iface)
{
OLEFontImpl *this = impl_from_IDispatch(iface);
return IFont_Release((IFont *)this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -