/* ptrnt - print labels on linux Copyright (C) 2025 Moritz Martinius This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once #include #include #include #include "graphics/Bitmap.hpp" #include "interface/IPrinterDriver.hpp" #include "interface/IPrinterTypes.hpp" #include "libusbwrap/LibUsbTypes.hpp" #include "libusbwrap/interface/IUsbDevice.hpp" namespace ptprnt::printer { /** * @brief Virtual printer driver for testing without hardware * * FakePrinter simulates a real label printer by processing bitmap data * column by column and reconstructing it into a new bitmap, mimicking * the physical printing process of label printers. */ class FakePrinter : public ::ptprnt::IPrinterDriver { public: FakePrinter() = default; ~FakePrinter() override = default; FakePrinter(const FakePrinter&) = delete; FakePrinter& operator=(const FakePrinter&) = delete; FakePrinter(FakePrinter&&) = default; FakePrinter& operator=(FakePrinter&&) = default; // Printer info - static to be accessed without instantiation static const PrinterInfo mInfo; // IPrinterDriver interface [[nodiscard]] std::string_view getDriverName() override; [[nodiscard]] std::string_view getName() override; [[nodiscard]] libusbwrap::usbId getUsbId() override; [[nodiscard]] std::string_view getVersion() override; [[nodiscard]] PrinterInfo getPrinterInfo() override; [[nodiscard]] PrinterStatus getPrinterStatus() override; bool attachUsbDevice(std::shared_ptr usbHndl) override; bool detachUsbDevice() override; bool printBitmap(const graphics::Bitmap& bitmap) override; bool printMonochromeData(const graphics::MonochromeData& data) override; bool printLabel(const std::unique_ptr label) override; bool print() override; /** * @brief Get the last printed bitmap * @return The reconstructed bitmap from simulated printing */ [[nodiscard]] const graphics::Bitmap& getLastPrint() const; /** * @brief Save the last print to a PNG file * @param filename Path to save the PNG * @return true if successful */ bool saveLastPrintToPng(const std::string& filename) const; private: /** * @brief Simulate printing by reconstructing bitmap column by column * @param data Monochrome data to "print" * @return Reconstructed bitmap */ graphics::Bitmap simulatePrinting(const graphics::MonochromeData& data); /** * @brief Save bitmap to PNG file using Cairo * @param bitmap The bitmap to save * @param filename Output filename * @return true if successful */ bool saveBitmapToPng(const graphics::Bitmap& bitmap, const std::string& filename) const; /** * @brief Generate timestamped filename for fake label output * @return Filename like "fakelabel_20231011_123456.png" */ std::string generateTimestampedFilename() const; std::unique_ptr> mLastPrint; bool mHasAttachedDevice = false; PrinterStatus mStatus{.tapeWidthMm = 12}; // Default to 12mm tape }; } // namespace ptprnt::printer