private string GetCellText(Cell cell, XGraphics gfx) { var text = string.Empty; var size = gfx.MeasureString(cell.Text, cell.font, XStringFormats.Center); var parts = cell.Text.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); while (parts.Length > 0) { int i; for (i = parts.Length; i > 0 && size.Width > cell.width; --i) { size = gfx.MeasureString(String.Join(" ", parts.Take(i)), cell.font, XStringFormats.Center); } text += String.Join(" ", parts.Take(i)) + '\n'; parts = parts.Skip(i).ToArray(); } return (text != string.Empty && text.Last() == '\n') ? text.Substring(0, text.Length - 1) : text; }
private XUnit GetCellHeight(Cell cell, XGraphics gfx) { if (cell.height != XUnit.Zero) return cell.height; else return gfx.MeasureString(GetCellText(cell, gfx), cell.font, XStringFormats.Center).Height; }