Skip to content

Commit 7ec9b2a

Browse files
authored
Revert "feat: Crossplatform font loading (#2530)" (#2637)
This reverts commit a06300f.
1 parent a71a7ec commit 7ec9b2a

17 files changed

+533
-276
lines changed

sources/engine/Stride.Assets/SpriteFont/Compiler/BitmapImporter.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
using System;
7979
using System.Collections.Generic;
8080
using System.Drawing;
81-
using FreeImageAPI;
81+
using System.Drawing.Imaging;
8282

8383
namespace Stride.Assets.SpriteFont.Compiler
8484
{
@@ -102,20 +102,20 @@ internal class BitmapImporter : IFontImporter
102102
public void Import(SpriteFontAsset options, List<char> characters)
103103
{
104104
// Load the source bitmap.
105-
FreeImageBitmap bitmap;
105+
Bitmap bitmap;
106106

107107
try
108108
{
109109
// TODO Check if source can be used as is from here
110-
bitmap = FreeImageBitmap.FromFile(options.FontSource.GetFontPath());
110+
bitmap = new Bitmap(options.FontSource.GetFontPath());
111111
}
112112
catch
113113
{
114114
throw new FontNotFoundException(options.FontSource.GetFontPath());
115115
}
116116

117117
// Convert to our desired pixel format.
118-
bitmap = bitmap.ConvertTo32Bits();
118+
bitmap = BitmapUtils.ChangePixelFormat(bitmap, PixelFormat.Format32bppArgb);
119119

120120
// What characters are included in this font?
121121
int characterIndex = 0;
@@ -148,32 +148,34 @@ public void Import(SpriteFontAsset options, List<char> characters)
148148

149149
// Seems to be the same as this one: http://www.tonicodes.net/blog/creating-custom-fonts-with-outline-for-wp7-and-xna/
150150
// Searches a 2D bitmap for characters that are surrounded by a marker pink color.
151-
static IEnumerable<Rectangle> FindGlyphs(FreeImageBitmap bitmap)
151+
static IEnumerable<Rectangle> FindGlyphs(Bitmap bitmap)
152152
{
153-
var bitmapData = new BitmapUtils.PixelAccessor(bitmap);
154-
for (int y = 1; y < bitmap.Height; y++)
153+
using (var bitmapData = new BitmapUtils.PixelAccessor(bitmap, ImageLockMode.ReadOnly))
155154
{
156-
for (int x = 1; x < bitmap.Width; x++)
155+
for (int y = 1; y < bitmap.Height; y++)
157156
{
158-
// Look for the top left corner of a character (a pixel that is not pink, but was pink immediately to the left and above it)
159-
if (!IsMarkerColor(bitmapData[x, y]) &&
160-
IsMarkerColor(bitmapData[x - 1, y]) &&
161-
IsMarkerColor(bitmapData[x, y - 1]))
157+
for (int x = 1; x < bitmap.Width; x++)
162158
{
163-
// Measure the size of this character.
164-
int w = 1, h = 1;
165-
166-
while ((x + w < bitmap.Width) && !IsMarkerColor(bitmapData[x + w, y]))
159+
// Look for the top left corner of a character (a pixel that is not pink, but was pink immediately to the left and above it)
160+
if (!IsMarkerColor(bitmapData[x, y]) &&
161+
IsMarkerColor(bitmapData[x - 1, y]) &&
162+
IsMarkerColor(bitmapData[x, y - 1]))
167163
{
168-
w++;
169-
}
164+
// Measure the size of this character.
165+
int w = 1, h = 1;
170166

171-
while ((y + h < bitmap.Height) && !IsMarkerColor(bitmapData[x, y + h]))
172-
{
173-
h++;
174-
}
167+
while ((x + w < bitmap.Width) && !IsMarkerColor(bitmapData[x + w, y]))
168+
{
169+
w++;
170+
}
171+
172+
while ((y + h < bitmap.Height) && !IsMarkerColor(bitmapData[x, y + h]))
173+
{
174+
h++;
175+
}
175176

176-
yield return new Rectangle(x, y, w, h);
177+
yield return new Rectangle(x, y, w, h);
178+
}
177179
}
178180
}
179181
}

0 commit comments

Comments
 (0)