ugly hackl to allow umlauts in pos text
This commit is contained in:
parent
b2c64d8631
commit
23659078b4
4 changed files with 41 additions and 8 deletions
|
@ -1,3 +1,7 @@
|
|||
set(Boost_USE_STATIC_LIBS ON)
|
||||
|
||||
find_package(Boost 1.62 REQUIRED)
|
||||
|
||||
find_package(LibUSB REQUIRED)
|
||||
|
||||
set(PRINTER_SOURCES
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "posprinter.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
const std::string PosPrinter::Command::RESET = {0x1b, 0x40};
|
||||
const std::string PosPrinter::Command::ENCODING = {'\x1b', '\x74', 16};
|
||||
|
@ -90,10 +92,22 @@ void PosPrinter::write(const std::string& text)
|
|||
{
|
||||
if (devicePtr_ == NULL)
|
||||
return;
|
||||
int length = text.length();
|
||||
|
||||
using namespace std::string_literals;
|
||||
std::string text_escaped = text;
|
||||
boost::replace_all(text_escaped, "ä", "\xe4");
|
||||
boost::replace_all(text_escaped, "ö", "\xf6");
|
||||
boost::replace_all(text_escaped, "ü", "\xfc");
|
||||
boost::replace_all(text_escaped, "Ä", "\xc4");
|
||||
boost::replace_all(text_escaped, "Ö", "\xd6");
|
||||
boost::replace_all(text_escaped, "Ü", "\xdc");
|
||||
boost::replace_all(text_escaped, "€", "\x80");
|
||||
|
||||
int length = text_escaped.length();
|
||||
int actual{0};
|
||||
int retValue = libusb_bulk_transfer(devicePtr_, (0x03 | LIBUSB_ENDPOINT_OUT),
|
||||
(unsigned char*)text.c_str(), length, &actual, 10000);
|
||||
int retValue =
|
||||
libusb_bulk_transfer(devicePtr_, (0x03 | LIBUSB_ENDPOINT_OUT),
|
||||
(unsigned char*)text_escaped.c_str(), length, &actual, 10000);
|
||||
if (retValue != 0 || actual != length)
|
||||
std::cerr << "Write Error" << std::endl;
|
||||
}
|
||||
|
@ -116,7 +130,7 @@ void PosPrinter::printTest()
|
|||
std::stringstream commandStream;
|
||||
commandStream << Command::ENCODING;
|
||||
commandStream << "Der Drucker kann von KIMA2\nangesprochen werden.\n\n"
|
||||
<< u8"Beachten Sie, dass nicht\nalle Modelle Strichcodes\nausdrucken können.";
|
||||
<< "Beachten Sie, dass nicht\nalle Modelle Strichcodes\nausdrucken können.";
|
||||
commandStream << Command::FEED;
|
||||
printHeader();
|
||||
write(commandStream.str());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue