Giter Site home page Giter Site logo

cyotek / cyotek.drawing.bitmapfont Goto Github PK

View Code? Open in Web Editor NEW
42.0 42.0 10.0 1.52 MB

Component for parsing bitmap font files generated by AngelCode's BMFont utility

License: MIT License

C# 98.09% Batchfile 1.91%
bitmap-font bmfont csharp csharp-library hacktoberfest

cyotek.drawing.bitmapfont's People

Contributors

abenedik avatar ashleighadams avatar cyotek avatar jtone123 avatar rds1983 avatar scottswu avatar tom94 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cyotek.drawing.bitmapfont's Issues

Remove .NET 3.5 and .NET Standard 1.3 targets

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.

Finish off removing dependency on System.Drawing

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)

Nuget package update?

Is it possible to get the nuget package updated? We'd like to use the .NET Standard-compatible library in osu!.

Add documentation

Add XML documentation comments, I think I saw only a bare handful. API is fairly simple but no excuse not to have them really.

Change namespace to Cyotek.Drawing

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.

Make structs immutable

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.

Add concrete collections

The Characters, Kernings and Pages properties either expose a Dictionary<> or a []. Both of these are bad design decisions. Change to use concrete collections.

`FormatException` from `BitmapFont.LoadXml` in some locales

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:
screenshot
...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.

_fontSize = Convert.ToInt32(properties.Attributes["size"].Value);
_bold = Convert.ToInt32(properties.Attributes["bold"].Value) != 0;
_italic = Convert.ToInt32(properties.Attributes["italic"].Value) != 0;
_unicode = Convert.ToInt32(properties.Attributes["unicode"].Value) != 0;
_stretchedHeight = Convert.ToInt32(properties.Attributes["stretchH"].Value);
_charset = properties.Attributes["charset"].Value;
_smoothed = Convert.ToInt32(properties.Attributes["smooth"].Value) != 0;
_superSampling = Convert.ToInt32(properties.Attributes["aa"].Value);
_padding = BitmapFontLoader.ParsePadding(properties.Attributes["padding"].Value);
_spacing = BitmapFontLoader.ParsePoint(properties.Attributes["spacing"].Value);
_outlineSize = Convert.ToInt32(properties.Attributes["outline"].Value);
// common attributes
properties = root.SelectSingleNode("common");
_baseHeight = Convert.ToInt32(properties.Attributes["base"].Value);
_lineHeight = Convert.ToInt32(properties.Attributes["lineHeight"].Value);
_textureSize = new Size(Convert.ToInt32(properties.Attributes["scaleW"].Value),
Convert.ToInt32(properties.Attributes["scaleH"].Value));
_packed = Convert.ToInt32(properties.Attributes["packed"].Value) != 0;
_alphaChannel = Convert.ToInt32(properties.Attributes["alphaChnl"].Value);
_redChannel = Convert.ToInt32(properties.Attributes["redChnl"].Value);
_greenChannel = Convert.ToInt32(properties.Attributes["greenChnl"].Value);
_blueChannel = Convert.ToInt32(properties.Attributes["blueChnl"].Value);

Add support for binary file format

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.

xctk:ColorPicker localization

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);

Add tests

It's a fairly simple library, but even so some tests would be helpful for sanity checking.

Improve allocations when loading text format fonts

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

Merge BinaryRealms MeasureFont implementation

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.