Exemple #1
0
        /// <summary>
        /// Gets a string format with specified settings.
        /// </summary>
        /// <param name="align">Text alignment information on the vertical plane.</param>
        /// <param name="lineAlign">Line alignment on the horizontal plane.</param>
        /// <param name="trimming"><b>StringTrimming</b> enumeration.</param>
        /// <param name="flags"><b>StringFormatFlags</b> enumeration that contains formatting information.</param>
        /// <param name="firstTab">The number of spaces between the beginning of a line of text and the first tab stop.</param>
        /// <param name="tabWidth">Distance between tab stops.</param>
        /// <param name="defaultTab">Default distance between default tabs stops.</param>
        /// <returns>The <b>StringFormat</b> object.</returns>
        public StringFormat GetStringFormat(StringAlignment align, StringAlignment lineAlign,
                                            StringTrimming trimming, StringFormatFlags flags, float firstTab, FloatCollection tabWidth,
                                            float defaultTab)
        {
            int hash = align.GetHashCode() ^ (lineAlign.GetHashCode() << 2) ^ (trimming.GetHashCode() << 5) ^
                       (flags.GetHashCode() << 16) ^ (100 - firstTab).GetHashCode() ^ tabWidth.GetHashCode();
            StringFormat result = stringFormats[hash] as StringFormat;

            if (result == null)
            {
                result               = new StringFormat();
                result.Alignment     = align;
                result.LineAlignment = lineAlign;
                result.Trimming      = trimming;
                result.FormatFlags   = flags;
                float[] tabStops = new float[64];
                // fixed issue 2823
                tabStops[0] = firstTab;
                for (int i = 1; i < 64; i++)
                {
                    if (i > tabWidth.Count)
                    {
                        tabStops[i] = defaultTab;
                        continue;
                    }
                    tabStops[i] = tabWidth[i - 1];
                }
                result.SetTabStops(0, tabStops);
                stringFormats[hash] = result;
            }
            return(result);
        }
Exemple #2
0
 private int ComputeHash()
 {
     unchecked
     {
         int hash = 27;
         hash = hash * 486187739 + Trimming.GetHashCode();
         hash = hash * 486187739 + Alignment.GetHashCode();
         hash = hash * 486187739 + LineAlignment.GetHashCode();
         hash = hash * 486187739 + Flags.GetHashCode();
         return(hash);
     }
 }
Exemple #3
0
        /// <summary>
        /// Gets a string format with specified settings.
        /// </summary>
        /// <param name="align">Text alignment information on the vertical plane.</param>
        /// <param name="lineAlign">Line alignment on the horizontal plane.</param>
        /// <param name="trimming"><b>StringTrimming</b> enumeration.</param>
        /// <param name="flags"><b>StringFormatFlags</b> enumeration that contains formatting information.</param>
        /// <param name="firstTab">The number of spaces between the beginning of a line of text and the first tab stop.</param>
        /// <param name="tabWidth">Distance between tab stops.</param>
        /// <returns>The <b>StringFormat</b> object.</returns>
        public StringFormat GetStringFormat(StringAlignment align, StringAlignment lineAlign,
                                            StringTrimming trimming, StringFormatFlags flags, float firstTab, float tabWidth)
        {
            int hash = align.GetHashCode() ^ (lineAlign.GetHashCode() << 2) ^ (trimming.GetHashCode() << 5) ^
                       (flags.GetHashCode() << 16) ^ (100 - firstTab).GetHashCode() ^ tabWidth.GetHashCode();
            StringFormat result = FStringFormats[hash] as StringFormat;

            if (result == null)
            {
                result               = new StringFormat();
                result.Alignment     = align;
                result.LineAlignment = lineAlign;
                result.Trimming      = trimming;
                result.FormatFlags   = flags;
                float[] tabStops = new float[64];
                for (int i = 0; i < 64; i++)
                {
                    tabStops[i] = i == 0 ? firstTab : tabWidth;
                }
                result.SetTabStops(0, tabStops);
                FStringFormats[hash] = result;
            }
            return(result);
        }