Skip to content

Added Image scaling and width feature. #9

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 6 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
4 changes: 4 additions & 0 deletions ImageMultiplier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D0B6B14-A4E6-4CFE-BE9A-4C63865A7C4D}"
ProjectSection(SolutionItems) = preProject
addin-project.xml = addin-project.xml
README.md = README.md
EndProjectSection
EndProject
Global
Expand All @@ -21,4 +22,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 1.3.7
EndGlobalSection
EndGlobal
60 changes: 28 additions & 32 deletions ImageMultiplier/ImageMultiplier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{7DBEB09D-BB9F-4D92-A141-A009135475EF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<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>
<AssemblyName>ImageMultiplier</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<ReleaseVersion>1.3.7</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -20,65 +22,56 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<DocumentationFile>bin\Release\ImageMultiplier.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<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>
<Reference Include="Mono.Addins">
<HintPath>..\packages\Mono.Addins.1.2\lib\net40\Mono.Addins.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\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>
</Reference>
<Reference Include="Mono.Cecil.Pdb">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<Reference Include="Svg">
<HintPath>..\packages\Svg.2.0.0\lib\Svg.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks">
<HintPath>..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.dll</HintPath>
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\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\ICSharpCode.NRefactory.5.5.1\lib\Net40\ICSharpCode.NRefactory.Cecil.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.NRefactory.CSharp">
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.0\lib\Net40\ICSharpCode.NRefactory.CSharp.dll</HintPath>
<HintPath>..\packages\ICSharpCode.NRefactory.5.5.1\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>
<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.6.1\lib\net45\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb">
<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.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks">
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -89,6 +82,8 @@
<Compile Include="OutputSpecifier.cs" />
<Compile Include="ProcessSpecifier.cs" />
<Compile Include="ImageProcessor.cs" />
<Compile Include="iOSImageSet.cs" />
<Compile Include="iOSImageSetImage.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ImageMultiplier.xft.xml" />
Expand All @@ -98,7 +93,8 @@
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MonoDevelop.Addins.0.2.3\build\net40\MonoDevelop.Addins.targets" Condition="Exists('..\packages\MonoDevelop.Addins.0.2.3\build\net40\MonoDevelop.Addins.targets')" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>
</Project>
142 changes: 59 additions & 83 deletions ImageMultiplier/ImageMultiplierGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,98 +14,74 @@

namespace ImageMultiplier
{
public class ImageMultiplierGenerator : ISingleFileCustomTool
{
public IAsyncOperation Generate(IProgressMonitor monitor, ProjectFile featureFile,
SingleFileCustomToolResult result)
{
return new ThreadAsyncOperation(() => {
public class ImageMultiplierGenerator : ISingleFileCustomTool
{
public IAsyncOperation Generate (IProgressMonitor 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);
// 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 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;
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);
//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);
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);
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));
}
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()));
}
}
} 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.GeneratedFilePath = "";

}, result);
}
}, result);
}


}
}
}
5 changes: 5 additions & 0 deletions ImageMultiplier/ImageMultiplierSyntax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@
<Word>process</Word>
<Word>type</Word>
<Word>width</Word>
<Word>height</Word>
<Word>scaling</Word>
<Word>color</Word>
<Word>path</Word>
<Word>as</Word>
<Word>ios_idiom</Word>
<Word>ios_scale</Word>
<Word>ios_subtype</Word>
</Keywords>

<Keywords color="Punctuation">
Expand Down
Loading