/// <summary> /// Změří velikost textu this tabulky, uloží ji do <see cref="CurrentSize"/> /// </summary> /// <param name="graphics"></param> /// <param name="extendColumnWidth"></param> public void TextMeasure(Graphics graphics, bool extendColumnWidth = false) { Size currentSize = Size.Empty; if (this.Rows != null && this.Rows.Count > 0) { TableTextRow titleRow = this.Rows[0]; for (int i = 0; i < this.Rows.Count; i++) { this.Rows[i].TextMeasure(this, graphics, extendColumnWidth, i, titleRow, ref currentSize); } currentSize.Width = titleRow.PrepareColumnsWidth(); } this.CurrentSize = currentSize.Add(3, 3); }
/// <summary> /// Změří velikost textu this tabulky, uloží ji do <see cref="CurrentSize"/> /// </summary> /// <param name="parentRow"></param> /// <param name="graphics"></param> /// <param name="extendColumnWidth"></param> /// <param name="rowIndex"></param> /// <param name="cellIndex"></param> /// <param name="titleRow"></param> /// <param name="rowSize">Souhrnná velikost</param> internal void TextMeasure(TableTextRow parentRow, Graphics graphics, bool extendColumnWidth, int rowIndex, int cellIndex, TableTextRow titleRow, ref Size rowSize) { this.ParentRow = parentRow; this.CellIndex = cellIndex; // Velikost textu + Padding + 1px (linky): Size currentSize = Painter.MeasureString(graphics, this.Text, this.CurrentFont) .Add(this.CurrentContentPadding) .Add(1, 1); this.CurrentSize = currentSize; this.StoreColumnWidth(currentSize.Width, rowIndex, cellIndex, titleRow); // Přiměřeně zvětšit velikost řádku: if (rowSize.Height < currentSize.Height) { rowSize.Height = currentSize.Height; } rowSize.Width += currentSize.Width; }
/// <summary> /// Metoda určí správnou šířku sloupce, pro zjištěnou reálnou šířku (dle textu, fontu, a okrajů), a pro další parametry. /// </summary> /// <param name="contentWidth"></param> /// <param name="rowIndex"></param> /// <param name="cellIndex"></param> /// <param name="titleRow"></param> /// <returns></returns> protected void StoreColumnWidth(int contentWidth, int rowIndex, int cellIndex, TableTextRow titleRow) { // Jak zacházet se šířkou sloupce: if (rowIndex == 0) { // Jsme "titulní" řádek: this.ContentMaxWidth = contentWidth; } else { // Jsme běžný datový řádek: this.ContentMaxWidth = null; // Najdeme buňku z titulního řádku, pro stejný sloupec jako this buňka: TableTextCell titleCell = ((titleRow != null && titleRow.Cells.Count > cellIndex) ? titleRow.Cells[cellIndex] : null); if (titleCell != null) { // Nastřádáme Max(): if (!titleCell.ContentMaxWidth.HasValue || (titleCell.ContentMaxWidth.HasValue && titleCell.ContentMaxWidth.Value < contentWidth)) { titleCell.ContentMaxWidth = contentWidth; } } } }
/// <summary> /// Změří velikost textu this tabulky, uloží ji do <see cref="CurrentSize"/> /// </summary> /// <param name="parentTable"></param> /// <param name="graphics"></param> /// <param name="extendColumnWidth"></param> /// <param name="rowIndex"></param> /// <param name="titleRow"></param> /// <param name="tableSize">Souhrnná velikost</param> internal void TextMeasure(TableText parentTable, Graphics graphics, bool extendColumnWidth, int rowIndex, TableTextRow titleRow, ref Size tableSize) { Size currentSize = Size.Empty; this.ParentTable = parentTable; this.RowIndex = rowIndex; if (this.Cells != null && this.Cells.Count > 0) { for (int i = 0; i < this.Cells.Count; i++) { this.Cells[i].TextMeasure(this, graphics, extendColumnWidth, rowIndex, i, titleRow, ref currentSize); } } this.CurrentSize = currentSize; if (tableSize.Width < currentSize.Width) { tableSize.Width = currentSize.Width; } tableSize.Height += currentSize.Height; }