public virtual void ParseText(TextRenderInfo textRenderInfo) { var text = textRenderInfo.GetText(); LineSegment baseline = textRenderInfo.GetBaseline(); if (textRenderInfo.GetRise() != 0) { Matrix m = new Matrix(0.0f, -textRenderInfo.GetRise()); baseline = baseline.TransformBy(m); } var start = baseline.GetStartPoint(); LineSegment ascentLine = textRenderInfo.GetAscentLine(); PdfTextBlock item = new PdfTextBlock { Value = text, Bottom = pageContext.PageHeight - start.Get(Vector.I2), Top = pageContext.PageHeight - ascentLine.GetStartPoint().Get(Vector.I2), Left = start.Get(Vector.I1), Width = baseline.GetEndPoint().Get(Vector.I1) - start.Get(Vector.I1), FontSize = FontManager.Instance.GetFontSize(textRenderInfo, baseline, ascentLine), StrokeColore = ColorManager.Instance.GetColor(textRenderInfo), CharSpacing = textRenderInfo.GetSingleSpaceWidth(), Font = GetFont(textRenderInfo), }; RightToLeftManager.Instance.AssignRtl(item, textRenderInfo.GetUnscaledWidth() < 0); pageContext.LinkManager.AssignLink(item); texts.Add(item); }
public virtual void TextExtractGlyphAverageWidth() { String text = "i"; PdfDictionary fontDict = InitFontDictWithNotSpecifiedWidthOfSpaceChar(); CanvasGraphicsState gs = new CanvasGraphicsState(); gs.SetFont(PdfFontFactory.CreateFont(fontDict)); gs.SetFontSize(12); TextRenderInfo testTRI = new TextRenderInfo(new PdfString(text), gs, new Matrix(), new Stack <CanvasTag>()); float singleSpaceWidth = testTRI.GetSingleSpaceWidth(); float iWidth = testTRI.GetUnscaledWidth(); NUnit.Framework.Assert.IsTrue(iWidth < singleSpaceWidth); NUnit.Framework.Assert.AreEqual(6.671999931335449, singleSpaceWidth, 0); }
string RecalculateSpaces(TextRenderInfo textInfo) { var chars = textInfo.GetCharacterRenderInfos(); float charSize = (textInfo.GetUnscaledWidth() / chars.Count) / 2.0f; StringBuilder sb = new StringBuilder(); foreach (var ch in chars) { string chText = ch.GetText(); if (chText != " " || (ch.GetUnscaledWidth() > charSize)) { sb.Append(chText); } } return(sb.ToString()); }
/** * Displays text. * @param string the text to display */ private void DisplayPdfString(PdfString str){ String unicode = Decode(str); //if (w.log) w._tr.WriteLine("RenderText : \"{0}\"", unicode); TextRenderInfo renderInfo = new TextRenderInfo(unicode, Gs(), textMatrix, markedContentStack); renderListener.RenderText(renderInfo); textMatrix = new Matrix(renderInfo.GetUnscaledWidth(), 0).Multiply(textMatrix); }