Skip to content

Commit

Permalink
Merge pull request libRocket#267 from konopka90/master
Browse files Browse the repository at this point in the history
New font provider - loading bitmap fonts
  • Loading branch information
wheybags committed Sep 15, 2015
2 parents bde96a2 + caf6eef commit cbbbed7
Show file tree
Hide file tree
Showing 41 changed files with 3,709 additions and 534 deletions.
2 changes: 1 addition & 1 deletion Build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ endmacro()
if(BUILD_SAMPLES)
include(SampleFileList)

set(samples treeview customlog drag loaddocument)
set(samples treeview customlog drag loaddocument bitmapfont)
set(tutorials template datagrid datagrid_tree tutorial_drag)

if(NOT BUILD_FRAMEWORK)
Expand Down
27 changes: 25 additions & 2 deletions Build/cmake/FileList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ set(Core_HDR_FILES
${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutlineInstancer.h
${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadowInstancer.h
${PROJECT_SOURCE_DIR}/Source/Core/FontFace.h
${PROJECT_SOURCE_DIR}/Source/Core/FontFaceHandle.h
${PROJECT_SOURCE_DIR}/Source/Core/FontFaceLayer.h
${PROJECT_SOURCE_DIR}/Source/Core/FontFamily.h
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFace.h
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFaceHandle.h
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFamily.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/BitmapFontDefinitions.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontParser.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFace.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFaceHandle.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFaceLayer.h
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFamily.h
${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.h
${PROJECT_SOURCE_DIR}/Source/Core/LayoutBlockBox.h
${PROJECT_SOURCE_DIR}/Source/Core/LayoutBlockBoxSpace.h
Expand Down Expand Up @@ -128,7 +135,12 @@ set(Core_PUB_HDR_FILES
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontDatabase.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffect.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontEffectInstancer.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontFace.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontFamily.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontGlyph.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FontProvider.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/FreeType/FontProvider.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/BitmapFont/FontProvider.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Geometry.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/GeometryUtilities.h
${PROJECT_SOURCE_DIR}/Include/Rocket/Core/Header.h
Expand Down Expand Up @@ -233,6 +245,17 @@ set(Core_SRC_FILES
${PROJECT_SOURCE_DIR}/Source/Core/FontFaceHandle.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FontFaceLayer.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FontFamily.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FontProvider.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFace.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFaceHandle.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontFamily.cpp
${PROJECT_SOURCE_DIR}/Source/Core/FreeType/FontProvider.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontParser.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFace.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFaceHandle.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFaceLayer.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontFamily.cpp
${PROJECT_SOURCE_DIR}/Source/Core/BitmapFont/FontProvider.cpp
${PROJECT_SOURCE_DIR}/Source/Core/Geometry.cpp
${PROJECT_SOURCE_DIR}/Source/Core/GeometryDatabase.cpp
${PROJECT_SOURCE_DIR}/Source/Core/GeometryUtilities.cpp
Expand Down
7 changes: 7 additions & 0 deletions Build/cmake/SampleFileList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ set(loaddocument_SRC_FILES
${PROJECT_SOURCE_DIR}/Samples/basic/loaddocument/src/main.cpp
)

set(bitmapfont_HDR_FILES
)

set(bitmapfont_SRC_FILES
${PROJECT_SOURCE_DIR}/Samples/basic/bitmapfont/src/main.cpp
)

set(ogre3d_HDR_FILES
${PROJECT_SOURCE_DIR}/Samples/basic/ogre3d/src/RenderInterfaceOgre3D.h
${PROJECT_SOURCE_DIR}/Samples/basic/ogre3d/src/RocketApplication.h
Expand Down
101 changes: 101 additions & 0 deletions Include/Rocket/Core/BitmapFont/FontProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* This source file is part of libRocket, the HTML/CSS Interface Middleware
*
* For the latest information, see http://www.librocket.com
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef ROCKETCOREBITMAPFONTFONTPROVIDER_H
#define ROCKETCOREBITMAPFONTFONTPROVIDER_H

#include "../StringUtilities.h"
#include "../Font.h"
#include "../FontProvider.h"

namespace Rocket {
namespace Core {


class FontEffect;
class FontFaceHandle;
class PropertyDictionary;

namespace BitmapFont {

class FontFamily;

/**
The font database contains all font families currently in use by Rocket.
@author Peter Curry
*/

class ROCKETCORE_API FontProvider : public Rocket::Core::FontProvider
{
public:
static bool Initialise();
static void Shutdown();

/// Adds a new font face to the database. The face's family, style and weight will be determined from the face itself.
/// @param[in] file_name The file to load the face from.
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const String& file_name);
/// Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
/// @param[in] file_name The file to load the face from.
/// @param[in] family The family to add the face to.
/// @param[in] style The style of the face (normal or italic).
/// @param[in] weight The weight of the face (normal or bold).
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const String& file_name, const String& family, Font::Style style, Font::Weight weight);
/// Adds a new font face to the database, loading from memory. The face's family, style and weight will be determined from the face itself.
/// @param[in] data The font data.
/// @param[in] data_length Length of the data.
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const byte* data, int data_length);
/// Adds a new font face to the database, loading from memory.
/// @param[in] data The font data.
/// @param[in] data_length Length of the data.
/// @param[in] family The family to add the face to.
/// @param[in] style The style of the face (normal or italic).
/// @param[in] weight The weight of the face (normal or bold).
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);

private:
FontProvider(void);
~FontProvider(void);

// Adds a loaded face to the appropriate font family.
bool AddFace(void* face, const String& family, Font::Style style, Font::Weight weight, bool release_stream);
// Loads a FreeType face.
void* LoadFace(const String& file_name);
// Loads a FreeType face from memory.
void* LoadFace(const byte* data, int data_length, const String& source, bool local_data);

static FontProvider* instance;
};

}
}
}

#endif
27 changes: 17 additions & 10 deletions Include/Rocket/Core/FontDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "StringUtilities.h"
#include "Header.h"
#include "Font.h"
#include "FontProvider.h"

namespace Rocket {
namespace Core {
Expand All @@ -49,6 +50,13 @@ class PropertyDictionary;
class ROCKETCORE_API FontDatabase
{
public:

enum FontProviderType
{
FreeType = 0,
BitmapFont
};

static bool Initialise();
static void Shutdown();

Expand All @@ -67,15 +75,15 @@ class ROCKETCORE_API FontDatabase
/// @param[in] data The font data.
/// @param[in] data_length Length of the data.
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const byte* data, int data_length);
static bool LoadFontFace(FontProviderType font_provider_type, const byte* data, int data_length);
/// Adds a new font face to the database, loading from memory.
/// @param[in] data The font data.
/// @param[in] data_length Length of the data.
/// @param[in] family The family to add the face to.
/// @param[in] style The style of the face (normal or italic).
/// @param[in] weight The weight of the face (normal or bold).
/// @return True if the face was loaded successfully, false otherwise.
static bool LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);
static bool LoadFontFace(FontProviderType font_provider_type, const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);

/// Returns a handle to a font face that can be used to position and render text. This will return the closest match
/// it can find, but in the event a font family is requested that does not exist, NULL will be returned instead of a
Expand All @@ -99,20 +107,19 @@ class ROCKETCORE_API FontDatabase
/// @param[in] The effect to release.
static void ReleaseFontEffect(const FontEffect* effect);

static void AddFontProvider(FontProvider * provider);

static void RemoveFontProvider(FontProvider * provider);

private:
FontDatabase(void);
~FontDatabase(void);

// Adds a loaded face to the appropriate font family.
bool AddFace(void* face, const String& family, Font::Style style, Font::Weight weight, bool release_stream);
// Loads a FreeType face.
void* LoadFace(const String& file_name);
// Loads a FreeType face from memory.
void* LoadFace(const byte* data, int data_length, const String& source, bool local_data);
static FontProviderType GetFontProviderType(const String& file_name);

typedef std::map< String, FontFamily*, StringUtilities::StringComparei > FontFamilyMap;
FontFamilyMap font_families;
typedef std::vector< FontProvider *> FontProviderTable;

static FontProviderTable font_provider_table;
static FontDatabase* instance;
};

Expand Down
15 changes: 6 additions & 9 deletions Source/Core/FontFace.h → Include/Rocket/Core/FontFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#ifndef ROCKETCOREFONTFACE_H
#define ROCKETCOREFONTFACE_H

#include "../../Include/Rocket/Core/Font.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include "Font.h"

namespace Rocket {
namespace Core {
Expand All @@ -44,8 +42,8 @@ class FontFaceHandle;
class FontFace
{
public:
FontFace(FT_Face face, Font::Style style, Font::Weight weight, bool release_stream);
~FontFace();
FontFace(Font::Style style, Font::Weight weight, bool release_stream);
virtual ~FontFace();

/// Returns the style of the font face.
/// @return The font face's style.
Expand All @@ -58,14 +56,13 @@ class FontFace
/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
/// @param[in] size The size of the desired handle, in points.
/// @return The shared font handle.
FontFaceHandle* GetHandle(const String& charset, int size);
virtual FontFaceHandle* GetHandle(const String& charset, int size) = 0;

/// Releases the face's FreeType face structure. This will mean handles for new sizes cannot be constructed,
/// but existing ones can still be fetched.
void ReleaseFace();
virtual void ReleaseFace() = 0;

private:
FT_Face face;
protected:
Font::Style style;
Font::Weight weight;

Expand Down
13 changes: 6 additions & 7 deletions Source/Core/FontFamily.h → Include/Rocket/Core/FontFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
#ifndef ROCKETCOREFONTFAMILY_H
#define ROCKETCOREFONTFAMILY_H

#include "../../Include/Rocket/Core/Font.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include <Rocket/Core/StringUtilities.h>
#include "Font.h"

namespace Rocket {
namespace Core {
Expand All @@ -46,25 +45,25 @@ class FontFamily
{
public:
FontFamily(const String& name);
~FontFamily();
virtual ~FontFamily();

/// Adds a new face to the family.
/// @param[in] ft_face The previously loaded FreeType face.
/// @param[in] style The style of the new face.
/// @param[in] weight The weight of the new face.
/// @param[in] release_stream True if the application must free the face's memory stream.
/// @return True if the face was loaded successfully, false otherwise.
bool AddFace(FT_Face ft_face, Font::Style style, Font::Weight weight, bool release_stream);
virtual bool AddFace(void* ft_face, Font::Style style, Font::Weight weight, bool release_stream) = 0;

/// Returns a handle to the most appropriate font in the family, at the correct size.
/// @param[in] charset The set of characters in the handle, as a comma-separated list of unicode ranges.
/// @param[in] style The style of the desired handle.
/// @param[in] weight The weight of the desired handle.
/// @param[in] size The size of desired handle, in points.
/// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
FontFaceHandle* GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size);
FontFaceHandle* GetFaceHandle(const String& charset, Font::Style style, Font::Weight weight, int size);

private:
protected:
String name;

typedef std::vector< FontFace* > FontFaceList;
Expand Down
70 changes: 70 additions & 0 deletions Include/Rocket/Core/FontProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This source file is part of libRocket, the HTML/CSS Interface Middleware
*
* For the latest information, see http://www.librocket.com
*
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#ifndef ROCKETCOREFONTPROVIDER_H
#define ROCKETCOREFONTPROVIDER_H

#include <Rocket/Core/StringUtilities.h>
#include <Rocket/Core/Font.h>
#include <Rocket/Core/Header.h>

namespace Rocket {
namespace Core {

class FontFaceHandle;
class FontFamily;

/**
The font database contains all font families currently in use by Rocket.
@author Peter Curry
*/

class ROCKETCORE_API FontProvider
{
public:

/// Returns a handle to a font face that can be used to position and render text. This will return the closest match
/// it can find, but in the event a font family is requested that does not exist, NULL will be returned instead of a
/// valid handle.
/// @param[in] family The family of the desired font handle.
/// @param[in] charset The set of characters required in the font face, as a comma-separated list of unicode ranges.
/// @param[in] style The style of the desired font handle.
/// @param[in] weight The weight of the desired font handle.
/// @param[in] size The size of desired handle, in points.
/// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size);

protected:

typedef std::map< String, FontFamily*, StringUtilities::StringComparei > FontFamilyMap;
FontFamilyMap font_families;
};

}
}

#endif
Loading

0 comments on commit cbbbed7

Please sign in to comment.