diff --git a/CSFML/build/VC2008/csfml-graphics.vcproj b/CSFML/build/VC2008/csfml-graphics.vcproj
index d7d16c7c..09bfd5c0 100644
--- a/CSFML/build/VC2008/csfml-graphics.vcproj
+++ b/CSFML/build/VC2008/csfml-graphics.vcproj
@@ -232,6 +232,10 @@
RelativePath="..\..\src\SFML\Graphics\FontStruct.h"
>
+
+
diff --git a/CSFML/include/SFML/Graphics/Font.h b/CSFML/include/SFML/Graphics/Font.h
index 16f76636..685da11f 100644
--- a/CSFML/include/SFML/Graphics/Font.h
+++ b/CSFML/include/SFML/Graphics/Font.h
@@ -36,26 +36,22 @@
/// Create a new font from a file
///
/// \param filename : Path of the font file to load
-/// \param charSize : Size of characters in bitmap - the bigger, the higher quality
-/// \param charset : Characters set to generate (just pass NULL to get the default charset)
///
/// \return A new sfFont object, or NULL if it failed
///
////////////////////////////////////////////////////////////
-CSFML_API sfFont* sfFont_CreateFromFile(const char* filename, unsigned int charSize, const sfUint32* charset);
+CSFML_API sfFont* sfFont_CreateFromFile(const char* filename);
////////////////////////////////////////////////////////////
/// Create a new image font a file in memory
///
/// \param data : Pointer to the file data in memory
/// \param sizeInBytes : Size of the data to load, in bytes
-/// \param charSize : Size of characters in bitmap - the bigger, the higher quality
-/// \param charset : Characters set to generate (just pass NULL to get the default charset)
///
/// \return A new sfFont object, or NULL if it failed
///
////////////////////////////////////////////////////////////
-CSFML_API sfFont* sfFont_CreateFromMemory(const char* data, size_t sizeInBytes, unsigned int charSize, const sfUint32* charset);
+CSFML_API sfFont* sfFont_CreateFromMemory(const char* data, size_t sizeInBytes);
////////////////////////////////////////////////////////////
/// Destroy an existing font
@@ -66,15 +62,52 @@ CSFML_API sfFont* sfFont_CreateFromMemory(const char* data, size_t sizeInBytes,
CSFML_API void sfFont_Destroy(sfFont* font);
////////////////////////////////////////////////////////////
-/// Get the base size of characters in a font;
-/// All glyphs dimensions are based on this value
+/// Get a glyph in a font
///
-/// \param font : Font object
+/// \param font : Source font
+/// \param codePoint : Unicode code point of the character to get
+/// \param characterSize : Character size, in pixels
///
-/// \return Base size of characters
+/// \return The corresponding glyph
///
////////////////////////////////////////////////////////////
-CSFML_API unsigned int sfFont_GetCharacterSize(const sfFont* font);
+CSFML_API sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize);
+
+////////////////////////////////////////////////////////////
+/// Get the kerning value corresponding to a given pair of characters in a font
+///
+/// \param font : Source font
+/// \param first : Unicode code point of the first character
+/// \param second : Unicode code point of the second character
+/// \param characterSize : Character size, in pixels
+///
+/// \return Kerning offset, in pixels
+///
+////////////////////////////////////////////////////////////
+CSFML_API int sfFont_GetKerning(sfFont* font, sfUint32 first, sfUint32 second, unsigned int characterSize);
+
+////////////////////////////////////////////////////////////
+/// Get the line spacing value
+///
+/// \param font : Source font
+/// \param codePoint : Unicode code point of the character to get
+/// \param characterSize : Character size, in pixels
+///
+/// \return Line spacing, in pixels
+///
+////////////////////////////////////////////////////////////
+CSFML_API int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize);
+
+////////////////////////////////////////////////////////////
+/// Get the image containing the glyphs of a given size in a font
+///
+/// \param font : Source font
+/// \param characterSize : Character size, in pixels
+///
+/// \return Read-only pointer to the image
+///
+////////////////////////////////////////////////////////////
+CSFML_API const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize);
////////////////////////////////////////////////////////////
/// Get the built-in default font (Arial)
diff --git a/CSFML/include/SFML/Graphics/Text.h b/CSFML/include/SFML/Graphics/Text.h
index 5c367402..a30fdb0a 100644
--- a/CSFML/include/SFML/Graphics/Text.h
+++ b/CSFML/include/SFML/Graphics/Text.h
@@ -336,7 +336,7 @@ CSFML_API void sfText_SetFont(sfText* text, const sfFont* font);
/// \param size : New size, in pixels
///
////////////////////////////////////////////////////////////
-CSFML_API void sfText_SetSize(sfText* text, float size);
+CSFML_API void sfText_SetCharacterSize(sfText* text, unsigned int size);
////////////////////////////////////////////////////////////
/// Set the style of a text
@@ -385,7 +385,7 @@ CSFML_API const sfFont* sfText_GetFont(const sfText* text);
/// \return Size of the characters
///
////////////////////////////////////////////////////////////
-CSFML_API float sfText_GetSize(const sfText* text);
+CSFML_API unsigned int sfText_GetCharacterSize(const sfText* text);
////////////////////////////////////////////////////////////
/// Get the style of a text
diff --git a/CSFML/src/SFML/Graphics/Font.cpp b/CSFML/src/SFML/Graphics/Font.cpp
index 8e2b2207..e66395a1 100644
--- a/CSFML/src/SFML/Graphics/Font.cpp
+++ b/CSFML/src/SFML/Graphics/Font.cpp
@@ -33,17 +33,10 @@
////////////////////////////////////////////////////////////
/// Create a new font from a file
////////////////////////////////////////////////////////////
-sfFont* sfFont_CreateFromFile(const char* filename, unsigned int charSize, const sfUint32* charset)
+sfFont* sfFont_CreateFromFile(const char* filename)
{
sfFont* font = new sfFont;
-
- bool success = false;
- if (charset)
- success = font->This.LoadFromFile(filename, charSize, charset);
- else
- success = font->This.LoadFromFile(filename, charSize);
-
- if (!success)
+ if (!font->This.LoadFromFile(filename))
{
delete font;
font = NULL;
@@ -56,17 +49,10 @@ sfFont* sfFont_CreateFromFile(const char* filename, unsigned int charSize, const
////////////////////////////////////////////////////////////
/// Create a new font from a file in memory
////////////////////////////////////////////////////////////
-sfFont* sfFont_CreateFromMemory(const char* data, size_t sizeInBytes, unsigned int charSize, const sfUint32* charset)
+sfFont* sfFont_CreateFromMemory(const char* data, size_t sizeInBytes)
{
sfFont* font = new sfFont;
-
- bool success = false;
- if (charset)
- success = font->This.LoadFromMemory(data, sizeInBytes, charSize, charset);
- else
- success = font->This.LoadFromMemory(data, sizeInBytes, charSize);
-
- if (!success)
+ if (!font->This.LoadFromMemory(data, sizeInBytes))
{
delete font;
font = NULL;
@@ -86,12 +72,57 @@ void sfFont_Destroy(sfFont* font)
////////////////////////////////////////////////////////////
-/// Get the base size of characters in a font;
-/// All glyphs dimensions are based on this value
+/// Get a glyph in a font
////////////////////////////////////////////////////////////
-unsigned int sfFont_GetCharacterSize(const sfFont* font)
+sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize)
{
- CSFML_CALL_RETURN(font, GetCharacterSize(), 0);
+ sfGlyph glyph = {0, {0, 0, 0, 0}, {0, 0, 0, 0}};
+ CSFML_CHECK_RETURN(font, glyph);
+
+ sf::Glyph SFMLGlyph = font->This.GetGlyph(codePoint, characterSize);
+
+ glyph.Advance = SFMLGlyph.Advance;
+ glyph.Rectangle.Left = SFMLGlyph.Rectangle.Left;
+ glyph.Rectangle.Top = SFMLGlyph.Rectangle.Top;
+ glyph.Rectangle.Right = SFMLGlyph.Rectangle.Right;
+ glyph.Rectangle.Bottom = SFMLGlyph.Rectangle.Bottom;
+ glyph.TexCoords.Left = SFMLGlyph.TexCoords.Left;
+ glyph.TexCoords.Top = SFMLGlyph.TexCoords.Top;
+ glyph.TexCoords.Right = SFMLGlyph.TexCoords.Right;
+ glyph.TexCoords.Bottom = SFMLGlyph.TexCoords.Bottom;
+
+ return glyph;
+}
+
+
+////////////////////////////////////////////////////////////
+/// Get the kerning value corresponding to a given pair of characters in a font
+////////////////////////////////////////////////////////////
+int sfFont_GetKerning(sfFont* font, sfUint32 first, sfUint32 second, unsigned int characterSize)
+{
+ CSFML_CALL_RETURN(font, GetKerning(first, second, characterSize), 0);
+}
+
+
+////////////////////////////////////////////////////////////
+/// Get the line spacing value
+////////////////////////////////////////////////////////////
+int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize)
+{
+ CSFML_CALL_RETURN(font, GetLineSpacing(characterSize), 0);
+}
+
+
+////////////////////////////////////////////////////////////
+/// Get the image containing the glyphs of a given size in a font
+////////////////////////////////////////////////////////////
+const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
+{
+ CSFML_CHECK_RETURN(font, NULL);
+
+ *font->Images[characterSize].This = font->This.GetImage(characterSize);
+
+ return &font->Images[characterSize];
}
diff --git a/CSFML/src/SFML/Graphics/FontStruct.h b/CSFML/src/SFML/Graphics/FontStruct.h
index 08a31f17..019ea773 100644
--- a/CSFML/src/SFML/Graphics/FontStruct.h
+++ b/CSFML/src/SFML/Graphics/FontStruct.h
@@ -29,6 +29,8 @@
// Headers
////////////////////////////////////////////////////////////
#include
+#include
+#include
-
-
-
-
diff --git a/build/vc2008/SFML.sln b/build/vc2008/SFML.sln
index 8442ed71..fa803a74 100644
--- a/build/vc2008/SFML.sln
+++ b/build/vc2008/SFML.sln
@@ -14,6 +14,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfml-main", "sfml-main.vcproj", "{2BD26A09-E1B6-42E2-A0D0-63987B76BB97}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfml-network", "sfml-network.vcproj", "{823DDC98-42D5-4A38-88CF-9DC06C788AE4}"
+ ProjectSection(ProjectDependencies) = postProject
+ {C061A27D-7CA0-4179-9869-672FA04A86A8} = {C061A27D-7CA0-4179-9869-672FA04A86A8}
+ EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfml-system", "sfml-system.vcproj", "{C061A27D-7CA0-4179-9869-672FA04A86A8}"
EndProject
diff --git a/build/vc2008/sfml-graphics.vcproj b/build/vc2008/sfml-graphics.vcproj
index feb22c5e..1954e795 100644
--- a/build/vc2008/sfml-graphics.vcproj
+++ b/build/vc2008/sfml-graphics.vcproj
@@ -3433,14 +3433,6 @@
RelativePath="..\..\include\SFML\Graphics\Font.hpp"
>
-
-
-
-
diff --git a/dotnet/extlibs/csfml-audio.dll b/dotnet/extlibs/csfml-audio.dll
index cd78f3c7..2e2ffb2c 100644
Binary files a/dotnet/extlibs/csfml-audio.dll and b/dotnet/extlibs/csfml-audio.dll differ
diff --git a/dotnet/extlibs/csfml-graphics.dll b/dotnet/extlibs/csfml-graphics.dll
index 6337dc10..496f2b87 100644
Binary files a/dotnet/extlibs/csfml-graphics.dll and b/dotnet/extlibs/csfml-graphics.dll differ
diff --git a/dotnet/extlibs/csfml-window.dll b/dotnet/extlibs/csfml-window.dll
index b45310ae..556dbca0 100644
Binary files a/dotnet/extlibs/csfml-window.dll and b/dotnet/extlibs/csfml-window.dll differ
diff --git a/dotnet/samples/shader/Shader.cs b/dotnet/samples/shader/Shader.cs
index a8a765a2..3ded018b 100644
--- a/dotnet/samples/shader/Shader.cs
+++ b/dotnet/samples/shader/Shader.cs
@@ -93,7 +93,7 @@ namespace sample_shader
Sprite entity = new Sprite(new Image("datas/shader/sprite.png"));
// Load the text font
- Font font = new Font("datas/shader/arial.ttf", 20);
+ Font font = new Font("datas/shader/arial.ttf");
// Load the image needed for the wave effect
Image waveImage = new Image("datas/shader/wave.jpg");
@@ -135,7 +135,7 @@ namespace sample_shader
Text infoText = new Text();
infoText.Font = font;
infoText.Size = 20;
- infoText.Position = new Vector2(5.0F, 510.0F);
+ infoText.Position = new Vector2(5.0F, 500.0F);
infoText.Color = new Color(250, 100, 30);
infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
"Press numpad 1 to change the background shader\n" +
diff --git a/dotnet/src/Graphics/Font.cs b/dotnet/src/Graphics/Font.cs
index 273d2d6c..91ffb66c 100644
--- a/dotnet/src/Graphics/Font.cs
+++ b/dotnet/src/Graphics/Font.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using System.IO;
@@ -7,6 +8,24 @@ namespace SFML
{
namespace Graphics
{
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Structure describing a glyph (a visual character)
+ ///
+ ////////////////////////////////////////////////////////////
+ [StructLayout(LayoutKind.Sequential)]
+ public struct Glyph
+ {
+ /// Offset to move horizontically to the next character
+ public int Advance;
+
+ /// Bounding rectangle of the glyph, in coordinates relative to the baseline
+ public IntRect Rectangle;
+
+ /// Texture coordinates of the glyph inside the font's image
+ public FloatRect TexCoords;
+ }
+
////////////////////////////////////////////////////////////
///
/// Font is the low-level class for loading and
@@ -24,47 +43,8 @@ namespace SFML
///
////////////////////////////////////////////////////////////
public Font(string filename) :
- this(filename, 30)
+ base(sfFont_CreateFromFile(filename))
{
- }
-
- ////////////////////////////////////////////////////////////
- ///
- /// Construct the font from a file, using custom size
- ///
- /// Font file to load
- /// Character size
- ///
- ////////////////////////////////////////////////////////////
- public Font(string filename, uint charSize) :
- this(filename, charSize, "")
- {
- }
-
- ////////////////////////////////////////////////////////////
- ///
- /// Construct the font from a file, using custom size and characters set
- ///
- /// Font file to load
- /// Character size
- /// Set of characters to generate
- ///
- ////////////////////////////////////////////////////////////
- public Font(string filename, uint charSize, string charset) :
- base(IntPtr.Zero)
- {
- unsafe
- {
- IntPtr ptr;
- int size;
- if (Int32.TryParse(charset, out size))
- ptr = new IntPtr(&size);
- else
- ptr = IntPtr.Zero;
-
- SetThis(sfFont_CreateFromFile(filename, charSize, ptr));
- }
-
if (This == IntPtr.Zero)
throw new LoadingFailedException("font", filename);
}
@@ -77,64 +57,73 @@ namespace SFML
///
////////////////////////////////////////////////////////////
public Font(Stream stream) :
- this(stream, 30)
- {
- }
-
- ////////////////////////////////////////////////////////////
- ///
- /// Construct the font from a file in a stream, using custom size
- ///
- /// Stream containing the file contents
- /// Character size
- ///
- ////////////////////////////////////////////////////////////
- public Font(Stream stream, uint charSize) :
- this(stream, charSize, "")
- {
- }
-
- ////////////////////////////////////////////////////////////
- ///
- /// Construct the font from a file in a stream
- ///
- /// Stream containing the file contents
- /// Character size
- /// Set of characters to generate
- ///
- ////////////////////////////////////////////////////////////
- public Font(Stream stream, uint charSize, string charset) :
base(IntPtr.Zero)
{
unsafe
{
- IntPtr ptr;
- int size;
- if (Int32.TryParse(charset, out size))
- ptr = new IntPtr(&size);
- else
- ptr = IntPtr.Zero;
-
stream.Position = 0;
byte[] StreamData = new byte[stream.Length];
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
fixed (byte* dataPtr = StreamData)
{
- SetThis(sfFont_CreateFromMemory((char*)dataPtr, Read, charSize, ptr));
+ SetThis(sfFont_CreateFromMemory((char*)dataPtr, Read));
}
}
+
if (This == IntPtr.Zero)
throw new LoadingFailedException("font");
}
////////////////////////////////////////////////////////////
///
- /// Base character size
+ /// Get a glyph in the font
///
+ /// Unicode code point of the character to get
+ /// Character size
+ /// The glyph corresponding to the character
////////////////////////////////////////////////////////////
- public uint CharacterSize
+ public Glyph GetGlyph(uint codePoint, uint characterSize)
{
- get { return sfFont_GetCharacterSize(This); }
+ return sfFont_GetGlyph(This, codePoint, characterSize);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the kerning offset between two glyphs
+ ///
+ /// Unicode code point of the first character
+ /// Unicode code point of the second character
+ /// Character size
+ /// Kerning offset, in pixels
+ ////////////////////////////////////////////////////////////
+ public int GetKerning(uint first, uint second, uint characterSize)
+ {
+ return sfFont_GetKerning(This, first, second, characterSize);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get spacing between two consecutive lines
+ ///
+ /// Character size
+ /// Line spacing, in pixels
+ ////////////////////////////////////////////////////////////
+ public int GetLineSpacing(uint characterSize)
+ {
+ return sfFont_GetLineSpacing(This, characterSize);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the image containing the glyphs of a given size
+ ///
+ /// Character size
+ /// Image storing the glyphs for the given size
+ ////////////////////////////////////////////////////////////
+ public Image GetImage(uint characterSize)
+ {
+ myImages[characterSize] = new Image(sfFont_GetImage(This, characterSize));
+ return myImages[characterSize];
}
////////////////////////////////////////////////////////////
@@ -168,6 +157,12 @@ namespace SFML
sfFont_Destroy(This);
+ if (disposing)
+ {
+ foreach (Image image in myImages.Values)
+ image.Dispose();
+ }
+
if (!disposing)
Context.Global.SetActive(false);
}
@@ -184,20 +179,30 @@ namespace SFML
{
}
+ private Dictionary myImages = new Dictionary();
private static Font ourDefaultFont = null;
#region Imports
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
- static extern IntPtr sfFont_CreateFromFile(string Filename, uint CharSize, IntPtr Charset);
+ static extern IntPtr sfFont_CreateFromFile(string Filename);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
- unsafe static extern IntPtr sfFont_CreateFromMemory(char* Data, uint SizeInBytes, uint CharSize, IntPtr Charset);
+ unsafe static extern IntPtr sfFont_CreateFromMemory(char* Data, uint SizeInBytes);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfFont_Destroy(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
- static extern uint sfFont_GetCharacterSize(IntPtr This);
+ static extern Glyph sfFont_GetGlyph(IntPtr This, uint codePoint, uint characterSize);
+
+ [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
+ static extern int sfFont_GetKerning(IntPtr This, uint first, uint second, uint characterSize);
+
+ [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
+ static extern int sfFont_GetLineSpacing(IntPtr This, uint characterSize);
+
+ [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
+ static extern IntPtr sfFont_GetImage(IntPtr This, uint characterSize);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfFont_GetDefaultFont();
diff --git a/dotnet/src/Graphics/Text.cs b/dotnet/src/Graphics/Text.cs
index e686d394..42ed4b23 100644
--- a/dotnet/src/Graphics/Text.cs
+++ b/dotnet/src/Graphics/Text.cs
@@ -211,10 +211,10 @@ namespace SFML
/// Base size of characters
///
////////////////////////////////////////////////////////////
- public float Size
+ public uint Size
{
- get {return sfText_GetSize(This);}
- set {sfText_SetSize(This, value);}
+ get {return sfText_GetCharacterSize(This);}
+ set {sfText_SetCharacterSize(This, value);}
}
////////////////////////////////////////////////////////////
@@ -376,7 +376,7 @@ namespace SFML
static extern void sfText_SetFont(IntPtr This, IntPtr Font);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
- static extern void sfText_SetSize(IntPtr This, float Size);
+ static extern void sfText_SetCharacterSize(IntPtr This, uint Size);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfText_SetStyle(IntPtr This, Styles Style);
@@ -385,7 +385,7 @@ namespace SFML
static extern string sfText_GetString(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
- static extern float sfText_GetSize(IntPtr This);
+ static extern uint sfText_GetCharacterSize(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern Styles sfText_GetStyle(IntPtr This);
diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp
index 318209d4..de3798b8 100644
--- a/include/SFML/Graphics/Font.hpp
+++ b/include/SFML/Graphics/Font.hpp
@@ -36,109 +36,328 @@
#include
#include