Complete rewrite of sf::Font to make it more flexible (no more fixed charset and size)

FS#125 - Fix tab character not working in sf::String

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1309 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-12-13 15:49:30 +00:00
parent 839c80556d
commit 3a34f81561
32 changed files with 1016 additions and 3016 deletions

View file

@ -232,6 +232,10 @@
RelativePath="..\..\src\SFML\Graphics\FontStruct.h"
>
</File>
<File
RelativePath="..\..\include\SFML\Graphics\Glyph.h"
>
</File>
<File
RelativePath="..\..\src\SFML\Graphics\Image.cpp"
>

View file

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

View file

@ -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

View file

@ -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];
}

View file

@ -29,6 +29,8 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <map>
////////////////////////////////////////////////////////////
@ -37,6 +39,7 @@
struct sfFont
{
sf::Font This;
std::map<unsigned int, sfImage> Images;
};

View file

@ -42,9 +42,9 @@ struct sfImage
OwnInstance = true;
}
sfImage(sf::Image* Image)
sfImage(sf::Image* image)
{
This = Image;
This = image;
OwnInstance = false;
}

View file

@ -320,9 +320,9 @@ void sfText_SetFont(sfText* text, const sfFont* font)
////////////////////////////////////////////////////////////
/// Set the size of a string
////////////////////////////////////////////////////////////
void sfText_SetSize(sfText* text, float size)
void sfText_SetCharacterSize(sfText* text, unsigned int size)
{
CSFML_CALL(text, SetSize(size))
CSFML_CALL(text, SetCharacterSize(size))
}
@ -373,9 +373,9 @@ const sfFont* sfText_GetFont(const sfText* text)
////////////////////////////////////////////////////////////
/// Get the size of the characters of a text
////////////////////////////////////////////////////////////
float sfText_GetSize(const sfText* text)
unsigned int sfText_GetCharacterSize(const sfText* text)
{
CSFML_CALL_RETURN(text, GetSize(), 0.f)
CSFML_CALL_RETURN(text, GetCharacterSize(), 0.f)
}

View file

@ -127,7 +127,10 @@ EXPORTS
sfFont_CreateFromFile
sfFont_CreateFromMemory
sfFont_Destroy
sfFont_GetCharacterSize
sfFont_GetGlyph
sfFont_GetKerning
sfFont_GetLineSpacing
sfFont_GetImage
sfFont_GetDefaultFont
sfText_Create
sfText_Destroy
@ -158,12 +161,12 @@ EXPORTS
sfText_SetString
sfText_SetUnicodeString
sfText_SetFont
sfText_SetSize
sfText_SetCharacterSize
sfText_SetStyle
sfText_GetUnicodeString
sfText_GetString
sfText_GetFont
sfText_GetSize
sfText_GetCharacterSize
sfText_GetStyle
sfText_GetCharacterPos
sfText_GetRect

View file

@ -127,7 +127,10 @@ EXPORTS
sfFont_CreateFromFile
sfFont_CreateFromMemory
sfFont_Destroy
sfFont_GetCharacterSize
sfFont_GetGlyph
sfFont_GetKerning
sfFont_GetLineSpacing
sfFont_GetImage
sfFont_GetDefaultFont
sfText_Create
sfText_Destroy
@ -158,12 +161,12 @@ EXPORTS
sfText_SetString
sfText_SetUnicodeString
sfText_SetFont
sfText_SetSize
sfText_SetCharacterSize
sfText_SetStyle
sfText_GetUnicodeString
sfText_GetString
sfText_GetFont
sfText_GetSize
sfText_GetCharacterSize
sfText_GetStyle
sfText_GetCharacterPos
sfText_GetRect