Mono.TextEditor.TextViewMargin.GetFoldRectangles C# (CSharp) Method

GetFoldRectangles() private method

private GetFoldRectangles ( int lineNr ) : FoldSegment>>.IEnumerable
lineNr int
return FoldSegment>>.IEnumerable
		IEnumerable<Tuple<Gdk.Rectangle, FoldSegment>> GetFoldRectangles (int lineNr)
		{
			if (lineNr < 0)
				yield break;

			var line = lineNr <= Document.LineCount ? Document.GetLine (lineNr) : null;
			//			int xStart = XOffset;
			int y = (int)(LineToY (lineNr) - textEditor.VAdjustment.Value);
			//			Gdk.Rectangle lineArea = new Gdk.Rectangle (XOffset, y, textEditor.Allocation.Width - XOffset, LineHeight);
			int width, height;
			var xPos = this.XOffset + this.TextStartPosition - textEditor.HAdjustment.Value;

			if (line == null)
				yield break;

			var foldings = Document.GetStartFoldings (line);
			int offset = line.Offset;
			double foldXMargin = foldMarkerXMargin * textEditor.Options.Zoom;
			restart:
			using (var calcTextLayout = textEditor.LayoutCache.RequestLayout ())
			using (var calcFoldingLayout = textEditor.LayoutCache.RequestLayout ()) {
				calcTextLayout.FontDescription = textEditor.Options.Font;
				calcTextLayout.Tabs = this.tabArray;

				calcFoldingLayout.FontDescription = markerLayout.FontDescription;
				calcFoldingLayout.Tabs = this.tabArray;
				foreach (var folding in foldings) {
					int foldOffset = folding.StartLine.Offset + folding.Column - 1;
					if (foldOffset < offset)
						continue;

					if (folding.IsFolded) {
						var txt = Document.GetTextAt (offset, System.Math.Max (0, System.Math.Min (foldOffset - offset, Document.TextLength - offset)));
						calcTextLayout.SetText (txt);
						calcTextLayout.GetSize (out width, out height);
						xPos += width / Pango.Scale.PangoScale;
						offset = folding.EndLine.Offset + folding.EndColumn;

						calcFoldingLayout.SetText (folding.Description);

						calcFoldingLayout.GetSize (out width, out height);

						var pixelWidth = width / Pango.Scale.PangoScale + foldXMargin * 2;

						var foldingRectangle = new Rectangle ((int)xPos, y, (int)pixelWidth, (int)LineHeight - 1);
						yield return Tuple.Create (foldingRectangle, folding);
						xPos += pixelWidth;
						if (folding.EndLine != line) {
							line = folding.EndLine;
							foldings = Document.GetStartFoldings (line);
							goto restart;
						}
					}
				}
			}
		}