Example #1
0
        private void btnBreakText_Click(object sender, EventArgs e)
        {
            string strInput = txtInput.Text;
              if (string.IsNullOrEmpty(strInput))
            return;

              txtOutput.Clear();

              LineBreak linebreak = new LineBreak();
              LineBreakElement[] lbElements = linebreak.FindLineBreaks(strInput);

              StringBuilder sb = new StringBuilder();

              int lineWidth = 0;
              int maxLineWidth = (int)nudLineWidth.Value;
              int ich = 0;
              foreach (char ch in strInput)
              {
            LineBreakCondition lbCondition = lbElements[ich].Condition;
            ich++;
            string strElem = ch.ToString();
            if (lbCondition == LineBreakCondition.Allowed)
            {
              if (lineWidth >= maxLineWidth)
              {
            sb.AppendLine(string.Empty);
            lineWidth = 0;
              }

              sb.Append(strElem);
            }
            else if (lbCondition == LineBreakCondition.Mandatory)
            {
              sb.AppendLine(string.Empty);
              lineWidth = 0;
              //sb.Append(strElem);
              // sb.AppendLine(strElem);
            }
            else
              sb.Append(strElem);

            lineWidth++;
              }

              txtOutput.Text = sb.ToString();
        }
Example #2
0
 public UnitTest1()
 {
     m_lineBreak = new LineBreak();
 }