public void RenderOverLines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = new PDFUnit(-this.TextRenderOptions.GetAscent().PointsValue, PageUnits.Points); PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
public void RenderUnderlines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = this.TextRenderOptions.GetAscent() / UnderlineOffsetFactor; PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
private PDFRect CalculateLastLineBounds(PDFUnit voffset, PDFTextRunEnd end) { PDFLayoutLine line = this._lines[this._lines.Count - 1]; PDFRect full = new PDFRect(this.TotalBounds.Location, PDFSize.Empty); full.Y += voffset; PDFUnit linewidth = PDFUnit.Zero; full.Height = line.Height; foreach (PDFLayoutRun run in line.Runs) { if (run == end) { break; } if (run is PDFTextRunSpacer) { full.X = run.Width; } else { linewidth += run.Width; } } full.Width = linewidth; return(full); }
private PDFRect CalculateOnlyLineBounds(PDFTextRunEnd end) { PDFLayoutLine line = this._lines[0]; PDFRect full = new PDFRect(this.TotalBounds.Location, PDFSize.Empty); bool counting = false; PDFUnit linewidth = PDFUnit.Zero; foreach (PDFLayoutRun run in line.Runs) { if (run == this) { counting = true; } else if (run == end) { break; } else if (counting) { linewidth += run.Width; } } full.Width = linewidth; full.Height = line.Height; return(full); }
public void RenderStrikeThrough(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { //Strike through is up offset one third the font ascent PDFUnit offsetV = new PDFUnit(-this.TextRenderOptions.GetAscent().PointsValue *StrikeThroughOffset, PageUnits.Points); PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
/// <summary> /// Close down and end the text /// </summary> protected virtual void EndText() { if (this.ContinueLayout) { this.AssertCurrentLine(); PDFTextRunEnd end = new PDFTextRunEnd(this.BeginningRun, this.CurrentLine, this.TextComponent); this.CurrentLine.AddRun(end); } }
private PDFRect CalculateInnerTotalBounds(PDFUnit voffset, PDFTextRunEnd ending) { PDFRect full = this.TotalBounds.Clone(); full.Size = PDFSize.Empty; full.Y += voffset; //only want the lines that are between the first and last line int firstIndex = 1; int lastIndex = this.Lines.Count - 2; PDFUnit maxright = PDFUnit.Zero; PDFUnit minleft = new PDFUnit(Double.MaxValue); for (int i = firstIndex; i <= lastIndex; i++) { PDFLayoutLine line = this.Lines[i]; #if FULL_WIDTH minleft = 0; maxright = PDFUnit.Max(maxright, line.FullWidth); #else PDFUnit x = PDFUnit.Zero; PDFUnit w = line.Width; if (line.Runs[0] is PDFTextRunSpacer) { x = line.Runs[0].Width; } maxright = PDFUnit.Max(maxright, w); minleft = PDFUnit.Min(minleft, x); full.Height += line.Height; #endif } if (minleft > 0) { full.X = minleft; } full.Width = maxright - minleft; return(full); }
/// <summary> /// Justs adds a run /// </summary> /// <param name="run"></param> public virtual void AddRun(PDFLayoutRun run) { if (run is PDFTextRunBegin) { PDFUnit ascent = ((PDFTextRunBegin)run).TextRenderOptions.GetAscent(); if (ascent > this.BaseLineOffset) { this.BaseLineOffset = ascent; } } else if (run is PDFTextRunEnd) { PDFTextRunEnd end = (PDFTextRunEnd)run; PDFUnit ascent = end.Start.TextRenderOptions.GetAscent(); if (ascent > this.BaseLineOffset) { this.BaseLineOffset = ascent; } } this.Runs.Add(run); }
/// <summary> /// Called from the PDFTextRunEnd layout item - so the text has a full set of pushed component layouts and we can calculate the bounds /// </summary> /// <param name="ending"></param> /// <param name="context"></param> /// <param name="pageIndex"></param> /// <param name="xoffset"></param> /// <param name="yoffset"></param> public void PushCompleteTextBlock(PDFTextRunEnd ending, PDFLayoutContext context, int pageIndex, PDFUnit xoffset, PDFUnit yoffset) { PDFRect[] all = new PDFRect[3]; if (this.Lines.Count == 1) { all[0] = this.CalculateOnlyLineBounds(ending); } else if (this.Lines.Count == 2) { all[0] = CalculateFirstLineBounds(); all[2] = CalculateLastLineBounds(all[0].Height, ending); } else { all[0] = CalculateFirstLineBounds(); all[1] = CalculateInnerTotalBounds(all[0].Height, ending); all[2] = CalculateLastLineBounds(all[0].Height + all[1].Height, ending); } _caclulatedBounds = all; }
protected virtual void RenderTextDecoration(PDFTextRunEnd endRun, PDFRenderContext context, PDFWriter writer, PDFUnit vOffset, PDFUnit linethickness) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Text Decoration", "Starting to render text decorations"); } //set up the graphics context PDFPen pen = PDFPen.Create(this.TextRenderOptions.FillBrush, linethickness); context.Graphics.SaveGraphicsState(); pen.SetUpGraphics(context.Graphics, this.TotalBounds); bool drawing = false; PDFPoint linestart = new PDFPoint(this.StartTextCursor.Width, this.StartTextCursor.Height + vOffset); foreach (PDFLayoutLine line in this.Lines) { PDFUnit linewidth = 0; foreach (PDFLayoutRun run in line.Runs) { if (run == this) { drawing = true; //lineoffset += this.LineInset; } else if (run == endRun) { drawing = false; break; } else if (drawing) { if (run is PDFTextRunCharacter) { PDFTextRunCharacter chars = (PDFTextRunCharacter)run; PDFPoint start = new PDFPoint(linestart.X + linewidth, linestart.Y); PDFPoint end = new PDFPoint(linestart.X + linewidth + chars.Width + chars.ExtraSpace, linestart.Y); context.Graphics.DrawLine(start, end); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Text Decoration", "Drawn line from " + start + " to " + end); } linewidth += chars.Width; } else if (run is PDFTextRunEnd) { } else if (run is PDFTextRunNewLine) { PDFTextRunNewLine newline = (PDFTextRunNewLine)run; PDFSize offset = newline.Offset; if (null != newline.NextLineSpacer) { PDFUnit nextoffset = newline.NextLineSpacer.Width; offset.Width = nextoffset - offset.Width; } linestart.X += offset.Width; linestart.Y += offset.Height; } else if (run is PDFTextRunSpacer) { //PDFTextRunSpacer spacer = (PDFTextRunSpacer)run; //cursor.X += spacer.Width; } else if (run is PDFTextRunProxy) { PDFTextRunProxy chars = (PDFTextRunProxy)run; PDFPoint start = new PDFPoint(linestart.X + linewidth, linestart.Y); PDFPoint end = new PDFPoint(linestart.X + linewidth + chars.Width, linestart.Y); context.Graphics.DrawLine(start, end); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Text Decoration", "Drawn line from " + start + " to " + end); } linewidth += chars.Width; } } } } if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Debug, "Text Decoration", "Completed the renderering of text decorations"); } //tear down the current graphics state context.Graphics.RestoreGraphicsState(); }