FS#90 - Improve Unicode string classes

Added the sf::String class to replace (and enhance) sf::Unicode::Text
FS#138 - Rename sf::String to sf::Text


git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1286 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-11-26 08:07:38 +00:00
parent 9f063921c9
commit 78247bd386
46 changed files with 3003 additions and 1725 deletions

View File

@ -318,15 +318,15 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\String.cpp" RelativePath="..\..\src\SFML\Graphics\Text.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\Graphics\String.h" RelativePath="..\..\include\SFML\Graphics\Text.h"
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\StringStruct.h" RelativePath="..\..\src\SFML\Graphics\TextStruct.h"
> >
</File> </File>
<File <File

View File

@ -313,15 +313,15 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\String.cpp" RelativePath="..\..\src\SFML\Graphics\Text.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\Graphics\String.h" RelativePath="..\..\include\SFML\Graphics\Text.h"
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\StringStruct.h" RelativePath="..\..\src\SFML\Graphics\TextStruct.h"
> >
</File> </File>
<File <File

View File

@ -59,12 +59,12 @@
<Unit filename="..\..\include\SFML\Graphics\Color.h" /> <Unit filename="..\..\include\SFML\Graphics\Color.h" />
<Unit filename="..\..\include\SFML\Graphics\Font.h" /> <Unit filename="..\..\include\SFML\Graphics\Font.h" />
<Unit filename="..\..\include\SFML\Graphics\Image.h" /> <Unit filename="..\..\include\SFML\Graphics\Image.h" />
<Unit filename="..\..\include\SFML\Graphics\Shader.h" />
<Unit filename="..\..\include\SFML\Graphics\Rect.h" /> <Unit filename="..\..\include\SFML\Graphics\Rect.h" />
<Unit filename="..\..\include\SFML\Graphics\RenderWindow.h" /> <Unit filename="..\..\include\SFML\Graphics\RenderWindow.h" />
<Unit filename="..\..\include\SFML\Graphics\Shader.h" />
<Unit filename="..\..\include\SFML\Graphics\Shape.h" /> <Unit filename="..\..\include\SFML\Graphics\Shape.h" />
<Unit filename="..\..\include\SFML\Graphics\Sprite.h" /> <Unit filename="..\..\include\SFML\Graphics\Sprite.h" />
<Unit filename="..\..\include\SFML\Graphics\String.h" /> <Unit filename="..\..\include\SFML\Graphics\Text.h" />
<Unit filename="..\..\include\SFML\Graphics\Types.h" /> <Unit filename="..\..\include\SFML\Graphics\Types.h" />
<Unit filename="..\..\include\SFML\Graphics\View.h" /> <Unit filename="..\..\include\SFML\Graphics\View.h" />
<Unit filename="..\..\src\SFML\Graphics\Color.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Color.cpp" />
@ -72,19 +72,20 @@
<Unit filename="..\..\src\SFML\Graphics\FontStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\FontStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Image.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Image.cpp" />
<Unit filename="..\..\src\SFML\Graphics\ImageStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\ImageStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
<Unit filename="..\..\src\SFML\Graphics\ShaderStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Rect.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Rect.cpp" />
<Unit filename="..\..\src\SFML\Graphics\RenderImage.cpp" /> <Unit filename="..\..\src\SFML\Graphics\RenderImage.cpp" />
<Unit filename="..\..\src\SFML\Graphics\RenderImageStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\RenderImageStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\RenderWindow.cpp" /> <Unit filename="..\..\src\SFML\Graphics\RenderWindow.cpp" />
<Unit filename="..\..\src\SFML\Graphics\RenderWindowStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\RenderWindowStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
<Unit filename="..\..\src\SFML\Graphics\ShaderStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Shape.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Shape.cpp" />
<Unit filename="..\..\src\SFML\Graphics\ShapeStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\ShapeStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" />
<Unit filename="..\..\src\SFML\Graphics\SpriteStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\SpriteStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\String.cpp" />
<Unit filename="..\..\src\SFML\Graphics\StringStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\StringStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\Text.cpp" />
<Unit filename="..\..\src\SFML\Graphics\TextStruct.h" />
<Unit filename="..\..\src\SFML\Graphics\View.cpp" /> <Unit filename="..\..\src\SFML\Graphics\View.cpp" />
<Unit filename="..\..\src\SFML\Graphics\ViewStruct.h" /> <Unit filename="..\..\src\SFML\Graphics\ViewStruct.h" />
<Extensions> <Extensions>

View File

@ -112,25 +112,25 @@ CSFML_API void sfRenderImage_Display(sfRenderImage* renderImage);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Draw something on a renderimage /// Draw something on a renderimage
/// ///
/// \param renderImage : Renderimage to draw in /// \param renderImage : Renderimage to draw in
/// \param sprite / string / shape : Object to draw /// \param sprite / text / shape : Object to draw
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_DrawSprite(sfRenderImage* renderImage, sfSprite* sprite); CSFML_API void sfRenderImage_DrawSprite(sfRenderImage* renderImage, sfSprite* sprite);
CSFML_API void sfRenderImage_DrawShape (sfRenderImage* renderImage, sfShape* shape); CSFML_API void sfRenderImage_DrawShape (sfRenderImage* renderImage, sfShape* shape);
CSFML_API void sfRenderImage_DrawString(sfRenderImage* renderImage, sfString* string); CSFML_API void sfRenderImage_DrawText (sfRenderImage* renderImage, sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Draw something on a renderimage with a shader /// Draw something on a renderimage with a shader
/// ///
/// \param renderImage : Renderimage to draw in /// \param renderImage : Renderimage to draw in
/// \param sprite / string / shape : Object to draw /// \param sprite / text / shape : Object to draw
/// \param shader : Shader to use /// \param shader : Shader to use
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, sfSprite* sprite, sfShader* shader); CSFML_API void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, sfSprite* sprite, sfShader* shader);
CSFML_API void sfRenderImage_DrawShapeWithShader (sfRenderImage* renderImage, sfShape* shape, sfShader* shader); CSFML_API void sfRenderImage_DrawShapeWithShader (sfRenderImage* renderImage, sfShape* shape, sfShader* shader);
CSFML_API void sfRenderImage_DrawStringWithShader(sfRenderImage* renderImage, sfString* string, sfShader* shader); CSFML_API void sfRenderImage_DrawTextWithShader (sfRenderImage* renderImage, sfText* text, sfShader* shader);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Clear the renderimage with the given color /// Clear the renderimage with the given color

View File

@ -292,25 +292,25 @@ CSFML_API void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow,
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Draw something on a renderwindow /// Draw something on a renderwindow
/// ///
/// \param renderWindow : Renderwindow to draw in /// \param renderWindow : Renderwindow to draw in
/// \param sprite / string / shape : Object to draw /// \param sprite / text / shape : Object to draw
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, sfSprite* sprite); CSFML_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, sfSprite* sprite);
CSFML_API void sfRenderWindow_DrawShape (sfRenderWindow* renderWindow, sfShape* shape); CSFML_API void sfRenderWindow_DrawShape (sfRenderWindow* renderWindow, sfShape* shape);
CSFML_API void sfRenderWindow_DrawString(sfRenderWindow* renderWindow, sfString* string); CSFML_API void sfRenderWindow_DrawText (sfRenderWindow* renderWindow, sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Draw something on a renderwindow with a shader /// Draw something on a renderwindow with a shader
/// ///
/// \param renderWindow : Renderwindow to draw in /// \param renderWindow : Renderwindow to draw in
/// \param sprite / string / shape : Object to draw /// \param sprite / text / shape : Object to draw
/// \param shader : Shader to use /// \param shader : Shader to use
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, sfSprite* sprite, sfShader* shader); CSFML_API void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, sfSprite* sprite, sfShader* shader);
CSFML_API void sfRenderWindow_DrawShapeWithShader (sfRenderWindow* renderWindow, sfShape* shape, sfShader* shader); CSFML_API void sfRenderWindow_DrawShapeWithShader (sfRenderWindow* renderWindow, sfShape* shape, sfShader* shader);
CSFML_API void sfRenderWindow_DrawStringWithShader(sfRenderWindow* renderWindow, sfString* string, sfShader* shader); CSFML_API void sfRenderWindow_DrawTextWithShader (sfRenderWindow* renderWindow, sfText* text, sfShader* shader);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Clear the screen with the given color /// Clear the screen with the given color

View File

@ -22,8 +22,8 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef SFML_STRING_H #ifndef SFML_TEXT_H
#define SFML_STRING_H #define SFML_TEXT_H
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
@ -36,389 +36,389 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// sfString styles /// sfText styles
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef enum typedef enum
{ {
sfStringRegular = 0, ///< Regular characters, no style sfTextRegular = 0, ///< Regular characters, no style
sfStringBold = 1 << 0, ///< Characters are bold sfTextBold = 1 << 0, ///< Characters are bold
sfStringItalic = 1 << 1, ///< Characters are in italic sfTextItalic = 1 << 1, ///< Characters are in italic
sfStringUnderlined = 1 << 2 ///< Characters are underlined sfTextUnderlined = 1 << 2 ///< Characters are underlined
} sfStringStyle; } sfTextStyle;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create a new string /// Create a new text
/// ///
/// \return A new sfString object, or NULL if it failed /// \return A new sfText object, or NULL if it failed
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfString* sfString_Create(); CSFML_API sfText* sfText_Create();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing string /// Destroy an existing text
/// ///
/// \param string : String to delete /// \param text : Text to delete
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_Destroy(sfString* string); CSFML_API void sfText_Destroy(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the X position of a string /// Set the X position of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param x : New X coordinate /// \param x : New X coordinate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetX(sfString* string, float x); CSFML_API void sfText_SetX(sfText* text, float x);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the Y position of a string /// Set the Y position of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param y : New Y coordinate /// \param y : New Y coordinate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetY(sfString* string, float y); CSFML_API void sfText_SetY(sfText* text, float y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the position of a string /// Set the position of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param x : New X coordinate /// \param x : New X coordinate
/// \param y : New Y coordinate /// \param y : New Y coordinate
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetPosition(sfString* string, float x, float y); CSFML_API void sfText_SetPosition(sfText* text, float x, float y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the horizontal scale of a string /// Set the horizontal scale of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param scale : New scale (must be strictly positive) /// \param scale : New scale (must be strictly positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetScaleX(sfString* string, float scale); CSFML_API void sfText_SetScaleX(sfText* text, float scale);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the vertical scale of a string /// Set the vertical scale of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param scale : New scale (must be strictly positive) /// \param scale : New scale (must be strictly positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetScaleY(sfString* string, float scale); CSFML_API void sfText_SetScaleY(sfText* text, float scale);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the scale of a string /// Set the scale of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param scaleX : New horizontal scale (must be strictly positive) /// \param scaleX : New horizontal scale (must be strictly positive)
/// \param scaleY : New vertical scale (must be strictly positive) /// \param scaleY : New vertical scale (must be strictly positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetScale(sfString* string, float scaleX, float scaleY); CSFML_API void sfText_SetScale(sfText* text, float scaleX, float scaleY);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the orientation of a string /// Set the orientation of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param rotation : Angle of rotation, in degrees /// \param rotation : Angle of rotation, in degrees
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetRotation(sfString* string, float rotation); CSFML_API void sfText_SetRotation(sfText* text, float rotation);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the local origin of a string, in coordinates /// Set the local origin of a text, in coordinates
/// relative to its left-top corner /// relative to its left-top corner
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param x : X coordinate of the origin /// \param x : X coordinate of the origin
/// \param y : Y coordinate of the origin /// \param y : Y coordinate of the origin
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetOrigin(sfString* string, float x, float y); CSFML_API void sfText_SetOrigin(sfText* text, float x, float y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the color of a string /// Set the color of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param color : New color /// \param color : New color
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetColor(sfString* string, sfColor color); CSFML_API void sfText_SetColor(sfText* text, sfColor color);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the blending mode for a string /// Set the blending mode for a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param mode : New blending mode /// \param mode : New blending mode
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetBlendMode(sfString* string, sfBlendMode mode); CSFML_API void sfText_SetBlendMode(sfText* text, sfBlendMode mode);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the X position of a string /// Get the X position of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current X position /// \return Current X position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetX(sfString* string); CSFML_API float sfText_GetX(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the top Y of a string /// Get the top Y of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current Y position /// \return Current Y position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetY(sfString* string); CSFML_API float sfText_GetY(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the horizontal scale of a string /// Get the horizontal scale of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current X scale factor (always positive) /// \return Current X scale factor (always positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetScaleX(sfString* string); CSFML_API float sfText_GetScaleX(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the vertical scale of a string /// Get the vertical scale of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current Y scale factor (always positive) /// \return Current Y scale factor (always positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetScaleY(sfString* string); CSFML_API float sfText_GetScaleY(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the orientation of a string /// Get the orientation of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current rotation, in degrees /// \return Current rotation, in degrees
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetRotation(sfString* string); CSFML_API float sfText_GetRotation(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the X position of the origin a string /// Get the X position of the origin a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current X origin position /// \return Current X origin position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetOriginX(sfString* string); CSFML_API float sfText_GetOriginX(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the top Y of the origin of a string /// Get the top Y of the origin of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current Y origin position /// \return Current Y origin position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetOriginY(sfString* string); CSFML_API float sfText_GetOriginY(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the color of a string /// Get the color of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current color /// \return Current color
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfColor sfString_GetColor(sfString* string); CSFML_API sfColor sfText_GetColor(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the current blending mode of a string /// Get the current blending mode of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current blending mode /// \return Current blending mode
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfBlendMode sfString_GetBlendMode(sfString* string); CSFML_API sfBlendMode sfText_GetBlendMode(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Move a string /// Move a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param offsetX : Offset on the X axis /// \param offsetX : Offset on the X axis
/// \param offsetY : Offset on the Y axis /// \param offsetY : Offset on the Y axis
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_Move(sfString* string, float offsetX, float offsetY); CSFML_API void sfText_Move(sfText* text, float offsetX, float offsetY);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Scale a string /// Scale a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param factorX : Horizontal scaling factor (must be strictly positive) /// \param factorX : Horizontal scaling factor (must be strictly positive)
/// \param factorY : Vertical scaling factor (must be strictly positive) /// \param factorY : Vertical scaling factor (must be strictly positive)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_Scale(sfString* string, float factorX, float factorY); CSFML_API void sfText_Scale(sfText* text, float factorX, float factorY);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Rotate a string /// Rotate a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param angle : Angle of rotation, in degrees /// \param angle : Angle of rotation, in degrees
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_Rotate(sfString* string, float angle); CSFML_API void sfText_Rotate(sfText* text, float angle);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into the string's local coordinates /// Transform a point from global coordinates into the string's local coordinates
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) /// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
/// ///
/// \param string : String object /// \param text : String object
/// \param pointX : X coordinate of the point to transform /// \param pointX : X coordinate of the point to transform
/// \param pointY : Y coordinate of the point to transform /// \param pointY : Y coordinate of the point to transform
/// \param x : Value to fill with the X coordinate of the converted point /// \param x : Value to fill with the X coordinate of the converted point
/// \param y : Value to fill with the y coordinate of the converted point /// \param y : Value to fill with the y coordinate of the converted point
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_TransformToLocal(sfString* string, float pointX, float pointY, float* x, float* y); CSFML_API void sfText_TransformToLocal(sfText* text, float pointX, float pointY, float* x, float* y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Transform a point from the string's local coordinates into global coordinates /// Transform a point from the string's local coordinates into global coordinates
/// (ie it applies the object's origin, translation, rotation and scale to the point) /// (ie it applies the object's origin, translation, rotation and scale to the point)
/// ///
/// \param string : String object /// \param text : String object
/// \param pointX : X coordinate of the point to transform /// \param pointX : X coordinate of the point to transform
/// \param pointY : Y coordinate of the point to transform /// \param pointY : Y coordinate of the point to transform
/// \param x : Value to fill with the X coordinate of the converted point /// \param x : Value to fill with the X coordinate of the converted point
/// \param y : Value to fill with the y coordinate of the converted point /// \param y : Value to fill with the y coordinate of the converted point
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_TransformToGlobal(sfString* string, float pointX, float pointY, float* X, float* y); CSFML_API void sfText_TransformToGlobal(sfText* text, float pointX, float pointY, float* X, float* y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text of a string (from a multibyte string) /// Set the string of a text (from a multibyte string)
/// ///
/// \param string : String to modify /// \param text : Text to modify
/// \param text : New text /// \param string : New string
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetText(sfString* string, const char* text); CSFML_API void sfText_SetString(sfText* text, const char* string);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text of a string (from a unicode string) /// Set the string of a text (from a unicode string)
/// ///
/// \param string : String to modify /// \param text : Text to modify
/// \param text : New text /// \param string : New string
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetUnicodeText(sfString* string, const sfUint32* text); CSFML_API void sfText_SetUnicodeString(sfText* text, const sfUint32* string);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the font of a string /// Set the font of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param font : Font to use /// \param font : Font to use
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetFont(sfString* string, sfFont* font); CSFML_API void sfText_SetFont(sfText* text, sfFont* font);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the size of a string /// Set the size of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param size : New size, in pixels /// \param size : New size, in pixels
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetSize(sfString* string, float size); CSFML_API void sfText_SetSize(sfText* text, float size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the style of a string /// Set the style of a text
/// ///
/// \param string : String to modify /// \param text : String to modify
/// \param style : New style (see sfStringStyle enum) /// \param style : New style (see sfTextStyle enum)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_SetStyle(sfString* string, unsigned long style); CSFML_API void sfText_SetStyle(sfText* text, unsigned long style);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the text of a string (returns a unicode string) /// Get the string of a text (returns a unicode string)
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Text as UTF-32 /// \return String as UTF-32
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API const sfUint32* sfString_GetUnicodeText(sfString* string); CSFML_API const sfUint32* sfText_GetUnicodeString(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the text of a string (returns an ANSI string) /// Get the text of a text (returns an ANSI string)
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Text an a locale-dependant ANSI string /// \return String an a locale-dependant ANSI string
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API const char* sfString_GetText(sfString* string); CSFML_API const char* sfText_GetString(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the font used by a string /// Get the font used by a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Pointer to the font /// \return Pointer to the font
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfFont* sfString_GetFont(sfString* string); CSFML_API sfFont* sfText_GetFont(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the size of the characters of a string /// Get the size of the characters of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Size of the characters /// \return Size of the characters
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API float sfString_GetSize(sfString* string); CSFML_API float sfText_GetSize(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the style of a string /// Get the style of a text
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Current string style (see sfStringStyle enum) /// \return Current string style (see sfTextStyle enum)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API unsigned long sfString_GetStyle(sfString* string); CSFML_API unsigned long sfText_GetStyle(sfText* text);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Return the visual position of the Index-th character of the string, /// Return the visual position of the Index-th character of the text,
/// in coordinates relative to the string /// in coordinates relative to the string
/// (note : translation, origin, rotation and scale are not applied) /// (note : translation, origin, rotation and scale are not applied)
/// ///
/// \param string : String to read /// \param text : String to read
/// \param index : Index of the character /// \param index : Index of the character
/// \param x : Value to fill with the X coordinate of the position /// \param x : Value to fill with the X coordinate of the position
/// \param y : Value to fill with the y coordinate of the position /// \param y : Value to fill with the y coordinate of the position
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API void sfString_GetCharacterPos(sfString* string, size_t index, float* x, float* y); CSFML_API void sfText_GetCharacterPos(sfText* text, size_t index, float* x, float* y);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the bounding rectangle of a string on screen /// Get the bounding rectangle of a text on screen
/// ///
/// \param string : String to read /// \param text : String to read
/// ///
/// \return Rectangle contaning the string in screen coordinates /// \return Rectangle contaning the string in screen coordinates
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfFloatRect sfString_GetRect(sfString* string); CSFML_API sfFloatRect sfText_GetRect(sfText* text);
#endif // SFML_STRING_H #endif // SFML_TEXT_H

View File

@ -33,7 +33,7 @@ typedef struct sfRenderImage sfRenderImage;
typedef struct sfRenderWindow sfRenderWindow; typedef struct sfRenderWindow sfRenderWindow;
typedef struct sfShape sfShape; typedef struct sfShape sfShape;
typedef struct sfSprite sfSprite; typedef struct sfSprite sfSprite;
typedef struct sfString sfString; typedef struct sfText sfText;
typedef struct sfView sfView; typedef struct sfView sfView;

View File

@ -30,7 +30,7 @@
#include <SFML/Graphics/ShapeStruct.h> #include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h> #include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h> #include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/StringStruct.h> #include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h> #include <SFML/Internal.h>
@ -128,10 +128,10 @@ void sfRenderImage_DrawShape(sfRenderImage* renderImage, sfShape* shape)
CSFML_CHECK(shape); CSFML_CHECK(shape);
CSFML_CALL(renderImage, Draw(shape->This)); CSFML_CALL(renderImage, Draw(shape->This));
} }
void sfRenderImage_DrawString(sfRenderImage* renderImage, sfString* string) void sfRenderImage_DrawText(sfRenderImage* renderImage, sfText* text)
{ {
CSFML_CHECK(string); CSFML_CHECK(text);
CSFML_CALL(renderImage, Draw(string->This)); CSFML_CALL(renderImage, Draw(text->This));
} }
@ -150,11 +150,11 @@ void sfRenderImage_DrawShapeWithShader(sfRenderImage* renderImage, sfShape* shap
CSFML_CHECK(shader); CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(shape->This, shader->This)); CSFML_CALL(renderImage, Draw(shape->This, shader->This));
} }
void sfRenderImage_DrawStringWithShader(sfRenderImage* renderImage, sfString* string, sfShader* shader) void sfRenderImage_DrawTextWithShader(sfRenderImage* renderImage, sfText* text, sfShader* shader)
{ {
CSFML_CHECK(string); CSFML_CHECK(text);
CSFML_CHECK(shader); CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(string->This, shader->This)); CSFML_CALL(renderImage, Draw(text->This, shader->This));
} }

View File

@ -31,7 +31,7 @@
#include <SFML/Graphics/ShaderStruct.h> #include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/ImageStruct.h> #include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/SpriteStruct.h> #include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/StringStruct.h> #include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h> #include <SFML/Internal.h>
#include <SFML/ConvertEvent.h> #include <SFML/ConvertEvent.h>
@ -366,10 +366,10 @@ void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, sfShape* shape)
CSFML_CHECK(shape); CSFML_CHECK(shape);
CSFML_CALL(renderWindow, Draw(shape->This)); CSFML_CALL(renderWindow, Draw(shape->This));
} }
void sfRenderWindow_DrawString(sfRenderWindow* renderWindow, sfString* string) void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, sfText* text)
{ {
CSFML_CHECK(string); CSFML_CHECK(text);
CSFML_CALL(renderWindow, Draw(string->This)); CSFML_CALL(renderWindow, Draw(text->This));
} }
@ -388,11 +388,11 @@ void sfRenderWindow_DrawShapeWithShader(sfRenderWindow* renderWindow, sfShape* s
CSFML_CHECK(shader); CSFML_CHECK(shader);
CSFML_CALL(renderWindow, Draw(shape->This, shader->This)); CSFML_CALL(renderWindow, Draw(shape->This, shader->This));
} }
void sfRenderWindow_DrawStringWithShader(sfRenderWindow* renderWindow, sfString* string, sfShader* shader) void sfRenderWindow_DrawTextWithShader(sfRenderWindow* renderWindow, sfText* text, sfShader* shader)
{ {
CSFML_CHECK(string); CSFML_CHECK(text);
CSFML_CHECK(shader); CSFML_CHECK(shader);
CSFML_CALL(renderWindow, Draw(string->This, shader->This)); CSFML_CALL(renderWindow, Draw(text->This, shader->This));
} }

View File

@ -25,397 +25,397 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/String.h> #include <SFML/Graphics/Text.h>
#include <SFML/Graphics/StringStruct.h> #include <SFML/Graphics/TextStruct.h>
#include <SFML/Graphics/Font.h> #include <SFML/Graphics/Font.h>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Internal.h> #include <SFML/Internal.h>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create a new string /// Create a new text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfString* sfString_Create() sfText* sfText_Create()
{ {
sfString* string = new sfString; sfText* text = new sfText;
string->Font = sfFont_GetDefaultFont(); text->Font = sfFont_GetDefaultFont();
return string; return text;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing string /// Destroy an existing text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_Destroy(sfString* string) void sfText_Destroy(sfText* text)
{ {
delete string; delete text;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the X position of a string /// Set the X position of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetX(sfString* string, float x) void sfText_SetX(sfText* text, float x)
{ {
CSFML_CALL(string, SetX(x)) CSFML_CALL(text, SetX(x))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the Y position of a string /// Set the Y position of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetY(sfString* string, float y) void sfText_SetY(sfText* text, float y)
{ {
CSFML_CALL(string, SetY(y)) CSFML_CALL(text, SetY(y))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the position of a string /// Set the position of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetPosition(sfString* string, float x, float y) void sfText_SetPosition(sfText* text, float x, float y)
{ {
CSFML_CALL(string, SetPosition(sf::Vector2f(x, y))) CSFML_CALL(text, SetPosition(sf::Vector2f(x, y)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the horizontal scale of a string /// Set the horizontal scale of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetScaleX(sfString* string, float scale) void sfText_SetScaleX(sfText* text, float scale)
{ {
CSFML_CALL(string, SetScaleX(scale)) CSFML_CALL(text, SetScaleX(scale))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the vertical scale of a string /// Set the vertical scale of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetScaleY(sfString* string, float scale) void sfText_SetScaleY(sfText* text, float scale)
{ {
CSFML_CALL(string, SetScaleY(scale)) CSFML_CALL(text, SetScaleY(scale))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the scale of a string /// Set the scale of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetScale(sfString* string, float scaleX, float scaleY) void sfText_SetScale(sfText* text, float scaleX, float scaleY)
{ {
CSFML_CALL(string, SetScale(sf::Vector2f(scaleX, scaleY))) CSFML_CALL(text, SetScale(sf::Vector2f(scaleX, scaleY)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the orientation of a string /// Set the orientation of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetRotation(sfString* string, float rotation) void sfText_SetRotation(sfText* text, float rotation)
{ {
CSFML_CALL(string, SetRotation(rotation)) CSFML_CALL(text, SetRotation(rotation))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the local origin of a string, in coordinates /// Set the local origin of a text, in coordinates
/// relative to its left-top corner /// relative to its left-top corner
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetOrigin(sfString* string, float x, float y) void sfText_SetOrigin(sfText* text, float x, float y)
{ {
CSFML_CALL(string, SetOrigin(sf::Vector2f(x, y))) CSFML_CALL(text, SetOrigin(sf::Vector2f(x, y)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the color of a string /// Set the color of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetColor(sfString* string, sfColor color) void sfText_SetColor(sfText* text, sfColor color)
{ {
CSFML_CALL(string, SetColor(sf::Color(color.r, color.g, color.b, color.a))) CSFML_CALL(text, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the blending mode for a string /// Set the blending mode for a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetBlendMode(sfString* string, sfBlendMode mode) void sfText_SetBlendMode(sfText* text, sfBlendMode mode)
{ {
CSFML_CALL(string, SetBlendMode(static_cast<sf::Blend::Mode>(mode))) CSFML_CALL(text, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the X position of a string /// Get the X position of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetX(sfString* string) float sfText_GetX(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetPosition().x, 0.f) CSFML_CALL_RETURN(text, GetPosition().x, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the Y position of a string /// Get the Y position of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetY(sfString* string) float sfText_GetY(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetPosition().y, 0.f) CSFML_CALL_RETURN(text, GetPosition().y, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the horizontal scale of a string /// Get the horizontal scale of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetScaleX(sfString* string) float sfText_GetScaleX(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetScale().x, 0.f) CSFML_CALL_RETURN(text, GetScale().x, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the vertical scale of a string /// Get the vertical scale of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetScaleY(sfString* string) float sfText_GetScaleY(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetScale().y, 0.f) CSFML_CALL_RETURN(text, GetScale().y, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the orientation of a string /// Get the orientation of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetRotation(sfString* string) float sfText_GetRotation(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetRotation(), 0.f) CSFML_CALL_RETURN(text, GetRotation(), 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the X position of the origin a string /// Get the X position of the origin a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetOriginX(sfString* string) float sfText_GetOriginX(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetOrigin().x, 0.f) CSFML_CALL_RETURN(text, GetOrigin().x, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the top Y of the origin of a string /// Get the top Y of the origin of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetOriginY(sfString* string) float sfText_GetOriginY(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetOrigin().y, 0.f) CSFML_CALL_RETURN(text, GetOrigin().y, 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the color of a string /// Get the color of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfColor sfString_GetColor(sfString* string) sfColor sfText_GetColor(sfText* text)
{ {
sfColor color = {0, 0, 0, 0}; sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(string, color) CSFML_CHECK_RETURN(text, color)
sf::Color SFMLColor = string->This.GetColor(); sf::Color SFMLColor = text->This.GetColor();
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a); return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the current blending mode of a string /// Get the current blending mode of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfBlendMode sfString_GetBlendMode(sfString* string) sfBlendMode sfText_GetBlendMode(sfText* text)
{ {
CSFML_CHECK_RETURN(string, sfBlendNone) CSFML_CHECK_RETURN(text, sfBlendNone)
return static_cast<sfBlendMode>(string->This.GetBlendMode()); return static_cast<sfBlendMode>(text->This.GetBlendMode());
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Move a string /// Move a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_Move(sfString* string, float offsetX, float offsetY) void sfText_Move(sfText* text, float offsetX, float offsetY)
{ {
CSFML_CALL(string, Move(sf::Vector2f(offsetX, offsetY))) CSFML_CALL(text, Move(sf::Vector2f(offsetX, offsetY)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Scale a string /// Scale a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_Scale(sfString* string, float factorX, float factorY) void sfText_Scale(sfText* text, float factorX, float factorY)
{ {
CSFML_CALL(string, Scale(sf::Vector2f(factorX, factorY))) CSFML_CALL(text, Scale(sf::Vector2f(factorX, factorY)))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Rotate a string /// Rotate a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_Rotate(sfString* string, float angle) void sfText_Rotate(sfText* text, float angle)
{ {
CSFML_CALL(string, Rotate(angle)) CSFML_CALL(text, Rotate(angle))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into the string's local coordinates /// Transform a point from global coordinates into the text's local coordinates
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) /// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_TransformToLocal(sfString* string, float pointX, float pointY, float* x, float* y) void sfText_TransformToLocal(sfText* text, float pointX, float pointY, float* x, float* y)
{ {
CSFML_CHECK(string) CSFML_CHECK(text)
sf::Vector2f point = string->This.TransformToLocal(sf::Vector2f(pointX, pointY)); sf::Vector2f point = text->This.TransformToLocal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x; if (x) *x = point.x;
if (y) *y = point.y; if (y) *y = point.y;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Transform a point from the string's local coordinates into global coordinates /// Transform a point from the text's local coordinates into global coordinates
/// (ie it applies the object's origin, translation, rotation and scale to the point) /// (ie it applies the object's origin, translation, rotation and scale to the point)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_TransformToGlobal(sfString* string, float pointX, float pointY, float* x, float* y) void sfText_TransformToGlobal(sfText* text, float pointX, float pointY, float* x, float* y)
{ {
CSFML_CHECK(string) CSFML_CHECK(text)
sf::Vector2f point = string->This.TransformToGlobal(sf::Vector2f(pointX, pointY)); sf::Vector2f point = text->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x; if (x) *x = point.x;
if (y) *y = point.y; if (y) *y = point.y;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text of a string (from a multibyte string) /// Set the string of a text (from a multibyte string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetText(sfString* string, const char* text) void sfText_SetString(sfText* text, const char* string)
{ {
CSFML_CALL(string, SetText(text)) CSFML_CALL(text, SetString(string))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text of a string (from a unicode string) /// Set the string of a text (from a unicode string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetUnicodeText(sfString* string, const sfUint32* text) void sfText_SetUnicodeString(sfText* text, const sfUint32* string)
{ {
sf::Unicode::UTF32String UTF32Text = text; sf::String UTF32Text = string;
CSFML_CALL(string, SetText(UTF32Text)) CSFML_CALL(text, SetString(UTF32Text))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the font of a string /// Set the font of a string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetFont(sfString* string, sfFont* font) void sfText_SetFont(sfText* text, sfFont* font)
{ {
CSFML_CHECK(font); CSFML_CHECK(font);
CSFML_CALL(string, SetFont(font->This)) CSFML_CALL(text, SetFont(font->This))
string->Font = font; text->Font = font;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the size of a string /// Set the size of a string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetSize(sfString* string, float size) void sfText_SetSize(sfText* text, float size)
{ {
CSFML_CALL(string, SetSize(size)) CSFML_CALL(text, SetSize(size))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the style of a string /// Set the style of a string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_SetStyle(sfString* string, unsigned long style) void sfText_SetStyle(sfText* text, unsigned long style)
{ {
CSFML_CALL(string, SetStyle(style)) CSFML_CALL(text, SetStyle(style))
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the text of a string (returns a unicode string) /// Get the string of a text (returns a unicode string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const sfUint32* sfString_GetUnicodeText(sfString* string) const sfUint32* sfText_GetUnicodeString(sfText* text)
{ {
CSFML_CHECK_RETURN(string, NULL) CSFML_CHECK_RETURN(text, NULL)
return static_cast<const sf::Unicode::UTF32String&>(string->This.GetText()).c_str(); return text->This.GetString().GetData();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the text of a string (returns an ANSI string) /// Get the string of a text (returns an ANSI string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const char* sfString_GetText(sfString* string) const char* sfText_GetString(sfText* text)
{ {
CSFML_CHECK_RETURN(string, NULL) CSFML_CHECK_RETURN(text, NULL)
string->Text = string->This.GetText(); text->String = text->This.GetString().ToAnsiString();
return string->Text.c_str(); return text->String.c_str();
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the font used by a string /// Get the font used by a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFont* sfString_GetFont(sfString* string) sfFont* sfText_GetFont(sfText* text)
{ {
CSFML_CHECK_RETURN(string, NULL) CSFML_CHECK_RETURN(text, NULL)
return string->Font; return text->Font;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the size of the characters of a string /// Get the size of the characters of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfString_GetSize(sfString* string) float sfText_GetSize(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetSize(), 0.f) CSFML_CALL_RETURN(text, GetSize(), 0.f)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the style of a string /// Get the style of a text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned long sfString_GetStyle(sfString* string) unsigned long sfText_GetStyle(sfText* text)
{ {
CSFML_CALL_RETURN(string, GetStyle(), 0) CSFML_CALL_RETURN(text, GetStyle(), 0)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Return the visual position of the Index-th character of the string, /// Return the visual position of the Index-th character of the text,
/// in coordinates relative to the string /// in coordinates relative to the text
/// (note : translation, origin, rotation and scale are not applied) /// (note : translation, origin, rotation and scale are not applied)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfString_GetCharacterPos(sfString* string, size_t index, float* x, float* y) void sfText_GetCharacterPos(sfText* text, size_t index, float* x, float* y)
{ {
CSFML_CHECK(string); CSFML_CHECK(text);
sf::Vector2f pos = string->This.GetCharacterPos(index); sf::Vector2f pos = text->This.GetCharacterPos(index);
if (x) *x = pos.x; if (x) *x = pos.x;
if (y) *y = pos.y; if (y) *y = pos.y;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the bounding rectangle of a string on screen /// Get the bounding rectangle of a text on screen
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfString_GetRect(sfString* string) sfFloatRect sfText_GetRect(sfText* text)
{ {
sfFloatRect rect = {0.f, 0.f, 0.f, 0.f}; sfFloatRect rect = {0.f, 0.f, 0.f, 0.f};
CSFML_CHECK_RETURN(string, rect) CSFML_CHECK_RETURN(text, rect)
sf::FloatRect SFMLRect = string->This.GetRect(); sf::FloatRect SFMLRect = text->This.GetRect();
string->Rect.Left = SFMLRect.Left; text->Rect.Left = SFMLRect.Left;
string->Rect.Top = SFMLRect.Top; text->Rect.Top = SFMLRect.Top;
string->Rect.Right = SFMLRect.Right; text->Rect.Right = SFMLRect.Right;
string->Rect.Bottom = SFMLRect.Bottom; text->Rect.Bottom = SFMLRect.Bottom;
return string->Rect; return text->Rect;
} }

View File

@ -22,28 +22,28 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef SFML_STRINGSTRUCT_H #ifndef SFML_TEXTSTRUCT_H
#define SFML_STRINGSTRUCT_H #define SFML_TEXTSTRUCT_H
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/String.hpp> #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/FontStruct.h> #include <SFML/Graphics/FontStruct.h>
#include <SFML/Graphics/Rect.h> #include <SFML/Graphics/Rect.h>
#include <string> #include <string>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Internal structure of sfMusic // Internal structure of sfText
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct sfString struct sfText
{ {
sf::String This; sf::Text This;
std::string Text; std::string String;
sfFont* Font; sfFont* Font;
sfFloatRect Rect; sfFloatRect Rect;
}; };
#endif // SFML_STRINGSTRUCT_H #endif // SFML_TEXTSTRUCT_H

View File

@ -130,44 +130,44 @@ EXPORTS
sfFont_Destroy sfFont_Destroy
sfFont_GetCharacterSize sfFont_GetCharacterSize
sfFont_GetDefaultFont sfFont_GetDefaultFont
sfString_Create sfText_Create
sfString_Destroy sfText_Destroy
sfString_SetX sfText_SetX
sfString_SetY sfText_SetY
sfString_SetPosition sfText_SetPosition
sfString_SetScaleX sfText_SetScaleX
sfString_SetScaleY sfText_SetScaleY
sfString_SetScale sfText_SetScale
sfString_SetRotation sfText_SetRotation
sfString_SetOrigin sfText_SetOrigin
sfString_SetColor sfText_SetColor
sfString_SetBlendMode sfText_SetBlendMode
sfString_GetX sfText_GetX
sfString_GetY sfText_GetY
sfString_GetScaleX sfText_GetScaleX
sfString_GetScaleY sfText_GetScaleY
sfString_GetRotation sfText_GetRotation
sfString_GetOriginX sfText_GetOriginX
sfString_GetOriginY sfText_GetOriginY
sfString_GetColor sfText_GetColor
sfString_GetBlendMode sfText_GetBlendMode
sfString_Move sfText_Move
sfString_Scale sfText_Scale
sfString_Rotate sfText_Rotate
sfString_TransformToLocal sfText_TransformToLocal
sfString_TransformToGlobal sfText_TransformToGlobal
sfString_SetText sfText_SetString
sfString_SetUnicodeText sfText_SetUnicodeString
sfString_SetFont sfText_SetFont
sfString_SetSize sfText_SetSize
sfString_SetStyle sfText_SetStyle
sfString_GetUnicodeText sfText_GetUnicodeString
sfString_GetText sfText_GetString
sfString_GetFont sfText_GetFont
sfString_GetSize sfText_GetSize
sfString_GetStyle sfText_GetStyle
sfString_GetCharacterPos sfText_GetCharacterPos
sfString_GetRect sfText_GetRect
sfRenderImage_Create sfRenderImage_Create
sfRenderImage_Destroy sfRenderImage_Destroy
sfRenderImage_GetWidth sfRenderImage_GetWidth
@ -177,10 +177,10 @@ EXPORTS
sfRenderImage_Display sfRenderImage_Display
sfRenderImage_DrawSprite sfRenderImage_DrawSprite
sfRenderImage_DrawShape sfRenderImage_DrawShape
sfRenderImage_DrawString sfRenderImage_DrawText
sfRenderImage_DrawSpriteWithShader sfRenderImage_DrawSpriteWithShader
sfRenderImage_DrawShapeWithShader sfRenderImage_DrawShapeWithShader
sfRenderImage_DrawStringWithShader sfRenderImage_DrawTextWithShader
sfRenderImage_Clear sfRenderImage_Clear
sfRenderImage_SetView sfRenderImage_SetView
sfRenderImage_GetView sfRenderImage_GetView
@ -213,10 +213,10 @@ EXPORTS
sfRenderWindow_GetFrameTime sfRenderWindow_GetFrameTime
sfRenderWindow_SetJoystickThreshold sfRenderWindow_SetJoystickThreshold
sfRenderWindow_DrawSprite sfRenderWindow_DrawSprite
sfRenderWindow_DrawString sfRenderWindow_DrawText
sfRenderWindow_DrawShape sfRenderWindow_DrawShape
sfRenderWindow_DrawSpriteWithShader sfRenderWindow_DrawSpriteWithShader
sfRenderWindow_DrawStringWithShader sfRenderWindow_DrawTextWithShader
sfRenderWindow_DrawShapeWithShader sfRenderWindow_DrawShapeWithShader
sfRenderWindow_Clear sfRenderWindow_Clear
sfRenderWindow_SetView sfRenderWindow_SetView

View File

@ -130,44 +130,44 @@ EXPORTS
sfFont_Destroy sfFont_Destroy
sfFont_GetCharacterSize sfFont_GetCharacterSize
sfFont_GetDefaultFont sfFont_GetDefaultFont
sfString_Create sfText_Create
sfString_Destroy sfText_Destroy
sfString_SetX sfText_SetX
sfString_SetY sfText_SetY
sfString_SetPosition sfText_SetPosition
sfString_SetScaleX sfText_SetScaleX
sfString_SetScaleY sfText_SetScaleY
sfString_SetScale sfText_SetScale
sfString_SetRotation sfText_SetRotation
sfString_SetOrigin sfText_SetOrigin
sfString_SetColor sfText_SetColor
sfString_SetBlendMode sfText_SetBlendMode
sfString_GetX sfText_GetX
sfString_GetY sfText_GetY
sfString_GetScaleX sfText_GetScaleX
sfString_GetScaleY sfText_GetScaleY
sfString_GetRotation sfText_GetRotation
sfString_GetOriginX sfText_GetOriginX
sfString_GetOriginY sfText_GetOriginY
sfString_GetColor sfText_GetColor
sfString_GetBlendMode sfText_GetBlendMode
sfString_Move sfText_Move
sfString_Scale sfText_Scale
sfString_Rotate sfText_Rotate
sfString_TransformToLocal sfText_TransformToLocal
sfString_TransformToGlobal sfText_TransformToGlobal
sfString_SetText sfText_SetString
sfString_SetUnicodeText sfText_SetUnicodeString
sfString_SetFont sfText_SetFont
sfString_SetSize sfText_SetSize
sfString_SetStyle sfText_SetStyle
sfString_GetUnicodeText sfText_GetUnicodeString
sfString_GetText sfText_GetString
sfString_GetFont sfText_GetFont
sfString_GetSize sfText_GetSize
sfString_GetStyle sfText_GetStyle
sfString_GetCharacterPos sfText_GetCharacterPos
sfString_GetRect sfText_GetRect
sfRenderImage_Create sfRenderImage_Create
sfRenderImage_Destroy sfRenderImage_Destroy
sfRenderImage_GetWidth sfRenderImage_GetWidth
@ -177,10 +177,10 @@ EXPORTS
sfRenderImage_Display sfRenderImage_Display
sfRenderImage_DrawSprite sfRenderImage_DrawSprite
sfRenderImage_DrawShape sfRenderImage_DrawShape
sfRenderImage_DrawString sfRenderImage_DrawText
sfRenderImage_DrawSpriteWithShader sfRenderImage_DrawSpriteWithShader
sfRenderImage_DrawShapeWithShader sfRenderImage_DrawShapeWithShader
sfRenderImage_DrawStringWithShader sfRenderImage_DrawTextWithShader
sfRenderImage_Clear sfRenderImage_Clear
sfRenderImage_SetView sfRenderImage_SetView
sfRenderImage_GetView sfRenderImage_GetView
@ -215,10 +215,10 @@ EXPORTS
sfRenderWindow_GetFrameTime sfRenderWindow_GetFrameTime
sfRenderWindow_SetJoystickThreshold sfRenderWindow_SetJoystickThreshold
sfRenderWindow_DrawSprite sfRenderWindow_DrawSprite
sfRenderWindow_DrawString sfRenderWindow_DrawText
sfRenderWindow_DrawShape sfRenderWindow_DrawShape
sfRenderWindow_DrawSpriteWithShader sfRenderWindow_DrawSpriteWithShader
sfRenderWindow_DrawStringWithShader sfRenderWindow_DrawTextWithShader
sfRenderWindow_DrawShapeWithShader sfRenderWindow_DrawShapeWithShader
sfRenderWindow_Clear sfRenderWindow_Clear
sfRenderWindow_SetView sfRenderWindow_SetView

View File

@ -133,7 +133,7 @@
<Unit filename="..\..\include\SFML\Graphics\Shader.hpp" /> <Unit filename="..\..\include\SFML\Graphics\Shader.hpp" />
<Unit filename="..\..\include\SFML\Graphics\Shape.hpp" /> <Unit filename="..\..\include\SFML\Graphics\Shape.hpp" />
<Unit filename="..\..\include\SFML\Graphics\Sprite.hpp" /> <Unit filename="..\..\include\SFML\Graphics\Sprite.hpp" />
<Unit filename="..\..\include\SFML\Graphics\String.hpp" /> <Unit filename="..\..\include\SFML\Graphics\Text.hpp" />
<Unit filename="..\..\include\SFML\Graphics\View.hpp" /> <Unit filename="..\..\include\SFML\Graphics\View.hpp" />
<Unit filename="..\..\src\SFML\Graphics\Batch.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Batch.cpp" />
<Unit filename="..\..\src\SFML\Graphics\Batch.hpp" /> <Unit filename="..\..\src\SFML\Graphics\Batch.hpp" />
@ -189,7 +189,7 @@
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
<Unit filename="..\..\src\SFML\Graphics\Shape.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Shape.cpp" />
<Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" />
<Unit filename="..\..\src\SFML\Graphics\String.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Text.cpp" />
<Unit filename="..\..\src\SFML\Graphics\View.cpp" /> <Unit filename="..\..\src\SFML\Graphics\View.cpp" />
<Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.cpp" /> <Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.cpp" />
<Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.hpp" /> <Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.hpp" />

View File

@ -98,12 +98,13 @@
<Unit filename="..\..\include\SFML\System\Resource.inl" /> <Unit filename="..\..\include\SFML\System\Resource.inl" />
<Unit filename="..\..\include\SFML\System\ResourcePtr.inl" /> <Unit filename="..\..\include\SFML\System\ResourcePtr.inl" />
<Unit filename="..\..\include\SFML\System\Sleep.hpp" /> <Unit filename="..\..\include\SFML\System\Sleep.hpp" />
<Unit filename="..\..\include\SFML\System\String.hpp" />
<Unit filename="..\..\include\SFML\System\Thread.hpp" /> <Unit filename="..\..\include\SFML\System\Thread.hpp" />
<Unit filename="..\..\include\SFML\System\ThreadLocal.hpp" /> <Unit filename="..\..\include\SFML\System\ThreadLocal.hpp" />
<Unit filename="..\..\include\SFML\System\ThreadLocalPtr.hpp" /> <Unit filename="..\..\include\SFML\System\ThreadLocalPtr.hpp" />
<Unit filename="..\..\include\SFML\System\ThreadLocalPtr.inl" /> <Unit filename="..\..\include\SFML\System\ThreadLocalPtr.inl" />
<Unit filename="..\..\include\SFML\System\Unicode.hpp" /> <Unit filename="..\..\include\SFML\System\Utf.hpp" />
<Unit filename="..\..\include\SFML\System\Unicode.inl" /> <Unit filename="..\..\include\SFML\System\Utf.inl" />
<Unit filename="..\..\include\SFML\System\Vector2.hpp" /> <Unit filename="..\..\include\SFML\System\Vector2.hpp" />
<Unit filename="..\..\include\SFML\System\Vector2.inl" /> <Unit filename="..\..\include\SFML\System\Vector2.inl" />
<Unit filename="..\..\include\SFML\System\Vector3.hpp" /> <Unit filename="..\..\include\SFML\System\Vector3.hpp" />
@ -114,9 +115,10 @@
<Unit filename="..\..\src\SFML\System\Platform.hpp" /> <Unit filename="..\..\src\SFML\System\Platform.hpp" />
<Unit filename="..\..\src\SFML\System\Randomizer.cpp" /> <Unit filename="..\..\src\SFML\System\Randomizer.cpp" />
<Unit filename="..\..\src\SFML\System\Sleep.cpp" /> <Unit filename="..\..\src\SFML\System\Sleep.cpp" />
<Unit filename="..\..\src\SFML\System\String.cpp" />
<Unit filename="..\..\src\SFML\System\Thread.cpp" /> <Unit filename="..\..\src\SFML\System\Thread.cpp" />
<Unit filename="..\..\src\SFML\System\ThreadLocal.cpp" /> <Unit filename="..\..\src\SFML\System\ThreadLocal.cpp" />
<Unit filename="..\..\src\SFML\System\Unicode.cpp" /> <Unit filename="..\..\src\SFML\System\Utf.cpp" />
<Unit filename="..\..\src\SFML\System\Win32\MutexImpl.cpp" /> <Unit filename="..\..\src\SFML\System\Win32\MutexImpl.cpp" />
<Unit filename="..\..\src\SFML\System\Win32\MutexImpl.hpp" /> <Unit filename="..\..\src\SFML\System\Win32\MutexImpl.hpp" />
<Unit filename="..\..\src\SFML\System\Win32\Platform.cpp" /> <Unit filename="..\..\src\SFML\System\Win32\Platform.cpp" />

View File

@ -3314,11 +3314,11 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\String.cpp" RelativePath="..\..\src\SFML\Graphics\Text.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\Graphics\String.hpp" RelativePath="..\..\include\SFML\Graphics\Text.hpp"
> >
</File> </File>
</Filter> </Filter>

View File

@ -470,6 +470,14 @@
RelativePath="..\..\include\SFML\System\Sleep.hpp" RelativePath="..\..\include\SFML\System\Sleep.hpp"
> >
</File> </File>
<File
RelativePath="..\..\src\SFML\System\String.cpp"
>
</File>
<File
RelativePath="..\..\include\SFML\System\String.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\System\Thread.cpp" RelativePath="..\..\src\SFML\System\Thread.cpp"
> >
@ -495,15 +503,15 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\System\Unicode.cpp" RelativePath="..\..\src\SFML\System\Utf.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\System\Unicode.hpp" RelativePath="..\..\include\SFML\System\Utf.hpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\System\Unicode.inl" RelativePath="..\..\include\SFML\System\Utf.inl"
> >
</File> </File>
<File <File

View File

@ -3409,11 +3409,11 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\Graphics\String.cpp" RelativePath="..\..\src\SFML\Graphics\Text.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\Graphics\String.hpp" RelativePath="..\..\include\SFML\Graphics\Text.hpp"
> >
</File> </File>
</Filter> </Filter>

View File

@ -431,6 +431,14 @@
RelativePath="..\..\include\SFML\System\Sleep.hpp" RelativePath="..\..\include\SFML\System\Sleep.hpp"
> >
</File> </File>
<File
RelativePath="..\..\src\SFML\System\String.cpp"
>
</File>
<File
RelativePath="..\..\include\SFML\System\String.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\System\Thread.cpp" RelativePath="..\..\src\SFML\System\Thread.cpp"
> >
@ -456,15 +464,15 @@
> >
</File> </File>
<File <File
RelativePath="..\..\src\SFML\System\Unicode.cpp" RelativePath="..\..\src\SFML\System\Utf.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\System\Unicode.hpp" RelativePath="..\..\include\SFML\System\Utf.hpp"
> >
</File> </File>
<File <File
RelativePath="..\..\include\SFML\System\Unicode.inl" RelativePath="..\..\include\SFML\System\Utf.inl"
> >
</File> </File>
<File <File

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -26,7 +26,7 @@ namespace sample_opengl
Sprite background = new Sprite(backgroundImage); Sprite background = new Sprite(backgroundImage);
// Create a text to display // Create a text to display
String2D text = new String2D("SFML / OpenGL demo"); Text text = new Text("SFML / OpenGL demo");
text.Position = new Vector2(250.0F, 450.0F); text.Position = new Vector2(250.0F, 450.0F);
text.Color = new Color(255, 255, 255, 170); text.Color = new Color(255, 255, 255, 170);

View File

@ -61,7 +61,7 @@ namespace sample_shader
private static ShaderSelector backgroundShader; private static ShaderSelector backgroundShader;
private static ShaderSelector entityShader; private static ShaderSelector entityShader;
private static ShaderSelector globalShader; private static ShaderSelector globalShader;
private static String2D shaderStr; private static Text shaderText;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
@ -122,25 +122,25 @@ namespace sample_shader
shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture); shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);
// Define a string for displaying current effect description // Define a string for displaying current effect description
shaderStr = new String2D(); shaderText = new Text();
shaderStr.Font = font; shaderText.Font = font;
shaderStr.Size = 20; shaderText.Size = 20;
shaderStr.Position = new Vector2(5.0F, 0.0F); shaderText.Position = new Vector2(5.0F, 0.0F);
shaderStr.Color = new Color(250, 100, 30); shaderText.Color = new Color(250, 100, 30);
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" + shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
"Flower shader: \"" + entityShader.Name + "\"\n" + "Flower shader: \"" + entityShader.Name + "\"\n" +
"Global shader: \"" + globalShader.Name + "\"\n"; "Global shader: \"" + globalShader.Name + "\"\n";
// Define a string for displaying help // Define a string for displaying help
String2D infoStr = new String2D(); Text infoText = new Text();
infoStr.Font = font; infoText.Font = font;
infoStr.Size = 20; infoText.Size = 20;
infoStr.Position = new Vector2(5.0F, 510.0F); infoText.Position = new Vector2(5.0F, 510.0F);
infoStr.Color = new Color(250, 100, 30); infoText.Color = new Color(250, 100, 30);
infoStr.Text = "Move your mouse to change the shaders' parameters\n" + infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
"Press numpad 1 to change the background shader\n" + "Press numpad 1 to change the background shader\n" +
"Press numpad 2 to change the flower shader\n" + "Press numpad 2 to change the flower shader\n" +
"Press numpad 3 to change the global shader"; "Press numpad 3 to change the global shader";
// Start the game loop // Start the game loop
float time = 0.0F; float time = 0.0F;
@ -176,9 +176,9 @@ namespace sample_shader
// Draw the contents of the render image to the window // Draw the contents of the render image to the window
window.Draw(new Sprite(image.Image), globalShader.Shader); window.Draw(new Sprite(image.Image), globalShader.Shader);
// Draw interface strings // Draw interface texts
window.Draw(shaderStr); window.Draw(shaderText);
window.Draw(infoStr); window.Draw(infoText);
// Finally, display the rendered frame on screen // Finally, display the rendered frame on screen
window.Display(); window.Display();
@ -192,9 +192,9 @@ namespace sample_shader
private static void DisplayError(RenderWindow window) private static void DisplayError(RenderWindow window)
{ {
// Define a string for displaying the error message // Define a string for displaying the error message
String2D errorStr = new String2D("Sorry, your system doesn't support shaders"); Text error = new Text("Sorry, your system doesn't support shaders");
errorStr.Position = new Vector2(100.0F, 250.0F); error.Position = new Vector2(100.0F, 250.0F);
errorStr.Color = new Color(200, 100, 150); error.Color = new Color(200, 100, 150);
// Start the game loop // Start the game loop
while (window.IsOpened()) while (window.IsOpened())
@ -206,7 +206,7 @@ namespace sample_shader
window.Clear(); window.Clear();
// Draw the error message // Draw the error message
window.Draw(errorStr); window.Draw(error);
// Finally, display the rendered frame on screen // Finally, display the rendered frame on screen
window.Display(); window.Display();
@ -242,9 +242,9 @@ namespace sample_shader
} }
// Update the text // Update the text
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" + shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
"Flower shader: \"" + entityShader.Name + "\"\n" + "Flower shader: \"" + entityShader.Name + "\"\n" +
"Global shader: \"" + globalShader.Name + "\"\n"; "Global shader: \"" + globalShader.Name + "\"\n";
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace SFML
/// This class defines a graphical 2D text, that can be drawn on screen /// This class defines a graphical 2D text, that can be drawn on screen
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public class String2D : Drawable public class Text : Drawable
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
@ -39,46 +39,46 @@ namespace SFML
/// Default constructor /// Default constructor
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public String2D() : public Text() :
this("") this("")
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Construct the string from a text /// Construct the text from a string
/// </summary> /// </summary>
/// <param name="text">Text to display</param> /// <param name="str">String to display</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public String2D(string text) : public Text(string str) :
this(text, Font.DefaultFont) this(str, Font.DefaultFont)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Construct the string from a text and a font /// Construct the text from a string and a font
/// </summary> /// </summary>
/// <param name="text">Text to display</param> /// <param name="str">String to display</param>
/// <param name="font">Font to use</param> /// <param name="font">Font to use</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public String2D(string text, Font font) : public Text(string str, Font font) :
this(text, font, 30) this(str, font, 30)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Construct the string from a text, font and size /// Construct the text from a string, font and size
/// </summary> /// </summary>
/// <param name="text">Text to display</param> /// <param name="str">String to display</param>
/// <param name="font">Font to use</param> /// <param name="font">Font to use</param>
/// <param name="size">Base characters size</param> /// <param name="size">Base characters size</param>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public String2D(string text, Font font, uint size) : public Text(string str, Font font, uint size) :
base(sfString_Create()) base(sfText_Create())
{ {
Text = text; DisplayedString = str;
Font = font; Font = font;
Size = size; Size = size;
} }
@ -90,8 +90,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override Vector2 Position public override Vector2 Position
{ {
get { return new Vector2(sfString_GetX(This), sfString_GetY(This)); } get { return new Vector2(sfText_GetX(This), sfText_GetY(This)); }
set { sfString_SetPosition(This, value.X, value.Y); } set { sfText_SetPosition(This, value.X, value.Y); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -101,8 +101,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override float Rotation public override float Rotation
{ {
get { return sfString_GetRotation(This); } get { return sfText_GetRotation(This); }
set { sfString_SetRotation(This, value); } set { sfText_SetRotation(This, value); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -112,8 +112,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override Vector2 Scale public override Vector2 Scale
{ {
get { return new Vector2(sfString_GetScaleX(This), sfString_GetScaleY(This)); } get { return new Vector2(sfText_GetScaleX(This), sfText_GetScaleY(This)); }
set { sfString_SetScale(This, value.X, value.Y); } set { sfText_SetScale(This, value.X, value.Y); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -124,8 +124,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override Vector2 Origin public override Vector2 Origin
{ {
get { return new Vector2(sfString_GetOriginX(This), sfString_GetOriginY(This)); } get { return new Vector2(sfText_GetOriginX(This), sfText_GetOriginY(This)); }
set { sfString_SetOrigin(This, value.X, value.Y); } set { sfText_SetOrigin(This, value.X, value.Y); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -135,8 +135,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override Color Color public override Color Color
{ {
get { return sfString_GetColor(This); } get { return sfText_GetColor(This); }
set { sfString_SetColor(This, value); } set { sfText_SetColor(This, value); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -146,8 +146,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public override BlendMode BlendMode public override BlendMode BlendMode
{ {
get { return sfString_GetBlendMode(This); } get { return sfText_GetBlendMode(This); }
set { sfString_SetBlendMode(This, value); } set { sfText_SetBlendMode(This, value); }
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -161,7 +161,7 @@ namespace SFML
public override Vector2 TransformToLocal(Vector2 point) public override Vector2 TransformToLocal(Vector2 point)
{ {
Vector2 Transformed; Vector2 Transformed;
sfString_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y); sfText_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
return Transformed; return Transformed;
} }
@ -177,22 +177,22 @@ namespace SFML
public override Vector2 TransformToGlobal(Vector2 point) public override Vector2 TransformToGlobal(Vector2 point)
{ {
Vector2 Transformed; Vector2 Transformed;
sfString_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y); sfText_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
return Transformed; return Transformed;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Text displayed /// String which is displayed
/// </summary> /// </summary>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public string Text public string DisplayedString
{ {
// TODO : use unicode functions // TODO : use unicode functions
// (convert from UTF-16 to UTF-32, and find how to marshal System.String as sfUint32*...) // (convert from UTF-16 to UTF-32, and find how to marshal System.String as sfUint32*...)
get {return sfString_GetText(This);} get {return sfText_GetString(This);}
set {sfString_SetText(This, value);} set {sfText_SetString(This, value);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -203,7 +203,7 @@ namespace SFML
public Font Font public Font Font
{ {
get {return myFont;} get {return myFont;}
set {myFont = value; sfString_SetFont(This, value != null ? value.This : IntPtr.Zero);} set {myFont = value; sfText_SetFont(This, value != null ? value.This : IntPtr.Zero);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -213,8 +213,8 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public float Size public float Size
{ {
get {return sfString_GetSize(This);} get {return sfText_GetSize(This);}
set {sfString_SetSize(This, value);} set {sfText_SetSize(This, value);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -224,34 +224,34 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Styles Style public Styles Style
{ {
get {return sfString_GetStyle(This);} get {return sfText_GetStyle(This);}
set {sfString_SetStyle(This, value);} set {sfText_SetStyle(This, value);}
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Get the string rectangle on screen /// Get the text rectangle on screen
/// </summary> /// </summary>
/// <returns>String rectangle in global coordinates (doesn't include rotation)</returns> /// <returns>Text rectangle in global coordinates (doesn't include rotation)</returns>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public FloatRect GetRect() public FloatRect GetRect()
{ {
return sfString_GetRect(This); return sfText_GetRect(This);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// <summary> /// <summary>
/// Return the visual position of the Index-th character of the string, /// Return the visual position of the Index-th character of the text,
/// in coordinates relative to the string /// in coordinates relative to the text
/// (note : translation, origin, rotation and scale are not applied) /// (note : translation, origin, rotation and scale are not applied)
/// </summary> /// </summary>
/// <param name="index">Index of the character</param> /// <param name="index">Index of the character</param>
/// <returns>Position of the Index-th character (end of string if Index is out of range)</returns> /// <returns>Position of the Index-th character (end of text if Index is out of range)</returns>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
public Vector2 GetCharacterPos(uint index) public Vector2 GetCharacterPos(uint index)
{ {
Vector2 Pos; Vector2 Pos;
sfString_GetCharacterPos(This, index, out Pos.X, out Pos.Y); sfText_GetCharacterPos(This, index, out Pos.X, out Pos.Y);
return Pos; return Pos;
} }
@ -266,9 +266,9 @@ namespace SFML
internal override void Render(RenderWindow target, Shader shader) internal override void Render(RenderWindow target, Shader shader)
{ {
if (shader == null) if (shader == null)
sfRenderWindow_DrawString(target.This, This); sfRenderWindow_DrawText(target.This, This);
else else
sfRenderWindow_DrawStringWithShader(target.This, This, shader.This); sfRenderWindow_DrawTextWithShader(target.This, This, shader.This);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -281,9 +281,9 @@ namespace SFML
internal override void Render(RenderImage target, Shader shader) internal override void Render(RenderImage target, Shader shader)
{ {
if (shader == null) if (shader == null)
sfRenderImage_DrawString(target.This, This); sfRenderImage_DrawText(target.This, This);
else else
sfRenderImage_DrawStringWithShader(target.This, This, shader.This); sfRenderImage_DrawTextWithShader(target.This, This, shader.This);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -294,113 +294,113 @@ namespace SFML
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
protected override void Destroy(bool disposing) protected override void Destroy(bool disposing)
{ {
sfString_Destroy(This); sfText_Destroy(This);
} }
private Font myFont = Font.DefaultFont; private Font myFont = Font.DefaultFont;
#region Imports #region Imports
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern IntPtr sfString_Create(); static extern IntPtr sfText_Create();
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_Destroy(IntPtr This); static extern void sfText_Destroy(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetPosition(IntPtr This, float X, float Y); static extern void sfText_SetPosition(IntPtr This, float X, float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetX(IntPtr This); static extern float sfText_GetX(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetY(IntPtr This); static extern float sfText_GetY(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetRotation(IntPtr This, float Rotation); static extern void sfText_SetRotation(IntPtr This, float Rotation);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetRotation(IntPtr This); static extern float sfText_GetRotation(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetScale(IntPtr This, float X, float Y); static extern void sfText_SetScale(IntPtr This, float X, float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetScaleX(IntPtr This); static extern float sfText_GetScaleX(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetScaleY(IntPtr This); static extern float sfText_GetScaleY(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetOrigin(IntPtr This, float X, float Y); static extern void sfText_SetOrigin(IntPtr This, float X, float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetOriginX(IntPtr This); static extern float sfText_GetOriginX(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetOriginY(IntPtr This); static extern float sfText_GetOriginY(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetColor(IntPtr This, Color Color); static extern void sfText_SetColor(IntPtr This, Color Color);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern Color sfString_GetColor(IntPtr This); static extern Color sfText_GetColor(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetBlendMode(IntPtr This, BlendMode Mode); static extern void sfText_SetBlendMode(IntPtr This, BlendMode Mode);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern BlendMode sfString_GetBlendMode(IntPtr This); static extern BlendMode sfText_GetBlendMode(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern Vector2 sfString_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y); static extern Vector2 sfText_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern Vector2 sfString_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y); static extern Vector2 sfText_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawString(IntPtr This, IntPtr String); static extern void sfRenderWindow_DrawText(IntPtr This, IntPtr String);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderWindow_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader); static extern void sfRenderWindow_DrawTextWithShader(IntPtr This, IntPtr String, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawString(IntPtr This, IntPtr String); static extern void sfRenderImage_DrawText(IntPtr This, IntPtr String);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfRenderImage_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader); static extern void sfRenderImage_DrawTextWithShader(IntPtr This, IntPtr String, IntPtr Shader);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetWidth(IntPtr This); static extern float sfText_GetWidth(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetHeight(IntPtr This); static extern float sfText_GetHeight(IntPtr This);
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetText(IntPtr This, string Text); static extern void sfText_SetString(IntPtr This, string Text);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetFont(IntPtr This, IntPtr Font); static extern void sfText_SetFont(IntPtr This, IntPtr Font);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetSize(IntPtr This, float Size); static extern void sfText_SetSize(IntPtr This, float Size);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_SetStyle(IntPtr This, Styles Style); static extern void sfText_SetStyle(IntPtr This, Styles Style);
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
static extern string sfString_GetText(IntPtr This); static extern string sfText_GetString(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern float sfString_GetSize(IntPtr This); static extern float sfText_GetSize(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern Styles sfString_GetStyle(IntPtr This); static extern Styles sfText_GetStyle(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern FloatRect sfString_GetRect(IntPtr This); static extern FloatRect sfText_GetRect(IntPtr This);
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity] [DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
static extern void sfString_GetCharacterPos(IntPtr This, uint Index, out float X, out float Y); static extern void sfText_GetCharacterPos(IntPtr This, uint Index, out float X, out float Y);
#endregion #endregion
} }

View File

@ -60,7 +60,7 @@
<Compile Include="Shader.cs" /> <Compile Include="Shader.cs" />
<Compile Include="Shape.cs" /> <Compile Include="Shape.cs" />
<Compile Include="Sprite.cs" /> <Compile Include="Sprite.cs" />
<Compile Include="String2D.cs" /> <Compile Include="Text.cs" />
<Compile Include="Vector2.cs" /> <Compile Include="Vector2.cs" />
<Compile Include="View.cs" /> <Compile Include="View.cs" />
</ItemGroup> </ItemGroup>

View File

@ -40,7 +40,7 @@
#include <SFML/Graphics/Shader.hpp> #include <SFML/Graphics/Shader.hpp>
#include <SFML/Graphics/Shape.hpp> #include <SFML/Graphics/Shape.hpp>
#include <SFML/Graphics/Sprite.hpp> #include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/String.hpp> #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/View.hpp> #include <SFML/Graphics/View.hpp>

View File

@ -30,7 +30,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp> #include <SFML/System/Resource.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/System/Unicode.hpp> #include <SFML/System/String.hpp>
#include <SFML/Graphics/Glyph.hpp> #include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Image.hpp> #include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
@ -40,16 +40,15 @@
namespace sf namespace sf
{ {
class String;
namespace priv namespace priv
{ {
class FontLoader; class FontLoader;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Font is the low-level class for loading and /// Font is the low-level class for loading and
/// manipulating character fonts. This class is meant to /// manipulating character fonts. This class is meant to
/// be used by sf::String /// be used by sf::Text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_API Font : public Resource<Font> class SFML_API Font : public Resource<Font>
{ {
@ -71,7 +70,7 @@ public :
/// \return True if loading was successful /// \return True if loading was successful
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool LoadFromFile(const std::string& filename, unsigned int charSize = 30, const Unicode::Text& charset = ourDefaultCharset); bool LoadFromFile(const std::string& filename, unsigned int charSize = 30, String charset = ourDefaultCharset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file in memory /// Load the font from a file in memory
@ -84,7 +83,7 @@ public :
/// \return True if loading was successful /// \return True if loading was successful
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize = 30, const Unicode::Text& charset = ourDefaultCharset); bool LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize = 30, String charset = ourDefaultCharset);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the base size of characters in the font; /// Get the base size of characters in the font;

View File

@ -22,14 +22,14 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef SFML_STRING_HPP #ifndef SFML_TEXT_HPP
#define SFML_STRING_HPP #define SFML_TEXT_HPP
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp> #include <SFML/System/Resource.hpp>
#include <SFML/System/Unicode.hpp> #include <SFML/System/String.hpp>
#include <SFML/Graphics/Drawable.hpp> #include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
@ -39,9 +39,9 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// String defines a graphical 2D text, that can be drawn on screen /// Text defines a graphical 2D text, that can be drawn on screen
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_API String : public Drawable class SFML_API Text : public Drawable
{ {
public : public :
@ -60,25 +60,25 @@ public :
/// Default constructor /// Default constructor
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String(); Text();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the string from any kind of text /// Construct the string from any kind of text
/// ///
/// \param text : Text assigned to the string /// \param string : Text assigned to the string
/// \param font : Font used to draw the string /// \param font : Font used to draw the string
/// \param size : Characters size /// \param size : Characters size
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
explicit String(const Unicode::Text& text, const Font& font = Font::GetDefaultFont(), float size = 30.f); explicit Text(const String& string, const Font& font = Font::GetDefaultFont(), float size = 30.f);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text (from any kind of string) /// Set the text (from any kind of string)
/// ///
/// \param text : New text /// \param string : New text
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SetText(const Unicode::Text& text); void SetString(const String& string);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the font of the string /// Set the font of the string
@ -112,7 +112,7 @@ public :
/// \return String's text /// \return String's text
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Unicode::Text& GetText() const; const String& GetString() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the font used by the string /// Get the font used by the string
@ -177,7 +177,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Unicode::Text myText; ///< Text to display String myString; ///< String to display
ResourcePtr<Font> myFont; ///< Font used to display the string ResourcePtr<Font> myFont; ///< Font used to display the string
float mySize; ///< Size of the characters float mySize; ///< Size of the characters
unsigned long myStyle; ///< Text style (see Style enum) unsigned long myStyle; ///< Text style (see Style enum)
@ -188,4 +188,4 @@ private :
} // namespace sf } // namespace sf
#endif // SFML_STRING_HPP #endif // SFML_TEXT_HPP

View File

@ -35,10 +35,11 @@
#include <SFML/System/Mutex.hpp> #include <SFML/System/Mutex.hpp>
#include <SFML/System/Randomizer.hpp> #include <SFML/System/Randomizer.hpp>
#include <SFML/System/Sleep.hpp> #include <SFML/System/Sleep.hpp>
#include <SFML/System/String.hpp>
#include <SFML/System/Thread.hpp> #include <SFML/System/Thread.hpp>
#include <SFML/System/ThreadLocal.hpp> #include <SFML/System/ThreadLocal.hpp>
#include <SFML/System/ThreadLocalPtr.hpp> #include <SFML/System/ThreadLocalPtr.hpp>
#include <SFML/System/Unicode.hpp> #include <SFML/System/Utf.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>

View File

@ -0,0 +1,530 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_STRING_HPP
#define SFML_STRING_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <locale>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Utility string class that automatically handles
/// conversions between types and encodings
///
////////////////////////////////////////////////////////////
class SFML_API String
{
public :
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::basic_string<Uint32>::iterator Iterator; ///< Iterator type
typedef std::basic_string<Uint32>::const_iterator ConstIterator; ///< Constant iterator type
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
/// This constructor creates an empty string.
///
////////////////////////////////////////////////////////////
String();
////////////////////////////////////////////////////////////
/// \brief Construct from a null-terminated C-style ANSI string
///
/// The source string is converted to UTF-32 according
/// to the current locale. See the other constructor for
/// explicitely passing the locale to use.
///
/// \param ansiString ANSI string to convert
///
////////////////////////////////////////////////////////////
String(const char* ansiString);
////////////////////////////////////////////////////////////
/// \brief Construct from an ANSI string
///
/// The source string is converted to UTF-32 according
/// to the current global locale. See the other constructor for
/// explicitely passing the locale to use.
///
/// \param ansiString ANSI string to convert
///
////////////////////////////////////////////////////////////
String(const std::string& ansiString);
////////////////////////////////////////////////////////////
/// \brief Construct from a null-terminated C-style ANSI string and a locale
///
/// The source string is converted to UTF-32 according
/// to the given locale. If you want to use the current global
/// locale, rather use the other constructor.
///
/// \param ansiString ANSI string to convert
/// \param locale Locale to use for conversion
///
////////////////////////////////////////////////////////////
String(const char* ansiString, const std::locale& locale);
////////////////////////////////////////////////////////////
/// \brief Construct from an ANSI string and a locale
///
/// The source string is converted to UTF-32 according
/// to the given locale. If you want to use the current global
/// locale, rather use the other constructor.
///
/// \param ansiString ANSI string to convert
/// \param locale Locale to use for conversion
///
////////////////////////////////////////////////////////////
String(const std::string& ansiString, const std::locale& locale);
////////////////////////////////////////////////////////////
/// \brief Construct from null-terminated C-style wide string
///
/// \param wideString Wide string to convert
///
////////////////////////////////////////////////////////////
String(const wchar_t* wideString);
////////////////////////////////////////////////////////////
/// \brief Construct from a wide string
///
/// \param wideString Wide string to convert
///
////////////////////////////////////////////////////////////
String(const std::wstring& wideString);
////////////////////////////////////////////////////////////
/// \brief Construct from a null-terminated C-style UTF-32 string
///
/// \param utf32String UTF-32 string to assign
///
////////////////////////////////////////////////////////////
String(const Uint32* utf32String);
////////////////////////////////////////////////////////////
/// \brief Construct from an UTF-32 string
///
/// \param utf32String UTF-32 string to assign
///
////////////////////////////////////////////////////////////
String(const std::basic_string<Uint32>& utf32String);
////////////////////////////////////////////////////////////
/// \brief Copy constructor
///
/// \param other Instance to copy
///
////////////////////////////////////////////////////////////
String(const String& copy);
////////////////////////////////////////////////////////////
/// \brief Implicit cast operator to std::string (ANSI string)
///
/// The current global locale is used for conversion. If you
/// want to explicitely specify a locale, see ToAnsiString.
/// Characters that do not fit in the target encoding are
/// discarded from the returned string.
/// This operator is defined for convenience, and is equivalent
/// to calling ToAnsiString().
///
/// \return Converted ANSI string
///
////////////////////////////////////////////////////////////
operator std::string() const;
////////////////////////////////////////////////////////////
/// \brief Implicit cast operator to std::wstring (wide string)
///
/// Characters that do not fit in the target encoding are
/// discarded from the returned string.
/// This operator is defined for convenience, and is equivalent
/// to calling ToWideString().
///
/// \return Converted wide string
///
////////////////////////////////////////////////////////////
operator std::wstring() const;
////////////////////////////////////////////////////////////
/// \brief Convert the unicode string to an ANSI string
///
/// The current global locale is used for conversion. If you
/// want to explicitely specify a locale, see the other overload
/// of ToAnsiString.
/// Characters that do not fit in the target encoding are
/// discarded from the returned string.
///
/// \return Converted ANSI string
///
////////////////////////////////////////////////////////////
std::string ToAnsiString() const;
////////////////////////////////////////////////////////////
/// \brief Convert the unicode string to an ANSI string
///
/// The UTF-32 string is converted to an ANSI string in
/// the encoding defined by \a locale. If you want to use
/// the current global locale, see the other overload
/// of ToAnsiString.
/// Characters that do not fit in the target encoding are
/// discarded from the returned string.
///
/// \param locale Locale to use for conversion
///
/// \return Converted ANSI string
///
////////////////////////////////////////////////////////////
std::string ToAnsiString(const std::locale& locale) const;
////////////////////////////////////////////////////////////
/// \brief Convert the unicode string to a wide string
///
/// Characters that do not fit in the target encoding are
/// discarded from the returned string.
///
/// \return Converted wide string
///
////////////////////////////////////////////////////////////
std::wstring ToWideString() const;
////////////////////////////////////////////////////////////
/// \brief Overload of assignment operator
///
/// \param right Instance to assign
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
String& operator =(const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of += operator to append an ANSI character
///
/// \param right Character to append
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
String& operator +=(char right);
////////////////////////////////////////////////////////////
/// \brief Overload of += operator to append a wide character
///
/// \param right Character to append
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
String& operator +=(wchar_t right);
////////////////////////////////////////////////////////////
/// \brief Overload of += operator to append an UTF-32 character
///
/// \param right Character to append
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
String& operator +=(Uint32 right);
////////////////////////////////////////////////////////////
/// \brief Overload of += operator to append an UTF-32 string
///
/// \param right String to append
///
/// \return Reference to self
///
////////////////////////////////////////////////////////////
String& operator +=(const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of [] operator to access a character by its position
///
/// This function provides read-only access to characters.
/// Note: this function doesn't throw if \a index is out of range.
///
/// \param index Index of the character to get
///
/// \return Character at position \a index
///
////////////////////////////////////////////////////////////
Uint32 operator [](std::size_t index) const;
////////////////////////////////////////////////////////////
/// \brief Overload of [] operator to access a character by its position
///
/// This function provides read and write access to characters.
/// Note: this function doesn't throw if \a index is out of range.
///
/// \param index Index of the character to get
///
/// \return Reference to the character at position \a index
///
////////////////////////////////////////////////////////////
Uint32& operator [](std::size_t index);
////////////////////////////////////////////////////////////
/// \brief Clear the string
///
/// This function removes all the characters from the string.
///
/// \see IsEmpty, Erase
///
////////////////////////////////////////////////////////////
void Clear();
////////////////////////////////////////////////////////////
/// \brief Get the size of the string
///
/// \return Number of characters in the string
///
/// \see IsEmpty
///
////////////////////////////////////////////////////////////
std::size_t GetSize() const;
////////////////////////////////////////////////////////////
/// \brief Check whether the string is empty or not
///
/// \return True if the string is empty (i.e. contains no character)
///
/// \see Clear, GetSize
///
////////////////////////////////////////////////////////////
bool IsEmpty() const;
////////////////////////////////////////////////////////////
/// \brief Erase one or more characters from the string
///
/// This function removes a sequence of \a count characters
/// starting from \a position.
///
/// \param position Position of the first character to erase
/// \param count Number of characters to erase
///
////////////////////////////////////////////////////////////
void Erase(std::size_t position, std::size_t count = 1);
////////////////////////////////////////////////////////////
/// \brief Get a pointer to the C-style array of characters
///
/// This functions provides a read-only access to a
/// null-terminated C-style representation of the string.
/// The returned pointer is temporary and is meant only for
/// immediate use, thus it is not recommended to store it.
///
/// \return Read-only pointer to the array of characters
///
////////////////////////////////////////////////////////////
const Uint32* GetData() const;
////////////////////////////////////////////////////////////
/// \brief Return an iterator to the beginning of the string
///
/// \return Read-write iterator to the beginning of the string characters
///
/// \see End
///
////////////////////////////////////////////////////////////
Iterator Begin();
////////////////////////////////////////////////////////////
/// \brief Return an iterator to the beginning of the string
///
/// \return Read-only iterator to the beginning of the string characters
///
/// \see End
///
////////////////////////////////////////////////////////////
ConstIterator Begin() const;
////////////////////////////////////////////////////////////
/// \brief Return an iterator to the beginning of the string
///
/// The end iterator refers to 1 position past the last character;
/// thus it represents an invalid character and should never be
/// accessed.
///
/// \return Read-write iterator to the end of the string characters
///
/// \see Begin
///
////////////////////////////////////////////////////////////
Iterator End();
////////////////////////////////////////////////////////////
/// \brief Return an iterator to the beginning of the string
///
/// The end iterator refers to 1 position past the last character;
/// thus it represents an invalid character and should never be
/// accessed.
///
/// \return Read-only iterator to the end of the string characters
///
/// \see Begin
///
////////////////////////////////////////////////////////////
ConstIterator End() const;
private :
friend SFML_API bool operator ==(const String& left, const String& right);
friend SFML_API bool operator <(const String& left, const String& right);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::basic_string<Uint32> myString; ///< Internal string of UTF-32 characters
};
////////////////////////////////////////////////////////////
/// \brief Overload of == operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if both strings are equal
///
////////////////////////////////////////////////////////////
SFML_API bool operator ==(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of != operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if both strings are different
///
////////////////////////////////////////////////////////////
SFML_API bool operator !=(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of < operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if \a left is alphabetically lesser than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator <(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of > operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if \a left is alphabetically greater than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator >(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of <= operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if \a left is alphabetically lesser or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator <=(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of >= operator to compare two UTF-32 strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return True if \a left is alphabetically greater or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator >=(const String& left, const String& right);
////////////////////////////////////////////////////////////
/// \brief Overload of binary + operator to concatenate a string and an ANSI character
///
/// \param left Source string
/// \param right Character to concatenate
///
/// \return Concatenated string
///
////////////////////////////////////////////////////////////
SFML_API String operator +(const String& left, char right);
////////////////////////////////////////////////////////////
/// \brief Overload of binary + operator to concatenate a string and a wide character
///
/// \param left Source string
/// \param right Character to concatenate
///
/// \return Concatenated string
///
////////////////////////////////////////////////////////////
SFML_API String operator +(const String& left, wchar_t right);
////////////////////////////////////////////////////////////
/// \brief Overload of binary + operator to concatenate a string and a UTF-32 character
///
/// \param left Source string
/// \param right Character to concatenate
///
/// \return Concatenated string
///
////////////////////////////////////////////////////////////
SFML_API String operator +(const String& left, Uint32 right);
////////////////////////////////////////////////////////////
/// \brief Overload of binary + operator to concatenate two strings
///
/// \param left Left operand (a string)
/// \param right Right operand (a string)
///
/// \return Concatenated string
///
////////////////////////////////////////////////////////////
SFML_API String operator +(const String& left, const String& right);
} // namespace sf
#endif // SFML_STRING_HPP
////////////////////////////////////////////////////////////
/// \class sf::String
///
////////////////////////////////////////////////////////////

View File

@ -1,290 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_UNICODE_HPP
#define SFML_UNICODE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <iterator>
#include <locale>
#include <string>
#include <stdlib.h>
namespace sf
{
////////////////////////////////////////////////////////////
/// Provides utility functions to convert from and to
/// any unicode and ASCII encoding
////////////////////////////////////////////////////////////
class SFML_API Unicode
{
public :
////////////////////////////////////////////////////////////
/// Define a string type for each encoding
/// Warning : in UTF8 and UTF16 strings, one element doesn't
/// necessarily maps to one character ; only an UTF32 element
/// is wide enough to hold all possible unicode values
////////////////////////////////////////////////////////////
typedef std::basic_string<Uint8> UTF8String;
typedef std::basic_string<Uint16> UTF16String;
typedef std::basic_string<Uint32> UTF32String;
////////////////////////////////////////////////////////////
/// This class is an abstract definition of a unicode text,
/// it can be converted from and to any kind of string
/// and encoding
////////////////////////////////////////////////////////////
class SFML_API Text
{
public :
////////////////////////////////////////////////////////////
/// Default constructor (empty text)
///
////////////////////////////////////////////////////////////
Text();
////////////////////////////////////////////////////////////
/// Construct the unicode text from any type of string
///
/// \param str : String to convert
///
////////////////////////////////////////////////////////////
Text(const char* str);
Text(const wchar_t* str);
Text(const Uint8* str);
Text(const Uint16* str);
Text(const Uint32* str);
Text(const std::string& str);
Text(const std::wstring& str);
Text(const Unicode::UTF8String& str);
Text(const Unicode::UTF16String& str);
Text(const Unicode::UTF32String& str);
////////////////////////////////////////////////////////////
/// Operator to cast the text to any type of string
///
/// \return Converted string
///
////////////////////////////////////////////////////////////
operator std::string () const;
operator std::wstring () const;
operator Unicode::UTF8String () const;
operator Unicode::UTF16String () const;
operator const Unicode::UTF32String&() const;
private :
////////////////////////////////////////////////////////////
// Data member
////////////////////////////////////////////////////////////
sf::Unicode::UTF32String myUTF32String; ///< UTF-32 unicode text
};
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an ANSI characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
/// \param locale : Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF32ToANSI(In begin, In end, Out output, char replacement = '?', const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// Generic function to convert an ANSI characters range
/// to an UTF-32 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param locale : Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ANSIToUTF32(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-8 characters range
/// to an UTF-16 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF8ToUTF16(In begin, In end, Out output, Uint16 replacement = '?');
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-8 characters range
/// to an UTF-32 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF8ToUTF32(In begin, In end, Out output, Uint32 replacement = '?');
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-16 characters range
/// to an UTF-8 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF16ToUTF8(In begin, In end, Out output, Uint8 replacement = '?');
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-16 characters range
/// to an UTF-32 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF16ToUTF32(In begin, In end, Out output, Uint32 replacement = '?');
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an UTF-8 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF32ToUTF8(In begin, In end, Out output, Uint8 replacement = '?');
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an UTF-16 characters range, using the given locale
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
/// \param output : Iterator pointing to the beginning of the output sequence
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out UTF32ToUTF16(In begin, In end, Out output, Uint16 replacement = '?');
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-8 string
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
///
/// \return Count of the characters in the string
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t GetUTF8Length(In begin, In end);
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-16 string
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
///
/// \return Count of the characters in the string
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t GetUTF16Length(In begin, In end);
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-32 string
///
/// \param begin : Iterator pointing to the beginning of the input sequence
/// \param end : Iterator pointing to the end of the input sequence
///
/// \return Count of the characters in the string
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t GetUTF32Length(In begin, In end);
private :
////////////////////////////////////////////////////////////
/// Get the default system locale
///
/// \return Reference to the default system locale
///
////////////////////////////////////////////////////////////
static const std::locale& GetDefaultLocale();
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions
static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences
};
#include <SFML/System/Unicode.inl>
} // namespace sf
#endif // SFML_UNICODE_HPP

View File

@ -1,474 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an ANSI characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF32ToANSI(In begin, In end, Out output, char replacement, const std::locale& locale)
{
#ifdef __MINGW32__
// MinGW has a almost no support for unicode stuff
// As a consequence, the MinGW version of this function can only use the default locale
// and ignores the one passed as parameter
while (begin < end)
{
char character = 0;
if (wctomb(&character, static_cast<wchar_t>(*begin++)) >= 0)
*output++ = character;
else if (replacement)
*output++ = replacement;
}
#else
// Get the facet of the locale which deals with character conversion
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
// Use the facet to convert each character of the input string
while (begin < end)
*output++ = facet.narrow(static_cast<wchar_t>(*begin++), replacement);
#endif
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an ANSI characters range
/// to an UTF-32 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::ANSIToUTF32(In begin, In end, Out output, const std::locale& locale)
{
#ifdef __MINGW32__
// MinGW has a almost no support for unicode stuff
// As a consequence, the MinGW version of this function can only use the default locale
// and ignores the one passed as parameter
while (begin < end)
{
wchar_t character = 0;
mbtowc(&character, &*begin, 1);
begin++;
*output++ = static_cast<Uint32>(character);
}
#else
// Get the facet of the locale which deals with character conversion
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
// Use the facet to convert each character of the input string
while (begin < end)
*output++ = static_cast<Uint32>(facet.widen(*begin++));
#endif
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-8 characters range
/// to an UTF-16 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF8ToUTF16(In begin, In end, Out output, Uint16 replacement)
{
while (begin < end)
{
Uint32 character = 0;
int trailingBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
if (begin + trailingBytes < end)
{
// First decode the UTF-8 character
switch (trailingBytes)
{
case 5 : character += *begin++; character <<= 6;
case 4 : character += *begin++; character <<= 6;
case 3 : character += *begin++; character <<= 6;
case 2 : character += *begin++; character <<= 6;
case 1 : character += *begin++; character <<= 6;
case 0 : character += *begin++;
}
character -= UTF8Offsets[trailingBytes];
// Then encode it in UTF-16
if (character < 0xFFFF)
{
// Character can be converted directly to 16 bits, just need to check it's in the valid range
if ((character >= 0xD800) && (character <= 0xDFFF))
{
// Invalid character (this range is reserved)
if (replacement)
*output++ = replacement;
}
else
{
// Valid character directly convertible to 16 bits
*output++ = static_cast<Uint16>(character);
}
}
else if (character > 0x0010FFFF)
{
// Invalid character (greater than the maximum unicode value)
if (replacement)
*output++ = replacement;
}
else
{
// Character will be converted to 2 UTF-16 elements
character -= 0x0010000;
*output++ = static_cast<Uint16>((character >> 10) + 0xD800);
*output++ = static_cast<Uint16>((character & 0x3FFUL) + 0xDC00);
}
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-8 characters range
/// to an UTF-32 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF8ToUTF32(In begin, In end, Out output, Uint32 replacement)
{
while (begin < end)
{
Uint32 character = 0;
int trailingBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
if (begin + trailingBytes < end)
{
// First decode the UTF-8 character
switch (trailingBytes)
{
case 5 : character += *begin++; character <<= 6;
case 4 : character += *begin++; character <<= 6;
case 3 : character += *begin++; character <<= 6;
case 2 : character += *begin++; character <<= 6;
case 1 : character += *begin++; character <<= 6;
case 0 : character += *begin++;
}
character -= UTF8Offsets[trailingBytes];
// Then write it if valid
if ((character < 0xD800) || (character > 0xDFFF))
{
// Valid UTF-32 character
*output++ = character;
}
else
{
// Invalid UTF-32 character
if (replacement)
*output++ = replacement;
}
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-16 characters range
/// to an UTF-8 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF16ToUTF8(In begin, In end, Out output, Uint8 replacement)
{
while (begin < end)
{
Uint32 character = *begin++;
// If it's a surrogate pair, first convert to a single UTF-32 character
if ((character >= 0xD800) && (character <= 0xDBFF))
{
if (begin < end)
{
// The second element is valid : convert the two elements to a UTF-32 character
Uint32 d = *begin++;
if ((d >= 0xDC00) && (d <= 0xDFFF))
character = static_cast<Uint32>(((character - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
}
else
{
// Invalid second element
if (replacement)
*output++ = replacement;
}
}
// Then convert to UTF-8
if (character > 0x0010FFFF)
{
// Invalid character (greater than the maximum unicode value)
if (replacement)
*output++ = replacement;
}
else
{
// Valid character
// Get number of bytes to write
int bytesToWrite = 1;
if (character < 0x80) bytesToWrite = 1;
else if (character < 0x800) bytesToWrite = 2;
else if (character < 0x10000) bytesToWrite = 3;
else if (character <= 0x0010FFFF) bytesToWrite = 4;
// Extract bytes to write
Uint8 bytes[4];
switch (bytesToWrite)
{
case 4 : bytes[3] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 3 : bytes[2] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 2 : bytes[1] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 1 : bytes[0] = static_cast<Uint8> (character | UTF8FirstBytes[bytesToWrite]);
}
// Add them to the output
const Uint8* currentByte = bytes;
switch (bytesToWrite)
{
case 4 : *output++ = *currentByte++;
case 3 : *output++ = *currentByte++;
case 2 : *output++ = *currentByte++;
case 1 : *output++ = *currentByte++;
}
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-16 characters range
/// to an UTF-32 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF16ToUTF32(In begin, In end, Out output, Uint32 replacement)
{
while (begin < end)
{
Uint16 character = *begin++;
if ((character >= 0xD800) && (character <= 0xDBFF))
{
// We have a surrogate pair, ie. a character composed of two elements
if (begin < end)
{
Uint16 d = *begin++;
if ((d >= 0xDC00) && (d <= 0xDFFF))
{
// The second element is valid : convert the two elements to a UTF-32 character
*output++ = static_cast<Uint32>(((character - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
}
else
{
// Invalid second element
if (replacement)
*output++ = replacement;
}
}
}
else if ((character >= 0xDC00) && (character <= 0xDFFF))
{
// Invalid character
if (replacement)
*output++ = replacement;
}
else
{
// Valid character directly convertible to UTF-32
*output++ = static_cast<Uint32>(character);
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an UTF-8 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF32ToUTF8(In begin, In end, Out output, Uint8 replacement)
{
while (begin < end)
{
Uint32 character = *begin++;
if (character > 0x0010FFFF)
{
// Invalid character (greater than the maximum unicode value)
if (replacement)
*output++ = replacement;
}
else
{
// Valid character
// Get number of bytes to write
int bytesToWrite = 1;
if (character < 0x80) bytesToWrite = 1;
else if (character < 0x800) bytesToWrite = 2;
else if (character < 0x10000) bytesToWrite = 3;
else if (character <= 0x0010FFFF) bytesToWrite = 4;
// Extract bytes to write
Uint8 bytes[4];
switch (bytesToWrite)
{
case 4 : bytes[3] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 3 : bytes[2] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 2 : bytes[1] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
case 1 : bytes[0] = static_cast<Uint8> (character | UTF8FirstBytes[bytesToWrite]);
}
// Add them to the output
const Uint8* currentByte = bytes;
switch (bytesToWrite)
{
case 4 : *output++ = *currentByte++;
case 3 : *output++ = *currentByte++;
case 2 : *output++ = *currentByte++;
case 1 : *output++ = *currentByte++;
}
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Generic function to convert an UTF-32 characters range
/// to an UTF-16 characters range, using the given locale
////////////////////////////////////////////////////////////
template <typename In, typename Out>
inline Out Unicode::UTF32ToUTF16(In begin, In end, Out output, Uint16 replacement)
{
while (begin < end)
{
Uint32 character = *begin++;
if (character < 0xFFFF)
{
// Character can be converted directly to 16 bits, just need to check it's in the valid range
if ((character >= 0xD800) && (character <= 0xDFFF))
{
// Invalid character (this range is reserved)
if (replacement)
*output++ = replacement;
}
else
{
// Valid character directly convertible to 16 bits
*output++ = static_cast<Uint16>(character);
}
}
else if (character > 0x0010FFFF)
{
// Invalid character (greater than the maximum unicode value)
if (replacement)
*output++ = replacement;
}
else
{
// Character will be converted to 2 UTF-16 elements
character -= 0x0010000;
*output++ = static_cast<Uint16>((character >> 10) + 0xD800);
*output++ = static_cast<Uint16>((character & 0x3FFUL) + 0xDC00);
}
}
return output;
}
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-8 string
////////////////////////////////////////////////////////////
template <typename In>
inline std::size_t Unicode::GetUTF8Length(In begin, In end)
{
std::size_t length = 0;
while (begin < end)
{
int nbBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
if (begin + nbBytes < end)
++length;
begin += nbBytes + 1;
}
return length;
}
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-16 string
////////////////////////////////////////////////////////////
template <typename In>
inline std::size_t Unicode::GetUTF16Length(In begin, In end)
{
std::size_t length = 0;
while (begin < end)
{
if ((*begin >= 0xD800) && (*begin <= 0xDBFF))
{
++begin;
if ((begin < end) && ((*begin >= 0xDC00) && (*begin <= 0xDFFF)))
{
++length;
}
}
else
{
++length;
}
++begin;
}
return length;
}
////////////////////////////////////////////////////////////
/// Get the number of characters composing an UTF-32 string
////////////////////////////////////////////////////////////
template <typename In>
inline std::size_t Unicode::GetUTF32Length(In begin, In end)
{
return end - begin;
}

672
include/SFML/System/Utf.hpp Normal file
View File

@ -0,0 +1,672 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_UTF_HPP
#define SFML_UTF_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <algorithm>
#include <locale>
#include <string>
#include <stdlib.h>
namespace sf
{
////////////////////////////////////////////////////////////
/// Get the default system locale
///
/// \return Reference to the default system locale
///
////////////////////////////////////////////////////////////
SFML_API const std::locale& GetDefaultLocale();
////////////////////////////////////////////////////////////
/// \brief Utility class providing generic functions for UTF conversions
///
////////////////////////////////////////////////////////////
template <unsigned int N>
class Utf;
////////////////////////////////////////////////////////////
/// \brief Specialization of the Utf template for UTF-8
///
////////////////////////////////////////////////////////////
template <>
class Utf<8>
{
public :
////////////////////////////////////////////////////////////
/// \brief Decode a single UTF-8 character
///
/// Decoding a character means finding its unique 32-bits
/// code (called the codepoint) in the Unicode standard.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Codepoint of the decoded UTF-8 character
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Encode a single UTF-8 character
///
/// Encoding a character means converting a unique 32-bits
/// code (called the codepoint) in the target encoding, UTF-8.
///
/// \param input Codepoint to encode as UTF-8
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out Encode(Uint32 input, Out output, Uint8 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Advance to the next UTF-8 character
///
/// This function is necessary for multi-elements encodings, as
/// a single character may use more than 1 storage element.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Next(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Count the number of characters of a UTF-8 sequence
///
/// This function is necessary for multi-elements encodings, as
/// a single character may use more than 1 storage element, thus the
/// total size can be different from (begin - end).
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t Count(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Convert an ANSI characters range to UTF-8
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert a wide characters range to UTF-8
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromWide(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-8 characters range to ANSI characters
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-8 characters range to wide characters
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-8 characters range to UTF-8
///
/// This functions does nothing more than a direct copy;
/// it is defined only to provide the same interface as other
/// specializations of the sf::Utf<> template, and allow
/// generic code to be written on top of it.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf8(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-8 characters range to UTF-16
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf16(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-8 characters range to UTF-32
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf32(In begin, In end, Out output);
};
////////////////////////////////////////////////////////////
/// \brief Specialization of the Utf template for UTF-16
///
////////////////////////////////////////////////////////////
template <>
class Utf<16>
{
public :
////////////////////////////////////////////////////////////
/// \brief Decode a single UTF-16 character
///
/// Decoding a character means finding its unique 32-bits
/// code (called the codepoint) in the Unicode standard.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Codepoint of the decoded UTF-16 character
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Encode a single UTF-16 character
///
/// Encoding a character means converting a unique 32-bits
/// code (called the codepoint) in the target encoding, UTF-16.
///
/// \param input Codepoint to encode as UTF-16
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out Encode(Uint32 input, Out output, Uint16 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Advance to the next UTF-16 character
///
/// This function is necessary for multi-elements encodings, as
/// a single character may use more than 1 storage element.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Next(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Count the number of characters of a UTF-16 sequence
///
/// This function is necessary for multi-elements encodings, as
/// a single character may use more than 1 storage element, thus the
/// total size can be different from (begin - end).
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t Count(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Convert an ANSI characters range to UTF-16
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert a wide characters range to UTF-16
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromWide(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-16 characters range to ANSI characters
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-16 characters range to wide characters
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-16 characters range to UTF-8
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf8(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-16 characters range to UTF-16
///
/// This functions does nothing more than a direct copy;
/// it is defined only to provide the same interface as other
/// specializations of the sf::Utf<> template, and allow
/// generic code to be written on top of it.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf16(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-16 characters range to UTF-32
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf32(In begin, In end, Out output);
};
////////////////////////////////////////////////////////////
/// \brief Specialization of the Utf template for UTF-16
///
////////////////////////////////////////////////////////////
template <>
class Utf<32>
{
public :
////////////////////////////////////////////////////////////
/// \brief Decode a single UTF-32 character
///
/// Decoding a character means finding its unique 32-bits
/// code (called the codepoint) in the Unicode standard.
/// For UTF-32, the character value is the same as the codepoint.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Codepoint of the decoded UTF-32 character
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Encode a single UTF-32 character
///
/// Encoding a character means converting a unique 32-bits
/// code (called the codepoint) in the target encoding, UTF-32.
/// For UTF-32, the codepoint is the same as the character value.
///
/// \param input Codepoint to encode as UTF-32
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out Encode(Uint32 input, Out output, Uint32 replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Advance to the next UTF-32 character
///
/// This function is trivial for UTF-32, which can store
/// every character in a single storage element.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static In Next(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Count the number of characters of a UTF-32 sequence
///
/// This function is trivial for UTF-32, which can store
/// every character in a single storage element.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
///
/// \return Iterator pointing to one past the last read element of the input sequence
///
////////////////////////////////////////////////////////////
template <typename In>
static std::size_t Count(In begin, In end);
////////////////////////////////////////////////////////////
/// \brief Convert an ANSI characters range to UTF-32
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert a wide characters range to UTF-32
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out FromWide(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-32 characters range to ANSI characters
///
/// The current global locale will be used by default, unless you
/// pass a custom one in the \a locale parameter.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Convert an UTF-32 characters range to wide characters
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-32 characters range to UTF-8
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf8(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-32 characters range to UTF-16
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf16(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Convert a UTF-32 characters range to UTF-32
///
/// This functions does nothing more than a direct copy;
/// it is defined only to provide the same interface as other
/// specializations of the sf::Utf<> template, and allow
/// generic code to be written on top of it.
///
/// \param begin Iterator pointing to the beginning of the input sequence
/// \param end Iterator pointing to the end of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename In, typename Out>
static Out ToUtf32(In begin, In end, Out output);
////////////////////////////////////////////////////////////
/// \brief Decode a single ANSI character to UTF-32
///
/// This function does not exist in other specializations
/// of sf::Utf<>, it is defined for convenience (it is used by
/// several other conversion functions).
///
/// \param input Input ANSI character
/// \param locale Locale to use for conversion
///
/// \return Converted character
///
////////////////////////////////////////////////////////////
template <typename In>
static Uint32 DecodeAnsi(In input, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Decode a single wide character to UTF-32
///
/// This function does not exist in other specializations
/// of sf::Utf<>, it is defined for convenience (it is used by
/// several other conversion functions).
///
/// \param input Input wide character
///
/// \return Converted character
///
////////////////////////////////////////////////////////////
template <typename In>
static Uint32 DecodeWide(In input);
////////////////////////////////////////////////////////////
/// \brief Encode a single UTF-32 character to ANSI
///
/// This function does not exist in other specializations
/// of sf::Utf<>, it is defined for convenience (it is used by
/// several other conversion functions).
///
/// \param codepoint Iterator pointing to the beginning of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it)
/// \param locale Locale to use for conversion
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
////////////////////////////////////////////////////////////
/// \brief Encode a single UTF-32 character to wide
///
/// This function does not exist in other specializations
/// of sf::Utf<>, it is defined for convenience (it is used by
/// several other conversion functions).
///
/// \param codepoint Iterator pointing to the beginning of the input sequence
/// \param output Iterator pointing to the beginning of the output sequence
/// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it)
///
/// \return Iterator to the end of the output sequence which has been written
///
////////////////////////////////////////////////////////////
template <typename Out>
static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0);
};
#include <SFML/System/Utf.inl>
// Make typedefs to get rid of the template syntax
typedef Utf<8> Utf8;
typedef Utf<16> Utf16;
typedef Utf<32> Utf32;
} // namespace sf
#endif // SFML_UTF_HPP

665
include/SFML/System/Utf.inl Normal file
View File

@ -0,0 +1,665 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
template <typename In>
In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
{
// Some useful precomputed data
static const int trailing[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
};
static const Uint32 offsets[6] =
{
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
};
// Decode the character
int trailingBytes = trailing[static_cast<int>(*begin)];
if (begin + trailingBytes < end)
{
output = 0;
switch (trailingBytes)
{
case 5 : output += *begin++; output <<= 6;
case 4 : output += *begin++; output <<= 6;
case 3 : output += *begin++; output <<= 6;
case 2 : output += *begin++; output <<= 6;
case 1 : output += *begin++; output <<= 6;
case 0 : output += *begin++;
}
output -= offsets[trailingBytes];
}
else
{
// Incomplete character
begin = end;
output = replacement;
}
return begin;
}
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement)
{
// Some useful precomputed data
static const Uint8 firstBytes[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};
// Encode the character
if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF)))
{
// Invalid character
if (replacement)
*output++ = replacement;
}
else
{
// Valid character
// Get the number of bytes to write
int bytesToWrite = 1;
if (input < 0x80) bytesToWrite = 1;
else if (input < 0x800) bytesToWrite = 2;
else if (input < 0x10000) bytesToWrite = 3;
else if (input <= 0x0010FFFF) bytesToWrite = 4;
// Extract the bytes to write
Uint8 bytes[4];
switch (bytesToWrite)
{
case 4 : bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
case 3 : bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
case 2 : bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
case 1 : bytes[0] = static_cast<Uint8> (input | firstBytes[bytesToWrite]);
}
// Add them to the output
const Uint8* currentByte = bytes;
switch (bytesToWrite)
{
case 4 : *output++ = *currentByte++;
case 3 : *output++ = *currentByte++;
case 2 : *output++ = *currentByte++;
case 1 : *output++ = *currentByte++;
}
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
In Utf<8>::Next(In begin, In end)
{
Uint32 codepoint;
return Decode(begin, end, codepoint);
}
////////////////////////////////////////////////////////////
template <typename In>
std::size_t Utf<8>::Count(In begin, In end)
{
std::size_t length = 0;
while (begin < end)
{
begin = Next(begin, end);
++length;
}
return length;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
{
while (begin < end)
{
Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale);
output = Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::FromWide(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint = Utf<32>::DecodeWide(*begin++);
output = Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<32>::EncodeWide(codepoint, output, replacement);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::ToUtf8(In begin, In end, Out output)
{
while (begin < end)
*output++ = *begin++;
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::ToUtf16(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<16>::Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<8>::ToUtf32(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
*output++ = codepoint;
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
{
Uint16 first = *begin++;
// If it's a surrogate pair, first convert to a single UTF-32 character
if ((first >= 0xD800) && (first <= 0xDBFF))
{
if (begin < end)
{
Uint32 second = *begin++;
if ((second >= 0xDC00) && (second <= 0xDFFF))
{
// The second element is valid: convert the two elements to a UTF-32 character
output = static_cast<Uint32>(((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000);
}
else
{
// Invalid character
output = replacement;
}
}
else
{
// Invalid character
begin = end;
output = replacement;
}
}
else
{
// We can make a direct copy
output = first;
}
return begin;
}
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement)
{
if (input < 0xFFFF)
{
// The character can be copied directly, we just need to check if it's in the valid range
if ((input >= 0xD800) && (input <= 0xDFFF))
{
// Invalid character (this range is reserved)
if (replacement)
*output++ = replacement;
}
else
{
// Valid character directly convertible to a single UTF-16 character
*output++ = static_cast<Uint16>(input);
}
}
else if (input > 0x0010FFFF)
{
// Invalid character (greater than the maximum unicode value)
if (replacement)
*output++ = replacement;
}
else
{
// The input character will be converted to two UTF-16 elements
input -= 0x0010000;
*output++ = static_cast<Uint16>((input >> 10) + 0xD800);
*output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
In Utf<16>::Next(In begin, In end)
{
Uint32 codepoint;
return Decode(begin, end, codepoint);
}
////////////////////////////////////////////////////////////
template <typename In>
std::size_t Utf<16>::Count(In begin, In end)
{
std::size_t length = 0;
while (begin < end)
{
begin = Next(begin, end);
++length;
}
return length;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
{
while (begin < end)
{
Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale);
output = Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::FromWide(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint = Utf<32>::DecodeWide(*begin++);
output = Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<32>::EncodeWide(codepoint, output, replacement);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::ToUtf8(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
output = Utf<8>::Encode(codepoint, output);
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::ToUtf16(In begin, In end, Out output)
{
while (begin < end)
*output++ = *begin++;
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<16>::ToUtf32(In begin, In end, Out output)
{
while (begin < end)
{
Uint32 codepoint;
begin = Decode(begin, end, codepoint);
*output++ = codepoint;
}
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
In Utf<32>::Decode(In begin, In end, Uint32& output, Uint32)
{
output = *begin++;
return begin;
}
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<32>::Encode(Uint32 input, Out output, Uint32 replacement)
{
*output++ = input;
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
In Utf<32>::Next(In begin, In end)
{
return ++begin;
}
////////////////////////////////////////////////////////////
template <typename In>
std::size_t Utf<32>::Count(In begin, In end)
{
return begin - end;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
{
while (begin < end)
*output++ = DecodeAnsi(*begin++, locale);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::FromWide(In begin, In end, Out output)
{
while (begin < end)
*output++ = DecodeWide(*begin++);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
{
while (begin < end)
output = EncodeAnsi(*begin++, output, replacement, locale);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement)
{
while (begin < end)
output = EncodeWide(*begin++, output, replacement);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::ToUtf8(In begin, In end, Out output)
{
while (begin < end)
output = Utf<8>::Encode(*begin++, output);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::ToUtf16(In begin, In end, Out output)
{
while (begin < end)
output = Utf<16>::Encode(*begin++, output);
return output;
}
////////////////////////////////////////////////////////////
template <typename In, typename Out>
Out Utf<32>::ToUtf32(In begin, In end, Out output)
{
while (begin < end)
*output++ = *begin++;
return output;
}
////////////////////////////////////////////////////////////
template <typename In>
Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale)
{
#ifdef __MINGW32__
// MinGW has almost no support for unicode stuff
// As a consequence, the MinGW version of this function can only use the default locale
// and ignores the one passed as parameter
wchar_t character = 0;
mbtowc(&character, &input, 1);
return static_cast<Uint32>(character);
#else
// Get the facet of the locale which deals with character conversion
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
// Use the facet to convert each character of the input string
return static_cast<Uint32>(facet.widen(input));
#endif
}
////////////////////////////////////////////////////////////
template <typename In>
Uint32 Utf<32>::DecodeWide(In input)
{
// The encoding of wide characters is not well defined and is left to the system;
// however we can safely assume that it is UCS-2 on Windows and
// UCS-4 on Unix systems.
// In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4,
// and UCS-4 *is* UTF-32).
return input;
}
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale)
{
#ifdef __MINGW32__
// MinGW has almost no support for unicode stuff
// As a consequence, the MinGW version of this function can only use the default locale
// and ignores the one passed as parameter
char character = 0;
if (wctomb(&character, static_cast<wchar_t>(codepoint)) >= 0)
*output++ = character;
else if (replacement)
*output++ = replacement;
return output;
#else
// Get the facet of the locale which deals with character conversion
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
// Use the facet to convert each character of the input string
*output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement);
return output;
#endif
}
////////////////////////////////////////////////////////////
template <typename Out>
Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement)
{
// The encoding of wide characters is not well defined and is left to the system;
// however we can safely assume that it is UCS-2 on Windows and
// UCS-4 on Unix systems.
// For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4).
// For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32).
switch (sizeof(wchar_t))
{
case 4:
{
*output++ = static_cast<wchar_t>(codepoint);
break;
}
default:
{
if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF)))
{
*output++ = static_cast<wchar_t>(codepoint);
}
else if (replacement)
{
*output++ = replacement;
}
break;
}
}
return output;
}

View File

@ -141,10 +141,11 @@ int main()
glEnd(); glEnd();
// Draw some text on top of our OpenGL object // Draw some text on top of our OpenGL object
sf::String text("SFML / OpenGL demo"); sf::Text text("SFML / OpenGL demo");
text.SetPosition(250.f, 450.f); text.SetPosition(250.f, 450.f);
text.SetColor(sf::Color(255, 255, 255, 170)); text.SetColor(sf::Color(255, 255, 255, 170));
window.Draw(text); window.Draw(text);
std::wstring s = text.GetString();
// Finally, display the rendered frame on screen // Finally, display the rendered frame on screen
window.Display(); window.Display();

View File

@ -45,7 +45,7 @@ int main()
return EXIT_FAILURE; return EXIT_FAILURE;
// Initialize the end text // Initialize the end text
sf::String end; sf::Text end;
end.SetFont(font); end.SetFont(font);
end.SetSize(60.f); end.SetSize(60.f);
end.Move(150.f, 200.f); end.Move(150.f, 200.f);
@ -125,12 +125,12 @@ int main()
if (ball.GetPosition().x < 0.f) if (ball.GetPosition().x < 0.f)
{ {
isPlaying = false; isPlaying = false;
end.SetText("You lost !\n(press escape to exit)"); end.SetString("You lost !\n(press escape to exit)");
} }
if (ball.GetPosition().x + ball.GetSize().x > window.GetView().GetSize().x) if (ball.GetPosition().x + ball.GetSize().x > window.GetView().GetSize().x)
{ {
isPlaying = false; isPlaying = false;
end.SetText("You won !\n(press escape to exit)"); end.SetString("You won !\n(press escape to exit)");
} }
if (ball.GetPosition().y < 0.f) if (ball.GetPosition().y < 0.f)
{ {

View File

@ -142,25 +142,25 @@ int main()
shaders["pixelate"].SetTexture("texture", sf::Shader::CurrentTexture); shaders["pixelate"].SetTexture("texture", sf::Shader::CurrentTexture);
// Define a string for displaying the description of the current shader // Define a string for displaying the description of the current shader
sf::String shaderStr; sf::Text shaderStr;
shaderStr.SetFont(font); shaderStr.SetFont(font);
shaderStr.SetSize(20); shaderStr.SetSize(20);
shaderStr.SetPosition(5.f, 0.f); shaderStr.SetPosition(5.f, 0.f);
shaderStr.SetColor(sf::Color(250, 100, 30)); shaderStr.SetColor(sf::Color(250, 100, 30));
shaderStr.SetText("Background shader: \"" + backgroundShader.GetName() + "\"\n" shaderStr.SetString("Background shader: \"" + backgroundShader.GetName() + "\"\n"
"Flower shader: \"" + entityShader.GetName() + "\"\n" "Flower shader: \"" + entityShader.GetName() + "\"\n"
"Global shader: \"" + globalShader.GetName() + "\"\n"); "Global shader: \"" + globalShader.GetName() + "\"\n");
// Define a string for displaying help // Define a string for displaying help
sf::String infoStr; sf::Text infoStr;
infoStr.SetFont(font); infoStr.SetFont(font);
infoStr.SetSize(20); infoStr.SetSize(20);
infoStr.SetPosition(5.f, 510.f); infoStr.SetPosition(5.f, 510.f);
infoStr.SetColor(sf::Color(250, 100, 30)); infoStr.SetColor(sf::Color(250, 100, 30));
infoStr.SetText("Move your mouse to change the shaders' parameters\n" infoStr.SetString("Move your mouse to change the shaders' parameters\n"
"Press numpad 1/4 to change the background shader\n" "Press numpad 1/4 to change the background shader\n"
"Press numpad 2/5 to change the flower shader\n" "Press numpad 2/5 to change the flower shader\n"
"Press numpad 3/6 to change the global shader"); "Press numpad 3/6 to change the global shader");
// Create a clock to measure the total time elapsed // Create a clock to measure the total time elapsed
sf::Clock clock; sf::Clock clock;
@ -195,9 +195,9 @@ int main()
} }
// Update the text // Update the text
shaderStr.SetText("Background shader: \"" + backgroundShader.GetName() + "\"\n" shaderStr.SetString("Background shader: \"" + backgroundShader.GetName() + "\"\n"
"Entity shader: \"" + entityShader.GetName() + "\"\n" "Entity shader: \"" + entityShader.GetName() + "\"\n"
"Global shader: \"" + globalShader.GetName() + "\"\n"); "Global shader: \"" + globalShader.GetName() + "\"\n");
} }
} }
@ -249,7 +249,7 @@ void DisplayError()
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader"); sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
// Define a string for displaying the error message // Define a string for displaying the error message
sf::String error("Sorry, your system doesn't support shaders"); sf::Text error("Sorry, your system doesn't support shaders");
error.SetPosition(100.f, 250.f); error.SetPosition(100.f, 250.f);
error.SetColor(sf::Color(200, 100, 150)); error.SetColor(sf::Color(200, 100, 150));

View File

@ -71,26 +71,25 @@ myCharSize(0)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file /// Load the font from a file
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Font::LoadFromFile(const std::string& filename, unsigned int charSize, const Unicode::Text& charset) bool Font::LoadFromFile(const std::string& filename, unsigned int charSize, String charset)
{ {
// Clear the previous character map // Clear the previous character map
myGlyphs.clear(); myGlyphs.clear();
// Always add these special characters // Always add these special characters
Unicode::UTF32String UTFCharset = charset; if (std::find(charset.Begin(), charset.End(), L' ') == charset.End()) charset += L' ';
if (UTFCharset.find(L' ') != Unicode::UTF32String::npos) UTFCharset += L' '; if (std::find(charset.Begin(), charset.End(), L'\n') == charset.End()) charset += L'\n';
if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n'; if (std::find(charset.Begin(), charset.End(), L'\v') == charset.End()) charset += L'\v';
if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v'; if (std::find(charset.Begin(), charset.End(), L'\t') == charset.End()) charset += L'\t';
if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
return priv::FontLoader::GetInstance().LoadFontFromFile(filename, charSize, UTFCharset, *this); return priv::FontLoader::GetInstance().LoadFontFromFile(filename, charSize, charset, *this);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file in memory /// Load the font from a file in memory
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::Text& charset) bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, String charset)
{ {
// Clear the previous character map // Clear the previous character map
myGlyphs.clear(); myGlyphs.clear();
@ -103,13 +102,12 @@ bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned in
} }
// Always add these special characters // Always add these special characters
Unicode::UTF32String UTFCharset = charset; if (std::find(charset.Begin(), charset.End(), L' ') == charset.End()) charset += L' ';
if (UTFCharset.find(L' ') != Unicode::UTF32String::npos) UTFCharset += L' '; if (std::find(charset.Begin(), charset.End(), L'\n') == charset.End()) charset += L'\n';
if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n'; if (std::find(charset.Begin(), charset.End(), L'\v') == charset.End()) charset += L'\v';
if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v'; if (std::find(charset.Begin(), charset.End(), L'\t') == charset.End()) charset += L'\t';
if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
return priv::FontLoader::GetInstance().LoadFontFromMemory(data, sizeInBytes, charSize, UTFCharset, *this); return priv::FontLoader::GetInstance().LoadFontFromMemory(data, sizeInBytes, charSize, charset, *this);
} }
@ -158,21 +156,22 @@ const Image& Font::GetImage() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Font& Font::GetDefaultFont() const Font& Font::GetDefaultFont()
{ {
static Font defaultFont; static Font font;
static bool defaultFontLoaded = false; static bool loaded = false;
static const char defaultFontData[] =
{
#include <SFML/Graphics/Arial.hpp>
};
// Load the default font on first call // Load the default font on first call
if (!defaultFontLoaded) if (!loaded)
{ {
defaultFont.LoadFromMemory(defaultFontData, sizeof(defaultFontData), 30); static const char data[] =
defaultFontLoaded = true; {
#include <SFML/Graphics/Arial.hpp>
};
font.LoadFromMemory(data, sizeof(data), 30);
loaded = true;
} }
return defaultFont; return font;
} }
} // namespace sf } // namespace sf

View File

@ -98,7 +98,7 @@ FontLoader::~FontLoader()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load a font from a file /// Load a font from a file
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font)
{ {
// Check if Freetype is correctly initialized // Check if Freetype is correctly initialized
if (!myLibrary) if (!myLibrary)
@ -131,7 +131,7 @@ bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int char
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file in memory /// Load the font from a file in memory
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font)
{ {
// Check if Freetype is correctly initialized // Check if Freetype is correctly initialized
if (!myLibrary) if (!myLibrary)
@ -164,12 +164,12 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create a bitmap font from a font face and a characters set /// Create a bitmap font from a font face and a characters set
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font)
{ {
// Let's find how many characters to put in each row to make them fit into a squared texture // Let's find how many characters to put in each row to make them fit into a squared texture
GLint maxSize; GLint maxSize;
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize)); GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.length())) * 0.75); int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
// Clamp the character size to make sure we won't create a texture too big // Clamp the character size to make sure we won't create a texture too big
if (nbChars * charSize >= static_cast<unsigned int>(maxSize)) if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
@ -198,7 +198,7 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const
// Render all glyphs and sort them by size to optimize texture space // Render all glyphs and sort them by size to optimize texture space
typedef std::multimap<FT_BitmapGlyph, Uint32, SizeCompare> GlyphTable; typedef std::multimap<FT_BitmapGlyph, Uint32, SizeCompare> GlyphTable;
GlyphTable glyphs; GlyphTable glyphs;
for (std::size_t i = 0; i < charset.length(); ++i) for (std::size_t i = 0; i < charset.GetSize(); ++i)
{ {
// Load the glyph corresponding to the current character // Load the glyph corresponding to the current character
error = FT_Load_Char(face, charset[i], FT_LOAD_TARGET_NORMAL); error = FT_Load_Char(face, charset[i], FT_LOAD_TARGET_NORMAL);
@ -293,7 +293,7 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const
font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]); font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]);
// Now that the texture is created, we can precompute texture coordinates // Now that the texture is created, we can precompute texture coordinates
for (std::size_t i = 0; i < charset.size(); ++i) for (std::size_t i = 0; i < charset.GetSize(); ++i)
{ {
Uint32 curChar = charset[i]; Uint32 curChar = charset[i];
font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]); font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]);
@ -491,7 +491,7 @@ FontLoader::~FontLoader()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load a font from a file /// Load a font from a file
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font)
{ {
// Get the contents of the font file // Get the contents of the font file
std::ifstream file(filename.c_str(), std::ios_base::binary); std::ifstream file(filename.c_str(), std::ios_base::binary);
@ -511,12 +511,12 @@ bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int char
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file in memory /// Load the font from a file in memory
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font)
{ {
// Let's find how many characters to put in each row to make them fit into a squared texture // Let's find how many characters to put in each row to make them fit into a squared texture
GLint maxSize; GLint maxSize;
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize)); GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.length())) * 0.75); int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
// Clamp the character size to make sure we won't create a texture too big // Clamp the character size to make sure we won't create a texture too big
if (nbChars * charSize >= static_cast<unsigned int>(maxSize)) if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
@ -544,7 +544,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
// Render all glyphs and sort them by size to optimize texture space // Render all glyphs and sort them by size to optimize texture space
typedef std::multimap<Glyph, Uint32, SizeCompare> GlyphTable; typedef std::multimap<Glyph, Uint32, SizeCompare> GlyphTable;
GlyphTable glyphs; GlyphTable glyphs;
for (std::size_t i = 0; i < charset.length(); ++i) for (std::size_t i = 0; i < charset.GetSize(); ++i)
{ {
// Load the glyph corresponding to the current character // Load the glyph corresponding to the current character
int index = stbtt_FindGlyphIndex(&info, static_cast<int>(charset[i])); int index = stbtt_FindGlyphIndex(&info, static_cast<int>(charset[i]));
@ -636,7 +636,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]); font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]);
// Now that the texture is created, we can precompute texture coordinates // Now that the texture is created, we can precompute texture coordinates
for (std::size_t i = 0; i < charset.size(); ++i) for (std::size_t i = 0; i < charset.GetSize(); ++i)
{ {
Uint32 curChar = charset[i]; Uint32 curChar = charset[i];
font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]); font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]);
@ -652,7 +652,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create a bitmap font from a font face and a characters set /// Create a bitmap font from a font face and a characters set
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font) FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font)
{ {
return 0; return 0;
} }

View File

@ -29,7 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/NonCopyable.hpp> #include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Unicode.hpp> #include <SFML/System/String.hpp>
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include <string> #include <string>
@ -67,7 +67,7 @@ public :
/// \return True if loading was successful /// \return True if loading was successful
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font); bool LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Load the font from a file in memory /// Load the font from a file in memory
@ -81,7 +81,7 @@ public :
/// \return True if loading was successful /// \return True if loading was successful
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font); bool LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font);
private : private :
@ -106,7 +106,7 @@ private :
/// \param font : Font object to fill up /// \param font : Font object to fill up
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FT_Error CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font); FT_Error CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get a description from a FT error code /// Get a description from a FT error code

View File

@ -25,7 +25,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/String.hpp> #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/Image.hpp> #include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderQueue.hpp> #include <SFML/Graphics/RenderQueue.hpp>
@ -35,7 +35,7 @@ namespace sf
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Default constructor /// Default constructor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String() : Text::Text() :
myFont (&Font::GetDefaultFont()), myFont (&Font::GetDefaultFont()),
mySize (30.f), mySize (30.f),
myStyle (Regular), myStyle (Regular),
@ -48,30 +48,30 @@ myNeedRectUpdate(true)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the string from any kind of text /// Construct the string from any kind of text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String::String(const Unicode::Text& text, const Font& font, float size) : Text::Text(const String& string, const Font& font, float size) :
myFont (&font), myFont (&font),
mySize (size), mySize (size),
myStyle (Regular), myStyle (Regular),
myNeedRectUpdate(true) myNeedRectUpdate(true)
{ {
SetText(text); SetString(string);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the text (from any kind of string) /// Set the text (from any kind of string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::SetText(const Unicode::Text& text) void Text::SetString(const String& string)
{ {
myNeedRectUpdate = true; myNeedRectUpdate = true;
myText = text; myString = string;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the font of the string /// Set the font of the string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::SetFont(const Font& font) void Text::SetFont(const Font& font)
{ {
if (myFont != &font) if (myFont != &font)
{ {
@ -84,7 +84,7 @@ void String::SetFont(const Font& font)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Set the size of the string /// Set the size of the string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::SetSize(float size) void Text::SetSize(float size)
{ {
if (mySize != size) if (mySize != size)
{ {
@ -98,7 +98,7 @@ void String::SetSize(float size)
/// Set the style of the text /// Set the style of the text
/// The default style is Regular /// The default style is Regular
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::SetStyle(unsigned long style) void Text::SetStyle(unsigned long style)
{ {
if (myStyle != style) if (myStyle != style)
{ {
@ -111,16 +111,16 @@ void String::SetStyle(unsigned long style)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the text (the returned text can be converted implicitely to any kind of string) /// Get the text (the returned text can be converted implicitely to any kind of string)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Unicode::Text& String::GetText() const const String& Text::GetString() const
{ {
return myText; return myString;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the font used by the string /// Get the font used by the string
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Font& String::GetFont() const const Font& Text::GetFont() const
{ {
return *myFont; return *myFont;
} }
@ -129,7 +129,7 @@ const Font& String::GetFont() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the size of the characters /// Get the size of the characters
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float String::GetSize() const float Text::GetSize() const
{ {
return mySize; return mySize;
} }
@ -138,7 +138,7 @@ float String::GetSize() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the style of the text /// Get the style of the text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned long String::GetStyle() const unsigned long Text::GetStyle() const
{ {
return myStyle; return myStyle;
} }
@ -149,14 +149,11 @@ unsigned long String::GetStyle() const
/// in coordinates relative to the string /// in coordinates relative to the string
/// (note : translation, center, rotation and scale are not applied) /// (note : translation, center, rotation and scale are not applied)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::Vector2f String::GetCharacterPos(std::size_t index) const sf::Vector2f Text::GetCharacterPos(std::size_t index) const
{ {
// First get the UTF32 representation of the text
const Unicode::UTF32String& text = myText;
// Adjust the index if it's out of range // Adjust the index if it's out of range
if (index > text.length()) if (index > myString.GetSize())
index = text.length(); index = myString.GetSize();
// The final size is based on the text size // The final size is based on the text size
float factor = mySize / myFont->GetCharacterSize(); float factor = mySize / myFont->GetCharacterSize();
@ -167,7 +164,7 @@ sf::Vector2f String::GetCharacterPos(std::size_t index) const
for (std::size_t i = 0; i < index; ++i) for (std::size_t i = 0; i < index; ++i)
{ {
// Get the current character and its corresponding glyph // Get the current character and its corresponding glyph
Uint32 curChar = text[i]; Uint32 curChar = myString[i];
const Glyph& curGlyph = myFont->GetGlyph(curChar); const Glyph& curGlyph = myFont->GetGlyph(curChar);
float advanceX = curGlyph.Advance * factor; float advanceX = curGlyph.Advance * factor;
@ -191,10 +188,10 @@ sf::Vector2f String::GetCharacterPos(std::size_t index) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the string rectangle on screen /// Get the string rectangle on screen
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FloatRect String::GetRect() const FloatRect Text::GetRect() const
{ {
if (myNeedRectUpdate) if (myNeedRectUpdate)
const_cast<String*>(this)->RecomputeRect(); const_cast<Text*>(this)->RecomputeRect();
FloatRect rect; FloatRect rect;
rect.Left = (myBaseRect.Left - GetOrigin().x) * GetScale().x + GetPosition().x; rect.Left = (myBaseRect.Left - GetOrigin().x) * GetScale().x + GetPosition().x;
@ -209,13 +206,10 @@ FloatRect String::GetRect() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// /see sfDrawable::Render /// /see sfDrawable::Render
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::Render(RenderTarget&, RenderQueue& queue) const void Text::Render(RenderTarget&, RenderQueue& queue) const
{ {
// First get the internal UTF-32 string of the text
const Unicode::UTF32String& text = myText;
// No text, no rendering :) // No text, no rendering :)
if (text.empty()) if (myString.IsEmpty())
return; return;
// Set the scaling factor to get the actual size // Set the scaling factor to get the actual size
@ -239,10 +233,10 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
// Draw one quad for each character // Draw one quad for each character
unsigned int index = 0; unsigned int index = 0;
queue.BeginBatch(); queue.BeginBatch();
for (std::size_t i = 0; i < text.size(); ++i) for (std::size_t i = 0; i < myString.GetSize(); ++i)
{ {
// Get the current character and its corresponding glyph // Get the current character and its corresponding glyph
Uint32 curChar = text[i]; Uint32 curChar = myString[i];
const Glyph& curGlyph = myFont->GetGlyph(curChar); const Glyph& curGlyph = myFont->GetGlyph(curChar);
int advance = curGlyph.Advance; int advance = curGlyph.Advance;
const IntRect& rect = curGlyph.Rectangle; const IntRect& rect = curGlyph.Rectangle;
@ -294,10 +288,10 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
y = charSize; y = charSize;
queue.BeginBatch(); queue.BeginBatch();
for (std::size_t i = 0; i < text.size(); ++i) for (std::size_t i = 0; i < myString.GetSize(); ++i)
{ {
// Get the current character and its corresponding glyph // Get the current character and its corresponding glyph
Uint32 curChar = text[i]; Uint32 curChar = myString[i];
const Glyph& curGlyph = myFont->GetGlyph(curChar); const Glyph& curGlyph = myFont->GetGlyph(curChar);
int advance = curGlyph.Advance; int advance = curGlyph.Advance;
const IntRect& rect = curGlyph.Rectangle; const IntRect& rect = curGlyph.Rectangle;
@ -360,16 +354,13 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Recompute the bounding rectangle of the text /// Recompute the bounding rectangle of the text
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void String::RecomputeRect() void Text::RecomputeRect()
{ {
// First get the internal UTF-32 string of the text
const Unicode::UTF32String& text = myText;
// Reset the "need update" state // Reset the "need update" state
myNeedRectUpdate = false; myNeedRectUpdate = false;
// No text, empty box :) // No text, empty box :)
if (text.empty()) if (myString.IsEmpty())
{ {
myBaseRect = FloatRect(0, 0, 0, 0); myBaseRect = FloatRect(0, 0, 0, 0);
return; return;
@ -383,10 +374,10 @@ void String::RecomputeRect()
float factor = mySize / myFont->GetCharacterSize(); float factor = mySize / myFont->GetCharacterSize();
// Go through each character // Go through each character
for (std::size_t i = 0; i < text.size(); ++i) for (std::size_t i = 0; i < myString.GetSize(); ++i)
{ {
// Get the current character and its corresponding glyph // Get the current character and its corresponding glyph
Uint32 curChar = text[i]; Uint32 curChar = myString[i];
const Glyph& curGlyph = myFont->GetGlyph(curChar); const Glyph& curGlyph = myFont->GetGlyph(curChar);
float advance = curGlyph.Advance * factor; float advance = curGlyph.Advance * factor;
const IntRect& rect = curGlyph.Rectangle; const IntRect& rect = curGlyph.Rectangle;

387
src/SFML/System/String.cpp Normal file
View File

@ -0,0 +1,387 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/String.hpp>
#include <SFML/System/Utf.hpp>
#include <iterator>
#include <string.h>
namespace sf
{
////////////////////////////////////////////////////////////
String::String()
{
}
////////////////////////////////////////////////////////////
String::String(const char* ansiString)
{
if (ansiString)
{
std::size_t length = strlen(ansiString);
if (length > 0)
{
myString.reserve(length + 1);
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(myString));
}
}
}
////////////////////////////////////////////////////////////
String::String(const std::string& ansiString)
{
myString.reserve(ansiString.length() + 1);
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(myString));
}
////////////////////////////////////////////////////////////
String::String(const char* ansiString, const std::locale& locale)
{
if (ansiString)
{
std::size_t length = strlen(ansiString);
if (length > 0)
{
myString.reserve(length + 1);
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(myString), locale);
}
}
}
////////////////////////////////////////////////////////////
String::String(const std::string& ansiString, const std::locale& locale)
{
myString.reserve(ansiString.length() + 1);
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(myString), locale);
}
////////////////////////////////////////////////////////////
String::String(const wchar_t* wideString)
{
if (wideString)
{
std::size_t length = wcslen(wideString);
if (length > 0)
{
myString.reserve(length + 1);
Utf32::FromWide(wideString, wideString + length, std::back_inserter(myString));
}
}
}
////////////////////////////////////////////////////////////
String::String(const std::wstring& wideString)
{
myString.reserve(wideString.length() + 1);
Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(myString));
}
////////////////////////////////////////////////////////////
String::String(const Uint32* utf32String)
{
if (utf32String)
myString = utf32String;
}
////////////////////////////////////////////////////////////
String::String(const std::basic_string<Uint32>& utf32String) :
myString(utf32String)
{
}
////////////////////////////////////////////////////////////
String::String(const String& copy) :
myString(copy.myString)
{
}
////////////////////////////////////////////////////////////
String::operator std::string() const
{
return ToAnsiString();
}
////////////////////////////////////////////////////////////
String::operator std::wstring() const
{
return ToWideString();
}
////////////////////////////////////////////////////////////
std::string String::ToAnsiString() const
{
// Prepare the output string
std::string output;
output.reserve(myString.length() + 1);
// Convert
Utf32::ToAnsi(myString.begin(), myString.end(), std::back_inserter(output), 0);
return output;
}
////////////////////////////////////////////////////////////
std::string String::ToAnsiString(const std::locale& locale) const
{
// Prepare the output string
std::string output;
output.reserve(myString.length() + 1);
// Convert
Utf32::ToAnsi(myString.begin(), myString.end(), std::back_inserter(output), 0, locale);
return output;
}
////////////////////////////////////////////////////////////
std::wstring String::ToWideString() const
{
// Prepare the output string
std::wstring output;
output.reserve(myString.length() + 1);
// Convert
Utf32::ToWide(myString.begin(), myString.end(), std::back_inserter(output), 0);
return output;
}
////////////////////////////////////////////////////////////
String& String::operator =(const String& right)
{
myString = right.myString;
return *this;
}
////////////////////////////////////////////////////////////
String& String::operator +=(char right)
{
myString += Utf32::DecodeAnsi(right);
return *this;
}
////////////////////////////////////////////////////////////
String& String::operator +=(wchar_t right)
{
myString += Utf32::DecodeWide(right);
return *this;
}
////////////////////////////////////////////////////////////
String& String::operator +=(Uint32 right)
{
myString += right;
return *this;
}
////////////////////////////////////////////////////////////
String& String::operator +=(const String& right)
{
myString += right.myString;
return *this;
}
////////////////////////////////////////////////////////////
Uint32 String::operator [](std::size_t index) const
{
return myString[index];
}
////////////////////////////////////////////////////////////
Uint32& String::operator [](std::size_t index)
{
return myString[index];
}
////////////////////////////////////////////////////////////
void String::Clear()
{
myString.clear();
}
////////////////////////////////////////////////////////////
std::size_t String::GetSize() const
{
return myString.size();
}
////////////////////////////////////////////////////////////
bool String::IsEmpty() const
{
return myString.empty();
}
////////////////////////////////////////////////////////////
void String::Erase(std::size_t position, std::size_t count)
{
myString.erase(position, count);
}
////////////////////////////////////////////////////////////
const Uint32* String::GetData() const
{
return myString.c_str();
}
////////////////////////////////////////////////////////////
String::Iterator String::Begin()
{
return myString.begin();
}
////////////////////////////////////////////////////////////
String::ConstIterator String::Begin() const
{
return myString.begin();
}
////////////////////////////////////////////////////////////
String::Iterator String::End()
{
return myString.end();
}
////////////////////////////////////////////////////////////
String::ConstIterator String::End() const
{
return myString.end();
}
////////////////////////////////////////////////////////////
bool operator ==(const String& left, const String& right)
{
return left.myString == right.myString;
}
////////////////////////////////////////////////////////////
bool operator !=(const String& left, const String& right)
{
return !(left == right);
}
////////////////////////////////////////////////////////////
bool operator <(const String& left, const String& right)
{
return left.myString < right.myString;
}
////////////////////////////////////////////////////////////
bool operator >(const String& left, const String& right)
{
return right < left;
}
////////////////////////////////////////////////////////////
bool operator <=(const String& left, const String& right)
{
return !(right < left);
}
////////////////////////////////////////////////////////////
bool operator >=(const String& left, const String& right)
{
return !(left < right);
}
////////////////////////////////////////////////////////////
String operator +(const String& left, char right)
{
String string = left;
string += right;
return string;
}
////////////////////////////////////////////////////////////
String operator +(const String& left, wchar_t right)
{
String string = left;
string += right;
return string;
}
////////////////////////////////////////////////////////////
String operator +(const String& left, Uint32 right)
{
String string = left;
string += right;
return string;
}
////////////////////////////////////////////////////////////
String operator +(const String& left, const String& right)
{
String string = left;
string += right;
return string;
}
} // namespace sf

View File

@ -1,300 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Unicode.hpp>
#include <stdexcept>
#include <string.h>
////////////////////////////////////////////////////////////
// References :
//
// http://www.unicode.org/
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
// http://people.w3.org/rishida/scripts/uniview/conversion
//
////////////////////////////////////////////////////////////
namespace
{
////////////////////////////////////////////////////////////
// Generic utility function to compute the number
// of characters in a null-terminated string of any type
////////////////////////////////////////////////////////////
template <typename T>
std::size_t StrLen(const T* Str)
{
std::size_t Length = 0;
while (*Str++) Length++;
return Length;
}
////////////////////////////////////////////////////////////
// Get the current system locale
////////////////////////////////////////////////////////////
std::locale GetCurrentLocale()
{
try
{
return std::locale("");
}
catch (std::runtime_error&)
{
// It seems some implementations don't know the "" locale
// (Mac OS, MinGW)
return std::locale();
}
}
}
namespace sf
{
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
const int Unicode::UTF8TrailingBytes[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
};
const Uint32 Unicode::UTF8Offsets[6] =
{
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
};
const Uint8 Unicode::UTF8FirstBytes[7] =
{
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};
////////////////////////////////////////////////////////////
/// Default constructor (empty text)
////////////////////////////////////////////////////////////
Unicode::Text::Text()
{
// Nothing to do
}
////////////////////////////////////////////////////////////
/// Construct the unicode text from any type of string
////////////////////////////////////////////////////////////
Unicode::Text::Text(const char* Str)
{
if (Str)
{
std::size_t Length = StrLen(Str);
if (Length > 0)
{
myUTF32String.reserve(Length + 1);
Unicode::ANSIToUTF32(Str, Str + Length, std::back_inserter(myUTF32String));
}
}
}
Unicode::Text::Text(const wchar_t* Str)
{
if (Str)
{
std::size_t Length = StrLen(Str);
if (Length > 0)
{
// See comments below, in Unicode::Text::Text(const std::wstring&)
myUTF32String.reserve(Length + 1);
switch (sizeof(wchar_t))
{
case 2 : Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0); break;
case 4 : std::copy(Str, Str + Length, std::back_inserter(myUTF32String)); break;
default : break;
}
}
}
}
Unicode::Text::Text(const Uint8* Str)
{
if (Str)
{
std::size_t Length = StrLen(Str);
if (Length > 0)
{
myUTF32String.reserve(Length + 1);
Unicode::UTF8ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
}
}
}
Unicode::Text::Text(const Uint16* Str)
{
if (Str)
{
std::size_t Length = StrLen(Str);
if (Length > 0)
{
myUTF32String.reserve(Length+ 1);
Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
}
}
}
Unicode::Text::Text(const Uint32* Str)
{
if (Str)
myUTF32String = Str;
}
Unicode::Text::Text(const std::string& Str)
{
myUTF32String.reserve(Str.length() + 1);
Unicode::ANSIToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
}
Unicode::Text::Text(const std::wstring& Str)
{
// This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
// 4-byte large wchar_t are encoded using UTF-32 (Unix)
// Is that always true ? (some platforms may use JIS Japanese encoding)
// The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
myUTF32String.reserve(Str.length() + 1);
// Select the proper function according to the (supposed) wchar_t system encoding
switch (sizeof(wchar_t))
{
// wchar_t uses UTF-16 -- need a conversion
case 2 :
{
Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
break;
}
// wchar_t uses UTF-32 -- direct copy
case 4 :
{
std::copy(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
break;
}
// This should never happen
default : break;
}
}
Unicode::Text::Text(const Unicode::UTF8String& Str)
{
myUTF32String.reserve(Str.length() + 1);
Unicode::UTF8ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
}
Unicode::Text::Text(const Unicode::UTF16String& Str)
{
myUTF32String.reserve(Str.length() + 1);
Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
}
Unicode::Text::Text(const Unicode::UTF32String& Str)
{
myUTF32String = Str;
}
////////////////////////////////////////////////////////////
/// Operator to cast the text to any type of string
////////////////////////////////////////////////////////////
Unicode::Text::operator std::string() const
{
std::string Output;
Output.reserve(myUTF32String.length() + 1);
Unicode::UTF32ToANSI(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0, Unicode::GetDefaultLocale());
return Output;
}
Unicode::Text::operator std::wstring() const
{
// This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
// 4-byte large wchar_t are encoded using UTF-32 (Unix)
// Is that always true ? (some platforms may use JIS Japanese encoding)
// The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
std::wstring Output;
Output.reserve(myUTF32String.length() + 1);
// Select the proper function according to the (supposed) wchar_t system encoding
switch (sizeof(wchar_t))
{
// wchar_t uses UTF-16 -- need a conversion
case 2 :
{
UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
break;
}
// wchar_t uses UTF-32 -- direct copy
case 4 :
{
std::copy(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output));
break;
}
// This should never happen
default : break;
}
return Output;
}
Unicode::Text::operator sf::Unicode::UTF8String() const
{
Unicode::UTF8String Output;
Output.reserve(myUTF32String.length() * 4 + 1);
Unicode::UTF32ToUTF8(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
return Output;
}
Unicode::Text::operator sf::Unicode::UTF16String() const
{
Unicode::UTF16String Output;
Output.reserve(myUTF32String.length() * 2 + 1);
Unicode::UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
return Output;
}
Unicode::Text::operator const sf::Unicode::UTF32String&() const
{
return myUTF32String;
}
////////////////////////////////////////////////////////////
/// Get the default system locale
////////////////////////////////////////////////////////////
const std::locale& Unicode::GetDefaultLocale()
{
// It seems getting the default locale is a very expensive operation,
// so we only do it once and then store the locale for reuse.
// Warning : this code won't be aware of any change of the default locale during runtime
static std::locale DefaultLocale = GetCurrentLocale();
return DefaultLocale;
}
} // namespace sf

79
src/SFML/System/Utf.cpp Normal file
View File

@ -0,0 +1,79 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Utf.hpp>
#include <exception>
#include <string.h>
////////////////////////////////////////////////////////////
// References :
//
// http://www.unicode.org/
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
// http://people.w3.org/rishida/scripts/uniview/conversion
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Private data
////////////////////////////////////////////////////////////
namespace
{
// Get the current global locale
std::locale GetCurrentLocale()
{
try
{
return std::locale("");
}
catch (std::exception&)
{
// It seems that some implementations don't know the "" locale (Mac OS X, MinGW)
return std::locale();
}
}
}
namespace sf
{
////////////////////////////////////////////////////////////
/// Get the default system locale
////////////////////////////////////////////////////////////
const std::locale& GetDefaultLocale()
{
// It seems that getting the default locale is a very expensive operation,
// so we only do it once and then store the locale for reuse.
// Warning: this code won't be aware of any change of the default locale during runtime.
static std::locale locale = GetCurrentLocale();
return locale;
}
} // namespace sf

View File

@ -698,14 +698,13 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
int length = Xutf8LookupString(myInputContext, &windowEvent.xkey, reinterpret_cast<char*>(keyBuffer), sizeof(keyBuffer), NULL, &status); int length = Xutf8LookupString(myInputContext, &windowEvent.xkey, reinterpret_cast<char*>(keyBuffer), sizeof(keyBuffer), NULL, &status);
if (length > 0) if (length > 0)
{ {
Uint32 unicode[2]; // just in case, but 1 character should be enough Uint32 unicode = 0;
const Uint32* end = Unicode::UTF8ToUTF32(keyBuffer, keyBuffer + length, unicode); Utf8::Decode(keyBuffer, keyBuffer + length, unicode, 0);
if (unicode != 0)
if (end > unicode)
{ {
Event textEvent; Event textEvent;
textEvent.Type = Event::TextEntered; textEvent.Type = Event::TextEntered;
textEvent.Text.Unicode = unicode[0]; textEvent.Text.Unicode = unicode;
SendEvent(textEvent); SendEvent(textEvent);
} }
} }