Skip to content

Commit 084e771

Browse files
Added source code
1 parent 40cd599 commit 084e771

30 files changed

Lines changed: 3170 additions & 0 deletions

TechOS.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32825.248
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechOS", "TechOS\TechOS.csproj", "{335D131E-9072-4D6C-9C3A-A227D55D310D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{335D131E-9072-4D6C-9C3A-A227D55D310D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{335D131E-9072-4D6C-9C3A-A227D55D310D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{335D131E-9072-4D6C-9C3A-A227D55D310D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{335D131E-9072-4D6C-9C3A-A227D55D310D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BA41AE7A-0A06-44A8-9BB2-67B0C8886090}
24+
EndGlobalSection
25+
EndGlobal

TechOS/CosmosTTF.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32526.322
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CosmosTTF", "CosmosTTF\CosmosTTF.csproj", "{184E6E5A-7CE6-4D4B-8024-0A3BDC7E5BF9}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Projektmappenelemente", "Projektmappenelemente", "{D8530763-A7DC-4EBF-BD52-5BDA5EC91807}"
9+
ProjectSection(SolutionItems) = preProject
10+
README.md = README.md
11+
EndProjectSection
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormTest", "WinFormTest\WinFormTest.csproj", "{FED20FAD-1DDA-4BE2-BD92-A0BC111676D1}"
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{184E6E5A-7CE6-4D4B-8024-0A3BDC7E5BF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{184E6E5A-7CE6-4D4B-8024-0A3BDC7E5BF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{184E6E5A-7CE6-4D4B-8024-0A3BDC7E5BF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{184E6E5A-7CE6-4D4B-8024-0A3BDC7E5BF9}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{FED20FAD-1DDA-4BE2-BD92-A0BC111676D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{FED20FAD-1DDA-4BE2-BD92-A0BC111676D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{FED20FAD-1DDA-4BE2-BD92-A0BC111676D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{FED20FAD-1DDA-4BE2-BD92-A0BC111676D1}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
GlobalSection(ExtensibilityGlobals) = postSolution
34+
SolutionGuid = {BDC0E86C-8879-4008-A701-52FA4A7D5026}
35+
EndGlobalSection
36+
EndGlobal

TechOS/CosmosTTF/CosmosTTF.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Cosmos.Debug.Kernel" Version="0-*" NoWarn="NU1604" />
11+
<PackageReference Include="Cosmos.System2" Version="0-*" NoWarn="NU1604" />
12+
</ItemGroup>
13+
</Project>

TechOS/CosmosTTF/CustomDict.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
/**
9+
* <summary>
10+
* Only supports string as key to allow for == operator, as Equals doesn't seem to work with cosmos
11+
* </summary>
12+
*/
13+
namespace CosmosTTF {
14+
public class CustomDictString<TV> : IEnumerable {
15+
private List<CustomDictEntry<TV>> entries;
16+
public int Count => entries.Count;
17+
18+
public CustomDictString() {
19+
this.entries = new();
20+
}
21+
22+
public void Add(string key, TV value) {
23+
this.entries.Add(new(key, value));
24+
}
25+
26+
public TV Get(string key) {
27+
foreach (var entry in this.entries) {
28+
if (entry.key == key) return entry.value;
29+
}
30+
31+
throw new NullReferenceException("CustomDict does not include key");
32+
}
33+
34+
public void Set(string key, TV value) {
35+
foreach (var entry in this.entries) {
36+
if (entry.key == key) {
37+
entry.value = value;
38+
return;
39+
}
40+
}
41+
42+
this.entries.Add(new(key, value));
43+
}
44+
45+
public bool Remove(string key) {
46+
int i = 0;
47+
foreach (var entry in this.entries) {
48+
if (entry.key == key) {
49+
entries.RemoveAt(0);
50+
return true;
51+
}
52+
53+
i++;
54+
}
55+
56+
return false;
57+
}
58+
59+
public bool TryGet(string key, out TV val) {
60+
foreach (var entry in this.entries) {
61+
//TTFManager.DebugUIPrint("CustomDict TryGet: Checking entry");
62+
if (entry.key == key) {
63+
//TTFManager.DebugUIPrint("CustomDict TryGet: Entry matched, setting out");
64+
val = entry.value;
65+
//TTFManager.DebugUIPrint("CustomDict TryGet: Entry matched, setted out and returning true");
66+
return true;
67+
}
68+
}
69+
70+
//TTFManager.DebugUIPrint("CustomDict TryGet: Not found, setting value to default(TV)");
71+
val = default(TV);
72+
//TTFManager.DebugUIPrint("CustomDict TryGet: Return false");
73+
return false;
74+
}
75+
76+
IEnumerator IEnumerable.GetEnumerator() {
77+
return this.entries.GetEnumerator();
78+
}
79+
80+
public TV this[string key] {
81+
get => Get(key);
82+
set => Set(key, value);
83+
}
84+
}
85+
86+
internal class CustomDictEntry<TV> {
87+
public string key;
88+
public TV value;
89+
90+
public CustomDictEntry(string key, TV value) {
91+
this.key = key;
92+
this.value = value;
93+
}
94+
}
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace LunarLabs.Fonts {
5+
public static class DistanceFieldUtils {
6+
/*
7+
Computes a distance field transform of a high resolution binary source channel and returns the result as a low resolution channel.
8+
9+
scale_down : The amount the source channel will be scaled down.
10+
A value of 8 means the destination image will be 1/8th the size of the source
11+
12+
spread: The spread in pixels before the distance field clamps to (zero/one).
13+
The valueis specified in units of the destination image. The spread in the source image will be spread*scale_down.
14+
*/
15+
public static GlyphBitmap CreateDistanceField(GlyphBitmap source, int scale, float spread) {
16+
var result = new GlyphBitmap(source.Width / scale, source.Height / scale);
17+
18+
var values = source.Pixels.Select(x => (x / 255.0f) - 0.5f).ToArray();
19+
20+
for (int y = 0; y < result.Height; y++) {
21+
for (int x = 0; x < result.Width; x++) {
22+
var sd = SignedDistance(values, source.Width, source.Height, x * scale, y * scale, spread);
23+
var n = (sd + spread) / (spread * 2.0f);
24+
25+
var c = (byte)(n * 255);
26+
var offset = x + y * result.Width;
27+
result.Pixels[offset] = c;
28+
}
29+
}
30+
31+
return result;
32+
}
33+
34+
private static float SignedDistance(float[] source, int w, int h, int cx, int cy, float clamp) {
35+
var cd = source[cx + cy * w];
36+
37+
int min_x = cx - (int)(Math.Floor(clamp) - 1);
38+
if (min_x < 0) {
39+
min_x = 0;
40+
}
41+
42+
int max_x = cx + (int)(Math.Floor(clamp) + 1);
43+
if (max_x >= w) {
44+
max_x = w - 1;
45+
}
46+
47+
float distance = clamp;
48+
for (int dy = 0; dy < (int)(Math.Floor(clamp) + 1); dy++) {
49+
if (dy > distance) {
50+
continue;
51+
}
52+
53+
if (cy - dy >= 0) {
54+
int y1 = cy - dy;
55+
for (int x = min_x; x <= max_x; x++) {
56+
if (x - cx > distance) {
57+
continue;
58+
}
59+
60+
float d = source[x + y1 * w];
61+
if (cd * d < 0) {
62+
float d2 = (y1 - cy) * (y1 - cy) + (x - cx) * (x - cx);
63+
if (d2 < (distance * distance)) { distance = (float)Math.Sqrt(d2); }
64+
}
65+
}
66+
}
67+
68+
if (dy != 0 && cy + dy < h) {
69+
int y2 = cy + dy;
70+
71+
for (int x = min_x; x < max_x; x++) {
72+
if (x - cx > distance) {
73+
continue;
74+
}
75+
76+
float d = source[x + y2 * w];
77+
if (cd * d < 0) {
78+
float d2 = (y2 - cy) * (y2 - cy) + (x - cx) * (x - cx);
79+
if (d2 < distance * distance) {
80+
distance = (float)Math.Sqrt(d2);
81+
}
82+
}
83+
}
84+
}
85+
86+
87+
}
88+
89+
if (cd > 0)
90+
return distance;
91+
else
92+
return -distance;
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)