diff --git a/Yavsc/Helpers/TeXHelpers.cs b/Yavsc/Helpers/TeXHelpers.cs index 0c1d82e9..3f5860f9 100644 --- a/Yavsc/Helpers/TeXHelpers.cs +++ b/Yavsc/Helpers/TeXHelpers.cs @@ -10,6 +10,59 @@ using Microsoft.AspNet.Mvc.ViewFeatures; namespace Yavsc.Helpers { + public class TeXString { + + public class Replacement { + string target; + string replacement; + public Replacement(string target, string replacement){ + this.target=target; + this.replacement=replacement; + } + public string Execute(string source) + { + return source.Replace(target,replacement); + } + } + + public readonly static Replacement[] SpecialCharsToCommands = + { + new Replacement("<","\\textless"), + new Replacement(">","\\textgreater"), + new Replacement("©","\\copyright"), + new Replacement("®","\\textregistered"), + new Replacement("\\","\\textbackslash"), + new Replacement("™","\\texttrademark"), + new Replacement("¶","\\P"), + new Replacement("|","\\textbar"), + new Replacement("%","\\%"), + new Replacement("{","\\{"), + new Replacement("}","\\}"), + new Replacement("_","\\_"), + new Replacement("#","\\#"), + new Replacement("$","\\$"), + new Replacement("_","\\_"), + new Replacement("¿","\\textquestiondown"), + new Replacement("§","\\S"), + new Replacement("£","\\pounds"), + new Replacement("&","\\&"), + new Replacement("¡","\\textexclamdown"), + new Replacement("†","\\dag"), + new Replacement("–","\\textendash") + }; + string data; + public TeXString(string str) { + data = str; + foreach (var r in SpecialCharsToCommands) { + data = r.Execute(data); + } + } + + override public string ToString() + { + return data; + } + } public static class TeXHelpers { public static string NewLinesWith(this string target, string separator) @@ -19,6 +72,13 @@ namespace Yavsc.Helpers return string.Join(separator, items); } + + public static TeXString ToTeX(string target, string lineSeparator="\n\\\\") + { + if (target==null) return null; + return new TeXString(target.NewLinesWith(lineSeparator)); + } + public static string RenderViewToString( this Controller controller, IViewEngine engine, IHttpContextAccessor httpContextAccessor, diff --git a/Yavsc/Views/Shared/Components/Estimate/Estimate_tex.cshtml b/Yavsc/Views/Shared/Components/Estimate/Estimate_tex.cshtml index 142f19cf..5f8c9d89 100644 --- a/Yavsc/Views/Shared/Components/Estimate/Estimate_tex.cshtml +++ b/Yavsc/Views/Shared/Components/Estimate/Estimate_tex.cshtml @@ -69,28 +69,28 @@ \def\FactureNum {@Model.Id.ToString()} % Numéro de facture \def\FactureAcquittee {non} % Facture acquittée : oui/non \def\FactureLieu {@proaddrn} % Lieu de l'édition de la facture -\def\FactureObjet {Facture : @Model.Title} % Objet du document +\def\FactureObjet {Facture : @TeXHelpers.ToTeX(Model.Title)} % Objet du document % Description de la facture \def\FactureDescr { - @Model.Description + @TeXHelpers.ToTeX(Model.Description) } % Infos Client -\def\ClientNom{@to.UserName} % Nom du client +\def\ClientNom{@TeXHelpers.ToTeX(to.UserName)} % Nom du client \def\ClientAdresse{ % Adresse du client @if (!string.IsNullOrWhiteSpace(PostalAddress)) { - @PostalAddress\\ } + @TeXHelpers.ToTeX(PostalAddress)\\ } @if (!string.IsNullOrWhiteSpace(to.PhoneNumber)) { - @to.PhoneNumber \\ + @TeXHelpers.ToTeX(to.PhoneNumber)\\ } - E-mail: @to.Email + E-mail: @TeXHelpers.ToTeX(to.Email) } % Liste des produits facturés : Désignation, prix @if (Model.Bill!=null) { foreach (CommandLine line in Model.Bill) { -\AjouterService{@line.Description}{@line.Count}{@line.UnitaryCost.ToString("F2",CultureInfo.InvariantCulture)} +\AjouterService{@TeXHelpers.ToTeX(line.Description)}{@line.Count}{@line.UnitaryCost.ToString("F2",CultureInfo.InvariantCulture)} } } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -106,24 +106,24 @@ \setlength{\parindent}{0pt} \renewcommand{\headrulewidth}{0pt} -\cfoot{ @if (!string.IsNullOrWhiteSpace(from.UserName)) { @from.UserName } - @if (!string.IsNullOrWhiteSpace(proaddrm)) { - @proaddrm } \newline - \small{ E-mail: @from.Email - @if (!string.IsNullOrWhiteSpace(from.PhoneNumber)) { - Téléphone fixe: @from.PhoneNumber } +\cfoot{ @TeXHelpers.ToTeX(from.UserName) @if (!string.IsNullOrWhiteSpace(proaddrm)) { - @TeXHelpers.ToTeX(proaddrm) } \newline + \small{ E-mail: @TeXHelpers.ToTeX(from.Email) @if (!string.IsNullOrWhiteSpace(from.PhoneNumber)) { - Téléphone fixe: @TeXHelpers.ToTeX(from.PhoneNumber) } } } \begin{document} % Logo de la société -@if (from.Avatar != null) { -\includegraphics{@from.Avatar} -} else { -%\includegraphics{logo.png} +@if (from.Avatar != null) { +\includegraphics{@from.Avatar} + +} else { +%\includegraphics{logo.png} + } % Nom et adresse de la société - @from.UserName \\ - @proaddrn + @TeXHelpers.ToTeX(from.UserName) \\ + @TeXHelpers.ToTeX(proaddrn) Facture n°\FactureNum