-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
14,882 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Cyotek.Drawing.BitmapFont; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace SpriteFontPlus | ||
{ | ||
public class BMFontLoader | ||
{ | ||
public static SpriteFont LoadXml(string xml, Texture2D texture) | ||
{ | ||
var data = new BitmapFont(); | ||
data.LoadXml(xml); | ||
|
||
#if !XENKO | ||
var glyphBounds = new List<Rectangle>(); | ||
var cropping = new List<Rectangle>(); | ||
var chars = new List<char>(); | ||
var kerning = new List<Vector3>(); | ||
|
||
var characters = data.Characters.Values.OrderBy(c => c.Char); | ||
foreach (var character in characters) | ||
{ | ||
var bounds = character.Bounds; | ||
|
||
// bounds.Offset(texture.Bounds.Location); | ||
|
||
glyphBounds.Add(bounds); | ||
cropping.Add(new Rectangle(character.Offset.X, character.Offset.Y, bounds.Width, bounds.Height)); | ||
|
||
chars.Add(character.Char); | ||
|
||
kerning.Add(new Vector3(0, character.Bounds.Width, character.XAdvance - character.Bounds.Width)); | ||
} | ||
|
||
var constructorInfo = typeof(SpriteFont).GetTypeInfo().DeclaredConstructors.First(); | ||
var result = (SpriteFont) constructorInfo.Invoke(new object[] | ||
{ | ||
texture, glyphBounds, cropping, | ||
chars, data.LineHeight, 0, kerning, ' ' | ||
}); | ||
|
||
return result; | ||
#else | ||
var textureRegion = textureRegionLoader(data.Pages[0].FileName); | ||
|
||
var glyphs = new List<Glyph>(); | ||
foreach (var pair in data.Characters) | ||
{ | ||
var character = pair.Value; | ||
|
||
var bounds = character.Bounds; | ||
bounds.X += textureRegion.Bounds.X; | ||
bounds.Y += textureRegion.Bounds.Y; | ||
var glyph = new Glyph | ||
{ | ||
Character = character.Char, | ||
BitmapIndex = 0, | ||
Offset = new Vector2(character.Offset.X, character.Offset.Y), | ||
Subrect = bounds, | ||
XAdvance = character.XAdvance | ||
}; | ||
|
||
glyphs.Add(glyph); | ||
} | ||
|
||
var textures = new List<Texture> | ||
{ | ||
textureRegion.Texture | ||
}; | ||
|
||
return DefaultAssets.FontSystem.NewStatic(data.LineHeight, glyphs, textures, 0, data.LineHeight); | ||
#endif | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace SpriteFontPlus | ||
{ | ||
public struct CharacterRange | ||
{ | ||
public static readonly CharacterRange BasicLatin = new CharacterRange((char) 0x0020, (char) 0x007F); | ||
|
||
public static readonly CharacterRange Latin1Supplement = | ||
new CharacterRange((char) 0x00A0, (char) 0x00FF); | ||
|
||
public static readonly CharacterRange LatinExtendedA = | ||
new CharacterRange((char) 0x0100, (char) 0x017F); | ||
|
||
public static readonly CharacterRange LatinExtendedB = | ||
new CharacterRange((char) 0x0180, (char) 0x024F); | ||
|
||
public static readonly CharacterRange Cyrillic = new CharacterRange((char) 0x0400, (char) 0x04FF); | ||
|
||
public static readonly CharacterRange CyrillicSupplement = | ||
new CharacterRange((char) 0x0500, (char) 0x052F); | ||
|
||
public static readonly CharacterRange Hiragana = | ||
new CharacterRange((char) 0x3040, (char) 0x309F); | ||
|
||
public static readonly CharacterRange Katakana = | ||
new CharacterRange((char) 0x30A0, (char) 0x30FF); | ||
|
||
public char Start { get; private set; } | ||
public char End { get; private set; } | ||
|
||
public CharacterRange(char start, char end) | ||
{ | ||
Start = start; | ||
End = end; | ||
} | ||
|
||
public CharacterRange(char single): this(single, single) | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.