예제 #1
0
        /// <summary>
        /// Static method thats format a paragraph
        /// </summary>
        /// <param name="strText">Input Text</param>
        /// <param name="fontSize">Font's size</param>
        /// <param name="fontType">Font's type</param>
        /// <param name="parWidth">Paragrapfh's width</param>
        /// <param name="lineHeight">Line's height</param>
        /// <param name="parAlign">Paragraph's Alignment</param>
        /// <returns>IEnumerable interface that cointains paragraphLine objects</returns>
        public static IEnumerable formatParagraph(string strText, int fontSize, predefinedFont fontType, int parWidth, int lineHeight, predefinedAlignment parAlign)
        {
            string[]      paragraphsArray = strText.Split("\n".ToCharArray());
            string[]      bufferArray;
            int           lineLength;
            paragraphLine tempPar;
            StringBuilder lineString  = new StringBuilder(parWidth);
            ArrayList     resultArray = new ArrayList();

            lineLength = 0;
            foreach (string paragraph in paragraphsArray)
            {
                bufferArray = paragraph.Split(" ".ToCharArray());
                foreach (string word in bufferArray)
                {
                    if ((textAdapter.wordWeight(word + " ", fontSize, fontType) + lineLength) > parWidth)
                    {
                        switch (parAlign)
                        {
                        case predefinedAlignment.csLeft:
                        default:
                            tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, 0);
                            break;

                        case predefinedAlignment.csRight:
                            tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, parWidth - lineLength);
                            break;

                        case predefinedAlignment.csCenter:
                            tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, Convert.ToInt32((parWidth - lineLength) / 2));
                            break;
                        }
                        resultArray.Add(tempPar);
                        lineString.Remove(0, lineString.Length);
                        lineLength = 0;
                    }
                    lineString.Append(word + " ");
                    lineLength += textAdapter.wordWeight(word + " ", fontSize, fontType);
                }
                if (lineLength > 0)
                {
                    switch (parAlign)
                    {
                    case predefinedAlignment.csLeft:
                    default:
                        tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, 0);
                        break;

                    case predefinedAlignment.csRight:
                        tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, parWidth - lineLength);
                        break;

                    case predefinedAlignment.csCenter:
                        tempPar = new paragraphLine(lineString.ToString(0, lineString.Length - 1), lineHeight, Convert.ToInt32((parWidth - lineLength) / 2));
                        break;
                    }
                    resultArray.Add(tempPar);
                    lineString.Remove(0, lineString.Length);
                    lineLength = 0;
                }
                bufferArray = null;
            }
            return(resultArray);
        }
예제 #2
0
 /// <summary>
 /// Static method thats format a paragraph
 /// </summary>
 /// <param name="strText">Input Text</param>
 /// <param name="fontSize">Font's size</param>
 /// <param name="fontType">Font's type</param>
 /// <param name="parWidth">Paragrapfh's width</param>
 /// <param name="lineHeight">Line's height</param>
 /// <param name="parAlign">Paragraph's Alignment</param>
 /// <returns>IEnumerable interface that cointains paragraphLine objects</returns>
 public static IEnumerable formatParagraph(string strText,int fontSize,predefinedFont fontType,int parWidth,int lineHeight,predefinedAlignment parAlign)
 {
     string[] paragraphsArray = strText.Split("\n".ToCharArray());
     string[] bufferArray;
     int lineLength;
     paragraphLine tempPar;
     StringBuilder lineString = new StringBuilder(parWidth);
     ArrayList resultArray = new ArrayList();
     lineLength = 0;
     foreach(string paragraph in paragraphsArray) {
         bufferArray = paragraph.Split(" ".ToCharArray());
         foreach(string word in bufferArray) {
             if ((textAdapter.wordWeight(word + " ",fontSize,fontType) + lineLength) > parWidth) {
                 switch (parAlign) {
                     case predefinedAlignment.csLeft: default:
                         tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,0);
                         break;
                     case predefinedAlignment.csRight:
                         tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,parWidth - lineLength);
                         break;
                     case predefinedAlignment.csCenter:
                         tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,Convert.ToInt32((parWidth - lineLength) / 2));
                         break;
                 }
                 resultArray.Add(tempPar);
                 lineString.Remove(0,lineString.Length);
                 lineLength = 0;
             }
             lineString.Append(word + " ");
             lineLength += textAdapter.wordWeight(word + " ",fontSize,fontType);
         }
         if (lineLength > 0) {
             switch (parAlign) {
                 case predefinedAlignment.csLeft: default:
                     tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,0);
                     break;
                 case predefinedAlignment.csRight:
                     tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,parWidth - lineLength);
                     break;
                 case predefinedAlignment.csCenter:
                     tempPar = new paragraphLine(lineString.ToString(0,lineString.Length - 1),lineHeight,Convert.ToInt32((parWidth - lineLength) / 2));
                     break;
             }
             resultArray.Add(tempPar);
             lineString.Remove(0,lineString.Length);
             lineLength = 0;
         }
         bufferArray = null;
     }
     return resultArray;
 }