示例#1
0
        /// <summary>
        /// Copyies chars at some position with defined length.
        /// </summary>
        /// <param name="pos">starting position to copy chars</param>
        /// <param name="length">length of copied chars</param>
        /// <returns></returns>
        public List <FastColoredTextBoxNS.Char> CopyChars(int pos, int length)
        {
            var result = new List <FastColoredTextBoxNS.Char>();

            if (pos >= Length)
            {
                return(result);
            }

            int    copyLength = Math.Min(length, Length - pos);
            string s          = Text.Substring(pos, copyLength);

            result.Capacity = copyLength;
            foreach (var c in s)
            {
                var fctb_c = new FastColoredTextBoxNS.Char
                {
                    c     = c,
                    style = GetStyleIndex(pos)
                };
                result.Add(fctb_c);
                pos++;
            }

            return(result);
        }
示例#2
0
文件: CwFCTB.cs 项目: VLiance/Cwc-src
        /// <summary>
        /// Appends style to chars of range
        /// </summary>
        public void SetStyles(StyleIndex _oFrontIndex, int _nFrontColor, StyleIndex _oBackIndex, int _nBackColor)
        {
            //set code to chars
            int fromLine = Math.Min(End.iLine, Start.iLine);
            int toLine   = Math.Max(End.iLine, Start.iLine);
            int fromChar = FromX;
            int toChar   = ToX;

            if (fromLine < 0)
            {
                return;
            }
            //
            for (int y = fromLine; y <= toLine; y++)
            {
                int fromX = y == fromLine ? fromChar : 0;
                int toX   = y == toLine?Math.Min(toChar - 1, tb[y].Count - 1) : tb[y].Count - 1;

                for (int x = fromX; x <= toX; x++)
                {
                    FastColoredTextBoxNS.Char c = tb[y][x];

                    c.style |= _oFrontIndex | _oBackIndex;
                    //     c.style |= _oFrontIndex ;
                    c.nCustomData = (ushort)(_nFrontColor | (_nBackColor << 4));
                    tb[y][x]      = c;
                }
            }
        }
示例#3
0
        public string GetHtml(Range r)
        {
            this.tb = r.tb;
            Dictionary <StyleIndex, object> styles = new Dictionary <StyleIndex, object>();
            StringBuilder sb             = new StringBuilder();
            StringBuilder tempSB         = new StringBuilder();
            StyleIndex    currentStyleId = StyleIndex.None;

            r.Normalize();
            int currentLine = r.Start.iLine;

            styles[currentStyleId] = null;
            //
            if (UseOriginalFont)
            {
                sb.AppendFormat("<font style=\"font-family: {0}, monospace; font-size: {1}px; line-height: {2}px;\">",
                                r.tb.Font.Name, r.tb.CharHeight - r.tb.LineInterval, r.tb.CharHeight);
            }
            //
            if (IncludeLineNumbers)
            {
                tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", currentLine + 1);
            }
            //
            bool hasNonSpace = false;

            foreach (Place p in r)
            {
                Char c = r.tb[p.iLine][p.iChar];
                if (c.style != currentStyleId)
                {
                    Flush(sb, tempSB, currentStyleId);
                    currentStyleId         = c.style;
                    styles[currentStyleId] = null;
                }

                if (p.iLine != currentLine)
                {
                    for (int i = currentLine; i < p.iLine; i++)
                    {
                        tempSB.AppendLine(UseBr ? "<br>" : "");
                        if (IncludeLineNumbers)
                        {
                            tempSB.AppendFormat("<span class=lineNumber>{0}</span>  ", i + 2);
                        }
                    }
                    currentLine = p.iLine;
                    hasNonSpace = false;
                }
                switch (c.c)
                {
                case ' ':
                    if ((hasNonSpace || !UseForwardNbsp) && !UseNbsp)
                    {
                        goto default;
                    }

                    tempSB.Append("&nbsp;");
                    break;

                case '<':
                    tempSB.Append("&lt;");
                    break;

                case '>':
                    tempSB.Append("&gt;");
                    break;

                case '&':
                    tempSB.Append("&amp;");
                    break;

                default:
                    hasNonSpace = true;
                    tempSB.Append(c.c);
                    break;
                }
            }
            Flush(sb, tempSB, currentStyleId);

            if (UseOriginalFont)
            {
                sb.AppendLine("</font>");
            }

            //build styles
            if (UseStyleTag)
            {
                tempSB.Length = 0;
                tempSB.AppendLine("<style type=\"text/css\">");
                foreach (var styleId in styles.Keys)
                {
                    tempSB.AppendFormat(".fctb{0}{{ {1} }}\r\n", GetStyleName(styleId), GetCss(styleId));
                }
                tempSB.AppendLine("</style>");

                sb.Insert(0, tempSB.ToString());
            }

            if (IncludeLineNumbers)
            {
                sb.Insert(0, LineNumbersCSS);
            }

            return(sb.ToString());
        }