Started work on extracting font images from fonts and firmware
parent
985fd1688e
commit
ac785b0c6a
56
Amazfit.sln
56
Amazfit.sln
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.0
|
||||
VisualStudioVersion = 15.0.27130.2026
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchFace.Parser", "WatchFace.Parser\WatchFace.Parser.csproj", "{8D2E0224-DE7F-4EC9-AD23-9904B9D7B409}"
|
||||
EndProject
|
||||
|
@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchFace", "WatchFace\Watc
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resources", "Resources\Resources.csproj", "{EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fonts", "Fonts\Fonts.csproj", "{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FwFonts", "FwFonts\FwFonts.csproj", "{E50E8437-0511-4A94-808A-AD5F3105D060}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -69,6 +75,54 @@ Global
|
|||
{EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x64.Build.0 = Release|Any CPU
|
||||
{EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EDD55D5D-9E80-451B-AC8A-0746BA6DC6E9}.Release|x86.Build.0 = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x64.Build.0 = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}.Release|x86.Build.0 = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E50E8437-0511-4A94-808A-AD5F3105D060}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text;
|
||||
using Fonts.Models;
|
||||
using NLog;
|
||||
|
||||
namespace Fonts
|
||||
{
|
||||
public class FileReader
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static FileDescriptor Read(Stream stream)
|
||||
{
|
||||
var binaryReader = new BinaryReader(stream);
|
||||
|
||||
var signature = Encoding.ASCII.GetString(binaryReader.ReadBytes(4));
|
||||
Logger.Trace("Font signature was read:");
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
Logger.Trace("Signature: {0}", signature);
|
||||
|
||||
NewHeader header;
|
||||
switch (signature) {
|
||||
case NewHeader.ResSignature:
|
||||
header = NewHeader.ReadFrom(binaryReader);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Signature '{signature}' is no recognized.");
|
||||
}
|
||||
|
||||
Logger.Trace("Font header was read:");
|
||||
Logger.Trace("Version: {0}, BlocksCount: {1}", header.Version, header.BlocksCount);
|
||||
|
||||
var blocks = new Reader(stream).Read(header.BlocksCount);
|
||||
return new FileDescriptor
|
||||
{
|
||||
HasNewHeader = true,
|
||||
BlocksCount = header.BlocksCount,
|
||||
Version = header.Version,
|
||||
Unknown = header.Unknown,
|
||||
Blocks = blocks,
|
||||
Images = new Reader(stream).Read(blocks)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{390EAF2D-9FA8-4DC1-8D4F-EA565AD3C682}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Fonts</RootNamespace>
|
||||
<AssemblyName>Fonts</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BumpKit, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Bumpkit.1.0.2\lib\BumpKit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.12\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileReader.cs" />
|
||||
<Compile Include="Models\BlockDescriptor.cs" />
|
||||
<Compile Include="Models\FileDescriptor.cs" />
|
||||
<Compile Include="Models\NewHeader.cs" />
|
||||
<Compile Include="GlyphReader.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Reader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Utils\Utils.csproj">
|
||||
<Project>{20e6917a-be26-43d6-a2dc-0f32759c4e9b}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,37 @@
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using BumpKit;
|
||||
using Utils;
|
||||
|
||||
namespace Fonts
|
||||
{
|
||||
public class GlyphReader
|
||||
{
|
||||
private readonly BinaryReader _reader;
|
||||
|
||||
public GlyphReader(Stream stream)
|
||||
{
|
||||
_reader = new BinaryReader(stream);
|
||||
}
|
||||
|
||||
public Bitmap Read(int width, int height)
|
||||
{
|
||||
var image = new Bitmap(width, height);
|
||||
using (var context = image.CreateUnsafeContext())
|
||||
{
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
var rowBytes = _reader.ReadBytes(width / 8);
|
||||
var bitReader = new BitReader(rowBytes);
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var pixelValue = bitReader.ReadBits(1);
|
||||
var color = pixelValue == 1 ? Color.Black : Color.White;
|
||||
context.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace Fonts.Models
|
||||
{
|
||||
public class BlockDescriptor
|
||||
{
|
||||
public char StartSymbol { get; set; }
|
||||
public char EndSymbol { get; set; }
|
||||
public int Offset { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Fonts.Models
|
||||
{
|
||||
public class FileDescriptor
|
||||
{
|
||||
public bool HasNewHeader { get; set; }
|
||||
public uint? BlocksCount { get; set; }
|
||||
public uint? Unknown { get; set; }
|
||||
public byte? Version { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<BlockDescriptor> Blocks { get; set; } = new List<BlockDescriptor>();
|
||||
|
||||
[IgnoreDataMember]
|
||||
public Dictionary<char, Bitmap> Images { get; set; } = new Dictionary<char, Bitmap>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Fonts.Models
|
||||
{
|
||||
public class NewHeader
|
||||
{
|
||||
public const int HeaderSize = 0x22;
|
||||
public const string ResSignature = "NEZK";
|
||||
|
||||
public string Signature { get; protected set; } = ResSignature;
|
||||
public byte Version { get; set; }
|
||||
public ushort BlocksCount { get; set; }
|
||||
|
||||
public uint Unknown { get; set; }
|
||||
|
||||
public void WriteTo(BinaryWriter writer)
|
||||
{
|
||||
var buffer = new byte[HeaderSize];
|
||||
for (var i = 0; i < buffer.Length; i++) buffer[i] = 0xff;
|
||||
|
||||
Encoding.ASCII.GetBytes(ResSignature).CopyTo(buffer, 0);
|
||||
buffer[0x4] = Version;
|
||||
BitConverter.GetBytes(Unknown).CopyTo(buffer, 0xa);
|
||||
BitConverter.GetBytes(BlocksCount).CopyTo(buffer, 0x20);
|
||||
writer.Write(buffer);
|
||||
}
|
||||
|
||||
public static NewHeader ReadFrom(BinaryReader reader)
|
||||
{
|
||||
var buffer = reader.ReadBytes(HeaderSize);
|
||||
return new NewHeader
|
||||
{
|
||||
Signature = Encoding.ASCII.GetString(buffer, 0, 0x4),
|
||||
Version = buffer[0x4],
|
||||
Unknown = BitConverter.ToUInt32(buffer, 0xa),
|
||||
BlocksCount = BitConverter.ToUInt16(buffer, 0x20)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Fonts")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Fonts")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("390eaf2d-9fa8-4dc1-8d4f-ea565ad3c682")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using Fonts.Models;
|
||||
using NLog;
|
||||
|
||||
namespace Fonts
|
||||
{
|
||||
public class Reader
|
||||
{
|
||||
private const int BlockDescriptorLength = 6;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly BinaryReader _binaryReader;
|
||||
private readonly Stream _stream;
|
||||
|
||||
public Reader(Stream stream)
|
||||
{
|
||||
_stream = stream;
|
||||
_binaryReader = new BinaryReader(_stream);
|
||||
}
|
||||
|
||||
public List<BlockDescriptor> Read(uint blocksCount)
|
||||
{
|
||||
var descriptorsTableLength = (int) (blocksCount * BlockDescriptorLength);
|
||||
Logger.Trace("Reading font descriptors table with {0} elements ({1} bytes)",
|
||||
blocksCount, descriptorsTableLength
|
||||
);
|
||||
var descriptors = _binaryReader.ReadBytes(descriptorsTableLength);
|
||||
var blocks = new List<BlockDescriptor>();
|
||||
for (var i = 0; i < blocksCount; i++)
|
||||
{
|
||||
blocks.Add(new BlockDescriptor
|
||||
{
|
||||
StartSymbol = BitConverter.ToChar(descriptors, i * BlockDescriptorLength),
|
||||
EndSymbol = BitConverter.ToChar(descriptors, i * BlockDescriptorLength + 2),
|
||||
Offset = BitConverter.ToUInt16(descriptors, i * BlockDescriptorLength + 4)
|
||||
});
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public Dictionary<char, Bitmap> Read(List<BlockDescriptor> blocks)
|
||||
{
|
||||
var imagesOffset = _stream.Position;
|
||||
Logger.Debug("Reading {0} images...", blocks.Count);
|
||||
var images = new Dictionary<char, Bitmap>();
|
||||
for (var i = 0; i < blocks.Count; i++)
|
||||
{
|
||||
var block = blocks[i];
|
||||
var blockOffset = block.Offset;
|
||||
var realOffset = blockOffset + imagesOffset;
|
||||
Logger.Trace("Glyphs block {0} offset is {1}...", i, blockOffset);
|
||||
if (_stream.Position != realOffset)
|
||||
{
|
||||
var bytesGap = realOffset - _stream.Position;
|
||||
Logger.Warn("Found {0} bytes gap before block number {1}", bytesGap, i);
|
||||
_stream.Seek(realOffset, SeekOrigin.Begin);
|
||||
}
|
||||
Logger.Debug("Reading block {0}...", i);
|
||||
|
||||
for (var ch = block.StartSymbol; ch <= block.EndSymbol; ch++)
|
||||
{
|
||||
images[ch] = new GlyphReader(_stream).Read(16, 16);
|
||||
// images[ch].Save($"1\\{(int)ch:X4}.png", ImageFormat.Png);
|
||||
var crc = _stream.ReadByte();
|
||||
}
|
||||
}
|
||||
return images;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Bumpkit" version="1.0.2" targetFramework="net40-client" />
|
||||
<package id="NLog" version="4.4.12" targetFramework="net40-client" />
|
||||
</packages>
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E50E8437-0511-4A94-808A-AD5F3105D060}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>FwFonts</RootNamespace>
|
||||
<AssemblyName>FwFonts</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Utils\Utils.csproj">
|
||||
<Project>{20e6917a-be26-43d6-a2dc-0f32759c4e9b}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("FwFonts")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("FwFonts")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e50e8437-0511-4a94-808a-ad5f3105d060")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -3,7 +3,7 @@ using System.Drawing;
|
|||
using System.IO;
|
||||
using BumpKit;
|
||||
using NLog;
|
||||
using Resources.Utils;
|
||||
using Utils;
|
||||
|
||||
namespace Resources.Image
|
||||
{
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using BumpKit;
|
||||
using NLog;
|
||||
using Resources.Utils;
|
||||
using Utils;
|
||||
|
||||
namespace Resources.Image
|
||||
{
|
||||
|
|
|
@ -38,22 +38,14 @@
|
|||
<HintPath>..\packages\NLog.4.4.12\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extractor.cs" />
|
||||
<Compile Include="ImageLoader.cs" />
|
||||
<Compile Include="Models\FileDescriptor.cs" />
|
||||
<Compile Include="Models\Header.cs" />
|
||||
<Compile Include="Utils\BitReader.cs" />
|
||||
<Compile Include="Utils\BitWriter.cs" />
|
||||
<Compile Include="Image\ColorError.cs" />
|
||||
<Compile Include="Image\FloydSteinbergDitherer.cs" />
|
||||
<Compile Include="Image\Writer.cs" />
|
||||
|
@ -69,5 +61,11 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Utils\Utils.csproj">
|
||||
<Project>{20e6917a-be26-43d6-a2dc-0f32759c4e9b}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Resources.Utils
|
||||
namespace Utils
|
||||
{
|
||||
public class BitReader
|
||||
{
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Resources.Utils
|
||||
namespace Utils
|
||||
{
|
||||
public class BitWriter
|
||||
{
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Utils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Utils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("20e6917a-be26-43d6-a2dc-0f32759c4e9b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{20E6917A-BE26-43D6-A2DC-0F32759C4E9B}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Utils</RootNamespace>
|
||||
<AssemblyName>Utils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BitReader.cs" />
|
||||
<Compile Include="BitWriter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -81,6 +81,10 @@ namespace WatchFace
|
|||
case ".res":
|
||||
UnpackResources(inputFileName);
|
||||
break;
|
||||
case ".ft":
|
||||
case ".latin":
|
||||
UnpackFont(inputFileName);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("The app doesn't support files with extension {0}.", inputFileExtension);
|
||||
Console.WriteLine("Only 'bin', 'res' and 'json' files are supported at this time.");
|
||||
|
@ -202,6 +206,21 @@ namespace WatchFace
|
|||
}
|
||||
}
|
||||
|
||||
private static void UnpackFont(string inputFileName)
|
||||
{
|
||||
var outputDirectory = CreateOutputDirectory(inputFileName);
|
||||
var baseName = Path.GetFileNameWithoutExtension(inputFileName);
|
||||
SetupLogger(Path.Combine(outputDirectory, $"{baseName}.log"));
|
||||
|
||||
Fonts.Models.FileDescriptor resDescriptor;
|
||||
using (var stream = File.OpenRead(inputFileName))
|
||||
{
|
||||
resDescriptor = Fonts.FileReader.Read(stream);
|
||||
}
|
||||
|
||||
ExportFontConfig(resDescriptor, Path.Combine(outputDirectory, "header.json"));
|
||||
}
|
||||
|
||||
private static void UnpackResources(string inputFileName)
|
||||
{
|
||||
var outputDirectory = CreateOutputDirectory(inputFileName);
|
||||
|
@ -360,6 +379,25 @@ namespace WatchFace
|
|||
}
|
||||
}
|
||||
|
||||
private static void ExportFontConfig(Fonts.Models.FileDescriptor resDescriptor, string jsonFileName)
|
||||
{
|
||||
Logger.Debug("Exporting resources config...");
|
||||
try
|
||||
{
|
||||
using (var fileStream = File.OpenWrite(jsonFileName))
|
||||
using (var writer = new StreamWriter(fileStream))
|
||||
{
|
||||
writer.Write(JsonConvert.SerializeObject(resDescriptor, Formatting.Indented,
|
||||
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
|
||||
writer.Flush();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExportResConfig(FileDescriptor resDescriptor, string jsonFileName)
|
||||
{
|
||||
Logger.Debug("Exporting resources config...");
|
||||
|
|
|
@ -58,6 +58,10 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Fonts\Fonts.csproj">
|
||||
<Project>{390eaf2d-9fa8-4dc1-8d4f-ea565ad3c682}</Project>
|
||||
<Name>Fonts</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Resources\Resources.csproj">
|
||||
<Project>{edd55d5d-9e80-451b-ac8a-0746ba6dc6e9}</Project>
|
||||
<Name>Resources</Name>
|
||||
|
|
Loading…
Reference in New Issue