Exemplo n.º 1
0
        public FormatChanges GetFormatChanges()
        {
            FormatChanges fc = new FormatChanges();

            fc.color = SelectionColor;
            fc.font  = SelectionFont;
            STRUCT_CHARFORMAT2 cf2 = new STRUCT_CHARFORMAT2();

            GetCharFormat(ref cf2);
            if ((cf2.dwMask & CFM_BOLD) != 0)
            {
                fc.bold = ((cf2.dwEffects & CFE_BOLD) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_ITALIC) != 0)
            {
                fc.italic = ((cf2.dwEffects & CFE_ITALIC) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_UNDERLINE) != 0)
            {
                fc.underline = ((cf2.dwEffects & CFE_UNDERLINE) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_SUPERSCRIPT) != 0)
            {
                fc.superscript = ((cf2.dwEffects & CFE_SUPERSCRIPT) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_SUBSCRIPT) != 0)
            {
                fc.subscript = ((cf2.dwEffects & CFE_SUBSCRIPT) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_STRIKEOUT) != 0)
            {
                fc.strikeout = ((cf2.dwEffects & CFE_STRIKEOUT) != 0) ? Ternary.Yes : Ternary.No;
            }
            if ((cf2.dwMask & CFM_FACE) != 0)
            {
                fc.fontfamily = cf2.szFaceName;
            }
            if ((cf2.dwMask & CFM_SIZE) != 0)
            {
                fc.fontsize = cf2.yHeight / 20f; /*again, this may not be right. why 20?*/
            }
            return(fc);
        }
Exemplo n.º 2
0
        public void SetFormatChanges(FormatChanges fc)
        {
            if (fc.color != Color.Empty)
            {
                SelectionColor = fc.color;
            }
            if (fc.font != null)
            {
                SelectionFont = fc.font;
            }

            STRUCT_CHARFORMAT2 cf2 = new STRUCT_CHARFORMAT2();

            if (fc.fontfamily != String.Empty)
            {
                cf2.dwMask    |= CFM_FACE;
                cf2.szFaceName = fc.fontfamily;
            }
            if (fc.fontsize != 0f)
            {
                cf2.dwMask |= CFM_SIZE;
                cf2.yHeight = (int)(fc.fontsize * 20f); /*no idea if this is correct conversion*/
            }
            if (fc.bold != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_BOLD;
                if (fc.bold == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_BOLD;
                }
            }
            if (fc.italic != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_ITALIC;
                if (fc.italic == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_ITALIC;
                }
            }
            if (fc.underline != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_UNDERLINE;
                if (fc.underline == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_UNDERLINE;
                }
            }
            if (fc.strikeout != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_STRIKEOUT;
                if (fc.strikeout == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_STRIKEOUT;
                }
            }
            if (fc.superscript != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_SUPERSCRIPT;
                if (fc.superscript == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_SUPERSCRIPT;
                }
            }
            if (fc.subscript != Ternary.Indeterminate)
            {
                cf2.dwMask |= CFM_SUBSCRIPT;
                if (fc.subscript == Ternary.Yes)
                {
                    cf2.dwEffects |= CFE_SUBSCRIPT;
                }
            }
            if (cf2.dwMask != 0)
            {
                SetCharFormat(ref cf2);
            }
        }