Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
            }
        }