mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Pulled some Font module code out of the freetype implementation files, since it's not freetype-specific.
--HG-- branch : minor
This commit is contained in:
@@ -226,6 +226,7 @@ source_group("modules\\filesystem\\physfs" FILES ${LOVE_SRC_MODULE_FILESYSTEM_PH
|
||||
set(LOVE_SRC_MODULE_FONT_ROOT
|
||||
src/modules/font/BMFontRasterizer.cpp
|
||||
src/modules/font/BMFontRasterizer.h
|
||||
src/modules/font/Font.cpp
|
||||
src/modules/font/Font.h
|
||||
src/modules/font/GlyphData.cpp
|
||||
src/modules/font/GlyphData.h
|
||||
|
||||
@@ -321,6 +321,7 @@
|
||||
FAC86E6C1724555D00EED715 /* Quad.h in Headers */ = {isa = PBXBuildFile; fileRef = FAC86E681724555D00EED715 /* Quad.h */; };
|
||||
FAD400A6196C5EBC004208B9 /* Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAD400A5196C5EBC004208B9 /* Text.cpp */; };
|
||||
FAD5970C196E174000E8EA36 /* wrap_Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAD5970B196E174000E8EA36 /* wrap_Text.cpp */; };
|
||||
FAD661A21A91BA1800B64301 /* Font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAD661A11A91BA1800B64301 /* Font.cpp */; };
|
||||
FAD8E84F1A7C949B0084E24D /* Vera.ttf.h in Headers */ = {isa = PBXBuildFile; fileRef = FAD8E84E1A7C949B0084E24D /* Vera.ttf.h */; };
|
||||
FADD58DD18C30367005FC3BF /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADD58DC18C30367005FC3BF /* FormatHandler.cpp */; };
|
||||
FADDCDAD1A91817800B32118 /* CoreAudioDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADDCDAB1A91817800B32118 /* CoreAudioDecoder.cpp */; };
|
||||
@@ -917,6 +918,7 @@
|
||||
FAD400A7196C5ECC004208B9 /* Text.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Text.h; sourceTree = "<group>"; };
|
||||
FAD5970B196E174000E8EA36 /* wrap_Text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Text.cpp; sourceTree = "<group>"; };
|
||||
FAD5970D196E17C100E8EA36 /* wrap_Text.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrap_Text.h; sourceTree = "<group>"; };
|
||||
FAD661A11A91BA1800B64301 /* Font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Font.cpp; sourceTree = "<group>"; };
|
||||
FAD8E84E1A7C949B0084E24D /* Vera.ttf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Vera.ttf.h; sourceTree = "<group>"; };
|
||||
FADD58DC18C30367005FC3BF /* FormatHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatHandler.cpp; sourceTree = "<group>"; };
|
||||
FADDCDAB1A91817800B32118 /* CoreAudioDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreAudioDecoder.cpp; sourceTree = "<group>"; };
|
||||
@@ -1226,6 +1228,7 @@
|
||||
children = (
|
||||
FA9556C919D3741A00F29A4C /* BMFontRasterizer.cpp */,
|
||||
FA9556CA19D3741A00F29A4C /* BMFontRasterizer.h */,
|
||||
FAD661A11A91BA1800B64301 /* Font.cpp */,
|
||||
2E9B5D9926034F9172215D5E /* Font.h */,
|
||||
12BB56F127170B3709670896 /* freetype */,
|
||||
74003CB27FA762A021183AD5 /* GlyphData.cpp */,
|
||||
@@ -2506,6 +2509,7 @@
|
||||
FA5FDC8A1788D548002F0ED2 /* peer.c in Sources */,
|
||||
FA5FDC8B1788D548002F0ED2 /* protocol.c in Sources */,
|
||||
FA5FDC8D1788D548002F0ED2 /* unix.c in Sources */,
|
||||
FAD661A21A91BA1800B64301 /* Font.cpp in Sources */,
|
||||
FA5FDC8E1788D548002F0ED2 /* win32.c in Sources */,
|
||||
FA34E7CD174B513F00E04D3F /* System.cpp in Sources */,
|
||||
FA34E7D2174B515D00E04D3F /* System.cpp in Sources */,
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "Font.h"
|
||||
#include "BMFontRasterizer.h"
|
||||
#include "ImageRasterizer.h"
|
||||
|
||||
#include "libraries/utf8/utf8.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
|
||||
Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images)
|
||||
{
|
||||
return new BMFontRasterizer(fontdef, images);
|
||||
}
|
||||
|
||||
Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text)
|
||||
{
|
||||
std::vector<uint32> glyphs;
|
||||
glyphs.reserve(text.size());
|
||||
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
|
||||
utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
|
||||
|
||||
while (i != end)
|
||||
glyphs.push_back(*i++);
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return newImageRasterizer(data, &glyphs[0], glyphs.size());
|
||||
}
|
||||
|
||||
Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs)
|
||||
{
|
||||
return new ImageRasterizer(data, glyphs, numglyphs);
|
||||
}
|
||||
|
||||
GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text)
|
||||
{
|
||||
uint32 codepoint = 0;
|
||||
|
||||
try
|
||||
{
|
||||
codepoint = utf8::peek_next(text.begin(), text.end());
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return r->getGlyphData(codepoint);
|
||||
}
|
||||
|
||||
GlyphData *Font::newGlyphData(Rasterizer *r, uint32 glyph)
|
||||
{
|
||||
return r->getGlyphData(glyph);
|
||||
}
|
||||
|
||||
} // font
|
||||
} // love
|
||||
@@ -49,13 +49,13 @@ public:
|
||||
virtual Rasterizer *newTrueTypeRasterizer(int size) = 0;
|
||||
virtual Rasterizer *newTrueTypeRasterizer(love::filesystem::FileData *data, int size) = 0;
|
||||
|
||||
virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images) = 0;
|
||||
virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images);
|
||||
|
||||
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs) = 0;
|
||||
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length) = 0;
|
||||
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &glyphs);
|
||||
virtual Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int length);
|
||||
|
||||
virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph) = 0;
|
||||
virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph) = 0;
|
||||
virtual GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph);
|
||||
virtual GlyphData *newGlyphData(Rasterizer *r, uint32 glyph);
|
||||
|
||||
// Implement Module.
|
||||
virtual ModuleType getModuleType() const { return M_FONT; }
|
||||
|
||||
@@ -21,11 +21,8 @@
|
||||
#include "Font.h"
|
||||
|
||||
#include "TrueTypeRasterizer.h"
|
||||
#include "font/ImageRasterizer.h"
|
||||
#include "font/BMFontRasterizer.h"
|
||||
|
||||
#include "libraries/utf8/utf8.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace love
|
||||
@@ -54,7 +51,7 @@ Rasterizer *Font::newRasterizer(love::filesystem::FileData *data)
|
||||
if (TrueTypeRasterizer::accepts(library, data))
|
||||
return newTrueTypeRasterizer(data, 12);
|
||||
else if (BMFontRasterizer::accepts(data))
|
||||
return newBMFontRasterizer(data, std::vector<image::ImageData *>());
|
||||
return newBMFontRasterizer(data, {});
|
||||
|
||||
throw love::Exception("Invalid font file: %s", data->getFilename().c_str());
|
||||
}
|
||||
@@ -74,58 +71,6 @@ Rasterizer *Font::newTrueTypeRasterizer(love::filesystem::FileData *data, int si
|
||||
return new TrueTypeRasterizer(library, data, size);
|
||||
}
|
||||
|
||||
Rasterizer *Font::newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images)
|
||||
{
|
||||
return new BMFontRasterizer(fontdef, images);
|
||||
}
|
||||
|
||||
Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, const std::string &text)
|
||||
{
|
||||
std::vector<uint32> glyphs;
|
||||
glyphs.reserve(text.size());
|
||||
|
||||
try
|
||||
{
|
||||
utf8::iterator<std::string::const_iterator> i(text.begin(), text.begin(), text.end());
|
||||
utf8::iterator<std::string::const_iterator> end(text.end(), text.begin(), text.end());
|
||||
|
||||
while (i != end)
|
||||
glyphs.push_back(*i++);
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return newImageRasterizer(data, &glyphs[0], glyphs.size());
|
||||
}
|
||||
|
||||
Rasterizer *Font::newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs)
|
||||
{
|
||||
return new ImageRasterizer(data, glyphs, numglyphs);
|
||||
}
|
||||
|
||||
GlyphData *Font::newGlyphData(Rasterizer *r, const std::string &text)
|
||||
{
|
||||
uint32 codepoint = 0;
|
||||
|
||||
try
|
||||
{
|
||||
codepoint = utf8::peek_next(text.begin(), text.end());
|
||||
}
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
return r->getGlyphData(codepoint);
|
||||
}
|
||||
|
||||
GlyphData *Font::newGlyphData(Rasterizer *r, uint32 glyph)
|
||||
{
|
||||
return r->getGlyphData(glyph);
|
||||
}
|
||||
|
||||
const char *Font::getName() const
|
||||
{
|
||||
return "love.font.freetype";
|
||||
|
||||
@@ -49,14 +49,6 @@ public:
|
||||
Rasterizer *newTrueTypeRasterizer(int size);
|
||||
Rasterizer *newTrueTypeRasterizer(love::filesystem::FileData *data, int size);
|
||||
|
||||
Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images);
|
||||
|
||||
Rasterizer *newImageRasterizer(love::image::ImageData *data, const std::string &text);
|
||||
Rasterizer *newImageRasterizer(love::image::ImageData *data, uint32 *glyphs, int numglyphs);
|
||||
|
||||
GlyphData *newGlyphData(Rasterizer *r, const std::string &glyph);
|
||||
GlyphData *newGlyphData(Rasterizer *r, uint32 glyph);
|
||||
|
||||
// Implement Module
|
||||
const char *getName() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user