Ejemplo n.º 1
0
        public static string Split(string text, SpriteFont font, float maxTextSize)
        {
            string source = text;

            text = "";
            if (source.Length == 0)
            {
                return(text);
            }
            do
            {
                string EOL;
                int    EOLOffset;
                string nextLine = WordWrap.FindNextLine(font, source, (uint)maxTextSize, out EOL, out EOLOffset);
                int    length   = EOL != null ? EOLOffset + 1 : 0;
                if (length != 0)
                {
                    string str = source.Substring(0, length);
                    text = text + str + Environment.NewLine;
                }
                else
                {
                    text = text + Environment.NewLine;
                }
                source = nextLine;
            }while (source != null);
            if (text.EndsWith("\n"))
            {
                text = text.Substring(0, text.Length - 2);
            }
            return(text);
        }
Ejemplo n.º 2
0
 public static bool CanBreakLineAt(string pszStart, int index)
 {
     if (index == 0 || WordWrap.IsWhiteSpace(pszStart[index]) && WordWrap.IsNonBeginningChar(pszStart[index + 1]) || index > 1 && WordWrap.IsWhiteSpace(pszStart[index - 2]) && ((int)pszStart[index - 1] == 34 && !WordWrap.IsWhiteSpace(pszStart[index])) || (!WordWrap.IsWhiteSpace(pszStart[index - 1]) && (int)pszStart[index] == 34 && WordWrap.IsWhiteSpace(pszStart[index + 1]) || !WordWrap.IsWhiteSpace(pszStart[index]) && !WordWrap.IsEastAsianChar(pszStart[index]) && (!WordWrap.IsEastAsianChar(pszStart[index - 1]) && (int)pszStart[index - 1] != 45)) || WordWrap.IsNonBeginningChar(pszStart[index]))
     {
         return(false);
     }
     else
     {
         return(!WordWrap.IsNonEndingChar(pszStart[index - 1]));
     }
 }
Ejemplo n.º 3
0
 public static string FindNonWhiteSpaceBackward(string source, int index, out int offset)
 {
     while (index >= 0 && (WordWrap.IsWhiteSpace(source[index]) || WordWrap.IsLineFeed(source[index])))
     {
         --index;
     }
     offset = index;
     if (index >= 0)
     {
         return(source.Substring(index));
     }
     else
     {
         return((string)null);
     }
 }
Ejemplo n.º 4
0
        public static string FindNonWhiteSpaceForward(string text)
        {
            int startIndex = 0;

            while (startIndex < text.Length && WordWrap.IsWhiteSpace(text[startIndex]))
            {
                ++startIndex;
            }
            if (startIndex < text.Length && WordWrap.IsLineFeed(text[startIndex]))
            {
                ++startIndex;
            }
            if (startIndex >= text.Length)
            {
                return((string)null);
            }
            else
            {
                return(text.Substring(startIndex));
            }
        }
Ejemplo n.º 5
0
 public static string FindNextLine(SpriteFont spriteFont, string source, uint width, out string EOL, out int EOLOffset)
 {
     if (WordWrap.GetWidth == null || source == null)
     {
         EOL       = (string)null;
         EOLOffset = -1;
         return((string)null);
     }
     else
     {
         int  index = 0;
         uint num   = 0U;
         for (; index < source.Length && !WordWrap.IsLineFeed(source[index]); ++index)
         {
             num += WordWrap.GetWidth(spriteFont, source[index]);
             if (num > width)
             {
                 break;
             }
         }
         if (index == 0)
         {
             EOL = WordWrap.FindNonWhiteSpaceBackward(source, index, out EOLOffset);
             return(WordWrap.FindNonWhiteSpaceForward(source.Substring(index + 1)));
         }
         else if (num <= width)
         {
             EOL = WordWrap.FindNonWhiteSpaceBackward(source, index - 1, out EOLOffset);
             if (index - 1 >= 0 && WordWrap.IsLineFeed(source[index - 1]))
             {
                 return(source.Substring(index));
             }
             if (index < 0 || index >= source.Length)
             {
                 return((string)null);
             }
             else
             {
                 return(WordWrap.FindNonWhiteSpaceForward(source.Substring(index)));
             }
         }
         else
         {
             int startIndex = index;
             for (; index > 0; --index)
             {
                 if (WordWrap.IsWhiteSpace(source[index]))
                 {
                     EOL = WordWrap.FindNonWhiteSpaceBackward(source, index, out EOLOffset);
                     if (EOL != null)
                     {
                         return(WordWrap.FindNonWhiteSpaceForward(source.Substring(index + 1)));
                     }
                     index = EOLOffset + 1;
                 }
                 if (WordWrap.CanBreakLineAt(source, index))
                 {
                     break;
                 }
             }
             if (index <= 0)
             {
                 EOL       = source.Substring(startIndex - 1);
                 EOLOffset = startIndex - 1;
                 return(source.Substring(startIndex));
             }
             else
             {
                 EOL       = source.Substring(index - 1);
                 EOLOffset = index - 1;
                 return(WordWrap.FindNonWhiteSpaceForward(source.Substring(index)));
             }
         }
     }
 }
Ejemplo n.º 6
0
 static WordWrap()
 {
     WordWrap.SetCallback(new WordWrap.CB_GetWidth(WordWrap.MyGetCharWidth), (WordWrap.CB_Reserved)null);
 }
Ejemplo n.º 7
0
 public static void SetCallback(WordWrap.CB_GetWidth cbGetWidth, WordWrap.CB_Reserved pReserved)
 {
     if (cbGetWidth != null)
     WordWrap.GetWidth = cbGetWidth;
       if (pReserved == null)
     return;
       WordWrap.Reserved = pReserved;
 }