Compare commits
2 Commits
ed77d34f1c
...
92efeaf778
Author | SHA1 | Date | |
---|---|---|---|
92efeaf778 | |||
cd15930e1d |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,9 +1,13 @@
|
||||
# Folder
|
||||
builddir/
|
||||
ptouch-print/
|
||||
subprojects/*
|
||||
!subprojects/*.wrap
|
||||
.cache/
|
||||
coverageReport/
|
||||
|
||||
# Files
|
||||
!subprojects/*.wrap
|
||||
.vscode/*
|
||||
!.vscode/c_cpp_properties.json
|
||||
!.vscode/settings.json
|
||||
!.vscode/launch.json
|
||||
ptouch-print/
|
21
generate_coverage.sh
Executable file
21
generate_coverage.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||
HTML_COV_PATH="coverageReport/html"
|
||||
HTML_START_FILE="index.html"
|
||||
|
||||
echo "Generating Coverage report for ptouch-prnt"
|
||||
|
||||
ninja -C builddir
|
||||
ninja -C builddir test
|
||||
|
||||
mkdir -p ${HTML_COV_PATH}
|
||||
gcovr --html --html-details --html-syntax-highlighting --filter src --output ${HTML_COV_PATH}/${HTML_START_FILE}
|
||||
|
||||
if [ $? ]
|
||||
then
|
||||
echo "Coverage report successful generated!"
|
||||
echo "Open: file://${SCRIPT_PATH}/${HTML_COV_PATH}/${HTML_START_FILE}"
|
||||
else
|
||||
echo "Error generating coverage report!"
|
||||
fi
|
38
meson.build
38
meson.build
@@ -17,45 +17,15 @@ endif
|
||||
|
||||
incdir = include_directories('src')
|
||||
|
||||
ptprnt_hpps = [
|
||||
'src/libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'src/libusbwrap/interface/IUsbDevice.hpp',
|
||||
'src/libusbwrap/UsbDeviceFactory.hpp',
|
||||
'src/libusbwrap/LibUsbTypes.hpp',
|
||||
'src/libusbwrap/UsbDevice.hpp',
|
||||
'src/interface/IPrinterDriver.hpp',
|
||||
'src/interface/IPrinterTypes.hpp',
|
||||
'src/P700Printer.hpp',
|
||||
'src/PtouchPrint.hpp',
|
||||
'src/graphics/Bitmap.hpp',
|
||||
'src/graphics/Image.hpp',
|
||||
'src/graphics/Monochrome.hpp'
|
||||
]
|
||||
|
||||
ptprnt_srcs = [
|
||||
'src/PtouchPrint.cpp',
|
||||
'src/P700Printer.cpp',
|
||||
'src/graphics/Image.cpp',
|
||||
'src/graphics/Bitmap.cpp',
|
||||
'src/graphics/Monochrome.cpp',
|
||||
'src/libusbwrap/UsbDeviceFactory.cpp',
|
||||
'src/libusbwrap/UsbDevice.cpp',
|
||||
]
|
||||
|
||||
ptprnt_lib = library('ptprnt',
|
||||
include_directories: incdir,
|
||||
install: true,
|
||||
dependencies: [usb_dep, log_dep, pangocairo_dep, cli11_dep],
|
||||
sources: [ptprnt_hpps, ptprnt_srcs])
|
||||
|
||||
ptprnt_dep = declare_dependency(include_directories: incdir,
|
||||
link_with: ptprnt_lib)
|
||||
subdir('src')
|
||||
|
||||
ptprnt_exe = executable(
|
||||
'ptprnt',
|
||||
'src/main.cpp',
|
||||
install: true,
|
||||
dependencies : [usb_dep, log_dep, cli11_dep, ptprnt_dep],
|
||||
dependencies : [usb_dep, log_dep, pangocairo_dep, cli11_dep],
|
||||
include_directories: incdir,
|
||||
sources: [ptprnt_srcs],
|
||||
cpp_args : ['-DPROJ_VERSION="'+meson.project_version()+'"'],
|
||||
)
|
||||
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "CLI/Option.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include "graphics/Bitmap.hpp"
|
||||
#include "graphics/Image.hpp"
|
||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||
|
||||
namespace ptprnt {
|
||||
@@ -84,7 +85,10 @@ int PtouchPrint::run() {
|
||||
//printer->printText("wurst", 1);
|
||||
|
||||
for (auto& cmd : mCommands) {
|
||||
std::cout << cmd.second << std::endl;
|
||||
if (cmd.first == CliCmdType::Text) {
|
||||
auto label{graphics::Image()};
|
||||
label.createLabel(cmd.second);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -52,6 +52,11 @@ bool Bitmap<T>::setPixels(const std::vector<T>& pixels) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::vector<T> Bitmap<T>::getPixelsCpy() {
|
||||
return mPixels;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::optional<std::vector<T>> Bitmap<T>::getLine(uint16_t line) {
|
||||
if (line >= mHeight) {
|
||||
|
@@ -22,6 +22,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
@@ -41,6 +42,7 @@ class Bitmap {
|
||||
uint16_t getWidth();
|
||||
uint16_t getHeight();
|
||||
bool setPixels(const std::vector<T>& pixels);
|
||||
std::vector<T> getPixelsCpy();
|
||||
std::optional<std::vector<T>> getLine(uint16_t line);
|
||||
std::optional<std::vector<T>> getCol(uint16_t col);
|
||||
|
||||
|
@@ -19,13 +19,23 @@
|
||||
|
||||
#include "Image.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream> // remove me
|
||||
#include <string>
|
||||
|
||||
#include "cairo.h"
|
||||
#include "pango/pango-context.h"
|
||||
#include "pango/pango-font.h"
|
||||
#include "pango/pango-layout.h"
|
||||
#include "pango/pango-types.h"
|
||||
#include "pango/pangocairo.h"
|
||||
|
||||
namespace ptprnt::graphics {
|
||||
Image::Image() {
|
||||
mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
||||
/*mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
||||
cairo_t* cr = cairo_create(mSurface);
|
||||
mFontDescription = pango_font_description_new();
|
||||
pango_font_description_set_family(mFontDescription, "sans");
|
||||
@@ -42,7 +52,7 @@ Image::Image() {
|
||||
cairo_move_to(cr, 0.0, 94.0);
|
||||
pango_cairo_show_layout_line(cr, pango_layout_get_line(mLayout, 0));
|
||||
|
||||
cairo_surface_write_to_png(mSurface, "hello.png");
|
||||
cairo_surface_write_to_png(mSurface, "hello.png");*/
|
||||
}
|
||||
|
||||
uint8_t* Image::getRaw() {
|
||||
@@ -50,8 +60,46 @@ uint8_t* Image::getRaw() {
|
||||
return cairo_image_surface_get_data(mSurface);
|
||||
}
|
||||
|
||||
uint8_t Image::getNumLines(std::string_view strv) {
|
||||
return std::count(strv.begin(), strv.end(), '\n');
|
||||
}
|
||||
|
||||
void Image::createLabel(const std::string& str) {
|
||||
// create Pango layout first, to get the render dimensions
|
||||
mSurface = cairo_image_surface_create(CAIRO_FORMAT_A8, 512, 128);
|
||||
cairo_t* cr = cairo_create(mSurface);
|
||||
//auto pangoCtx{pango_context_new()};
|
||||
auto pangoLyt{pango_cairo_create_layout(cr)};
|
||||
auto pangoFontDesc{pango_font_description_from_string("FreeSans 32")};
|
||||
|
||||
pango_layout_set_single_paragraph_mode(pangoLyt, true);
|
||||
pango_layout_set_height(pangoLyt, getNumLines(str) * -1);
|
||||
pango_layout_set_alignment(pangoLyt, PANGO_ALIGN_CENTER);
|
||||
pango_layout_set_font_description(pangoLyt, pangoFontDesc);
|
||||
pango_layout_set_text(pangoLyt, str.c_str(), static_cast<int>(str.length()));
|
||||
|
||||
// Debug only
|
||||
GError* gerr{nullptr};
|
||||
pango_layout_write_to_file(pangoLyt, PANGO_LAYOUT_SERIALIZE_DEFAULT, "hello.txt", &gerr);
|
||||
|
||||
// create Cairo surface from p ango layout
|
||||
int* width{};
|
||||
int* height{}; // TODO: change me, fixed for current printer (128px)
|
||||
PangoRectangle* rect{};
|
||||
|
||||
pango_cairo_show_layout(cr, pangoLyt);
|
||||
pango_layout_get_extents(pangoLyt, rect, rect);
|
||||
std::cerr << "Width is: " << rect->width << " height is:" << rect->height << std::endl;
|
||||
|
||||
//auto cairoSfc{cairo_image_surface_create(CAIRO_FORMAT_A8, *width, *height)};
|
||||
|
||||
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
||||
|
||||
// Debug only
|
||||
cairo_surface_write_to_png(mSurface, "hellow.png");
|
||||
}
|
||||
|
||||
Image::~Image() {
|
||||
g_object_unref(mLayout);
|
||||
pango_font_description_free(mFontDescription);
|
||||
spdlog::info("Image dtor...");
|
||||
}
|
||||
} // namespace ptprnt::graphics
|
@@ -22,15 +22,30 @@
|
||||
#include <pango/pangocairo.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ptprnt::graphics {
|
||||
|
||||
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
|
||||
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
|
||||
|
||||
class Image {
|
||||
public:
|
||||
Image();
|
||||
~Image();
|
||||
|
||||
Image(const Image&) = delete;
|
||||
Image& operator=(const Image&) = delete;
|
||||
Image(Image&&) = delete;
|
||||
Image& operator=(Image&&) = delete;
|
||||
|
||||
uint8_t* getRaw();
|
||||
void createLabel(const std::string& labelText);
|
||||
|
||||
private:
|
||||
// methods
|
||||
uint8_t getNumLines(std::string_view str);
|
||||
// members
|
||||
PangoLayout* mLayout;
|
||||
PangoFontDescription* mFontDescription;
|
||||
cairo_surface_t* mSurface;
|
||||
|
@@ -16,10 +16,6 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "PtouchPrint.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
24
src/meson.build
Normal file
24
src/meson.build
Normal file
@@ -0,0 +1,24 @@
|
||||
ptprnt_hpps = files (
|
||||
'libusbwrap/interface/IUsbDeviceFactory.hpp',
|
||||
'libusbwrap/interface/IUsbDevice.hpp',
|
||||
'libusbwrap/UsbDeviceFactory.hpp',
|
||||
'libusbwrap/LibUsbTypes.hpp',
|
||||
'libusbwrap/UsbDevice.hpp',
|
||||
'interface/IPrinterDriver.hpp',
|
||||
'interface/IPrinterTypes.hpp',
|
||||
'P700Printer.hpp',
|
||||
'PtouchPrint.hpp',
|
||||
'graphics/Bitmap.hpp',
|
||||
'graphics/Image.hpp',
|
||||
'graphics/Monochrome.hpp'
|
||||
)
|
||||
|
||||
ptprnt_srcs = files (
|
||||
'PtouchPrint.cpp',
|
||||
'P700Printer.cpp',
|
||||
'graphics/Image.cpp',
|
||||
'graphics/Bitmap.cpp',
|
||||
'graphics/Monochrome.cpp',
|
||||
'libusbwrap/UsbDeviceFactory.cpp',
|
||||
'libusbwrap/UsbDevice.cpp',
|
||||
)
|
@@ -21,7 +21,9 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
TEST(basic_test, Bitmap_createBitmapWithCertainSize_yieldsSpecifiedSize) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
@@ -64,3 +66,36 @@ TEST(basic_test, Bitmap_getBitmapColInsideOfImage_yieldsValidColSize) {
|
||||
auto colSize = col->size();
|
||||
ASSERT_EQ(8, colSize);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_setsGivenPixels) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
bm.setPixels(pix);
|
||||
auto pixCpy = bm.getPixelsCpy();
|
||||
|
||||
ASSERT_EQ(pix, pixCpy);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_isSuccessfulWithValidPixels) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
ASSERT_TRUE(bm.setPixels(pix));
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixels_yieldsSamePixelsBack) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(16, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
bm.setPixels(pix);
|
||||
auto pixCpy = bm.getPixelsCpy();
|
||||
ASSERT_EQ(pix, pixCpy);
|
||||
}
|
||||
|
||||
TEST(basic_test, Bitmap_setPixelsWithWrongSize_isFailing) {
|
||||
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(5, 8);
|
||||
std::vector<uint8_t> pix(16 * 8);
|
||||
|
||||
ASSERT_FALSE(bm.setPixels(pix));
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ['monochrome_test/monochrome_test.cpp']]
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ptprnt_srcs + ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ptprnt_srcs +['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ptprnt_srcs +['monochrome_test/monochrome_test.cpp']]
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
@@ -8,8 +8,7 @@ foreach test : tests
|
||||
executable(test.get(1),
|
||||
sources: test.get(2),
|
||||
include_directories: incdir,
|
||||
link_with:[ptprnt_lib],
|
||||
dependencies: [gtest_dep, pangocairo_dep]
|
||||
dependencies: [gtest_dep, usb_dep, log_dep, pangocairo_dep, cli11_dep]
|
||||
)
|
||||
)
|
||||
endforeach
|
Reference in New Issue
Block a user