Compare commits
2 Commits
42561d5ace
...
23d74e35a1
| Author | SHA1 | Date |
|---|---|---|
|
|
23d74e35a1 | |
|
|
5cfaf9881d |
|
|
@ -5,15 +5,15 @@ RUN apk update && \
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
autoconf \
|
autoconf \
|
||||||
bash \
|
bash \
|
||||||
boost-build \
|
|
||||||
build-base \
|
build-base \
|
||||||
cmake \
|
cmake \
|
||||||
|
clang \
|
||||||
|
clang-extra-tools \
|
||||||
gdb \
|
gdb \
|
||||||
git \
|
git \
|
||||||
libstdc++ \
|
libstdc++ \
|
||||||
libtool \
|
libtool \
|
||||||
linux-headers \
|
linux-headers \
|
||||||
ninja \
|
|
||||||
m4 \
|
m4 \
|
||||||
perl \
|
perl \
|
||||||
python3 \
|
python3 \
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
"build": {
|
"build": {
|
||||||
"dockerfile": "Dockerfile"
|
"dockerfile": "Dockerfile"
|
||||||
},
|
},
|
||||||
|
|
||||||
// Configure tool-specific properties.
|
// Configure tool-specific properties.
|
||||||
"customizations": {
|
"customizations": {
|
||||||
"vscode": {
|
"vscode": {
|
||||||
|
|
|
||||||
|
|
@ -7,51 +7,44 @@
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <boost/gil/image.hpp>
|
#include <boost/gil/image.hpp>
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include FT_BITMAP_H
|
#include FT_BITMAP_H
|
||||||
|
|
||||||
namespace bmrshared
|
namespace bmrshared
|
||||||
{
|
{
|
||||||
class freetype_lib;
|
class freetype_lib;
|
||||||
|
|
||||||
class freetype_face final : public std::enable_shared_from_this<freetype_face>
|
class freetype_face final : public std::enable_shared_from_this<freetype_face>
|
||||||
{
|
{
|
||||||
using character_index = FT_ULong;
|
using character_index = FT_ULong;
|
||||||
using pixel_size = FT_UInt;
|
using pixel_size = FT_UInt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
freetype_face(std::shared_ptr<freetype_lib> lib,
|
freetype_face(std::shared_ptr<freetype_lib> lib,
|
||||||
const std::string& font_path,
|
const std::string& font_path,
|
||||||
pixel_size pixel_width,
|
pixel_size pixel_width,
|
||||||
pixel_size pixel_height,
|
pixel_size pixel_height,
|
||||||
bool render_monochrome
|
bool render_monochrome);
|
||||||
);
|
|
||||||
|
|
||||||
~freetype_face();
|
~freetype_face();
|
||||||
|
|
||||||
FT_BBox get_boundbox() const;
|
FT_BBox get_boundbox() const;
|
||||||
FT_Glyph_Metrics get_dimensions(character_index character_index) const;
|
FT_Glyph_Metrics get_dimensions(character_index character_index) const;
|
||||||
|
|
||||||
void render(
|
void render(character_index character_index, std::function<void(int x, int y, const uint8_t level)> painter);
|
||||||
character_index character_index,
|
|
||||||
std::function<void(int x,
|
private:
|
||||||
int y,
|
FT_Int32 get_load_flags() const;
|
||||||
const uint8_t level
|
FT_Render_Mode get_render_mode() const;
|
||||||
)> painter);
|
|
||||||
|
private:
|
||||||
private:
|
std::shared_ptr<freetype_lib> m_lib;
|
||||||
FT_Int32 get_load_flags() const;
|
FT_Face m_face;
|
||||||
FT_Render_Mode get_render_mode() const;
|
bool m_renderMonochrome;
|
||||||
|
};
|
||||||
private:
|
} // namespace bmrshared
|
||||||
std::shared_ptr<freetype_lib> m_lib;
|
|
||||||
FT_Face m_face;
|
|
||||||
bool m_renderMonochrome;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,21 @@
|
||||||
// the Free Software Foundation.
|
// the Free Software Foundation.
|
||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <memory>
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
|
#include <memory>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
|
||||||
namespace bmrshared
|
namespace bmrshared
|
||||||
{
|
{
|
||||||
class freetype_lib final : public std::enable_shared_from_this<freetype_lib>
|
class freetype_lib final : public std::enable_shared_from_this<freetype_lib>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
freetype_lib();
|
freetype_lib();
|
||||||
~freetype_lib();
|
~freetype_lib();
|
||||||
|
|
||||||
FT_Library get_ft_library();
|
FT_Library get_ft_library();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FT_Library m_library;
|
FT_Library m_library;
|
||||||
};
|
};
|
||||||
}
|
} // namespace bmrshared
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,15 @@
|
||||||
|
|
||||||
namespace bmrshared
|
namespace bmrshared
|
||||||
{
|
{
|
||||||
struct dimensions final
|
struct dimensions final
|
||||||
{
|
{
|
||||||
FT_Pos width;
|
FT_Pos width;
|
||||||
FT_Pos height;
|
FT_Pos height;
|
||||||
FT_Pos vertOriginOffsetY;
|
FT_Pos vertOriginOffsetY;
|
||||||
};
|
};
|
||||||
|
|
||||||
dimensions freetype_calculate_dimensions(freetype_face& face, std::string_view text);
|
dimensions freetype_calculate_dimensions(freetype_face& face, std::string_view text);
|
||||||
void freetype_paint(freetype_face& face, std::string_view text, const std::function<void(int x, int y, uint8_t level)>& paintfn);
|
void freetype_paint(freetype_face& face,
|
||||||
}
|
std::string_view text,
|
||||||
|
const std::function<void(int x, int y, uint8_t level)>& paintfn);
|
||||||
|
} // namespace bmrshared
|
||||||
|
|
@ -5,31 +5,23 @@
|
||||||
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
||||||
// the Free Software Foundation.
|
// the Free Software Foundation.
|
||||||
//
|
//
|
||||||
|
#include <algorithm>
|
||||||
#include <bmrshared/freetype_face.hpp>
|
#include <bmrshared/freetype_face.hpp>
|
||||||
#include <bmrshared/freetype_lib.hpp>
|
#include <bmrshared/freetype_lib.hpp>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
using namespace bmrshared;
|
using namespace bmrshared;
|
||||||
|
|
||||||
freetype_face::freetype_face(
|
freetype_face::freetype_face(std::shared_ptr<freetype_lib> lib,
|
||||||
std::shared_ptr<freetype_lib> lib,
|
const std::string& font_path,
|
||||||
const std::string& font_path,
|
pixel_size pixel_width,
|
||||||
pixel_size pixel_width,
|
pixel_size pixel_height,
|
||||||
pixel_size pixel_height,
|
bool render_monochrome)
|
||||||
bool render_monochrome)
|
|
||||||
: m_lib(lib)
|
: m_lib(lib)
|
||||||
, m_renderMonochrome(render_monochrome)
|
, m_renderMonochrome(render_monochrome)
|
||||||
{
|
{
|
||||||
FT_New_Face(
|
FT_New_Face(m_lib->get_ft_library(), font_path.c_str(), 0, &m_face);
|
||||||
m_lib->get_ft_library(),
|
|
||||||
font_path.c_str(),
|
|
||||||
0,
|
|
||||||
&m_face);
|
|
||||||
|
|
||||||
FT_Set_Pixel_Sizes(
|
FT_Set_Pixel_Sizes(m_face, pixel_width, pixel_height);
|
||||||
m_face,
|
|
||||||
pixel_width,
|
|
||||||
pixel_height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
freetype_face::~freetype_face()
|
freetype_face::~freetype_face()
|
||||||
|
|
@ -42,24 +34,18 @@ FT_BBox freetype_face::get_boundbox() const
|
||||||
return m_face->bbox;
|
return m_face->bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_Glyph_Metrics freetype_face::get_dimensions(
|
FT_Glyph_Metrics freetype_face::get_dimensions(character_index character_index) const
|
||||||
character_index character_index) const
|
|
||||||
{
|
{
|
||||||
// Load glyph and retrieve metrics.
|
// Load glyph and retrieve metrics.
|
||||||
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
||||||
FT_Load_Glyph(m_face, glyph_index, get_load_flags());
|
FT_Load_Glyph(m_face, glyph_index, get_load_flags());
|
||||||
|
|
||||||
FT_GlyphSlot& glyphSlot = m_face->glyph;
|
FT_GlyphSlot& glyphSlot = m_face->glyph;
|
||||||
return glyphSlot->metrics;
|
return glyphSlot->metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void freetype_face::render(
|
void freetype_face::render(FT_ULong character_index, std::function<void(int x, int y, uint8_t level)> painter)
|
||||||
FT_ULong character_index,
|
|
||||||
std::function<void(int x,
|
|
||||||
int y,
|
|
||||||
uint8_t level
|
|
||||||
)> painter)
|
|
||||||
{
|
{
|
||||||
// Load glyph and retrieve metrics.
|
// Load glyph and retrieve metrics.
|
||||||
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
||||||
|
|
@ -74,12 +60,12 @@ void freetype_face::render(
|
||||||
FT_Bitmap_Init(&target);
|
FT_Bitmap_Init(&target);
|
||||||
FT_Bitmap_Convert(m_lib->get_ft_library(), &bitmap, &target, 1);
|
FT_Bitmap_Convert(m_lib->get_ft_library(), &bitmap, &target, 1);
|
||||||
|
|
||||||
for(unsigned int x = 0; x < target.width; ++x)
|
for (unsigned int x = 0; x < target.width; ++x)
|
||||||
{
|
{
|
||||||
for(unsigned int y = 0; y < target.rows; ++y)
|
for (unsigned int y = 0; y < target.rows; ++y)
|
||||||
{
|
{
|
||||||
const uint8_t& value = 0xff * target.buffer[x + target.width * y];
|
const uint8_t& value = 0xff * target.buffer[x + target.width * y];
|
||||||
painter(x,y,value);
|
painter(x, y, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
||||||
// the Free Software Foundation.
|
// the Free Software Foundation.
|
||||||
//
|
//
|
||||||
#include <bmrshared/freetype_utils.hpp>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <bmrshared/freetype_utils.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace bmrshared
|
namespace bmrshared
|
||||||
|
|
@ -21,7 +21,7 @@ dimensions freetype_calculate_dimensions(freetype_face& face, std::string_view t
|
||||||
for (const char& c : text)
|
for (const char& c : text)
|
||||||
{
|
{
|
||||||
const FT_Glyph_Metrics& dim = face.get_dimensions(c);
|
const FT_Glyph_Metrics& dim = face.get_dimensions(c);
|
||||||
|
|
||||||
line_width += dim.horiAdvance;
|
line_width += dim.horiAdvance;
|
||||||
const auto char_above_origin = dim.horiBearingY;
|
const auto char_above_origin = dim.horiBearingY;
|
||||||
const auto char_below_origin = dim.height - dim.horiBearingY;
|
const auto char_below_origin = dim.height - dim.horiBearingY;
|
||||||
|
|
@ -29,10 +29,14 @@ dimensions freetype_calculate_dimensions(freetype_face& face, std::string_view t
|
||||||
line_above_origin = std::max(line_above_origin, char_above_origin);
|
line_above_origin = std::max(line_above_origin, char_above_origin);
|
||||||
line_below_origin = std::max(line_below_origin, char_below_origin);
|
line_below_origin = std::max(line_below_origin, char_below_origin);
|
||||||
}
|
}
|
||||||
return {.width = line_width, .height = (line_above_origin + line_below_origin), .vertOriginOffsetY = line_above_origin};
|
return {.width = line_width,
|
||||||
|
.height = (line_above_origin + line_below_origin),
|
||||||
|
.vertOriginOffsetY = line_above_origin};
|
||||||
}
|
}
|
||||||
|
|
||||||
void freetype_paint(freetype_face& face, std::string_view text, const std::function<void(int x, int y, uint8_t level)>& paintfn)
|
void freetype_paint(freetype_face& face,
|
||||||
|
std::string_view text,
|
||||||
|
const std::function<void(int x, int y, uint8_t level)>& paintfn)
|
||||||
{
|
{
|
||||||
FT_Pos line_x = 0;
|
FT_Pos line_x = 0;
|
||||||
FT_Pos char_offset_x = 0;
|
FT_Pos char_offset_x = 0;
|
||||||
|
|
@ -42,15 +46,15 @@ void freetype_paint(freetype_face& face, std::string_view text, const std::funct
|
||||||
paintfn((char_offset_x + x), (y - char_offset_y), level);
|
paintfn((char_offset_x + x), (y - char_offset_y), level);
|
||||||
};
|
};
|
||||||
|
|
||||||
for( const char& c : text)
|
for (const char& c : text)
|
||||||
{
|
{
|
||||||
const FT_Glyph_Metrics& dim = face.get_dimensions(c);
|
const FT_Glyph_Metrics& dim = face.get_dimensions(c);
|
||||||
char_offset_x = (line_x + (dim.horiAdvance - dim.width)/2)/64;
|
char_offset_x = (line_x + (dim.horiAdvance - dim.width) / 2) / 64;
|
||||||
char_offset_y = dim.horiBearingY/64;
|
char_offset_y = dim.horiBearingY / 64;
|
||||||
|
|
||||||
face.render(c, painter_char);
|
face.render(c, painter_char);
|
||||||
line_x += dim.horiAdvance;
|
line_x += dim.horiAdvance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace bmrshared
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
constexpr std::string_view magic_file_location = "/usr/local/bin/magic.mgc";
|
constexpr std::string_view magic_file_location = "/usr/local/bin/magic.mgc";
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_magic, no_throw_on_query)
|
TEST(test_magic, no_throw_on_query)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ struct function_wrapper<T, TExtraArguments...>
|
||||||
using wrapper_type = std::function<flexible_value(const T&, const IDataSource&, TExtraArguments...)>;
|
using wrapper_type = std::function<flexible_value(const T&, const IDataSource&, TExtraArguments...)>;
|
||||||
|
|
||||||
template<typename M, typename... TSourceParams>
|
template<typename M, typename... TSourceParams>
|
||||||
static wrapper_type Wrap(M T::*callableFn, TSourceParams... paramNames)
|
static wrapper_type Wrap(M T::* callableFn, TSourceParams... paramNames)
|
||||||
{
|
{
|
||||||
std::array<std::string, sizeof...(TSourceParams)> names{paramNames...};
|
std::array<std::string, sizeof...(TSourceParams)> names{paramNames...};
|
||||||
return [callableFn, names](const T& obj, const IDataSource& source, TExtraArguments... args)
|
return [callableFn, names](const T& obj, const IDataSource& source, TExtraArguments... args)
|
||||||
|
|
@ -47,7 +47,7 @@ struct function_wrapper<T, TExtraArguments...>
|
||||||
using wrapper_type = std::function<flexible_value(T&, const IDataSource&, TExtraArguments...)>;
|
using wrapper_type = std::function<flexible_value(T&, const IDataSource&, TExtraArguments...)>;
|
||||||
|
|
||||||
template<typename M, typename... TSourceParams>
|
template<typename M, typename... TSourceParams>
|
||||||
static wrapper_type Wrap(M T::*callableFn, TSourceParams... paramNames)
|
static wrapper_type Wrap(M T::* callableFn, TSourceParams... paramNames)
|
||||||
{
|
{
|
||||||
std::array<std::string, sizeof...(TSourceParams)> names{paramNames...};
|
std::array<std::string, sizeof...(TSourceParams)> names{paramNames...};
|
||||||
return [callableFn, names](T& obj, const IDataSource& source, TExtraArguments... args)
|
return [callableFn, names](T& obj, const IDataSource& source, TExtraArguments... args)
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ namespace detail
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename FirstTupleType, typename... TupleTypes, std::size_t NTypesToKeep, typename... TypesToKeep>
|
template<typename FirstTupleType, typename... TupleTypes, std::size_t NTypesToKeep, typename... TypesToKeep>
|
||||||
requires(NTypesToKeep > 0)
|
requires(NTypesToKeep > 0)
|
||||||
|
|
||||||
struct tuple_keepelemsfront<std::tuple<FirstTupleType, TupleTypes...>, NTypesToKeep, TypesToKeep...>
|
struct tuple_keepelemsfront<std::tuple<FirstTupleType, TupleTypes...>, NTypesToKeep, TypesToKeep...>
|
||||||
{
|
{
|
||||||
using tuple = typename tuple_keepelemsfront<std::tuple<TupleTypes...>,
|
using tuple = typename tuple_keepelemsfront<std::tuple<TupleTypes...>,
|
||||||
(NTypesToKeep - 1),
|
(NTypesToKeep - 1),
|
||||||
|
|
@ -52,10 +52,10 @@ namespace detail
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<typename M, typename T, std::size_t TParameterCount, typename... TExtraArguments>
|
template<typename M, typename T, std::size_t TParameterCount, typename... TExtraArguments>
|
||||||
requires(function_info<M T::*>::is_const_member == false)
|
requires(function_info<M T::*>::is_const_member == false)
|
||||||
|
|
||||||
flexible_value invoke(T& callableObj,
|
flexible_value invoke(T& callableObj,
|
||||||
M T::*callableFn,
|
M T::* callableFn,
|
||||||
std::array<std::string, TParameterCount> names,
|
std::array<std::string, TParameterCount> names,
|
||||||
const IDataSource& source,
|
const IDataSource& source,
|
||||||
TExtraArguments&&... arguments)
|
TExtraArguments&&... arguments)
|
||||||
|
|
@ -72,10 +72,10 @@ flexible_value invoke(T& callableObj,
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename M, typename T, std::size_t TParameterCount, typename... TExtraArguments>
|
template<typename M, typename T, std::size_t TParameterCount, typename... TExtraArguments>
|
||||||
requires(function_info<M T::*>::is_const_member == true)
|
requires(function_info<M T::*>::is_const_member == true)
|
||||||
|
|
||||||
flexible_value invoke(const T& callableObj,
|
flexible_value invoke(const T& callableObj,
|
||||||
M T::*callableFn,
|
M T::* callableFn,
|
||||||
std::array<std::string, TParameterCount> names,
|
std::array<std::string, TParameterCount> names,
|
||||||
const IDataSource& source,
|
const IDataSource& source,
|
||||||
TExtraArguments&&... arguments)
|
TExtraArguments&&... arguments)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue