Skip to content

Commit

Permalink
output format in scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
strawberryfield committed Apr 3, 2022
1 parent 9180432 commit 4e8dbde
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 23 deletions.
6 changes: 1 addition & 5 deletions Common/Engines/BaseBuilderEngine.cs
Expand Up @@ -116,10 +116,6 @@ public override void SetJsonParams(string json)
/// Does the dirty work
/// </summary>
/// <returns>Image to print</returns>
public override MagickImage GetResult(bool quiet)
{
img = new(fmt);
return base.GetResult(quiet);
}
public override MagickImage GetResult(bool quiet) => base.GetResult(quiet);

}
12 changes: 10 additions & 2 deletions Common/Engines/BaseEngine.cs
Expand Up @@ -44,6 +44,7 @@ public int Dpi
{
_dpi = value;
fmt = new(_dpi);
img = new(fmt);
}
}
/// <summary>
Expand Down Expand Up @@ -107,7 +108,7 @@ public string Script
/// <summary>
/// Storage for the instantiated Script object
/// </summary>
protected object ScriptInstance { get; set; }
protected object ScriptInstance { get; set; }

#endregion

Expand Down Expand Up @@ -200,7 +201,14 @@ public void SetBaseJsonParams()
/// </summary>
/// <param name="quiet">suppress messages when running</param>
/// <returns>Image to print</returns>
public virtual MagickImage GetResult(bool quiet) => null;
public virtual MagickImage GetResult(bool quiet)
{
if (CustomCode != null)
{
ScriptInstance = Compiler.New(CustomCode, this);
}
return null;
}

/// <summary>
/// Writes exif infos on image
Expand Down
11 changes: 9 additions & 2 deletions Common/Engines/CreditCardEngine.cs
Expand Up @@ -184,9 +184,16 @@ public override void SetJsonParams(string json)
/// <returns>Image to print</returns>
public override MagickImage GetResult(bool quiet)
{
img = new(fmt);

MagickImage final = img.FineArt10x15_v();
if (ScriptInstance != null)
{
var f = Compiler.Run(ScriptInstance, "OutputImage", null);
if (f != null)
{
final = (MagickImage)f;
}
}

MagickImage front = Get(FilesList[0], quiet);
int bordertop = final.Height / 2 - front.Height;
int borderleft = (final.Width - front.Width) / 2;
Expand Down
20 changes: 14 additions & 6 deletions Common/Engines/MontaggioDorsiEngine.cs
Expand Up @@ -95,14 +95,18 @@ public override void SetJsonParams(string json)
/// <returns></returns>
public override MagickImage GetResult(bool quiet)
{
if (CustomCode != null)
_ = base.GetResult(quiet);

MagickImage final = PaperFormat == PaperFormats.Medium ? img.InCartha15x20_o() : img.InCartha20x27_o();
if (ScriptInstance != null)
{
ScriptInstance = Compiler.New(CustomCode, this);
var f = Compiler.Run(ScriptInstance, "OutputImage", null);
if(f != null)
{
final = (MagickImage)f;
}
}

img = new(fmt);

MagickImage final = PaperFormat == PaperFormats.Medium ? img.InCartha15x20_o() : img.InCartha20x27_o();
MagickImageCollection imagesV = new();
MagickImageCollection imagesO = new();

Expand Down Expand Up @@ -185,7 +189,11 @@ private int LoadImages(int n, int counter, MagickImageCollection dest, bool quie

if (ScriptInstance != null)
{
image = (MagickImage)Compiler.Run(ScriptInstance, "ProcessOnLoad", new object[] { image });
var im = Compiler.Run(ScriptInstance, "ProcessOnLoad", new object[] { image });
if (im != null)
{
image = (MagickImage)im;
}
}

MagickImage dorso = Utils.RotateResizeAndFill(image, orientation, FillColor);
Expand Down
20 changes: 14 additions & 6 deletions Common/Engines/MontaggioFotoEngine.cs
Expand Up @@ -126,15 +126,19 @@ public override void SetJsonParams(string json)
/// <returns></returns>
public MagickImage GetResult(bool quiet, int i)
{
if (CustomCode != null)
_ = base.GetResult(quiet);

MagickImage final = img.FineArt10x15_o();
if (ScriptInstance != null)
{
ScriptInstance = Compiler.New(CustomCode, this);
var f = Compiler.Run(ScriptInstance, "OutputImage", null);
if (f != null)
{
final = (MagickImage)f;
}
}

img = new(fmt);
MagickImage final = img.FineArt10x15_o();
MagickImage img1 = Get(FilesList[i], quiet);

MagickImage img2;
i++;
if (i < FilesList.Count)
Expand Down Expand Up @@ -183,7 +187,11 @@ private MagickImage Get(string filename, bool quiet)

if (ScriptInstance != null)
{
image = (MagickImage)Compiler.Run(ScriptInstance, "ProcessOnLoad", new object[] { image });
var i = Compiler.Run(ScriptInstance, "ProcessOnLoad", new object[] { image });
if(i != null)
{
image = (MagickImage)i;
}
}

MagickImage img1 = Utils.RotateResizeAndFill(image,
Expand Down
6 changes: 6 additions & 0 deletions Common/Scripting/BaseScripting.cs
Expand Up @@ -33,6 +33,12 @@ internal class BaseScripting : IScripting
/// Custom class initialization
/// </summary>
public void Init() { }
/// <summary>
/// Image for final output
/// </summary>
/// <returns></returns>
public MagickImage OutputImage() => null;
";

public virtual string WrapScript(string script, string engine) => $@"{Compiler.Usings}
Expand Down
8 changes: 7 additions & 1 deletion Common/Scripting/Compiler.cs
Expand Up @@ -129,11 +129,17 @@ public static object Run(Assembly assembly, string ClassName, string Method, obj
public static object Run(object obj, string Method, object[] args)
{
Type type = obj.GetType();
return type.InvokeMember(Method,
if (type != null && type.GetMethod(Method) != null)
{

return type.InvokeMember(Method,
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
obj,
args);
}
else
return null;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion build_tools/publish.cmd
Expand Up @@ -33,7 +33,7 @@ set candle="%wix%candle.exe"
set light="%wix%light.exe"
set WixUtils="%wix%WixUtilExtension.dll"

set version=22.03.26
set version=22.04.03

@del /S /Q %build%
@del /Q %bin%%pkgname%*.*
Expand Down
12 changes: 12 additions & 0 deletions docs/Cartella.1
Expand Up @@ -197,6 +197,14 @@ set output dir/filename
.P
.PD
extra info for user scripts
.PD 0
.P
.PD
Text can be stored in a file instead of a string
.PD 0
.P
.PD
The file must be referenced as `\[at]filename'
.PP
\f[B]\[en]nobanner\f[R] :
.PD 0
Expand Down Expand Up @@ -349,6 +357,10 @@ These are the signatures of the scriptable methods:
/// Custom class initialization ///
.PP
public void Init() { }
///
/// Image for final output ///
.PP
/// public MagickImage OutputImage() => null;
.PP
\[ti]\[ti]\[ti]
.SH COPYRIGHT
Expand Down
12 changes: 12 additions & 0 deletions docs/CreditCard.1
Expand Up @@ -167,6 +167,14 @@ set output dir/filename
.P
.PD
extra info for user scripts
.PD 0
.P
.PD
Text can be stored in a file instead of a string
.PD 0
.P
.PD
The file must be referenced as `\[at]filename'
.PP
\f[B]\[en]nobanner\f[R] :
.PD 0
Expand Down Expand Up @@ -315,6 +323,10 @@ These are the signatures of the scriptable methods:
/// Custom class initialization ///
.PP
public void Init() { }
///
/// Image for final output ///
.PP
/// public MagickImage OutputImage() => null;
.PP
\[ti]\[ti]\[ti]
.SH COPYRIGHT
Expand Down
12 changes: 12 additions & 0 deletions docs/MontaggioDorsi.1
Expand Up @@ -104,6 +104,14 @@ set output dir/filename
.P
.PD
extra info for user scripts
.PD 0
.P
.PD
Text can be stored in a file instead of a string
.PD 0
.P
.PD
The file must be referenced as `\[at]filename'
.PP
\f[B]\[en]nobanner\f[R] :
.PD 0
Expand Down Expand Up @@ -243,6 +251,10 @@ These are the signatures of the scriptable methods:
.PP
public void Init() { }
///
/// Image for final output ///
.PP
/// public MagickImage OutputImage() => null;
///
/// Preprocesses the loaded image ///
.PP
/// The loaded image /// The Processed image public MagickImage
Expand Down
12 changes: 12 additions & 0 deletions docs/MontaggioFoto.1
Expand Up @@ -114,6 +114,14 @@ set output dir/filename
.P
.PD
extra info for user scripts
.PD 0
.P
.PD
Text can be stored in a file instead of a string
.PD 0
.P
.PD
The file must be referenced as `\[at]filename'
.PP
\f[B]\[en]nobanner\f[R] :
.PD 0
Expand Down Expand Up @@ -256,6 +264,10 @@ These are the signatures of the scriptable methods:
.PP
public void Init() { }
///
/// Image for final output ///
.PP
/// public MagickImage OutputImage() => null;
///
/// Preprocesses the loaded image ///
.PP
/// The loaded image /// The Processed image public MagickImage
Expand Down
12 changes: 12 additions & 0 deletions docs/Scatola.1
Expand Up @@ -194,6 +194,14 @@ set output dir/filename
.P
.PD
extra info for user scripts
.PD 0
.P
.PD
Text can be stored in a file instead of a string
.PD 0
.P
.PD
The file must be referenced as `\[at]filename'
.PP
\f[B]\[en]nobanner\f[R] :
.PD 0
Expand Down Expand Up @@ -346,6 +354,10 @@ These are the signatures of the scriptable methods:
/// Custom class initialization ///
.PP
public void Init() { }
///
/// Image for final output ///
.PP
/// public MagickImage OutputImage() => null;
.PP
\[ti]\[ti]\[ti]
.SH COPYRIGHT
Expand Down
2 changes: 2 additions & 0 deletions docs/help_cartella.txt
Expand Up @@ -37,6 +37,8 @@ Options:
The file must be referenced as '@filename'
-o, --output=VALUE set output dir/filename
--tag=VALUE extra info for user scripts
Text can be stored in a file instead of a string
The file must be referenced as '@filename'
--nobanner suppress the banner
-h, --help show this message and exit
--helpjson show json parameters template
Expand Down
2 changes: 2 additions & 0 deletions docs/help_creditcard.txt
Expand Up @@ -35,6 +35,8 @@ Options:
The file must be referenced as '@filename'
-o, --output=VALUE set output dir/filename
--tag=VALUE extra info for user scripts
Text can be stored in a file instead of a string
The file must be referenced as '@filename'
--nobanner suppress the banner
-h, --help show this message and exit
--helpjson show json parameters template
Expand Down
2 changes: 2 additions & 0 deletions docs/help_montaggiodorsi.txt
Expand Up @@ -22,6 +22,8 @@ Options:
The file must be referenced as '@filename'
-o, --output=VALUE set output dir/filename
--tag=VALUE extra info for user scripts
Text can be stored in a file instead of a string
The file must be referenced as '@filename'
--nobanner suppress the banner
-h, --help show this message and exit
--helpjson show json parameters template
Expand Down
2 changes: 2 additions & 0 deletions docs/help_montaggiofoto.txt
Expand Up @@ -23,6 +23,8 @@ Options:
The file must be referenced as '@filename'
-o, --output=VALUE set output dir/filename
--tag=VALUE extra info for user scripts
Text can be stored in a file instead of a string
The file must be referenced as '@filename'
--nobanner suppress the banner
-h, --help show this message and exit
--helpjson show json parameters template
Expand Down
2 changes: 2 additions & 0 deletions docs/help_scatola.txt
Expand Up @@ -37,6 +37,8 @@ Options:
The file must be referenced as '@filename'
-o, --output=VALUE set output dir/filename
--tag=VALUE extra info for user scripts
Text can be stored in a file instead of a string
The file must be referenced as '@filename'
--nobanner suppress the banner
-h, --help show this message and exit
--helpjson show json parameters template
Expand Down
6 changes: 6 additions & 0 deletions docs/helpscript_Cartella.txt
Expand Up @@ -9,4 +9,10 @@ Copyright (c) 2020-2022 Roberto Ceccarelli - Casasoft
/// </summary>
public void Init() { }

/// <summary>
/// Image for final output
/// </summary>
/// <returns></returns>
public MagickImage OutputImage() => null;

-----
6 changes: 6 additions & 0 deletions docs/helpscript_CreditCard.txt
Expand Up @@ -9,4 +9,10 @@ Copyright (c) 2020-2022 Roberto Ceccarelli - Casasoft
/// </summary>
public void Init() { }

/// <summary>
/// Image for final output
/// </summary>
/// <returns></returns>
public MagickImage OutputImage() => null;

-----
6 changes: 6 additions & 0 deletions docs/helpscript_MontaggioDorsi.txt
Expand Up @@ -9,6 +9,12 @@ Copyright (c) 2020-2022 Roberto Ceccarelli - Casasoft
/// </summary>
public void Init() { }

/// <summary>
/// Image for final output
/// </summary>
/// <returns></returns>
public MagickImage OutputImage() => null;

/// <summary>
/// Preprocesses the loaded image
/// </summary>
Expand Down

0 comments on commit 4e8dbde

Please sign in to comment.