Ejemplo n.º 1
0
 public static string WrapText(string text, int width, IFont f)
 {
     WrapKey key = new WrapKey(text, width);
     object obj2 = f.WrapCache[key];
     if (obj2 != null)
     {
         return (string) obj2;
     }
     if (f.GetStringWidth(text) <= width)
     {
         f.WrapCache.Add(key, text);
         return text;
     }
     string[] strArray = text.Split(new char[] { ' ' });
     StringBuilder builder = new StringBuilder();
     ArrayList dataStore = GetDataStore();
     for (int i = 0; i < strArray.Length; i++)
     {
         if (f.GetStringWidth(builder.ToString() + strArray[i]) > width)
         {
             if (f.GetStringWidth(strArray[i]) > width)
             {
                 builder.Append(strArray[i]);
                 while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
                 {
                     StringBuilder builder2 = new StringBuilder();
                     builder2.Append(builder[0]);
                     for (int k = 1; k < builder.Length; k++)
                     {
                         if (f.GetStringWidth(builder2.ToString() + builder[k]) > width)
                         {
                             dataStore.Add(builder2);
                             builder = new StringBuilder(builder.ToString().Substring(builder2.Length));
                             continue;
                         }
                         builder2.Append(builder[k]);
                     }
                 }
                 if (i < (strArray.Length - 1))
                 {
                     builder.Append(' ');
                 }
                 continue;
             }
             if (builder.Length > 0)
             {
                 dataStore.Add(builder);
             }
             builder = new StringBuilder(strArray[i]);
             if (i < (strArray.Length - 1))
             {
                 builder.Append(' ');
             }
             continue;
         }
         builder.Append(strArray[i]);
         if (i < (strArray.Length - 1))
         {
             builder.Append(' ');
         }
     }
     if (builder.Length > 0)
     {
         while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
         {
             StringBuilder builder3 = new StringBuilder();
             builder3.Append(builder[0]);
             for (int m = 1; m < builder.Length; m++)
             {
                 if (f.GetStringWidth(builder3.ToString() + builder[m]) > width)
                 {
                     dataStore.Add(builder3);
                     builder = new StringBuilder(builder.ToString().Substring(builder3.Length));
                     continue;
                 }
                 builder3.Append(builder[m]);
             }
         }
         if (builder.Length > 0)
         {
             dataStore.Add(builder);
         }
     }
     StringBuilder builder4 = new StringBuilder();
     int count = dataStore.Count;
     for (int j = 0; j < count; j++)
     {
         builder4.Append(((StringBuilder) dataStore[j]).ToString());
         if (j < (count - 1))
         {
             builder4.Append('\n');
         }
     }
     string str = builder4.ToString();
     f.WrapCache.Add(key, str);
     ReleaseDataStore(dataStore);
     return str;
 }
Ejemplo n.º 2
0
        public override bool Equals(object x)
        {
            WrapKey key = (WrapKey)x;

            return((this == key) || (((this.m_HashCode == key.m_HashCode) && (this.m_MaxWidth == key.m_MaxWidth)) && (this.m_ToWrap == key.m_ToWrap)));
        }