public virtual void CalculateFontAscenderDescenderFromFontMetricsOpenSansRegularFontTest() { PdfFont font = PdfFontFactory.CreateFont(OPEN_SANS_FONTS + "OpenSans-Regular.ttf"); float[] ascenderDescenderFromFontMetrics = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE ); NUnit.Framework.Assert.AreEqual(1068.0f, ascenderDescenderFromFontMetrics[0], EPS); NUnit.Framework.Assert.AreEqual(-292.0f, ascenderDescenderFromFontMetrics[1], EPS); }
public virtual void CalculateFontAscenderDescenderFromFontMetricsFreeSansFontTest() { PdfFont font = PdfFontFactory.CreateFont(FONTS + "FreeSans.ttf"); float[] ascenderDescenderFromFontMetrics = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE ); NUnit.Framework.Assert.AreEqual(800.0f, ascenderDescenderFromFontMetrics[0], EPS); NUnit.Framework.Assert.AreEqual(-200.0f, ascenderDescenderFromFontMetrics[1], EPS); }
public virtual void CalculateFontAscenderDescenderFromFontMetricsNotoSansCJKjpBoldFontTest() { PdfFont font = PdfFontFactory.CreateFont(FONTS + "NotoSansCJKjp-Bold.otf"); float[] ascenderDescenderFromFontMetrics = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE ); NUnit.Framework.Assert.AreEqual(1160.0f, ascenderDescenderFromFontMetrics[0], EPS); NUnit.Framework.Assert.AreEqual(-320.0f, ascenderDescenderFromFontMetrics[1], EPS); }
public virtual void CalculateFontAscenderDescenderFromFontMetricsNotoColorEmojiFontTest() { PdfFont font = PdfFontFactory.CreateFont(FONTS + "NotoColorEmoji.ttf"); float[] ascenderDescenderFromFontMetrics = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE ); System.Console.Out.WriteLine(ascenderDescenderFromFontMetrics[0]); System.Console.Out.WriteLine(ascenderDescenderFromFontMetrics[1]); }
public virtual void CalculateFontAscenderDescenderFromFontMetricsHelveticaTest() { PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); float[] fontAscenderDescender = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE); NUnit.Framework.Assert.AreEqual(718.0f * TextRenderer.TYPO_ASCENDER_SCALE_COEFF, fontAscenderDescender[0], EPS); NUnit.Framework.Assert.AreEqual(-207.0f * TextRenderer.TYPO_ASCENDER_SCALE_COEFF, fontAscenderDescender[1] , EPS); }
public virtual void CalculateFontAscenderDescenderFromFontMetricsTimesTest() { PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); float[] fontAscenderDescender = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE); NUnit.Framework.Assert.AreEqual(683.0f * TextRenderer.TYPO_ASCENDER_SCALE_COEFF, fontAscenderDescender[0], EPS); NUnit.Framework.Assert.AreEqual(-217.0f * TextRenderer.TYPO_ASCENDER_SCALE_COEFF, fontAscenderDescender[1] , EPS); }
internal static float[] GetFontAscenderDescenderNormalized(AbstractRenderer renderer) { PdfFont font = renderer.ResolveFirstPdfFont(); float fontSize = renderer.GetPropertyAsUnitValue(Property.FONT_SIZE).GetValue(); float[] fontAscenderDescenderFromMetrics = TextRenderer.CalculateAscenderDescender(font, RenderingMode.HTML_MODE ); float fontAscender = fontAscenderDescenderFromMetrics[0] / FontProgram.UNITS_NORMALIZATION * fontSize; float fontDescender = fontAscenderDescenderFromMetrics[1] / FontProgram.UNITS_NORMALIZATION * fontSize; return(new float[] { fontAscender, fontDescender }); }
private float[] CalculateAscenderDescender() { PdfFont listItemFont = ResolveFirstPdfFont(); UnitValue fontSize = this.GetPropertyAsUnitValue(Property.FONT_SIZE); if (listItemFont != null && fontSize != null) { if (!fontSize.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ListItemRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .FONT_SIZE)); } float[] ascenderDescender = TextRenderer.CalculateAscenderDescender(listItemFont); return(new float[] { fontSize.GetValue() *ascenderDescender[0] / TextRenderer.TEXT_SPACE_COEFF, fontSize. GetValue() *ascenderDescender[1] / TextRenderer.TEXT_SPACE_COEFF }); } return(new float[] { 0, 0 }); }
public virtual TextRectangle GetTextRectangle(SvgDrawContext context, Point basePoint) { if (GetParent() is TextSvgBranchRenderer && basePoint != null) { float parentFontSize = ((TextSvgBranchRenderer)GetParent()).GetFontSize(); PdfFont parentFont = ((TextSvgBranchRenderer)GetParent()).GetFont(); float textLength = GetTextContentLength(parentFontSize, parentFont); float[] fontAscenderDescenderFromMetrics = TextRenderer.CalculateAscenderDescender(parentFont, RenderingMode .HTML_MODE); float fontAscender = fontAscenderDescenderFromMetrics[0] / FontProgram.UNITS_NORMALIZATION * parentFontSize; float fontDescender = fontAscenderDescenderFromMetrics[1] / FontProgram.UNITS_NORMALIZATION * parentFontSize; // TextRenderer#calculateAscenderDescender returns fontDescender as a negative value so we should subtract this value float textHeight = fontAscender - fontDescender; return(new TextRectangle((float)basePoint.GetX(), (float)basePoint.GetY() - fontAscender, textLength, textHeight , (float)basePoint.GetY())); } else { return(null); } }