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); } }
public virtual void Draw(DrawContext drawContext) { throw new NotSupportedException(); }
public override void Draw(DrawContext drawContext) { if (occupiedArea == null) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ListItemRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Drawing won't be performed.")); return; } if (drawContext.IsTaggingEnabled()) { LayoutTaggingHelper taggingHelper = this.GetProperty <LayoutTaggingHelper>(Property.TAGGING_HELPER); if (taggingHelper != null) { if (symbolRenderer != null) { LayoutTaggingHelper.AddTreeHints(taggingHelper, symbolRenderer); } if (taggingHelper.IsArtifact(this)) { taggingHelper.MarkArtifactHint(symbolRenderer); } else { TaggingHintKey hintKey = LayoutTaggingHelper.GetHintKey(this); TaggingHintKey parentHint = taggingHelper.GetAccessibleParentHint(hintKey); if (parentHint != null && !(StandardRoles.LI.Equals(parentHint.GetAccessibleElement().GetAccessibilityProperties ().GetRole()))) { TaggingDummyElement listItemIntermediate = new TaggingDummyElement(StandardRoles.LI); IList <TaggingHintKey> intermediateKid = JavaCollectionsUtil.SingletonList <TaggingHintKey>(LayoutTaggingHelper .GetOrCreateHintKey(listItemIntermediate)); taggingHelper.ReplaceKidHint(hintKey, intermediateKid); if (symbolRenderer != null) { taggingHelper.AddKidsHint(listItemIntermediate, JavaCollectionsUtil.SingletonList <IRenderer>(symbolRenderer )); } taggingHelper.AddKidsHint(listItemIntermediate, JavaCollectionsUtil.SingletonList <IRenderer>(this)); } } } } base.Draw(drawContext); // It will be null in case of overflow (only the "split" part will contain symbol renderer. if (symbolRenderer != null && !symbolAddedInside) { symbolRenderer.SetParent(this); float x = occupiedArea.GetBBox().GetX(); ListSymbolPosition symbolPosition = (ListSymbolPosition)ListRenderer.GetListItemOrListProperty(this, parent , Property.LIST_SYMBOL_POSITION); if (symbolPosition != ListSymbolPosition.DEFAULT) { float?symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); x -= symbolAreaWidth + (float)(symbolIndent == null ? 0 : symbolIndent); if (symbolPosition == ListSymbolPosition.OUTSIDE) { UnitValue marginLeftUV = this.GetPropertyAsUnitValue(Property.MARGIN_LEFT); if (!marginLeftUV.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ListItemRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .MARGIN_LEFT)); } x += marginLeftUV.GetValue(); } } ApplyMargins(occupiedArea.GetBBox(), false); ApplyBorderBox(occupiedArea.GetBBox(), false); if (childRenderers.Count > 0) { float?yLine = null; for (int i = 0; i < childRenderers.Count; i++) { if (childRenderers[i].GetOccupiedArea().GetBBox().GetHeight() > 0) { yLine = ((AbstractRenderer)childRenderers[i]).GetFirstYLineRecursively(); if (yLine != null) { break; } } } if (yLine != null) { if (symbolRenderer is TextRenderer) { ((TextRenderer)symbolRenderer).MoveYLineTo((float)yLine); } else { symbolRenderer.Move(0, (float)yLine - symbolRenderer.GetOccupiedArea().GetBBox().GetY()); } } else { symbolRenderer.Move(0, occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight() - (symbolRenderer .GetOccupiedArea().GetBBox().GetY() + symbolRenderer.GetOccupiedArea().GetBBox().GetHeight())); } } else { if (symbolRenderer is TextRenderer) { ((TextRenderer)symbolRenderer).MoveYLineTo(occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight () - CalculateAscenderDescender()[0]); } else { symbolRenderer.Move(0, occupiedArea.GetBBox().GetY() + occupiedArea.GetBBox().GetHeight() - symbolRenderer .GetOccupiedArea().GetBBox().GetHeight() - symbolRenderer.GetOccupiedArea().GetBBox().GetY()); } } ApplyBorderBox(occupiedArea.GetBBox(), true); ApplyMargins(occupiedArea.GetBBox(), true); ListSymbolAlignment listSymbolAlignment = (ListSymbolAlignment)parent.GetProperty <ListSymbolAlignment?>(Property .LIST_SYMBOL_ALIGNMENT, ListSymbolAlignment.RIGHT); float xPosition = x - symbolRenderer.GetOccupiedArea().GetBBox().GetX(); if (listSymbolAlignment == ListSymbolAlignment.RIGHT) { xPosition += symbolAreaWidth - symbolRenderer.GetOccupiedArea().GetBBox().GetWidth(); } symbolRenderer.Move(xPosition, 0); if (symbolRenderer.GetOccupiedArea().GetBBox().GetRight() > parent.GetOccupiedArea().GetBBox().GetLeft()) { BeginElementOpacityApplying(drawContext); symbolRenderer.Draw(drawContext); EndElementOpacityApplying(drawContext); } } }
/// <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(); } } }
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(); } }