Skip to content

Commit 57e1c0b

Browse files
committed
-
1 parent 82200b6 commit 57e1c0b

File tree

9 files changed

+53
-151
lines changed

9 files changed

+53
-151
lines changed

AddinUtilities.cs

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ public static void initFonts()
3939
if (m_latexFonts == null)
4040
{
4141
m_latexFonts = new List<LatexFont>();
42-
m_latexFonts.Add(new LatexFont("Computer Modern Roman", "cmr"));
42+
//m_latexFonts.Add(new LatexFont("Computer Modern Roman", "cmr"));
4343
m_latexFonts.Add(new LatexFont("Times Roman", "ptm"));
4444
m_latexFonts.Add(new LatexFont("Palatino", "ppl"));
45-
m_latexFonts.Add(new LatexFont("NewCenturySchoolBook", "pnc"));
45+
m_latexFonts.Add(new LatexFont("New Century Schoolbook", "pnc"));
4646
m_latexFonts.Add(new LatexFont("Bookman", "pbk"));
47-
m_latexFonts.Add(new LatexFont("Computer Modern SansSerif", "cmss"));
47+
//m_latexFonts.Add(new LatexFont("Computer Modern SansSerif", "cmss"));
4848
m_latexFonts.Add(new LatexFont("Helvetica", "phv"));
49-
m_latexFonts.Add(new LatexFont("AvantGarde", "pag"));
50-
m_latexFonts.Add(new LatexFont("Computer Modern Typewriter", "cmtt"));
49+
m_latexFonts.Add(new LatexFont("Avant Garde", "pag"));
50+
//m_latexFonts.Add(new LatexFont("Computer Modern Typewriter", "cmtt"));
5151
m_latexFonts.Add(new LatexFont("Courier", "pcr"));
52-
m_latexFonts.Add(new LatexFont("Computer Modern Fibonacci", "cmfib"));
53-
m_latexFonts.Add(new LatexFont("Computer Modern Dunhill", "cmdh"));
52+
//m_latexFonts.Add(new LatexFont("Computer Modern Fibonacci", "cmfib"));
53+
//m_latexFonts.Add(new LatexFont("Computer Modern Dunhill", "cmdh"));
5454
}
5555
if (m_latexFontSeries == null)
5656
{
@@ -289,7 +289,7 @@ public static bool executeMikTex()
289289
return true;
290290
}
291291

292-
public static bool executeDviPng(LatexEquation equation, bool usePreview, bool firstRun)
292+
public static bool executeDviPng(LatexEquation equation, bool firstRun)
293293
{
294294
string appPath = AddinUtilities.getAppDataLocation();
295295
Directory.SetCurrentDirectory(appPath);
@@ -325,73 +325,6 @@ public static bool executeDviPng(LatexEquation equation, bool usePreview, bool f
325325
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))
326326
return false;
327327
}
328-
329-
if (usePreview)
330-
{
331-
try
332-
{
333-
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(output, @"depth=(\S*)]");
334-
string depthStr = match.Groups[1].Value;
335-
equation.m_offset = Int32.Parse(depthStr);
336-
}
337-
catch
338-
{
339-
equation.m_offset = 0;
340-
}
341-
}
342-
return true;
343-
}
344-
345-
public static bool executeDviPng(List<LatexEquation> equations)
346-
{
347-
string appPath = AddinUtilities.getAppDataLocation();
348-
Directory.SetCurrentDirectory(appPath);
349-
350-
// Check Dpi
351-
float[] systemDPI = AddinUtilities.getSystemDPI();
352-
353-
float dpiValue = 192;
354-
foreach (LatexEquation equation in equations)
355-
{
356-
float factor = equation.m_fontSize / 12.0f;
357-
float dpi = factor * systemDPI[0]; // Multiply chosen dpi with factor
358-
if (dpi > dpiValue)
359-
dpiValue = dpi;
360-
}
361-
362-
SettingsManager mgr = SettingsManager.getCurrent();
363-
try
364-
{
365-
File.Delete(appPath + "\\teximport.png");
366-
}
367-
catch
368-
{
369-
MessageBox.Show("teximport.png could not be written. Permission denied.");
370-
return false;
371-
}
372-
373-
string output = "";
374-
if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvipng.exe\" -T tight -bg Transparent --depth --noghostscript -D " + dpiValue.ToString() + " -o teximport%d.png teximport.dvi", true, false, out output))
375-
if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvipng.exe\" -T tight -bg Transparent --depth --noghostscript -D " + dpiValue.ToString() + " -o teximport%d.png teximport.dvi", true, true, out output))
376-
return false;
377-
378-
try
379-
{
380-
System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(output, @"depth=(\S*)\]");
381-
if (matches.Count == equations.Count)
382-
{
383-
LatexEquation [] eq = equations.ToArray();
384-
for (int i = 0; i < equations.Count; i++)
385-
{
386-
string depthStr = matches[i].Groups[1].Value;
387-
eq[i].m_offset = Int32.Parse(depthStr);
388-
}
389-
}
390-
}
391-
catch
392-
{
393-
//equation.m_offset = 0;
394-
}
395328
return true;
396329
}
397330

@@ -415,10 +348,7 @@ public static bool executeDviPs(LatexEquation equation)
415348
string output = "";
416349

417350
// run dvips
418-
if (!startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvips.exe\" teximport.dvi", true, false, out output))
419-
return false;
420-
421-
equation.m_offset = 0;
351+
startProcess("cmd.exe", "/c \"" + mgr.SettingsData.miktexPath + "\\dvips.exe\" teximport.dvi", true, false, out output);
422352

423353
return true;
424354
}
@@ -433,7 +363,7 @@ public static bool createLatexPng(LatexEquation equation, bool usePreview, bool
433363
LatexFileGenerator.writeTexFile(appPath + "\\teximport.tex", equation, usePreview);
434364
if (!executeMikTex())
435365
return false;
436-
if (!executeDviPng(equation, usePreview, firstRun))
366+
if (!executeDviPng(equation, firstRun))
437367
return false;
438368

439369
return true;

DockerUI.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<Grid Margin="0,0,0,0">
1010
<StackPanel>
1111
<Label Content="Latex" />
12-
<Button Content="Add equation" Margin="2,0,0,0" Name="btn_addEquation" Click="btn_addEquation_Click"/>
13-
<Button Content="Edit equation" Margin="2,0,0,0" Name="btn_editEquation" Click="btn_editEquation_Click"/>
12+
<Button Content="Add latex" Margin="2,2,2,2" Name="btn_addLatex" Click="btn_addLatex_Click"/>
13+
<Button Content="Edit latex" Margin="2,2,2,2" Name="btn_editLatex" Click="btn_editLatex_Click"/>
14+
<Button Content="Add equation" Margin="2,2,2,2" Name="btn_addEquation" Click="btn_addEquation_Click"/>
15+
<Button Content="Add eqnarray" Margin="2,2,2,2" Name="btn_addEqnarray" Click="btn_addEqnarray_Click"/>
1416
</StackPanel>
1517
</Grid>
1618

DockerUI.xaml.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public DockerUI(corel.Application app)
4646

4747
private void btn_addEquation_Click(object sender, RoutedEventArgs e)
4848
{
49-
createLatexObject(null, "Create latex object");
49+
string template = "\\begin{equation*}\r\n\t<Enter latex code>\r\n\\end{equation*}\r\n";
50+
createLatexObject(template, "Create latex equation");
5051
}
5152

5253
public void createLatexObject(string template, string title)
@@ -65,10 +66,7 @@ public bool editLatexObject(Corel.Interop.VGCore.Shape s)
6566
{
6667
m_dialog.init(eq, "Edit latex object");
6768

68-
// We cannot use the usual dialog result, since it is not correct, when hiding the window
69-
//IntPtr hwnd = GetForegroundWindow();
7069
m_dialog.ShowDialog();
71-
//SetForegroundWindow(hwnd);
7270
if (m_dialog.Result == System.Windows.Forms.DialogResult.OK)
7371
{
7472
Corel.Interop.VGCore.Shape latexObj = m_dialog.LatexEquation.m_shape;
@@ -83,9 +81,10 @@ public bool editLatexObject(Corel.Interop.VGCore.Shape s)
8381
return false;
8482
}
8583

86-
private void btn_editEquation_Click(object sender, RoutedEventArgs e)
84+
private void btn_editLatex_Click(object sender, RoutedEventArgs e)
8785
{
88-
Corel.Interop.VGCore.Shapes sel = corelApp.ActiveLayer.SelectableShapes;
86+
Corel.Interop.VGCore.ShapeRange sel = corelApp.ActiveDocument.SelectionRange;
87+
//Corel.Interop.VGCore.Shapes sel = corelApp.ActiveLayer.SelectableShapes;
8988
bool found = false;
9089
foreach (Corel.Interop.VGCore.Shape s in sel)
9190
{
@@ -95,5 +94,16 @@ private void btn_editEquation_Click(object sender, RoutedEventArgs e)
9594
if (!found)
9695
createLatexObject(null, "Create latex object");
9796
}
97+
98+
private void btn_addLatex_Click(object sender, RoutedEventArgs e)
99+
{
100+
createLatexObject(null, "Create latex object");
101+
}
102+
103+
private void btn_addEqnarray_Click(object sender, RoutedEventArgs e)
104+
{
105+
string template = "\\begin{eqnarray*}\r\n\t<Enter latex code>\r\n\\end{eqnarray*}\r\n";
106+
createLatexObject(template, "Create latex equation array");
107+
}
98108
}
99109
}

Latex4CorelDraw.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
3535
<ItemGroup>
36-
<Reference Include="ScintillaNET">
37-
<HintPath>..\Scintilla\2.6\bin\Release\ScintillaNET.dll</HintPath>
36+
<Reference Include="ScintillaNET, Version=2.6.0.0, Culture=neutral, PublicKeyToken=948d6c9751444115, processorArchitecture=MSIL">
37+
<SpecificVersion>False</SpecificVersion>
38+
<HintPath>..\Scintilla\3.5.10\ScintillaNET.dll</HintPath>
3839
</Reference>
3940
<Reference Include="System" />
4041
<Reference Include="System.Core" />

LatexDialog.cs

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -229,25 +229,29 @@ private bool generateEquation(bool createShape)
229229
(LatexFontShape)comboBoxShape.SelectedItem);
230230

231231
// Run once with preview to get depth value
232+
m_finishedSuccessfully = true;
232233
if (!createShape)
233234
m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation, true, true);
234235

235236
if (m_finishedSuccessfully)
236237
{
237238
// Run once without to get correct tight image
238239
if (!createShape)
239-
AddinUtilities.createLatexPng(m_latexEquation, false, false);
240+
m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation, false, false);
240241
else
241242
{
242-
AddinUtilities.createLatexPs(m_latexEquation);
243-
244-
string imageFile = Path.Combine(AddinUtilities.getAppDataLocation(), "teximport.ps");
245-
Corel.Interop.VGCore.StructImportOptions impopt = new Corel.Interop.VGCore.StructImportOptions();
246-
impopt.MaintainLayers = true;
247-
Corel.Interop.VGCore.ImportFilter impflt = DockerUI.Current.CorelApp.ActiveLayer.ImportEx(imageFile, Corel.Interop.VGCore.cdrFilter.cdrPSInterpreted, impopt);
248-
impflt.Finish();
249-
m_latexEquation.m_shape = DockerUI.Current.CorelApp.ActiveShape;
250-
ShapeTags.setShapeTags(m_latexEquation);
243+
m_finishedSuccessfully = AddinUtilities.createLatexPs(m_latexEquation);
244+
245+
if (m_finishedSuccessfully)
246+
{
247+
string imageFile = Path.Combine(AddinUtilities.getAppDataLocation(), "teximport.ps");
248+
Corel.Interop.VGCore.StructImportOptions impopt = new Corel.Interop.VGCore.StructImportOptions();
249+
impopt.MaintainLayers = true;
250+
Corel.Interop.VGCore.ImportFilter impflt = DockerUI.Current.CorelApp.ActiveLayer.ImportEx(imageFile, Corel.Interop.VGCore.cdrFilter.cdrPSInterpreted, impopt);
251+
impflt.Finish();
252+
m_latexEquation.m_shape = DockerUI.Current.CorelApp.ActiveShape;
253+
ShapeTags.setShapeTags(m_latexEquation);
254+
}
251255
}
252256
}
253257
return m_finishedSuccessfully;
@@ -345,44 +349,6 @@ private void openLatexTemplateToolStripMenuItem_Click(object sender, EventArgs e
345349
System.Diagnostics.Process.Start(templateFileName);
346350
}
347351

348-
/* private bool m_textChanged = false;
349-
350-
private void textBoxLatex_TextChanged(object sender, EventArgs e)
351-
{
352-
List<string> list = new List<string>();
353-
list.Add("\\begin");
354-
list.Add("\\end");
355-
if (!m_textChanged)
356-
{
357-
// Get text until caret
358-
int oldSelStart = textBoxLatex.SelectionStart;
359-
string str = textBoxLatex.Text.Substring(0, textBoxLatex.SelectionStart);
360-
if (str.Length > 0)
361-
{
362-
int index = str.LastIndexOf(" ") + 1;
363-
str = str.Substring(index);
364-
365-
foreach (string entry in list)
366-
{
367-
if (entry.IndexOf(str) == 0)
368-
{
369-
m_textChanged = true;
370-
textBoxLatex.SelectionStart = index;
371-
textBoxLatex.SelectionLength = str.Length;
372-
textBoxLatex.SelectedText = entry;
373-
textBoxLatex.SelectionStart = oldSelStart;
374-
textBoxLatex.SelectionLength = entry.Length - oldSelStart;
375-
break;
376-
}
377-
}
378-
}
379-
}
380-
else
381-
{
382-
m_textChanged = false;
383-
}
384-
}*/
385-
386352
}
387353

388354
public class LatexFont

LatexFileGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class LatexEquation
1818
public int m_textShapeId;
1919
public int m_imageWidth;
2020
public int m_imageHeight;
21-
public int m_offset;
2221
public Corel.Interop.VGCore.Shape m_shape;
2322

2423
public LatexEquation(string latexCode, float fontSize, string textColor, LatexFont font, LatexFontSeries fontSeries, LatexFontShape fontShape)
@@ -31,7 +30,6 @@ public LatexEquation(string latexCode, float fontSize, string textColor, LatexFo
3130
m_fontShape = fontShape;
3231
m_imageWidth = 0;
3332
m_imageHeight = 0;
34-
m_offset = 0;
3533
m_textShapeId = -1;
3634
}
3735

@@ -45,7 +43,6 @@ public LatexEquation(string latexCode, float fontSize, string textColor, LatexFo
4543
m_fontShape = fontShape;
4644
m_imageWidth = 0;
4745
m_imageHeight = 0;
48-
m_offset = 0;
4946
m_textShapeId = textShapeId;
5047
}
5148
}
@@ -92,7 +89,9 @@ public static void writeTexFile(string fileName, LatexEquation equation, bool us
9289
content += "\\color{txtcolor}\n";
9390
content += "\\changefont{" + equation.m_font.latexFontName + "}{" +
9491
equation.m_fontSeries.latexFontSeries + "}{" +
95-
equation.m_fontShape.latexFontShape + "}\n";
92+
equation.m_fontShape.latexFontShape + "}{" +
93+
equation.m_fontSize.ToString() + "}{" +
94+
((equation.m_fontSize*1.2)).ToString(System.Globalization.CultureInfo.InvariantCulture) + "}\n";
9695
content += equation.m_code;
9796
if (usePreview)
9897
content += "\n\\end{preview}\n";

Resources/LatexInlineTemplate.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
\documentclass[12pt,a4paper,ngerman]{article}
22
\usepackage{amsmath}
33
\usepackage[utf8]{inputenc}
4-
\usepackage{ngerman}
54
\usepackage{bbm}
65
\usepackage{ae,aecompl}
76
\usepackage{color}
87
\usepackage[active,displaymath,textmath,tightpage]{preview}
9-
%\usepackage{helvet}
10-
%\renewcommand\familydefault{phv}
11-
\newcommand{\changefont}[3]{\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}
8+
\newcommand{\changefont}[5]{\fontfamily{#1} \fontseries{#2} \fontshape{#3} \fontsize{#4}{#5}\selectfont}
129
\setlength{\parindent}{0pt}
1310
\begin{document}
1411
\thispagestyle{empty}

Resources/LatexTemplate.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
\documentclass[12pt,a4paper,ngerman]{article}
22
\usepackage{amsmath}
33
\usepackage[utf8]{inputenc}
4-
\usepackage{ngerman}
54
\usepackage{bbm}
65
\usepackage{ae,aecompl}
76
\usepackage{color}
8-
%\usepackage{helvet}
9-
%\renewcommand\familydefault{phv}
10-
\newcommand{\changefont}[3]{\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}
7+
\newcommand{\changefont}[5]{\fontfamily{#1} \fontseries{#2} \fontshape{#3} \fontsize{#4}{#5}\selectfont}
118
\setlength{\parindent}{0pt}
129
\begin{document}
1310
\thispagestyle{empty}

SettingsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool loadSettings()
7070
m_settings = new Settings();
7171
m_settings.textColor = "0,0,0";
7272
m_settings.fontSize = "12";
73-
m_settings.font = "Computer Modern Roman";
73+
m_settings.font = "Times Roman";
7474
m_settings.fontSeries = "Standard";
7575
m_settings.fontShape = "Standard";
7676
m_settings.insertAtCursor = true;

0 commit comments

Comments
 (0)