📄 tomfmt.cpp
字号:
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetLanguageID");
return GetParameter((long *)&_CF.lcid, CFM_LCID, 4, pValue);
}
/*
* ITextFont::GetName(BSTR *pbstr)
*
* @mfunc
* Property get method that gets the font name.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG :
* (can allocate bstr) ? NOERROR : E_OUTOFMEMORY
*/
STDMETHODIMP CTxtFont::GetName (
BSTR *pbstr) //@parm Out parm to receive font name bstr
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetName");
if(!pbstr)
return E_INVALIDARG;
*pbstr = NULL;
HRESULT hr = UpdateFormat(); // If live Font object, update
// _CF to current _prg values
if(hr != NOERROR) // Attached to zombied range
return hr;
*pbstr = pSysAllocString(_CF.szFaceName);
return *pbstr ? NOERROR : E_OUTOFMEMORY;
}
/*
* ITextFont::GetOutline(long * pValue)
*
* @mfunc
* Property get method that gets the outline state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetOutline (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetOutline");
return EffectGetter(pValue, CFM_OUTLINE);
}
/*
* ITextFont::GetPosition(float *pValue)
*
* @mfunc
* Property get method that gets the character position
* relative to the baseline. The value is given in floating-point
* points.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetPosition (
float *pValue) //@parm Out parm to receive relative vertical position
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetPosition");
return GetParameter(&_CF.yOffset, CFM_OFFSET, -4, (long *)pValue);
}
/*
* ITextFont::GetProtected(long * pValue)
*
* @mfunc
* Property get method that gets the protected state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetProtected (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetProtected");
return EffectGetter(pValue, CFM_PROTECTED);
}
/*
* ITextFont::GetShadow(long * pValue)
*
* @mfunc
* Property get method that gets the shadow state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetShadow (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetShadow");
return EffectGetter(pValue, CFM_SHADOW);
}
/*
* ITextFont::GetSize(float * pValue)
*
* @mfunc
* Property get method that gets the font size, which is given
* in floating-point points.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetSize (
float *pValue) //@parm Out parm to receive font size
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetSize");
return GetParameter(&_CF.yHeight, CFM_SIZE, -4, (long *)pValue);
}
/*
* ITextFont::GetSmallCaps(long * pValue)
*
* @mfunc
* Property get method that gets the SmallCaps state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetSmallCaps (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetSmallCaps");
return EffectGetter(pValue, CFM_SMALLCAPS);
}
/*
* ITextFont::GetSpacing(float * pValue)
*
* @mfunc
* Property get method that gets the intercharacter spacing,
* which is given in floating-point points.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetSpacing (
float *pValue) //@parm Out parm to receive intercharacter spacing
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetSpacing");
return GetParameter((long *)&_CF.sSpacing, CFM_SPACING, -2, (long *)pValue);
}
/*
* ITextFont::GetStrikeThrough(long * pValue)
*
* @mfunc
* Property get method that gets the strikeout state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetStrikeThrough (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetStrikeThrough");
return EffectGetter(pValue, CFM_STRIKEOUT);
}
/*
* ITextFont::GetStyle(long * pValue)
*
* @mfunc
* Property get method that gets the character style handle for
* the characters in a range.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR;
*/
STDMETHODIMP CTxtFont::GetStyle (
long *pValue) //@parm Out parm to receive character style handle
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetStyle");
return GetParameter((long *)&_CF.sStyle, CFM_STYLE, 2, pValue);
}
/*
* ITextFont::GetSubscript(long * pValue)
*
* @mfunc
* Property get method that gets the subscript state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetSubscript (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetSubscript");
return EffectGetter(pValue, CFE_SUBSCRIPT);
}
/*
* ITextFont::GetSuperscript(long * pValue)
*
* @mfunc
* Property get method that gets the superscript state.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetSuperscript (
long *pValue) //@parm Out parm to receive tomBool
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetSuperscript");
return EffectGetter(pValue, CFE_SUPERSCRIPT);
}
/*
* ITextFont::GetUnderline(long * pValue)
*
* @mfunc
* Property get method that gets the underline style.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR
*/
STDMETHODIMP CTxtFont::GetUnderline (
long *pValue) //@parm Out parm to receive underline style
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetUnderline");
if(!pValue)
return E_INVALIDARG;
HRESULT hr = UpdateFormat(); // If live Font object, update
// _CF to current _prg values
*pValue = 0; // Default no underline
if(!(_CF.dwMask & CFM_UNDERLINE)) // It's a NINCH
*pValue = tomUndefined;
else if(_CF.dwEffects & CFM_UNDERLINE)
*pValue = (LONG)_CF.bUnderlineType ? (LONG)_CF.bUnderlineType : tomTrue;
return hr;
}
/*
* ITextFont::GetWeight(long * pValue)
*
* @mfunc
* Property get method that gets the font weight for
* the characters in a range.
*
* @rdesc
* HRESULT = (!pValue) ? E_INVALIDARG : NOERROR;
*/
STDMETHODIMP CTxtFont::GetWeight (
long *pValue) //@parm Out parm to receive character style handle
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::GetWeight");
return GetParameter((long *)&_CF.wWeight, CFM_WEIGHT, 2, pValue);
}
/*
* ITextFont::IsEqual(ITextFont * pFont, long * pB)
*
* @mfunc
* Method that sets *<p pB> = tomTrue if this text font has the
* same properties as *<p pFont>. For this to be true, *<p pFont> has to
* belong to the same TOM engine as the present one. The IsEqual()
* method should ignore entries for which either font object has a
* tomUndefined value.
*
* @rdesc
* HRESULT = (equal objects) ? NOERROR : S_FALSE
*
* @devnote
* This implementation assumes that all properties are defined and that
* pFont belongs to RichEdit. It would be nice to generalize this so
* that undefined properties are ignored in the comparison and so that
* pFont could belong to a different TOM engine. This would help in
* using RichEdit Find dialogs to search for rich text in Word using
* TOM.
*/
STDMETHODIMP CTxtFont::IsEqual (
ITextFont * pFont, //@parm ITextFont to compare to
long * pB) //@parm Out parm to receive comparison result
{
#ifndef PEGASUS
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::IsEqual");
UpdateFormat(); // Update _CFs in case they are
((CTxtFont *)pFont)->UpdateFormat(); // attached to ranges
// Ignore differences in CharSet, since TOM thinks all CharSets are Unicode!
LONG CharSet = _CF.bCharSet;
_CF.bCharSet = ((CTxtFont *)pFont)->_CF.bCharSet;
HRESULT hr = IsTrue(SameVtables(this, pFont) &&
_CF.Compare(&((CTxtFont *)pFont)->_CF), pB);
_CF.bCharSet = CharSet;
return hr;
#else
return 0;
#endif
}
/*
* ITextFont::Reset(long Value)
*
* @mfunc
* Method that resets the character formatting to the default
* values to 1) those defined by the RTF \plain control word (Value =
* tomDefault), and 2) all undefined values (Value = tomUndefined).
*
* @rdesc
* HRESULT = (if success) ? NOERROR :
* (protected) ? E_ACCESSDENIED : E_OUTOFMEMORY
*/
STDMETHODIMP CTxtFont::Reset (
long Value) //@parm Kind of reset (tomDefault or tomUndefined)
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::Reset");
HRESULT hr = CanChange(NULL);
if(hr != NOERROR) // Takes care of zombie
return hr; // and protection
if(Value == tomDefault)
{
if(_prg)
{
CTxtEdit *ped = _prg->GetPed();
if (ped)
{
CopyFormat(&_CF, ped->GetCharFormat(-1), sizeof(CCharFormat));
FormatSetter(CFM_ALL2);
}
else
{
return E_OUTOFMEMORY;
}
}
else
_CF.InitDefault(0);
}
else if(Value == tomUndefined && !_prg) // Only applicable
_CF.dwMask = 0; // for clones
else
return E_INVALIDARG;
return NOERROR;
}
/*
* ITextFont::SetAllCaps(long Value)
*
* @mfunc
* Property put method that sets the AllCaps state according to
* the value given by Value.
*
* @rdesc
* HRESULT = (if success) ? NOERROR :
* (protected) ? E_ACCESSDENIED : E_OUTOFMEMORY
*/
STDMETHODIMP CTxtFont::SetAllCaps (
long Value) //@parm New value. Default value: tomToggle
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::SetAllCaps");
return EffectSetter(Value, CFM_ALLCAPS | CFM_SMALLCAPS, CFE_ALLCAPS);
}
/*
* ITextFont::SetAnimation(long Value)
*
* @mfunc
* Property put method that sets the animation type
*
* @rdesc
* HRESULT = (Value defined) ? NOERROR : E_INVALIDARG
*/
STDMETHODIMP CTxtFont::SetAnimation (
long Value) //@parm New animation type
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::SetAnimation");
if(Value == tomUndefined)
return NOERROR;
if((unsigned)Value > tomAnimationMax)
return E_INVALIDARG;
return SetParameter((long *)&_CF.bAnimation, CFM_ANIMATION, 1, Value);
}
/*
* ITextFont::SetBackColor(long Value)
*
* @mfunc
* Property put method that sets the background color according
* to the value given by Value.
*
* @rdesc
* HRESULT = (if success) ? NOERROR :
* (protected) ? E_ACCESSDENIED : E_OUTOFMEMORY
* @devnote
* Legal values are tomUndefined, tomAutoColor (both negative) and
* in principle any positive values. Currently wingdi.h only defines
* high bytes = 0, 1, 2, 4. But more values might happen, so we only
* rule out negative values other than tomUndefined and tomAutoColor.
*/
STDMETHODIMP CTxtFont::SetBackColor (
long Value ) //@parm New COLORREF value to use
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::SetBackColor");
if(Value == tomUndefined) // NINCH
return NOERROR;
_CF.dwEffects |= CFE_AUTOBACKCOLOR; // Default AutoBackColor
if(Value != tomAutoColor)
{
if(Value < 0)
return E_INVALIDARG;
_CF.dwEffects &= ~CFE_AUTOBACKCOLOR; // Turn off AutoBackColor
_CF.crBackColor = (COLORREF)Value; // Use new BackColor
}
return FormatSetter(CFM_BACKCOLOR);
}
/*
* ITextFont::SetBold(long Value)
*
* @mfunc
* Property put method that sets the bold state according to
* the value given by Value.
*
* @rdesc
* HRESULT = (if success) ? NOERROR :
* (protected) ? E_ACCESSDENIED : E_OUTOFMEMORY
*/
STDMETHODIMP CTxtFont::SetBold (
long Value) //@parm New value. Default value: tomToggle
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::SetBold");
return EffectSetter(Value, CFM_BOLD, CFE_BOLD);
}
/*
* ITextFont::SetDuplicate(ITextFont *pFont)
*
* @mfunc
* Property put method that sets this text font character
* formatting to that given by pFont.
*
* @rdesc
* HRESULT = (if success) ? NOERROR :
* (protected) ? E_ACCESSDENIED : E_OUTOFMEMORY
*/
STDMETHODIMP CTxtFont::SetDuplicate(
ITextFont *pFont) //@parm Font object to apply to this font object
{
TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtFont::SetDuplicate");
DWORD dwMask = 0;
BSTR bstr;
CTxtRange * prg;
long Value;
float x;
if(IsZombie()) // Check for range zombie
return CO_E_RELEASED;
if(SameVtables(this, pFont)) // If pFont belongs to this TOM
{ // engine, can cast and copy
((CTxtFont *)pFont)->UpdateFormat();
_CF = ((CTxtFont *)pFont)->_CF;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -