<commit_before>#include <QFile>
#include <QTextStream>
#include <qtreports/converters/utils/replacer.hpp>
#include <qtreports/converters/convertertohtml.hpp>
#include <cmath>

namespace qtreports {
    namespace detail {

        ConverterToHTML::ConverterToHTML( const ReportPtr & report ) :
            m_report( report ) {}

        ConverterToHTML::~ConverterToHTML() {}

        bool    ConverterToHTML::convert() {
            return createHTML();
        }

        bool    ConverterToHTML::convert( const QString & path ) {
            if( !convert() ) {
                return false;
            }

            QFile file( path );
            file.open(
                QIODevice::OpenModeFlag::WriteOnly |
                QIODevice::OpenModeFlag::Text |
                QIODevice::OpenModeFlag::Truncate
            );

            if( !file.isOpen() ) {
                m_lastError = "The file can not be opened";
                return false;
            }

            QTextStream stream( &file );
            stream.setCodec( "UTF-8" );
            stream << m_html;

            return true;
        }

        bool    ConverterToHTML::createHTML() {
            if(m_report.isNull())
            {
                m_lastError = "Report is empty";
                return false;
            }

            int pageHeight = m_report->getHeight();
            int pageWidth = m_report->getWidth();
            int freePageSpace = pageHeight;

            auto& styles = m_report->getStyles();

            m_html += QString("<!DOCTYPE html>\n"
                      "<html>\n"
                      " <head>\n"
                      "  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n"
                      "  <title>Report</title>\n"
                      "  <style>\n"

                      "   div, .detail, .title, .band {\n"
                      "   position: relative;\n"
                      "   width: 100%;\n"
                      "   overflow: hidden;\n"
                      "   }\n"

                      "   @media print {\n"
                      "   .page {page-break-after: always;}\n"
                      "   }\n"

                      "   .page {\n"
                      "   width: %1px;\n"
                      "   height: %2px;\n" 
                      "   }\n"

                      "   .statictext, .textfield, .shape{\n"
                      "   position: absolute;\n"
                      "   background-color: transparent;\n"
                      "   }\n")
                    .arg(pageWidth).arg(pageHeight);

            for (auto i = styles.begin(); i != styles.end(); ++i) {
                auto* style = (*i).data();
                m_html += QString(
                    "   .%1 {\n"
                    "   font-family: %2 !important;\n"
                    "   font-size: %3pt !important;\n"
                    "   color: %4 !important;\n"
                    "   font-style: %5 !important;\n"
                    "   font-weight: %6 !important;\n"
                    "   text-decoration: %7 %8 !important;\n"
                    "   }\n"
                )
                .arg("style-" + style->getName())                       // 1 name
                .arg(style->getFontName())                              // 2 font-family
                .arg(style->getFontSize())                              // 3 font-size
                .arg(style->getFontColor().name())                      // 4 color
                .arg(style->isItalic() ? "italic" : "")                 // 5 font-style
                .arg(style->isBold() ? "800" : "300")                   // 6 font-weight
                .arg(style->isUnderline() ? "underline" : "")           // 7 text-docration
                .arg(style->isStrikeThrough() ? "line-through" : "");   // 8 text-decoration
            }
            QString defaultStyleName = m_report->getDefaultStyle().isNull() ? "" : "style-" + m_report->getDefaultStyle()->getName();

            m_html += QString("   .statictext {\n"
                      "   font-family: %3;\n"
                      "   font-size: %4pt;\n"
                      "   color: %5;\n"
                      "   font-style: %6;\n"
                      "   font-weight: %7;\n"
                      "   }\n"

                      "   .textfield {\n"
                      "   font-family: %8;\n"
                      "   font-size: %9pt;\n"
                      "   color: %10;\n"
                      "   font-style: %11;\n"
                      "   font-weight: %12;\n"
                      "   }\n"

                      "  </style>\n"
                      " </head>\n"
                      " <body>\n")
                    .arg("Verdana").arg("12").arg("black").arg("normal").arg("normal")
                    .arg("Verdana").arg("12").arg("black").arg("normal").arg("normal");

            m_html += "  <div class='page'>\n";

            auto title = m_report->getTitle();
            if(!title.isNull())
            {
                m_html += "   <div class='title'>\n";

                detail::Replacer replacer;<commit_msg>Fixed font handler for statictext and textfield<commit_after>#include <QFile>
#include <QTextStream>
#include <qtreports/converters/utils/replacer.hpp>
#include <qtreports/converters/convertertohtml.hpp>
#include <cmath>

namespace qtreports {
    namespace detail {

        ConverterToHTML::ConverterToHTML( const ReportPtr & report ) :
            m_report( report ) {}

        ConverterToHTML::~ConverterToHTML() {}

        bool    ConverterToHTML::convert() {
            return createHTML();
        }

        bool    ConverterToHTML::convert( const QString & path ) {
            if( !convert() ) {
                return false;
            }

            QFile file( path );
            file.open(
                QIODevice::OpenModeFlag::WriteOnly |
                QIODevice::OpenModeFlag::Text |
                QIODevice::OpenModeFlag::Truncate
            );

            if( !file.isOpen() ) {
                m_lastError = "The file can not be opened";
                return false;
            }

            QTextStream stream( &file );
            stream.setCodec( "UTF-8" );
            stream << m_html;

            return true;
        }

        bool    ConverterToHTML::createHTML() {
            if(m_report.isNull())
            {
                m_lastError = "Report is empty";
                return false;
            }

            int pageHeight = m_report->getHeight();
            int pageWidth = m_report->getWidth();
            int freePageSpace = pageHeight;

            auto& styles = m_report->getStyles();

            m_html += QString("<!DOCTYPE html>\n"
                      "<html>\n"
                      " <head>\n"
                      "  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n"
                      "  <title>Report</title>\n"
                      "  <style>\n"

                      "   div, .detail, .title, .band {\n"
                      "   position: relative;\n"
                      "   width: 100%;\n"
                      "   overflow: hidden;\n"
                      "   }\n"

                      "   @media print {\n"
                      "   .page {page-break-after: always;}\n"
                      "   }\n"

                      "   .page {\n"
                      "   width: %1px;\n"
                      "   height: %2px;\n" 
                      "   }\n"

                      "   .statictext, .textfield, .shape{\n"
                      "   position: absolute;\n"
                      "   background-color: transparent;\n"
                      "   }\n")
                    .arg(pageWidth).arg(pageHeight);

			Style *mainStyle = nullptr;
            for (auto i = styles.begin(); i != styles.end(); ++i) {
                auto* style = (*i).data();
				mainStyle = style;
                m_html += QString(
                    "   .%1 {\n"
                    "   font-family: %2 !important;\n"
                    "   font-size: %3pt !important;\n"
                    "   color: %4 !important;\n"
                    "   font-style: %5 !important;\n"
                    "   font-weight: %6 !important;\n"
                    "   text-decoration: %7 %8 !important;\n"
                    "   }\n"
                )
                .arg("style-" + style->getName())                       // 1 name
                .arg(style->getFontName())                              // 2 font-family
                .arg(style->getFontSize())                              // 3 font-size
                .arg(style->getFontColor().name())                      // 4 color
                .arg(style->isItalic() ? "italic" : "")                 // 5 font-style
                .arg(style->isBold() ? "800" : "300")                   // 6 font-weight
                .arg(style->isUnderline() ? "underline" : "")           // 7 text-docration
                .arg(style->isStrikeThrough() ? "line-through" : "");   // 8 text-decoration
            }
            QString defaultStyleName = m_report->getDefaultStyle().isNull() ? "" : "style-" + m_report->getDefaultStyle()->getName();

            if(mainStyle == nullptr) {
                m_html += QString("   .statictext {\n"
                          "   font-family: %3;\n"
                          "   font-size: %4pt;\n"
                          "   color: %5;\n"
                          "   font-style: %6;\n"
                          "   font-weight: %7;\n"
                          "   }\n"

                          "   .textfield {\n"
                          "   font-family: %8;\n"
                          "   font-size: %9pt;\n"
                          "   color: %10;\n"
                          "   font-style: %11;\n"
                          "   font-weight: %12;\n"
                          "   }\n"

                          "  </style>\n"
                          " </head>\n"
                          " <body>\n")
                        .arg("Verdana").arg("12").arg("black").arg("normal").arg("normal")
                        .arg("Verdana").arg("12").arg("black").arg("normal").arg("normal");
            }
            else {
                m_html += QString("   .statictext {\n"
                          "   font-family: %3;\n"
                          "   font-size: %4pt;\n"
                          "   color: %5;\n"
                          "   font-style: %6;\n"
                          "   font-weight: %7;\n"
                          "   }\n"

                          "   .textfield {\n"
                          "   font-family: %8;\n"
                          "   font-size: %9pt;\n"
                          "   color: %10;\n"
                          "   font-style: %11;\n"
                          "   font-weight: %12;\n"
                          "   }\n"

                          "  </style>\n"
                          " </head>\n"
                          " <body>\n")
                        .arg("'" + mainStyle->getFontName() + "'").arg(mainStyle->getFontSize()).arg(mainStyle->getFontColor().name())
                        .arg(mainStyle->isItalic() ? "italic" : "normal").arg(mainStyle->isBold() ? "800" : "300")
                        .arg(mainStyle->getFontName()).arg(mainStyle->getFontSize()).arg(mainStyle->getFontColor().name())
                        .arg(mainStyle->isItalic() ? "italic" : "normal").arg(mainStyle->isBold() ? "800" : "300");
            }

            m_html += "  <div class='page'>\n";

            auto title = m_report->getTitle();
            if(!title.isNull())
            {
                m_html += "   <div class='title'>\n";

                detail::Replacer replacer;
{'fraction_non_alphanumeric': 0.14260264675941636, 'fraction_numerical': 0.00992534781133356, 'mean_word_length': 0.9770249874224384, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1349', 'n_tokens_mistral': 3354, 'n_tokens_neox': 3092, 'n_words': 542}