public static SheetPosition GetSheetPosition(string sheetPositions, int position) { SheetPosition sheetPosition = null; try { sheetPositions = sheetPositions.Substring(1, sheetPositions.Length - 2); string[] positions = sheetPositions.Split("),("); if (position < positions.Length) { sheetPosition = new SheetPosition(); string[] attributes = positions[position].Split(":")[1].Split(","); sheetPosition.Position = attributes[0]; sheetPosition.Type = attributes[1]; sheetPosition.Description = attributes[2]; } } catch { } return(sheetPosition); }
public void AddImage(string path, string number, string positions, float left, float top, float width, float height, Shape shape, Appearance appearance, string picture, string overprint, Color frameColor, ColorStyle colorStyle, FrameStyle frameStyle, bool roundedCorners) { number = !string.IsNullOrEmpty(picture) ? picture.Trim() : number.Trim(); if (number.Contains('(')) { number = number.Substring(0, number.IndexOf('(') - 1).Trim(); } string image = null; string n = number; while (image == null && n != "") { image = ImageHelper.GetDisplayImagePath(path, n, colorStyle); if (image == null) { if (!Char.IsDigit(n[0])) { n = n.Substring(1); } else if (!Char.IsDigit(n[n.Length - 1]) || n.Contains('+')) { n = n.Substring(0, n.Length - 1); } else { n = ""; } } } if (image == null) { return; // No need to stay here if the image is not found, return immediately } float x = left; float y = top; float w = width; float h = height; switch (shape) { case Shape.Triangle45: AddImage(left + 3 * 5 / (float)Math.Sqrt(2), top + 2 * 5 / (float)Math.Sqrt(2), width - 2 * 3 * 5 / (float)Math.Sqrt(2), height - 5 - 2 * 5 / (float)Math.Sqrt(2), n, image, overprint, RotateFlipType.RotateNoneFlipNone, appearance, roundedCorners); break; case Shape.Triangle60Inverted: AddImage(left + 5 + 5 / (float)Math.Sqrt(3), top + 5, width - 2 * (5 + 5 / (float)Math.Sqrt(3)), height - 2 * (5 + 5 / (float)Math.Sqrt(3)), n, image, overprint, RotateFlipType.RotateNoneFlipNone, appearance, roundedCorners); break; case Shape.Triangle60: AddImage(left + 5 + 5 / (float)Math.Sqrt(3), top + 2 * 5, width - 2 * (5 + 5 / (float)Math.Sqrt(3)), height - 2 * (5 + 5 / (float)Math.Sqrt(3)), n, image, overprint, RotateFlipType.RotateNoneFlipNone, appearance, roundedCorners); break; case Shape.RectangleRotated: AddImage(left + 5 * (float)Math.Sqrt(2), top + 5 * (float)Math.Sqrt(2), width - 2 * 5 * (float)Math.Sqrt(2), height - 2 * 5 * (float)Math.Sqrt(2), n, image, overprint, RotateFlipType.RotateNoneFlipNone, appearance, roundedCorners); break; default: int numberOfStamps = appearance.NumberOfStamps(); for (int i = 0; i < numberOfStamps; i++) { RotateFlipType?rotateFlipType = RotateFlipType.RotateNoneFlipNone; switch (appearance) { case Appearance.Singular: case Appearance.Rotated: case Appearance.WatermarkInverted: case Appearance.WatermarkReversed: case Appearance.WatermarkInvertedAndReversed: case Appearance.WatermarkSideways: case Appearance.WatermarkSidewaysInverted: if (frameColor != Color.White) { x = left + 4; y = top + 4; w = width - 8; h = height - 8; switch (appearance) { case Appearance.Rotated: case Appearance.WatermarkInverted: rotateFlipType = RotateFlipType.Rotate180FlipNone; break; case Appearance.WatermarkReversed: rotateFlipType = RotateFlipType.RotateNoneFlipX; break; case Appearance.WatermarkInvertedAndReversed: rotateFlipType = RotateFlipType.Rotate180FlipX; break; case Appearance.WatermarkSideways: rotateFlipType = RotateFlipType.Rotate270FlipNone; break; case Appearance.WatermarkSidewaysInverted: rotateFlipType = RotateFlipType.Rotate90FlipNone; break; } } break; case Appearance.Proof: if (frameStyle == FrameStyle.Thick) { AddArea(left + 4, top + 4, width - 8, height - 8, Color.Black); } x = left + 8; y = top + 8; w = width - 16; h = height - 16; break; case Appearance.BandePublicitaire: h = (height - 4) / 1.4F - 4; x = left + 4; y = top + height - 4 - h; w = width - 8; break; case Appearance.PaireCarnet: // H = 2 * {(h - 4) + 0.3 * (h - 4)} + 4 = 2 * 1.3 * (h - 4) + 4 = 2.6 * h - 10.4 + 4 = 2.6 * h - 6.4 // h = (H + 6.4) / 2.6 h = (height + 6.4F) / 2.6F - 8; x = left + 4; y = top + (i == 0 ? height / 2 - h - 2 : height / 2 + 2); w = width - 8; break; case Appearance.HorizontalInterpanneaux: w = (width - 4) / 2.5F; x = left + (i == 0 ? 4 : w * 1.5F + 4); y = top + 4; w = w - 4; h = height - 8; break; case Appearance.PairHorizontal: case Appearance.HorizontalStrip3: case Appearance.HorizontalStrip4: case Appearance.HorizontalStrip5: case Appearance.HorizontalStrip6: case Appearance.TeteBecheHorizontal: case Appearance.TeteBecheHorizontalGutter: case Appearance.HorizontalGutterPair: w = (width + (numberOfStamps - 1) * 4) / numberOfStamps; x = left + i * (w - 4) + 4; y = top + 4; w = w - 8; h = height - 8; if (appearance == Appearance.TeteBecheHorizontal) { if (w < h) { rotateFlipType = (i == 0 ? RotateFlipType.RotateNoneFlipNone : RotateFlipType.Rotate180FlipNone); } else { rotateFlipType = (i == 0 ? RotateFlipType.Rotate270FlipNone : RotateFlipType.Rotate90FlipNone); } } if (appearance == Appearance.TeteBecheHorizontalGutter) { if (w < h) { rotateFlipType = (i == 0 ? RotateFlipType.RotateNoneFlipNone : RotateFlipType.Rotate180FlipNone); } else { rotateFlipType = (i == 0 ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate270FlipNone); } } if (i == 1 && (appearance == Appearance.TeteBecheHorizontalGutter || appearance == Appearance.HorizontalGutterPair)) { rotateFlipType = null; } break; case Appearance.PairVertical: case Appearance.VerticalStrip3: case Appearance.VerticalStrip4: case Appearance.VerticalStrip5: case Appearance.VerticalStrip6: case Appearance.TeteBecheVertical: case Appearance.TeteBecheVerticalGutter: case Appearance.VerticalGutterPair: h = (height + (numberOfStamps - 1) * 4) / numberOfStamps; x = left + 4; y = top + i * (h - 4) + 4; w = width - 8; h = h - 8; if (appearance == Appearance.TeteBecheVertical || appearance == Appearance.TeteBecheVerticalGutter) { if (w < h) { rotateFlipType = (i == 0 ? RotateFlipType.RotateNoneFlipNone : RotateFlipType.Rotate180FlipNone); } else { rotateFlipType = (i == 0 ? RotateFlipType.Rotate270FlipNone : RotateFlipType.Rotate90FlipNone); } } if (i == 1 && (appearance == Appearance.TeteBecheVerticalGutter || appearance == Appearance.VerticalGutterPair)) { rotateFlipType = null; } break; case Appearance.Block5x5: w = (width - 4) / 5; h = (height - 4) / 5; x = left + 4 + (i % 5) * w; y = top + 4 + (i / 5) * h; w = w - 4; h = h - 4; break; case Appearance.Block2x5: case Appearance.Block2x5Rotated: int rows = appearance.NumberOfHorizontalAndVerticalStamps().Width; int cols = appearance.NumberOfHorizontalAndVerticalStamps().Height; w = (width - 4) / rows; h = (height - 4) / cols; x = left + 4 + (i % rows) * w; y = top + 4 + ((i / rows) % cols) * h; w = w - 4; h = h - 4; if (appearance == Appearance.Block2x5Rotated) { rotateFlipType = RotateFlipType.Rotate270FlipNone; } break; case Appearance.Block: w = (width + 4) / 2; h = (height + 4) / 2; x = left + (i == 1 || i == 3 ? w : 4); y = top + (i == 2 || i == 3 ? h : 4); w = w - 8; h = h - 8; break; case Appearance.Sheet2x3: w = (width + 8) / 3; h = (height + 4) / 2; x = left + (i % 3) * (w - 4) + 4; y = top + (i / 3) * (h - 4) + 4; w = w - 8; h = h - 8; break; case Appearance.ImperfTop: h = (height + 4) / 2; x = left + 4; y = top + h; w = width - 8; h = h - 8; break; case Appearance.ImperfBottom: h = (height + 4) / 2; x = left + 4; y = top + 4; w = width - 8; h = h - 8; break; case Appearance.ImperfLeft: w = (width + 4) / 2; x = left + w; y = top + 4; w = w - 8; h = height - 8; break; case Appearance.ImperfRight: w = (width + 4) / 2; x = left + 4; y = top + 4; w = w - 8; h = height - 8; break; default: throw new Exception("todo"); } if (rotateFlipType != null) { switch (appearance) { case Appearance.ImperfTop: case Appearance.ImperfBottom: case Appearance.ImperfLeft: case Appearance.ImperfRight: case Appearance.Proof: case Appearance.BandePublicitaire: case Appearance.PaireCarnet: if (frameStyle == FrameStyle.Thick && i == 0) { AddArea(left + 4, top + 4, width - 8F + 0.25F, height - 8F + 0.25F, Color.Black); } break; } if (positions == "") { AddImage(x, y, w, h, n, image, overprint, rotateFlipType, appearance, roundedCorners); } else { SheetPosition sheetPosition = SheetHelper.GetSheetPosition(positions, i); if (sheetPosition != null) { if (sheetPosition.Type == "") { AddImage(x, y, w, h, n, image, overprint, rotateFlipType, appearance, roundedCorners: false); } else { AddImage(x, y, w, h, n, ImageHelper.GetDisplayImagePath(path, n + sheetPosition.Type, colorStyle), overprint, rotateFlipType, appearance, roundedCorners); } AddText(x + 0.5F, y + 0.5F, w - 1, sheetPosition.Position, "Times New Roman", 7, fontBold: true, alignment: Alignment.Left); AddText(x + 0.5F, y + 0.5F, w - 1, sheetPosition.Type, "Times New Roman", 7, fontBold: true, alignment: Alignment.Right); AddText(x + 0.5F, y + h - 2.5F, w - 1, sheetPosition.Description, "Times New Roman", 7, fontBold: true, alignment: Alignment.Centered); } else { AddImage(x, y, w, h, n, image, overprint, rotateFlipType, appearance, roundedCorners); } } } } break; } }