public virtual float GetLeadingValue(Leading leading) { switch (leading.GetLeadingType()) { case Leading.FIXED: { return(leading.GetValue()); } case Leading.MULTIPLIED: { return(occupiedArea.GetBBox().GetHeight() * leading.GetValue()); } default: { throw new InvalidOperationException(); } } }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); Rectangle area = GetOccupiedAreaBBox(); img.ScaleToFit(area.GetWidth(), area.GetHeight()); drawContext.GetCanvas().AddXObjectFittedIntoRectangle(img.GetXObject(), new Rectangle( area.GetX() + (area.GetWidth() - img.GetImageWidth() * img.GetProperty <float>(Property.HORIZONTAL_SCALING)) / 2, area.GetY() + (area.GetHeight() - img.GetImageHeight() * img.GetProperty <float>(Property.VERTICAL_SCALING)) / 2, img.GetImageWidth() * img.GetProperty <float>(Property.HORIZONTAL_SCALING), img.GetImageHeight() * img.GetProperty <float>(Property.VERTICAL_SCALING))); drawContext.GetCanvas().Stroke(); Paragraph p = new Paragraph(content); Leading leading = p.GetDefaultProperty <Leading>(Property.LEADING); UnitValue defaultFontSizeUv = new DocumentRenderer(new Document(drawContext.GetDocument())) .GetPropertyAsUnitValue(Property.FONT_SIZE); float defaultFontSize = defaultFontSizeUv.IsPointValue() ? defaultFontSizeUv.GetValue() : 12f; float x; float y; TextAlignment?alignment; switch (position) { case POSITION.TOP_LEFT: { x = area.GetLeft() + 3; y = area.GetTop() - defaultFontSize * leading.GetValue(); alignment = TextAlignment.LEFT; break; } case POSITION.TOP_RIGHT: { x = area.GetRight() - 3; y = area.GetTop() - defaultFontSize * leading.GetValue(); alignment = TextAlignment.RIGHT; break; } case POSITION.BOTTOM_LEFT: { x = area.GetLeft() + 3; y = area.GetBottom() + 3; alignment = TextAlignment.LEFT; break; } case POSITION.BOTTOM_RIGHT: { x = area.GetRight() - 3; y = area.GetBottom() + 3; alignment = TextAlignment.RIGHT; break; } default: { x = 0; y = 0; alignment = TextAlignment.CENTER; break; } } new Canvas(drawContext.GetCanvas(), area).ShowTextAligned(p, x, y, alignment); }