📄 tomfmt.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft shared
// source or premium shared source license agreement under which you licensed
// this source code. If you did not accept the terms of the license agreement,
// you are not authorized to use this source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the SOURCE.RTF on your install media or the root of your tools installation.
// THE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*
* @doc TOM
*
* @module tomfmt.cpp - Implement the CTxtFont and CTxtPara Classes |
*
* This module contains the implementation of the TOM ITextFont and
* ITextPara interfaces
*
* History: <nl>
* 11/8/95 - MurrayS: created
* 5/96 - MurrayS: added zombie protection
*
*/
#include "_common.h"
#include "_tomfmt.h"
ASSERTDATA
#define tomFloatUndefined ((float)(int)tomUndefined)
// Alignment translation vectors
const BYTE g_rgREtoTOMAlign[] = // RichEdit to TOM
{
tomAlignLeft, tomAlignLeft, tomAlignRight, tomAlignCenter, tomAlignJustify
};
const BYTE g_rgTOMtoREAlign[] = // TOM to RichEdit
{
PFA_LEFT, PFA_CENTER, PFA_RIGHT, PFA_JUSTIFY
};
BOOL SameVtables(IUnknown *punk1, IUnknown *punk2);
/*
* QueryInterface(riid, riid1, punk, ppv, fZombie)
*
* @func
* QueryInterface punk for the ref IDs riid1, IID_IDispatch, and
* IID_IUnknown
*
* @rdesc
* HRESULT = (!ppv) ? E_INVALIDARG :
* (interface found) ? NOERROR : E_NOINTERFACE
*/
HRESULT QueryInterface (REFIID riid, REFIID riid1, IUnknown *punk,
void **ppv, BOOL fZombie)
{
if(!ppv)
return E_INVALIDARG;
*ppv = NULL;
if(fZombie) // Check for range zombie
return CO_E_RELEASED;
Assert(punk);
#ifndef PEGASUS
if( IsEqualIID(riid, IID_IUnknown) ||
IsEqualIID(riid, IID_IDispatch) ||
IsEqualIID(riid, riid1) )
{
*ppv = punk;
punk->AddRef();
return NOERROR;
}
#endif
return E_NOINTERFACE;
}
//------------------------------- CTxtFont -------------------------------------
/*
* CTxtFont::CTxtFont(prg)
*
* @mfunc
* Constructor
*/
CTxtFont::CTxtFont(CTxtRange *prg) : CTxtFormat(prg)
{
_CF.dwMask = 0; // Private CCharFormat is initially undefined
}
//------------------------- CTxtFont IUnknown Methods -------------------------------------
/* CTxtFont::IUnknown methods
*
* See tomDoc.cpp for comments
*/
STDMETHODIMP CTxtFont::QueryInterface (REFIID riid, void **ppv)
{
#ifndef PEGASUS
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::QueryInterface");
return ::QueryInterface(riid, IID_ITextFont, this, ppv, IsZombie());
#else
return 0;
#endif
}
STDMETHODIMP_(ULONG) CTxtFont::AddRef()
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::AddRef");
return ++_cRefs;
}
STDMETHODIMP_(ULONG) CTxtFont::Release()
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::Release");
_cRefs--;
if(!_cRefs)
{
delete this;
return 0;
}
return _cRefs;
}
//------------------------- CTxtFont IDispatch Methods -------------------------------------
/*
* CTxtFont::GetTypeInfoCount(pcTypeInfo)
*
* @mfunc
* Get the number of TYPEINFO elements (1)
*
* @rdesc
* HRESULT = (pcTypeInfo) ? NOERROR : E_INVALIDARG;
*/
STDMETHODIMP CTxtFont::GetTypeInfoCount (
UINT * pcTypeInfo) //@parm Out parm to receive type-info count
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetTypeInfoCount");
if(!pcTypeInfo)
return E_INVALIDARG;
*pcTypeInfo = 1;
return NOERROR;
}
/*
* CTxtFont::GetTypeInfo(iTypeInfo, lcid, ppTypeInfo)
*
* @mfunc
* Return ptr to type information object for ITextFont interface
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CTxtFont::GetTypeInfo (
UINT iTypeInfo, //@parm Index of type info to return
LCID lcid, //@parm Local ID of type info
ITypeInfo **ppTypeInfo) //@parm Out parm to receive type info
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetTypeInfo");
return ::GetTypeInfo(iTypeInfo, g_pTypeInfoFont, ppTypeInfo);
}
/*
* CTxtFont::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid)
*
* @mfunc
* Get DISPIDs for ITextFont methods and properties
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CTxtFont::GetIDsOfNames (
REFIID riid, //@parm Interface ID to interpret names for
OLECHAR ** rgszNames, //@parm Array of names to be mapped
UINT cNames, //@parm Count of names to be mapped
LCID lcid, //@parm Local ID to use for interpretation
DISPID * rgdispid) //@parm Out parm to receive name mappings
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetIDsOfNames");
HRESULT hr = GetTypeInfoPtrs(); // Ensure TypeInfo ptrs are OK
if(hr != NOERROR)
return hr;
return g_pTypeInfoFont->GetIDsOfNames(rgszNames, cNames, rgdispid);
}
/*
* CTxtFont::Invoke(dispidMember, riid, lcid, wFlags, pdispparams,
* pvarResult, pexcepinfo, puArgError)
* @mfunc
* Invoke methods for the ITextFont interface
*
* @rdesc
* HRESULT
*/
STDMETHODIMP CTxtFont::Invoke (
DISPID dispidMember, //@parm Identifies member function
REFIID riid, //@parm Pointer to interface ID
LCID lcid, //@parm Locale ID for interpretation
USHORT wFlags, //@parm Flags describing context of call
DISPPARAMS *pdispparams, //@parm Ptr to method arguments
VARIANT * pvarResult, //@parm Out parm for result (if not NULL)
EXCEPINFO * pexcepinfo, //@parm Out parm for exception info
UINT * puArgError) //@parm Out parm for error
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::Invoke");
HRESULT hr = GetTypeInfoPtrs(); // Ensure TypeInfo ptrs are OK
if(hr != NOERROR)
return hr;
if(IsZombie())
return CO_E_RELEASED;
return g_pTypeInfoFont->Invoke(this, dispidMember, wFlags,
pdispparams, pvarResult, pexcepinfo, puArgError);
}
//--------------------------- ITextFont Methods -------------------------------------
/*
* ITextFont::CanChange(long * pbCanChange)
*
* @mfunc
* Method that sets *pbCanChange = tomTrue if and only if the
* font can be changed.
*
* @rdesc
* HRESULT = (can change char format) ? NOERROR : S_FALSE
*/
STDMETHODIMP CTxtFont::CanChange (
long *pbCanChange) //@parm Out parm to receive boolean value
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::CanChange");
return CTxtFormat::CanChange(pbCanChange);
}
/*
* ITextFont::GetAllCaps(long * pValue)
*
* @mfunc
* Property get method that gets the AllCaps state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetAllCaps (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetAllCaps");
return EffectGetter(pValue, CFM_ALLCAPS);
}
/*
* ITextFont::GetAnimation(long * pValue)
*
* @mfunc
* Property get method that gets the animation type as defined
* in the table below.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetAnimation (
long *pValue) //@parm Out parm to receive animation type
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetAnimation");
return GetParameter((long *)&_CF.bAnimation, CFM_ANIMATION, 1, pValue);
}
/*
* ITextFont::GetBackColor(long * pValue)
*
* @mfunc
* Property get method that gets the background color. The
* value is a Win32 COLORREF.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetBackColor (
long *pValue) //@parm Out parm to receive COLORREF value
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetBackColor");
HRESULT hr = EffectGetter(pValue, CFE_AUTOBACKCOLOR);
if(hr != NOERROR || *pValue == tomUndefined)
return hr;
*pValue = (*pValue == tomFalse) ? _CF.crBackColor : tomAutoColor;
return NOERROR;
}
/*
* ITextFont::GetBold(long * pValue)
*
* @mfunc
* Property get method that gets the bold state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetBold (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetBold");
return EffectGetter(pValue, CFM_BOLD);
}
/*
* ITextFont::GetDuplicate(ITextFont **ppFont)
*
* @mfunc
* Property get method that gets a clone of this character
* format object.
*
* @rdesc
* HRESULT = (!ppFont) ? E_INVALIDARG :
* (if success) ? NOERROR : S_FALSE
*/
STDMETHODIMP CTxtFont::GetDuplicate (
ITextFont **ppFont) //@parm Out parm to receive font clone
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetDuplicate");
if(!ppFont)
return E_INVALIDARG;
*ppFont = NULL;
if(IsZombie())
return CO_E_RELEASED;
CTxtFont *pFont = new CTxtFont(NULL);
if(!pFont)
return E_OUTOFMEMORY;
if(_prg) // If live font object, load
_prg->GetCharFormat(&pFont->_CF); // clone directly from range
else
pFont->_CF = _CF;
*ppFont = pFont;
return NOERROR;
}
/*
* ITextFont::GetEmboss(long * pValue)
*
* @mfunc
* Property get method that gets the embossed state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetEmboss (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetEmboss");
return EffectGetter(pValue, CFM_EMBOSS);
}
/*
* ITextFont::GetForeColor(long * pValue)
*
* @mfunc
* Property get method that gets the foreground color.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetForeColor (
long *pValue) //@parm Out parm to receive COLORREF value
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetForeColor");
HRESULT hr = EffectGetter(pValue, CFE_AUTOCOLOR);
if(hr != NOERROR || *pValue == tomUndefined)
return hr;
*pValue = (*pValue == tomFalse) ? _CF.crTextColor : tomAutoColor;
return NOERROR;
}
/*
* ITextFont::GetHidden(long * pValue)
*
* @mfunc
* Property get method that gets the hidden state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetHidden (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetHidden");
return EffectGetter(pValue, CFM_HIDDEN);
}
/*
* ITextFont::GetEngrave(long * pValue)
*
* @mfunc
* Property get method that gets the imprint state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetEngrave (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetEngrave");
return EffectGetter(pValue, CFM_IMPRINT);
}
/*
* ITextFont::GetItalic(long * pValue)
*
* @mfunc
* Property get method that gets the italic state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetItalic (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetItalic");
return EffectGetter(pValue, CFM_ITALIC);
}
/*
* ITextFont::GetKerning(float * pValue)
*
* @mfunc
* Property get method that gets the minimum kerning size,
* which is given in floating-point points.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*
* @comm
* A kerning size of 0 turns off kerning, but an arbitrarily small
* value turns it on, e.g., 1.0, which is too small to see, let alone
* kern!
*/
STDMETHODIMP CTxtFont::GetKerning (
float *pValue) //@parm Out parm to receive minimum kerning size
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetKerning");
return GetParameter((long *)&_CF.wKerning, CFM_KERNING, -2, (long *)pValue);
}
/*
* ITextFont::GetLanguageID(long * pValue)
*
* @mfunc
* Property get method that gets the language ID (more
* generally LCID).
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetLanguageID (
long *pValue) //@parm Out parm to receive LCID value
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -