/// <summary> /// Processes (measures) a blank. /// </summary> /// <returns>True if the blank causes a line break.</returns> FormatResult FormatBlank() { if (IgnoreBlank()) return FormatResult.Ignore; this.savedWordWidth = 0; XUnit width = MeasureString(" "); VerticalLineInfo newVertInfo = CalcCurrentVerticalInfo(); Rectangle rect = this.formattingArea.GetFittingRect(this.currentYPosition, newVertInfo.height + BottomBorderOffset); if (rect == null) return FormatResult.NewArea; if (width + currentXPosition <= rect.X + rect.Width + Tolerance) { this.currentXPosition += width; this.currentVerticalInfo = newVertInfo; SaveBlankWidth(width); return FormatResult.Continue; } return FormatResult.NewLine; }
void FormatListSymbol() { string symbol; XFont font; if (GetListSymbol(out symbol, out font)) { this.currentVerticalInfo = CalcVerticalInfo(font); this.currentXPosition += this.gfx.MeasureString(symbol, font, StringFormat).Width; FormatTab(); } }
/// <summary> /// Starts a new line by resetting measuring values. /// Do not call before the first first line is formatted! /// </summary> /// <returns>True, if the new line may fit the formatting area.</returns> bool StartNewLine() { this.tabOffsets = new ArrayList(); this.lastTab = null; this.lastTabPosition = 0; this.currentYPosition += this.currentVerticalInfo.height; #if true Rectangle rect = this.formattingArea.GetFittingRect(currentYPosition, this.currentVerticalInfo.height + BottomBorderOffset); if (rect == null) return false; this.isFirstLine = false; this.currentXPosition = StartXPosition; // depends on "currentVerticalInfo" this.currentVerticalInfo = new VerticalLineInfo(); this.currentVerticalInfo = CalcCurrentVerticalInfo(); #else if (this.formattingArea.GetFittingRect(currentYPosition, this.currentVerticalInfo.height + BottomBorderOffset) == null) return false; this.currentVerticalInfo = new VerticalLineInfo(); this.currentVerticalInfo = CalcCurrentVerticalInfo(); this.isFirstLine = false; this.currentXPosition = this.StartXPosition; #endif this.startLeaf = this.currentLeaf; this.currentBlankCount = 0; this.currentWordsWidth = 0; this.currentLineWidth = 0; return true; }
FormatResult FormatAsWord(XUnit width) { VerticalLineInfo newVertInfo = CalcCurrentVerticalInfo(); Rectangle rect = this.formattingArea.GetFittingRect(this.currentYPosition, newVertInfo.height + BottomBorderOffset); if (rect == null) return FormatResult.NewArea; if (this.currentXPosition + width <= rect.X + rect.Width - this.RightIndent + Tolerance) { this.savedWordWidth = width; this.currentXPosition += width; // For Tabs in justified context if (!this.IgnoreHorizontalGrowth) this.currentWordsWidth += width; if (this.savedBlankWidth > 0) { // For Tabs in justified context if (!this.IgnoreHorizontalGrowth) ++this.currentBlankCount; } // For Tabs in justified context if (!this.IgnoreHorizontalGrowth) this.currentLineWidth += width + PopSavedBlankWidth(); this.currentVerticalInfo = newVertInfo; this.minWidth = Math.Max(this.minWidth, width); return FormatResult.Continue; } else { savedWordWidth = width; return FormatResult.NewLine; } }
/// <summary> /// Renders a single line. /// </summary> /// <param name="lineInfo"></param> void RenderLine(LineInfo lineInfo) { this.currentVerticalInfo = lineInfo.vertical; this.currentLeaf = lineInfo.startIter; this.startLeaf = lineInfo.startIter; this.endLeaf = lineInfo.endIter; this.currentBlankCount = lineInfo.blankCount; this.currentLineWidth = lineInfo.lineWidth; this.currentWordsWidth = lineInfo.wordsWidth; this.currentXPosition = this.StartXPosition; this.tabOffsets = lineInfo.tabOffsets; this.lastTabPassed = lineInfo.lastTab == null; this.lastTab = lineInfo.lastTab; this.tabIdx = 0; bool ready = this.currentLeaf == null; if (this.isFirstLine) RenderListSymbol(); while (!ready) { if (this.currentLeaf.Current == lineInfo.endIter.Current) ready = true; if (this.currentLeaf.Current == lineInfo.lastTab) this.lastTabPassed = true; RenderElement(this.currentLeaf.Current); this.currentLeaf = this.currentLeaf.GetNextLeaf(); } this.currentYPosition += lineInfo.vertical.height; this.isFirstLine = false; }
/// <summary> /// Initializes this instance for formatting. /// </summary> /// <param name="area">The area for formatting</param> /// <param name="previousFormatInfo">A previous format info.</param> /// <returns>False, if nothing of the paragraph will fit the area any more.</returns> private bool InitFormat(Area area, FormatInfo previousFormatInfo) { this.phase = Phase.Formatting; this.tabOffsets = new ArrayList(); ParagraphFormatInfo prevParaFormatInfo = (ParagraphFormatInfo)previousFormatInfo; if (previousFormatInfo == null || prevParaFormatInfo.LineCount == 0) { ((ParagraphFormatInfo)this.renderInfo.FormatInfo).isStarting = true; ParagraphIterator parIt = new ParagraphIterator(this.paragraph.Elements); this.currentLeaf = parIt.GetFirstLeaf(); this.isFirstLine = true; } else { this.currentLeaf = prevParaFormatInfo.GetLastLineInfo().endIter.GetNextLeaf(); this.isFirstLine = false; ((ParagraphFormatInfo)this.renderInfo.FormatInfo).isStarting = false; } this.startLeaf = this.currentLeaf; this.currentVerticalInfo = CalcCurrentVerticalInfo(); this.currentYPosition = area.Y + TopBorderOffset; this.formattingArea = area; Rectangle rect = this.formattingArea.GetFittingRect(this.currentYPosition, this.currentVerticalInfo.height); if (rect == null) return false; this.currentXPosition = rect.X + LeftIndent; if (this.isFirstLine) FormatListSymbol(); return true; }
void HandleNonFittingLine() { if (this.currentLeaf != null) { if (this.savedWordWidth > 0) { this.currentWordsWidth = this.savedWordWidth; this.currentLineWidth = this.savedWordWidth; } this.currentLeaf = this.currentLeaf.GetNextLeaf(); this.currentYPosition += this.currentVerticalInfo.height; this.currentVerticalInfo = new VerticalLineInfo(); } }
/// <summary> /// Starts a new line by resetting measuring values. /// Do not call before the first first line is formatted! /// </summary> /// <returns>True, if the new line may fit the formatting area.</returns> bool StartNewLine() { _tabOffsets = new List<TabOffset>(); _lastTab = null; _lastTabPosition = 0; _currentYPosition += _currentVerticalInfo.Height; Rectangle rect = _formattingArea.GetFittingRect(_currentYPosition, _currentVerticalInfo.Height + BottomBorderOffset); if (rect == null) return false; _isFirstLine = false; _currentXPosition = StartXPosition; // depends on "currentVerticalInfo" _currentVerticalInfo = new VerticalLineInfo(); _currentVerticalInfo = CalcCurrentVerticalInfo(); _startLeaf = _currentLeaf; _currentBlankCount = 0; _currentWordsWidth = 0; _currentLineWidth = 0; return true; }
void HandleNonFittingLine() { if (_currentLeaf != null) { if (_savedWordWidth > 0) { _currentWordsWidth = _savedWordWidth; _currentLineWidth = _savedWordWidth; } _currentLeaf = _currentLeaf.GetNextLeaf(); _currentYPosition += _currentVerticalInfo.Height; _currentVerticalInfo = new VerticalLineInfo(); } }