Example #1
0
        public static BBCodeStyle fuseStyleHierarchy(List <BBCodeStyle> parentToChildHierarchy)
        {
            if (parentToChildHierarchy == null || parentToChildHierarchy.Count < 1)
            {
                return(null);
            }

            if (parentToChildHierarchy.Count == 1)
            {
                return(parentToChildHierarchy[0].clone());
            }

            BBCodeStyle t = parentToChildHierarchy[0].clone();

            if (t.foreColor == null)
            {
                t.foreColor = new Color(0x000000, Mode.NORMAL);
            }
            if (t.backColor == null)
            {
                t.backColor = new Color(0xCC99CC, Mode.NORMAL);
            }

            if (t.isBold == StateMode.DEFAULT)
            {
                t.isBold = StateMode.OFF;
            }
            if (t.isItalic == StateMode.DEFAULT)
            {
                t.isItalic = StateMode.OFF;
            }
            if (t.isStriked == StateMode.DEFAULT)
            {
                t.isStriked = StateMode.OFF;
            }
            if (t.isUnderlined == StateMode.DEFAULT)
            {
                t.isUnderlined = StateMode.OFF;
            }

            if (!t.isAbsFontSize)
            {
                t.isAbsFontSize = true;

                if (t.fontSize <= 0.0f)
                {
                    t.fontSize = 12.0f;
                }
            }

            int i, l = parentToChildHierarchy.Count;

            for (i = 1; i < l; i++)
            {
                t = fuseStyles(parentToChildHierarchy[i], t);
            }

            return(t);
        }
Example #2
0
        public static BBCodeStyle fuseStyles(BBCodeStyle child, BBCodeStyle parent)
        {
            if (parent == null)
                return child != null ? child.clone() : null;

            if (child == null)
                return parent.clone();

            BBCodeStyle outStyle = child.clone();

            if (outStyle.isBold == StateMode.DEFAULT)
                outStyle.isBold = parent.isBold;

            if (outStyle.isItalic == StateMode.DEFAULT)
                outStyle.isItalic = parent.isItalic;

            if (outStyle.isStriked == StateMode.DEFAULT)
                outStyle.isStriked = parent.isStriked;

            if (outStyle.isUnderlined == StateMode.DEFAULT)
                outStyle.isUnderlined = parent.isUnderlined;

            if (outStyle.fontSize == 0)
            {
                outStyle.fontSize = parent.fontSize;
                outStyle.isAbsFontSize = parent.isAbsFontSize;
            }
            else
            {
                if (!outStyle.isAbsFontSize)
                {
                    outStyle.isAbsFontSize = parent.isAbsFontSize && parent.fontSize != 0;
                    outStyle.fontSize = parent.fontSize + outStyle.fontSize;
                }
                else
                {
                    if (outStyle.fontSize < 0)
                        outStyle.fontSize = 1;
                }
            }

            if (string.IsNullOrEmpty(outStyle.fontName))
                outStyle.fontName = parent.fontName;

            if (outStyle.backColor == null)
                outStyle.backColor = parent.backColor;
            else
                outStyle.backColor = Color.Mix(parent.backColor, outStyle.backColor);

            if (outStyle.foreColor == null)
                outStyle.foreColor = parent.foreColor;
            else
                outStyle.foreColor = Color.Mix(outStyle.backColor, outStyle.foreColor);

            return outStyle;
        }
Example #3
0
		public static void applyStyleToTextbox(BBCodeStyle style, RichTextBox tf, int selStart, int selEnd)
		{
			if (style == null || tf == null || selEnd <= selStart || selEnd < 0)
				return;

			tf.Select(selStart, selEnd);

			FontStyle fontStyle = tf.Font.Style;
			String fontName = tf.Font.Name;
			float fontSize = tf.Font.Size;


			if (style.isBold == StateMode.ON)
				fontStyle |= FontStyle.Bold;
			else if (style.isBold == StateMode.OFF)
				fontStyle &= ~FontStyle.Bold;

			if (style.isItalic == StateMode.ON)
				fontStyle |= FontStyle.Italic;
			else if (style.isItalic == StateMode.OFF)
				fontStyle &= ~FontStyle.Italic;

			if (style.isUnderlined == StateMode.ON)
				fontStyle |= FontStyle.Underline;
			else if (style.isUnderlined == StateMode.OFF)
				fontStyle &= ~FontStyle.Underline;

			if (style.isStriked == StateMode.ON)
				fontStyle |= FontStyle.Strikeout;
			else if (style.isStriked == StateMode.OFF)
				fontStyle &= ~FontStyle.Strikeout;


			if (style.fontSize > 0)
				fontSize = (float)style.fontSize;
			else if (style.fontSize < 0)
				fontSize += (float)style.fontSize;

			if (style.fontName != null && style.fontName.Length > 0)
				fontName = style.fontName;


			if (style.foreColor != null)
				tf.SelectionColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.foreColor.color & 0xFFFFFF)));

			if (style.backColor != null)
				tf.SelectionBackColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.backColor.color & 0xFFFFFF)));


			Font font = new Font(fontName, (float)(fontSize > 1.0f ? fontSize : 1.0f), fontStyle);
			tf.SelectionFont = font;
		}
Example #4
0
        public BBCodeStyle clone()
        {
            BBCodeStyle c = new BBCodeStyle();

            c.isBold        = this.isBold;
            c.isItalic      = this.isItalic;
            c.isStriked     = this.isStriked;
            c.isUnderlined  = this.isUnderlined;
            c.fontName      = this.fontName;
            c.fontSize      = this.fontSize;
            c.isAbsFontSize = this.isAbsFontSize;
            c.foreColor     = this.foreColor == null ? null : this.foreColor.clone();
            c.backColor     = this.backColor == null ? null : this.backColor.clone();

            return(c);
        }
Example #5
0
        public static BBCodeStyle getCascadedNodeStyle(IndexTree tree)
        {
            if (tree == null)
            {
                return(null);
            }

            List <BBCodeStyle> styleHierarchy = new List <BBCodeStyle>();
            IndexTree          currTree       = tree;

            while (currTree != null)
            {
                styleHierarchy.Add(getNodeStyle(currTree));
                currTree = currTree.parentNode;
            }
            styleHierarchy.Reverse();

            return(BBCodeStyle.fuseStyleHierarchy(styleHierarchy));
        }
Example #6
0
        public static BBCodeStyle fuseStyles(BBCodeStyle child, BBCodeStyle parent)
        {
            if (parent == null)
            {
                return(child != null?child.clone() : null);
            }

            if (child == null)
            {
                return(parent.clone());
            }

            BBCodeStyle outStyle = child.clone();

            if (outStyle.isBold == StateMode.DEFAULT)
            {
                outStyle.isBold = parent.isBold;
            }

            if (outStyle.isItalic == StateMode.DEFAULT)
            {
                outStyle.isItalic = parent.isItalic;
            }

            if (outStyle.isStriked == StateMode.DEFAULT)
            {
                outStyle.isStriked = parent.isStriked;
            }

            if (outStyle.isUnderlined == StateMode.DEFAULT)
            {
                outStyle.isUnderlined = parent.isUnderlined;
            }

            if (outStyle.fontSize == 0)
            {
                outStyle.fontSize      = parent.fontSize;
                outStyle.isAbsFontSize = parent.isAbsFontSize;
            }
            else
            {
                if (!outStyle.isAbsFontSize)
                {
                    outStyle.isAbsFontSize = (bool)(parent.isAbsFontSize && parent.fontSize != 0);
                    outStyle.fontSize      = parent.fontSize + outStyle.fontSize;
                }
                else
                {
                    if (outStyle.fontSize < 0)
                    {
                        outStyle.fontSize = 1;
                    }
                }
            }

            if (string.IsNullOrEmpty(outStyle.fontName))
            {
                outStyle.fontName = parent.fontName;
            }

            if (outStyle.backColor == null)
            {
                outStyle.backColor = parent.backColor;
            }
            else
            {
                outStyle.backColor = Color.Mix(parent.backColor, outStyle.backColor);
            }

            if (outStyle.foreColor == null)
            {
                outStyle.foreColor = parent.foreColor;
            }
            else
            {
                outStyle.foreColor = Color.Mix(outStyle.backColor, outStyle.foreColor);
            }

            return(outStyle);
        }
Example #7
0
        public BBCodeStyle clone()
        {
            BBCodeStyle c = new BBCodeStyle();

            c.isBold = this.isBold;
            c.isItalic = this.isItalic;
            c.isStriked = this.isStriked;
            c.isUnderlined = this.isUnderlined;
            c.fontName = this.fontName;
            c.fontSize = this.fontSize;
            c.isAbsFontSize = this.isAbsFontSize;
            c.foreColor = this.foreColor == null ? null : this.foreColor.clone();
            c.backColor = this.backColor == null ? null : this.backColor.clone();

            return c;
        }
Example #8
0
		public static void applyStyleTreeToTextbox(RichTextBox tf, String input, IndexTree bbCodeTree)
		{
			if (tf == null || bbCodeTree == null || input == null || input.Length < 1)
				return;

			tf.Text = "";

			BBCodeStyle rootStyle = new BBCodeStyle();
			rootStyle.isAbsFontSize = false;
			rootStyle.fontName = tf.Font.Name;
			rootStyle.fontSize = tf.Font.Size;
			rootStyle.isAbsFontSize = true;
			rootStyle.foreColor = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
			rootStyle.backColor = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionBackColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
			rootStyle.isBold = tf.Font.Bold ? StateMode.ON : StateMode.OFF;
			rootStyle.isItalic = tf.Font.Italic ? StateMode.ON : StateMode.OFF;
			rootStyle.isStriked = tf.Font.Strikeout ? StateMode.ON : StateMode.OFF;
			rootStyle.isUnderlined = tf.Font.Underline ? StateMode.ON : StateMode.OFF;

			PairTag rootPair = new PairTag(new BBCodeTagMatch(true, 0, "", "", "", 0, 0, false), new VoidCloserTagMatch(input.Length));
			(rootPair.openerMatch as BBCodeTagMatch).bbCodeStyle = rootStyle;

			bbCodeTree = IndexTree.cloneTree(bbCodeTree);
			bbCodeTree.data = rootPair;

			List<IndexTree> flatTree = IndexTree.flattenTree(bbCodeTree);
			String flatText = BBCodeUtils.assembleOutput(input, bbCodeTree);
			String corrFlatText = _replaceEnclosures(flatText);

			IndexTree.normalizeTree(bbCodeTree);
			flatTree = IndexTree.flattenTree(bbCodeTree);

			tf.Text = corrFlatText/*flatText*/;

			if (flatText == input)
				return;

			String currText;
			String currCorrText;
			int offsetA = 0;
			int offsetB = 0;
			int idxA, idxB;
			int i = -1;
			int l = flatTree.Count;
			while (++i < l)
			{
				idxA = flatTree[i].indexA;
				idxB = flatTree[i].indexB;

				currText = flatText.Substring(idxA, idxB - idxA);
				currCorrText = _replaceEnclosures(currText);

				offsetB = currCorrText.Length + idxA - idxB;

				applyStyleToTextbox(BBCodeUtils.getCascadedNodeStyle(flatTree[i]),
									tf,
									idxA + offsetA,
									idxB + offsetA + offsetB);

				offsetA += offsetB;
			}

			tf.Select(tf.Text.Length, tf.Text.Length);
		}
Example #9
0
        public static void applyStyleToTextbox(BBCodeStyle style, RichTextBox tf, int selStart, int selEnd)
        {
            if (style == null || tf == null || selEnd <= selStart || selEnd < 0)
            {
                return;
            }

            tf.Select(selStart, selEnd);

            FontStyle fontStyle = tf.Font.Style;
            String    fontName  = tf.Font.Name;
            float     fontSize  = tf.Font.Size;


            if (style.isBold == StateMode.ON)
            {
                fontStyle |= FontStyle.Bold;
            }
            else if (style.isBold == StateMode.OFF)
            {
                fontStyle &= ~FontStyle.Bold;
            }

            if (style.isItalic == StateMode.ON)
            {
                fontStyle |= FontStyle.Italic;
            }
            else if (style.isItalic == StateMode.OFF)
            {
                fontStyle &= ~FontStyle.Italic;
            }

            if (style.isUnderlined == StateMode.ON)
            {
                fontStyle |= FontStyle.Underline;
            }
            else if (style.isUnderlined == StateMode.OFF)
            {
                fontStyle &= ~FontStyle.Underline;
            }

            if (style.isStriked == StateMode.ON)
            {
                fontStyle |= FontStyle.Strikeout;
            }
            else if (style.isStriked == StateMode.OFF)
            {
                fontStyle &= ~FontStyle.Strikeout;
            }


            if (style.fontSize > 0)
            {
                fontSize = (float)style.fontSize;
            }
            else if (style.fontSize < 0)
            {
                fontSize += (float)style.fontSize;
            }

            if (!string.IsNullOrEmpty(style.fontName))
            {
                fontName = style.fontName;
            }


            if (style.foreColor != null)
            {
                tf.SelectionColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.foreColor.color & 0xFFFFFF)));
            }

            if (style.backColor != null)
            {
                tf.SelectionBackColor = Color.FromArgb((int)((uint)(0xFF000000) | (uint)(style.backColor.color & 0xFFFFFF)));
            }


            Font font = new Font(fontName, (float)(fontSize > 1.0f ? fontSize : 1.0f), fontStyle);

            tf.SelectionFont = font;
        }
Example #10
0
        public static void applyStyleTreeToTextbox(RichTextBox tf, String input, IndexTree bbCodeTree)
        {
            if (tf == null || bbCodeTree == null || string.IsNullOrEmpty(input))
            {
                return;
            }

            tf.Text = "";

            BBCodeStyle rootStyle = new BBCodeStyle();

            rootStyle.isAbsFontSize = false;
            rootStyle.fontName      = tf.Font.Name;
            rootStyle.fontSize      = tf.Font.Size;
            rootStyle.isAbsFontSize = true;
            rootStyle.foreColor     = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
            rootStyle.backColor     = new BBCodeStyle.Color((uint)0xFF000000 | (uint)(tf.SelectionBackColor.ToArgb() & (int)0xFFFFFF), BBCodeStyle.Mode.NORMAL);
            rootStyle.isBold        = tf.Font.Bold ? StateMode.ON : StateMode.OFF;
            rootStyle.isItalic      = tf.Font.Italic ? StateMode.ON : StateMode.OFF;
            rootStyle.isStriked     = tf.Font.Strikeout ? StateMode.ON : StateMode.OFF;
            rootStyle.isUnderlined  = tf.Font.Underline ? StateMode.ON : StateMode.OFF;

            PairTag rootPair = new PairTag(new BBCodeTagMatch(true, 0, "", "", "", 0, 0, false), new VoidCloserTagMatch(input.Length));

            (rootPair.openerMatch as BBCodeTagMatch).bbCodeStyle = rootStyle;

            bbCodeTree      = IndexTree.cloneTree(bbCodeTree);
            bbCodeTree.data = rootPair;

            List <IndexTree> flatTree     = IndexTree.flattenTree(bbCodeTree);
            String           flatText     = assembleOutput(input, bbCodeTree);
            String           corrFlatText = _replaceEnclosures(flatText);

            IndexTree.normalizeTree(bbCodeTree);
            flatTree = IndexTree.flattenTree(bbCodeTree);

            tf.Text = corrFlatText /*flatText*/;

            if (flatText == input)
            {
                return;
            }

            String currText;
            String currCorrText;
            int    offsetA = 0;
            int    offsetB = 0;
            int    idxA, idxB;
            int    i = -1;
            int    l = flatTree.Count;

            while (++i < l)
            {
                idxA = flatTree[i].indexA;
                idxB = flatTree[i].indexB;

                currText     = flatText.Substring(idxA, idxB - idxA);
                currCorrText = _replaceEnclosures(currText);

                offsetB = currCorrText.Length + idxA - idxB;

                applyStyleToTextbox(getCascadedNodeStyle(flatTree[i]),
                                    tf,
                                    idxA + offsetA,
                                    idxB + offsetA + offsetB);

                offsetA += offsetB;
            }

            tf.Select(tf.Text.Length, tf.Text.Length);
        }