/* (non-Javadoc) * @see com.itextpdf.html2pdf.css.apply.impl.BlockCssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker) */ public override void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker worker) { base.Apply(context, stylesContainer, worker); IPropertyContainer cell = worker.GetElementResult(); if (cell != null) { IDictionary <String, String> cssProps = stylesContainer.GetStyles(); VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForCells(cssProps, context, cell); float em = CssUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE)); float rem = context.GetCssContext().GetRootFontSize(); Border[] bordersArray = BorderStyleApplierUtil.GetBordersArray(cssProps, em, rem); if (bordersArray[0] == null) { cell.SetProperty(Property.BORDER_TOP, Border.NO_BORDER); } if (bordersArray[1] == null) { cell.SetProperty(Property.BORDER_RIGHT, Border.NO_BORDER); } if (bordersArray[2] == null) { cell.SetProperty(Property.BORDER_BOTTOM, Border.NO_BORDER); } if (bordersArray[3] == null) { cell.SetProperty(Property.BORDER_LEFT, Border.NO_BORDER); } } }
/* (non-Javadoc) * @see com.itextpdf.html2pdf.css.apply.ICssApplier#apply(com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.html2pdf.html.node.IStylesContainer, com.itextpdf.html2pdf.attach.ITagWorker) */ public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker ) { SpanTagWorker spanTagWorker = (SpanTagWorker)tagWorker; IDictionary <String, String> cssStyles = stylesContainer.GetStyles(); foreach (IPropertyContainer child in spanTagWorker.GetOwnLeafElements()) { // Workaround for form fields so that SpanTagCssApplier does not apply its font-size to the child. // Form fields have their own CSS applier // TODO remove when form fields are not leaf elements anymore if (!(child is IFormField)) { ApplyChildElementStyles(child, cssStyles, context, stylesContainer); } } VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForInlines(cssStyles, context, stylesContainer, spanTagWorker .GetAllElements()); if (cssStyles.ContainsKey(CssConstants.OPACITY)) { foreach (IPropertyContainer elem in spanTagWorker.GetAllElements()) { if (elem is Text && !elem.HasProperty(Property.OPACITY)) { OpacityApplierUtil.ApplyOpacity(cssStyles, context, elem); } } } // TODO as for now spans are flattened, let's at least make kids of floating spans floating too String floatVal = cssStyles.Get(CssConstants.FLOAT); if (floatVal != null && !CssConstants.NONE.Equals(floatVal)) { foreach (IPropertyContainer elem in spanTagWorker.GetAllElements()) { FloatPropertyValue?kidFloatVal = elem.GetProperty <FloatPropertyValue?>(Property.FLOAT); if (kidFloatVal == null || FloatPropertyValue.NONE.Equals(kidFloatVal)) { FloatApplierUtil.ApplyFloating(cssStyles, context, elem); } } } if (spanTagWorker.GetAllElements() != null) { foreach (IPropertyContainer child in spanTagWorker.GetAllElements()) { FloatPropertyValue?kidFloatVal = child.GetProperty <FloatPropertyValue?>(Property.FLOAT); if (child is Text && !child.HasOwnProperty(Property.BACKGROUND) && (kidFloatVal == null || FloatPropertyValue .NONE.Equals(kidFloatVal))) { BackgroundApplierUtil.ApplyBackground(cssStyles, context, child); } } } }
public virtual void Apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker ) { IDictionary <String, String> boxStyles = stylesContainer.GetStyles(); IPropertyContainer marginBox = tagWorker.GetElementResult(); BackgroundApplierUtil.ApplyBackground(boxStyles, context, marginBox); FontStyleApplierUtil.ApplyFontStyles(boxStyles, context, stylesContainer, marginBox); BorderStyleApplierUtil.ApplyBorders(boxStyles, context, marginBox); VerticalAlignmentApplierUtil.ApplyVerticalAlignmentForCells(boxStyles, context, marginBox); // Set overflow to HIDDEN if it's not explicitly set in css in order to avoid overlapping with page content. String overflow = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW)) ? boxStyles. Get(CssConstants.OVERFLOW) : null; String overflowX = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW_X)) ? boxStyles .Get(CssConstants.OVERFLOW_X) : overflow; if (overflowX == null || CssConstants.HIDDEN.Equals(overflowX)) { marginBox.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.HIDDEN); } else { marginBox.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE); } String overflowY = CssConstants.OVERFLOW_VALUES.Contains(boxStyles.Get(CssConstants.OVERFLOW_Y)) ? boxStyles .Get(CssConstants.OVERFLOW_Y) : overflow; if (overflowY == null || CssConstants.HIDDEN.Equals(overflowY)) { marginBox.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.HIDDEN); } else { marginBox.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE); } // TODO outlines are currently not supported for page margin boxes, because of the outlines handling specificity (they are handled on renderer's parent level) OutlineApplierUtil.ApplyOutlines(boxStyles, context, marginBox); marginBox.SetProperty(Property.FONT_PROVIDER, context.GetFontProvider()); marginBox.SetProperty(Property.FONT_SET, context.GetTempFonts()); if (!(stylesContainer is PageMarginBoxContextNode)) { ILog logger = LogManager.GetLogger(typeof(PageMarginBoxCssApplier)); logger.Warn(iText.Html2pdf.LogMessageConstant.PAGE_MARGIN_BOX_SOME_PROPERTIES_NOT_PROCESSED); return; } float availableWidth = ((PageMarginBoxContextNode)stylesContainer).GetContainingBlockForMarginBox().GetWidth (); float availableHeight = ((PageMarginBoxContextNode)stylesContainer).GetContainingBlockForMarginBox().GetHeight (); MarginApplierUtil.ApplyMargins(boxStyles, context, marginBox, availableHeight, availableWidth); PaddingApplierUtil.ApplyPaddings(boxStyles, context, marginBox, availableHeight, availableWidth); }