Compare commits

..

No commits in common. "master" and "feature/fontrender" have entirely different histories.

24 changed files with 142 additions and 317 deletions

22
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM alpine:3.21.3
# Install tools required for building.
RUN apk update && \
apk add --no-cache \
autoconf \
bash \
boost-build \
build-base \
cmake \
gdb \
git \
libstdc++ \
libtool \
linux-headers \
ninja \
m4 \
perl \
python3 \
py3-pip && \
pip install --break-system-packages conan && \
conan profile detect

View File

@ -1,22 +1,15 @@
{
"name": "4beumer.nl C++",
"name": "C++",
"build": {
"dockerfile": "../devcontainer.Dockerfile",
"dockerfile": "Dockerfile"
},
"postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postcreate.py --environment=${containerWorkspaceFolder}/dev-environment.json",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"conan-extension.installArgs": [
"-of build",
"-s build_type=Debug",
"-s compiler.cppstd=23"
],
},
"settings": {},
"extensions": [
"ms-vscode.cpptools",
"ms-python.python",
"twxs.cmake",
"ms-vscode.cmake-tools",
"konicy.conan-extension"

View File

@ -1,36 +0,0 @@
#! /usr/bin/python
import argparse
import json
import os
import subprocess
import sys
def runcmd(command):
print('RUN ' + command)
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
for line in iter(process.stdout.readline, b''): # b'' indicates EOF
print(line.decode('utf-8'), end='')
def load_environment(filename):
with open(filename) as f:
return json.load(f)
parser = argparse.ArgumentParser()
parser.add_argument('--environment')
args = parser.parse_args()
environment = load_environment(args.environment)
env_build_type = environment["build_type"]
env_cppstd = environment["cppstd"]
env_conan_remote_fallback = environment["conan_remote_fallback"]
env_conan_remote_upload = environment["conan_remote_upload"]
runcmd('conan remote remove conancenter')
runcmd('conan remote add conan-upload ' + env_conan_remote_upload)
runcmd('conan remote add conan-remote ' + env_conan_remote_fallback)
runcmd('conan install . -of build -s compiler.cppstd=' + env_cppstd + ' -s build_type=' + env_build_type + ' --build=never')
sys.exit(0)

View File

@ -1,32 +0,0 @@
# Network experiment
This repository mostly contains personal experiments related to C++, CMake, conan, and some stuff that might end up on a raspberry pi. I have tried to rely mostly on development containers and almost no tools on the host. This should make it possible to build/develop/use this code on any machine that runs dev container, including ARM systems and Windows.
## How to use:
### Start developing
1. Clone the repository to a location of your liking.
2. Have an IDE that supports dev containers. I have used Visual studio code.
3. Open the project in your IDE, it should offer to open the project in a dev container.
Also take into consideration the following files:
1. ``dev-environment.json``
This file contains information about the type of build, the C++ version to use, and conan remotes used to retrieve packages.
2. ``.devcontainer/devcontainer.json``
Also contains configuration on plugins used (and some duplicated config on build type and C++ version).
### Building conan dependencies
Available in this repository is a ``dev-pre-conan-pkgs.Dockerfile`` that can be used to build all the conan dependencies and upload them to a remote.
1. Use dev-environment.json to configure the remotes (Where retrieve info, where to upload binaries).
2. Build the docker image using the following command:
``docker build -t tmp_bldconan -f dev-prep-conan-pkgs.Dockerfile .``
3. Run using the image to build & upload packages:
``docker run -ti tmp_bldconan``
- While running a username and password will be required to login.
- Do not forget to remove the image if you do not need it anymore.
Building conan packages for other architectures is also possible using "buildx". See external documentation on how to setup this feature. When setup, the following commands can be used to build for 32 bit ARM (useful for raspberry pi).
- ``docker buildx build -t tmp_bldconan_arm32 -f dev-prep-conan-pkgs.Dockerfile . --load --platform=linux/arm``
- ``docker run -ti --platform linux/arm tmp_bldconan_arm32``

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
find_package(Boost 1.90.0 REQUIRED COMPONENTS program_options headers CONFIG)
find_package(Boost 1.84.0 REQUIRED COMPONENTS program_options headers CONFIG)
find_package(JPEG REQUIRED)
project(text2image)
@ -11,7 +11,7 @@ add_executable(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_link_libraries(

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)
find_package(freetype REQUIRED)
find_package(Boost 1.90.0 REQUIRED COMPONENTS headers CONFIG)
find_package(Boost 1.84.0 REQUIRED COMPONENTS headers CONFIG)
project(bmrshared-freetype)
@ -14,7 +14,7 @@ add_library(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_include_directories(

View File

@ -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
}

View File

@ -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
}

View File

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

View File

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

View File

@ -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
}

View File

@ -11,7 +11,7 @@ add_library(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_include_directories(
@ -26,6 +26,6 @@ target_link_libraries(
)
install(
FILES ${BLDENV_LIBMAGIC_PACKAGE_FOLDER}/res/magic.mgc
FILES ${CONAN_LIBMAGIC_PACKAGE_FOLDER}/res/magic.mgc
DESTINATION bin
)

View File

@ -13,7 +13,7 @@ add_executable(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_link_libraries(

View File

@ -11,7 +11,7 @@ add_library(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_include_directories(

View File

@ -15,7 +15,7 @@ add_executable(
set_property(
TARGET ${PROJECT_NAME}
PROPERTY CXX_STANDARD 23
PROPERTY CXX_STANDARD 20
)
target_link_libraries(

View File

@ -3,30 +3,18 @@ from conan import ConanFile
from conan.tools.files import copy
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
class BmrConan(ConanFile):
class HelloConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = "boost/1.84.0", "gtest/1.14.0", "libmagic/5.45", "freetype/2.13.3", "libjpeg/9f"
generators = "CMakeDeps"
build_policy = "never"
def configure(self):
self.options["boost"].without_cobalt = True
if self.settings.arch == "armv7":
self.options["libpng"].neon = False
def requirements(self):
self.requires("boost/1.90.0")
self.requires("gtest/1.16.0")
self.requires("libmagic/5.45")
self.requires("freetype/2.14.1")
self.requires("libjpeg/9f")
self.requires("libpng/1.6.54")
build_policy = "*"
def generate(self):
# We need to find the folder of libmagic and supply it to cmake so that
# we can deploy the magic file.
libmagic = self.dependencies["libmagic"]
tc = CMakeToolchain(self)
tc.variables["BLDENV_LIBMAGIC_PACKAGE_FOLDER"] = libmagic.package_folder
tc.variables["CONAN_LIBMAGIC_PACKAGE_FOLDER"] = libmagic.package_folder
tc.generate()

View File

@ -1,6 +0,0 @@
{
"build_type": "Debug",
"cppstd" : "23",
"conan_remote_fallback" : "https://artifacts.4beumer.nl/repository/conan-center-proxy/",
"conan_remote_upload" : "https://artifacts.4beumer.nl/repository/conan-bmrdev/"
}

View File

@ -1,43 +0,0 @@
FROM alpine:3.22.2
# Install packages needed in both building and running.
RUN apk update && \
apk add --no-cache \
libstdc++
# Install tools required for building.
RUN mkdir -p /root/.local/bin
ENV PATH="${PATH}:/root/.local/bin"
RUN apk add --no-cache \
autoconf \
bash \
binutils \
build-base \
cmake \
clang \
clang-extra-tools \
gdb \
git \
libtool \
linux-headers \
ninja \
m4 \
perl \
python3 \
pipx
RUN pipx ensurepath \
&& pipx install conan \
&& conan profile detect
RUN mkdir -p /tmpdev
WORKDIR /tmpdev
ADD conanfile.py .
ADD dev-environment.json .
ADD --chmod=544 ./scripts/dev-prep-conan-pkgs/dev-prep-conan-pkgs.py .
ADD --chmod=544 ./scripts/dev-prep-conan-pkgs/entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]

View File

@ -1,32 +0,0 @@
FROM alpine:3.22.2
# Install packages needed in both building and running.
RUN apk update && \
apk add --no-cache \
libstdc++
# Install tools required for building.
RUN mkdir -p /root/.local/bin
ENV PATH="${PATH}:/root/.local/bin"
RUN apk add --no-cache \
autoconf \
bash \
binutils \
build-base \
cmake \
clang \
clang-extra-tools \
gdb \
git \
libtool \
linux-headers \
ninja \
m4 \
perl \
python3 \
pipx
RUN pipx ensurepath \
&& pipx install conan \
&& conan profile detect

View File

@ -1,39 +0,0 @@
#! /usr/bin/python
import argparse
import json
import os
import subprocess
import sys
def runcmd(command):
print('RUN ' + command)
process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
for line in iter(process.stdout.readline, b''): # b'' indicates EOF
print(line.decode('utf-8'), end='')
def load_environment(filename):
with open(filename) as f:
return json.load(f)
parser = argparse.ArgumentParser()
parser.add_argument('--environment')
args = parser.parse_args()
environment = load_environment(args.environment)
env_build_type = environment["build_type"]
env_cppstd = environment["cppstd"]
env_conan_remote_fallback = environment["conan_remote_fallback"]
env_conan_remote_upload = environment["conan_remote_upload"]
with open('CMakeLists.txt', 'w') as fp:
pass
runcmd('conan remote remove conancenter')
runcmd('conan remote add conan-upload ' + env_conan_remote_upload)
runcmd('conan remote add conan-remote ' + env_conan_remote_fallback)
runcmd('conan install . -of build -s compiler.cppstd=' + env_cppstd + ' -s build_type=' + env_build_type + ' --build=*')
sys.exit(0)

View File

@ -1,5 +0,0 @@
#!/bin/bash
./dev-prep-conan-pkgs.py --environment=dev-environment.json
conan upload -r conan-upload "*/*" --check -c