Skip to content

Commit a82d8bc

Browse files
committed
- cleanup
1 parent fadef65 commit a82d8bc

File tree

11 files changed

+32
-494
lines changed

11 files changed

+32
-494
lines changed

Latex4PowerPoint/AddinUtilities.cs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public static bool executeMikTex()
397397
return true;
398398
}
399399

400-
public static bool executeDviPng(LatexEquation equation, bool usePreview, bool firstRun)
400+
public static bool executeDviPng(LatexEquation equation)
401401
{
402402
string appPath = AddinUtilities.getAppDataLocation();
403403
Directory.SetCurrentDirectory(appPath);
@@ -421,32 +421,10 @@ public static bool executeDviPng(LatexEquation equation, bool usePreview, bool f
421421
}
422422

423423
string output = "";
424-
if (firstRun)
425-
{
426-
// In first run, run dvipng only once
427-
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))
424+
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))
425+
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))
428426
return false;
429-
}
430-
else
431-
{
432-
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))
433-
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))
434-
return false;
435-
}
436427

437-
if (usePreview)
438-
{
439-
try
440-
{
441-
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(output, @"depth=(\S*)]");
442-
string depthStr = match.Groups[1].Value;
443-
equation.m_offset = Int32.Parse(depthStr);
444-
}
445-
catch
446-
{
447-
equation.m_offset = 0;
448-
}
449-
}
450428
return true;
451429
}
452430

@@ -483,37 +461,20 @@ public static bool executeDviPng(List<LatexEquation> equations)
483461
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))
484462
return false;
485463

486-
try
487-
{
488-
System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(output, @"depth=(\S*)\]");
489-
if (matches.Count == equations.Count)
490-
{
491-
LatexEquation [] eq = equations.ToArray();
492-
for (int i = 0; i < equations.Count; i++)
493-
{
494-
string depthStr = matches[i].Groups[1].Value;
495-
eq[i].m_offset = Int32.Parse(depthStr);
496-
}
497-
}
498-
}
499-
catch
500-
{
501-
//equation.m_offset = 0;
502-
}
503464
return true;
504465
}
505466

506-
public static bool createLatexPng(LatexEquation equation, bool usePreview, bool firstRun)
467+
public static bool createLatexPng(LatexEquation equation)
507468
{
508469
// Check paths
509470
SettingsManager mgr = SettingsManager.getCurrent();
510471

511472
string appPath = AddinUtilities.getAppDataLocation();
512473
Directory.SetCurrentDirectory(appPath);
513-
LatexFileGenerator.writeTexFile(appPath + "\\teximport.tex", equation, usePreview);
474+
LatexFileGenerator.writeTexFile(appPath + "\\teximport.tex", equation);
514475
if (!executeMikTex())
515476
return false;
516-
if (!executeDviPng(equation, usePreview, firstRun))
477+
if (!executeDviPng(equation))
517478
return false;
518479

519480
return true;

Latex4PowerPoint/InlineLatex.cs

Lines changed: 0 additions & 166 deletions
This file was deleted.

Latex4PowerPoint/Latex4PowerPoint.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@
184184
<Compile Include="ErrorDialog.designer.cs">
185185
<DependentUpon>ErrorDialog.cs</DependentUpon>
186186
</Compile>
187-
<Compile Include="InlineLatex.cs" />
188187
<Compile Include="LatexDialog.cs">
189188
<SubType>Form</SubType>
190189
</Compile>
@@ -213,6 +212,7 @@
213212
<EmbeddedResource Include="Properties\Resources.resx">
214213
<Generator>ResXFileCodeGenerator</Generator>
215214
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
215+
<SubType>Designer</SubType>
216216
</EmbeddedResource>
217217
<EmbeddedResource Include="Ribbon.resx">
218218
<DependentUpon>Ribbon.cs</DependentUpon>
@@ -237,7 +237,6 @@
237237
<Compile Include="Ribbon.designer.cs">
238238
<DependentUpon>Ribbon.cs</DependentUpon>
239239
</Compile>
240-
<Compile Include="SelectionHandler.cs" />
241240
<Compile Include="SettingsManager.cs" />
242241
<Compile Include="ShapeTags.cs" />
243242
<Compile Include="ThisAddIn.cs">
@@ -251,9 +250,6 @@
251250
</Compile>
252251
<AppDesigner Include="Properties\" />
253252
</ItemGroup>
254-
<ItemGroup>
255-
<None Include="Resources\LatexInlineTemplate.txt" />
256-
</ItemGroup>
257253
<ItemGroup>
258254
<None Include="Resources\LatexTemplate.txt" />
259255
</ItemGroup>

Latex4PowerPoint/LatexDialog.cs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,16 @@ private bool generateEquation(bool createShape, bool useSystemDPI)
270270

271271
m_latexEquation = new LatexEquation(m_scintilla.Text, size, dpiValue, m_textColor, (LatexFont)comboBoxFont.SelectedItem,
272272
(LatexFontSeries)comboBoxSeries.SelectedItem,
273-
(LatexFontShape)comboBoxShape.SelectedItem, false);
273+
(LatexFontShape)comboBoxShape.SelectedItem);
274274

275-
// Run once with preview to get depth value
276-
m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation, true, true);
277275

278-
if (m_finishedSuccessfully)
276+
m_finishedSuccessfully = AddinUtilities.createLatexPng(m_latexEquation);
277+
if (createShape)
279278
{
280-
// Run once without to get correct tight image
281-
AddinUtilities.createLatexPng(m_latexEquation, false, false);
282-
if (createShape)
283-
{
284-
AddinUtilities.createLatexShape("teximport.png", m_latexEquation);
285-
m_latexEquation.m_shape.Select(Microsoft.Office.Core.MsoTriState.msoTrue);
286-
AddinUtilities.centerLatexShape(m_latexEquation);
287-
alignLatexShape(m_latexEquation);
288-
}
279+
AddinUtilities.createLatexShape("teximport.png", m_latexEquation);
280+
m_latexEquation.m_shape.Select(Microsoft.Office.Core.MsoTriState.msoTrue);
281+
AddinUtilities.centerLatexShape(m_latexEquation);
282+
alignLatexShape(m_latexEquation);
289283
}
290284
return m_finishedSuccessfully;
291285
}
@@ -294,31 +288,25 @@ private void alignLatexShape(LatexEquation equation)
294288
{
295289
if (m_textRange != null)
296290
{
297-
System.Drawing.FontFamily family = AddinUtilities.getFontFamily(m_textRange);
298-
//float height = (float)(m_textRange.BoundHeight * ((float)family.GetCellAscent(System.Drawing.FontStyle.Regular) / (float)family.GetLineSpacing(System.Drawing.FontStyle.Regular)));
299-
float lineSpacing = m_textRange.Font.Size*(float)family.GetLineSpacing(System.Drawing.FontStyle.Regular) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
300-
float spaceBefore = 0.0f;
301-
if (m_textRange.BoundHeight > lineSpacing)
302-
spaceBefore = m_textRange.ParagraphFormat.SpaceBefore * lineSpacing;
303-
float height = spaceBefore + (m_textRange.Font.Size * (float)family.GetCellAscent(System.Drawing.FontStyle.Regular)) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
304-
float offset = (float)equation.m_offset / (float)equation.m_imageHeight;
291+
//System.Drawing.FontFamily family = AddinUtilities.getFontFamily(m_textRange);
292+
////float height = (float)(m_textRange.BoundHeight * ((float)family.GetCellAscent(System.Drawing.FontStyle.Regular) / (float)family.GetLineSpacing(System.Drawing.FontStyle.Regular)));
293+
//float lineSpacing = m_textRange.Font.Size*(float)family.GetLineSpacing(System.Drawing.FontStyle.Regular) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
294+
//float spaceBefore = 0.0f;
295+
//if (m_textRange.BoundHeight > lineSpacing)
296+
// spaceBefore = m_textRange.ParagraphFormat.SpaceBefore * lineSpacing;
297+
//float height = spaceBefore + (m_textRange.Font.Size * (float)family.GetCellAscent(System.Drawing.FontStyle.Regular)) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
298+
//float offset = (float)equation.m_offset / (float)equation.m_imageHeight;
305299

306300
//// Test
307301
//int slideId = ThisAddIn.Current.Application.ActiveWindow.Selection.SlideRange.SlideID;
308302
//Microsoft.Office.Interop.PowerPoint.Slide slide = ThisAddIn.Current.Application.ActivePresentation.Slides.FindBySlideID(slideId);
309-
//slide.Shapes.AddLine(m_textRange.BoundLeft, m_textRange.BoundTop + height + spaceBefore, m_textRange.BoundLeft + 50, m_textRange.BoundTop + height + spaceBefore);
310-
//slide.Shapes.AddLine(m_textRange.BoundLeft, m_textRange.BoundTop + height + spaceBefore, m_textRange.BoundLeft + 50, m_textRange.BoundTop + height + offset * equation.m_shape.Height + spaceBefore);
311-
//slide.Shapes.AddLine(m_textRange.BoundLeft - 5, m_textRange.BoundTop, m_textRange.BoundLeft - 5, m_textRange.BoundTop + lineSpacing + spaceBefore);
312-
//float asc = m_textRange.Font.Size * (float)family.GetCellAscent(System.Drawing.FontStyle.Regular) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
313-
//float ds = m_textRange.Font.Size * (float)family.GetCellDescent(System.Drawing.FontStyle.Regular) / (float)family.GetEmHeight(System.Drawing.FontStyle.Regular);
314-
//slide.Shapes.AddLine(m_textRange.BoundLeft - 15, m_textRange.BoundTop, m_textRange.BoundLeft - 15, m_textRange.BoundTop + asc + spaceBefore);
315-
//slide.Shapes.AddLine(m_textRange.BoundLeft - 25, m_textRange.BoundTop, m_textRange.BoundLeft - 25, m_textRange.BoundTop + asc + ds + spaceBefore);
303+
//slide.Shapes.AddLine(m_textRange.BoundLeft, m_textRange.BoundTop, m_textRange.BoundLeft + m_textRange.BoundWidth, m_textRange.BoundTop + m_textRange.BoundHeight);
316304
//// Test
317305

318306
if (equation.m_shape != null)
319307
{
320-
equation.m_shape.Left = m_textRange.BoundLeft + 2 * m_textRange.BoundWidth;
321-
equation.m_shape.Top = m_textRange.BoundTop + height - (1.0f - offset) * equation.m_shape.Height;
308+
equation.m_shape.Left = m_textRange.BoundLeft + m_textRange.BoundWidth;
309+
equation.m_shape.Top = m_textRange.BoundTop + m_textRange.BoundHeight - equation.m_shape.Height; // - offset * equation.m_shape.Height;
322310
}
323311
}
324312
}

0 commit comments

Comments
 (0)