Beispiel #1
0
 private static void SetFormat(LineTag tag, Font font, Color color, Color back_color, TextPositioning text_position,
                               float char_offset, bool visible, FormatSpecified specified)
 {
     if ((FormatSpecified.Font & specified) == FormatSpecified.Font)
     {
         tag.Font = font;
     }
     if ((FormatSpecified.Color & specified) == FormatSpecified.Color)
     {
         tag.color = color;
     }
     if ((FormatSpecified.BackColor & specified) == FormatSpecified.BackColor)
     {
         tag.back_color = back_color;
     }
     if ((FormatSpecified.TextPosition & specified) == FormatSpecified.TextPosition)
     {
         tag.TextPosition = text_position;
     }
     if ((FormatSpecified.CharOffset & specified) == FormatSpecified.CharOffset)
     {
         tag.CharOffset = char_offset;
     }
     if ((FormatSpecified.Visibility & specified) == FormatSpecified.Visibility)
     {
         tag.Visible = visible;
     }
     // Console.WriteLine ("setting format:   {0}  {1}   new color {2}", color.Color, specified, tag.color.Color);
 }
Beispiel #2
0
		/// <summary>Format area of document in specified font and color</summary>
		/// <param name="start_pos">1-based start position on start_line</param>
		/// <param name="end_pos">1-based end position on end_line </param>
		internal void FormatText (Line start_line, int start_pos, Line end_line, int end_pos, Font font,
				Color color, Color back_color, FormatSpecified specified)
		{
			Line    l;

			// First, format the first line
			if (start_line != end_line) {
				// First line
				LineTag.FormatText(start_line, start_pos, start_line.text.Length - start_pos + 1, font, color, back_color, specified);

				// Format last line
				LineTag.FormatText(end_line, 1, end_pos, font, color, back_color, specified);

				// Now all the lines inbetween
				for (int i = start_line.line_no + 1; i < end_line.line_no; i++) {
					l = GetLine(i);
					LineTag.FormatText(l, 1, l.text.Length, font, color, back_color, specified);
				}
			} else {
				// Special case, single line
				LineTag.FormatText(start_line, start_pos, end_pos - start_pos, font, color, back_color, specified);
				
				if ((end_pos - start_pos) == 0 && CaretTag.Length != 0)
					CaretTag = CaretTag.Next;
			}
		}
		private static void SetFormat (LineTag tag, Font font, Color color, Color back_color, FormatSpecified specified)
		{
			if ((FormatSpecified.Font & specified) == FormatSpecified.Font) {
				tag.Font = font;
			}
			if ((FormatSpecified.Color & specified) == FormatSpecified.Color)
				tag.color = color;
			if ((FormatSpecified.BackColor & specified) == FormatSpecified.BackColor) {
				tag.back_color = back_color;
			}
			// Console.WriteLine ("setting format:   {0}  {1}   new color {2}", color.Color, specified, tag.color.Color);
		}
		/// <summary>Applies 'font' and 'brush' to characters starting at 'start' for 'length' chars; 
		/// Removes any previous tags overlapping the same area; 
		/// returns true if lineheight has changed</summary>
		/// <param name="formatStart">1-based character position on line</param>
		public static bool FormatText (Line line, int formatStart, int length, Font font, Color color, Color backColor, FormatSpecified specified)
		{
			LineTag tag;
			LineTag start_tag;
			LineTag end_tag;
			int end;
			bool retval = false;		// Assume line-height doesn't change

			// Too simple?
			if (((FormatSpecified.Font & specified) == FormatSpecified.Font) && font.Height != line.height)
				retval = true;

			line.recalc = true;		// This forces recalculation of the line in RecalculateDocument

			// A little sanity, not sure if it's needed, might be able to remove for speed
			if (length > line.text.Length)
				length = line.text.Length;

			tag = line.tags;
			end = formatStart + length;

			// Common special case
			if ((formatStart == 1) && (length == tag.Length)) {
				SetFormat (tag, font, color, backColor, specified);
				return retval;
			}

			// empty selection style at begining of line means
			// we only need one new tag
			if  (formatStart == 1 && length == 0) {
				line.tags.Break (1);
				SetFormat (line.tags, font, color, backColor, specified);
				return retval;
			}

			start_tag = FindTag (line, formatStart - 1);

			// we are at an empty tag already!
			// e.g. [Tag 0 - "He"][Tag 1 = 0 length][Tag 2 "llo world"]
			// Find Tag will return tag 0 at position 3, but we should just
			// use the empty tag after..
			if (start_tag.End == formatStart && length == 0 && start_tag.Next != null && start_tag.Next.Length == 0) {
				SetFormat (start_tag.Next, font, color, backColor, specified);
				return retval;
			}

			// if we are at the end of a tag, we want to move to the next tag
			while (start_tag.End == formatStart && start_tag.Next != null)
				start_tag = start_tag.Next;

			tag = start_tag.Break (formatStart);

			// empty selection style at end of line - its the only situation
			// where the rest of the tag would be empty, since we moved to the
			// begining of next non empty tag
			if (tag.Length == 0) {
				SetFormat (tag, font, color, backColor, specified);
				return retval;
			}

			// empty - so we just create another tag for
			// after our new (now) empty one..
			if (length == 0) {
				tag.Break (formatStart);
				SetFormat (tag, font, color, backColor, specified);
				return retval;
			}

			while (tag != null && tag.End <= end) {
				SetFormat (tag, font, color, backColor, specified);
				tag = tag.next;
			}

			// did the last tag conveniently fit?
			if (tag != null && tag.End == end)
				return retval;

			/// Now do the last tag
			end_tag = FindTag (line, end-1);

			if (end_tag != null) {
				end_tag.Break (end);
				SetFormat (end_tag, font, color, backColor, specified);
			}

			return retval;
		}
Beispiel #5
0
 private static void SetFormat(LineTag tag, Font font, Color_ color, Color_ back_color, FormatSpecified specified)
 {
     if ((FormatSpecified.Font & specified) == FormatSpecified.Font)
     {
         tag.Font = font;
     }
     if ((FormatSpecified.Color & specified) == FormatSpecified.Color)
     {
         tag.color = color;
     }
     if ((FormatSpecified.BackColor & specified) == FormatSpecified.BackColor)
     {
         tag.back_color = back_color;
     }
     // Console.WriteLine ("setting format:   {0}  {1}   new Color_ {2}", color.Color, specified, tag.color.Color);
 }
Beispiel #6
0
        /// <summary>Applies 'font' and 'brush' to characters starting at 'start' for 'length' chars;
        /// Removes any previous tags overlapping the same area;
        /// returns true if lineheight has changed</summary>
        /// <param name="formatStart">1-based character position on line</param>
        public static bool FormatText(Line line, int formatStart, int length, Font font, Color_ color, Color_ backColor, FormatSpecified specified)
        {
            LineTag tag;
            LineTag start_tag;
            LineTag end_tag;
            int     end;
            bool    retval = false;                     // Assume line-height doesn't change

            // Too simple?
            if (((FormatSpecified.Font & specified) == FormatSpecified.Font) && font.Height != line.height)
            {
                retval = true;
            }

            line.recalc = true;                         // This forces recalculation of the line in RecalculateDocument

            // A little sanity, not sure if it's needed, might be able to remove for speed
            if (length > line.text.Length)
            {
                length = line.text.Length;
            }

            tag = line.tags;
            end = formatStart + length;

            // Common special case
            if ((formatStart == 1) && (length == tag.Length))
            {
                SetFormat(tag, font, color, backColor, specified);
                return(retval);
            }

            // empty selection style at begining of line means
            // we only need one new tag
            if (formatStart == 1 && length == 0)
            {
                line.tags.Break(1);
                SetFormat(line.tags, font, color, backColor, specified);
                return(retval);
            }

            start_tag = FindTag(line, formatStart - 1);

            // we are at an empty tag already!
            // e.g. [Tag 0 - "He"][Tag 1 = 0 length][Tag 2 "llo world"]
            // Find Tag will return tag 0 at position 3, but we should just
            // use the empty tag after..
            if (start_tag.End == formatStart && length == 0 && start_tag.Next != null && start_tag.Next.Length == 0)
            {
                SetFormat(start_tag.Next, font, color, backColor, specified);
                return(retval);
            }

            // if we are at the end of a tag, we want to move to the next tag
            while (start_tag.End == formatStart && start_tag.Next != null)
            {
                start_tag = start_tag.Next;
            }

            tag = start_tag.Break(formatStart);

            // empty selection style at end of line - its the only situation
            // where the rest of the tag would be empty, since we moved to the
            // begining of next non empty tag
            if (tag.Length == 0)
            {
                SetFormat(tag, font, color, backColor, specified);
                return(retval);
            }

            // empty - so we just create another tag for
            // after our new (now) empty one..
            if (length == 0)
            {
                tag.Break(formatStart);
                SetFormat(tag, font, color, backColor, specified);
                return(retval);
            }

            while (tag != null && tag.End <= end)
            {
                SetFormat(tag, font, color, backColor, specified);
                tag = tag.next;
            }

            // did the last tag conveniently fit?
            if (tag != null && tag.End == end)
            {
                return(retval);
            }

            /// Now do the last tag
            end_tag = FindTag(line, end - 1);

            if (end_tag != null)
            {
                end_tag.Break(end);
                SetFormat(end_tag, font, color, backColor, specified);
            }

            return(retval);
        }
Beispiel #7
0
 private static void SetFormat(LineTag tag, Font font, Color color, Color back_color, FormatSpecified specified)
 {
     SetFormat(tag, font, color, back_color, TextPositioning.Normal, 0, true, specified);
 }
Beispiel #8
0
 public static bool FormatText(Line line, int formatStart, int length, Font font, Color color, Color backColor, FormatSpecified specified)
 {
     return(FormatText(line, formatStart, length, font, color, backColor, TextPositioning.Normal, 0, true, specified));
 }