private void ApplyListSymbolPosition() { if (symbolRenderer != null) { ListSymbolPosition symbolPosition = (ListSymbolPosition)ListRenderer.GetListItemOrListProperty(this, parent , Property.LIST_SYMBOL_POSITION); if (symbolPosition == ListSymbolPosition.INSIDE) { if (childRenderers.Count > 0 && childRenderers[0] is ParagraphRenderer) { ParagraphRenderer paragraphRenderer = (ParagraphRenderer)childRenderers[0]; float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolIndent != null) { symbolRenderer.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePointValue((float)symbolIndent)); } paragraphRenderer.childRenderers.Add(0, symbolRenderer); symbolAddedInside = true; } else { if (childRenderers.Count > 0 && childRenderers[0] is ImageRenderer) { Paragraph p = new Paragraph(); p.GetAccessibilityProperties().SetRole(null); IRenderer paragraphRenderer = p.SetMargin(0).CreateRendererSubTree(); float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolIndent != null) { symbolRenderer.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePointValue((float)symbolIndent)); } paragraphRenderer.AddChild(symbolRenderer); paragraphRenderer.AddChild(childRenderers[0]); childRenderers[0] = paragraphRenderer; symbolAddedInside = true; } } if (!symbolAddedInside) { Paragraph p = new Paragraph(); p.GetAccessibilityProperties().SetRole(null); IRenderer paragraphRenderer = p.SetMargin(0).CreateRendererSubTree(); float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolIndent != null) { symbolRenderer.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePointValue((float)symbolIndent)); } paragraphRenderer.AddChild(symbolRenderer); childRenderers.Add(0, paragraphRenderer); symbolAddedInside = true; } } } }
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) { bool isRtl = BaseDirection.RIGHT_TO_LEFT.Equals(this.GetProperty <BaseDirection?>(Property.BASE_DIRECTION)); symbolRenderer.SetParent(this); float x = isRtl ? occupiedArea.GetBBox().GetRight() : occupiedArea.GetBBox().GetLeft(); ListSymbolPosition symbolPosition = (ListSymbolPosition)ListRenderer.GetListItemOrListProperty(this, parent , Property.LIST_SYMBOL_POSITION); if (symbolPosition != ListSymbolPosition.DEFAULT) { float?symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (isRtl) { x += (symbolAreaWidth + (float)(symbolIndent == null ? 0 : symbolIndent)); } else { x -= (symbolAreaWidth + (float)(symbolIndent == null ? 0 : symbolIndent)); } if (symbolPosition == ListSymbolPosition.OUTSIDE) { if (isRtl) { UnitValue marginRightUV = this.GetPropertyAsUnitValue(Property.MARGIN_RIGHT); if (!marginRightUV.IsPointValue()) { ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ListItemRenderer)); logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property .MARGIN_RIGHT)); } x -= marginRightUV.GetValue(); } else { 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 LineRenderer) { symbolRenderer.Move(0, (float)yLine - ((LineRenderer)symbolRenderer).GetYLine()); } 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, isRtl ? ListSymbolAlignment.LEFT : ListSymbolAlignment.RIGHT); float dxPosition = x - symbolRenderer.GetOccupiedArea().GetBBox().GetX(); if (listSymbolAlignment == ListSymbolAlignment.RIGHT) { if (!isRtl) { dxPosition += symbolAreaWidth - symbolRenderer.GetOccupiedArea().GetBBox().GetWidth(); } } else { if (listSymbolAlignment == ListSymbolAlignment.LEFT) { if (isRtl) { dxPosition -= (symbolAreaWidth - symbolRenderer.GetOccupiedArea().GetBBox().GetWidth()); } } } if (symbolRenderer is LineRenderer) { if (isRtl) { symbolRenderer.Move(dxPosition - symbolRenderer.GetOccupiedArea().GetBBox().GetWidth(), 0); } else { symbolRenderer.Move(dxPosition, 0); } } else { symbolRenderer.Move(dxPosition, 0); } if (symbolRenderer.GetOccupiedArea().GetBBox().GetRight() > parent.GetOccupiedArea().GetBBox().GetLeft()) { BeginElementOpacityApplying(drawContext); symbolRenderer.Draw(drawContext); EndElementOpacityApplying(drawContext); } } }
private void ApplyListSymbolPosition() { if (symbolRenderer != null) { ListSymbolPosition symbolPosition = (ListSymbolPosition)ListRenderer.GetListItemOrListProperty(this, parent , Property.LIST_SYMBOL_POSITION); if (symbolPosition == ListSymbolPosition.INSIDE) { bool isRtl = BaseDirection.RIGHT_TO_LEFT.Equals(this.GetProperty <BaseDirection?>(Property.BASE_DIRECTION)); if (childRenderers.Count > 0 && childRenderers[0] is ParagraphRenderer) { ParagraphRenderer paragraphRenderer = (ParagraphRenderer)childRenderers[0]; float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolRenderer is LineRenderer) { if (symbolIndent != null) { symbolRenderer.GetChildRenderers()[1].SetProperty(isRtl ? Property.MARGIN_LEFT : Property.MARGIN_RIGHT, UnitValue .CreatePointValue((float)symbolIndent)); } foreach (IRenderer childRenderer in symbolRenderer.GetChildRenderers()) { paragraphRenderer.childRenderers.Add(0, childRenderer); } } else { if (symbolIndent != null) { symbolRenderer.SetProperty(isRtl ? Property.MARGIN_LEFT : Property.MARGIN_RIGHT, UnitValue.CreatePointValue ((float)symbolIndent)); } paragraphRenderer.childRenderers.Add(0, symbolRenderer); } symbolAddedInside = true; } else { if (childRenderers.Count > 0 && childRenderers[0] is ImageRenderer) { Paragraph p = new Paragraph(); p.GetAccessibilityProperties().SetRole(null); IRenderer paragraphRenderer = p.SetMargin(0).CreateRendererSubTree(); float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolIndent != null) { symbolRenderer.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePointValue((float)symbolIndent)); } paragraphRenderer.AddChild(symbolRenderer); paragraphRenderer.AddChild(childRenderers[0]); childRenderers[0] = paragraphRenderer; symbolAddedInside = true; } } if (!symbolAddedInside) { Paragraph p = new Paragraph(); p.GetAccessibilityProperties().SetRole(null); IRenderer paragraphRenderer = p.SetMargin(0).CreateRendererSubTree(); float? symbolIndent = this.GetPropertyAsFloat(Property.LIST_SYMBOL_INDENT); if (symbolIndent != null) { symbolRenderer.SetProperty(Property.MARGIN_RIGHT, UnitValue.CreatePointValue((float)symbolIndent)); } paragraphRenderer.AddChild(symbolRenderer); childRenderers.Add(0, paragraphRenderer); symbolAddedInside = true; } } } }