private void DrawBleedMarks( Demon.PDF.Rectangle mediaBox, Demon.PDF.Rectangle bodyBox, Demon.PDF.Rectangle headerBox, Demon.PDF.Rectangle footerBox, Page page) { Demon.PDF.Color color = new Demon.PDF.Color { Red = 0.75f, Green = 0.75f, Blue = 0.75f }; List <Position> path = new List <Position>(); Position p1 = new Position(bodyBox.Left - 20, bodyBox.Top + 1); Position p2 = new Position(bodyBox.Left - 1, bodyBox.Top + 1); Position p3 = new Position(bodyBox.Left - 1, bodyBox.Top + 20); path.Add(p1); path.Add(p2); path.Add(p3); page.AddPath(path, 1, color, null); path.Clear(); p1 = new Position(bodyBox.Right + 20, bodyBox.Top + 1); p2 = new Position(bodyBox.Right + 1, bodyBox.Top + 1); p3 = new Position(bodyBox.Right + 1, bodyBox.Top + 20); path.Add(p1); path.Add(p2); path.Add(p3); page.AddPath(path, 1, color, null); path.Clear(); p1 = new Position(bodyBox.Left - 20, bodyBox.Bottom - 1); p2 = new Position(bodyBox.Left - 1, bodyBox.Bottom - 1); p3 = new Position(bodyBox.Left - 1, bodyBox.Bottom - 20); path.Add(p1); path.Add(p2); path.Add(p3); page.AddPath(path, 1, color, null); path.Clear(); p1 = new Position(bodyBox.Right + 20, bodyBox.Bottom - 1); p2 = new Position(bodyBox.Right + 1, bodyBox.Bottom - 1); p3 = new Position(bodyBox.Right + 1, bodyBox.Bottom - 20); path.Add(p1); path.Add(p2); path.Add(p3); page.AddPath(path, 1, color, null); }
private void RenderPageLayout(PageLayout pageLayout, Document document, bool drawRules) { Demon.PDF.Rectangle mediaBox = Convert.Rectangle(pageLayout.MediaBox); Demon.PDF.Rectangle bodyBox = Convert.Rectangle(pageLayout.BodyBox); Demon.PDF.Rectangle headerBox = Convert.Rectangle(pageLayout.HeaderBox); Demon.PDF.Rectangle footerBox = Convert.Rectangle(pageLayout.FooterBox); Page page = new Page(pageLayout.PageNumber, mediaBox, bodyBox, headerBox, footerBox, document); if (drawRules || pageLayout.DrawRules) { DrawBleedMarks(mediaBox, bodyBox, headerBox, footerBox, page); DrawRules(mediaBox, bodyBox, headerBox, footerBox, page); } // Background before content foreach (FixedPicture picture in pageLayout.Background) { RenderFixedPicture(picture, page); } // Content foreach (Layout sublayout in pageLayout.SubLayouts) { Render(sublayout, page); } if (pageLayout.Header != null) { Render(pageLayout.Header, page); } if (pageLayout.Footer != null) { Render(pageLayout.Footer, page); } // Overlay after content foreach (FixedPicture picture in pageLayout.Overlays) { RenderFixedPicture(picture, page); } }
private void DrawRules( Demon.PDF.Rectangle mediaBox, Demon.PDF.Rectangle bodyBox, Demon.PDF.Rectangle headerBox, Demon.PDF.Rectangle footerBox, Page page) { int fontSize = 8; int fontHeight = _rulesFont.GetCapHeight(fontSize); Demon.PDF.Color color = new Demon.PDF.Color { Red = 0.75f, Green = 0.75f, Blue = 0.75f }; List <Position> path = new List <Position>(); Position p1; Position p2; // Side media box rule (left) for (int x = 0; x < mediaBox.Height; x += 10) { path.Clear(); if (x % 100 == 0) { p1 = new Position(mediaBox.Left, mediaBox.Bottom + x); p2 = new Position(mediaBox.Left + 12, mediaBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); string text = x.ToString(); int tx = p2.X + 2; int ty = p2.Y - (fontHeight / 2); page.AddText(text, tx, ty, _rulesFont.FamilyName, false, false, fontSize, color); } else if (x % 50 == 0) { p1 = new Position(mediaBox.Left, mediaBox.Bottom + x); p2 = new Position(mediaBox.Left + 12, mediaBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } else if (x % 10 == 0) { p1 = new Position(mediaBox.Left, mediaBox.Bottom + x); p2 = new Position(mediaBox.Left + 5, mediaBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } } // Bottom media box rule (bottom) for (int x = 0; x < mediaBox.Width; x += 10) { path.Clear(); if (x % 100 == 0) { p1 = new Position(mediaBox.Left + x, mediaBox.Bottom); p2 = new Position(mediaBox.Left + x, mediaBox.Bottom + 12); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); string text = x.ToString(); int textLen = _rulesFont.GetTextLength(text, 0, text.Length, fontSize) / _rulesFont.UnitsPerEm; int tx = p2.X - (textLen / 2); int ty = p2.Y + 2; page.AddText(text, tx, ty, _rulesFont.FamilyName, false, false, fontSize, color); } else if (x % 50 == 0) { p1 = new Position(mediaBox.Left + x, mediaBox.Bottom); p2 = new Position(mediaBox.Left + x, mediaBox.Bottom + 12); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } else if (x % 10 == 0) { p1 = new Position(mediaBox.Left + x, mediaBox.Bottom); p2 = new Position(mediaBox.Left + x, mediaBox.Bottom + 5); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } } // Side body box rule (right) int start = mediaBox.Bottom - bodyBox.Bottom; // negative start to put zero at the body box bottom start = (start / 10) * 10; for (int x = start; x < mediaBox.Height; x += 10) { path.Clear(); if (x % 100 == 0) { p1 = new Position(mediaBox.Right, bodyBox.Bottom + x); p2 = new Position(mediaBox.Right - 12, bodyBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); string text = x.ToString(); int textLen = _rulesFont.GetTextLength(text, 0, text.Length, fontSize) / _rulesFont.UnitsPerEm; int tx = p2.X - 2 - textLen; int ty = p2.Y - (fontHeight / 2); page.AddText(text, tx, ty, _rulesFont.FamilyName, false, false, fontSize, color); } else if (x % 50 == 0) { p1 = new Position(mediaBox.Right, bodyBox.Bottom + x); p2 = new Position(mediaBox.Right - 12, bodyBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } else if (x % 10 == 0) { p1 = new Position(mediaBox.Right, bodyBox.Bottom + x); p2 = new Position(mediaBox.Right - 5, bodyBox.Bottom + x); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } } // Bottom body box rule (top) start = mediaBox.Left - bodyBox.Left; // negative start to put zero at the body box left start = (start / 10) * 10; for (int x = start; x < mediaBox.Width; x += 10) { path.Clear(); if (x % 100 == 0) { p1 = new Position(bodyBox.Left + x, mediaBox.Top); p2 = new Position(bodyBox.Left + x, mediaBox.Top - 12); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); string text = x.ToString(); int textLen = _rulesFont.GetTextLength(text, 0, text.Length, fontSize) / _rulesFont.UnitsPerEm; int tx = p2.X - (textLen / 2); int ty = p2.Y - 2 - fontHeight; page.AddText(text, tx, ty, _rulesFont.FamilyName, false, false, fontSize, color); } else if (x % 50 == 0) { p1 = new Position(bodyBox.Left + x, mediaBox.Top); p2 = new Position(bodyBox.Left + x, mediaBox.Top - 12); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } else if (x % 10 == 0) { p1 = new Position(bodyBox.Left + x, mediaBox.Top); p2 = new Position(bodyBox.Left + x, mediaBox.Top - 5); path.Add(p1); path.Add(p2); page.AddPath(path, 1, color, null); } } }
private void RenderFixedPicture(FixedPicture picture, Page page) { Demon.PDF.Rectangle bounds = Convert.Rectangle(picture.Bounds); page.AddImage(picture.Image.Size, picture.Image.RawData, 8, bounds); }
private void RenderPictureLayout(PictureLayout layout, Page page) { Demon.PDF.Rectangle bounds = Convert.Rectangle(layout.ImageBounds); // bounds of the image within the layout page.AddImage(layout.Image.Size, layout.Image.RawData, 8, bounds); }
private void RenderPhotoLayout(PhotoLayout layout, Page page) { Demon.PDF.Rectangle bounds = Convert.Rectangle(layout.PhotoBounds); // bounds of the photo within the layout page.AddImage(layout.PhotoData.Size, layout.PhotoData.RawData, 8, bounds); }