MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / TEST

Function TEST

source/MRTest/MRPdfTests.cpp:11–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9{
10
11TEST( MRMesh, Pdf )
12{
13 UniqueTemporaryFolder pathFolder;
14 Pdf pdfTest;
15 pdfTest.addText( "Test Title", true );
16 pdfTest.addText( "Test text"
17 "\nstring 1"
18 "\nstring 2" );
19
20 constexpr float scaleFactor = 17.f / 6.f; // ~2.8(3)
21 constexpr float pageWidth = 595.f;
22 constexpr float borderFieldLeft = 20 * scaleFactor;
23 constexpr float borderFieldRight = pageWidth - 10 * scaleFactor;
24 constexpr float pageWorkWidth = borderFieldRight - borderFieldLeft;
25
26 const int colorMapSizeX = int( pageWorkWidth );
27 const int colorMapSizeY = int( 10 * scaleFactor );
28 std::vector<Color> pixels( colorMapSizeX * colorMapSizeY );
29 Color colorLeft = Color::blue();
30 Color colorRight = Color::red();
31 for ( int i = 0; i < colorMapSizeX; ++i )
32 {
33 for ( int j = 0; j < colorMapSizeY; ++j )
34 {
35 const float c = float( i ) / colorMapSizeX;
36 pixels[i + j * colorMapSizeX] = lerp( colorLeft, colorRight, c );
37 }
38 }
39
40 auto colorMapPath = pathFolder / std::filesystem::path( "color_map.png" );
41 auto res = ImageSave::toAnySupportedFormat( { pixels, Vector2i( colorMapSizeX, colorMapSizeY ) }, colorMapPath );
42
43 pdfTest.addImageFromFile( colorMapPath, { .size = {-1, 0}, .caption = "test image", .uniformScale = Pdf::ImageParams::UniformScale::FromWidth } );
44 pdfTest.saveToFile( pathFolder / std::filesystem::path( "test.pdf" ) );
45}
46
47} //namespace MR
48

Callers

nothing calls this directly

Calls 5

lerpFunction · 0.85
addImageFromFileMethod · 0.80
toAnySupportedFormatFunction · 0.50
addTextMethod · 0.45
saveToFileMethod · 0.45

Tested by

no test coverage detected