-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathLatexFileGenerator.cs
106 lines (96 loc) · 3.68 KB
/
LatexFileGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace Latex4CorelDraw
{
public class LatexEquation
{
public string m_code;
public float m_fontSize;
public string m_color;
public LatexFont m_font;
public LatexFontSeries m_fontSeries;
public LatexFontShape m_fontShape;
public int m_textShapeId;
public int m_imageWidth;
public int m_imageHeight;
public Corel.Interop.VGCore.Shape m_shape;
public LatexEquation(string latexCode, float fontSize, string textColor, LatexFont font, LatexFontSeries fontSeries, LatexFontShape fontShape)
{
m_code = latexCode;
m_fontSize = fontSize;
m_color = textColor;
m_font = font;
m_fontSeries = fontSeries;
m_fontShape = fontShape;
m_imageWidth = 0;
m_imageHeight = 0;
m_textShapeId = -1;
}
public LatexEquation(string latexCode, float fontSize, string textColor, LatexFont font, LatexFontSeries fontSeries, LatexFontShape fontShape, int textShapeId)
{
m_code = latexCode;
m_fontSize = fontSize;
m_color = textColor;
m_font = font;
m_fontSeries = fontSeries;
m_fontShape = fontShape;
m_imageWidth = 0;
m_imageHeight = 0;
m_textShapeId = textShapeId;
}
}
public class LatexFileGenerator
{
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);
}
}
}
}