Esempio n. 1
0
        private bool generateEquation(bool createShape)
        {
            // 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_scintilla.Text, size, m_textColor, (LatexFont)comboBoxFont.SelectedItem,
                                                (LatexFontSeries)comboBoxSeries.SelectedItem,
                                                (LatexFontShape)comboBoxShape.SelectedItem,
                                                (LatexMathFont)comboBoxMathFont.SelectedItem);

            // Run once with preview to get depth value
            m_finishedSuccessfully = true;
            if (!createShape)
            {
                m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation, true);
            }

            if (m_finishedSuccessfully)
            {
                // Run once without to get correct tight image
                if (!createShape)
                {
                    m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation, false);
                }
                else
                {
                    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);
        }