Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
clown committed Dec 17, 2018
1 parent e2b0ab8 commit 337ba3b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 56 deletions.
46 changes: 16 additions & 30 deletions Libraries/Ghostscript/Sources/Converter.cs
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/* ------------------------------------------------------------------------- */
using Cube.Collections.Mixin;
using Cube.FileSystem;
using Cube.Generics;
using Cube.Log;
Expand Down Expand Up @@ -301,26 +302,22 @@ protected Converter(Format format, IO io, IEnumerable<Format> supported)
/// <returns>Collection of arguments.</returns>
///
/* ----------------------------------------------------------------- */
protected virtual IEnumerable<Argument> OnCreateArguments()
protected virtual IEnumerable<Argument> OnCreateArguments() => new []
{
var args = new List<Argument>
{
Format.GetArgument(),
new Argument('d', "SAFER"),
new Argument('d', "BATCH"),
new Argument('d', "NOPAUSE"),
CreateQuiet(),
CreateLog(),
CreateResources(),
CreateFonts(),
CreateResolution(),
Paper.GetArgument(),
Orientation.GetArgument(),
}
.Concat(Options);

return Trim(args);
Format.GetArgument(),
new Argument('d', "SAFER"),
new Argument('d', "BATCH"),
new Argument('d', "NOPAUSE"),
CreateQuiet(),
CreateLog(),
CreateResources(),
CreateFonts(),
CreateResolution(),
Paper.GetArgument(),
Orientation.GetArgument(),
}
.Concat(Options)
.Compact();

/* ----------------------------------------------------------------- */
///
Expand All @@ -335,7 +332,7 @@ protected virtual IEnumerable<Argument> OnCreateArguments()
///
/* ----------------------------------------------------------------- */
protected virtual IEnumerable<Code> OnCreateCodes() =>
Trim(new[] { Orientation.GetCode() });
new[] { Orientation.GetCode() }.Compact();

#endregion

Expand Down Expand Up @@ -443,17 +440,6 @@ private IEnumerable<Argument> CreateCodes()
/* ----------------------------------------------------------------- */
private Argument CreateResolution() => new Argument('r', Resolution);

/* ----------------------------------------------------------------- */
///
/// Trim
///
/// <summary>
/// Removes null objects from the specified collection.
/// </summary>
///
/* ----------------------------------------------------------------- */
private IEnumerable<T> Trim<T>(IEnumerable<T> src) => src.OfType<T>();

/* ----------------------------------------------------------------- */
///
/// Invoke
Expand Down
18 changes: 4 additions & 14 deletions Libraries/Ghostscript/Sources/DocumentConverter.cs
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/* ------------------------------------------------------------------------- */
using Cube.Collections.Mixin;
using Cube.FileSystem;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -179,7 +180,7 @@ public class DocumentConverter : Converter
/* ----------------------------------------------------------------- */
protected override IEnumerable<Code> OnCreateCodes() =>
base.OnCreateCodes()
.Concat(Trim(new[] { CreateEmbedFontsCode() }));
.Concat(new[] { CreateEmbedFontsCode() }.Compact());

/* ----------------------------------------------------------------- */
///
Expand Down Expand Up @@ -214,7 +215,7 @@ private IEnumerable<Argument> CreateFontArguments()
/// </remarks>
///
/* ----------------------------------------------------------------- */
private IEnumerable<Argument> CreateImageArguments() => Trim(new[]
private IEnumerable<Argument> CreateImageArguments() => new[]
{
new Argument("ColorImageResolution", Resolution),
new Argument("GrayImageResolution", Resolution),
Expand All @@ -234,7 +235,7 @@ private IEnumerable<Argument> CreateFontArguments()
Compression.GetArgument("ColorImageFilter"),
Compression.GetArgument("GrayImageFilter"),
Compression.GetArgument("MonoImageFilter"),
});
}.Compact();

/* ----------------------------------------------------------------- */
///
Expand Down Expand Up @@ -264,17 +265,6 @@ private IEnumerable<Argument> CreateFontArguments()
Resolution < 1200 ? 1200 :
Resolution;

/* ----------------------------------------------------------------- */
///
/// Trim
///
/// <summary>
/// Removes null objects from the specified collection.
/// </summary>
///
/* ----------------------------------------------------------------- */
private IEnumerable<T> Trim<T>(IEnumerable<T> src) => src.OfType<T>();

#endregion
}
}
14 changes: 2 additions & 12 deletions Libraries/Ghostscript/Sources/PdfConverter.cs
Expand Up @@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
/* ------------------------------------------------------------------------- */
using Cube.Collections.Mixin;
using Cube.FileSystem;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -132,7 +133,7 @@ public class PdfConverter : DocumentConverter
/* ----------------------------------------------------------------- */
protected override IEnumerable<Argument> OnCreateArguments() =>
base.OnCreateArguments()
.Concat(Trim(new[] { CreateVersion(), CreateFastWebView() }));
.Concat(new[] { CreateVersion(), CreateFastWebView() }.Compact());

/* ----------------------------------------------------------------- */
///
Expand Down Expand Up @@ -160,17 +161,6 @@ public class PdfConverter : DocumentConverter
private Argument CreateFastWebView() =>
Linearization ? new Argument('d', "FastWebView") : null;

/* ----------------------------------------------------------------- */
///
/// Trim
///
/// <summary>
/// Removes null objects from the specified collection.
/// </summary>
///
/* ----------------------------------------------------------------- */
private IEnumerable<T> Trim<T>(IEnumerable<T> src) => src.OfType<T>();

#endregion
}
}

0 comments on commit 337ba3b

Please sign in to comment.