Compare commits
1 Commits
778a01429c
...
gitignore-
Author | SHA1 | Date | |
---|---|---|---|
|
e0e158ca90
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@ subprojects/*
|
|||||||
coverageReport/
|
coverageReport/
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
|
ptprnt.log
|
||||||
!subprojects/*.wrap
|
!subprojects/*.wrap
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/c_cpp_properties.json
|
!.vscode/c_cpp_properties.json
|
||||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -85,5 +85,6 @@
|
|||||||
},
|
},
|
||||||
"clang-tidy.buildPath": "builddir/",
|
"clang-tidy.buildPath": "builddir/",
|
||||||
"clangd.onConfigChanged": "restart",
|
"clangd.onConfigChanged": "restart",
|
||||||
"C_Cpp.default.compileCommands": "builddir/compile_commands.json"
|
"C_Cpp.default.compileCommands": "builddir/compile_commands.json",
|
||||||
|
"mesonbuild.configureOnOpen": true
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,6 @@
|
|||||||
#include "CLI/Option.hpp"
|
#include "CLI/Option.hpp"
|
||||||
#include "P700Printer.hpp"
|
#include "P700Printer.hpp"
|
||||||
#include "graphics/Bitmap.hpp"
|
#include "graphics/Bitmap.hpp"
|
||||||
#include "graphics/Image.hpp"
|
|
||||||
#include "libusbwrap/UsbDeviceFactory.hpp"
|
#include "libusbwrap/UsbDeviceFactory.hpp"
|
||||||
|
|
||||||
namespace ptprnt {
|
namespace ptprnt {
|
||||||
@@ -99,10 +98,6 @@ int PtouchPrint::run() {
|
|||||||
|
|
||||||
for (auto& cmd : mCommands) {
|
for (auto& cmd : mCommands) {
|
||||||
spdlog::debug("Command: {}", cmd.second);
|
spdlog::debug("Command: {}", cmd.second);
|
||||||
if (cmd.first == CliCmdType::Text) {
|
|
||||||
auto label{graphics::Image()};
|
|
||||||
label.createLabel(cmd.second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -19,23 +19,13 @@
|
|||||||
|
|
||||||
#include "Image.hpp"
|
#include "Image.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <spdlog/spdlog.h>
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <iostream> // remove me
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "cairo.h"
|
|
||||||
#include "pango/pango-context.h"
|
|
||||||
#include "pango/pango-font.h"
|
#include "pango/pango-font.h"
|
||||||
#include "pango/pango-layout.h"
|
|
||||||
#include "pango/pango-types.h"
|
|
||||||
#include "pango/pangocairo.h"
|
|
||||||
|
|
||||||
namespace ptprnt::graphics {
|
namespace ptprnt::graphics {
|
||||||
Image::Image() {
|
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);
|
cairo_t* cr = cairo_create(mSurface);
|
||||||
mFontDescription = pango_font_description_new();
|
mFontDescription = pango_font_description_new();
|
||||||
pango_font_description_set_family(mFontDescription, "sans");
|
pango_font_description_set_family(mFontDescription, "sans");
|
||||||
@@ -52,7 +42,7 @@ Image::Image() {
|
|||||||
cairo_move_to(cr, 0.0, 94.0);
|
cairo_move_to(cr, 0.0, 94.0);
|
||||||
pango_cairo_show_layout_line(cr, pango_layout_get_line(mLayout, 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() {
|
uint8_t* Image::getRaw() {
|
||||||
@@ -60,46 +50,8 @@ uint8_t* Image::getRaw() {
|
|||||||
return cairo_image_surface_get_data(mSurface);
|
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() {
|
Image::~Image() {
|
||||||
spdlog::info("Image dtor...");
|
g_object_unref(mLayout);
|
||||||
|
pango_font_description_free(mFontDescription);
|
||||||
}
|
}
|
||||||
} // namespace ptprnt::graphics
|
} // namespace ptprnt::graphics
|
@@ -22,30 +22,15 @@
|
|||||||
#include <pango/pangocairo.h>
|
#include <pango/pangocairo.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace ptprnt::graphics {
|
namespace ptprnt::graphics {
|
||||||
|
|
||||||
constexpr const char* DEFAULT_FONT_FAMILY = "sans";
|
|
||||||
constexpr const uint8_t DEFAULT_FONT_SIZE = 32;
|
|
||||||
|
|
||||||
class Image {
|
class Image {
|
||||||
public:
|
public:
|
||||||
Image();
|
Image();
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
Image(const Image&) = delete;
|
|
||||||
Image& operator=(const Image&) = delete;
|
|
||||||
Image(Image&&) = delete;
|
|
||||||
Image& operator=(Image&&) = delete;
|
|
||||||
|
|
||||||
uint8_t* getRaw();
|
uint8_t* getRaw();
|
||||||
void createLabel(const std::string& labelText);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods
|
|
||||||
uint8_t getNumLines(std::string_view str);
|
|
||||||
// members
|
|
||||||
PangoLayout* mLayout;
|
PangoLayout* mLayout;
|
||||||
PangoFontDescription* mFontDescription;
|
PangoFontDescription* mFontDescription;
|
||||||
cairo_surface_t* mSurface;
|
cairo_surface_t* mSurface;
|
||||||
|
Reference in New Issue
Block a user