public override void Draw(DrawContext drawContext) { base.Draw(drawContext); ILineDrawer lineDrawer = this.GetProperty <ILineDrawer>(Property.LINE_DRAWER); if (lineDrawer != null) { lineDrawer.Draw(drawContext.GetCanvas(), occupiedArea.GetBBox()); } }
public override void Draw(DrawContext drawContext) { ILineDrawer leader = this.GetProperty <ILineDrawer>(Property.TAB_LEADER); if (leader == null) { return; } bool isTagged = drawContext.IsTaggingEnabled(); if (isTagged) { drawContext.GetCanvas().OpenTag(new CanvasArtifact()); } leader.Draw(drawContext.GetCanvas(), occupiedArea.GetBBox()); if (isTagged) { drawContext.GetCanvas().CloseTag(); } }
/// <summary><inheritDoc/></summary> public override void DrawChildren(DrawContext drawContext) { ILineDrawer lineDrawer = this.GetProperty <ILineDrawer>(Property.LINE_DRAWER); if (lineDrawer != null) { Rectangle area = GetOccupiedAreaBBox(); ApplyMargins(area, false); lineDrawer.Draw(drawContext.GetCanvas(), area); } }
private void ApplyConcatMatrix(DrawContext drawContext, float?angle) { AffineTransform rotationTransform = AffineTransform.GetRotateInstance((float)angle); Rectangle rect = GetBorderAreaBBox(); IList <Point> rotatedPoints = TransformPoints(RectangleToPointsList(rect), rotationTransform); float[] shift = CalculateShiftToPositionBBoxOfPointsAt(rect.GetX(), rect.GetY() + rect.GetHeight(), rotatedPoints ); double[] matrix = new double[6]; rotationTransform.GetMatrix(matrix); drawContext.GetCanvas().ConcatMatrix(matrix[0], matrix[1], matrix[2], matrix[3], shift[0], shift[1]); }
/// <summary><inheritDoc/></summary> public override void DrawChildren(DrawContext drawContext) { ILineDrawer lineDrawer = this.GetProperty <ILineDrawer>(Property.LINE_DRAWER); if (lineDrawer != null) { PdfCanvas canvas = drawContext.GetCanvas(); bool isTagged = drawContext.IsTaggingEnabled(); if (isTagged) { canvas.OpenTag(new CanvasArtifact()); } Rectangle area = GetOccupiedAreaBBox(); ApplyMargins(area, false); lineDrawer.Draw(canvas, area); if (isTagged) { canvas.CloseTag(); } } }
public override void DrawBackground(DrawContext drawContext) { PdfCanvas canvas = drawContext.GetCanvas(); Matrix ctm = canvas.GetGraphicsState().GetCtm(); // Avoid rotation float?angle = this.GetPropertyAsFloat(Property.ROTATION_ANGLE); bool avoidRotation = null != angle && HasProperty(Property.BACKGROUND); bool restoreRotation = HasOwnProperty(Property.ROTATION_ANGLE); if (avoidRotation) { AffineTransform transform = new AffineTransform(ctm.Get(0), ctm.Get(1), ctm.Get(3), ctm.Get(4), ctm.Get(6) , ctm.Get(7)); try { transform = transform.CreateInverse(); } catch (NoninvertibleTransformException e) { throw new Exception(e.Message, e); } transform.Concatenate(new AffineTransform()); canvas.ConcatMatrix(transform); SetProperty(Property.ROTATION_ANGLE, null); } base.DrawBackground(drawContext); // restore concat matrix and rotation angle if (avoidRotation) { if (restoreRotation) { SetProperty(Property.ROTATION_ANGLE, angle); } else { DeleteOwnProperty(Property.ROTATION_ANGLE); } canvas.ConcatMatrix(new AffineTransform(ctm.Get(0), ctm.Get(1), ctm.Get(3), ctm.Get(4), ctm.Get(6), ctm.Get (7))); } }
public override void Draw(DrawContext drawContext) { PdfDocument document = drawContext.GetDocument(); ApplyDestination(document); ApplyAction(document); bool isTagged = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement; TagTreePointer tagPointer = null; IAccessibleElement accessibleElement = null; if (isTagged) { accessibleElement = (IAccessibleElement)GetModelElement(); PdfName role = accessibleElement.GetRole(); if (role != null && !PdfName.Artifact.Equals(role)) { tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer(); if (!tagPointer.IsElementConnectedToTag(accessibleElement)) { AccessibleAttributesApplier.ApplyLayoutAttributes(role, this, document); if (role.Equals(PdfName.TD)) { AccessibleAttributesApplier.ApplyTableAttributes(this); } if (role.Equals(PdfName.List)) { AccessibleAttributesApplier.ApplyListAttributes(this); } } tagPointer.AddTag(accessibleElement, true); } else { isTagged = false; } } bool isRelativePosition = IsRelativePosition(); if (isRelativePosition) { ApplyAbsolutePositioningTranslation(false); } BeginRotationIfApplied(drawContext.GetCanvas()); DrawBackground(drawContext); DrawBorder(drawContext); DrawChildren(drawContext); EndRotationIfApplied(drawContext.GetCanvas()); if (isRelativePosition) { ApplyAbsolutePositioningTranslation(true); } if (isTagged) { tagPointer.MoveToParent(); if (isLastRendererForModelElement) { document.GetTagStructureContext().RemoveElementConnectionToTag(accessibleElement); } } flushed = true; }
public override void Draw(DrawContext drawContext) { base.Draw(drawContext); PdfDocument document = drawContext.GetDocument(); bool isTagged = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement; bool isArtifact = false; TagTreePointer tagPointer = null; if (isTagged) { tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer(); IAccessibleElement accessibleElement = (IAccessibleElement)GetModelElement(); PdfName role = accessibleElement.GetRole(); if (role != null && !PdfName.Artifact.Equals(role)) { AccessibleAttributesApplier.ApplyLayoutAttributes(accessibleElement.GetRole(), this, document); tagPointer.AddTag(accessibleElement); } else { isTagged = false; if (PdfName.Artifact.Equals(role)) { isArtifact = true; } } } ApplyMargins(occupiedArea.GetBBox(), false); bool isRelativePosition = IsRelativePosition(); if (isRelativePosition) { ApplyAbsolutePositioningTranslation(false); } if (fixedYPosition == null) { fixedYPosition = occupiedArea.GetBBox().GetY() + pivotY; } if (fixedXPosition == null) { fixedXPosition = occupiedArea.GetBBox().GetX(); } PdfCanvas canvas = drawContext.GetCanvas(); if (isTagged) { canvas.OpenTag(tagPointer.GetTagReference()); } else { if (isArtifact) { canvas.OpenTag(new CanvasArtifact()); } } PdfXObject xObject = ((Image)(GetModelElement())).GetXObject(); canvas.AddXObject(xObject, matrix[0], matrix[1], matrix[2], matrix[3], (float)fixedXPosition + deltaX, (float )fixedYPosition); if (true.Equals(GetPropertyAsBoolean(Property.FLUSH_ON_DRAW))) { xObject.Flush(); } if (isTagged || isArtifact) { canvas.CloseTag(); } if (isRelativePosition) { ApplyAbsolutePositioningTranslation(true); } ApplyMargins(occupiedArea.GetBBox(), true); if (isTagged) { tagPointer.MoveToParent(); } }
public override void Draw(DrawContext drawContext) { if (occupiedArea == null) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ImageRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Drawing won't be performed.")); return; } bool isRelativePosition = IsRelativePosition(); if (isRelativePosition) { ApplyRelativePositioningTranslation(false); } bool isTagged = drawContext.IsTaggingEnabled(); LayoutTaggingHelper taggingHelper = null; bool isArtifact = false; TagTreePointer tagPointer = null; if (isTagged) { taggingHelper = this.GetProperty <LayoutTaggingHelper>(Property.TAGGING_HELPER); if (taggingHelper == null) { isArtifact = true; } else { isArtifact = taggingHelper.IsArtifact(this); if (!isArtifact) { tagPointer = taggingHelper.UseAutoTaggingPointerAndRememberItsPosition(this); if (taggingHelper.CreateTag(this, tagPointer)) { tagPointer.GetProperties().AddAttributes(0, AccessibleAttributesApplier.GetLayoutAttributes(this, tagPointer )); } } } } BeginTransformationIfApplied(drawContext.GetCanvas()); float?angle = this.GetPropertyAsFloat(Property.ROTATION_ANGLE); if (angle != null) { drawContext.GetCanvas().SaveState(); ApplyConcatMatrix(drawContext, angle); } base.Draw(drawContext); bool clipImageInAViewOfBorderRadius = ClipBackgroundArea(drawContext, ApplyMargins(GetOccupiedAreaBBox(), false), true); ApplyMargins(occupiedArea.GetBBox(), false); ApplyBorderBox(occupiedArea.GetBBox(), GetBorders(), false); if (fixedYPosition == null) { fixedYPosition = occupiedArea.GetBBox().GetY() + pivotY; } if (fixedXPosition == null) { fixedXPosition = occupiedArea.GetBBox().GetX(); } if (angle != null) { fixedXPosition += rotatedDeltaX; fixedYPosition -= rotatedDeltaY; drawContext.GetCanvas().RestoreState(); } PdfCanvas canvas = drawContext.GetCanvas(); if (isTagged) { if (isArtifact) { canvas.OpenTag(new CanvasArtifact()); } else { canvas.OpenTag(tagPointer.GetTagReference()); } } PdfXObject xObject = ((Image)(GetModelElement())).GetXObject(); BeginElementOpacityApplying(drawContext); canvas.AddXObject(xObject, matrix[0], matrix[1], matrix[2], matrix[3], (float)fixedXPosition + deltaX, (float )fixedYPosition); EndElementOpacityApplying(drawContext); EndTransformationIfApplied(drawContext.GetCanvas()); if (true.Equals(GetPropertyAsBoolean(Property.FLUSH_ON_DRAW))) { xObject.Flush(); } if (isTagged) { canvas.CloseTag(); } if (clipImageInAViewOfBorderRadius) { canvas.RestoreState(); } if (isRelativePosition) { ApplyRelativePositioningTranslation(true); } ApplyBorderBox(occupiedArea.GetBBox(), GetBorders(), true); ApplyMargins(occupiedArea.GetBBox(), true); if (isTagged && !isArtifact) { taggingHelper.FinishTaggingHint(this); taggingHelper.RestoreAutoTaggingPointerPosition(this); } }
/// <summary> /// Performs the drawing operation for the border of this renderer, if /// defined by any of the /// <see cref="Property.BORDER"/> /// values in either the layout /// element or this /// <see cref="IRenderer"/> /// itself. /// </summary> /// <param name="drawContext">the context (canvas, document, etc) of this drawing operation. /// </param> public virtual void DrawBorder(DrawContext drawContext) { Border[] borders = GetBorders(); bool gotBorders = false; foreach (Border border in borders) { gotBorders = gotBorders || border != null; } if (gotBorders) { float topWidth = borders[0] != null ? borders[0].GetWidth() : 0; float rightWidth = borders[1] != null ? borders[1].GetWidth() : 0; float bottomWidth = borders[2] != null ? borders[2].GetWidth() : 0; float leftWidth = borders[3] != null ? borders[3].GetWidth() : 0; Rectangle bBox = GetBorderAreaBBox(); if (bBox.GetWidth() <= 0 || bBox.GetHeight() <= 0) { ILogger logger = LoggerFactory.GetLogger(typeof(iText.Layout.Renderer.AbstractRenderer )); logger.Error(String.Format(LogMessageConstant.RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES , "border")); return; } float x1 = bBox.GetX(); float y1 = bBox.GetY(); float x2 = bBox.GetX() + bBox.GetWidth(); float y2 = bBox.GetY() + bBox.GetHeight(); bool isTagged = drawContext.IsTaggingEnabled() && GetModelElement() is IAccessibleElement; PdfCanvas canvas = drawContext.GetCanvas(); if (isTagged) { canvas.OpenTag(new CanvasArtifact()); } if (borders[0] != null) { canvas.SaveState(); borders[0].Draw(canvas, x1, y2, x2, y2, leftWidth, rightWidth); canvas.RestoreState(); } if (borders[1] != null) { canvas.SaveState(); borders[1].Draw(canvas, x2, y2, x2, y1, topWidth, bottomWidth); canvas.RestoreState(); } if (borders[2] != null) { canvas.SaveState(); borders[2].Draw(canvas, x2, y1, x1, y1, rightWidth, leftWidth); canvas.RestoreState(); } if (borders[3] != null) { canvas.SaveState(); borders[3].Draw(canvas, x1, y1, x1, y2, bottomWidth, topWidth); canvas.RestoreState(); } if (isTagged) { canvas.CloseTag(); } } }