use ppm instead of svg for generating qr pixbuf
This commit is contained in:
@@ -65,29 +65,26 @@ void RemoteAuthDialog::OnFingerprint(const std::string &fingerprint) {
|
||||
int size = qr.getSize();
|
||||
const int border = 4;
|
||||
|
||||
const auto module_set = "0 0 0";
|
||||
const auto module_clr = "255 255 255";
|
||||
|
||||
std::ostringstream sb;
|
||||
sb << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
sb << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
|
||||
sb << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 ";
|
||||
sb << (size + border * 2) << " " << (size + border * 2) << "\" stroke=\"none\">\n";
|
||||
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
|
||||
sb << "\t<path d=\"";
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
sb << "P3\n";
|
||||
sb << size + border * 2 << " " << size + border * 2 << " 255\n";
|
||||
for (int y = -border; y < size + border; y++) {
|
||||
for (int x = -border; x < size + border; x++) {
|
||||
if (qr.getModule(x, y)) {
|
||||
if (x != 0 || y != 0)
|
||||
sb << " ";
|
||||
sb << "M" << (x + border) << "," << (y + border) << "h1v1h-1z";
|
||||
sb << module_set << "\n";
|
||||
} else {
|
||||
sb << module_clr << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
sb << "\" fill=\"#000000\"/>\n";
|
||||
sb << "</svg>\n";
|
||||
|
||||
const auto svg = sb.str();
|
||||
const auto img = sb.str();
|
||||
|
||||
auto loader = Gdk::PixbufLoader::create();
|
||||
loader->write(reinterpret_cast<const guint8 *>(svg.data()), svg.size());
|
||||
loader->write(reinterpret_cast<const guint8 *>(img.data()), img.size());
|
||||
loader->close();
|
||||
const auto pb = loader->get_pixbuf()->scale_simple(256, 256, Gdk::INTERP_NEAREST);
|
||||
|
||||
|
Reference in New Issue
Block a user