public void PDFFontMetricsConstructor_Test() { double emheight = 12.7; double ascent = 120.34; double descent = 12.9; double lineheight = 13.6; PDFFontMetrics target = new PDFFontMetrics(emheight, ascent, descent, lineheight); Assert.IsNotNull(target); Assert.AreEqual(emheight, target.EmHeight); Assert.AreEqual(ascent, target.Ascent); Assert.AreEqual(descent, target.Descent); Assert.AreEqual(lineheight, target.LineHeight); Assert.AreEqual(lineheight - (ascent + descent), target.LineSpacing); }
protected override Native.PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFRect bounds = this.TotalBounds; bounds.X += context.Offset.X; bounds.Y += context.Offset.Y; //Set the arrangement for this text run Component owner = this.Owner as Component; if (owner != null && null != this._caclulatedBounds) { for (int i = 0; i < this._caclulatedBounds.Length; i++) { PDFRect b = this._caclulatedBounds[i]; if (b.IsEmpty == false) { if (i == 0) { b.X += this.LineInset; } b.X += context.Offset.X; b.Y += context.Offset.Y; owner.SetArrangement(context, context.FullStyle, b); } } } //TODO:Add any backgrounds and borders based on the 3 rects in the calculated bounds. PDFFontMetrics metrics = this.TextRenderOptions.Font.FontMetrics; bounds.X += this.LineInset; PDFSize cursor = new PDFSize(bounds.X, bounds.Y); //pdf text rendering is done from the baseline, we need the rendering to appear to start from the top //so add the ascent of the font metrics //Previous 27 Feb 20 //cursor.Height += this.TextRenderOptions.Font.FontMetrics.Ascent; //With mixed content if (this.TextRenderOptions.Leading.HasValue) { cursor.Height += this.TextRenderOptions.Leading.Value - metrics.Descent; } else { cursor.Height += this.Line.BaseLineOffset; } if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Text Begin", "Marker to beginning to render the text for component " + this.Owner.ToString() + " at cursor position " + cursor); } if (this.ShouldRenderBackground(context)) { this.RenderTextBackground(context, writer); } context.Graphics.SaveGraphicsState(); context.Graphics.BeginText(); context.Graphics.SetTextRenderOptions(this.TextRenderOptions, bounds); if (_hascustomspace && this.TextRenderOptions.CharacterSpacing.HasValue == false && this.TextRenderOptions.WordSpacing.HasValue == false) { context.Graphics.SetTextSpacing(this._wordspace, this._charspace, this.TextRenderOptions.Font.Size); } context.Graphics.MoveTextCursor(cursor, true); this.StartTextCursor = cursor; return(null); }