Exemplo n.º 1
0
        public static bool executePs2Pdf(LatexEquation equation)
        {
            string appPath = AddinUtilities.getAppDataLocation();

            Directory.SetCurrentDirectory(appPath);


            SettingsManager mgr = SettingsManager.getCurrent();

            try
            {
                File.Delete(appPath + "\\teximport.pdf");
            }
            catch
            {
                MessageBox.Show("teximport.pdf could not be written. Permission denied.");
                return(false);
            }

            string output = "";

            // run ps2pdf
            startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\ps2pdf.exe\" -dNoOutputFonts teximport.ps teximport.pdf", true, false, out output);

            return(true);
        }
Exemplo n.º 2
0
        private void btn_bulkEdit_Click(object sender, RoutedEventArgs e)
        {
            Corel.Interop.VGCore.ShapeRange sel = corelApp.ActiveDocument.SelectionRange;
            LatexEquation eq = ShapeTags.getLatexEquation(sel.FirstShape);

            if (eq != null)
            {
                m_sdialog.init(eq, "Bulk-edit style");
                m_sdialog.ShowDialog();
                if (m_sdialog.Result == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (Corel.Interop.VGCore.Shape s in sel)
                    {
                        eq = ShapeTags.getLatexEquation(s);
                        m_sdialog.LatexEquation = eq;
                        if (m_sdialog.generateEquation())
                        {
                            Corel.Interop.VGCore.Shape latexObj = m_sdialog.LatexEquation.m_shape;
                            if (latexObj != null)
                            {
                                latexObj.TransformationMatrix = s.TransformationMatrix;
                                s.Delete();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void init(LatexEquation eq, string title)
        {
            this.Text = title;
            m_finishedSuccessfully = false;
            if (eq != null)
            {
                m_latexEquation = eq;
                if (!comboBoxFontSize.Items.Contains(eq.m_fontSize))
                {
                    comboBoxFontSize.Items.Add(eq.m_fontSize);
                }
                comboBoxFontSize.SelectedItem = eq.m_fontSize;
                comboBoxFont.Text             = eq.m_font.fontName;
                comboBoxSeries.Text           = eq.m_fontSeries.fontSeries;
                comboBoxShape.Text            = eq.m_fontShape.fontShape;
                comboBoxMathFont.Text         = eq.m_mathFont.fontName;

                try
                {
                    buttonColor.BackColor = AddinUtilities.stringToColor(eq.m_color);
                    m_textColor           = eq.m_color;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 4
0
 public static void setShapeTags(LatexEquation equation)
 {
     addTag(equation.m_shape, "LatexCode", equation.m_code.Replace("\r\n", "\\r\\n"));
     addTag(equation.m_shape, "LatexFontSize", equation.m_fontSize.ToString());
     addTag(equation.m_shape, "LatexTextColor", equation.m_color);
     addTag(equation.m_shape, "LatexFont", equation.m_font.fontName);
     addTag(equation.m_shape, "LatexFontSeries", equation.m_fontSeries.fontSeries);
     addTag(equation.m_shape, "LatexFontShape", equation.m_fontShape.fontShape);
     addTag(equation.m_shape, "LatexTextShapeId", equation.m_textShapeId.ToString());
     addTag(equation.m_shape, "Latex4CorelDrawVersion", AddinUtilities.getVersionString());
 }
        public static void writeTexFile(string fileName, LatexEquation equation)
        {
            string templateText     = "";
            string templateFileName = AddinUtilities.getAppDataLocation() + "\\LatexTemplate.txt";

            // Use resource template, if no file exists
            if (!File.Exists(templateFileName))
            {
                templateText = Properties.Resources.LatexTemplate;
            }
            else  // Otherwise use the file
            {
                // Read template
                try
                {
                    SettingsManager mgr = SettingsManager.getCurrent();

                    StreamReader sr;
                    sr           = File.OpenText(templateFileName);
                    templateText = sr.ReadToEnd();
                    sr.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            string content = "";

            content += "\\definecolor{txtcolor}{rgb}{" + equation.m_color + "}\n";;
            content += "\\color{txtcolor}\n";
            content += "\\changefont{" + equation.m_font.latexFontName + "}{" +
                       equation.m_fontSeries.latexFontSeries + "}{" +
                       equation.m_fontShape.latexFontShape + "}{" +
                       equation.m_fontSize.ToString() + "}{" +
                       ((equation.m_fontSize * 1.2)).ToString(System.Globalization.CultureInfo.InvariantCulture) + "}\n";
            content += equation.m_code;

            templateText = templateText.Replace("${Content}", content);

            // Write Latex file
            try
            {
                StreamWriter sw = File.CreateText(fileName);
                sw.Write(templateText);
                sw.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 6
0
        public bool generateEquation()
        {
            // Check paths
            SettingsManager mgr = SettingsManager.getCurrent();

            // Check font size
            string fontSize = comboBoxFontSize.Text;
            float  size     = 12;

            try
            {
                size = Convert.ToSingle(fontSize);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Font size exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // Check Dpi
            float[] systemDPI = AddinUtilities.getSystemDPI();
            float   dpiValue  = systemDPI[0];

            mgr.SettingsData.fontSize   = comboBoxFontSize.Text;
            mgr.SettingsData.font       = comboBoxFont.Text;
            mgr.SettingsData.fontSeries = comboBoxSeries.Text;
            mgr.SettingsData.fontShape  = comboBoxShape.Text;
            mgr.SettingsData.mathFont   = comboBoxMathFont.Text;
            mgr.SettingsData.textColor  = m_textColor;
            mgr.saveSettings();

            m_latexEquation = new LatexEquation(m_latexEquation.m_code, size, m_textColor, (LatexFont)comboBoxFont.SelectedItem,
                                                (LatexFontSeries)comboBoxSeries.SelectedItem,
                                                (LatexFontShape)comboBoxShape.SelectedItem,
                                                (LatexMathFont)comboBoxMathFont.SelectedItem);

            m_finishedSuccessfully = AddinUtilities.createLatexPdf(m_latexEquation);

            if (m_finishedSuccessfully)
            {
                string imageFile = Path.Combine(AddinUtilities.getAppDataLocation(), "teximport.pdf");
                Corel.Interop.VGCore.StructImportOptions impopt = new Corel.Interop.VGCore.StructImportOptions();
                impopt.MaintainLayers = true;
                Corel.Interop.VGCore.ImportFilter impflt = DockerUI.Current.CorelApp.ActiveLayer.ImportEx(imageFile, Corel.Interop.VGCore.cdrFilter.cdrPDF, impopt);
                impflt.Finish();
                m_latexEquation.m_shape = DockerUI.Current.CorelApp.ActiveShape;
                ShapeTags.setShapeTags(m_latexEquation);
            }

            return(m_finishedSuccessfully);
        }
Exemplo n.º 7
0
        public static bool executeDviPng(LatexEquation equation, bool firstRun)
        {
            string appPath = AddinUtilities.getAppDataLocation();

            Directory.SetCurrentDirectory(appPath);

            // Check Dpi
            float[] systemDPI = AddinUtilities.getSystemDPI();

            float factor   = equation.m_fontSize / 12.0f;
            float dpiValue = factor * systemDPI[0];   // Multiply chosen dpi with factor


            SettingsManager mgr = SettingsManager.getCurrent();

            try
            {
                File.Delete(appPath + "\\teximport.png");
            }
            catch
            {
                MessageBox.Show("teximport.png could not be written. Permission denied.");
                return(false);
            }

            string output = "";

            if (firstRun)
            {
                // In first run, run dvipng only once
                if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvipng.exe\" -T tight -bg Transparent --depth --noghostscript -D " + dpiValue.ToString() + " -o teximport.png teximport.dvi", true, false, out output))
                {
                    return(false);
                }
            }
            else
            {
                if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvipng.exe\" -T tight -bg Transparent --depth --noghostscript -D " + dpiValue.ToString() + " -o teximport.png teximport.dvi", true, false, out output))
                {
                    if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvipng.exe\" -T tight -bg Transparent --depth --noghostscript -D " + dpiValue.ToString() + " -o teximport.png teximport.dvi", true, true, out output))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        public static bool createLatexPng(LatexEquation equation, bool firstRun)
        {
            // Check paths
            SettingsManager mgr = SettingsManager.getCurrent();

            string appPath = AddinUtilities.getAppDataLocation();

            Directory.SetCurrentDirectory(appPath);
            LatexFileGenerator.writeTexFile(appPath + "\\teximport.tex", equation);
            if (!executeMikTex())
            {
                return(false);
            }
            if (!executeDviPng(equation, firstRun))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool editLatexObject(Corel.Interop.VGCore.Shape s)
        {
            LatexEquation eq = ShapeTags.getLatexEquation(s);

            if (eq != null)
            {
                m_dialog.init(eq, "Edit latex object");

                m_dialog.ShowDialog();
                if (m_dialog.Result == System.Windows.Forms.DialogResult.OK)
                {
                    Corel.Interop.VGCore.Shape latexObj = m_dialog.LatexEquation.m_shape;
                    if (latexObj != null)
                    {
                        latexObj.TransformationMatrix = s.TransformationMatrix;
                        s.Delete();
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        public void init(LatexEquation eq, string title)
        {
            init(title);
            if (eq != null)
            {
                m_scintilla.Text = eq.m_code;
                m_scintilla.Selection.SelectAll();

                comboBoxFontSize.Text = eq.m_fontSize.ToString();
                comboBoxFont.Text     = eq.m_font.fontName;
                comboBoxSeries.Text   = eq.m_fontSeries.fontSeries;
                comboBoxShape.Text    = eq.m_fontShape.fontShape;

                try
                {
                    buttonColor.BackColor = AddinUtilities.stringToColor(eq.m_color);
                    m_textColor           = eq.m_color;
                }
                catch
                {
                }
            }
        }