90 lines
2.3 KiB
C#
90 lines
2.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using ReportGeneration.Abstract;
|
|
using ReportGeneration.Interface;
|
|
|
|
namespace ReportGeneration.Generators.LatexInclude;
|
|
|
|
public class LatexIncludeDocumentGenerator : DocumentGeneratorBase
|
|
{
|
|
private string? _lastHeading;
|
|
private int _sectionFigCnt;
|
|
|
|
public string Path { get; }
|
|
|
|
public LatexIncludeDocumentGenerator(string name, bool overwrite = false)
|
|
: this(PrepareDir(name, overwrite))
|
|
{
|
|
}
|
|
|
|
private LatexIncludeDocumentGenerator(string name) : base($"{name}/main.tex")
|
|
{
|
|
}
|
|
|
|
private static string PrepareDir(string name, bool overwrite)
|
|
{
|
|
var path = System.IO.Path.GetFullPath(name);
|
|
if (Directory.Exists(path))
|
|
{
|
|
if (overwrite)
|
|
{
|
|
Directory.Delete(path, true);
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException($"Directory '{path}' already exists!");
|
|
}
|
|
}
|
|
|
|
Directory.CreateDirectory(path);
|
|
return path;
|
|
}
|
|
|
|
#region Writing
|
|
|
|
/// <inheritdoc />
|
|
public override IDocumentGenerator AppendHeading(int level, string text)
|
|
{
|
|
_sectionFigCnt = 0;
|
|
var heading = (level) switch
|
|
{
|
|
1 => $"\\chapter{text}",
|
|
2 => $"\\section{text}",
|
|
3 => $"\\subsection{text}",
|
|
4 => $"\\subsubsection{text}",
|
|
5 => $"\\subsubsubsection{text}",
|
|
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
|
|
};
|
|
|
|
_lastHeading = heading;
|
|
return AppendParagraph(heading);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override ITableGenerator MakeTable(int columns, Stream stream)
|
|
{
|
|
var includePath = System.IO.Path.Join(Path, $"fig_{_lastHeading}_{++_sectionFigCnt}.tex");
|
|
var file = File.Open(includePath, FileMode.CreateNew);
|
|
|
|
AppendParagraph($"\\include{includePath}");
|
|
|
|
return new LatexIncludeTableGenerator(columns, file);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override IDocumentGenerator AppendParagraph(string? text = default)
|
|
{
|
|
AppendLine(text);
|
|
AppendLine();
|
|
return this;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public override string FormatImage(string path, IBounds? bounds = default) => @$"
|
|
\begin{{figure}}[ht]
|
|
\centering
|
|
\fbox{{\includegraphics[width=.7\textwidth]{{{path}}}}}
|
|
\caption{{Ein gut für die Texterkennung geeigneter Screenshot. Die wesentlichen Inhalte weisen einen guten Kontrast zum Hintergrund auf und befinden sich in Bereichen mit gleichmäßiger Helligkeit.}}
|
|
\end{{figure}}";
|
|
} |