Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

int wxPdfDocument::LineCount ( double  w,
const wxString &  txt 
) [virtual]

This method counts the number of lines a text would occupy in respect to a given maximal width.

Parameters:
wWidth of cells. If 0, they extend up to the right margin of the page.
txtString for which the number of lines is to be counted
Returns:
Number of lines this text would occupy

Definition at line 1211 of file pdfdoc.cpp.

References GetStringWidth(), m_cMargin, m_rMargin, m_w, and m_x.

Referenced by TextBox().

{
  // Output text with automatic or explicit line breaks
  if (w == 0)
  {
    w = m_w - m_rMargin - m_x;
  }

  double wmax = (w - 2 * m_cMargin);
  wxString s = txt;
  s.Replace(_T("\r"),_T("")); // remove carriage returns
  int nb = s.Length();
  if (nb > 0 && s[nb-1] == _T('\n'))
  {
    nb--;
  }

  int sep = -1;
  int i = 0;
  int j = 0;
  double len = 0;
  int nl = 1;
  wxChar c;
  while (i < nb)
  {
    // Get next character
    c = s[i];
    if (c == _T('\n'))
    {
      // Explicit line break
      i++;
      sep = -1;
      j = i;
      len = 0;
      nl++;
      continue;
    }
    if (c == _T(' '))
    {
      sep = i;
    }
    len = GetStringWidth(s.SubString(j, i));

    if (len > wmax)
    {
      // Automatic line break
      if (sep == -1)
      {
        if (i == j)
        {
          i++;
        }
      }
      else
      {
        i = sep + 1;
      }
      sep = -1;
      j = i;
      len = 0;
      nl++;
    }
    else
    {
      i++;
    }
  }
  return nl;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index