Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        /// This is called when PDFLatex has exited
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //void texProcess_Exited(object sender, EventArgs e)
        void texprocess_Exited(string StdOutput, string ErrOutput)
        {
            // HACK: make thread-safe
            //Dispatcher.Invoke(new Action(
            //delegate()
            //{
            timer.Stop();

            Dispatcher.BeginInvoke(new Action(delegate()
            {
                Job job = CurrentJob;   // todo_tex.Dequeue();
                if (JobNumberChanged != null)
                {
                    JobNumberChanged(this); // invoke here... it would also be possible to invoke on start of compilation...
                }
                // Parse tex errors/warnings and display
                myPdflatexOutputParser.parseOutput(job);


                if (texProcess.ExitCode == 0)
                {
                    if (job.BBWritten && !job.GeneratePrecompiledHeaders)
                    {
                        ReadBBFromFile(job);
                    }

                    if (OnCompileEvent != null)
                    {
                        OnCompileEvent(this, "Compilation done", CompileEventType.Success);
                    }
                    if (JobSucceeded != null)
                    {
                        JobSucceeded(this, job);
                    }

                    if (job.CreateBMP && !job.GeneratePrecompiledHeaders)
                    {
                        string pathnoext = Helper.RemoveFileExtension(job.path);

                        if (!mypdfDoc.LoadPdf(pathnoext + ".pdf"))
                        {
                            MessageBox.Show("Couldn't load pdf " + pathnoext + ".pdf");
                        }
                        else if (mypdfDoc.IsEmpty())
                        {
                            MessageBox.Show("Image is empty. Did you fill out the sample code block?");
                        }
                        else
                        {
                            mypdfDoc.SaveBmp(pathnoext + ".bmp", Resolution);
                            if (BitmapGenerated != null)
                            {
                                BitmapGenerated(this);
                            }
                        }
                    }
                    else if (job.GeneratePrecompiledHeaders == true)
                    { //if the header should have been generated but it was not
                        if (!File.Exists(Helper.GetPrecompiledHeaderPath() + System.IO.Path.GetFileNameWithoutExtension(Helper.GetPrecompiledHeaderFilename()) + ".fmt"))
                        {
                            todo_tex.Clear();
                            if (OnCompileEvent != null)
                            {
                                OnCompileEvent(this, "Compilation of pre-compiled header succeded but the pre-compiled header file could not be found." +
                                               " It is supposed to be here: " + Helper.GetPrecompiledHeaderPath() + System.IO.Path.GetFileNameWithoutExtension(Helper.GetPrecompiledHeaderFilename()) + ".fmt" +
                                               Environment.NewLine + "Compilation of main document stopped. Check settings and read/write permissions!", CompileEventType.Error);
                            }
                        }
                        else
                        {
                            //clear source and temp files of compilation of header
                            //note: the .tex file must not be deleted!
                            Helper.DeleteTemporaryFiles(job.path, false);
                        }
                    }
                }
                else
                {
                    //if generating pre-compiled header failed. it will not work next time.
                    //so clear job queue and tell user to fix header code.
                    if (job.GeneratePrecompiledHeaders == true)
                    {
                        todo_tex.Clear();
                        if (OnCompileEvent != null)
                        {
                            OnCompileEvent(this, "Compilation of pre-compiled header failed with exit code " + texProcess.ExitCode + ". Compilation of main document stopped. Check under settings code of pre-compiled header!", CompileEventType.Error);
                        }
                    }
                    else
                    {
                        if (OnCompileEvent != null)
                        {
                            OnCompileEvent(this, "Compilation failed with exit code " + texProcess.ExitCode, CompileEventType.Error);
                        }
                    }

                    if (JobFailed != null)
                    {
                        JobFailed(this, job);
                    }
                }

                //parse output from pdflatex.
                //myPdflatexOutputParser.parseOutput();
                //This does not work because something texProcess_Exited is called
                //before the complete output was received by texProcess_OutputDataReceived().

                //isRunning = false;
                SetValue(CompilingPropertyKey, false);

                if (todo_tex.Count > 0)
                {
                    doCompile();
                }
            }));
        }