📄 olefont.c
字号:
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Name (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Name(
IFont* iface,
BSTR name)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, name);
if (this->description.lpstrName==0)
{
this->description.lpstrName = HeapAlloc(GetProcessHeap(),
0,
(lstrlenW(name)+1) * sizeof(WCHAR));
}
else
{
this->description.lpstrName = HeapReAlloc(GetProcessHeap(),
0,
this->description.lpstrName,
(lstrlenW(name)+1) * sizeof(WCHAR));
}
if (this->description.lpstrName==0)
return E_OUTOFMEMORY;
strcpyW(this->description.lpstrName, name);
TRACE("new name %s\n", debugstr_w(this->description.lpstrName));
OLEFont_SendNotify(this, DISPID_FONT_NAME);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Size (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Size(
IFont* iface,
CY* psize)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, psize);
/*
* Sanity check
*/
if (psize==0)
return E_POINTER;
psize->s.Hi = 0;
psize->s.Lo = this->description.cySize.s.Lo;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Size (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Size(
IFont* iface,
CY size)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, size.s.Lo);
this->description.cySize.s.Hi = 0;
this->description.cySize.s.Lo = size.s.Lo;
OLEFont_SendNotify(this, DISPID_FONT_SIZE);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Bold (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Bold(
IFont* iface,
BOOL* pbold)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pbold);
/*
* Sanity check
*/
if (pbold==0)
return E_POINTER;
*pbold = this->description.sWeight > 550;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Bold (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Bold(
IFont* iface,
BOOL bold)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, bold);
this->description.sWeight = bold ? FW_BOLD : FW_NORMAL;
OLEFont_SendNotify(this, DISPID_FONT_BOLD);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Italic (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Italic(
IFont* iface,
BOOL* pitalic)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, pitalic);
/*
* Sanity check
*/
if (pitalic==0)
return E_POINTER;
*pitalic = this->description.fItalic;
return S_OK;
}
/************************************************************************
* OLEFontImpl_put_Italic (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_put_Italic(
IFont* iface,
BOOL italic)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%d)\n", this, italic);
this->description.fItalic = italic;
OLEFont_SendNotify(this, DISPID_FONT_ITALIC);
return S_OK;
}
/************************************************************************
* OLEFontImpl_get_Underline (IFont)
*
* See Windows documentation for more details on IFont methods.
*/
static HRESULT WINAPI OLEFontImpl_get_Underline(
IFont* iface,
BOOL* punderline)
{
OLEFontImpl *this = (OLEFontImpl *)iface;
TRACE("(%p)->(%p)\n", this, punderline);
/*
* Sanity check
*/
if (punderline==0)
return E_POINTER;
*punderline = this->description.fUnderline;
return S_OK;
}
/************************************************************************
* 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;
PHFONTItem newEntry;
/*
* 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);
/* Add font to the cache */
newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(HFONTItem));
newEntry->ref = 1;
newEntry->gdiFont = this->gdiFont;
EnterCriticalSection(&OLEFontImpl_csHFONTLIST);
list_add_tail(&OLEFontImpl_hFontList,&newEntry->entry);
LeaveCriticalSection(&OLEFontImpl_csHFONTLIST);
}
*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;
PHFONTItem newEntry;
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -