private static object GetSuperscript(ITextFont font) { TomBool super = font.Superscript; if (super == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return super == TomBool.tomTrue; } }
private static object GetUnderlineStyle(ITextFont font) { // note: if a range spans different underline styles then it won't return tomUndefined. instead it appears // to return the underline style at the endpoint. if a range spans underlined and non-underlined text then // it returns tomUndefined properly. TomUnderline underline = font.Underline; if (underline == TomUnderline.tomUndefined) { return TextPattern.MixedAttributeValue; } else { switch (underline) { case TomUnderline.tomTrue: return TextDecorationLineStyle.Single; default: // TextDecorationLineStyle enum matches TomUnderline enum return (TextDecorationLineStyle)(int)underline; } } }
private object GetReadOnly(ITextFont font) { // if the entire pattern is read-only then every range within it is also // read only. if (_pattern.ReadOnly) { return true; } // check if the "Protected" font style is turned on. TomBool protect = font.Protected; if (protect == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return protect == TomBool.tomTrue; } }
private static object GetStrikethroughStyle(ITextFont font) { TomBool strike = font.StrikeThrough; if (strike == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return strike == TomBool.tomTrue ? TextDecorationLineStyle.Single : TextDecorationLineStyle.None; } }
private static object GetItalic(ITextFont font) { TomBool italic = font.Italic; if (italic == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return italic == TomBool.tomTrue; } }
private static object GetOutlineStyles(ITextFont font) { TomBool outline = font.Outline; TomBool shadow = font.Shadow; TomBool emboss = font.Emboss; TomBool engrave = font.Engrave; if (outline == TomBool.tomUndefined || shadow == TomBool.tomUndefined || emboss == TomBool.tomUndefined || engrave == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { OutlineStyles style = 0; style |= (outline == TomBool.tomTrue) ? OutlineStyles.Outline : 0; style |= (shadow == TomBool.tomTrue) ? OutlineStyles.Shadow : 0; style |= (emboss == TomBool.tomTrue) ? OutlineStyles.Embossed : 0; style |= (engrave == TomBool.tomTrue) ? OutlineStyles.Engraved : 0; return style; } }
private static object GetForegroundColor(ITextFont font) { int color = font.ForeColor; switch (color) { case (int)TomConst.tomAutocolor: // tomAutocolor means richedit is using the default system foreground color. // review: if RichEdit sends a WM_CTLCOLOR message to it's parent then the // text color can depend on whatever foreground color the parent supplies. return SafeNativeMethods.GetSysColor(NativeMethods.COLOR_WINDOWTEXT); case (int)TomConst.tomUndefined: return TextPattern.MixedAttributeValue; default: // if the high-byte is zero then we have a COLORREF if ((color & 0xff000000) == 0) { return color; } else { // we have a PALETTEINDEX color return AutomationElement.NotSupported; } } }
private static object GetHidden(ITextFont font) { TomBool hidden = font.Hidden; if (hidden == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return hidden == TomBool.tomTrue; } }
private static object GetFontWeight(ITextFont font) { int weight = font.Weight; if (weight == (int)TomConst.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return weight; } }
private static object GetFontSize(ITextFont font) { float size = font.Size; if ((TomConst)size == TomConst.tomUndefined) { return TextPattern.MixedAttributeValue; } else { return (double)size; } }
private static object GetCapStyle(ITextFont font) { TomBool allCaps = font.AllCaps; TomBool smallCaps = font.SmallCaps; if (allCaps == TomBool.tomUndefined || smallCaps == TomBool.tomUndefined) { return TextPattern.MixedAttributeValue; } else { // note: AllCaps and SmallCaps are mutually exclusive. if (font.AllCaps == TomBool.tomTrue) { return CapStyle.AllCap; } else if (font.SmallCaps == TomBool.tomTrue) { return CapStyle.SmallCap; } else { return CapStyle.None; } } }
private static object GetAnimationStyle(ITextFont font) { TomAnimation anim = font.Animation; if (anim == TomAnimation.tomUndefined) { return TextPattern.MixedAttributeValue; } else { // the AnimationStyle enum matches the TomAnimation enum return (AnimationStyle)(int)anim; } }
internal RichTextFont(ITextFont font) { _font = font; }