Skip to content

Commit 84cdbfb

Browse files
authored
Merge pull request #20 from Amomum/master
Added option `array-contents-only`
2 parents 3e3f198 + 91060b5 commit 84cdbfb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Pixie/CommandLineOptions/ParseOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ namespace Pixie
55
[Verb("parse", HelpText = "parses a pattern filled with graphical font to a byte array")]
66
internal class ParseOptions : CommonOptions
77
{
8-
[Option('s', "single-array", HelpText = "place all characters to single array")]
8+
[Option('s', "single-array", HelpText = "place all characters into single array")]
99
public bool SingleArray { get; set; }
10+
11+
[Option( 'a', "array-contents-only", HelpText = "Omit single array name and curly braces, only produce array contents")]
12+
public bool ArrayContentOnly { get; set; }
1013

1114
[Value(0, HelpText = "image containing font bitmap", MetaName = "file name", Required = true)]
1215
public string InputFileName { get; set; }

Pixie/OutputFileFormatter.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ static class OutputFileFormatter
2020
/// <param name="symbols">byte[] representation of symbols</param>
2121
/// <param name="fileName">path to the file to create</param>
2222
/// <param name="singleArray">shall output be written to single array or one array per symbol</param>
23-
public static void WriteOutput(List<byte[]> symbols, string fileName, bool singleArray = false)
23+
/// <param name="contentOnly">for single array: output will be just array contents, without name or curly braces</param>
24+
public static void WriteOutput(List<byte[]> symbols, string fileName, bool singleArray = false, bool contentOnly = false)
2425
{
2526
try
2627
{
@@ -45,8 +46,15 @@ public static void WriteOutput(List<byte[]> symbols, string fileName, bool singl
4546
var totalLength = (from s in symbols
4647
select s.Length).Sum();
4748

48-
writer.Write($"unsigned char c[{totalLength}] = \n");
49-
writer.Write("{\n ");
49+
if (contentOnly == false)
50+
{
51+
writer.Write($"unsigned char c[{totalLength}] = \n");
52+
writer.Write("{\n ");
53+
}
54+
else
55+
{
56+
writer.Write(" ");
57+
}
5058

5159
int elementCounter = 0;
5260

@@ -64,7 +72,12 @@ public static void WriteOutput(List<byte[]> symbols, string fileName, bool singl
6472
}
6573
}
6674
}
67-
writer.Write("\n};");
75+
76+
if (contentOnly == false)
77+
{
78+
writer.Write("\n};");
79+
}
80+
6881
writer.WriteLine("\n");
6982
}
7083
else

Pixie/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static ErrorCode ParseFontImage(ParseOptions options)
7676
var bitmap = new Bitmap(Image.FromFile(options.InputFileName));
7777
var mapper = new PixelMapper(bitmap, Settings);
7878
var map = mapper.MapPixels(options.SkipHeaders);
79-
OutputFileFormatter.WriteOutput(map, options.OutputFileName, options.SingleArray);
79+
OutputFileFormatter.WriteOutput(map, options.OutputFileName, options.SingleArray, options.ArrayContentOnly);
8080
}
8181
catch (Exception e)
8282
{

0 commit comments

Comments
 (0)