public LatexDialog() { InitializeComponent(); // Be sure, there is a language.xml file AddinUtilities.copyLanguageFile(); this.SuspendLayout(); m_scintilla = new ScintillaNET.Scintilla(); this.groupBoxLatex.Controls.Add(m_scintilla); m_scintilla.Dock = DockStyle.Fill; m_scintilla.Margins[0].Width = 20; m_scintilla.ConfigurationManager.CustomLocation = AddinUtilities.getAppDataLocation() + "\\Language.xml"; m_scintilla.ConfigurationManager.Language = "mytex"; m_scintilla.IsBraceMatching = true; m_scintilla.TabIndex = 0; m_scintilla.AutoComplete.DropRestOfWord = true; this.ResumeLayout(false); m_scintilla.Focus(); m_scintilla.KeyDown += new KeyEventHandler(m_scintilla_KeyDown); createFontEntries(); m_finishedSuccessfully = false; this.FormClosing += new FormClosingEventHandler(LatexDialog_FormClosing); }
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 { } } }
private void buttonPreview_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (pictureBoxPreview.Image != null) { pictureBoxPreview.Image.Dispose(); } bool finishedSuccessfully = generateEquation(false); if (finishedSuccessfully) { string imageFile = Path.Combine(AddinUtilities.getAppDataLocation(), "teximport.png"); using (FileStream stream = new FileStream(imageFile, FileMode.Open, FileAccess.Read)) { pictureBoxPreview.Image = System.Drawing.Image.FromStream(stream); int sum = buttonColor.BackColor.R + buttonColor.BackColor.G + buttonColor.BackColor.B; //Color col = Color.FromArgb(255 - buttonColor.BackColor.R, 255 - buttonColor.BackColor.G, 255 - buttonColor.BackColor.B); System.Drawing.Color col = System.Drawing.Color.White; if (sum / 3 > 127) { col = System.Drawing.Color.Black; } pictureBoxPreview.BackColor = col; panel1.BackColor = col; stream.Close(); } } Cursor.Current = Cursors.Default; }
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); }
private void createFontEntries() { AddinUtilities.initFonts(); comboBoxFont.Items.AddRange(AddinUtilities.LatexFonts.ToArray()); comboBoxSeries.Items.AddRange(AddinUtilities.LatexFontSeries.ToArray()); comboBoxShape.Items.AddRange(AddinUtilities.LatexFontShapes.ToArray()); }
public static LatexFontSeries getLatexFontSeries(Shape s) { string str = (string)s.ObjectData["LatexFontSeries"].Value; if (str != null) { return(AddinUtilities.getLatexFontSeries(str)); } return(null); }
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 int getLatexTextShapeId(Shape s) { string str = (string)s.ObjectData["LatexTextShapeId"].Value.ToString(); int value = -1; if ((str != null) && (str != "")) { value = AddinUtilities.getInt(str, -1); } return(value); }
public static float getLatexFontSize(Shape s) { string str = (string)s.ObjectData["LatexFontSize"].Value.ToString(); float fontSizeValue = 12.0f; if (str != null) { fontSizeValue = AddinUtilities.getFloat(str, 12.0f); } return(fontSizeValue); }
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); } }
public DockerUI(corel.Application app) { this.corelApp = app; m_current = this; InitializeComponent(); AddinUtilities.initFonts(); AddinUtilities.copyLatexTemplate("LatexTemplate.txt", Properties.Resources.LatexTemplate); m_dialog = new LatexDialog(); SettingsManager mgr = SettingsManager.getCurrent(); }
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); }
// Serialization public void saveSettings() { try { string path = AddinUtilities.getAppDataLocation(); XmlSerializer s = new XmlSerializer(typeof(Settings)); TextWriter w = new StreamWriter(path + "\\settings.xml"); s.Serialize(w, m_settings); w.Close(); } catch (Exception ex) { MessageBox.Show("Exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); }
public static LatexMathFont getLatexMathFont(Shape s) { Version objVer = new Version(s.ObjectData["Latex4CorelDrawVersion"].Value.ToString()); if (objVer < new Version(1, 0, 2, 0)) { return(new LatexMathFont("Standard", "")); } string str = (string)s.ObjectData["LatexMathFont"].Value; if (str != null) { return(AddinUtilities.getLatexMathFont(str)); } return(null); }
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); }
public static void copyLatexTemplate(string fileName, string templateText) { string templateFileName = AddinUtilities.getAppDataLocation() + "\\" + fileName; // Write resource template, if no file exists if (!File.Exists(templateFileName)) { // Write template to app data location try { StreamWriter sw; sw = File.CreateText(templateFileName); sw.Write(templateText); sw.Close(); } catch (Exception ex) { MessageBox.Show("Exception: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// Deserialization public bool loadSettings() { bool result = true; try { string path = AddinUtilities.getAppDataLocation(); XmlSerializer s = new XmlSerializer(typeof(Settings)); TextReader r = new StreamReader(path + "\\settings.xml"); m_settings = (Settings)s.Deserialize(r); r.Close(); } catch { // Set default values m_settings = new Settings(); m_settings.textColor = "0,0,0"; m_settings.fontSize = "12"; m_settings.font = "Times Roman"; m_settings.fontSeries = "Standard"; m_settings.fontShape = "Standard"; m_settings.mathFont = "Standard"; m_settings.insertAtCursor = true; result = false; } // If the miktex path was not found, try to find it in the registry if ((m_settings.miktexPath == null) || (m_settings.miktexPath == "")) { RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MiKTeX 2.8", false); if (key != null) { m_settings.miktexPath = (string)key.GetValue("InstallLocation", ""); if (m_settings.miktexPath != "") { m_settings.miktexPath += "\\miktex\\bin"; } } } return(result); }
private void init(string title) { this.Text = title; m_finishedSuccessfully = false; m_scintilla.Text = ""; m_scintilla.UndoRedo.EmptyUndoBuffer(); SettingsManager mgr = SettingsManager.getCurrent(); if (!comboBoxFontSize.Items.Contains(mgr.SettingsData.fontSize)) { comboBoxFontSize.Items.Add(mgr.SettingsData.fontSize); } comboBoxFontSize.SelectedItem = mgr.SettingsData.fontSize; comboBoxFont.Text = mgr.SettingsData.font; comboBoxSeries.Text = mgr.SettingsData.fontSeries; comboBoxShape.Text = mgr.SettingsData.fontShape; buttonColor.BackColor = AddinUtilities.stringToColor(mgr.SettingsData.textColor); m_textColor = mgr.SettingsData.textColor; pictureBoxPreview.BackColor = Color.White; panel1.BackColor = Color.White; }
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 { } } }
private void openLatexTemplateToolStripMenuItem_Click(object sender, EventArgs e) { string templateFileName = AddinUtilities.getAppDataLocation() + "\\LatexTemplate.txt"; System.Diagnostics.Process.Start(templateFileName); }
private void changeOptionsToolStripMenuItem_Click(object sender, EventArgs e) { AddinUtilities.changeOptions(); }