public DeviceRgb colorRiesgo(string riesgo) { DeviceRgb color = new DeviceRgb(0, 0, 0); if (riesgo == "Nulo") { color = new DeviceRgb(0, 0, 204); } else if (riesgo == "Bajo") { color = new DeviceRgb(102, 178, 255); } else if (riesgo == "Intermedio") { color = new DeviceRgb(0, 204, 0); } else if (riesgo == "Alto") { color = new DeviceRgb(255, 255, 0); } else if (riesgo == "Muy Alto") { color = new DeviceRgb(255, 0, 0); } return(color); }
private Color GetColor(IList colorArgs) { Color color = null; switch (colorArgs.Count) { case 1: { color = new DeviceGray(((PdfNumber)colorArgs[0]).FloatValue()); break; } case 3: { color = new DeviceRgb(((PdfNumber)colorArgs[0]).FloatValue(), ((PdfNumber)colorArgs[1]).FloatValue(), ((PdfNumber )colorArgs[2]).FloatValue()); break; } case 4: { color = new DeviceCmyk(((PdfNumber)colorArgs[0]).FloatValue(), ((PdfNumber)colorArgs[1]).FloatValue(), ((PdfNumber )colorArgs[2]).FloatValue(), ((PdfNumber)colorArgs[3]).FloatValue()); break; } } return(color); }
public virtual void UnderlineOpacityTest01() { String outFileName = destinationFolder + "underlineOpacityTest01.pdf"; String cmpFileName = sourceFolder + "cmp_underlineOpacityTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); DeviceRgb darkBlue = new DeviceRgb(32, 80, 129); Div div = new Div().SetBackgroundColor(darkBlue).SetHeight(300); div.Add(new Paragraph("Simple text inside of the div with transparent (0.0) underline.").SetUnderline(ColorConstants .RED, 0.0f, .75f, 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.3) underline.").SetUnderline(ColorConstants .RED, 0.3f, .75f, 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.5) underline.").SetUnderline(ColorConstants .RED, 0.5f, .75f, 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.7) underline.").SetUnderline(ColorConstants .RED, 0.7f, .75f, 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); div.Add(new Paragraph("Simple text inside of the div with transparent (1.0) underline.").SetUnderline(ColorConstants .RED, 1.0f, .75f, 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); div.Add(new Paragraph("Simple text inside of the div with underline.").SetUnderline(ColorConstants.RED, .75f , 0, 0, -1 / 8f, PdfCanvasConstants.LineCapStyle.BUTT)); document.Add(div); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private static Cell CreateProfilePicture(PdfDocument pdfDocument) { var pdfFormXObject = new PdfFormXObject(new Rectangle(100, 100)); var pdfCanvas = new PdfCanvas(pdfFormXObject, pdfDocument); pdfCanvas.SaveState(); // Setting color to the circle var color = new DeviceRgb(255, 255, 255); pdfCanvas.SetColor(color, true); // creating a circle pdfCanvas.Circle(50, 50, 50); pdfCanvas.Fill(); var rect = new Rectangle(pdfFormXObject.GetWidth() - 100, pdfFormXObject.GetHeight() - 90, 100, 75); pdfCanvas.Rectangle(rect); pdfCanvas.RestoreState(); var paragraph = new Paragraph("302\r\nPicture\r\n not available").SetTextAlignment(TextAlignment.CENTER).SetFontColor(ColorConstants.BLACK); using (var c = new Canvas(pdfCanvas, pdfDocument, rect, true)) { c.Add(paragraph); c.Close(); } var image = new Image(pdfFormXObject).SetHeight(100).SetWidth(100).SetHorizontalAlignment(HorizontalAlignment.CENTER); var cell = new Cell().SetPaddingTop(Spacing).SetPaddingBottom(Spacing).Add(image); return(cell); }
public virtual void BackgroundOpacityTest01() { String outFileName = destinationFolder + "backgroundOpacityTest01.pdf"; String cmpFileName = sourceFolder + "cmp_backgroundOpacityTest01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); DeviceRgb darkBlue = new DeviceRgb(32, 80, 129); Div div = new Div().SetBackgroundColor(darkBlue).SetHeight(200); div.Add(new Paragraph("Simple text inside of the div with transparent (0.0) background.").SetBackgroundColor (ColorConstants.RED, 0f)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.3) background.").SetBackgroundColor (ColorConstants.RED, 0.3f)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.5) background.").SetBackgroundColor (ColorConstants.RED, 0.5f)); div.Add(new Paragraph("Simple text inside of the div with transparent (0.7) background.").SetBackgroundColor (ColorConstants.RED, 0.7f)); div.Add(new Paragraph("Simple text inside of the div with transparent (1.0) background.").SetBackgroundColor (ColorConstants.RED, 1f)); div.Add(new Paragraph("Simple text inside of the div with background.").SetBackgroundColor(ColorConstants. RED)); document.Add(div); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private MimeFile RenderCertificate(CertificateEntity entity) { using MemoryStream ms = new MemoryStream(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(ms)); Document doc = new Document(pdfDoc, new PageSize(PageSize.LETTER.GetHeight(), PageSize.LETTER.GetWidth())); PageSize ps = pdfDoc.GetDefaultPageSize(); doc.SetMargins(25f, 0f, 25f, 0f); PdfFont times = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD); PdfFont helvetica = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); doc.SetFont(times).SetFontSize(34); doc.ShowTextAligned("King County Search And Rescue Association", ps.GetWidth() / 2, ps.GetHeight() - 100, TextAlignment.CENTER); var imgName = typeof(CertificateStore).Assembly.GetManifestResourceNames().Single(f => f.EndsWith(".kcsara_logo_color.jpg")); using (var stream = typeof(CertificateStore).Assembly.GetManifestResourceStream(imgName)) { var logoData = new byte[stream.Length]; stream.Read(logoData, 0, logoData.Length); doc.Add(new Image(ImageDataFactory.CreateJpeg(logoData), (ps.GetWidth() - 172) / 2, 330, 172)); } doc.SetFont(helvetica).SetFontSize(18); doc.ShowTextAligned("This Certificate of Achievement is to acknowledge that", ps.GetWidth() / 2, 282, TextAlignment.CENTER); doc.SetFont(times).SetFontSize(30); doc.ShowTextAligned(entity.Name, ps.GetWidth() / 2, 230, TextAlignment.CENTER); doc.ShowTextAligned( new Paragraph().Add("has reaffirmed a dedication to serve the public, through continued\nprofessional development, and completion of a written exam for:") .SetFont(helvetica).SetFontSize(18).SetTextAlignment(TextAlignment.CENTER).SetMultipliedLeading(1.3f), ps.GetWidth() / 2, 160, TextAlignment.CENTER); doc.ShowTextAligned(new Paragraph().Add(entity.Title).SetFont(times).SetFontSize(26).SetTextAlignment(TextAlignment.CENTER), ps.GetWidth() / 2, 120, TextAlignment.CENTER); doc.ShowTextAligned(new Paragraph().Add(string.Format("Issued this {0}{1} Day of {2:MMMM, yyyy}", entity.Completed.Day, GetOrdinal(entity.Completed.Day), entity.Completed)).SetFont(helvetica).SetFontSize(15).SetTextAlignment(TextAlignment.CENTER), ps.GetWidth() / 2, 76, TextAlignment.CENTER); Color grey = new DeviceRgb(200, 200, 200); PdfCanvas canvas = new PdfCanvas(pdfDoc.GetFirstPage()); doc.SetFont(helvetica).SetFontSize(7).SetFontColor(grey); doc.ShowTextAligned(string.Format("Submission {0}", entity.RowKey), 75, 28, TextAlignment.LEFT); doc.ShowTextAligned(url, ps.GetWidth() - 75, 28, TextAlignment.RIGHT); doc.Close(); return(new MimeFile { Data = ms.ToArray(), FileName = entity.Title.ToLowerInvariant().Replace(" ", "-") + ".pdf", MimeType = "application/pdf" }); }
/// <summary>Operations to perform before drawing an element.</summary> /// <remarks> /// Operations to perform before drawing an element. /// This includes setting stroke color and width, fill color. /// </remarks> /// <param name="context">the svg draw context</param> internal virtual void PreDraw(SvgDrawContext context) { if (this.attributesAndStyles != null) { PdfCanvas currentCanvas = context.GetCurrentCanvas(); if (!partOfClipPath) { { // fill String fillRawValue = GetAttribute(SvgConstants.Attributes.FILL); this.doFill = !SvgConstants.Values.NONE.EqualsIgnoreCase(fillRawValue); if (doFill && CanElementFill()) { Color color = ColorConstants.BLACK; if (fillRawValue != null) { color = WebColors.GetRGBColor(fillRawValue); } currentCanvas.SetFillColor(color); } } { // stroke String strokeRawValue = GetAttribute(SvgConstants.Attributes.STROKE); if (!SvgConstants.Values.NONE.EqualsIgnoreCase(strokeRawValue)) { DeviceRgb rgbColor = WebColors.GetRGBColor(strokeRawValue); if (strokeRawValue != null && rgbColor != null) { currentCanvas.SetStrokeColor(rgbColor); String strokeWidthRawValue = GetAttribute(SvgConstants.Attributes.STROKE_WIDTH); float strokeWidth = 1f; if (strokeWidthRawValue != null) { strokeWidth = CssUtils.ParseAbsoluteLength(strokeWidthRawValue); } currentCanvas.SetLineWidth(strokeWidth); doStroke = true; } } } { // opacity String opacityValue = GetAttribute(SvgConstants.Attributes.FILL_OPACITY); if (opacityValue != null && !SvgConstants.Values.NONE.EqualsIgnoreCase(opacityValue)) { PdfExtGState gs1 = new PdfExtGState(); gs1.SetFillOpacity(float.Parse(opacityValue, System.Globalization.CultureInfo.InvariantCulture)); currentCanvas.SetExtGState(gs1); } } } } }
public virtual void BackgroundConstructorWithClipTest() { DeviceRgb deviceRgbColor = new DeviceRgb(); float opacity = 10f; BackgroundBox backgroundClip = BackgroundBox.BORDER_BOX; Background background = new Background(deviceRgbColor, opacity, backgroundClip); NUnit.Framework.Assert.AreEqual(deviceRgbColor, background.GetColor()); NUnit.Framework.Assert.AreEqual(opacity, background.GetOpacity(), EPS); NUnit.Framework.Assert.AreEqual(backgroundClip, background.GetBackgroundClip()); }
protected virtual void ReadLegend(XmlTextReader xml) { //Int32 index = Convert.ToInt32(xml.GetAttribute("index")); iText.Kernel.Colors.DeviceRgb iTextColour = new DeviceRgb(); ReadColour(xml, ref iTextColour, "colour"); String label = xml.GetAttribute("label"); Legends.Add(new Legend(label, iTextColour)); mColours.Add(iTextColour); }
private static void ApplyBackgroundColor(String backgroundColorStr, IPropertyContainer element, BackgroundBox clip) { if (backgroundColorStr != null && !CssConstants.TRANSPARENT.Equals(backgroundColorStr)) { float[] rgbaColor = CssDimensionParsingUtils.ParseRgbaColor(backgroundColorStr); Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); float opacity = rgbaColor[3]; Background backgroundColor = new Background(color, opacity, clip); element.SetProperty(Property.BACKGROUND, backgroundColor); } }
protected virtual void ReadColour(XmlTextReader xml, ref iText.Kernel.Colors.DeviceRgb iTextColour, String attributeName) { String colourString = xml.GetAttribute(attributeName); String[] values = colourString.Split(','); if (values.Length == 3) { int r = Convert.ToInt32(values[0]); int g = Convert.ToInt32(values[1]); int b = Convert.ToInt32(values[2]); iTextColour = new DeviceRgb(r, g, b); } }
/// <summary>Applies background to an element.</summary> /// <param name="cssProps">the CSS properties</param> /// <param name="context">the processor context</param> /// <param name="element">the element</param> public static void ApplyBackground(IDictionary <String, String> cssProps, ProcessorContext context, IPropertyContainer element) { String backgroundColorStr = cssProps.Get(CssConstants.BACKGROUND_COLOR); if (backgroundColorStr != null && !CssConstants.TRANSPARENT.Equals(backgroundColorStr)) { float[] rgbaColor = CssUtils.ParseRgbaColor(backgroundColorStr); Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); float opacity = rgbaColor[3]; Background backgroundColor = new Background(color, opacity); element.SetProperty(Property.BACKGROUND, backgroundColor); } String backgroundImageStr = cssProps.Get(CssConstants.BACKGROUND_IMAGE); if (backgroundImageStr != null && !backgroundImageStr.Equals(CssConstants.NONE)) { String backgroundRepeatStr = cssProps.Get(CssConstants.BACKGROUND_REPEAT); PdfXObject image = context.GetResourceResolver().RetrieveImageExtended(CssUtils.ExtractUrl(backgroundImageStr )); bool repeatX = true; bool repeatY = true; if (backgroundRepeatStr != null) { repeatX = backgroundRepeatStr.Equals(CssConstants.REPEAT) || backgroundRepeatStr.Equals(CssConstants.REPEAT_X ); repeatY = backgroundRepeatStr.Equals(CssConstants.REPEAT) || backgroundRepeatStr.Equals(CssConstants.REPEAT_Y ); } if (image != null) { BackgroundImage backgroundImage = null; if (image is PdfImageXObject) { backgroundImage = new BackgroundImage((PdfImageXObject)image, repeatX, repeatY); } else { if (image is PdfFormXObject) { backgroundImage = new BackgroundImage((PdfFormXObject)image, repeatX, repeatY); } else { throw new InvalidOperationException(); } } element.SetProperty(Property.BACKGROUND_IMAGE, backgroundImage); } } }
private Paragraph CriarParagrafo(string texto, float tamanhoFonte, Margem margem, string cor, float alturaPagina, int?paginaInicial, int?totalPaginas) { PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); float fontSize; float padding; DefinirParametrosParagrafo(alturaPagina, tamanhoFonte, out fontSize, out padding); DeviceRgb color = Hexa2Rgb(cor); var style = new Style(); style.SetFont(font); style.SetFontSize(fontSize); style.SetFontColor(color); if (margem == Margem.Esquerda) { style.SetPaddingTop(padding); } else if (margem == Margem.Direita) { style.SetPaddingBottom(padding); } else { throw new Exception("Valor de margem desconhecido."); } if (texto.Contains("{PaginaInicial}")) { texto = texto.Replace("{PaginaInicial}", paginaInicial.ToString()); } if (texto.Contains("{TotalPaginas}")) { texto = texto.Replace("{TotalPaginas}", totalPaginas.ToString()); } Text text = new Text(texto); text.AddStyle(style); Paragraph paragraph = new Paragraph(text); paragraph.SetWidth(alturaPagina) .SetFixedLeading(fontSize + 1); return(paragraph); }
private DeviceRgb Hexa2Rgb(string corHexa) { if (corHexa.Length == 6) { int red = Convert.ToInt32(corHexa.Substring(0, 2), 16); int green = Convert.ToInt32(corHexa.Substring(2, 2), 16); int blue = Convert.ToInt32(corHexa.Substring(4, 2), 16); DeviceRgb deviceRgb = new DeviceRgb(red, green, blue); return(deviceRgb); } else { throw new Exception("Informe todos os 6 caracteres do código hexadecimal"); } }
private void DoAddStamp(PdfDocument pdfDocument, ConversionProfile profile, string fontPath) { var font = PdfFontFactory.CreateFont(fontPath, PdfEncodings.IDENTITY_H, true); var color = new DeviceRgb(profile.Stamping.Color); pdfDocument.AddFont(font); var numberOfPages = pdfDocument.GetNumberOfPages(); for (int i = 1; i <= numberOfPages; i++) { var pdfImportedPage = pdfDocument.GetPage(i); var pageSize = pdfImportedPage.GetPageSize(); float rotationAngle = (float)(Math.Atan2(pageSize.GetHeight(), pageSize.GetWidth())); var pdfPage = pdfDocument.GetPage(i); var layer = pdfPage.NewContentStreamAfter(); var canvas = new PdfCanvas(layer, pdfPage.GetResources(), pdfDocument); canvas.SaveState(); var canvasLayer = new Canvas(canvas, pdfDocument, pdfPage.GetPageSize()); if (profile.Stamping.FontAsOutline) { canvasLayer.SetStrokeWidth(profile.Stamping.FontOutlineWidth); canvasLayer.SetStrokeColor(color); canvasLayer.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.STROKE); } canvasLayer.SetFontColor(color); canvasLayer.SetFont(font); canvasLayer.SetFontSize(profile.Stamping.FontSize); canvasLayer.ShowTextAligned( profile.Stamping.StampText, pdfPage.GetPageSize().GetWidth() / 2, pdfPage.GetPageSize().GetHeight() / 2, TextAlignment.CENTER, VerticalAlignment.MIDDLE, rotationAngle); canvas.RestoreState(); } }
public static byte[] CreateLabels() { var garamond = Path.Combine(CurrentPath, "Fonts", "GARA.TTF"); var garamondBold = Path.Combine(CurrentPath, "Fonts", "GARABD.TTF"); var font = PdfFontFactory.CreateFont(garamond, true); var boldFont = PdfFontFactory.CreateFont(garamondBold, true); var beers = GetBeers(); var labelBackground = new DeviceRgb(254, 246, 229); var drawActionRectangles = beers.SelectMany(beer => new List <Action <PdfCanvas, Rectangle> > { (canvas, rectangle) => { TextSharpHelpers.DrawRectangle(canvas, rectangle, labelBackground); //name //gold label const float startOfLabelOffset = 4f; var topCursor = new Cursor(); topCursor.AdvanceCursor(rectangle.GetTop() - startOfLabelOffset); if (beer.Points > 0) { DrawPoints(rectangle, topCursor, canvas, beer, boldFont); } if (beer.Barrel) { DrawBarrel(rectangle, topCursor, canvas); } if (beer.Hops) { DrawHops(rectangle, topCursor, canvas); } if (!string.IsNullOrEmpty(beer.GoldLabelImageName)) { DrawGoldLabel(rectangle, topCursor, canvas, beer); } DrawBeerName(rectangle, topCursor, canvas, beer, font); } }).ToList(); var drawActionRectangleQueue = new Queue <Action <PdfCanvas, Rectangle> >(drawActionRectangles); return(PdfGenerator.DrawRectangles( drawActionRectangleQueue, ColorConstants.WHITE)); }
public static Cell CrearCelda(string tipo, string valor) { Cell celda = null; Paragraph p = new Paragraph(valor); //LETRAS iText.Kernel.Font.PdfFont letraNormal = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); iText.Kernel.Font.PdfFont letraNegrilla = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD); //COLORES Color colorLetraEncabezado = new DeviceRgb(255, 255, 255); Color colorLetraPrincipal = new DeviceRgb(0, 0, 0); switch (tipo) { case "key": celda = new Cell().Add(p) .SetFont(letraNegrilla).SetFontSize(8).SetTextAlignment(TextAlignment.RIGHT).SetVerticalAlignment(VerticalAlignment.MIDDLE) .SetFontColor(colorLetraPrincipal) .SetBorder(Border.NO_BORDER) .SetBorderBottom(new DottedBorder(ColorConstants.BLACK, 1, 0.4f)); break; case "value": celda = new Cell().Add(p) .SetFont(letraNormal).SetFontSize(8).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE) .SetFontColor(colorLetraPrincipal) .SetBorder(Border.NO_BORDER) .SetBorderBottom(new DottedBorder(ColorConstants.BLACK, 1, 0.4f)); break; case "error": celda = new Cell().Add(p) .SetFont(letraNormal).SetFontSize(6).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE) .SetFontColor(colorLetraPrincipal) .SetBorder(Border.NO_BORDER) .SetBorderBottom(new DottedBorder(ColorConstants.BLACK, 1, 0.4f)); break; } return(celda); }
protected internal virtual Color GetDarkerColor() { if (color is DeviceRgb) { return(DeviceRgb.MakeDarker((DeviceRgb)color)); } else { if (color is DeviceCmyk) { return(DeviceCmyk.MakeDarker((DeviceCmyk)color)); } else { if (color is DeviceGray) { return(DeviceGray.MakeDarker((DeviceGray)color)); } } } return(color); }
/// <summary> /// Makes the /// <see cref="Border.transparentColor"/> /// color of the border darker and returns the result /// </summary> /// <returns>The darker color</returns> protected internal virtual Color GetDarkerColor() { Color color = this.transparentColor.GetColor(); if (color is DeviceRgb) { return(DeviceRgb.MakeDarker((DeviceRgb)color)); } else { if (color is DeviceCmyk) { return(DeviceCmyk.MakeDarker((DeviceCmyk)color)); } else { if (color is DeviceGray) { return(DeviceGray.MakeDarker((DeviceGray)color)); } } } return(color); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> private void ElementOpacityTest(String elem) { String outFileName = destinationFolder + elem + "ElementOpacity01.pdf"; String cmpFileName = sourceFolder + "cmp_" + elem + "ElementOpacity01.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdfDocument); DeviceRgb divBackground = WebColors.GetRGBColor("#82abd6"); DeviceRgb paraBackground = WebColors.GetRGBColor("#994ec7"); DeviceRgb textBackground = WebColors.GetRGBColor("#009688"); DeviceRgb tableBackground = WebColors.GetRGBColor("#ffc107"); document.SetFontColor(ColorConstants.WHITE); Div div = new Div().SetBackgroundColor(divBackground); if ("div".Equals(elem)) { div.SetOpacity(0.3f); } div.Add(new Paragraph("direct div content")); Paragraph p = new Paragraph("direct paragraph content").SetBackgroundColor(paraBackground); if ("para".Equals(elem)) { p.SetOpacity(0.3f); } Text text = new Text("text content").SetBackgroundColor(textBackground); p.Add(text); if ("text".Equals(elem)) { text.SetOpacity(0.3f); } div.Add(p); iText.Layout.Element.Image image = new Image(ImageDataFactory.Create(sourceFolder + "itis.jpg")); div.Add(image); if ("image".Equals(elem)) { image.SetOpacity(0.3f); } Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth().SetBackgroundColor(tableBackground ); table.AddCell("Cell00"); table.AddCell("Cell01"); Cell cell10 = new Cell().Add(new Paragraph("Cell10")); if ("cell".Equals(elem)) { cell10.SetOpacity(0.3f); } table.AddCell(cell10); table.AddCell(new Cell().Add(new Paragraph("Cell11"))); if ("table".Equals(elem)) { table.SetOpacity(0.3f); } div.Add(table); List list = new List(); if ("list".Equals(elem)) { list.SetOpacity(0.3f); } ListItem listItem = new ListItem("item 0"); list.Add(listItem); if ("listItem".Equals(elem)) { listItem.SetOpacity(0.3f); } list.Add("item 1"); div.Add(list); document.Add(div); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void HandleEvent(Event pdfEvent) { { PdfDocumentEvent docEvent = (PdfDocumentEvent)pdfEvent; PdfDocument pdfDoc = docEvent.GetDocument(); Document document = new Document(pdfDoc); PdfPage page = docEvent.GetPage(); int pageNumber = pdfDoc.GetPageNumber(page); Rectangle pageSize = page.GetPageSize(); PdfCanvas pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc); //Add header and footer PdfFont font = PdfFontFactory.CreateRegisteredFont("calibri-bold"); if (pageNumber == 1) { if (_docOptions.HasFlag(DocConverter.DocOptions.AddHeaderPageOne)) { pdfCanvas.SaveState(); PdfExtGState state = new PdfExtGState(); state.SetFillOpacity(1.0f); pdfCanvas.SetExtGState(state); var imageHeight = _idHeaderFirst.GetHeight() * 72 / 96; //convert pixels to points var imageToAdd = new Image(_idHeaderFirst, 0, pageSize.GetTop() - imageHeight, pageSize.GetWidth()); imageToAdd.GetAccessibilityProperties() .SetAlternateDescription("Background header image"); imageToAdd.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); PdfLayer pdflayer = new PdfLayer("main layer", pdfDoc); pdflayer.SetOn(true); Canvas canvas = new Canvas(pdfCanvas, pdfDoc, document.GetPageEffectiveArea(pdfDoc.GetDefaultPageSize())); pdflayer.SetPageElement("L"); pdfCanvas.BeginLayer(pdflayer); canvas.EnableAutoTagging(page); canvas.Add(imageToAdd); pdfCanvas.EndLayer(); } if (_docOptions.HasFlag(DocConverter.DocOptions.DisplayTitle)) { //Add Title Color purpleColor = new DeviceRgb(85, 60, 116); TagTreePointer tagPointer = new TagTreePointer(pdfDoc); tagPointer.SetPageForTagging(page); tagPointer.AddTag(StandardRoles.TITLE); pdfCanvas.BeginText().SetColor(purpleColor, true).SetFontAndSize(font, 28) .MoveText(42, pageSize.GetTop() - 150).OpenTag(tagPointer.GetTagReference()).ShowText(_title).CloseTag().Stroke(); } } else if (_docOptions.HasFlag(DocConverter.DocOptions.AddHeaderAllPages)) { pdfCanvas.SaveState(); PdfExtGState state = new PdfExtGState(); state.SetFillOpacity(1.0f); pdfCanvas.SetExtGState(state); var imageHeight = _idHeaderAll.GetHeight() * 72 / 96; //convert pixels to points var imageToAdd = new Image(_idHeaderAll, 0, pageSize.GetTop() - imageHeight, pageSize.GetWidth()); imageToAdd.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); imageToAdd.GetAccessibilityProperties() .SetAlternateDescription("Background header image"); PdfLayer pdflayer = new PdfLayer("main layer", pdfDoc); pdflayer.SetOn(true); Canvas canvas = new Canvas(pdfCanvas, pdfDoc, document.GetPageEffectiveArea(pdfDoc.GetDefaultPageSize())); pdfCanvas.BeginLayer(pdflayer); canvas.EnableAutoTagging(page); canvas.Add(imageToAdd); pdfCanvas.EndLayer(); pdfCanvas.RestoreState(); } if (_docOptions.HasFlag(DocConverter.DocOptions.AddLineBottomEachPage)) { //Add line to the bottom Color blueColor = new DeviceCmyk(100, 25, 0, 39); pdfCanvas.SetStrokeColor(blueColor) .MoveTo(36, 36) .LineTo(559, 36) .ClosePathStroke(); } pdfCanvas.Release(); } }
/// <summary>Applies font styles to an element.</summary> /// <param name="cssProps">the CSS props</param> /// <param name="context">the processor context</param> /// <param name="stylesContainer">the styles container</param> /// <param name="element">the element</param> public static void ApplyFontStyles(IDictionary <String, String> cssProps, ProcessorContext context, IStylesContainer stylesContainer, IPropertyContainer element) { float em = CssUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE)); float rem = context.GetCssContext().GetRootFontSize(); if (em != 0) { element.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(em)); } if (cssProps.Get(CssConstants.FONT_FAMILY) != null) { // TODO DEVSIX-2534 IList <String> fontFamilies = FontFamilySplitter.SplitFontFamily(cssProps.Get(CssConstants.FONT_FAMILY)); element.SetProperty(Property.FONT, fontFamilies.ToArray(new String[fontFamilies.Count])); } if (cssProps.Get(CssConstants.FONT_WEIGHT) != null) { element.SetProperty(Property.FONT_WEIGHT, cssProps.Get(CssConstants.FONT_WEIGHT)); } if (cssProps.Get(CssConstants.FONT_STYLE) != null) { element.SetProperty(Property.FONT_STYLE, cssProps.Get(CssConstants.FONT_STYLE)); } String cssColorPropValue = cssProps.Get(CssConstants.COLOR); if (cssColorPropValue != null) { TransparentColor transparentColor; if (!CssConstants.TRANSPARENT.Equals(cssColorPropValue)) { float[] rgbaColor = CssUtils.ParseRgbaColor(cssColorPropValue); Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); float opacity = rgbaColor[3]; transparentColor = new TransparentColor(color, opacity); } else { transparentColor = new TransparentColor(ColorConstants.BLACK, 0f); } element.SetProperty(Property.FONT_COLOR, transparentColor); } // Make sure to place that before text-align applier String direction = cssProps.Get(CssConstants.DIRECTION); if (CssConstants.RTL.Equals(direction)) { element.SetProperty(Property.BASE_DIRECTION, BaseDirection.RIGHT_TO_LEFT); element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT); } else { if (CssConstants.LTR.Equals(direction)) { element.SetProperty(Property.BASE_DIRECTION, BaseDirection.LEFT_TO_RIGHT); element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT); } } if (stylesContainer is IElementNode && ((IElementNode)stylesContainer).ParentNode() is IElementNode && CssConstants .RTL.Equals(((IElementNode)((IElementNode)stylesContainer).ParentNode()).GetStyles().Get(CssConstants. DIRECTION)) && !element.HasProperty(Property.HORIZONTAL_ALIGNMENT)) { // We should only apply horizontal alignment if parent has dir attribute or direction property element.SetProperty(Property.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT); } // Make sure to place that after direction applier String align = cssProps.Get(CssConstants.TEXT_ALIGN); if (CssConstants.LEFT.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT); } else { if (CssConstants.RIGHT.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT); } else { if (CssConstants.CENTER.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.CENTER); } else { if (CssConstants.JUSTIFY.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.JUSTIFIED); element.SetProperty(Property.SPACING_RATIO, 1f); } } } } String whiteSpace = cssProps.Get(CssConstants.WHITE_SPACE); element.SetProperty(Property.NO_SOFT_WRAP_INLINE, CssConstants.NOWRAP.Equals(whiteSpace) || CssConstants.PRE .Equals(whiteSpace)); String textDecorationProp = cssProps.Get(CssConstants.TEXT_DECORATION); if (textDecorationProp != null) { String[] textDecorations = iText.IO.Util.StringUtil.Split(textDecorationProp, "\\s+"); IList <Underline> underlineList = new List <Underline>(); foreach (String textDecoration in textDecorations) { if (CssConstants.BLINK.Equals(textDecoration)) { logger.Error(iText.Html2pdf.LogMessageConstant.TEXT_DECORATION_BLINK_NOT_SUPPORTED); } else { if (CssConstants.LINE_THROUGH.Equals(textDecoration)) { underlineList.Add(new Underline(null, .75f, 0, 0, 1 / 4f, PdfCanvasConstants.LineCapStyle.BUTT)); } else { if (CssConstants.OVERLINE.Equals(textDecoration)) { underlineList.Add(new Underline(null, .75f, 0, 0, 9 / 10f, PdfCanvasConstants.LineCapStyle.BUTT)); } else { if (CssConstants.UNDERLINE.Equals(textDecoration)) { underlineList.Add(new Underline(null, .75f, 0, 0, -1 / 10f, PdfCanvasConstants.LineCapStyle.BUTT)); } else { if (CssConstants.NONE.Equals(textDecoration)) { underlineList = null; // if none and any other decoration are used together, none is displayed break; } } } } } } element.SetProperty(Property.UNDERLINE, underlineList); } String textIndent = cssProps.Get(CssConstants.TEXT_INDENT); if (textIndent != null) { UnitValue textIndentValue = CssUtils.ParseLengthValueToPt(textIndent, em, rem); if (textIndentValue != null) { if (textIndentValue.IsPointValue()) { element.SetProperty(Property.FIRST_LINE_INDENT, textIndentValue.GetValue()); } else { logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED , CssConstants.TEXT_INDENT)); } } } String letterSpacing = cssProps.Get(CssConstants.LETTER_SPACING); if (letterSpacing != null && !letterSpacing.Equals(CssConstants.NORMAL)) { UnitValue letterSpacingValue = CssUtils.ParseLengthValueToPt(letterSpacing, em, rem); if (letterSpacingValue.IsPointValue()) { element.SetProperty(Property.CHARACTER_SPACING, letterSpacingValue.GetValue()); } } // browsers ignore values in percents String wordSpacing = cssProps.Get(CssConstants.WORD_SPACING); if (wordSpacing != null) { UnitValue wordSpacingValue = CssUtils.ParseLengthValueToPt(wordSpacing, em, rem); if (wordSpacingValue != null) { if (wordSpacingValue.IsPointValue()) { element.SetProperty(Property.WORD_SPACING, wordSpacingValue.GetValue()); } } } // browsers ignore values in percents String lineHeight = cssProps.Get(CssConstants.LINE_HEIGHT); // specification does not give auto as a possible lineHeight value // nevertheless some browsers compute it as normal so we apply the same behaviour. // What's more, it's basically the same thing as if lineHeight is not set in the first place if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight) ) { if (CssUtils.IsNumericValue(lineHeight)) { float?mult = CssUtils.ParseFloat(lineHeight); if (mult != null) { element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, (float)mult)); } } else { UnitValue lineHeightValue = CssUtils.ParseLengthValueToPt(lineHeight, em, rem); if (lineHeightValue != null && lineHeightValue.IsPointValue()) { element.SetProperty(Property.LEADING, new Leading(Leading.FIXED, lineHeightValue.GetValue())); } else { if (lineHeightValue != null) { element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, lineHeightValue.GetValue() / 100)); } } } } else { element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, 1.2f)); } }
/// <summary> /// Creates an InsetBorder instance with the specified width and the /// <see cref="iText.Kernel.Colors.DeviceRgb">rgb color</see>. /// </summary> /// <param name="width">width of the border</param> /// <param name="color"> /// the /// <see cref="iText.Kernel.Colors.DeviceRgb">rgb color</see> /// of the border /// </param> public InsetBorder(DeviceRgb color, float width) : base(color, width) { }
/// <summary>Creates an InsetBorder instance with the specified width, color and opacity.</summary> /// <param name="color">color of the border</param> /// <param name="width">width of the border</param> /// <param name="opacity">opacity of the border</param> public InsetBorder(DeviceRgb color, float width, float opacity) : base(color, width, opacity) { }
public virtual iText.Kernel.Pdf.Annot.DA.AnnotationDefaultAppearance SetColor(DeviceRgb rgbColor) { SetColorOperand(rgbColor.GetColorValue(), "rg"); return(this); }
/// <summary>Applies font styles to an element.</summary> /// <param name="cssProps">the CSS props</param> /// <param name="context">the processor context</param> /// <param name="stylesContainer">the styles container</param> /// <param name="element">the element</param> public static void ApplyFontStyles(IDictionary <String, String> cssProps, ProcessorContext context, IStylesContainer stylesContainer, IPropertyContainer element) { float em = CssDimensionParsingUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE)); float rem = context.GetCssContext().GetRootFontSize(); if (em != 0) { element.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(em)); } if (cssProps.Get(CssConstants.FONT_FAMILY) != null) { // TODO DEVSIX-2534 IList <String> fontFamilies = FontFamilySplitter.SplitFontFamily(cssProps.Get(CssConstants.FONT_FAMILY)); element.SetProperty(Property.FONT, fontFamilies.ToArray(new String[fontFamilies.Count])); } if (cssProps.Get(CssConstants.FONT_WEIGHT) != null) { element.SetProperty(Property.FONT_WEIGHT, cssProps.Get(CssConstants.FONT_WEIGHT)); } if (cssProps.Get(CssConstants.FONT_STYLE) != null) { element.SetProperty(Property.FONT_STYLE, cssProps.Get(CssConstants.FONT_STYLE)); } String cssColorPropValue = cssProps.Get(CssConstants.COLOR); if (cssColorPropValue != null) { TransparentColor transparentColor; if (!CssConstants.TRANSPARENT.Equals(cssColorPropValue)) { float[] rgbaColor = CssDimensionParsingUtils.ParseRgbaColor(cssColorPropValue); Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]); float opacity = rgbaColor[3]; transparentColor = new TransparentColor(color, opacity); } else { transparentColor = new TransparentColor(ColorConstants.BLACK, 0f); } element.SetProperty(Property.FONT_COLOR, transparentColor); } // Make sure to place that before text-align applier String direction = cssProps.Get(CssConstants.DIRECTION); if (CssConstants.RTL.Equals(direction)) { element.SetProperty(Property.BASE_DIRECTION, BaseDirection.RIGHT_TO_LEFT); element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT); } else { if (CssConstants.LTR.Equals(direction)) { element.SetProperty(Property.BASE_DIRECTION, BaseDirection.LEFT_TO_RIGHT); element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT); } } if (stylesContainer is IElementNode && ((IElementNode)stylesContainer).ParentNode() is IElementNode && CssConstants .RTL.Equals(((IElementNode)((IElementNode)stylesContainer).ParentNode()).GetStyles().Get(CssConstants. DIRECTION)) && !element.HasProperty(Property.HORIZONTAL_ALIGNMENT)) { // We should only apply horizontal alignment if parent has dir attribute or direction property element.SetProperty(Property.HORIZONTAL_ALIGNMENT, HorizontalAlignment.RIGHT); } // Make sure to place that after direction applier String align = cssProps.Get(CssConstants.TEXT_ALIGN); if (CssConstants.LEFT.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.LEFT); } else { if (CssConstants.RIGHT.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.RIGHT); } else { if (CssConstants.CENTER.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.CENTER); } else { if (CssConstants.JUSTIFY.Equals(align)) { element.SetProperty(Property.TEXT_ALIGNMENT, TextAlignment.JUSTIFIED); element.SetProperty(Property.SPACING_RATIO, 1f); } } } } String whiteSpace = cssProps.Get(CssConstants.WHITE_SPACE); bool textWrappingDisabled = CssConstants.NOWRAP.Equals(whiteSpace) || CssConstants.PRE.Equals(whiteSpace); element.SetProperty(Property.NO_SOFT_WRAP_INLINE, textWrappingDisabled); if (!textWrappingDisabled) { String overflowWrap = cssProps.Get(CssConstants.OVERFLOW_WRAP); if (CssConstants.ANYWHERE.Equals(overflowWrap)) { element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.ANYWHERE); } else { if (CssConstants.BREAK_WORD.Equals(overflowWrap)) { element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD); } else { element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.NORMAL); } } String wordBreak = cssProps.Get(CssConstants.WORD_BREAK); if (CssConstants.BREAK_ALL.Equals(wordBreak)) { element.SetProperty(Property.SPLIT_CHARACTERS, new BreakAllSplitCharacters()); } else { if (CssConstants.KEEP_ALL.Equals(wordBreak)) { element.SetProperty(Property.SPLIT_CHARACTERS, new KeepAllSplitCharacters()); } else { if (CssConstants.BREAK_WORD.Equals(wordBreak)) { // CSS specification cite that describes the reason for overflow-wrap overriding: // "For compatibility with legacy content, the word-break property also supports // a deprecated break-word keyword. When specified, this has the same effect // as word-break: normal and overflow-wrap: anywhere, regardless of the actual value // of the overflow-wrap property." element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD); element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters()); } else { element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters()); } } } } float[] colors = new float[4]; Color textDecorationColor; float opacity_1 = 1f; String textDecorationColorProp = cssProps.Get(CssConstants.TEXT_DECORATION_COLOR); if (textDecorationColorProp == null || CssConstants.CURRENTCOLOR.Equals(textDecorationColorProp)) { if (element.GetProperty <TransparentColor>(Property.FONT_COLOR) != null) { TransparentColor transparentColor = element.GetProperty <TransparentColor>(Property.FONT_COLOR); textDecorationColor = transparentColor.GetColor(); opacity_1 = transparentColor.GetOpacity(); } else { textDecorationColor = ColorConstants.BLACK; } } else { if (textDecorationColorProp.StartsWith("hsl")) { logger.Error(iText.Html2pdf.LogMessageConstant.HSL_COLOR_NOT_SUPPORTED); textDecorationColor = ColorConstants.BLACK; } else { colors = CssDimensionParsingUtils.ParseRgbaColor(textDecorationColorProp); textDecorationColor = new DeviceRgb(colors[0], colors[1], colors[2]); opacity_1 = colors[3]; } } String textDecorationLineProp = cssProps.Get(CssConstants.TEXT_DECORATION_LINE); if (textDecorationLineProp != null) { String[] textDecorationLines = iText.IO.Util.StringUtil.Split(textDecorationLineProp, "\\s+"); IList <Underline> underlineList = new List <Underline>(); foreach (String textDecorationLine in textDecorationLines) { if (CssConstants.BLINK.Equals(textDecorationLine)) { logger.Error(iText.Html2pdf.LogMessageConstant.TEXT_DECORATION_BLINK_NOT_SUPPORTED); } else { if (CssConstants.LINE_THROUGH.Equals(textDecorationLine)) { underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, 1 / 4f, PdfCanvasConstants.LineCapStyle .BUTT)); } else { if (CssConstants.OVERLINE.Equals(textDecorationLine)) { underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, 9 / 10f, PdfCanvasConstants.LineCapStyle .BUTT)); } else { if (CssConstants.UNDERLINE.Equals(textDecorationLine)) { underlineList.Add(new Underline(textDecorationColor, opacity_1, .75f, 0, 0, -1 / 10f, PdfCanvasConstants.LineCapStyle .BUTT)); } else { if (CssConstants.NONE.Equals(textDecorationLine)) { underlineList = null; // if none and any other decoration are used together, none is displayed break; } } } } } } element.SetProperty(Property.UNDERLINE, underlineList); } String textIndent = cssProps.Get(CssConstants.TEXT_INDENT); if (textIndent != null) { UnitValue textIndentValue = CssDimensionParsingUtils.ParseLengthValueToPt(textIndent, em, rem); if (textIndentValue != null) { if (textIndentValue.IsPointValue()) { element.SetProperty(Property.FIRST_LINE_INDENT, textIndentValue.GetValue()); } else { logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.CSS_PROPERTY_IN_PERCENTS_NOT_SUPPORTED , CssConstants.TEXT_INDENT)); } } } String letterSpacing = cssProps.Get(CssConstants.LETTER_SPACING); if (letterSpacing != null && !CssConstants.NORMAL.Equals(letterSpacing)) { UnitValue letterSpacingValue = CssDimensionParsingUtils.ParseLengthValueToPt(letterSpacing, em, rem); if (letterSpacingValue.IsPointValue()) { element.SetProperty(Property.CHARACTER_SPACING, letterSpacingValue.GetValue()); } } // browsers ignore values in percents String wordSpacing = cssProps.Get(CssConstants.WORD_SPACING); if (wordSpacing != null) { UnitValue wordSpacingValue = CssDimensionParsingUtils.ParseLengthValueToPt(wordSpacing, em, rem); if (wordSpacingValue != null) { if (wordSpacingValue.IsPointValue()) { element.SetProperty(Property.WORD_SPACING, wordSpacingValue.GetValue()); } } } // browsers ignore values in percents String lineHeight = cssProps.Get(CssConstants.LINE_HEIGHT); SetLineHeight(element, lineHeight, em, rem); SetLineHeightByLeading(element, lineHeight, em, rem); }
/// <summary>Creates a Border3D instance with the specified width and color.</summary> /// <param name="color">color of the border</param> /// <param name="width">with of the border</param> protected internal Border3D(DeviceRgb color, float width) : base(color, width) { }
/// <summary> /// Creates a RidgeBorder instance with the specified width and the /// <see cref="iText.Kernel.Colors.DeviceRgb">rgb color</see> /// . /// </summary> /// <param name="width">width of the border</param> /// <param name="color"> /// the /// <see cref="iText.Kernel.Colors.DeviceRgb">rgb color</see> /// of the border /// </param> public RidgeBorder(DeviceRgb color, float width) : base(color, width) { }
public static byte[] CreateLabels(IEnumerable <Expansion> selectedExpansions, bool includeSpecialSetupCards) { var allHeroes = DataAccess.GetHeroCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(heroCardSet => heroCardSet.Heroes); var allMasterminds = DataAccess.GetMastermindCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(mastermindCardSet => mastermindCardSet.Masterminds); var allVillains = DataAccess.GetVillainCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(villainCardSet => villainCardSet.Villains); var allHenchmen = DataAccess.GetHenchmenCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(henchmenCardSet => henchmenCardSet.Henchmen); var allStartingCards = DataAccess.GetStartingCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(startingCardSet => startingCardSet.StartingCards); var allSetupCards = DataAccess.GetSetupCardSets() .Where(set => selectedExpansions.Contains(set.Expansion)) .SelectMany(setupCardSet => setupCardSet.SetupCards) .Where(setupCard => includeSpecialSetupCards || !setupCard.IsSpecialCard); var allVillainSetupCards = DataAccess.GetVillainSetupCardSets().Where(set => selectedExpansions.Contains(set.Expansion)).SelectMany(setupCardSet => setupCardSet.VillainSetupCards); var mastermindBaseColor = new DeviceRgb(255, 61, 83); var villainBaseColor = new DeviceRgb(255, 102, 119); var henchmenBaseColor = new DeviceRgb(255, 173, 182); var startingCardBaseColor = new DeviceRgb(200, 200, 200); var setupCardBaseColor = new DeviceRgb(35, 255, 39); var villainSetupCardBaseColor = new DeviceRgb(255, 73, 197); var fontPath = Path.Combine(CurrentPath, "Fonts", "KOMIKAX.TTF"); var font = PdfFontFactory.CreateFont(fontPath, true); var drawHeroActions = allHeroes.Select(hero => new Action <PdfCanvas, Rectangle>( (canvas, rectangle) => { var topCursor = new Cursor(); var bottomCursor = new Cursor(); const float startOfLabelOffset = 4f; topCursor.AdvanceCursor(rectangle.GetTop() - startOfLabelOffset); bottomCursor.AdvanceCursor(rectangle.GetBottom() + startOfLabelOffset); TextSharpHelpers.DrawRoundedRectangle(canvas, rectangle, new DeviceRgb(168, 255, 247)); DrawFactionsAndTypes(hero, rectangle, canvas, topCursor, bottomCursor); DrawCardText(rectangle, topCursor, bottomCursor, canvas, hero.Name, font); DrawSetText(rectangle, topCursor, bottomCursor, canvas, hero.Expansion.GetExpansionName(), font); } )).ToList(); var drawMastermindActions = allMasterminds.Select(mastermind => CreateActionToDrawNameAndSet( mastermind.Name, mastermind.Expansion.GetExpansionName(), font, mastermindBaseColor )); var drawVillainActions = allVillains.Select(villain => CreateActionToDrawNameAndSet( villain.Name, villain.Expansion.GetExpansionName(), font, villainBaseColor )); var drawHenchmenActions = allHenchmen.Select(henchmen => CreateActionToDrawNameAndSet( henchmen.Name, henchmen.Expansion.GetExpansionName(), font, henchmenBaseColor )); var drawStartingCardsActions = allStartingCards.Select(startingCard => CreateActionToDrawNameAndSet( startingCard.Name, startingCard.Expansion.GetExpansionName(), font, startingCardBaseColor )); var drawSetupCardsActions = allSetupCards.Select(setupCard => CreateActionToDrawNameAndSet( setupCard.Name, setupCard.Expansion.GetExpansionName(), font, setupCardBaseColor )); var drawVillainSetupCardsActions = allVillainSetupCards.Select(villainSetupCard => CreateActionToDrawNameAndSet( villainSetupCard.Name, villainSetupCard.Expansion.GetExpansionName(), font, villainSetupCardBaseColor )); var allActions = drawHeroActions .Concat(drawMastermindActions) .Concat(drawVillainActions) .Concat(drawHenchmenActions) .Concat(drawStartingCardsActions) .Concat(drawSetupCardsActions) .Concat(drawVillainSetupCardsActions); var drawActionRectangleQueue = new Queue <Action <PdfCanvas, Rectangle> >(allActions); return(PdfGenerator.DrawRectangles(drawActionRectangleQueue, ColorConstants.WHITE)); }
public virtual void Borders3DTest() { fileName = "borders3DTest.pdf"; Document doc = CreateDocument(); List list = new List(); ListItem grooveBorderItem = new ListItem("groove"); grooveBorderItem.SetBorder(new GrooveBorder(2)).SetMarginBottom(5).SetWidth(100); list.Add(grooveBorderItem); ListItem ridgeBorderItem = new ListItem("ridge"); ridgeBorderItem.SetBorder(new RidgeBorder(2)).SetMarginBottom(5).SetWidth(100); list.Add(ridgeBorderItem); ListItem insetBorderItem = new ListItem("inset"); insetBorderItem.SetBorder(new InsetBorder(1)).SetMarginBottom(5).SetWidth(100); list.Add(insetBorderItem); ListItem outsetBorderItem = new ListItem("outset"); outsetBorderItem.SetBorder(new OutsetBorder(1)).SetMarginBottom(5).SetWidth(100); list.Add(outsetBorderItem); doc.Add(list); Paragraph emptyParagraph = new Paragraph("\n"); doc.Add(emptyParagraph); DeviceRgb blueRgb = new DeviceRgb(0, 0, 200); DeviceRgb greenRgb = new DeviceRgb(0, 255, 0); DeviceCmyk magentaCmyk = new DeviceCmyk(0, 100, 0, 0); DeviceCmyk yellowCmyk = new DeviceCmyk(0, 0, 100, 0); list = new List(); grooveBorderItem = new ListItem("groove"); grooveBorderItem.SetBorder(new GrooveBorder(blueRgb, 2)).SetMarginBottom(5).SetWidth(100); list.Add(grooveBorderItem); ridgeBorderItem = new ListItem("ridge"); ridgeBorderItem.SetBorder(new RidgeBorder(greenRgb, 2)).SetMarginBottom(5).SetWidth(100); list.Add(ridgeBorderItem); insetBorderItem = new ListItem("inset"); insetBorderItem.SetBorder(new InsetBorder(magentaCmyk, 1)).SetMarginBottom(5).SetWidth(100); list.Add(insetBorderItem); outsetBorderItem = new ListItem("outset"); outsetBorderItem.SetBorder(new OutsetBorder(yellowCmyk, 1)).SetMarginBottom(5).SetWidth(100); list.Add(outsetBorderItem); doc.Add(list); emptyParagraph = new Paragraph("\n"); doc.Add(emptyParagraph); list = new List(); grooveBorderItem = new ListItem("groove"); grooveBorderItem.SetBorder(new GrooveBorder(yellowCmyk, 8)).SetMarginBottom(5); list.Add(grooveBorderItem); ridgeBorderItem = new ListItem("ridge"); ridgeBorderItem.SetBorder(new RidgeBorder(magentaCmyk, 8)).SetMarginBottom(5); list.Add(ridgeBorderItem); insetBorderItem = new ListItem("inset"); insetBorderItem.SetBorder(new InsetBorder(greenRgb, 8)).SetMarginBottom(5); list.Add(insetBorderItem); outsetBorderItem = new ListItem("outset"); outsetBorderItem.SetBorder(new OutsetBorder(blueRgb, 8)).SetMarginBottom(5); list.Add(outsetBorderItem); doc.Add(list); CloseDocumentAndCompareOutputs(doc); }