public override IList <IElement> Start(IWorkerContext ctx, Tag tag) { float x = 0, y = 0; IDictionary <String, String> attributes = tag.Attributes; if (attributes != null) { try { if (attributes.ContainsKey(X)) { x = int.Parse(attributes[X]); } } catch { // TODO: handle exception } try { if (attributes.ContainsKey(Y)) { y = int.Parse(attributes[Y]); } } catch { // TODO: handle exception } } IList <IElement> l = new List <IElement>(0); Chunk c = new ChunkCssApplier().Apply(new Chunk(""), tag); l.Add(new Text(c, x, y, tag.CSS, Split(attributes[DX]), Split(attributes[DY]))); return(l); }
/** * */ public CssAppliers() { chunk = new ChunkCssApplier(); paragraph = new ParagraphCssApplier(); nonewlineparagraph = new NoNewLineParagraphCssApplier(); htmlcell = new HtmlCellCssApplier(); list = new ListStyleTypeCssApplier(); lineseparator = new LineSeparatorCssApplier(); image = new ImageCssApplier(); }
/** * */ public CssAppliersImpl() { map = new Dictionary <Type, ICssApplier>(); map[typeof(Chunk)] = new ChunkCssApplier(null); map[typeof(Paragraph)] = new ParagraphCssApplier(this); map[typeof(NoNewLineParagraph)] = new NoNewLineParagraphCssApplier(); map[typeof(HtmlCell)] = new HtmlCellCssApplier(); map[typeof(List)] = new ListStyleTypeCssApplier(); map[typeof(LineSeparator)] = new LineSeparatorCssApplier(); map[typeof(text.Image)] = new ImageCssApplier(); map[typeof(PdfDiv)] = new DivCssApplier(); }
virtual public void ResolveFontSize() { Tag t = new Tag("t"); t.CSS["font-size"] = "12pt"; Chunk c = new Chunk("default text with no styles attached."); c = new ChunkCssApplier().Apply(c, t); Assert.AreEqual(12, c.Font.Size, 0); t.CSS["font-size"] = "18pt"; c = new ChunkCssApplier().Apply(c, t); Assert.AreEqual(18, c.Font.Size, 0); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, * java.util.List, com.itextpdf.text.Document, java.lang.String) */ public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.SanitizeInline(content); IList <IElement> l = new List <IElement>(1); if (sanitized.Length > 0) { Chunk c = new ChunkCssApplier().Apply(new Chunk(sanitized), tag); // NoNewLineParagraph noNewLineParagraph = new NoNewLineParagraphCssApplier(configuration).Apply(new NoNewLineParagraph(c), tag); l.Add(c); } return(l); }
virtual public void ResolveDefaultToLarger() { p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c1 = new ChunkCssApplier().Apply(new Chunk("Text before span "), p); Assert.AreEqual(12, c1.Font.Size, 0); span.CSS[CSS.Property.FONT_SIZE] = CSS.Value.LARGER; span.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(span).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c2 = new ChunkCssApplier().Apply(new Chunk("text in span "), span); Assert.AreEqual(13.5f, c2.Font.Size, 0); }
public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { IList <IElement> l = new List <IElement>(1); String sanitized = content.Trim(); //TODO check this if (sanitized.Length > 0) { Chunk c = new ChunkCssApplier().Apply(new Chunk(sanitized), tag); l.Add(new Text(c, tag.CSS, null, null)); } return(l); }
virtual public void ResolveSmallAndMedium() { p.CSS[CSS.Property.FONT_SIZE] = CSS.Value.SMALL; p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c1 = new ChunkCssApplier().Apply(new Chunk("Text before span "), p); Assert.AreEqual(9.75f, c1.Font.Size, 0); span.CSS[CSS.Property.FONT_SIZE] = CSS.Value.MEDIUM; span.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(span).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c2 = new ChunkCssApplier().Apply(new Chunk("text in span "), span); Assert.AreEqual(12f, c2.Font.Size, 0); }
virtual public void Resolve34ToLarger() { p.CSS[CSS.Property.FONT_SIZE] = "34pt"; p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p) + "pt"; Chunk c1 = new ChunkCssApplier().Apply(new Chunk("Text before span "), p); Assert.AreEqual(34, c1.Font.Size, 0); span.CSS[CSS.Property.FONT_SIZE] = CSS.Value.LARGER; span.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(span) + "pt"; Chunk c2 = new ChunkCssApplier().Apply(new Chunk("text in span "), span); Assert.AreEqual(34 * 1.5f, c2.Font.Size, 0); }
virtual public void Resolve34ToSmaller() { p.CSS[CSS.Property.FONT_SIZE] = "34pt"; p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c1 = new ChunkCssApplier().Apply(new Chunk("Text before span "), p); Assert.AreEqual(34, c1.Font.Size, 0); span.CSS[CSS.Property.FONT_SIZE] = CSS.Value.SMALLER; span.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(span).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c2 = new ChunkCssApplier().Apply(new Chunk("text in span "), span); Assert.AreEqual(34 * 2 / 3f, c2.Font.Size, 1e-5); }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { String sanitized = HTMLUtils.SanitizeInline(content); IList <IElement> l = new List <IElement>(1); if (sanitized.Length > 0) { Chunk c = new ChunkCssApplier().Apply(new Chunk(sanitized), tag); try { l.Add(CssAppliers.GetInstance().Apply(new NoNewLineParagraph(c), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } return(l); }
public override IList <IElement> Content(IWorkerContext ctx, Tag tag, String content) { float x = -1, y = -1; IDictionary <String, String> attributes = tag.Attributes; if (attributes != null) { try{ if (attributes.ContainsKey(X)) { x = int.Parse(attributes[X]); } }catch { // TODO: handle exception } try{ if (attributes.ContainsKey(Y)) { y = int.Parse(attributes[Y]); } }catch { // TODO: handle exception } } IList <IElement> l = new List <IElement>(1); String sanitized = HTMLUtils.SanitizeInline(content); //TODO check this if (sanitized.Length > 0 && attributes.ContainsKey(DX) && attributes.ContainsKey(DY)) { Chunk c = new ChunkCssApplier().Apply(new Chunk(sanitized), tag); if (x == -1 && y == -1) { l.Add(new Text(c, tag.CSS, Split(attributes[DX]), Split(attributes[DY]))); } else { l.Add(new Text(c, x, y, tag.CSS, Split(attributes[DX]), Split(attributes[DY]))); } } return(l); }
public void ResolveLargeXLargeXXLarge() { p.CSS[CSS.Property.FONT_SIZE] = CSS.Value.LARGE; p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c1 = new ChunkCssApplier().Apply(new Chunk("Text before span "), p); Assert.AreEqual(13.5f, c1.Font.Size, 0); span.CSS[CSS.Property.FONT_SIZE] = CSS.Value.X_LARGE; span.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(span).ToString(CultureInfo.InvariantCulture) + "pt"; Chunk c2 = new ChunkCssApplier().Apply(new Chunk("text in span "), span); Assert.AreEqual(18f, c2.Font.Size, 0); p.CSS[CSS.Property.FONT_SIZE] = CSS.Value.XX_LARGE; p.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(p) + "pt"; Chunk c3 = new ChunkCssApplier().Apply(new Chunk("Text after span."), p); Assert.AreEqual(24f, c3.Font.Size, 0); }
/** * Sets the default cell width and widest word of a cell. * <ul> * <li>cell width = {@link Table#getCellStartWidth(HtmlCell)} + the width of the widest line of text.</li> * <li>widest word = {@link Table#getCellStartWidth(HtmlCell)} + the widest word of the cell.</li> * </ul> * These 2 widths are used as the starting point when determining the width of the table in * @param cell HtmlCell of which the widths are needed. * @return float array containing the default cell width and the widest word. * <ul> * <li>float[0] = cell width.</li> * <li>float[1] = widest word.</li> * </ul> */ private float[] SetCellWidthAndWidestWord(HtmlCell cell) { IList <float> rulesWidth = new List <float>(); float widestWordOfCell = 0f; float startWidth = GetCellStartWidth(cell); float cellWidth = startWidth; IList <IElement> compositeElements = cell.CompositeElements; if (compositeElements != null) { foreach (IElement baseLevel in compositeElements) { if (baseLevel is Phrase) { for (int i = 0; i < ((Phrase)baseLevel).Count; i++) { IElement inner = ((Phrase)baseLevel)[i]; if (inner is Chunk) { cellWidth += ((Chunk)inner).GetWidthPoint(); float widestWord = startWidth + new ChunkCssApplier().GetWidestWord((Chunk)inner); if (widestWord > widestWordOfCell) { widestWordOfCell = widestWord; } } } rulesWidth.Add(cellWidth); cellWidth = startWidth; } else if (baseLevel is List) { foreach (IElement li in ((List)baseLevel).Items) { rulesWidth.Add(cellWidth); cellWidth = startWidth + ((ListItem)li).IndentationLeft; foreach (Chunk c in ((ListItem)li).Chunks) { cellWidth += c.GetWidthPoint(); float widestWord = new ChunkCssApplier().GetWidestWord(c); if (startWidth + widestWord > widestWordOfCell) { widestWordOfCell = startWidth + widestWord; } } } rulesWidth.Add(cellWidth); cellWidth = startWidth; } else if (baseLevel is PdfPTable) { rulesWidth.Add(cellWidth); cellWidth = startWidth + ((PdfPTable)baseLevel).TotalWidth; foreach (PdfPRow innerRow in ((PdfPTable)baseLevel).Rows) { int size = innerRow.GetCells().Length; TableBorderEvent evente = (TableBorderEvent)((PdfPTable)baseLevel).TableEvent; TableStyleValues values = evente.TableStyleValues; float minRowWidth = values.BorderWidthLeft + (size + 1) * values.HorBorderSpacing + values.BorderWidthRight; int celnr = 0; foreach (PdfPCell innerCell in innerRow.GetCells()) { celnr++; if (innerCell != null) { float innerWidestWordOfCell = SetCellWidthAndWidestWord(new HtmlCell(innerCell, celnr == size))[1]; minRowWidth += innerWidestWordOfCell; } } if (minRowWidth > widestWordOfCell) { widestWordOfCell = minRowWidth; } } rulesWidth.Add(cellWidth); cellWidth = startWidth; } } } foreach (float width in rulesWidth) { if (width > cellWidth) { cellWidth = width; } } return(new float[] { cellWidth, widestWordOfCell }); }