/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="textBounds"></param> /// <param name="drawWords"></param> /// <param name="control"></param> /// <param name="RunningLine"></param> /// <param name="Columns">Value -1 means, that no paging is done, normaly columns are 1,2,3...</param> /// <param name="ColumnSeparatorWidth"></param> /// <param name="PageCount"></param> /// <returns></returns> public void RecalculateWordsLayout(MNPageContext context, Size textBoundsSize, List <SMTextContainerWord> drawWords) { Rectangle textBounds = Rectangle.Empty; textBounds.Size = textBoundsSize; float lineY = 0; float lineX = ItemMargin.Left; float maxX = textBoundsSize.Width - ItemMargin.Right; SMTextContainerLine currLine = new SMTextContainerLine(); drawLines.Clear(); drawLines.Add(currLine); // first placement of word tokens foreach (SMTextContainerWord wt in drawWords) { SizeF szf = context.g.MeasureString(wt.text, Font.Font, textBounds.Width, StringFormat.GenericDefault); wt.rect.Width = (int)szf.Width + ItemPadding.Left + ItemPadding.Right; wt.rect.Height = (int)szf.Height + ItemPadding.Top + ItemPadding.Bottom; if (((lineX + wt.rect.Width + ItemMargin.Left) > maxX) && currLine.Count > 0) { lineX = ItemMargin.Left; lineY += wt.rect.Height + ItemMargin.Top + ItemMargin.Bottom; currLine = new SMTextContainerLine(); drawLines.Add(currLine); } wt.rect.X = (int)lineX; wt.rect.Y = (int)lineY; lineX += wt.rect.Width + ItemMargin.Left + ItemMargin.Right; currLine.Add(wt); } // vertical alignment AdjustLinesVerticaly(textBounds, drawLines, GetVerticalAlign()); // horizontal aligment AdjustLinesHorizontaly((int)textBounds.Width, GetHorizontalAlign(), drawLines); }
private void AdjustLineWords(SMTextContainerLine line, float areaWidth, SMHorizontalAlign align, bool lastLine) { float totalWidth = 0; foreach (SMTextContainerWord wb in line) { totalWidth += wb.rect.Width + ItemMargin.LeftRight; } if (line.Count > 0) { float adjustment = 0; float adjustmentStep = 0; bool doAdjust = true; if (align == SMHorizontalAlign.Left || (align == SMHorizontalAlign.Justify && lastLine)) { doAdjust = false; } else if (align == SMHorizontalAlign.Center) { adjustment = (areaWidth - totalWidth) / 2; } else if (align == SMHorizontalAlign.Right) { adjustment = (areaWidth - totalWidth); } else if (align == SMHorizontalAlign.Justify) { adjustmentStep = (areaWidth - totalWidth) / (line.Count + 1); } if (doAdjust) { foreach (SMTextContainerWord wat in line) { wat.rect.X += (int)adjustment; wat.rect.Width += (int)adjustmentStep; adjustment += adjustmentStep; } } } }