Skip to content

Commit

Permalink
Moved to Hebron
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Shapiro committed Jan 1, 2022
1 parent 0247c63 commit 4361ea3
Show file tree
Hide file tree
Showing 29 changed files with 3,262 additions and 3,032 deletions.
33 changes: 8 additions & 25 deletions generation/StbTrueTypeSharp.Generator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StbTrueTypeSharp.Generator", "StbTrueTypeSharp.Generator\StbTrueTypeSharp.Generator.csproj", "{002FAE39-051D-4BB2-B8D5-12543919E819}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StbTrueTypeSharp.Generator", "StbTrueTypeSharp.Generator\StbTrueTypeSharp.Generator.csproj", "{002FAE39-051D-4BB2-B8D5-12543919E819}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sichem", "..\..\Sichem\Sichem\Sichem.csproj", "{71352218-91C4-490E-A650-AB17C48D0300}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hebron", "..\..\Hebron\src\Hebron\Hebron.csproj", "{E033D124-60E8-4BB8-9D01-B9DB7F716743}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|Any CPU.ActiveCfg = Debug|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|Mixed Platforms.Build.0 = Debug|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|x64.ActiveCfg = Debug|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|x64.Build.0 = Debug|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{002FAE39-051D-4BB2-B8D5-12543919E819}.Debug|Any CPU.Build.0 = Debug|Any CPU
{002FAE39-051D-4BB2-B8D5-12543919E819}.Release|Any CPU.ActiveCfg = Release|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Release|Mixed Platforms.ActiveCfg = Release|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Release|Mixed Platforms.Build.0 = Release|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Release|x64.ActiveCfg = Release|x64
{002FAE39-051D-4BB2-B8D5-12543919E819}.Release|x64.Build.0 = Release|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Debug|Any CPU.ActiveCfg = Debug|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Debug|Mixed Platforms.Build.0 = Debug|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Debug|x64.ActiveCfg = Debug|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Debug|x64.Build.0 = Debug|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Release|Any CPU.ActiveCfg = Release|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Release|Mixed Platforms.ActiveCfg = Release|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Release|Mixed Platforms.Build.0 = Release|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Release|x64.ActiveCfg = Release|x64
{71352218-91C4-490E-A650-AB17C48D0300}.Release|x64.Build.0 = Release|x64
{E033D124-60E8-4BB8-9D01-B9DB7F716743}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E033D124-60E8-4BB8-9D01-B9DB7F716743}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E033D124-60E8-4BB8-9D01-B9DB7F716743}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E033D124-60E8-4BB8-9D01-B9DB7F716743}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 0 additions & 6 deletions generation/StbTrueTypeSharp.Generator/App.config

This file was deleted.

109 changes: 44 additions & 65 deletions generation/StbTrueTypeSharp.Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using Hebron;
using Hebron.Roslyn;
using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Sichem;

namespace StbSharp.StbTrueType.Generator
{
Expand Down Expand Up @@ -60,49 +63,58 @@ private static bool OwnedByClass(this string value, string cls)
return value.Contains("(" + cls + " ") || value.Contains("(" + cls + "*");
}

private static void Write(Dictionary<string, string> input, Dictionary<string, string> output)
private static void Write<T>(Dictionary<string, T> input, Dictionary<string, string> output) where T : SyntaxNode
{
foreach (var pair in input)
var keys = (from string k in input.Keys orderby k select k).ToArray();
foreach (var key in keys)
{
string outputKey = null;
foreach (var pair2 in _outputs)
{
foreach (var prefix in pair2.Value)
{
if (pair.Key.StartsWith(prefix))
if (key.StartsWith(prefix))
{
outputKey = pair2.Key;
goto found;
}
}
}
found:
;

string value;
using (var sw = new StringWriter())
{
input[key].NormalizeWhitespace().WriteTo(sw);

value = sw.ToString();
value += Environment.NewLine;
}

if (outputKey == null)
{
if (pair.Value.OwnedByClass("stbtt__bitmap"))
if (value.OwnedByClass("stbtt__bitmap"))
{
outputKey = "Bitmap";
}
else if (pair.Value.OwnedByClass("stbtt__buf"))
else if (value.OwnedByClass("stbtt__buf"))
{
outputKey = "Buf";
}
else if (pair.Value.OwnedByClass("stbtt__csctx"))
else if (value.OwnedByClass("stbtt__csctx"))
{
outputKey = "CharString";
}
else if (pair.Value.OwnedByClass("stbtt_fontinfo"))
else if (value.OwnedByClass("stbtt_fontinfo"))
{
outputKey = "FontInfo";
}
else if (pair.Value.OwnedByClass("stbrp_context") ||
pair.Value.OwnedByClass("stbtt_pack_context"))
else if (value.OwnedByClass("stbrp_context") ||
value.OwnedByClass("stbtt_pack_context"))
{
outputKey = "RectPack";
}
else if (pair.Value.OwnedByClass("stbtt__hheap"))
else if (value.OwnedByClass("stbtt__hheap"))
{
outputKey = "Heap";
}
Expand All @@ -118,91 +130,57 @@ private static void Write(Dictionary<string, string> input, Dictionary<string, s
output[outputKey] = string.Empty;
}

output[outputKey] += pair.Value;
output[outputKey] += value;
}
}

private static string PostProcess(string data)
{
data = Utility.ReplaceNativeCalls(data);

data = data.Replace("(void *)(0)", "null");
data = data.Replace("stbtt_vertex* vertices = 0;", "stbtt_vertex* vertices = null;");
data = data.Replace("(flags & 16)?dx:-dx", "(flags & 16) != 0?dx:-dx");
data = data.Replace("(flags & 32)?dy:-dy", "(flags & 32) != 0?dy:-dy");
data = data.Replace("(vertices) == (0)", "vertices == null");
data = data.Replace("sizeof((vertices[0]))", "sizeof(stbtt_vertex)");
data = data.Replace("(int)(!(flags & 1))", "((flags & 1) != 0?0:1)");
data = data.Replace("vertices = 0;", "vertices = null;");
data = data.Replace("stbtt_vertex* comp_verts = 0;", "stbtt_vertex* comp_verts = null;");
data = data.Replace("stbtt_vertex* tmp = 0;", "stbtt_vertex* tmp = null;");
data = data.Replace(",)", ")");
data = data.Replace("+ +", "+");
data = data.Replace("(sizeof(stbtt__hheap_chunk) + size * count)",
"((ulong)sizeof(stbtt__hheap_chunk)+ size * (ulong)(count))");
data = data.Replace("size * hh->num_remaining_in_head_chunk",
"size * (ulong)hh->num_remaining_in_head_chunk");
data = data.Replace("sizeof((*z))", "sizeof(stbtt__active_edge)");
data = data.Replace("_next_ = 0;", "_next_ = null;");
data = data.Replace("sizeof((scanline[0]))", "sizeof(float)");
data = data.Replace("int c = (int)(((a)->y0) < ((b)->y0));", "int c = (int)(a->y0 < b->y0?1:0);");
data = data.Replace("sizeof((*e))", "sizeof(stbtt__edge)");
data = data.Replace("sizeof((**contour_lengths))", "sizeof(int)");
data = data.Replace("sizeof((points[0]))", "sizeof(stbtt__point)");
data = data.Replace("sizeof((*context))", "sizeof(stbrp_context)");
data = data.Replace("sizeof((*nodes))", "sizeof(stbrp_node)");
data = data.Replace("sizeof((*rects))", "sizeof(stbrp_rect)");
data = data.Replace("(int)(((a[0]) == (b[0])) && ((a[1]) == (b[1])));",
"(int)(((a[0] == b[0]) && (a[1] == b[1]))?1:0);");
data = data.Replace("stbtt__hheap hh = (stbtt__hheap)({ null, null, 0 })",
"stbtt__hheap hh = new stbtt__hheap()");

return data;
}

static void Process()
{
var parameters = new ConversionParameters
var parameters = new RoslynConversionParameters
{
InputPath = @"stb_truetype.h",
Defines = new[]
{
"STB_TRUETYPE_IMPLEMENTATION",
"STB_TRUETYPE_IMPLEMENTATION",
},
Classes = new[]
{
"stbtt_pack_context",
"stbtt_fontinfo",
},
SkipStructs = new string[]
{
"stbtt_fontinfo",
},
SkipGlobalVariables = new string[]
{
},
SkipFunctions = new string[]
{
"stbtt__find_table",
},
Classes = new string[]
{
"stbtt_pack_context",
"stbtt_fontinfo",
},
GlobalArrays = new string[]
{
"stbtt__find_table",
},
GenerateSafeCode = false,
};

var cp = new ClangParser();
var dump = TextCodeConverter.Convert(parameters.InputPath, parameters.Defines);
File.WriteAllText(@"..\..\..\..\..\..\src\StbTrueType.txt", dump);

var result = cp.Process(parameters);
var result = RoslynCodeConverter.Convert(parameters);

// Post processing
Logger.Info("Post processing...");

var outputFiles = new Dictionary<string, string>();
Write(result.Constants, outputFiles);
Write(result.NamedEnums, outputFiles);
Write(result.UnnamedEnumValues, outputFiles);
Write(result.GlobalVariables, outputFiles);
Write(result.Enums, outputFiles);
Write(result.Delegates, outputFiles);
Write(result.Structs, outputFiles);
Write(result.Methods, outputFiles);
Write(result.Functions, outputFiles);

foreach (var pair in outputFiles)
{
Expand All @@ -214,6 +192,7 @@ static void Process()

sb.AppendLine("using System;");
sb.AppendLine("using System.Runtime.InteropServices;");
sb.AppendLine("using Hebron.Runtime;");

sb.AppendLine();

Expand All @@ -223,7 +202,7 @@ static void Process()
data = sb.ToString() + data;
data += "}\n}";

var fileName = @"..\..\..\..\..\src\StbTrueType.Generated." + pair.Key + ".cs";
var fileName = @"..\..\..\..\..\..\src\StbTrueType.Generated." + pair.Key + ".cs";
Logger.Info("Writing {0}", fileName);
File.WriteAllText(fileName, data);
}
Expand Down
36 changes: 0 additions & 36 deletions generation/StbTrueTypeSharp.Generator/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,70 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{002FAE39-051D-4BB2-B8D5-12543919E819}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StbSharp.StbTrueType.Generator</RootNamespace>
<AssemblyName>StbSharp.StbTrueType.Generator</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<ProjectReference Include="..\..\..\Hebron\src\Hebron\Hebron.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="stb_truetype.h">
<None Update="stb_truetype.h">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Sichem\Sichem\Sichem.csproj">
<Project>{71352218-91c4-490e-a650-ab17c48d0300}</Project>
<Name>Sichem</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
Loading

0 comments on commit 4361ea3

Please sign in to comment.