private void CloneHelper(ref Borders borders, Borders source) { if (source != null) { borders = source.Clone(); borders._parent = source._parent; } }
/// <summary> /// Clones this instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public new PdfImageStyle Clone() { var cloned = (PdfImageStyle)base.Clone(); cloned.Content = Content.Clone(); cloned.Borders = Borders.Clone(); cloned.Properties = Properties.Clone(); return(cloned); }
/// <summary> /// Gets a borders object that should be used for rendering. /// </summary> /// <exception cref="System.ArgumentException"> /// Thrown when the cell is not in this list. /// This situation occurs if the given cell is merged "away" by a previous one. /// </exception> public Borders GetEffectiveBorders(Cell cell) { //Borders borders = cell.GetValue("Borders", GV.ReadOnly) as Borders; Borders borders = cell._borders; if (borders != null) { //Document doc = borders.Document; borders = borders.Clone(); borders._parent = cell; //doc = borders.Document; } else { borders = new Borders(cell._parent); } int cellIdx = BinarySearch(cell, new CellComparer()); if (!(cellIdx >= 0 && cellIdx < Count)) { throw new ArgumentException("cell is not a relevant cell", nameof(cell)); } if (cell._mergeRight > 0) { Cell rightBorderCell = cell.Table[cell.Row.Index, cell.Column.Index + cell._mergeRight]; if (rightBorderCell._borders != null && rightBorderCell._borders._right != null) { borders.Right = rightBorderCell._borders._right.Clone(); } else { borders._right = null; } } if (cell._mergeDown > 0) { if (cell.Table.Rows.Count <= cell.Row.Index + cell._mergeDown) { throw new ArgumentOutOfRangeException( nameof(cell.Table.Rows), $"{nameof(Cell)}.{nameof(cell.MergeDown)} exceeded the row limit.\n\n" + $" Row count: {cell.Table.Rows.Count}\n" + $"Required Row count: {cell.Row.Index + cell._mergeDown + 1} ([cell row index: {cell.Row.Index}] + [merge down: {cell.MergeDown}] + 1)\n"); } Cell bottomBorderCell = cell.Table[cell.Row.Index + cell._mergeDown, cell.Column.Index]; if (bottomBorderCell._borders != null && bottomBorderCell._borders._bottom != null) { borders.Bottom = bottomBorderCell._borders._bottom.Clone(); } else { borders._bottom = null; } } // For BorderTypes Top, Right, Bottom and Left update the width with the neighbours touching border where required. // In case of rounded corners this should not be done. Cell leftNeighbor = GetNeighbor(cellIdx, NeighborPosition.Left); if (leftNeighbor != null && leftNeighbor.RoundedCorner != RoundedCorner.TopRight && leftNeighbor.RoundedCorner != RoundedCorner.BottomRight) { Borders nbrBrdrs = leftNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Right) >= GetEffectiveBorderWidth(borders, BorderType.Left)) { borders.SetValue("Left", GetBorderFromBorders(nbrBrdrs, BorderType.Right)); } } Cell rightNeighbor = GetNeighbor(cellIdx, NeighborPosition.Right); if (rightNeighbor != null && rightNeighbor.RoundedCorner != RoundedCorner.TopLeft && rightNeighbor.RoundedCorner != RoundedCorner.BottomLeft) { Borders nbrBrdrs = rightNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Left) > GetEffectiveBorderWidth(borders, BorderType.Right)) { borders.SetValue("Right", GetBorderFromBorders(nbrBrdrs, BorderType.Left)); } } Cell topNeighbor = GetNeighbor(cellIdx, NeighborPosition.Top); if (topNeighbor != null && topNeighbor.RoundedCorner != RoundedCorner.BottomLeft && topNeighbor.RoundedCorner != RoundedCorner.BottomRight) { Borders nbrBrdrs = topNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Bottom) >= GetEffectiveBorderWidth(borders, BorderType.Top)) { borders.SetValue("Top", GetBorderFromBorders(nbrBrdrs, BorderType.Bottom)); } } Cell bottomNeighbor = GetNeighbor(cellIdx, NeighborPosition.Bottom); if (bottomNeighbor != null && bottomNeighbor.RoundedCorner != RoundedCorner.TopLeft && bottomNeighbor.RoundedCorner != RoundedCorner.TopRight) { Borders nbrBrdrs = bottomNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Top) > GetEffectiveBorderWidth(borders, BorderType.Bottom)) { borders.SetValue("Bottom", GetBorderFromBorders(nbrBrdrs, BorderType.Top)); } } return(borders); }
private void CloneHelper(ref Borders borders, Borders source) { if (source != null) { borders = source.Clone(); borders._parent = source._parent; } }
/// <summary> /// Gets a borders object that should be used for rendering. /// </summary> /// <exception cref="System.ArgumentException"> /// Thrown when the cell is not in this list. /// This situation occurs if the given cell is merged "away" by a previous one. /// </exception> public Borders GetEffectiveBorders(Cell cell) { Borders borders = cell.GetValue("Borders", GV.ReadOnly) as Borders; if (borders != null) { Document doc = borders.Document; borders = borders.Clone(); borders.parent = cell; doc = borders.Document; } else { borders = new Borders(cell.parent); } int cellIdx = this.BinarySearch(cell, new CellComparer()); if (!(cellIdx >= 0 && cellIdx < this.Count)) { throw new ArgumentException("cell is not a relevant cell", "cell"); } if (cell.mergeRight > 0) { Cell rightBorderCell = cell.Table[cell.Row.Index, cell.Column.Index + cell.mergeRight]; if (rightBorderCell.borders != null && rightBorderCell.borders.right != null) { borders.Right = rightBorderCell.borders.right.Clone(); } else { borders.right = null; } } if (cell.mergeDown > 0) { Cell bottomBorderCell = cell.Table[cell.Row.Index + cell.mergeDown, cell.Column.Index]; if (bottomBorderCell.borders != null && bottomBorderCell.borders.bottom != null) { borders.Bottom = bottomBorderCell.borders.bottom.Clone(); } else { borders.bottom = null; } } Cell leftNeighbor = GetNeighbor(cellIdx, NeighborPosition.Left); Cell rightNeighbor = GetNeighbor(cellIdx, NeighborPosition.Right); Cell topNeighbor = GetNeighbor(cellIdx, NeighborPosition.Top); Cell bottomNeighbor = GetNeighbor(cellIdx, NeighborPosition.Bottom); if (leftNeighbor != null) { Borders nbrBrdrs = leftNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Right) >= GetEffectiveBorderWidth(borders, BorderType.Left)) { borders.SetValue("Left", GetBorderFromBorders(nbrBrdrs, BorderType.Right)); } } if (rightNeighbor != null) { Borders nbrBrdrs = rightNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Left) > GetEffectiveBorderWidth(borders, BorderType.Right)) { borders.SetValue("Right", GetBorderFromBorders(nbrBrdrs, BorderType.Left)); } } if (topNeighbor != null) { Borders nbrBrdrs = topNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Bottom) >= GetEffectiveBorderWidth(borders, BorderType.Top)) { borders.SetValue("Top", GetBorderFromBorders(nbrBrdrs, BorderType.Bottom)); } } if (bottomNeighbor != null) { Borders nbrBrdrs = bottomNeighbor.GetValue("Borders", GV.ReadWrite) as Borders; if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Top) > GetEffectiveBorderWidth(borders, BorderType.Bottom)) { borders.SetValue("Bottom", GetBorderFromBorders(nbrBrdrs, BorderType.Top)); } } return(borders); }
/// <summary> /// Gets a borders object that should be used for rendering. /// </summary> /// <exception cref="System.ArgumentException"> /// Thrown when the cell is not in this list. /// This situation occurs if the given cell is merged "away" by a previous one. /// </exception> public Borders GetEffectiveBorders(Cell cell) { CellInfo cellInfo = this.CellIndex[cell] as CellInfo; if (cellInfo == null) { throw new ArgumentException("cell is not a relevant cell", "cell"); } if (cellInfo.Borders == null) { Borders borders = GetCellBorders(cell); if (borders != null) { Document doc = borders.Document; borders = borders.Clone(); borders.parent = cell; doc = borders.Document; } else { borders = new Borders(cell.parent); } if (cell.mergeRight > 0) { Cell rightBorderCell = cell.Table[cell.Row.Index, cell.Column.Index + cell.mergeRight]; if (rightBorderCell.borders != null && rightBorderCell.borders.right != null) { borders.Right = rightBorderCell.borders.right.Clone(); } else { borders.right = null; } } if (cell.mergeDown > 0) { Cell bottomBorderCell = cell.Table[cell.Row.Index + cell.mergeDown, cell.Column.Index]; if (bottomBorderCell.borders != null && bottomBorderCell.borders.bottom != null) { borders.Bottom = bottomBorderCell.borders.bottom.Clone(); } else { borders.bottom = null; } } Cell leftNeighbor = GetNeighbor(cellInfo, NeighborPosition.Left); Cell rightNeighbor = GetNeighbor(cellInfo, NeighborPosition.Right); Cell topNeighbor = GetNeighbor(cellInfo, NeighborPosition.Top); Cell bottomNeighbor = GetNeighbor(cellInfo, NeighborPosition.Bottom); if (leftNeighbor != null) { Borders nbrBrdrs = GetCellBorders(leftNeighbor); if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Right) >= GetEffectiveBorderWidth(borders, BorderType.Left)) { borders.SetValue("Left", GetBorderFromBorders(nbrBrdrs, BorderType.Right)); } } if (rightNeighbor != null) { Borders nbrBrdrs = GetCellBorders(rightNeighbor); if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Left) > GetEffectiveBorderWidth(borders, BorderType.Right)) { borders.SetValue("Right", GetBorderFromBorders(nbrBrdrs, BorderType.Left)); } } if (topNeighbor != null) { Borders nbrBrdrs = GetCellBorders(topNeighbor); if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Bottom) >= GetEffectiveBorderWidth(borders, BorderType.Top)) { borders.SetValue("Top", GetBorderFromBorders(nbrBrdrs, BorderType.Bottom)); } } if (bottomNeighbor != null) { Borders nbrBrdrs = GetCellBorders(bottomNeighbor); if (nbrBrdrs != null && GetEffectiveBorderWidth(nbrBrdrs, BorderType.Top) > GetEffectiveBorderWidth(borders, BorderType.Bottom)) { borders.SetValue("Bottom", GetBorderFromBorders(nbrBrdrs, BorderType.Top)); } } cellInfo.Borders = borders; } return(cellInfo.Borders); }