Exemple #1
0
        /// <summary>
        /// Checks if format of two characters is identical
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool compareFormat(RTFChar other)
        {
            if (this.fontIndex != other.fontIndex)
            {
                return(false);
            }
            if (this.col != other.col)
            {
                return(false);
            }
            if (this.FontStyle != other.FontStyle)
            {
                return(false);
            }
            if (this.size != other.size)
            {
                return(false);
            }

            //no formating diferences were found
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Concatinated two lines into one.
        /// </summary>
        /// <param name="fl1">First formattedLine</param>
        /// <param name="fl2">Second formattedLine</param>
        /// <returns>Concatinated version of the two lines</returns>
        public static RTFLine operator +(RTFLine fl1, RTFLine fl2)
        {
            RTFLine newLine = fl1;

            if (fl1.data == null)
            {
                return(fl2);
            }

            if (fl2.data == null)
            {
                return(fl1);
            }

            RTFChar[] newData = new RTFChar[fl1.data.Length + fl2.data.Length];
            fl1.data.CopyTo(newData, 0);
            fl2.data.CopyTo(newData, fl1.data.Length);

            newLine.data = newData;

            return(newLine);
        }
Exemple #3
0
        /// <summary>
        /// Creates a RTFString from rtf code.
        /// </summary>
        /// <param name="rtf">rtf code.</param>
        /// <returns>A formattedString version of the rtf code.</returns>
        public RTFString parseRTF(string rtf)
        {
            rtCapture.Rtf = rtf;

            rtCapture.SelectAll();
            int numChars = rtCapture.SelectionLength;

            RTFString text = new RTFString();

            text.invalidateMesurements();
            RTFLine   currentLine = new RTFLine();
            RTFChar   currentChar = new RTFChar();
            ArrayList fontTable   = new ArrayList();
            int       fontIndex;

            int i;

            for (i = 0; i < numChars; i++)
            {
                rtCapture.Select(i, 1);
                currentChar.FontStyle = rtCapture.SelectionFont.Style;
                currentChar.size      = rtCapture.SelectionFont.Size;
                currentChar.Char      = rtCapture.SelectedText[0];
                currentChar.col       = rtCapture.SelectionColor;
                if (currentChar.Char == '\r')
                {
                    //do nothing
                }
                else if (currentChar.Char == '\n')
                {
                    if (currentLine.count == 0)
                    {
                        fontIndex = fontTable.IndexOf(rtCapture.SelectionFont.FontFamily);
                        if (fontIndex == -1)
                        {
                            fontIndex = fontTable.Add(rtCapture.SelectionFont.FontFamily);
                        }

                        currentChar.fontIndex = fontIndex;

                        //append to line
                        currentLine += currentChar;
                    }

                    //end line
                    currentLine.horizontalAllignment = rtCapture.SelectionAlignment;
                    currentLine.bulleted             = rtCapture.SelectionBullet;
                    text       += currentLine;
                    currentLine = new RTFLine();
                }
                else
                {
                    //check font table
                    fontIndex = fontTable.IndexOf(rtCapture.SelectionFont.FontFamily);
                    if (fontIndex == -1)
                    {
                        fontIndex = fontTable.Add(rtCapture.SelectionFont.FontFamily);
                    }

                    currentChar.fontIndex = fontIndex;

                    //append to line
                    currentLine += currentChar;
                }
            }

            //check if last line was not terminated and needs apending
            if (currentLine.data != null)
            {
                if (currentLine.data.Length > 0)
                {
                    currentLine.horizontalAllignment = rtCapture.SelectionAlignment;
                    text += currentLine;
                }
            }

            //build the font table
            text.fontTable = new FontFamily[fontTable.Count];
            for (i = 0; i < fontTable.Count; i++)
            {
                text.fontTable[i] = (FontFamily)fontTable[i];
            }

            return(text);
        }