/// <summary> /// Creates a /// <see cref="iText.Layout.Borders.Border"/> /// instance based on specific properties. /// </summary> /// <param name="outlineWidth">the outline width</param> /// <param name="outlineStyle">the outline style</param> /// <param name="outlineColor">the outline color</param> /// <param name="em">the em value</param> /// <param name="rem">the root em value</param> /// <returns>the border</returns> public static Border GetCertainBorder(String outlineWidth, String outlineStyle, String outlineColor, float em, float rem) { if (outlineStyle == null || CssConstants.NONE.Equals(outlineStyle)) { return(null); } if (outlineWidth == null) { outlineWidth = CssDefaults.GetDefaultValue(CssConstants.OUTLINE_WIDTH); } float outlineWidthValue; if (CssConstants.BORDER_WIDTH_VALUES.Contains(outlineWidth)) { if (CssConstants.THIN.Equals(outlineWidth)) { outlineWidth = "1px"; } else { if (CssConstants.MEDIUM.Equals(outlineWidth)) { outlineWidth = "2px"; } else { if (CssConstants.THICK.Equals(outlineWidth)) { outlineWidth = "3px"; } } } } UnitValue unitValue = CssDimensionParsingUtils.ParseLengthValueToPt(outlineWidth, em, rem); if (unitValue == null) { return(null); } if (unitValue.IsPercentValue()) { LOGGER.Error("outline-width in percents is not supported"); return(null); } outlineWidthValue = unitValue.GetValue(); Border outline = null; if (outlineWidthValue > 0) { DeviceRgb color = (DeviceRgb)ColorConstants.BLACK; float opacity = 1f; if (outlineColor != null) { if (!CssConstants.TRANSPARENT.Equals(outlineColor)) { float[] rgbaColor = CssDimensionParsingUtils.ParseRgbaColor(outlineColor); color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); opacity = rgbaColor[3]; } else { opacity = 0f; } } else { if (CssConstants.GROOVE.Equals(outlineStyle) || CssConstants.RIDGE.Equals(outlineStyle) || CssConstants.INSET .Equals(outlineStyle) || CssConstants.OUTSET.Equals(outlineStyle)) { color = new DeviceRgb(212, 208, 200); } } switch (outlineStyle) { case CssConstants.SOLID: case CssConstants.AUTO: { outline = new SolidBorder(color, outlineWidthValue, opacity); break; } case CssConstants.DASHED: { outline = new DashedBorder(color, outlineWidthValue, opacity); break; } case CssConstants.DOTTED: { outline = new DottedBorder(color, outlineWidthValue, opacity); break; } case CssConstants.DOUBLE: { outline = new DoubleBorder(color, outlineWidthValue, opacity); break; } case CssConstants.GROOVE: { outline = new GrooveBorder(color, outlineWidthValue, opacity); break; } case CssConstants.RIDGE: { outline = new RidgeBorder(color, outlineWidthValue, opacity); break; } case CssConstants.INSET: { outline = new InsetBorder(color, outlineWidthValue, opacity); break; } case CssConstants.OUTSET: { outline = new OutsetBorder(color, outlineWidthValue, opacity); break; } default: { outline = null; break; } } } return(outline); }
/// <summary> /// Creates a /// <see cref="iText.Layout.Borders.Border"/> /// instance based on specific properties. /// </summary> /// <param name="borderWidth">the border width</param> /// <param name="borderStyle">the border style</param> /// <param name="borderColor">the border color</param> /// <param name="em">the em value</param> /// <param name="rem">the root em value</param> /// <returns>the border</returns> public static Border GetCertainBorder(String borderWidth, String borderStyle, String borderColor, float em , float rem) { if (borderStyle == null || CssConstants.NONE.Equals(borderStyle)) { return(null); } if (borderWidth == null) { borderWidth = CssDefaults.GetDefaultValue(CssConstants.BORDER_WIDTH); } float borderWidthValue; if (CssConstants.BORDER_WIDTH_VALUES.Contains(borderWidth)) { if (CssConstants.THIN.Equals(borderWidth)) { borderWidth = "1px"; } else { if (CssConstants.MEDIUM.Equals(borderWidth)) { borderWidth = "2px"; } else { if (CssConstants.THICK.Equals(borderWidth)) { borderWidth = "3px"; } } } } UnitValue unitValue = CssUtils.ParseLengthValueToPt(borderWidth, em, rem); if (unitValue == null) { return(null); } if (unitValue.IsPercentValue()) { return(null); } borderWidthValue = unitValue.GetValue(); Border border = null; if (borderWidthValue > 0) { DeviceRgb color = (DeviceRgb)ColorConstants.BLACK; float opacity = 1f; if (borderColor != null) { if (!CssConstants.TRANSPARENT.Equals(borderColor)) { float[] rgbaColor = CssUtils.ParseRgbaColor(borderColor); color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); opacity = rgbaColor[3]; } else { opacity = 0f; } } else { if (CssConstants.GROOVE.Equals(borderStyle) || CssConstants.RIDGE.Equals(borderStyle) || CssConstants.INSET .Equals(borderStyle) || CssConstants.OUTSET.Equals(borderStyle)) { color = new DeviceRgb(212, 208, 200); } } switch (borderStyle) { case CssConstants.SOLID: { border = new SolidBorder(color, borderWidthValue, opacity); break; } case CssConstants.DASHED: { border = new DashedBorder(color, borderWidthValue, opacity); break; } case CssConstants.DOTTED: { border = new RoundDotsBorder(color, borderWidthValue, opacity); break; } case CssConstants.DOUBLE: { border = new DoubleBorder(color, borderWidthValue, opacity); break; } case CssConstants.GROOVE: { border = new GrooveBorder(color, borderWidthValue, opacity); break; } case CssConstants.RIDGE: { border = new RidgeBorder(color, borderWidthValue, opacity); break; } case CssConstants.INSET: { border = new InsetBorder(color, borderWidthValue, opacity); break; } case CssConstants.OUTSET: { border = new OutsetBorder(color, borderWidthValue, opacity); break; } default: { border = null; break; } } } return(border); }