private void CreateRows()
{
if (_Elements != null)
{
int x = 0;
_Rows = new List<Row>();
//build rows---------------------------------------------
var row = new Row();
_Rows.Add(row);
bool WhiteSpace = false;
foreach (Element Element in _Elements)
{
if (Element.words == null)
return;
if (Element.NewLine)
{
//tag forces a new line
x = 0;
row = new Row();
_Rows.Add(row);
WhiteSpace = true;
}
if (Element.TagName == "hr")
{
row.RenderSeparator = true;
}
//else
//{
foreach (Word word in Element.words)
{
if (WordWrap)
{
int scrollwdh = 0;
if (ScrollBars == ScrollBars.Both || ScrollBars == ScrollBars.Vertical)
scrollwdh = vScroll.Width;
if ((word.Width + x) > ClientWidth - Margin - scrollwdh)
{
//new line due to wordwrap
x = 0;
row = new Row();
_Rows.Add(row);
WhiteSpace = true;
}
}
if (word.Text.Replace(" ", "") != "" || word.Image != null)
WhiteSpace = false;
if (!WhiteSpace)
{
row.Words.Add(word);
x += word.Width;
}
}
//}
}
//apply width and height to all rows
int index = 0;
foreach (Row r in _Rows)
{
int width = 0;
int height = 0;
int padd = 0;
if (index > 0)
{
int previndex = index - 1;
var prev = (Row) _Rows[previndex];
while (previndex >= 0 && prev.Words.Count == 0)
{
prev = (Row) _Rows[previndex];
previndex--;
}
if (previndex >= 0)
{
prev = (Row) _Rows[previndex];
if (prev.Words.Count > 0)
{
var w = (Word) prev.Words[prev.Words.Count - 1];
height = w.Height;
}
}
}
foreach (Word w in r.Words)
{
if (w.Height > height && (w.Text != ""))
height = w.Height;
width += w.Width;
}
r.Height = height;
int MaxImageH = 0;
foreach (Word w in r.Words)
{
if (w.Image != null)
{
if (w.Height > height)
MaxImageH = w.Height;
}
}
foreach (Word w in r.Words)
{
int imgH = 0;
int imgPadd = 0;
if (w.Image != null)
{
string valign = GetAttrib("valign", w.Element.Tag);
switch (valign)
{
case "top":
{
imgH = r.Height;
imgPadd = w.Height - imgH;
break;
}
case "middle":
case "center":
{
imgH = r.Height;
int tmp = (w.Height - imgH)/2;
imgH += tmp;
imgPadd = tmp;
break;
}
case "bottom":
{
imgH = w.Height;
imgPadd = 0;
break;
}
default:
{
imgH = w.Height;
imgPadd = 0;
break;
}
}
if (imgH > height)
height = imgH;
if (imgPadd > padd)
padd = imgPadd;
width += w.Width;
}
}
r.Width = width;
r.Height = height;
r.BottomPadd = padd;
index++;
}
vScroll.Maximum = _Rows.Count;
}
}