public virtual void CalculateLineHeighttTextRendererPointTest() { Document document = new Document(new PdfDocument(new PdfWriter(new ByteArrayOutputStream()))); TextRenderer textRenderer = new TextRenderer(new Text("Hello")); textRenderer.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(200)); textRenderer.SetParent(document.GetRenderer()); float lineHeight = LineHeightHelper.CalculateLineHeight(textRenderer); NUnit.Framework.Assert.AreEqual(200, lineHeight, EPS); }
private static void SetLineHeight(IPropertyContainer elementToSet, String lineHeight, float em, float rem) { if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight) ) { if (CssTypesValidationUtils.IsNumericValue(lineHeight)) { float?number = CssDimensionParsingUtils.ParseFloat(lineHeight); if (number != null) { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue((float)number)); } else { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue()); } } else { UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeight, em, rem); if (lineHeightValue != null && lineHeightValue.IsPointValue()) { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(lineHeightValue.GetValue())); } else { if (lineHeightValue != null) { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue(lineHeightValue.GetValue() / 100f)); } else { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue()); } } } } else { elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue()); } }
public virtual void LineRendererLayoutInHtmlModeWithLineHeightAndChildInHtmlModeTest() { Document document = CreateDocument(); LineRenderer lineRenderer = new LineRenderer(); lineRenderer.SetParent(document.GetRenderer()); lineRenderer.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE); lineRenderer.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(50)); TextRenderer textRenderer1 = new TextRenderer(new Text("text")); textRenderer1.SetProperty(Property.RENDERING_MODE, RenderingMode.HTML_MODE); TextRenderer textRenderer2 = new TextRenderer(new Text("text")); lineRenderer.AddChild(textRenderer1); lineRenderer.AddChild(textRenderer2); lineRenderer.Layout(new LayoutContext(CreateLayoutArea(1000, 1000))); NUnit.Framework.Assert.AreEqual(28.67920f, lineRenderer.maxAscent, EPS); NUnit.Framework.Assert.AreEqual(-21.32080f, lineRenderer.maxDescent, EPS); }