| 1 |
// SPDX-FileCopyrightText: 2016 Dominik Seichter <[email protected]> |
| 2 |
// SPDX-FileCopyrightText: 2021 Francesco Pretto <[email protected]> |
| 3 |
// SPDX-License-Identifier: MIT-0 |
| 4 |
|
| 5 |
#include <PdfTest.h> |
| 6 |
|
| 7 |
using namespace std; |
| 8 |
using namespace PoDoFo; |
| 9 |
|
| 10 |
TEST_CASE("TestDevices") |
| 11 |
{ |
| 12 |
string_view testString = "Hello World Buffer!"; |
| 13 |
charbuff buffer1; |
| 14 |
|
| 15 |
// large appends |
| 16 |
StringStreamDevice streamLarge(buffer1); |
| 17 |
for (unsigned i = 0; i < 100; i++) |
| 18 |
streamLarge.Write(testString); |
| 19 |
|
| 20 |
if (buffer1.size() != testString.size() * 100) |
| 21 |
FAIL(utls::Format("Buffer1 size is wrong after 100 attaches: {}", buffer1.size())); |
| 22 |
} |
| 23 |
|
| 24 |
TEST_CASE("TestSaveIncremental") |
| 25 |
{ |
| 26 |
PdfMemDocument doc; |
| 27 |
auto testPath = TestUtils::GetTestOutputFilePath("TestSaveIncremental.pdf"); |
| 28 |
doc.GetPages().CreatePage(PdfPageSize::A4); |
| 29 |
doc.Save(testPath); |
| 30 |
doc.Load(testPath); |
| 31 |
doc.SaveUpdate(testPath); |
| 32 |
doc.Load(testPath); |
| 33 |
} |
| 34 |
|
| 35 |
TEST_CASE("TestStreamedDocument") |
| 36 |
{ |
| 37 |
auto testPath = TestUtils::GetTestOutputFilePath("TestStreamedDocument.pdf"); |
| 38 |
PdfStreamedDocument document(testPath); |
| 39 |
auto& page = document.GetPages().CreatePage(PdfPageSize::A4); |
| 40 |
// NOTE: use a TTC version of the LiberationSans format to test TTC extraction |
| 41 |
auto& font = document.GetFonts().GetOrCreateFont(TestUtils::GetTestInputFilePath("FontsTTC", "LiberationSans.ttc"), 2); |
| 42 |
PdfPainter painter; |
| 43 |
painter.SetCanvas(page); |
| 44 |
painter.TextState.SetFont(font, 18); |
| 45 |
painter.DrawText("Hello World!", 56.69, page.GetRect().Height - 56.69); |
| 46 |
painter.FinishDrawing(); |
| 47 |
} |