void RenderPreview(int i) { SPanel.Children.Clear(); Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i); CanvasSaveLoad.ToPresentationMode(can); CanvasSaveLoad.SimulateCanvas(can); can.UpdateLayout(); Size size = new Size(); can.Measure(size); can.Arrange(new Rect(size)); ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can)); Border pageP = new Border(); pageP.Background = new ImageBrush(bs); pageP.BorderBrush = new SolidColorBrush(Color.FromRgb(44, 62, 80)); pageP.BorderThickness = new Thickness(3); pageP.Width = data.CanvasW; pageP.Height = data.CanvasH; pageP.Margin = new Thickness(10, 10, 10, 15); SPanel.Children.Add(pageP); L_Page.Content = (i + 1) + "/" + data.pages.Count; }
private void PrintAddPage(int i, FixedDocument document, Size sizeContent, Size margins) { Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i); CanvasSaveLoad.ToPresentationMode(can); CanvasSaveLoad.SimulateCanvas(can); can.UpdateLayout(); Size size = new Size(); can.Measure(size); can.Arrange(new Rect(size)); ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can)); Image image = new Image(); if (SB_Fit.IsChecked()) { image.Width = sizeContent.Width; image.Height = sizeContent.Height; } else { image.Width = data.CanvasW; image.Height = data.CanvasH; } image.Stretch = Stretch.Uniform; image.Source = bs; FixedPage page = new FixedPage(); page.Width = document.DocumentPaginator.PageSize.Width; page.Height = document.DocumentPaginator.PageSize.Width; if (SB_Fit.IsChecked()) { page.Margin = new Thickness(margins.Width, margins.Height, 0, 0); } page.Children.Clear(); page.Children.Add(image); PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(page); document.Pages.Add(pageContent); }
public static Canvas LoadSpecificCanvas(DataStore data, int pos) { Canvas canvas = new Canvas(); canvas.Width = MainWindow.CanvasW; canvas.Height = MainWindow.CanvasH; if (!String.IsNullOrWhiteSpace(data.pages[pos].canvas)) { CanvasWriter.LoadCanvas(canvas, data.pages[pos].canvas); } ExtractHiddenData(data, canvas, pos); return(canvas); }
void SaveOutputData() { if (currentLoaded >= 0) { if (!output.Pages.ContainsKey(currentLoaded)) { output.Pages.Add(currentLoaded, new OutputPage()); } output.Pages[currentLoaded].Page = currentLoaded; output.Pages[currentLoaded].Image = CanvasWriter.SaveCanvasToImg(PlayCanvas); output.Pages[currentLoaded].AllAnswers = TAllAnswers; output.Pages[currentLoaded].GoodAnswers = TGood; output.Pages[currentLoaded].WrongAnswers = TWrong; output.CreatedTime = DateTime.Now; output.PresentationPagesCount = data.pages.Count; output.HaveScripts = data.AreScriptsAllowed; output.ScriptsAllowed = ScriptWarningBoxAllowed; SaveControlState(); } }
private void LoadCanvas() { Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, curloaded); CanvasSaveLoad.ToPresentationMode(can); CanvasSaveLoad.SimulateCanvas(can); can.UpdateLayout(); Size size = new Size(); can.Measure(size); can.Arrange(new Rect(size)); ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can)); IMBorder.Background = new ImageBrush(bs); IMBorder.BorderBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); IMBorder.BorderThickness = new Thickness(1); IMBorder.Width = data.CanvasW; IMBorder.Height = data.CanvasH; TextBox_Page.Text = "" + (curloaded + 1); L_Pages.Content = "/" + data.pages.Count; }
private void LoadCanvas(int pos, bool IgnoreHidden = false) { //Hidden page if (!IgnoreHidden) { if (data.pages[pos].isHidden) { bool finded = false; if (LoadedPage > pos) { for (int i = pos; i >= 0; i--) { if (!data.pages[i].isHidden) { pos = i; finded = true; break; } } } else { for (int i = pos; i < maxC; i++) { if (!data.pages[i].isHidden) { pos = i; finded = true; break; } } } if (!finded) { return; } } } //hidden page Good_Teacher.MainWindow.ActualPage = pos; LoadedPage = pos; currentC = pos; if (data.SaveOutput) { SaveOutputData(); } if (data.SaveTemporaryData) { SaveTemporary(); } PlaySound(pos); TGood = 0; TWrong = 0; TAllAnswers = 0; PlayCanvas.Children.Clear(); if (!String.IsNullOrWhiteSpace(data.pages[pos].canvas)) { CanvasWriter.LoadCanvas(PlayCanvas, data.pages[pos].canvas); } CanvasSaveLoad.ExtractHiddenData(data, PlayCanvas, pos); CanvasSaveLoad.ToPresentationMode(PlayCanvas); ToSpecialPresentation(); UpdateNumberLabel(); MakeAnimations(pos); currentLoaded = pos; NoCount = true; if (data.SaveTemporaryData) { LoadTempData(); } NoCount = false; foreach (RepeatingData repeat in data.RepeatingControls) { if (!repeat.IgnorePages.Contains((pos + 1))) { ContentViewer contentViewer = repeat.contentViewer.CreateControl(data); contentViewer.IsHitTestVisible = false; PlayCanvas.Children.Add(contentViewer); } } foreach (TimerAction timer in data.pages[currentLoaded].Timers) { timer.SetActualTime(); timer.Stop = false; } DoScript(); dispatcherTimerTransition.Interval = TimeSpan.FromMilliseconds(data.pages[LoadedPage].TransitionMove); dispatcherTimerTransition.IsEnabled = (data.pages[LoadedPage].transitionType != Good_Teacher.Class.Enumerators.TransitionTypeEnum.TransitionType.Manual); }
private void ExportCanvasToPDF() { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = Strings.ResStrings.File + ".pdf"; saveFileDialog.Filter = Strings.FormatStrings.PDF + "| *.pdf|" + Strings.ResStrings.AllFiles + "| *.*"; if (saveFileDialog.ShowDialog() == true) { PdfDocument pdf = new PdfDocument(); for (int i = 0; i < data.pages.Count; i++) { Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i); CanvasSaveLoad.ToPresentationMode(can); CanvasSaveLoad.SimulateCanvas(can); can.UpdateLayout(); Size size = new Size(); can.Measure(size); can.Arrange(new Rect(size)); BitmapSource bs; if (RB_BQuality.IsChecked == true) { bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can)); } else { int quality = 90; int.TryParse(TB_Quality.Text, out quality); bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullJpg(can, quality)); } var ximg = XImage.FromBitmapSource(bs); ximg.Interpolate = false; PdfPage pdfPage = pdf.AddPage(); pdfPage.Width = XUnit.FromPresentation(data.CanvasW); pdfPage.Height = XUnit.FromPresentation(data.CanvasH); XGraphics xgr = XGraphics.FromPdfPage(pdfPage); xgr.DrawImage( ximg, 0, 0, pdfPage.Width, pdfPage.Height); } pdf.Info.Creator = Strings.ResStrings.AppName; pdf.Info.CreationDate = DateTime.Now; pdf.Info.Subject = TB_Subject.Text; pdf.Info.Author = TB_Author.Text; pdf.Info.Title = TB_Title.Text; pdf.Info.Keywords = TB_Keywords.Text; pdf.Save(saveFileDialog.FileName); IsExported = true; Close(); } }
private void timer_Tick(object sender, EventArgs e) { if (ActualLoadPosition < data.pages.Count) { IMG_can = CanvasSaveLoad.LoadSpecificCanvas(data, ActualLoadPosition); IMG_can.Width = MainWindow.CanvasW; IMG_can.Height = MainWindow.CanvasH; BitmapSource bitmapSource = (BitmapSource) new ImageSourceConverter().ConvertFrom(CanvasWriter.SaveCanvasToImgSimulate(IMG_can, MiniatureW, MiniatureH)); ((PageMiniature)WP_Pages.Children[ActualLoadPosition]).SetData(ActualLoadPosition, bitmapSource); ActualLoadPosition++; } else { timer.Stop(); } }