コード例 #1
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);
            }
        }