Skip to content

Commit

Permalink
On master: basic, first implementation of BitmapFont
Browse files Browse the repository at this point in the history
  • Loading branch information
TheThibz authored and crazyjul committed Jan 9, 2012
1 parent 43bd69d commit c277258
Show file tree
Hide file tree
Showing 25 changed files with 2,257 additions and 25 deletions.
34 changes: 33 additions & 1 deletion Build/Rocket.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketDebugger", "RocketDebugger.vcproj", "{1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41A}"
ProjectSection(ProjectDependencies) = postProject
{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
{6B82ACD3-521B-45F9-89B3-BD728A3CE500} = {6B82ACD3-521B-45F9-89B3-BD728A3CE500}
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5} = {5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketFreeType", "RocketFreeType.vcproj", "{6B82ACD3-521B-45F9-89B3-BD728A3CE500}"
ProjectSection(ProjectDependencies) = postProject
{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RocketBitmapFont", "RocketBitmapFont.vcproj", "{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}"
ProjectSection(ProjectDependencies) = postProject
{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shell", "..\Samples\shell\Shell.vcproj", "{AF4FF882-AFD9-457B-979E-A5B482388D46}"
ProjectSection(ProjectDependencies) = postProject
{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
{1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41A} = {1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41A}
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5} = {5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectX", "..\Samples\basic\directx\DirectX.vcproj", "{3C58D3B5-9478-4221-954A-01E3C4F1FA89}"
ProjectSection(ProjectDependencies) = postProject
{1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B} = {1AAC0B29-AEB9-4E3F-8EDF-B46F8949C41B}
{1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41A} = {1AAC0B29-AEC9-4E3F-9EDF-B56F8949C41A}
{AF4FF882-AFD9-457B-979E-A5B482388D46} = {AF4FF882-AFD9-457B-979E-A5B482388D46}
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5} = {5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand All @@ -41,6 +61,18 @@ Global
{6B82ACD3-521B-45F9-89B3-BD728A3CE500}.Debug|Win32.Build.0 = Debug|Win32
{6B82ACD3-521B-45F9-89B3-BD728A3CE500}.Release|Win32.ActiveCfg = Release|Win32
{6B82ACD3-521B-45F9-89B3-BD728A3CE500}.Release|Win32.Build.0 = Release|Win32
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}.Debug|Win32.ActiveCfg = Debug|Win32
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}.Debug|Win32.Build.0 = Debug|Win32
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}.Release|Win32.ActiveCfg = Release|Win32
{5BEC81C2-EC50-46B8-83D7-68730F4B9CE5}.Release|Win32.Build.0 = Release|Win32
{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.ActiveCfg = Debug|Win32
{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.Build.0 = Debug|Win32
{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.ActiveCfg = Release|Win32
{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.Build.0 = Release|Win32
{3C58D3B5-9478-4221-954A-01E3C4F1FA89}.Debug|Win32.ActiveCfg = Debug|Win32
{3C58D3B5-9478-4221-954A-01E3C4F1FA89}.Debug|Win32.Build.0 = Debug|Win32
{3C58D3B5-9478-4221-954A-01E3C4F1FA89}.Release|Win32.ActiveCfg = Release|Win32
{3C58D3B5-9478-4221-954A-01E3C4F1FA89}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Build/RocketDebugger.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="RocketCore_d.lib RocketFreeType_d.lib"
AdditionalDependencies="RocketCore_d.lib RocketBitmapFont_d.lib"
OutputFile="..\bin\$(ProjectName)_d.dll"
AdditionalLibraryDirectories="..\bin"
RandomizedBaseAddress="1"
Expand Down
2 changes: 1 addition & 1 deletion Build/RocketFreeType.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\Include;..\..\support\freetype\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;ROCKETFREETYPE_EXPORTS"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;RocketFreeType_EXPORTS;ROCKETFREETYPE_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
Expand Down
112 changes: 112 additions & 0 deletions Include/Rocket/Core/BitmapFont/FontProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 <Rocket/Core/StringUtilities.h>
#include <Rocket/Core/BitmapFont/Header.h>
#include <Rocket/Core/Font.h>
#include <Rocket/Core/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 ROCKETCOREBITMAPFONT_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.
/// @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);

/// 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.
virtual FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size);

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

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

static FontProvider* instance;
};

}
}
}

#endif
47 changes: 47 additions & 0 deletions Include/Rocket/Core/BitmapFont/Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 ROCKETCOREBITMAPFONTHEADER_H
#define ROCKETCOREBITMAPFONTHEADER_H

#include <Rocket/Core/Platform.h>

#if !defined STATIC_LIB
#if defined ROCKET_PLATFORM_WIN32
#if defined RocketBitmapFont_EXPORTS
#define ROCKETCOREBITMAPFONT_API __declspec(dllexport)
#else
#define ROCKETCOREBITMAPFONT_API __declspec(dllimport)
#endif
#else
#define ROCKETCOREBITMAPFONT_API __attribute__((visibility("default")))
#endif
#else
#define ROCKETCOREBITMAPFONT_API
#endif

#endif
22 changes: 21 additions & 1 deletion Include/Rocket/Core/FontFaceHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ class ROCKETCORE_API FontFaceHandle : public ReferenceCountable
/// @return The font face's charset.
const UnicodeRangeList& GetCharset() const;


const String & GetTextureBaseName() const
{
return TextureBaseName;
}

const String & GetTextureDirectory() const
{
return TextureDirectory;
}

int GetTextureSize() const
{
return TextureSize;
}

protected:
/// Destroys the handle.
virtual void OnReferenceDeactivate();
Expand All @@ -127,7 +143,7 @@ class ROCKETCORE_API FontFaceHandle : public ReferenceCountable
int GetKerning(word lhs, word rhs) const;

// Generates (or shares) a layer derived from a font effect.
FontFaceLayer* GenerateLayer(FontEffect* font_effect);
virtual FontFaceLayer* GenerateLayer(FontEffect* font_effect);

typedef std::map< const FontEffect*, FontFaceLayer* > FontLayerMap;
typedef std::map< String, FontFaceLayer* > FontLayerCache;
Expand Down Expand Up @@ -158,6 +174,10 @@ class ROCKETCORE_API FontFaceHandle : public ReferenceCountable

String raw_charset;
UnicodeRangeList charset;

String TextureBaseName;
String TextureDirectory;
int TextureSize;
};

}
Expand Down
12 changes: 10 additions & 2 deletions Include/Rocket/Core/FontProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
#define ROCKETCOREFONTPROVIDER_H

#include <Rocket/Core/StringUtilities.h>
#include <Rocket/Core/FreeType/Header.h>
#ifdef ROCKETCOREFREETYPE_API
#include <Rocket/Core/FreeType/Header.h>
#else
#include <Rocket/Core/BitmapFont/Header.h>
#endif
#include <Rocket/Core/Font.h>

namespace Rocket {
Expand All @@ -41,7 +45,11 @@ namespace Core {
@author Peter Curry
*/

class ROCKETCOREFREETYPE_API FontProvider
#ifdef ROCKETCOREFREETYPE_API
class ROCKETCOREFREETYPE_API FontProvider
#else
class ROCKETCOREBITMAPFONT_API FontProvider
#endif
{
public:

Expand Down
4 changes: 2 additions & 2 deletions Samples/basic/directx/DirectX.vcproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="DirectX"
ProjectGUID="{3C58D3B5-9478-4221-954A-01E3C4F1FA89}"
TargetFrameworkVersion="131072"
Expand Down Expand Up @@ -55,7 +55,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="RocketCore_d.lib RocketDebugger_d.lib opengl32.lib d3d9.lib d3dx9.lib"
AdditionalDependencies="RocketCore_d.lib RocketDebugger_d.lib RocketBitmapFont_d.lib opengl32.lib d3d9.lib d3dx9.lib"
OutputFile="..\..\..\bin\$(ProjectName)_d.exe"
AdditionalLibraryDirectories="..\..\..\bin"
GenerateDebugInformation="true"
Expand Down
4 changes: 3 additions & 1 deletion Samples/basic/directx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <Rocket/Core.h>
#include <Rocket/Debugger.h>
#include <Rocket/Core/BitmapFont/FontProvider.h>
#include <Input.h>
#include <Shell.h>
#include "RenderInterfaceDirectX.h"
Expand Down Expand Up @@ -155,6 +156,7 @@ int main(int ROCKET_UNUSED(argc), char** ROCKET_UNUSED(argv))
Rocket::Core::SetSystemInterface(&system_interface);

Rocket::Core::Initialise();
Rocket::Core::BitmapFont::FontProvider::Initialise();

// Create the main Rocket context and set it on the shell's input layer.
context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
Expand All @@ -168,7 +170,7 @@ int main(int ROCKET_UNUSED(argc), char** ROCKET_UNUSED(argv))
Rocket::Debugger::Initialise(context);
Input::SetContext(context);

Shell::LoadFonts("../../assets/");
Shell::LoadFonts("../../assets/BitmapFont/");

// Load and show the tutorial document.
Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml");
Expand Down
13 changes: 6 additions & 7 deletions Samples/shell/src/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@
*/

#include "Shell.h"
#include <Rocket/Core/FontDatabase.h>

#include <Rocket/Core/Core.h>
#include <Rocket/Core/BitmapFont/FontProvider.h>

Rocket::Core::String Shell::executable_path;

/// Loads the default fonts from the given path.
void Shell::LoadFonts(const char* directory)
{
Rocket::Core::String font_names[4];
font_names[0] = "Delicious-Roman.otf";
font_names[1] = "Delicious-Italic.otf";
font_names[2] = "Delicious-Bold.otf";
font_names[3] = "Delicious-BoldItalic.otf";
Rocket::Core::String font_names[1];
font_names[0] = "arial_latin.fnt";

for (int i = 0; i < sizeof(font_names) / sizeof(Rocket::Core::String); i++)
{
Rocket::Core::FontDatabase::LoadFontFace(Rocket::Core::String(directory) + font_names[i]);
Rocket::Core::BitmapFont::FontProvider::LoadFontFace(Rocket::Core::String(directory) + font_names[i]);
}
}

Expand Down
Loading

0 comments on commit c277258

Please sign in to comment.