<commit_before>#include "../PdfRenderer.h"
#include "../../PdfReader/PdfReader.h"
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/common/Directory.h"
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
#include "../../DesktopEditor/xmlsec/src/include/CertificateCommon.h"

void TEST(CPdfRenderer* pRenderer)
{
    // ТЕСТОВЫЕ КОММАНДЫ
    pRenderer->PathCommandStart();
    pRenderer->PathCommandMoveTo(10, 10);
    pRenderer->PathCommandLineTo(20, 20);
    pRenderer->PathCommandCurveTo(70, 30, 30, 20, 50, 50);
    pRenderer->PathCommandClose();
    pRenderer->put_BrushColor1(0xFF0000);
    pRenderer->put_PenColor(0x0000FF);
    pRenderer->put_PenSize(1);
    pRenderer->DrawPath(c_nStroke | c_nWindingFillMode);
    pRenderer->PathCommandEnd();
}

void TEST2(CPdfRenderer* pRenderer)
{
    pRenderer->OnlineWordToPdf(NSFile::GetProcessDirectory() + L"/../example/pdf.bin", L"", true);
}

void TEST3(CPdfRenderer* pRenderer)
{
    pRenderer->OnlineWordToPdfFromBinary(NSFile::GetProcessDirectory() + L"/../example1/1/pdf.bin", L"", true);
}

int main()
{
    CApplicationFontsWorker oWorker;
    oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
    oWorker.m_bIsNeedThumbnails = false;

    if (!NSDirectory::Exists(oWorker.m_sDirectory))
        NSDirectory::CreateDirectory(oWorker.m_sDirectory);

    NSFonts::IApplicationFonts* pApplicationFonts = oWorker.Check();

    CPdfRenderer pdfWriter(pApplicationFonts);
    pdfWriter.SetTempFolder(NSFile::GetProcessDirectory() + L"/wtemp");

    PdfReader::CPdfReader* pReader = new PdfReader::CPdfReader(pApplicationFonts);
    pReader->SetTempDirectory(NSFile::GetProcessDirectory() + L"/rtemp");

    // PDFDoc монополизирует доступ к файлу для чтения и не отпускает пока не деструкнится.
    // Для дозаписи файл нужно прочитать в память для ридера, а доступ к файлу отдать вритеру.
    std::wstring sSrcFile = NSFile::GetProcessDirectory() + L"/test.pdf";
    std::wstring sDstFile = NSFile::GetProcessDirectory() + L"/test2.pdf";

    if (NSFile::CFileBinary::Exists(sDstFile))
        NSFile::CFileBinary::Remove(sDstFile);

    std::wstring sPassword;
    bool bResult = pReader->LoadFromFile(sSrcFile);
    if (!bResult)
    {
        sPassword = L"<PASSWORD>";
        pReader->LoadFromFile(sSrcFile, L"", sPassword, sPassword);
        bResult = pReader->GetError() == 0;
    }

    double dPageDpiX, dPageDpiY;
    double dWidth, dHeight;
    pReader->GetPageInfo(0, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);

    dWidth  *= 25.4 / dPageDpiX;
    dHeight *= 25.4 / dPageDpiY;

    ICertificate* pCertificate = NULL;
    if (true)
    {
        std::wstring sCertificateFile = NSFile::GetProcessDirectory() + L"/test.pfx";
        std::wstring sPrivateKeyFile = L"";
        std::string sCertificateFilePassword = "<PASSWORD>";
        std::string sPrivateFilePassword = "";

        pCertificate = NSCertificate::FromFiles(sPrivateKeyFile, sPrivateFilePassword, sCertificateFile, sCertificateFilePassword);
    }

    if (false && bResult)
    {
        pdfWriter.SetPassword(L"<PASSWORD>");
        pdfWriter.NewPage();
        pdfWriter.BeginCommand(c_nPageType);
        pdfWriter.put_Width(dWidth);
        pdfWriter.put_Height(dHeight);
        pReader->DrawPageOnRenderer(&pdfWriter, 0, NULL);<commit_msg>test not CID Font in pdf<commit_after>#include "../PdfRenderer.h"
#include "../../PdfReader/PdfReader.h"
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/common/Directory.h"
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
#include "../../DesktopEditor/xmlsec/src/include/CertificateCommon.h"

void TEST(CPdfRenderer* pRenderer)
{
    // ТЕСТОВЫЕ КОММАНДЫ
    pRenderer->PathCommandStart();
    pRenderer->PathCommandMoveTo(10, 10);
    pRenderer->PathCommandLineTo(20, 20);
    pRenderer->PathCommandCurveTo(70, 30, 30, 20, 50, 50);
    pRenderer->PathCommandClose();
    pRenderer->put_BrushColor1(0xFF0000);
    pRenderer->put_PenColor(0x0000FF);
    pRenderer->put_PenSize(1);
    pRenderer->DrawPath(c_nStroke | c_nWindingFillMode);
    pRenderer->PathCommandEnd();
}

void TEST2(CPdfRenderer* pRenderer)
{
    pRenderer->OnlineWordToPdf(NSFile::GetProcessDirectory() + L"/../example/pdf.bin", L"", true);
}

void TEST3(CPdfRenderer* pRenderer)
{
    pRenderer->OnlineWordToPdfFromBinary(NSFile::GetProcessDirectory() + L"/../example1/1/pdf.bin", L"", true);
}

int main()
{
    CApplicationFontsWorker oWorker;
    oWorker.m_sDirectory = NSFile::GetProcessDirectory() + L"/fonts_cache";
    oWorker.m_bIsNeedThumbnails = false;

    if (!NSDirectory::Exists(oWorker.m_sDirectory))
        NSDirectory::CreateDirectory(oWorker.m_sDirectory);

    NSFonts::IApplicationFonts* pApplicationFonts = oWorker.Check();

    CPdfRenderer pdfWriter(pApplicationFonts);
    pdfWriter.SetTempFolder(NSFile::GetProcessDirectory() + L"/wtemp");

    PdfReader::CPdfReader* pReader = new PdfReader::CPdfReader(pApplicationFonts);
    pReader->SetTempDirectory(NSFile::GetProcessDirectory() + L"/rtemp");

    // PDFDoc монополизирует доступ к файлу для чтения и не отпускает пока не деструкнится.
    // Для дозаписи файл нужно прочитать в память для ридера, а доступ к файлу отдать вритеру.
    std::wstring sSrcFile = NSFile::GetProcessDirectory() + L"/test.pdf";
    std::wstring sDstFile = NSFile::GetProcessDirectory() + L"/test2.pdf";

    if (NSFile::CFileBinary::Exists(sDstFile))
        NSFile::CFileBinary::Remove(sDstFile);

    std::wstring sPassword;
    bool bResult = pReader->LoadFromFile(sSrcFile);
    if (!bResult)
    {
        sPassword = L"<PASSWORD>";
        pReader->LoadFromFile(sSrcFile, L"", sPassword, sPassword);
        bResult = pReader->GetError() == 0;
    }

    double dPageDpiX, dPageDpiY;
    double dWidth, dHeight;
    pReader->GetPageInfo(0, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);

    dWidth  *= 25.4 / dPageDpiX;
    dHeight *= 25.4 / dPageDpiY;

    ICertificate* pCertificate = NULL;
    if (true)
    {
        std::wstring sCertificateFile = NSFile::GetProcessDirectory() + L"/test.pfx";
        std::wstring sPrivateKeyFile = L"";
        std::string sCertificateFilePassword = "<PASSWORD>";
        std::string sPrivateFilePassword = "";

        pCertificate = NSCertificate::FromFiles(sPrivateKeyFile, sPrivateFilePassword, sCertificateFile, sCertificateFilePassword);
    }

    if (false)
    {
        pReader->ConvertToRaster(0, NSFile::GetProcessDirectory() + L"/res.png", 4, dWidth * dPageDpiX / 25.4, dHeight * dPageDpiX / 25.4, true, pReader->GetFontManager());
        RELEASEOBJECT(pReader);
        RELEASEINTERFACE(pApplicationFonts);
        RELEASEOBJECT(pCertificate);
        return 0;
    }

    if (false && bResult)
    {
        pdfWriter.SetPassword(L"<PASSWORD>");
        pdfWriter.NewPage();
        pdfWriter.BeginCommand(c_nPageType);
        pdfWriter.put_Width(dWidth);
        pdfWriter.put_Height(dHeight);
        pReader->DrawPageOnRenderer(&pdfWriter, 0, NULL);
{'fraction_non_alphanumeric': 0.13915765509391007, 'fraction_numerical': 0.014371087080250427, 'mean_word_length': 4.017130620985011, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3674490', 'n_tokens_mistral': 2473, 'n_tokens_neox': 2395, 'n_words': 381}