public static void Test() { bool success; StringBuilder profileName = new StringBuilder(256); uint size = (uint)profileName.Capacity * 2; success = GetStandardColorSpaceProfile(0, LogicalColorSpace.sRGB, profileName, ref size); ProfileFilename sRGBFilename = new ProfileFilename(profileName.ToString()); IntPtr hSRGBProfile = OpenColorProfile(sRGBFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); ProfileFilename isoCoatedFilename = new ProfileFilename(@"C:\Users\me\Documents\ISOcoated_v2_300_eci.icc"); IntPtr hIsoCoatedProfile = OpenColorProfile(isoCoatedFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); IntPtr[] profiles = new IntPtr[] { hSRGBProfile, hIsoCoatedProfile }; uint[] intents = new uint[] { IntentPerceptual }; IntPtr transform = CreateMultiProfileTransform(profiles, 2, intents, 1, ColorTransformMode.BestMode, IndexDontCare); RGBColor[] rgbColors = new RGBColor[1]; rgbColors[0] = new RGBColor(); CMYKColor[] cmykColors = new CMYKColor[1]; cmykColors[0] = new CMYKColor(); rgbColors[0].red = 30204; rgbColors[0].green = 4420; rgbColors[0].blue = 60300; success = TranslateColors(transform, rgbColors, 1, ColorType.RGB, cmykColors, ColorType.CMYK); success = DeleteColorTransform(transform); success = CloseColorProfile(hSRGBProfile); success = CloseColorProfile(hIsoCoatedProfile); }
public void _TEST_TO_UNITY_COLORS() { CMYKColor cc = new CMYKColor(1, 0, 0, 0); Assert.AreEqual(Color.cyan, cc.ToUnityColor()); cc = new CMYKColor(Color.red); Assert.AreEqual(Color.red, cc.ToUnityColor()); }
public void _TEST_SIMPLE_COLORS() { CMYKColor cc = new CMYKColor(Color.red); Assert.AreEqual(new CMYKColor(0, 1, 1, 0), cc); cc = new CMYKColor(Color.cyan); Assert.AreEqual(new CMYKColor(1, 0, 0, 0), cc); }
public void _TEST_EQUAL() { CMYKColor cc1 = null; CMYKColor cc2 = null; Assert.IsTrue(cc1 == cc2); cc1 = new CMYKColor(1, 1, 1, 1); Assert.IsFalse(cc1 == cc2); }
public bool IsDestroyedByColor(Color color) { Color remainder = this.wallColor - color; bool isWithinTolerance = CMYKColor.IsWithinTolerance(remainder, this.wallTolerance); LogHelper.Log(typeof(Wall), String.Format("Destroy={0}/Dif{1} - This({2}) - Ball({3})", isWithinTolerance, remainder, this.wallColor, color)); return(isWithinTolerance); }
public Color(System.Xml.XmlNode colorNode) { Key = colorNode.Attributes["key"].Value; CMYKColor = new CMYKColor(colorNode.SelectSingleNode("cmyk")); RGBColor = new RGBColor(colorNode.SelectSingleNode("rgb")); if (colorNode.SelectSingleNode("pms") != null) { PMSColor = new PMSColor(colorNode.SelectSingleNode("pms")); } }
public void _TEST_MIX_COLORS() { Assert.AreEqual(Color.magenta, CMYKColor.CombineColors(new[] { new KeyValuePair <Color, float>(Color.red, 1f), new KeyValuePair <Color, float>(Color.blue, 1f) })); Assert.AreEqual(1, CMYKColor.CombineColors(new[] { new KeyValuePair <Color, float>(Color.red, 1f), new KeyValuePair <Color, float>(Color.blue, 1f) }).a); Assert.AreEqual(Color.cyan, CMYKColor.CombineColors(new[] { new KeyValuePair <Color, float>(Color.green, 1f), new KeyValuePair <Color, float>(Color.blue, 1f) })); Assert.AreEqual(Color.black, CMYKColor.CombineColors(new[] { new KeyValuePair <Color, float>(Color.green, 0f), new KeyValuePair <Color, float>(Color.blue, 0f) })); }
private List <PdfObject> SetNonStrokingCMYK(PdfLiteral oper, List <PdfObject> operands) { PdfNumber c = (PdfNumber)operands[0]; PdfNumber m = (PdfNumber)operands[1]; PdfNumber y = (PdfNumber)operands[2]; PdfNumber k = (PdfNumber)operands[3]; CMYKColor color = new CMYKColor(c.FloatValue, m.FloatValue, y.FloatValue, k.FloatValue); return(new List <PdfObject>() { new PdfNumber(0), new PdfNumber(0), new PdfNumber(0), new PdfLiteral("rg") }); }
public static byte[] CreateLabels() { var garamond = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "GARA.TTF"); var garamondBold = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "GARABD.TTF"); var baseFont = BaseFont.CreateFont(garamond, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); var boldBaseFont = BaseFont.CreateFont(garamondBold, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); var beers = GetBeers(); var labelBackground = new CMYKColor(0, 8, 26, 0); var drawActionRectangles = beers.SelectMany(beer => new List <Action <PdfContentByte, Rectangle> > { (canvas, rectangle) => { TextSharpHelpers.DrawRectangle(canvas, rectangle, labelBackground); //name //gold label const float startOfLabelOffset = 4f; var topCursor = new Cursor(); topCursor.AdvanceCursor(rectangle.Top - startOfLabelOffset); if (beer.Points > 0) { DrawPoints(rectangle, topCursor, canvas, beer, boldBaseFont); } 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, baseFont); } }).ToList(); var drawActionRectangleQueue = new Queue <Action <PdfContentByte, Rectangle> >(drawActionRectangles); return(PdfGenerator.DrawRectangles( drawActionRectangleQueue, BaseColor.WHITE)); }
/* a method that save the packing slip pdf */ public static void CreatePackingSlip(GiantTigerValues value, int[] cancelIndex, bool preview) { // the case if all of the items in the order are cancelled -> don't need to print the packing slip if (cancelIndex.Length >= value.VendorSku.Count) { return; } // first check if the save directory exist -> if not create it if (!File.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } // initialize fields Document doc = new Document(PageSize.LETTER, 0, 0, 0, 0); string file = SavePath + "\\" + value.PoNumber + ".pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)); // open the documents doc.Open(); PdfContentByte contentByte = writer.DirectContent; PdfContentByte draw = writer.DirectContent; #region Logo and Barcode Set Up // add giant tiger logo Image logo = Image.GetInstance(Properties.Resources.giantTigerPackSlip, System.Drawing.Imaging.ImageFormat.Png); logo.ScalePercent(20f); logo.SetAbsolutePosition(40f, doc.PageSize.Height - 100f); doc.Add(logo); // add barcode Barcode39 barcode39 = new Barcode39 { Code = value.OmsOrderNumber, StartStopText = false, Font = null, Extended = true }; Image image = barcode39.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(40f); image.SetAbsolutePosition(340f, doc.PageSize.Height - 80f); contentByte.AddImage(image); #endregion // initialize local fields for text BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); BaseFont boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); CMYKColor white = new CMYKColor(0f, 0f, 0f, 0f); CMYKColor black = new CMYKColor(0f, 0f, 0f, 1f); ColumnText ct = new ColumnText(draw); #region Sold To // sold to Phrase text = new Phrase("SOLD TO / VENDU A", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 40f, 655f, 200f, 670f, 0f, Element.ALIGN_LEFT); ct.Go(); // sold to address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 42f, 568f, 177f, 668f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Ship To // ship to text = new Phrase("SHIP TO / EXPEDIE A", new Font(boldFont, 10f)); ct.SetSimpleColumn(text, 300f, 655f, 450f, 670f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship to address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada\n" + value.ShipTo.DayPhone, new Font(baseFont, 9f)); ct.SetSimpleColumn(text, 302f, 568f, 447f, 668f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Draw First Box draw.SetColorFill(black); draw.MoveTo(40f, 580f); draw.LineTo(doc.PageSize.Width - 40f, 580f); draw.LineTo(doc.PageSize.Width - 40f, 543f); draw.LineTo(40f, 543f); draw.LineTo(40f, 580f); draw.ClosePathFillStroke(); draw.SetColorStroke(white); draw.MoveTo(160f, 580f); draw.LineTo(160f, 543f); draw.Stroke(); draw.MoveTo(280f, 580f); draw.LineTo(280f, 543f); draw.Stroke(); draw.MoveTo(320f, 580f); draw.LineTo(320f, 543f); draw.Stroke(); draw.MoveTo(500f, 580f); draw.LineTo(500f, 543f); draw.Stroke(); draw.SetColorStroke(black); draw.MoveTo(40f, 543f); draw.LineTo(40f, 530f); draw.Stroke(); draw.MoveTo(40f, 530f); draw.LineTo(doc.PageSize.Width - 40f, 530f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 530f); draw.LineTo(doc.PageSize.Width - 40f, 543f); draw.Stroke(); draw.MoveTo(160f, 543f); draw.LineTo(160f, 530f); draw.Stroke(); draw.MoveTo(280f, 543f); draw.LineTo(280f, 530f); draw.Stroke(); draw.MoveTo(320f, 543f); draw.LineTo(320f, 530f); draw.Stroke(); draw.MoveTo(500f, 543f); draw.LineTo(500f, 530f); draw.Stroke(); #endregion #region Messgae in First Box text = new Phrase("SHIPPING METHOD \\\nMODE D'EXPEDITION", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 550f, 160f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ORDER DATE \\\nDATE DE LA\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 160f, 540f, 280f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("PAGE", new Font(boldFont, 10, Font.NORMAL, new CMYKColor(0f, 0f, 0f, 0f))); ct.SetSimpleColumn(text, 280f, 550f, 320f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ORDER NUMBER \\\nNUMERO DE COMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 320f, 550f, 500f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("PO NUMBER \\\nBON DE\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 500f, 540f, doc.PageSize.Width - 40f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("Canada Post Ground", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, 523f, 160f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.OrderDate.ToString("MM/dd/yyyy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 160f, 523f, 280f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("1 of 1", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 280f, 523f, 320f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.WebOrderNo, new Font(baseFont, 10)); ct.SetSimpleColumn(text, 320f, 523f, 500f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.PoNumber, new Font(baseFont, 10)); ct.SetSimpleColumn(text, 500f, 523f, doc.PageSize.Width - 40f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); #endregion #region Draw Second Box draw.MoveTo(40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 483f); draw.LineTo(40f, 483f); draw.LineTo(40f, 520f); draw.ClosePathFillStroke(); draw.SetColorStroke(white); draw.MoveTo(130f, 520f); draw.LineTo(130f, 483f); draw.Stroke(); draw.MoveTo(220f, 520f); draw.LineTo(220f, 483f); draw.Stroke(); draw.MoveTo(400f, 520f); draw.LineTo(400f, 483f); draw.Stroke(); draw.MoveTo(480f, 520f); draw.LineTo(480f, 483f); draw.Stroke(); #endregion #region Message in Second Box text = new Phrase("QTY ORDERED \\\nQTE\nCOMMANDEE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 480f, 130f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ITEM \\\nARTICLE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 130f, 480f, 220f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("DESCRIPTION", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 220f, 480f, 400f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("QTY SHIPPED \\\nQTE EXPEDIEE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 400f, 480f, 480f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("VENDOR SKU \\\nNO D'ARTICLE DU\nFOURNISSEUR", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 480f, 480f, doc.PageSize.Width - 40f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); // item addition draw.SetColorStroke(black); draw.SetLineWidth(0.25f); float height = 480f; // adding items for (int i = 0; i < value.VendorSku.Count; i++) { // if the item is cancelled, skip this item if (cancelIndex.Any(j => i == j)) { continue; } // draw box draw.MoveTo(40f, height); draw.LineTo(40f, height - 10f); draw.Stroke(); draw.MoveTo(40f, height - 10f); draw.LineTo(doc.PageSize.Width - 40f, height - 10f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, height - 10f); draw.LineTo(doc.PageSize.Width - 40f, height); draw.Stroke(); draw.MoveTo(130f, height); draw.LineTo(130f, height - 10f); draw.Stroke(); draw.MoveTo(220f, height); draw.LineTo(220f, height - 10f); draw.Stroke(); draw.MoveTo(400f, height); draw.LineTo(400f, height - 10f); draw.Stroke(); draw.MoveTo(480f, height); draw.LineTo(480f, height - 10f); draw.Stroke(); // qty text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, height - 19f, 130, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // item text = new Phrase(value.ClientItemId[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 130f, height - 19f, 220f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // description text = new Phrase("", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 220f, height - 19f, 400f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // qty shipped text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 400f, height - 19f, 480f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // vendor sku text = new Phrase(value.VendorSku[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 480f, height - 19f, doc.PageSize.Width - 40f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // decrease height for next item height -= 10f; } #endregion #region Ending Boxes #region Top Box // restore width draw.SetLineWidth(1f); // draw box draw.MoveTo(40f, 250f); draw.LineTo(doc.PageSize.Width - 40f, 250f); draw.LineTo(doc.PageSize.Width - 40f, 235f); draw.LineTo(40f, 235f); draw.LineTo(40f, 250f); draw.ClosePathFillStroke(); // message in the box text = new Phrase("Thank you for ordering from Giant Tiger! Merci d’avoir placé une commande chez Tigre Géant!", new Font(boldFont, 10f, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 224f, doc.PageSize.Width - 40f, 239f, 0f, Element.ALIGN_CENTER); ct.Go(); #endregion #region Bottom Box // draw box draw.MoveTo(40f, 225f); draw.LineTo(doc.PageSize.Width - 40f, 225f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 225f); draw.LineTo(doc.PageSize.Width - 40f, 50f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 50f); draw.LineTo(40f, 50f); draw.Stroke(); draw.MoveTo(40f, 50f); draw.LineTo(40f, 225f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width / 2, 225f); draw.LineTo(doc.PageSize.Width / 2, 50f); draw.Stroke(); // message in the left box text = new Phrase("Didn't receive your entire order or questions about your order?\n" + "You may receive your order in separate shipments. To track your order status. Please log into My Account at gianttiger.com.\n\r" + "Want to Return or Exchange an Item?\n" + "If you are not satisfied with your order for any reason please contact our Customer Service Team at 1-844-99-GIANT (44268) or email [email protected]. " + "For in-store returns or exchanges, your shipment confirmation email is required. To review our return policy, please visit gianttiger.com/ReturnPolicy.", new Font(baseFont, 9f)); ct.SetSimpleColumn(text, 50f, 55f, doc.PageSize.Width / 2 - 10, 225f, 10f, Element.ALIGN_LEFT); ct.Go(); // message in the right box text = new Phrase("Votre commande est incomplète ou vous avez des questions à son sujet?\n" + "Il se peut que vous receviez votre commande dans des envois distincts. Pour suivre l'état de votre commande, s’il vous plaît vous connecter à Mon Compte au tigregeant.com.\n\r" + "Vous voulez retourner ou échanger un article?\nSi vous n'êtes pas satisfait avec votre achat, veuillez communiquer avec notre service à la clientèle au 1-844-99-GIANT (44268) " + "ou envoyer un courriel à [email protected]. Les échanges et les remboursements peuvent être effectués à n’importe quel de nos magasins avec la présentation du courriel confirmant " + "l'expédition de votre commande. Pour consulter notre politique de retour, s'il vous plaît visitez tigregeant.com/PolitiqueRetour.", new Font(baseFont, 9f)); ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 10f, 55f, doc.PageSize.Width - 50f, 225f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion doc.Close(); if (!preview) { return; } // start the pdf for previewing if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1) { System.Diagnostics.Process.Start(file); } }