| 31 | } |
| 32 | |
| 33 | std::string ToSVG(const BitMatrix& matrix) |
| 34 | { |
| 35 | // see https://stackoverflow.com/questions/10789059/create-qr-code-in-vector-image/60638350#60638350 |
| 36 | |
| 37 | const int width = matrix.width(); |
| 38 | const int height = matrix.height(); |
| 39 | std::ostringstream out; |
| 40 | |
| 41 | out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 42 | << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 " << width << " " << height |
| 43 | << "\" stroke=\"none\">\n" |
| 44 | << "<path d=\""; |
| 45 | |
| 46 | for (int y = 0; y < height; ++y) |
| 47 | for (int x = 0; x < width; ++x) |
| 48 | if (matrix.get(x, y)) |
| 49 | out << "M" << x << "," << y << "h1v1h-1z"; |
| 50 | |
| 51 | out << "\"/>\n</svg>"; |
| 52 | |
| 53 | return out.str(); |
| 54 | } |
| 55 | |
| 56 | BitMatrix ParseBitMatrix(const std::string& str, char one, bool expectSpace) |
| 57 | { |