Exemplo n.º 1
0
        public static string ConvertTextOptionsToString(StiTextOptions op, char separator)
        {
            //return string.Format(
            //    "HotkeyPrefix={1}{0} LineLimit={2}{0} RightToLeft={3}{0} Trimming={4}{0} WordWrap={5}{0} Angle={6}{0} FirstTabOffset={7}{0} DistanceBetweenTabs={8}{0}",
            //    separator,
            //    op.HotkeyPrefix,
            //    op.LineLimit,
            //    op.RightToLeft,
            //    op.Trimming,
            //    op.WordWrap,
            //    op.Angle,
            //    op.FirstTabOffset,
            //    op.DistanceBetweenTabs);

            string format = (op.FirstTabOffset == 40f && op.DistanceBetweenTabs == 20f) ? "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}" : "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}";

            return(string.Format(format, separator,
                                 op.HotkeyPrefix != HotkeyPrefix.None ? "HotkeyPrefix=" + op.HotkeyPrefix.ToString() : string.Empty,
                                 op.LineLimit ? "LineLimit=True" : string.Empty,
                                 op.RightToLeft ? "RightToLeft=True" : string.Empty,
                                 op.Trimming != StringTrimming.None ? "Trimming=" + op.Trimming.ToString() : string.Empty,
                                 op.WordWrap ? "WordWrap=True" : string.Empty,
                                 op.Angle == 0f ? "A=0" : "Angle=" + op.Angle.ToString(),
                                 op.FirstTabOffset == 40f ? "O=40" : "FirstTabOffset=" + op.FirstTabOffset.ToString(),
                                 op.DistanceBetweenTabs == 20f ? "D=20" : "DistanceBetweenTabs=" + op.DistanceBetweenTabs.ToString()));
        }
Exemplo n.º 2
0
        public static SizeD MeasureString(Graphics g, string text, Font font,
                                          StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing, float angle)
        {
            StiTextOptions options = new StiTextOptions();

            options.Angle = angle;
            return(MeasureString(g, text, font, 0, options, ha, va, antialiasing));
        }
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public object Clone()
        {
            StiTextOptions textOptions = new StiTextOptions();

            if (this.bits != null)
            {
                textOptions.bits = this.bits.Clone() as bitsTextOptions;
            }
            textOptions.wordWrap = this.wordWrap;

            return(textOptions);
        }
Exemplo n.º 4
0
        public static StringFormat GetStringFormat(
            StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing, float zoom)
        {
            var stringFormat = textOptions.GetStringFormat(antialiasing, zoom);

            stringFormat.Alignment     = GetAlignment(ha);
            stringFormat.LineAlignment = GetAlignment(va);
            if (MeasureTrailingSpaces)
            {
                stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
            }

            return(stringFormat);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="g">Graphics to draw on.</param>
 /// <param name="text">Text to draw on.</param>
 /// <param name="font">Font to draw on.</param>
 /// <param name="brush">Brush to draw.</param>
 /// <param name="rect">Rectangle to draw.</param>
 /// <param name="textOptions">Options to show text.</param>
 /// <param name="ha">Horizontal alignment.</param>
 /// <param name="va">Vertical alignment.</param>
 public static void DrawString(Graphics g, string text, Font font, Brush brush,
                               RectangleD rect, StiTextOptions textOptions,
                               StiTextHorAlignment ha, StiVertAlignment va, bool antialiasing,
                               float zoom)
 {
     using (StringFormat stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, zoom))
     {
         if (ha == StiTextHorAlignment.Width)
         {
             DrawStringWidth(g, text, font, brush, rect, stringFormat, textOptions.Angle);
         }
         else
         {
             DrawString(g, text, font, brush, rect, stringFormat, textOptions.Angle);
         }
     }
 }
Exemplo n.º 6
0
 public static StringFormat GetStringFormat(
     StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va, float zoom)
 {
     return(GetStringFormat(textOptions, ha, va, false, zoom));
 }
Exemplo n.º 7
0
        public static SizeD MeasureString(Graphics g, string text, Font font,
                                          double width, StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va,
                                          bool antialiasing)
        {
            #region Cache for stringFormat - about 4% speed optimization
            int hashCode;
            unchecked
            {
                hashCode = textOptions.GetHashCode();
                hashCode = (hashCode * 397) ^ (int)ha;
                hashCode = (hashCode * 397) ^ (int)va;
                hashCode = (hashCode * 397) ^ (antialiasing ? 1231 : 1237);
            }
            var stringFormat = (StringFormat)hashStringFormats[hashCode];
            if (stringFormat == null)
            {
                stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, 1);
                lock (hashStringFormats)
                {
                    hashStringFormats[hashCode] = stringFormat;
                }
            }
            #endregion

            //using (StringFormat stringFormat = GetStringFormat(textOptions, ha, va, antialiasing, 1))
            //{
            if (!textOptions.WordWrap)
            {
                width = 0;
            }

            SizeF size = new SizeF((float)width, 0);
            try
            {
                //size = g.MeasureString(text, font, (int)width, stringFormat);
                size = g.MeasureString(text, font, new SizeF((float)width, 999999f), stringFormat);
            }
            catch
            {
                size = new SizeF((float)width, 0);
            }

            if (textOptions.Angle == 90 || textOptions.Angle == 270)
            {
                float rw = size.Width;
                size.Width  = size.Height;
                size.Height = rw;
            }
            else if (textOptions.Angle != 0f)
            {
                float sx = (float)size.Width / 2;
                float sy = (float)size.Height / 2;

                var points = new PointF[]
                {
                    new PointF(-sx, -sy),
                    new PointF(sx, -sy),
                    new PointF(sx, sy),
                    new PointF(-sx, sy)
                };

                var m = new Matrix();
                m.Rotate(-(float)textOptions.Angle);
                m.TransformPoints(points);

                int index = 0;
                foreach (PointF point in points)
                {
                    double px = point.X;
                    double py = point.Y;

                    points[index++] = new PointF((float)(px + size.Width / 2), (float)(py + size.Height / 2));
                }

                using (var path = new GraphicsPath())
                {
                    path.AddPolygon(points);
                    var rect2 = path.GetBounds();
                    return(new SizeD(rect2.Width, rect2.Height));
                }
            }
            return(new SizeD(size.Width, size.Height));
            //}
        }
Exemplo n.º 8
0
 /// <summary>
 /// Draws text.
 /// </summary>
 /// <param name="g">Graphics to draw on.</param>
 /// <param name="text">Text to draw on.</param>
 /// <param name="font">Font to draw on.</param>
 /// <param name="brush">Brush to draw.</param>
 /// <param name="rect">Rectangle to draw.</param>
 /// <param name="textOptions">Options to show text.</param>
 /// <param name="ha">Horizontal alignment.</param>
 /// <param name="va">Vertical alignment.</param>
 public static void DrawString(Graphics g, string text, Font font, Brush brush,
                               RectangleD rect, StiTextOptions textOptions, StiTextHorAlignment ha, StiVertAlignment va)
 {
     DrawString(g, text, font, brush, rect, textOptions, ha, va, false, 1);
 }
Exemplo n.º 9
0
        public static string ConvertTextOptionsToLocalizedString(StiTextOptions op, char separator, bool wordWrap)
        {
            string boolTrueStr  = StiLocalization.Get("PropertyEnum", "boolTrue");
            string boolFalseStr = StiLocalization.Get("PropertyEnum", "boolFalse");

            if (wordWrap)
            {
                return(string.Format(
                           "{0}={1}\n{2}={3}\n{4}={5}\n{6}={7}\n{8}={9}\n{10}={11}\n{12}={13}\n{14}={15}",
                           StiLocalization.Get("PropertyMain", "HotkeyPrefix"),
                           StiLocalization.Get("PropertyEnum", "HotkeyPrefix" + op.HotkeyPrefix.ToString()),

                           StiLocalization.Get("PropertyMain", "LineLimit"),
                           op.LineLimit ? boolTrueStr : boolFalseStr,

                           StiLocalization.Get("PropertyMain", "RightToLeft"),
                           op.RightToLeft ? boolTrueStr : boolFalseStr,

                           StiLocalization.Get("PropertyMain", "Trimming"),
                           StiLocalization.Get("PropertyEnum", "StringTrimming" + op.Trimming.ToString()),

                           StiLocalization.Get("PropertyMain", "WordWrap"),
                           op.WordWrap ? boolTrueStr : boolFalseStr,

                           StiLocalization.Get("PropertyMain", "Angle"),
                           op.Angle,

                           StiLocalization.Get("PropertyMain", "FirstTabOffset"),
                           op.FirstTabOffset,

                           StiLocalization.Get("PropertyMain", "DistanceBetweenTabs"),
                           op.DistanceBetweenTabs));
            }
            else
            {
                return(string.Format(
                           "{0}={1}{2} {3}={4}{5} {6}={7}{8} {9}={10}{11} {12}={13}{14} {15}={16}{17} {18}={19}{20} {21}={22}",
                           StiLocalization.Get("PropertyMain", "HotkeyPrefix"),
                           StiLocalization.Get("PropertyEnum", "HotkeyPrefix" + op.HotkeyPrefix.ToString()), separator,

                           StiLocalization.Get("PropertyMain", "LineLimit"),
                           op.LineLimit ? boolTrueStr : boolFalseStr, separator,

                           StiLocalization.Get("PropertyMain", "RightToLeft"),
                           op.RightToLeft ? boolTrueStr : boolFalseStr, separator,

                           StiLocalization.Get("PropertyMain", "Trimming"),
                           StiLocalization.Get("PropertyEnum", "StringTrimming" + op.Trimming.ToString()), separator,

                           StiLocalization.Get("PropertyMain", "WordWrap"),
                           op.WordWrap ? boolTrueStr : boolFalseStr, separator,

                           StiLocalization.Get("PropertyMain", "Angle"),
                           op.Angle, separator,

                           StiLocalization.Get("PropertyMain", "FirstTabOffset"),
                           op.FirstTabOffset, separator,

                           StiLocalization.Get("PropertyMain", "DistanceBetweenTabs"),
                           op.DistanceBetweenTabs));
            }
        }
Exemplo n.º 10
0
        public static string ConvertTextOptionsToLocalizedString(StiTextOptions op, bool wordWrap)
        {
            char ch = CultureInfo.CurrentCulture.TextInfo.ListSeparator[0];

            return(ConvertTextOptionsToLocalizedString(op, ch, wordWrap));
        }
Exemplo n.º 11
0
        public static StiTextOptions ConvertStringToTextOptions(string str, char separator)
        {
            string[] words = str.Split(new char[1] {
                separator
            });

            StiTextOptions to = new StiTextOptions();

            #region HotkeyPrefix
            if (words[0].IndexOf("Hide", StringComparison.InvariantCulture) >= 0)
            {
                to.HotkeyPrefix = HotkeyPrefix.Hide;
            }
            else if (words[0].IndexOf("Show", StringComparison.InvariantCulture) >= 0)
            {
                to.HotkeyPrefix = HotkeyPrefix.Show;
            }
            else
            {
                to.HotkeyPrefix = HotkeyPrefix.None;
            }
            #endregion

            #region LineLimit
            to.LineLimit = words[1].IndexOf("True", StringComparison.InvariantCulture) >= 0;
            #endregion

            #region RightToLeft
            to.RightToLeft = words[2].IndexOf("True", StringComparison.InvariantCulture) >= 0;
            #endregion

            #region Trimming
            if (words[3].IndexOf("EllipsisCharacter", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.EllipsisCharacter;
            }
            else if (words[3].IndexOf("Character", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.Character;
            }
            else if (words[3].IndexOf("EllipsisPath", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.EllipsisPath;
            }
            else if (words[3].IndexOf("EllipsisWord", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.EllipsisWord;
            }
            else if (words[3].IndexOf("None", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.None;
            }
            else if (words[3].IndexOf("Word", StringComparison.InvariantCulture) >= 0)
            {
                to.Trimming = StringTrimming.Word;
            }
            #endregion

            #region WordWrap
            to.WordWrap = words[4].IndexOf("True", StringComparison.InvariantCulture) >= 0;
            #endregion

            #region Angle
            string[] angles = words[5].Split(new char[1] {
                '='
            });
            to.Angle = float.Parse(angles[1].Trim());

            #endregion

            if (words.Length > 6)
            {
                #region FirstTabOffset
                string[] firsts = words[6].Split(new char[1] {
                    '='
                });
                to.FirstTabOffset = float.Parse(firsts[1].Trim());
                #endregion

                #region DistanceBetweenTabs
                string[] tabs = words[7].Split(new char[1] {
                    '='
                });
                to.DistanceBetweenTabs = float.Parse(tabs[1].Trim());
                #endregion
            }

            return(to);
        }
 private bool Equals(StiTextOptions other)
 {
     return(Equals(bits, other.bits) && wordWrap.Equals(other.wordWrap));
 }