Skip to content

Height added #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed ImageMultiplier.ImageMultiplier_1.3.5.mpack
Binary file not shown.
Empty file modified ImageMultiplier.sln
100644 → 100755
Empty file.
58 changes: 25 additions & 33 deletions ImageMultiplier/ImageMultiplier.csproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{7DBEB09D-BB9F-4D92-A141-A009135475EF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<ProjectTypeGuids>{86F6BF2A-E449-4B3E-813B-9ACC37E5545F};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{1A1D66F4-8ACE-48A2-8798-F507D4750DF8}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>ImageMultiplier</RootNamespace>
Expand Down Expand Up @@ -31,60 +32,47 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="MonoDevelop.Core">
<Package>/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Core.dll</Package>
</Reference>
<Reference Include="MonoDevelop.Ide">
<Package>/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/MonoDevelop.Ide.dll</Package>
</Reference>
<Reference Include="Mono.TextEditor">
<Package>/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/Mono.TextEditor.dll</Package>
</Reference>
<Reference Include="gtk-sharp" />
<Reference Include="glib-sharp" />
<Reference Include="gdk-sharp" />
<Reference Include="pango-sharp" />
<Reference Include="Mono.Cairo" />
<Reference Include="Svg">
<HintPath>..\packages\Svg.1.7.0\lib\Svg.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Drawing" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Svg">
<HintPath>..\packages\Svg.2.1.0\lib\Svg.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.Cecil">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Cecil.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.CSharp">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.CSharp.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.dll</HintPath>
</Reference>
<Reference Include="Mono.Addins">
<HintPath>..\packages\Mono.Addins.1.2\lib\net40\Mono.Addins.dll</HintPath>
<Reference Include="ICSharpCode.NRefactory.Xml">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Xml.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.Cecil">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.Cecil.dll</HintPath>
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.CSharp">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.CSharp.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.Xml">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.Xml.dll</HintPath>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AddinInfo.cs" />
<Compile Include="ThreadAsyncOperation.cs" />
<Compile Include="ImageMultiplierGenerator.cs" />
<Compile Include="OutputSpecifier.cs" />
<Compile Include="ProcessSpecifier.cs" />
Expand All @@ -96,8 +84,12 @@
<EmbeddedResource Include="Manifest.addin.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="addin.info">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MonoDevelop.Addins.0.3.3\build\net40\MonoDevelop.Addins.targets" Condition="Exists('..\packages\MonoDevelop.Addins.0.3.3\build\net40\MonoDevelop.Addins.targets')" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
Expand Down
Empty file modified ImageMultiplier/ImageMultiplier.xft.xml
100644 → 100755
Empty file.
182 changes: 93 additions & 89 deletions ImageMultiplier/ImageMultiplierGenerator.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,99 +11,103 @@
using Svg.Transforms;
using Newtonsoft.Json;
using System.Collections.Generic;

using System.Threading.Tasks;

namespace ImageMultiplier
{
public class ImageMultiplierGenerator : ISingleFileCustomTool
{
public IAsyncOperation Generate(IProgressMonitor monitor, ProjectFile featureFile,
{


public async Task Generate(ProgressMonitor monitor, ProjectFile featureFile,
SingleFileCustomToolResult result)
{
return new ThreadAsyncOperation(() => {

// This is the project directory containing the .imfl file
string dir = System.IO.Path.GetDirectoryName(featureFile.FilePath);
monitor.Log.WriteLine("Creating images for " + featureFile.FilePath);

var processor = new ImageProcessor(monitor, result);

var lines = System.IO.File.ReadLines(featureFile.FilePath);
int lineNumber = 0;
var outputSpecifiers = new List<OutputSpecifier>();
foreach (var line in lines)
{
lineNumber++;
if (String.IsNullOrWhiteSpace(line)) continue;
if (line.StartsWith("#")) continue;

//monitor.Log.WriteLine("Interpreting " + line);

try
{
// Slight hack ...
if (line.Contains("type:"))
{
var ts = JsonConvert.DeserializeObject<OutputSpecifier>(line);
if (ts != null)
{
string testPath = processor.GetFullOutputPath(dir, ts, "test.svg");
var directory = Path.GetDirectoryName(testPath);
if (!Directory.Exists(directory))
{
string shortDirectory = Path.GetDirectoryName(string.Format(ts.path, "x.png"));
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err17", "Directory not found " + shortDirectory));
}
else
{
outputSpecifiers.Add(ts);
monitor.Log.WriteLine("Added output specifier " + line);
}
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse output specifier"));
}
}
else if (line.Contains("process:"))
{
var ps = JsonConvert.DeserializeObject<ProcessSpecifier>(line);
if (ps != null)
{
// Process output
var subdir = Path.GetDirectoryName(ps.process);
var searchPattern = Path.GetFileName(ps.process);
var inputDirectory = Path.Combine(dir, subdir);

if (Directory.Exists(inputDirectory))
{
var outputters = outputSpecifiers.Where (s => [email protected] (s.type));
processor.Process(dir, Directory.GetFiles (inputDirectory, searchPattern), outputters, lineNumber);
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err17", "Directory not found " + subdir));
}

}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse process specifier"));
}
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse this line"));
}
}
catch (Exception ex)
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err1", ex.ToString()));
}
}

result.GeneratedFilePath = "";

}, result);
{

await Task.Run(() =>
{
// This is the project directory containing the .imfl file
string dir = System.IO.Path.GetDirectoryName(featureFile.FilePath);
monitor.Log.WriteLine("Creating images for " + featureFile.FilePath);

var processor = new ImageProcessor(monitor, result);

var lines = System.IO.File.ReadLines(featureFile.FilePath);
int lineNumber = 0;
var outputSpecifiers = new List<OutputSpecifier>();
foreach (var line in lines)
{
lineNumber++;
if (String.IsNullOrWhiteSpace(line)) continue;
if (line.StartsWith("#")) continue;

//monitor.Log.WriteLine("Interpreting " + line);

try
{
// Slight hack ...
if (line.Contains("type:"))
{
var ts = JsonConvert.DeserializeObject<OutputSpecifier>(line);
if (ts != null)
{
string testPath = processor.GetFullOutputPath(dir, ts, "test.svg");
var directory = Path.GetDirectoryName(testPath);
if (!Directory.Exists(directory))
{
string shortDirectory = Path.GetDirectoryName(string.Format(ts.path, "x.png"));
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err17", "Directory not found " + shortDirectory));
}
else
{
outputSpecifiers.Add(ts);
monitor.Log.WriteLine("Added output specifier " + line);
}
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse output specifier"));
}
}
else if (line.Contains("process:"))
{
var ps = JsonConvert.DeserializeObject<ProcessSpecifier>(line);
if (ps != null)
{
// Process output
var subdir = Path.GetDirectoryName(ps.process);
var searchPattern = Path.GetFileName(ps.process);
var inputDirectory = Path.Combine(dir, subdir);

if (Directory.Exists(inputDirectory))
{
var outputters = outputSpecifiers.Where(s => [email protected](s.type));
processor.Process(dir, Directory.GetFiles(inputDirectory, searchPattern), outputters, lineNumber);
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err17", "Directory not found " + subdir));
}

}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse process specifier"));
}
}
else
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err2", "Could not parse this line"));
}
}
catch (Exception ex)
{
result.Errors.Add(new CompilerError(featureFile.FilePath, lineNumber, 1, "Err1", ex.ToString()));
}
}

result.GeneratedFilePath = "";
});

}


Expand Down
1 change: 1 addition & 0 deletions ImageMultiplier/ImageMultiplierSyntax.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Word>process</Word>
<Word>type</Word>
<Word>width</Word>
<Word>height</Word>
<Word>color</Word>
<Word>path</Word>
<Word>as</Word>
Expand Down
15 changes: 9 additions & 6 deletions ImageMultiplier/ImageProcessor.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace ImageMultiplier
/// </summary>
public class ImageProcessor
{
private readonly IProgressMonitor monitor;
private readonly ProgressMonitor monitor;
private readonly SingleFileCustomToolResult result;

public ImageProcessor (IProgressMonitor monitor, SingleFileCustomToolResult result)
public ImageProcessor (ProgressMonitor monitor, SingleFileCustomToolResult result)
{
this.monitor = monitor;
this.result = result;
Expand Down Expand Up @@ -48,12 +48,12 @@ public void Process (string dir, IEnumerable<string> svgFiles, IEnumerable<Outpu
foreach (var outputter in outputters)
{
string formattedPath = GetFullOutputPath (dir, outputter, svgFile);
ProcessOneFile (inputInfo, svgFile, formattedPath, outputter.width, lineNumber);
ProcessOneFile (inputInfo, svgFile, formattedPath, outputter.width,outputter.height==0?outputter.width:outputter.height , lineNumber,outputter.color);
};
}
}

private void ProcessOneFile(FileInfo inputInfo, string svgFile, string outputPath, int width, int lineNumber)
private void ProcessOneFile(FileInfo inputInfo, string svgFile, string outputPath, int width, int height, int lineNumber,string hexColor)
{
try
{
Expand Down Expand Up @@ -83,8 +83,11 @@ private void ProcessOneFile(FileInfo inputInfo, string svgFile, string outputPat
}

// Wipe out any size information
svgDocument.Height = new SvgUnit(SvgUnitType.Pixel, width);
svgDocument.Height = new SvgUnit(SvgUnitType.Pixel, height);
svgDocument.Width = new SvgUnit(SvgUnitType.Pixel, width);
if(!string.IsNullOrEmpty(hexColor)){
svgDocument.Color = new SvgColourServer(System.Drawing.ColorTranslator.FromHtml(hexColor));
}

// Change the default color
// TODO: This is not yet working
Expand All @@ -98,7 +101,7 @@ private void ProcessOneFile(FileInfo inputInfo, string svgFile, string outputPat
// }
// monitor.Log.WriteLine("Custom attributes style = " + svgDocument.CustomAttributes["style"]);

using (var bb = new System.Drawing.Bitmap(width, width))
using (var bb = new System.Drawing.Bitmap(width, height))
{
svgDocument.Draw(bb);
bb.Save(outputPath, ImageFormat.Png);
Expand Down
Empty file modified ImageMultiplier/Manifest.addin.xml
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions ImageMultiplier/OutputSpecifier.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class OutputSpecifier
/// <value>The width.</value>
public int width { get; set; }

/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>The height.</value>
public int height { get; set; }
/// <summary>
/// Not used yet, but will allow recoloring of SVG icons
/// </summary>
Expand Down
Empty file modified ImageMultiplier/ProcessSpecifier.cs
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion ImageMultiplier/Properties/AddinInfo.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[assembly:Addin (
"ImageMultiplier",
Namespace = "ImageMultiplier",
Version = "1.3.6"
Version = "1.3.9"
)]

[assembly:AddinName ("ImageMultiplier")]
Expand Down
Empty file modified ImageMultiplier/Properties/AssemblyInfo.cs
100644 → 100755
Empty file.
Empty file modified ImageMultiplier/Properties/ImageMultiplier.addin.xml
100644 → 100755
Empty file.
Loading