private void SaveXpsPage(string filename) { var clone = VisualClone(); if (!XpsDocs.ContainsKey(filename)) { var d = new FixedDocument(); d.DocumentPaginator.PageSize = GetSize(clone); XpsDocs.Add(filename, d); } var doc = XpsDocs[filename]; XpsSnapshots[filename] = this; var size = doc.DocumentPaginator.PageSize; var cont = new PageContent(); var pg = new FixedPage(); var canvas = new Canvas(); canvas.Children.Add(clone); canvas.Width = size.Width; canvas.Height = size.Height; pg.Width = size.Width; pg.Height = size.Height; pg.Background = Brushes.White; pg.Children.Add(canvas); FixedPage.SetLeft(canvas, 0); FixedPage.SetRight(canvas, 0); ((IAddChild)cont).AddChild(pg); //clone.MeasureAndArrange(new Size(clone.Width, clone.Height)); var width = clone.Width; var height = clone.Height; double zoom = 1; if (FitToPage) { zoom = Math.Min(size.Width / width, size.Height / height); } if (zoom != 1) { clone.LayoutTransform = new MatrixTransform(zoom, 0, 0, zoom, 0, 0); width *= zoom; height *= zoom; clone.MeasureAndArrange(new Size(width, height)); } Canvas.SetLeft(clone, (size.Width - width) / 2); Canvas.SetTop(clone, (size.Height - height) / 2); cont.Measure(size); cont.Arrange(new Rect(new Point(), size)); cont.UpdateLayout(); doc.Pages.Add(cont); }
private static void eventualiStampigli(FixedPage page1, LavoroDiStampaFoto lavoroDiStampa) { SolidColorBrush coloreFg = new SolidColorBrush(Colors.Black); SolidColorBrush coloreBg = new SolidColorBrush(Colors.White); int stampigliMarginBotton = Configurazione.UserConfigLumen.stampigliMarginBottom; int stampigliMarginTop = Configurazione.UserConfigLumen.stampigliMarginBottom; int stampigliMarginRight = Configurazione.UserConfigLumen.stampigliMarginRight; int stampigliMarginLeft = Configurazione.UserConfigLumen.stampigliMarginRight; // Prima era 30 poi 16 poi l'ho reso esterno int fontSize = Configurazione.UserConfigLumen.fontSizeStampaFoto; if (fontSize <= 0) { fontSize = 14; // Default } // Numero della foto if (lavoroDiStampa.param.stampigli.numFoto) { TextBlock textNumero = new TextBlock(); textNumero.Text = lavoroDiStampa.fotografia.etichetta; textNumero.FontSize = fontSize; // 30pt text textNumero.Foreground = coloreFg; textNumero.Background = coloreBg; FixedPage.SetBottom(textNumero, stampigliMarginBotton); FixedPage.SetRight(textNumero, stampigliMarginRight); page1.Children.Add(textNumero); } // Giornata if (lavoroDiStampa.param.stampigli.giornata) { TextBlock textGiorno = new TextBlock(); textGiorno.Text = lavoroDiStampa.fotografia.giornata.ToString("d"); textGiorno.FontSize = fontSize; // 30pt text textGiorno.Foreground = coloreFg; textGiorno.Background = coloreBg; FixedPage.SetBottom(textGiorno, stampigliMarginBotton); FixedPage.SetLeft(textGiorno, stampigliMarginLeft); page1.Children.Add(textGiorno); } // Operatore if (lavoroDiStampa.param.stampigli.operatore) { TextBlock textOperatore = new TextBlock(); textOperatore.Text = lavoroDiStampa.fotografia.fotografo.iniziali; textOperatore.FontSize = fontSize; // 30pt text textOperatore.Foreground = coloreFg; textOperatore.Background = coloreBg; FixedPage.SetTop(textOperatore, stampigliMarginTop); FixedPage.SetRight(textOperatore, stampigliMarginRight); page1.Children.Add(textOperatore); } }
private static Rectangle CreateContentRectangle(Brush vb, Rect rect) { var rc = new Rectangle { Width = rect.Width, Height = rect.Height, Fill = vb }; FixedPage.SetLeft(rc, rect.X); FixedPage.SetTop(rc, rect.Y); FixedPage.SetRight(rc, rect.Width); FixedPage.SetBottom(rc, rect.Height); return(rc); }
/// <summary>method write control to page in absolute position /// </summary> /// <param name="item">adding control</param> /// <param name="left">control left displacement, default is not set</param> /// <param name="top">control top displacement, default is not set</param> /// <param name="right">control right displacement, default is not set</param> /// <param name="bottom">control bottom displacement, default is not set</param> private void WriteItemToPage(UIElement item, double left = double.MinValue, double top = double.MinValue, double right = double.MinValue, double bottom = double.MinValue) { if (left > double.MinValue) { FixedPage.SetLeft(item, m_DisplayResolution * left); } if (top > double.MinValue) { FixedPage.SetTop(item, m_DisplayResolution * top); } if (right > double.MinValue) { FixedPage.SetRight(item, m_DisplayResolution * right); } if (bottom > double.MinValue) { FixedPage.SetBottom(item, m_DisplayResolution * bottom); } FixedPage.Children.Add(item); UpdatePageLayout(); }
private static FixedPage CreateFixedPageForStep(Step st, PrintStuff ps) { FixedPage page = new FixedPage(); page.Background = Brushes.White; page.Width = ps.dpi * ps.page_width; page.Height = ps.dpi * ps.page_height; double picWidth = 4; double picHeight = 4; ViewMaker vo = new ViewMaker(); vo.bAnimate = false; vo.bShowAnnotations = true; vo.bShowAxes = false; vo.bShowEndGrain = true; vo.bShowFaceLabels = true; vo.bShowHighlights = true; vo.bShowLines = true; vo.bStaticLines = true; vo.height = (int)(ps.dpi * picHeight); vo.width = (int)(ps.dpi * picWidth); vo.bCloneTran = true; vo.bAutoZoom = true; vo.transparencies = null; vo.MakeView(st); // Move the picture to the center of the area Rect r = wpfmisc.Get2DBoundingBox(vo.vp); vo.vp.RenderTransform = new TranslateTransform((vo.vp.Width - r.Width) / 2 - r.Left, (vo.vp.Height - r.Height) / 2 - r.Top); Border b = new Border(); //b.Background = Brushes.Yellow; b.BorderThickness = new Thickness(1); b.BorderBrush = Brushes.Black; b.Child = vo.vp; FixedPage.SetLeft(b, ps.dpi * ps.margin_left); FixedPage.SetTop(b, ps.dpi * (ps.margin_left * 2)); page.Children.Add((UIElement)b); TextBlock tbTitle = new TextBlock(); tbTitle.Text = st.Description; tbTitle.FontSize = 24; tbTitle.FontFamily = new FontFamily("Arial"); FixedPage.SetLeft(tbTitle, ps.dpi * ps.margin_left); FixedPage.SetTop(tbTitle, ps.dpi * ps.margin_top); page.Children.Add((UIElement)tbTitle); TextBlock tbProse = new TextBlock(); tbProse.TextWrapping = TextWrapping.Wrap; tbProse.MaxWidth = vo.width; tbProse.Text = st.prose; tbProse.FontSize = 12; tbProse.FontFamily = new FontFamily("serif"); FixedPage.SetLeft(tbProse, ps.dpi * ps.margin_left); FixedPage.SetTop(tbProse, ps.dpi * (ps.margin_top + 1)); page.Children.Add((UIElement)tbProse); FlowDocumentScrollViewer fdsv_notes = new FlowDocumentScrollViewer(); fdsv_notes.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; fdsv_notes.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; fdsv_notes.Width = ps.dpi * 3; fdsv_notes.Height = ps.dpi * 3; if (st.Notes != null) { // TODO fdsv_notes.Document = XamlReader.Load(new XmlTextReader(new StringReader(st.Notes))) as FlowDocument; } FixedPage.SetLeft(fdsv_notes, ps.dpi * ps.margin_left); FixedPage.SetTop(fdsv_notes, ps.dpi * 6); page.Children.Add((UIElement)fdsv_notes); TextBlock tbCredit = new TextBlock(new Run("www.sawdust.com")); tbCredit.FontSize = 10; tbCredit.FontFamily = new FontFamily("Arial"); FixedPage.SetRight(tbCredit, ps.dpi * ps.margin_right); FixedPage.SetBottom(tbCredit, ps.dpi * ps.margin_bottom); page.Children.Add(tbCredit); Size sz = new Size(ps.dpi * ps.page_width, ps.dpi * ps.page_height); page.Measure(sz); page.Arrange(new Rect(new Point(), sz)); page.UpdateLayout(); return(page); }