Ejemplo n.º 1
0
        public override RTFStyleDescriptor GetRTF()
        {
            var result = new RTFStyleDescriptor();

            if (BackgroundBrush is SolidBrush)
            {
                result.BackColor = (BackgroundBrush as SolidBrush).Color;
            }

            if (ForeBrush is SolidBrush)
            {
                result.ForeColor = (ForeBrush as SolidBrush).Color;
            }

            if ((FontStyle & FontStyle.Bold) != 0)
            {
                result.AdditionalTags += @"\b";
            }
            if ((FontStyle & FontStyle.Italic) != 0)
            {
                result.AdditionalTags += @"\i";
            }
            if ((FontStyle & FontStyle.Strikeout) != 0)
            {
                result.AdditionalTags += @"\strike";
            }
            if ((FontStyle & FontStyle.Underline) != 0)
            {
                result.AdditionalTags += @"\ul";
            }

            return(result);
        }
Ejemplo n.º 2
0
        private RTFStyleDescriptor GetRtfDescriptor(StyleIndex styleIndex)
        {
            var styles = new List <Style>();
            //find text renderer
            TextStyle textStyle    = null;
            int       mask         = 1;
            bool      hasTextStyle = false;

            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                {
                    if (tb.Styles[i].IsExportable)
                    {
                        Style style = tb.Styles[i];
                        styles.Add(style);

                        bool isTextStyle = style is TextStyle;
                        if (isTextStyle)
                        {
                            if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                            {
                                hasTextStyle = true;
                                textStyle    = style as TextStyle;
                            }
                        }
                    }
                }
                mask = mask << 1;
            }
            //add TextStyle css
            RTFStyleDescriptor result = null;

            if (!hasTextStyle)
            {
                //draw by default renderer
                result = tb.DefaultStyle.GetRTF();
            }
            else
            {
                result = textStyle.GetRTF();
            }

            return(result);
        }
Ejemplo n.º 3
0
        private void Flush(StringBuilder sb, StringBuilder tempSB, StyleIndex currentStyle)
        {
            //find textRenderer
            if (tempSB.Length == 0)
            {
                return;
            }

            RTFStyleDescriptor desc = GetRtfDescriptor(currentStyle);
            int cf   = GetColorTableNumber(desc.ForeColor);
            int cb   = GetColorTableNumber(desc.BackColor);
            var tags = new StringBuilder();

            if (cf >= 0)
            {
                tags.AppendFormat(@"\cf{0}", cf);
            }
            if (cb >= 0)
            {
                tags.AppendFormat(@"\highlight{0}", cb);
            }
            if (!string.IsNullOrEmpty(desc.AdditionalTags))
            {
                tags.Append(desc.AdditionalTags.Trim());
            }

            if (tags.Length > 0)
            {
                sb.AppendFormat(@"{{{0} {1}}}", tags, tempSB);
            }
            else
            {
                sb.Append(tempSB);
            }
            tempSB.Length = 0;
        }