public RasterControl() { InitializeComponent(); if (DesignMode) { return; } disablerPanel = new Panel() { Dock = DockStyle.Fill, BackColor = Color.Transparent, Visible = false, Cursor = Cursors.No }; toolTip1.SetToolTip(disablerPanel, "Overlay out of sync. WYSIWYG editing is disabled"); //toolTip1.SetToolTip(this, "The WYSIWYG area"); //toolTip1.Popup += new PopupEventHandler(toolTip1_Popup); //toolTip1.ReshowDelay = 50; //toolTip1.InitialDelay = 100; //toolTip1.ShowAlways = true; toolTip1.Active = true; this.MouseHover += new EventHandler(RasterControl_MouseHover); this.Controls.Add(disablerPanel); CreateContextMenu(); //this.CanFocus = true; this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.Selectable, true); TheRasterModel = new RasterControlModel(this); IPdfToBmp <Bitmap> Pdf2Bmp; if (CompilerSettings.Instance.UseExternalRenderer) { Pdf2Bmp = new PdfToBmpExtWinForms(); } else { Pdf2Bmp = new PdfToBmp(); } TheDisplayModel = new TikzDisplayModel <Bitmap>(this, Pdf2Bmp); TheOverlayModel = new PdfOverlayModel(this, this); TheOverlayModel.DisplayTree.DisplayTreeChanged += new EventHandler <TikzDisplayTree.DisplayTreeChangedEventArgs>(DisplayTree_DisplayTreeChanged); MarkObject_Timer.Interval = 500; MarkObject_Timer.Tick += new EventHandler(MarkObject_Timer_Tick); // listen to Bitmap changes MyBindings.Add(BindingFactory.CreateBinding(TheDisplayModel, "Bmp", (o) => this.Invalidate(), null)); }
/// <summary> /// Displays an Export As dialog and, if successful, exports the current tikzpicture /// as either bmp, jpeg, tiff or png. /// </summary> void ExportFile() { if (CurFileNeverSaved) { MainWindow.AddStatusLine("Please save document first", true); return; } string s = Helper.GetCurrentWorkingDir(); string t = Helper.GetPreviewFilename(); string PreviewPdfFilePath = s + "\\" + this.FilePath + t + ".pdf"; string TheFilePath = Helper.RemoveFileExtension(this.FilePath) + ".pdf"; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Jpeg Files|*.jpg|Portable Network Graphics|*.png|Bitmap Files|*.bmp|Tiff Files|*.tif|Graphics Interchange Format|*.gif|Extended Meta File|*.emf|Windows Meta File|*.wmf|Html File|*.html|Scalable Vector Graphics|*.svg"; sfd.FilterIndex = 1; sfd.OverwritePrompt = true; sfd.ValidateNames = true; sfd.AddExtension = true; sfd.FileName = System.IO.Path.GetFileName(TheFilePath); // change file extension to .pdf sfd.FileName = Helper.RemoveFileExtension(sfd.FileName) + ".jpg"; sfd.InitialDirectory = System.IO.Path.GetDirectoryName(TheFilePath); if (sfd.ShowDialog() != true) { return; } TheFilePath = sfd.FileName; try { System.Drawing.Imaging.ImageFormat imgFormat; bool Transparent = true; switch (System.IO.Path.GetExtension(TheFilePath).ToLower()) { case ".jpg": imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; Transparent = false; break; case ".bmp": imgFormat = System.Drawing.Imaging.ImageFormat.Bmp; Transparent = false; break; case ".gif": imgFormat = System.Drawing.Imaging.ImageFormat.Gif; Transparent = false; break; case ".emf": imgFormat = System.Drawing.Imaging.ImageFormat.Emf; break; case ".wmf": imgFormat = System.Drawing.Imaging.ImageFormat.Wmf; break; case ".tif": imgFormat = System.Drawing.Imaging.ImageFormat.Tiff; break; case ".png": imgFormat = System.Drawing.Imaging.ImageFormat.Png; break; case ".svg": case ".html": case ".htm": // The file will be compiled and exported by ExportCompileDialog ExportCompiler.ExportCompileDialog.Export(Document.Text, TheFilePath); return; default: MainWindow.AddStatusLine("Could not export file: Unknown file extension.", true); return; } PdfToBmp p2b = new PdfToBmp(); p2b.LoadPdf(PreviewPdfFilePath); p2b.SaveBmp(TheFilePath, Consts.ptspertikzunit, Transparent, imgFormat); } catch (Exception Ex) { MainWindow.AddStatusLine("Could not export file. " + Ex.Message, true); return; } MainWindow.AddStatusLine("File exported as " + TheFilePath); }
/// <summary> /// Displays an Export As dialog and, if successful, exports the current tikzpicture /// as either bmp, jpeg, tiff or png. /// </summary> void ExportFile() { if (CurFileNeverSaved) { MainWindow.AddStatusLine("Please save document first", true); return; } string s = Helper.GetCurrentWorkingDir(); string t = Helper.GetPreviewFilename(); string PreviewPdfFilePath = s + "\\" + this.FilePath + t + ".pdf"; string TheFilePath = Helper.RemoveFileExtension(this.FilePath) + ".pdf"; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Jpeg Files|*.jpg|Portable Network Graphics|*.png|Bitmap Files|*.bmp|Tiff Files|*.tif|Graphics Interchange Format|*.gif|Extended Meta File|*.emf|Windows Meta File|*.wmf|Html File|*.html|Scalable Vector Graphics|*.svg"; sfd.FilterIndex = 1; sfd.OverwritePrompt = true; sfd.ValidateNames = true; sfd.AddExtension = true; sfd.FileName = System.IO.Path.GetFileName(TheFilePath); // change file extension to .pdf sfd.FileName = Helper.RemoveFileExtension(sfd.FileName) + ".jpg"; sfd.InitialDirectory = System.IO.Path.GetDirectoryName(TheFilePath); if (sfd.ShowDialog() != true) return; TheFilePath = sfd.FileName; try { System.Drawing.Imaging.ImageFormat imgFormat; bool Transparent = true; switch (System.IO.Path.GetExtension(TheFilePath).ToLower()) { case ".jpg": imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; Transparent = false; break; case ".bmp": imgFormat = System.Drawing.Imaging.ImageFormat.Bmp; Transparent = false; break; case ".gif": imgFormat = System.Drawing.Imaging.ImageFormat.Gif; Transparent = false; break; case ".emf": imgFormat = System.Drawing.Imaging.ImageFormat.Emf; break; case ".wmf": imgFormat = System.Drawing.Imaging.ImageFormat.Wmf; break; case ".tif": imgFormat = System.Drawing.Imaging.ImageFormat.Tiff; break; case ".png": imgFormat = System.Drawing.Imaging.ImageFormat.Png; break; case ".svg": case ".html": case ".htm": // The file will be compiled and exported by ExportCompileDialog ExportCompiler.ExportCompileDialog.Export(Document.Text, TheFilePath); return; default: MainWindow.AddStatusLine("Could not export file: Unknown file extension.", true); return; } PdfToBmp p2b = new PdfToBmp(); p2b.LoadPdf(PreviewPdfFilePath); p2b.SaveBmp(TheFilePath, Consts.ptspertikzunit, Transparent, imgFormat); } catch (Exception Ex) { MainWindow.AddStatusLine("Could not export file. " + Ex.Message, true); return; } MainWindow.AddStatusLine("File exported as " + TheFilePath); }