| 652 | using GeneratorFunc = bool (*)(QTextStream &, const QVector<CharacterProperties> &, const QVector<CharacterWidth> &, const QMap<QString, QString> &); |
| 653 | |
| 654 | bool code(QTextStream &out, const QVector<CharacterProperties> &props, const QVector<CharacterWidth> &widths, const QMap<QString, QString> &args) |
| 655 | { |
| 656 | static constexpr int DIRECT_LUT_SIZE = 256; |
| 657 | |
| 658 | Q_UNUSED(props); |
| 659 | QTextStream eout(stderr, QIODevice::WriteOnly); |
| 660 | |
| 661 | if (args.value(QStringLiteral("param")).isEmpty()) { |
| 662 | eout << QStringLiteral("Template file not specified.") << Qt::endl << Qt::endl; |
| 663 | return false; |
| 664 | } |
| 665 | QFile templateFile(args.value(QStringLiteral("param"))); |
| 666 | if (!templateFile.open(QIODevice::ReadOnly)) { |
| 667 | eout << QStringLiteral("Could not open file ") << templateFile.fileName() << ": " << templateFile.errorString(); |
| 668 | exit(1); |
| 669 | } |
| 670 | |
| 671 | const QString templateText = QString::fromUtf8(templateFile.readAll()); |
| 672 | templateFile.close(); |
| 673 | |
| 674 | Var::Map data = { |
| 675 | {QStringLiteral("gen-file-warning"), QStringLiteral("THIS IS A GENERATED FILE. DO NOT EDIT.")}, |
| 676 | {QStringLiteral("cmdline"), args.value(QStringLiteral("cmdline"))}, |
| 677 | {QStringLiteral("direct-lut"), Var::Vector(DIRECT_LUT_SIZE)}, |
| 678 | {QStringLiteral("direct-lut-size"), DIRECT_LUT_SIZE}, |
| 679 | {QStringLiteral("ranges-luts"), Var::Vector()}, |
| 680 | {QStringLiteral("ranges-lut-list"), Var::Vector()}, |
| 681 | {QStringLiteral("ranges-lut-list-size"), 0}, |
| 682 | }; |
| 683 | |
| 684 | // Fill direct-lut with widths of 0x00-0xFF |
| 685 | for (unsigned i = 0; i < DIRECT_LUT_SIZE; ++i) { |
| 686 | Q_ASSERT(widths[i].isValid()); |
| 687 | data[QStringLiteral("direct-lut")].vec[i] = int(widths[i]); |
| 688 | } |
| 689 | |
| 690 | static const QVector<CharacterWidth> widthsSortOrder = {CharacterWidth::NonPrintable, 2, CharacterWidth::Ambiguous, 0, 1}; |
| 691 | const QMap<CharacterWidth, QVector<QPair<uint, uint>>> mergedRanges = mergedRangesFromWidths(widths, widthsSortOrder, {DIRECT_LUT_SIZE, CODE_POINTS_NUM}); |
| 692 | |
| 693 | // Find last non-empty ranges lut |
| 694 | int lastWidthId = 0; |
| 695 | for (int wi = widthsSortOrder.size() - 1; wi > 0; --wi) { |
| 696 | if (mergedRanges.contains(widthsSortOrder[wi])) { |
| 697 | lastWidthId = wi; |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | // Create ranges-luts for all widths except last non-empty one and empty ones |
| 702 | for (int wi = 0; lastWidthId != 0 && wi < lastWidthId; ++wi) { |
| 703 | const CharacterWidth width = widthsSortOrder[wi]; |
| 704 | auto currentMergedRangesIt = mergedRanges.find(width); |
| 705 | if (currentMergedRangesIt == mergedRanges.end() || currentMergedRangesIt.value().isEmpty()) |
| 706 | continue; |
| 707 | const int size = mergedRanges[width].size(); |
| 708 | const QString name = QString(QStringLiteral("LUT_%1")).arg(width.toString().toUpper()); |
| 709 | data[QStringLiteral("ranges-luts")].vec.append(Var::Map{ |
| 710 | {QStringLiteral("name"), name}, |
| 711 | {QStringLiteral("ranges"), Var::Vector()}, |
nothing calls this directly
no test coverage detected