//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace BansheeEngine { /** @addtogroup GUI-Engine * @{ */ /// /// Font resource containing data about textual characters and how to render text. Contains one or multiple font /// bitmaps, each for a specific size. /// public sealed class Font : Resource { /// /// Creates a new font resource. For runtime use only. /// private Font() { } /// /// Returns font bitmap for a specific font size. /// /// Size of the bitmap in points. /// Bitmap object if size was found, null otherwise. public FontBitmap GetBitmap(int size) { return Internal_GetBitmap(mCachedPtr, size); } /// /// Finds the available font bitmap size closest to the provided size. /// /// Size of the bitmap in points. /// Nearest available bitmap size. public int GetClosestSize(int size) { return Internal_GetClosestSize(mCachedPtr, size); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern FontBitmap Internal_GetBitmap(IntPtr instance, int size); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetClosestSize(IntPtr instance, int size); } /// /// Contains textures and data about every character for a bitmap font of a specific size. /// public sealed class FontBitmap : ScriptObject { /// /// Constructor for internal runtime use only. /// internal FontBitmap() { } /// /// Size of the font in the bitmap, in points. /// public int Size { get { return Internal_GetSize(mCachedPtr); } } /// /// Y offset to the baseline on which the characters are placed, in pixels. /// public int BaselineOffset { get { return Internal_GetBaselineOffset(mCachedPtr); } } /// /// Height of a single line of the font, in pixels. /// public int LineHeight { get { return Internal_GetLineHeight(mCachedPtr); } } /// /// Width of a space in pixels. /// public int SpaceWidth { get { return Internal_GetSpaceWidth(mCachedPtr); } } /// /// Character to use when data for a character is missing. /// public CharDesc MissingChar { get { CharDesc value; Internal_GetMissingChar(mCachedPtr, out value); return value; } } /// /// Textures in which the character's pixels are stored. /// public Texture[] Pages { get { return Internal_GetPages(mCachedPtr); } } /// /// Returns a description of the character in the bitmap. /// /// Unicode key of the character to retrieve. /// Character data if it was found in the bitmap, missing character data otherwise. public CharDesc GetChar(int id) { CharDesc value; Internal_GetChar(mCachedPtr, id, out value); return value; } /// /// Returns a set of pairs that determine if the provided character should be closer or father together than normal /// with a specific other character. For example the combination of "A" and "V" characters is normally a kerning /// pair "AV" as their bounds overlap and are closer together than characters would be normally. /// /// Unicode key of the character to retrieve kerning pairs for. /// A set of kerning pairs for the character. public KerningPair[] GetKerning(int id) { return Internal_GetKerning(mCachedPtr, id); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetSize(IntPtr instance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetBaselineOffset(IntPtr instance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetLineHeight(IntPtr instance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetSpaceWidth(IntPtr instance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetMissingChar(IntPtr instance, out CharDesc output); [MethodImpl(MethodImplOptions.InternalCall)] private static extern Texture[] Internal_GetPages(IntPtr instance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetChar(IntPtr instance, int id, out CharDesc output); [MethodImpl(MethodImplOptions.InternalCall)] private static extern KerningPair[] Internal_GetKerning(IntPtr instance, int id); } /// /// Marks a range of characters in a font. /// [StructLayout(LayoutKind.Sequential), SerializeObject] public struct CharRange { public int start; public int end; } /// /// Kerning pair representing larger or smaller offset between a specific pair of characters. /// [StructLayout(LayoutKind.Sequential), SerializeObject] public struct KerningPair // Note: Must match C++ struct KerningPair { public int OtherChar; public int Amount; } /// /// Describes a single character in a font of a specific size. /// [StructLayout(LayoutKind.Sequential), SerializeObject] public struct CharDesc // Note: Must match C++ struct ScriptCharDesc { /// Character ID, corresponding to a Unicode key. public int Id; /// Index of the texture the character is located on. public int Page; /// Texture coordinates of the character in the page texture. public float UVX; /// Texture coordinates of the character in the page texture. public float UVY; /// Size of the character in texture coordinates. public float UVWidth; /// Size of the character in texture coordinates. public float UVHeight; /// Size of the character in pixels. public int Width; /// Size of the character in pixels. public int Height; /// Offset for the visible portion of the character in pixels. public int XOffset; /// Offset for the visible portion of the character in pixels. public int YOffset; /// Determines how much to advance the pen after writing this character, in pixels. public int XAdvance; /// Determines how much to advance the pen after writing this character, in pixels. public int YAdvance; } /** @} */ }