Compare commits
No commits in common. "master" and "feature/fontrender" have entirely different histories.
master
...
feature/fo
|
|
@ -5,15 +5,15 @@ RUN apk update && \
|
|||
apk add --no-cache \
|
||||
autoconf \
|
||||
bash \
|
||||
boost-build \
|
||||
build-base \
|
||||
cmake \
|
||||
clang \
|
||||
clang-extra-tools \
|
||||
gdb \
|
||||
git \
|
||||
libstdc++ \
|
||||
libtool \
|
||||
linux-headers \
|
||||
ninja \
|
||||
m4 \
|
||||
perl \
|
||||
python3 \
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@
|
|||
//
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include <boost/gil/image.hpp>
|
||||
#include <ft2build.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_BITMAP_H
|
||||
|
||||
|
|
@ -29,14 +30,20 @@ class freetype_face final : public std::enable_shared_from_this<freetype_face>
|
|||
const std::string& font_path,
|
||||
pixel_size pixel_width,
|
||||
pixel_size pixel_height,
|
||||
bool render_monochrome);
|
||||
bool render_monochrome
|
||||
);
|
||||
|
||||
~freetype_face();
|
||||
|
||||
FT_BBox get_boundbox() const;
|
||||
FT_Glyph_Metrics get_dimensions(character_index character_index) const;
|
||||
|
||||
void render(character_index character_index, std::function<void(int x, int y, const uint8_t level)> painter);
|
||||
void render(
|
||||
character_index character_index,
|
||||
std::function<void(int x,
|
||||
int y,
|
||||
const uint8_t level
|
||||
)> painter);
|
||||
|
||||
private:
|
||||
FT_Int32 get_load_flags() const;
|
||||
|
|
@ -47,4 +54,4 @@ class freetype_face final : public std::enable_shared_from_this<freetype_face>
|
|||
FT_Face m_face;
|
||||
bool m_renderMonochrome;
|
||||
};
|
||||
} // namespace bmrshared
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
// the Free Software Foundation.
|
||||
//
|
||||
#pragma once
|
||||
#include <ft2build.h>
|
||||
#include <memory>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace bmrshared
|
||||
|
|
@ -23,4 +23,4 @@ class freetype_lib final : public std::enable_shared_from_this<freetype_lib>
|
|||
private:
|
||||
FT_Library m_library;
|
||||
};
|
||||
} // namespace bmrshared
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,5 @@ struct dimensions final
|
|||
};
|
||||
|
||||
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);
|
||||
} // namespace bmrshared
|
||||
void freetype_paint(freetype_face& face, std::string_view text, const std::function<void(int x, int y, uint8_t level)>& paintfn);
|
||||
}
|
||||
|
|
@ -5,13 +5,14 @@
|
|||
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
||||
// the Free Software Foundation.
|
||||
//
|
||||
#include <algorithm>
|
||||
#include <bmrshared/freetype_face.hpp>
|
||||
#include <bmrshared/freetype_lib.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace bmrshared;
|
||||
|
||||
freetype_face::freetype_face(std::shared_ptr<freetype_lib> lib,
|
||||
freetype_face::freetype_face(
|
||||
std::shared_ptr<freetype_lib> lib,
|
||||
const std::string& font_path,
|
||||
pixel_size pixel_width,
|
||||
pixel_size pixel_height,
|
||||
|
|
@ -19,9 +20,16 @@ freetype_face::freetype_face(std::shared_ptr<freetype_lib> lib,
|
|||
: m_lib(lib)
|
||||
, m_renderMonochrome(render_monochrome)
|
||||
{
|
||||
FT_New_Face(m_lib->get_ft_library(), font_path.c_str(), 0, &m_face);
|
||||
FT_New_Face(
|
||||
m_lib->get_ft_library(),
|
||||
font_path.c_str(),
|
||||
0,
|
||||
&m_face);
|
||||
|
||||
FT_Set_Pixel_Sizes(m_face, pixel_width, pixel_height);
|
||||
FT_Set_Pixel_Sizes(
|
||||
m_face,
|
||||
pixel_width,
|
||||
pixel_height);
|
||||
}
|
||||
|
||||
freetype_face::~freetype_face()
|
||||
|
|
@ -34,7 +42,8 @@ FT_BBox freetype_face::get_boundbox() const
|
|||
return m_face->bbox;
|
||||
}
|
||||
|
||||
FT_Glyph_Metrics freetype_face::get_dimensions(character_index character_index) const
|
||||
FT_Glyph_Metrics freetype_face::get_dimensions(
|
||||
character_index character_index) const
|
||||
{
|
||||
// Load glyph and retrieve metrics.
|
||||
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
||||
|
|
@ -45,7 +54,12 @@ FT_Glyph_Metrics freetype_face::get_dimensions(character_index character_index)
|
|||
}
|
||||
|
||||
|
||||
void freetype_face::render(FT_ULong character_index, std::function<void(int x, int y, uint8_t level)> painter)
|
||||
void freetype_face::render(
|
||||
FT_ULong character_index,
|
||||
std::function<void(int x,
|
||||
int y,
|
||||
uint8_t level
|
||||
)> painter)
|
||||
{
|
||||
// Load glyph and retrieve metrics.
|
||||
const auto glyph_index = FT_Get_Char_Index(m_face, character_index);
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
// under the terms of the GNU Lesser General Public License v3.0 as published by
|
||||
// the Free Software Foundation.
|
||||
//
|
||||
#include <algorithm>
|
||||
#include <bmrshared/freetype_utils.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
namespace bmrshared
|
||||
|
|
@ -29,14 +29,10 @@ dimensions freetype_calculate_dimensions(freetype_face& face, std::string_view t
|
|||
line_above_origin = std::max(line_above_origin, char_above_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 char_offset_x = 0;
|
||||
|
|
@ -57,4 +53,4 @@ void freetype_paint(freetype_face& face,
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace bmrshared
|
||||
}
|
||||
Loading…
Reference in New Issue