-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
f849d51
commit fd60ebb
Showing
36 changed files
with
2,562 additions
and
214 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,165 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using SharpFont; | ||
|
||
namespace Velentr.Font | ||
{ | ||
/// <summary> | ||
/// Various constants defined for the font system. | ||
/// </summary> | ||
internal sealed class Constants | ||
{ | ||
/// <summary> | ||
/// The default hidef texture size | ||
/// </summary> | ||
public const int DEFAULT_HIDEF_TEXTURE_SIZE = 4096; | ||
|
||
/// <summary> | ||
/// The default reach texture size | ||
/// </summary> | ||
public const int DEFAULT_REACH_TEXTURE_SIZE = 2048; | ||
|
||
/// <summary> | ||
/// The default cache surface format | ||
/// </summary> | ||
public const SurfaceFormat DEFAULT_CACHE_SURFACE_FORMAT = SurfaceFormat.Bgra4444; | ||
|
||
/// <summary> | ||
/// The glyph bitmap origin | ||
/// </summary> | ||
public static FTVector26Dot6 GlyphBitmapOrigin = new FTVector26Dot6(0, 0); | ||
|
||
/// <summary> | ||
/// The default character list | ||
/// </summary> | ||
private char[] _defaultCharacterList; | ||
|
||
/// <summary> | ||
/// The default characters | ||
/// </summary> | ||
public string DefaultCharacters = " AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789~`!@#$%^&*()_+-=[]\\{}|;':\",./<>?。? 【】{}、|《》()…¥"; | ||
|
||
/// <summary> | ||
/// The default load flags | ||
/// </summary> | ||
public LoadFlags DefaultLoadFlags = LoadFlags.Default; | ||
|
||
/// <summary> | ||
/// The default load target | ||
/// </summary> | ||
public LoadTarget DefaultLoadTarget = LoadTarget.Normal; | ||
|
||
/// <summary> | ||
/// The default render mode | ||
/// </summary> | ||
public RenderMode DefaultRenderMode = RenderMode.Normal; | ||
|
||
/// <summary> | ||
/// The default spaces in a tab | ||
/// </summary> | ||
public int DefaultSpacesInTab = 4; | ||
|
||
/// <summary> | ||
/// The kerning sanity multiplier | ||
/// </summary> | ||
public int KerningSanityMultiplier = 5; | ||
|
||
/// <summary> | ||
/// Initializes the <see cref="Constants"/> class. | ||
/// </summary> | ||
static Constants() { } | ||
|
||
/// <summary> | ||
/// Prevents a default instance of the <see cref="Constants"/> class from being created. | ||
/// </summary> | ||
private Constants() { } | ||
|
||
/// <summary> | ||
/// Gets the settings. | ||
/// </summary> | ||
/// <value> | ||
/// The settings. | ||
/// </value> | ||
public static Constants Settings { get; } = new Constants(); | ||
|
||
/// <summary> | ||
/// Gets or sets the default character list. | ||
/// </summary> | ||
/// <value> | ||
/// The default character list. | ||
/// </value> | ||
public char[] DefaultCharacterList | ||
{ | ||
get => _defaultCharacterList ?? (_defaultCharacterList = DefaultCharacters.ToCharArray()); | ||
set | ||
{ | ||
_defaultCharacterList = value; | ||
DefaultCharacters = new string(_defaultCharacterList); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Whether to store the font's file data or not. | ||
/// Increases memory usage, but allows the program to not have to re-read the font file when generating the same font at different sizes. | ||
/// </summary> | ||
/// <value> | ||
/// The default character list. | ||
/// </value> | ||
public bool StoreFontFileData { get; set; } = true; | ||
|
||
/// <summary> | ||
/// A full arc of a circle | ||
/// </summary> | ||
public const float TWO_PI = (float)(2 * Math.PI); | ||
|
||
/// <summary> | ||
/// The maximum size of the TextCache object on a particular font | ||
/// </summary> | ||
public int MaxTextCacheSize = 16; | ||
|
||
/// <summary> | ||
/// The color mapping. | ||
/// </summary> | ||
private Dictionary<string, Color> _colorMapping = null; | ||
|
||
/// <summary> | ||
/// Gets the color mapping. | ||
/// </summary> | ||
/// | ||
/// <value> | ||
/// The color mapping. | ||
/// </value> | ||
public Dictionary<string, Color> ColorMapping | ||
{ | ||
get | ||
{ | ||
if (_colorMapping == null) | ||
{ | ||
_colorMapping = new Dictionary<string, Color>(); | ||
var props = typeof(Color).GetProperties(); | ||
|
||
foreach (var color in props) | ||
{ | ||
switch (color.Name) | ||
{ | ||
case "PackedValue": | ||
case "B": | ||
case "G": | ||
case "R": | ||
case "A": | ||
break; | ||
default: | ||
_colorMapping[color.Name.ToUpperInvariant()] = (Color)color.GetValue(color); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return _colorMapping; | ||
} | ||
} | ||
|
||
} | ||
} |
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,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<SharedGUID>bfaa5910-e8e8-4d47-b59b-9839992f2e81</SharedGUID> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<Import_RootNamespace>Velentr.Font</Import_RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)Constants.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)DrawStringExtensions.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)DrawStringMarkdownExtensions.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Font.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)FontManager.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\Cache.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\FontImplementation.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\Glyph.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\GlyphCache.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\Helpers.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\TextCharacter.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\TextImplementation.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Internal\TypefaceImplementation.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)MarkdownMapping.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Text.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Typeface.cs" /> | ||
</ItemGroup> | ||
</Project> |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>bfaa5910-e8e8-4d47-b59b-9839992f2e81</ProjectGuid> | ||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" /> | ||
<PropertyGroup /> | ||
<Import Project="Core.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" /> | ||
</Project> |
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,108 @@ | ||
using System.Text; | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace Velentr.Font | ||
{ | ||
|
||
/// <summary> | ||
/// Extensions to SpriteBatch.Draw to handle Velentr.Font | ||
/// </summary> | ||
// ReSharper disable once CheckNamespace | ||
// ReSharper disable once UnusedMember.Global | ||
public static class DrawStringExtension | ||
{ | ||
/// <summary> | ||
/// Draw text to the screen with the given Font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The spritebatch</param> | ||
/// <param name="font">The Font to use when rendering the string</param> | ||
/// <param name="text">The string to render</param> | ||
/// <param name="position">Position at which to render the string</param> | ||
/// <param name="color">Color with which to render the string</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Font font, string text, Vector2 position, Color color) | ||
{ | ||
font.Draw(spriteBatch, text, color, new Rectangle((int) position.X, (int) position.Y, 0, 0)); | ||
} | ||
|
||
/// <summary> | ||
/// Draw text to the screen with the given Font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The sprite batch.</param> | ||
/// <param name="font">The font.</param> | ||
/// <param name="text">The text.</param> | ||
/// <param name="position">The position.</param> | ||
/// <param name="color">The color.</param> | ||
/// <param name="rotation">A rotation of this string.</param> | ||
/// <param name="origin">Center of the rotation. 0,0 by default.</param> | ||
/// <param name="scale">A scaling of this string.</param> | ||
/// <param name="effects">Modifications for drawing. Can be combined.</param> | ||
/// <param name="layerDepth">A depth of the layer of this string.</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) | ||
{ | ||
font.Draw(spriteBatch, text, color, new Rectangle((int)position.X, (int)position.Y, 0, 0), rotation, origin, scale, effects, layerDepth); | ||
} | ||
|
||
/// <summary> | ||
/// Draws text to the screen with the given font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The spritebatch</param> | ||
/// <param name="font">The Font to use when rendering the string</param> | ||
/// <param name="text">The string to render.</param> | ||
/// <param name="position">Position at which to render the string</param> | ||
/// <param name="color">Color with which to render the string</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Font font, StringBuilder text, Vector2 position, Color color) | ||
{ | ||
font.Draw(spriteBatch, text.ToString(), color, new Rectangle((int)position.X, (int)position.Y, 0, 0)); | ||
} | ||
|
||
/// <summary> | ||
/// Draw text to the screen with the given Font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The sprite batch.</param> | ||
/// <param name="font">The font.</param> | ||
/// <param name="text">The text.</param> | ||
/// <param name="position">The position.</param> | ||
/// <param name="color">The color.</param> | ||
/// <param name="rotation">A rotation of this string.</param> | ||
/// <param name="origin">Center of the rotation. 0,0 by default.</param> | ||
/// <param name="scale">A scaling of this string.</param> | ||
/// <param name="effects">Modifications for drawing. Can be combined.</param> | ||
/// <param name="layerDepth">A depth of the layer of this string.</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Font font, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) | ||
{ | ||
font.Draw(spriteBatch, text.ToString(), color, new Rectangle((int)position.X, (int)position.Y, 0, 0), rotation, origin, scale, effects, layerDepth); | ||
} | ||
|
||
/// <summary> | ||
/// Draw text to the screen with the given Font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The spritebatch</param> | ||
/// <param name="text">The text to render.</param> | ||
/// <param name="position">Position at which to render the text</param> | ||
/// <param name="color">Color with which to render the text</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Text text, Vector2 position, Color color) | ||
{ | ||
text.Draw(spriteBatch, position, color); | ||
} | ||
|
||
/// <summary> | ||
/// Draw text to the screen with the given Font. | ||
/// </summary> | ||
/// <param name="spriteBatch">The spritebatch</param> | ||
/// <param name="text">The text to render.</param> | ||
/// <param name="position">Position at which to render the text</param> | ||
/// <param name="color">Color with which to render the text</param> | ||
/// <param name="rotation">A rotation of this string.</param> | ||
/// <param name="origin">Center of the rotation. 0,0 by default.</param> | ||
/// <param name="scale">A scaling of this string.</param> | ||
/// <param name="effects">Modifications for drawing. Can be combined.</param> | ||
/// <param name="layerDepth">A depth of the layer of this string.</param> | ||
public static void DrawString(this SpriteBatch spriteBatch, Text text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) | ||
{ | ||
text.Draw(spriteBatch, position, color, rotation, origin, scale, effects, layerDepth); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.