cyotek / cyotek.drawing.bitmapfont Goto Github PK
View Code? Open in Web Editor NEWComponent for parsing bitmap font files generated by AngelCode's BMFont utility
License: MIT License
Component for parsing bitmap font files generated by AngelCode's BMFont utility
License: MIT License
Building the .NET Standard 1.3 displays a build warning due to it relying on a beta Microsoft package. While this would be resolved by #22, it is an obsolete target.
Also, since installing the .NET 5.0 SDK (which takes precedence over other versions), it appears to be no longer possible to build the .NET 3.5 target. While forcing a specific SDK version works this done with a global file rather than a command line switch so isn't desirable. According to support docs .NET 3.5 is still supported until 2029 so it is a bit annoying that the tooling no longer appears to support it. Consider looking into doing a separate MSBuild based compile for 3.5 as long as it is still fully automatic for the NuGet package build. Otherwise, drop it as well.
Hiero is popular tool used to make .fnt: https://github.com/libgdx/libgdx/wiki/Hiero
However it has one trait - it omits outline setting in the begging of the file(i.e. "outline=0").
So Cyotek.Drawing.BitmapFont fails to load such .fnt as it expects this setting to be there.
Sample .fnt is attached.
Arial.zip
Some properties expose System.Drawing types (e.g. Rectangle
, Size
). In order to ensure the library can be used anywhere without dependencies these should be changed to native types.
v2 introduced native alternatives whilst flagging the System.Drawing versions as obsolete, but some were omitted (for example MeasureFont
returns a Size
)
Is it possible to get the nuget package updated? We'd like to use the .NET Standard-compatible library in osu!.
Add XML documentation comments, I think I saw only a bare handful. API is fairly simple but no excuse not to have them really.
The current namespace is Cyotek.Drawing.BitmapFont, but the core class is also BitmapFont. Change the namespace to be used Cyotek.Drawing to match normal conventions.
Given that the purpose of the library is to load bitmap fonts, but not to edit or save them, it doesn't make sense that the structures are mutable. It makes even less sense if the structs are updated with custom GetHashCode
overrides.
Suggest making them fully immutable.
The Characters
, Kernings
and Pages
properties either expose a Dictionary<>
or a []
. Both of these are bad design decisions. Change to use concrete collections.
Repro:
mkdir repro-25 && cd repro-25 && dotnet new console && dotnet add package Cyotek.Drawing.BitmapFont -v 2.0.1
Then edit Program.cs
to:
using System;
using System.IO;
using Cyotek.Drawing.BitmapFont;
using var fs = File.OpenRead("./courier16px.fnt");
BitmapFont font = new();
font.LoadXml(fs);
Console.WriteLine("success");
Download this file (curl -O https://raw.githubusercontent.com/TASVideos/BizHawk/2.6.1/src/BizHawk.Client.EmuHawk/Resources/courier16px.fnt
).
Finally, dotnet run
. On Windows with the default en-AU locale (and presumably most others), you get:
success
But change this setting:
...and run again, and you get:
Unhandled exception. System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at Cyotek.Drawing.BitmapFont.BitmapFont.LoadXml(TextReader reader)
at Cyotek.Drawing.BitmapFont.BitmapFont.LoadXml(Stream stream)
at <Program>$.<Main>$(String[] args)
Probable cause: I think all these calls to Convert.ToInt32
need to have CultureInfo.InvariantCulture
as the second argument.
Cyotek.Drawing.BitmapFont/src/BitmapFont.cs
Lines 814 to 836 in dd44d7d
As reading the binary file is almost certainly going to be faster than parsing the text formats, especially the XML format, probably worth investigating adding a binary parser.
http://www.angelcode.com/products/bmfont/doc/file_format.html#bin
Format doesn't look too bad, although there's 3 different versions - either only support the third, or find older versions of the program to generate older formats.
Definitely needs tests adding if going to add binary support.
Is localization implemented for it?
I tried to use the following code during initialization to set it to a different language but there seem to be no effect
Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
It's a fairly simple library, but even so some tests would be helpful for sanity checking.
NuGet package is at version 1.0.2, whereas in my head it's at 1.2.0. Need to change the versions to properly match semantic versioning and think 3 fields not 4!
Completely against my expectations, loading the Text format is slightly slower than XML, but also uses significantly more allocations. While the the performance is probably fine, need to cut down on the number of allocations.
BenchmarkDotNet=v0.10.8, OS=Windows 10 Redstone 1 (10.0.14393)
Processor=AMD FX(tm)-6300 Six-Core Processor, ProcessorCount=6
Frequency=3429483 Hz, Resolution=291.5891 ns, Timer=TSC
[Host] : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.2101.1
DefaultJob : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.2101.1
Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|
LoadAuto | 8.620 ms | 0.1708 ms | 0.3489 ms | 187.5000 | 93.7500 | 15.6250 | 1.04 MB |
LoadText | 13.511 ms | 0.2649 ms | 0.3883 ms | 2156.2500 | 15.6250 | 15.6250 | 3.7 MB |
LoadXml | 8.144 ms | 0.1607 ms | 0.2200 ms | 203.1250 | 93.7500 | 15.6250 | 1.03 MB |
A quick compare of the original bitmap font code with the version embedded in the BinaryRealms library shows that I updated MeasureFont to handle tab characters, along with an extra overload that returned the source text data split up by lines (wrapped or forced). Might be worth merging in this change.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.