mirror of https://github.com/mosra/magnum.git
Browse Source
In next few commits AbstractFont will become plugin interface. Font implementations are now in magnum-plugins repository. Removed all traces of FreeType and HarfBuzz dependencies.pull/278/head
14 changed files with 3 additions and 634 deletions
@ -1,57 +0,0 @@
|
||||
# - Find HarfBuzz |
||||
# |
||||
# This module tries to find HarfBuzz library and then defines: |
||||
# HARFBUZZ_FOUND - True if HarfBuzz library is found |
||||
# HARFBUZZ_INCLUDE_DIRS - Include dirs |
||||
# HARFBUZZ_LIBRARIES - HarfBuzz libraries |
||||
# |
||||
# Additionally these variables are defined for internal usage: |
||||
# HARFBUZZ_INCLUDE_DIR - Include dir (w/o dependencies) |
||||
# HARFBUZZ_LIBRARY - HarfBuzz library (w/o dependencies) |
||||
# |
||||
|
||||
# |
||||
# This file is part of Magnum. |
||||
# |
||||
# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
# |
||||
# 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. |
||||
# |
||||
|
||||
# Library |
||||
find_library(HARFBUZZ_LIBRARY NAMES harfbuzz) |
||||
|
||||
# Include dir |
||||
find_path(HARFBUZZ_INCLUDE_DIR |
||||
NAMES hb.h |
||||
PATH_SUFFIXES harfbuzz |
||||
) |
||||
|
||||
include(FindPackageHandleStandardArgs) |
||||
find_package_handle_standard_args("HarfBuzz" DEFAULT_MSG |
||||
HARFBUZZ_LIBRARY |
||||
HARFBUZZ_INCLUDE_DIR |
||||
) |
||||
|
||||
set(HARFBUZZ_INCLUDE_DIRS ${HARFBUZZ_INCLUDE_DIR}) |
||||
set(HARFBUZZ_LIBRARIES ${HARFBUZZ_LIBRARY}) |
||||
|
||||
mark_as_advanced(FORCE |
||||
HARFBUZZ_LIBRARY |
||||
HARFBUZZ_INCLUDE_DIR) |
||||
@ -1,180 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
#include "FreeTypeFont.h" |
||||
#include "GlyphCache.h" |
||||
|
||||
#include <algorithm> |
||||
#include <ft2build.h> |
||||
#include FT_FREETYPE_H |
||||
#include <Utility/Unicode.h> |
||||
|
||||
#include "Extensions.h" |
||||
#include "Image.h" |
||||
#include "TextureTools/Atlas.h" |
||||
#include "TextureTools/DistanceField.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
|
||||
class FreeTypeLayouter: public AbstractLayouter { |
||||
public: |
||||
explicit FreeTypeLayouter(FT_Face ftFont, const GlyphCache* const cache, const Float fontSize, const Float textSize, const std::string& text); |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; |
||||
|
||||
private: |
||||
FT_Face font; |
||||
const GlyphCache* const cache; |
||||
const Float fontSize, textSize; |
||||
std::vector<FT_UInt> glyphs; |
||||
}; |
||||
|
||||
} |
||||
|
||||
FreeTypeFontRenderer::FreeTypeFontRenderer() { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Init_FreeType(&_library) == 0); |
||||
} |
||||
|
||||
FreeTypeFontRenderer::~FreeTypeFontRenderer() { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Done_FreeType(_library) == 0); |
||||
} |
||||
|
||||
FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): AbstractFont(size) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Face(renderer.library(), fontFile.c_str(), 0, &ftFont) == 0); |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(ftFont, 0, size*64, 100, 100) == 0); |
||||
} |
||||
|
||||
FreeTypeFont::FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): AbstractFont(size) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_New_Memory_Face(renderer.library(), data, dataSize, 0, &ftFont) == 0); |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Set_Char_Size(ftFont, 0, size*64, 100, 100) == 0); |
||||
} |
||||
|
||||
void FreeTypeFont::createGlyphCache(GlyphCache* const cache, const std::string& characters) { |
||||
/** @bug Crash when atlas is too small */ |
||||
|
||||
/* Get glyph codes from characters */ |
||||
std::vector<FT_UInt> charIndices; |
||||
charIndices.reserve(characters.size()+1); |
||||
charIndices.push_back(0); |
||||
for(std::size_t i = 0; i != characters.size(); ) { |
||||
UnsignedInt codepoint; |
||||
std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(characters, i); |
||||
charIndices.push_back(FT_Get_Char_Index(ftFont, codepoint)); |
||||
} |
||||
|
||||
/* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */ |
||||
std::sort(charIndices.begin(), charIndices.end()); |
||||
charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end()); |
||||
|
||||
/* Sizes of all characters */ |
||||
std::vector<Vector2i> charSizes; |
||||
charSizes.reserve(charIndices.size()); |
||||
for(FT_UInt c: charIndices) { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, c, FT_LOAD_DEFAULT) == 0); |
||||
charSizes.push_back(Vector2i(ftFont->glyph->metrics.width, ftFont->glyph->metrics.height)/64); |
||||
} |
||||
|
||||
/* Create texture atlas */ |
||||
const std::vector<Rectanglei> charPositions = cache->reserve(charSizes); |
||||
|
||||
/* Render all characters to the atlas and create character map */ |
||||
unsigned char* pixmap = new unsigned char[cache->textureSize().product()](); |
||||
Image2D image(cache->textureSize(), Image2D::Format::Red, Image2D::Type::UnsignedByte, pixmap); |
||||
for(std::size_t i = 0; i != charPositions.size(); ++i) { |
||||
/* Load and render glyph */ |
||||
/** @todo B&W only if radius != 0 */ |
||||
FT_GlyphSlot glyph = ftFont->glyph; |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0); |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0); |
||||
|
||||
/* Copy rendered bitmap to texture image */ |
||||
const FT_Bitmap& bitmap = glyph->bitmap; |
||||
CORRADE_INTERNAL_ASSERT(std::abs(bitmap.width-charPositions[i].width()) <= 2); |
||||
CORRADE_INTERNAL_ASSERT(std::abs(bitmap.rows-charPositions[i].height()) <= 2); |
||||
for(Int yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout) |
||||
for(Int xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout) |
||||
pixmap[yout*cache->textureSize().x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin]; |
||||
|
||||
/* Insert glyph parameters into cache */ |
||||
cache->insert(charIndices[i], |
||||
Vector2i(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height()), |
||||
charPositions[i]); |
||||
} |
||||
|
||||
/* Set cache image */ |
||||
cache->setImage({}, &image); |
||||
} |
||||
|
||||
FreeTypeFont::~FreeTypeFont() { |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Done_Face(ftFont) == 0); |
||||
} |
||||
|
||||
AbstractLayouter* FreeTypeFont::layout(const GlyphCache* const cache, const Float size, const std::string& text) { |
||||
return new FreeTypeLayouter(ftFont, cache, this->size(), size, text); |
||||
} |
||||
|
||||
namespace { |
||||
|
||||
FreeTypeLayouter::FreeTypeLayouter(FT_Face font, const GlyphCache* const cache, const Float fontSize, const Float textSize, const std::string& text): font(font), cache(cache), fontSize(fontSize), textSize(textSize) { |
||||
/* Get glyph codes from characters */ |
||||
glyphs.reserve(text.size()); |
||||
for(std::size_t i = 0; i != text.size(); ) { |
||||
UnsignedInt codepoint; |
||||
std::tie(codepoint, i) = Corrade::Utility::Unicode::nextChar(text, i); |
||||
glyphs.push_back(FT_Get_Char_Index(font, codepoint)); |
||||
} |
||||
_glyphCount = glyphs.size(); |
||||
} |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> FreeTypeLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { |
||||
/* Position of the texture in the resulting glyph, texture coordinates */ |
||||
Vector2i position; |
||||
Rectanglei rectangle; |
||||
std::tie(position, rectangle) = (*cache)[glyphs[i]]; |
||||
|
||||
Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize, |
||||
Vector2(rectangle.size())/fontSize); |
||||
Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache->textureSize(), |
||||
Vector2(rectangle.topRight())/cache->textureSize()); |
||||
|
||||
/* Load glyph */ |
||||
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(font, glyphs[i], FT_LOAD_DEFAULT) == 0); |
||||
const FT_GlyphSlot slot = font->glyph; |
||||
Vector2 offset = Vector2(0, 0); /** @todo really? */ |
||||
Vector2 advance = Vector2(slot->advance.x, slot->advance.y)/(64*fontSize); |
||||
|
||||
/* Absolute quad position, composed from cursor position, glyph offset
|
||||
and texture position, denormalized to requested text size */ |
||||
Rectangle quadPosition = Rectangle::fromSize( |
||||
(cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*textSize, |
||||
texturePosition.size()*textSize); |
||||
|
||||
return std::make_tuple(quadPosition, textureCoordinates, advance); |
||||
} |
||||
|
||||
} |
||||
|
||||
}} |
||||
@ -1,118 +0,0 @@
|
||||
#ifndef Magnum_Text_FreeTypeFont_h |
||||
#define Magnum_Text_FreeTypeFont_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::FreeTypeFontRenderer, Magnum::Text::FreeTypeFont |
||||
*/ |
||||
|
||||
#include <unordered_map> |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
#include "Texture.h" |
||||
#include "Text/AbstractFont.h" |
||||
#include "Text/magnumTextVisibility.h" |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
struct FT_LibraryRec_; |
||||
typedef FT_LibraryRec_* FT_Library; |
||||
struct FT_FaceRec_; |
||||
typedef FT_FaceRec_* FT_Face; |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief FreeType font renderer |
||||
|
||||
Contains global instance of font renderer. See FreeTypeFont class documentation |
||||
for more information. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT FreeTypeFontRenderer { |
||||
public: |
||||
explicit FreeTypeFontRenderer(); |
||||
|
||||
~FreeTypeFontRenderer(); |
||||
|
||||
/** @brief FreeType library handle */ |
||||
inline FT_Library library() { return _library; } |
||||
|
||||
private: |
||||
FT_Library _library; |
||||
}; |
||||
|
||||
/**
|
||||
@brief FreeType font |
||||
|
||||
@section FreeTypeFont-usage Usage |
||||
|
||||
You need to maintain instance of FreeTypeFontRenderer during the lifetime of |
||||
all FreeTypeFont instances. The font can be created either from file or from |
||||
memory location of format supported by [FreeType](http://www.freetype.org/)
|
||||
library. |
||||
@code |
||||
Text::FreeTypeFontRenderer fontRenderer; |
||||
|
||||
Text::FreeTypeFont font(fontRenderer, "MyFreeTypeFont.ttf", 48.0f); |
||||
@endcode |
||||
Next step is to prerender all the glyphs which will be used in text rendering |
||||
later, see GlyphCache for more information. See TextRenderer for information |
||||
about text rendering. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT FreeTypeFont: public AbstractFont { |
||||
public: |
||||
/**
|
||||
* @brief Create font from file |
||||
* @param renderer Font renderer |
||||
* @param fontFile Font file |
||||
* @param size Font size |
||||
*/ |
||||
explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); |
||||
|
||||
/**
|
||||
* @brief Create font from memory |
||||
* @param renderer Font renderer |
||||
* @param data Font data |
||||
* @param dataSize Font data size |
||||
* @param size Font size |
||||
*/ |
||||
explicit FreeTypeFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); |
||||
|
||||
~FreeTypeFont(); |
||||
|
||||
void createGlyphCache(GlyphCache* const cache, const std::string& characters) override; |
||||
AbstractLayouter* layout(const GlyphCache* const cache, const Float size, const std::string& text) override; |
||||
|
||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
||||
private: |
||||
#else |
||||
protected: |
||||
#endif |
||||
FT_Face ftFont; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
@ -1,124 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
#include "HarfBuzzFont.h" |
||||
|
||||
#include <hb-ft.h> |
||||
|
||||
#include "GlyphCache.h" |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
namespace { |
||||
|
||||
class HarfBuzzLayouter: public AbstractLayouter { |
||||
public: |
||||
explicit HarfBuzzLayouter(hb_font_t* const font, const GlyphCache* const cache, const Float fontSize, const Float textSize, const std::string& text); |
||||
~HarfBuzzLayouter(); |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) override; |
||||
|
||||
private: |
||||
const hb_font_t* const font; |
||||
const GlyphCache* const cache; |
||||
const Float fontSize, textSize; |
||||
hb_buffer_t* buffer; |
||||
hb_glyph_info_t* glyphInfo; |
||||
hb_glyph_position_t* glyphPositions; |
||||
}; |
||||
|
||||
} |
||||
|
||||
HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size): FreeTypeFont(renderer, fontFile, size) { |
||||
finishConstruction(); |
||||
} |
||||
|
||||
HarfBuzzFont::HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size): FreeTypeFont(renderer, data, dataSize, size) { |
||||
finishConstruction(); |
||||
} |
||||
|
||||
void HarfBuzzFont::finishConstruction() { |
||||
/* Create Harfbuzz font */ |
||||
hbFont = hb_ft_font_create(ftFont, nullptr); |
||||
} |
||||
|
||||
HarfBuzzFont::~HarfBuzzFont() { |
||||
hb_font_destroy(hbFont); |
||||
} |
||||
|
||||
AbstractLayouter* HarfBuzzFont::layout(const GlyphCache* const cache, const Float size, const std::string& text) { |
||||
return new HarfBuzzLayouter(hbFont, cache, this->size(), size, text); |
||||
} |
||||
|
||||
namespace { |
||||
|
||||
HarfBuzzLayouter::HarfBuzzLayouter(hb_font_t* const font, const GlyphCache* const cache, const Float fontSize, const Float textSize, const std::string& text): font(font), cache(cache), fontSize(fontSize), textSize(textSize) { |
||||
/* Prepare HarfBuzz buffer */ |
||||
buffer = hb_buffer_create(); |
||||
hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); |
||||
hb_buffer_set_script(buffer, HB_SCRIPT_LATIN); |
||||
hb_buffer_set_language(buffer, hb_language_from_string("en", 2)); |
||||
|
||||
/* Layout the text */ |
||||
hb_buffer_add_utf8(buffer, text.c_str(), -1, 0, -1); |
||||
hb_shape(font, buffer, nullptr, 0); |
||||
|
||||
glyphInfo = hb_buffer_get_glyph_infos(buffer, &_glyphCount); |
||||
glyphPositions = hb_buffer_get_glyph_positions(buffer, &_glyphCount); |
||||
} |
||||
|
||||
HarfBuzzLayouter::~HarfBuzzLayouter() { |
||||
/* Destroy HarfBuzz buffer */ |
||||
hb_buffer_destroy(buffer); |
||||
} |
||||
|
||||
std::tuple<Rectangle, Rectangle, Vector2> HarfBuzzLayouter::renderGlyph(const Vector2& cursorPosition, const UnsignedInt i) { |
||||
/* Position of the texture in the resulting glyph, texture coordinates */ |
||||
Vector2i position; |
||||
Rectanglei rectangle; |
||||
std::tie(position, rectangle) = (*cache)[glyphInfo[i].codepoint]; |
||||
|
||||
Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize, |
||||
Vector2(rectangle.size())/fontSize); |
||||
Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache->textureSize(), |
||||
Vector2(rectangle.topRight())/cache->textureSize()); |
||||
|
||||
/* Glyph offset and advance to next glyph in normalized coordinates */ |
||||
Vector2 offset = Vector2(glyphPositions[i].x_offset, |
||||
glyphPositions[i].y_offset)/(64*fontSize); |
||||
Vector2 advance = Vector2(glyphPositions[i].x_advance, |
||||
glyphPositions[i].y_advance)/(64*fontSize); |
||||
|
||||
/* Absolute quad position, composed from cursor position, glyph offset
|
||||
and texture position, denormalized to requested text size */ |
||||
Rectangle quadPosition = Rectangle::fromSize( |
||||
(cursorPosition + offset + Vector2(texturePosition.left(), texturePosition.bottom()))*textSize, |
||||
texturePosition.size()*textSize); |
||||
|
||||
return std::make_tuple(quadPosition, textureCoordinates, advance); |
||||
} |
||||
|
||||
} |
||||
|
||||
}} |
||||
@ -1,81 +0,0 @@
|
||||
#ifndef Magnum_Text_HarfBuzzFont_h |
||||
#define Magnum_Text_HarfBuzzFont_h |
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
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. |
||||
*/ |
||||
|
||||
/** @file
|
||||
* @brief Class Magnum::Text::HarfBuzzFont |
||||
*/ |
||||
|
||||
#include "Text/FreeTypeFont.h" |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
struct hb_font_t; |
||||
#endif |
||||
|
||||
#ifndef MAGNUM_USE_HARFBUZZ |
||||
#error Magnum is not compiled with HarfBuzz support |
||||
#endif |
||||
|
||||
namespace Magnum { namespace Text { |
||||
|
||||
/**
|
||||
@brief HarfBuzz font |
||||
|
||||
Improves FreeTypeFont with [HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz)
|
||||
text layouting capabilities, such as kerning, ligatures etc. See FreeTypeFont |
||||
class documentation for more information about usage. |
||||
*/ |
||||
class MAGNUM_TEXT_EXPORT HarfBuzzFont: public FreeTypeFont { |
||||
public: |
||||
/**
|
||||
* @brief Create font from file |
||||
* @param renderer Font renderer |
||||
* @param fontFile Font file |
||||
* @param size Font size |
||||
*/ |
||||
explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const std::string& fontFile, Float size); |
||||
|
||||
/**
|
||||
* @brief Create font from memory |
||||
* @param renderer Font renderer |
||||
* @param data Font data |
||||
* @param dataSize Font data size |
||||
* @param size Font size |
||||
*/ |
||||
explicit HarfBuzzFont(FreeTypeFontRenderer& renderer, const unsigned char* data, std::size_t dataSize, Float size); |
||||
|
||||
~HarfBuzzFont(); |
||||
|
||||
AbstractLayouter* layout(const GlyphCache* const cache, const Float size, const std::string& text) override; |
||||
|
||||
private: |
||||
void MAGNUM_TEXT_LOCAL finishConstruction(); |
||||
|
||||
hb_font_t* hbFont; |
||||
}; |
||||
|
||||
}} |
||||
|
||||
#endif |
||||
Loading…
Reference in new issue