KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pdf_test_utils.cpp File Reference
#include <algorithm>
#include <qa_utils/file_utils.h>
#include <qa_utils/pdf_test_utils.h>
#include <gal/color4d.h>
#include <wx/filefn.h>
#include <wx/ffile.h>
#include <wx/utils.h>
#include <wx/image.h>
#include <wx/imagpng.h>
#include <zlib.h>

Go to the source code of this file.

Functions

TEXT_ATTRIBUTES BuildTextAttributes (int aSizeIu, int aStrokeWidth, bool aBold, bool aItalic)
 Build a commonly used set of text attributes for plotting text in tests.
 
std::unique_ptr< KIFONT::STROKE_FONTLoadStrokeFontUnique ()
 Load the default stroke font and return a unique_ptr for RAII deletion.
 
static void append_decompressed_streams (std::string &aBuffer)
 
bool ReadPdfWithDecompressedStreams (const wxString &aPdfPath, std::string &aOutBuffer)
 Read a PDF file and append best-effort decompressed contents of any Flate streams to the returned buffer to make text searches easier.
 
int CountOccurrences (const std::string &aHaystack, const std::string &aNeedle)
 Count occurrences of a substring in a string (overlapping allowed).
 
bool RasterizePdfCountDark (const wxString &aPdfPath, int aDpi, int aNearWhiteThresh, long &aOutDarkPixels)
 Rasterize a PDF page to PNG using pdftoppm if available and count non-near-white pixels.
 

Function Documentation

◆ append_decompressed_streams()

static void append_decompressed_streams ( std::string & aBuffer)
static

Definition at line 66 of file pdf_test_utils.cpp.

Referenced by ReadPdfWithDecompressedStreams().

◆ BuildTextAttributes()

TEXT_ATTRIBUTES BuildTextAttributes ( int aSizeIu = 3000,
int aStrokeWidth = 300,
bool aBold = false,
bool aItalic = false )

◆ CountOccurrences()

int CountOccurrences ( const std::string & aHaystack,
const std::string & aNeedle )

Count occurrences of a substring in a string (overlapping allowed).

Definition at line 159 of file pdf_test_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ LoadStrokeFontUnique()

◆ RasterizePdfCountDark()

bool RasterizePdfCountDark ( const wxString & aPdfPath,
int aDpi,
int aNearWhiteThresh,
long & aOutDarkPixels )

Rasterize a PDF page to PNG using pdftoppm if available and count non-near-white pixels.

Parameters
aPdfPathInput PDF path.
aDpiRasterization DPI.
aNearWhiteThreshThreshold for each RGB channel to consider white (e.g., 240).
aOutDarkPixelsOutput: number of pixels darker than threshold.
Returns
true if rasterization succeeded and dark pixel count is valid. False if tool not available or conversion failed.

Definition at line 179 of file pdf_test_utils.cpp.

References KI_TEST::SCOPED_TEMP_DIR::ChildPathStr().

Referenced by BOOST_AUTO_TEST_CASE().

◆ ReadPdfWithDecompressedStreams()

bool ReadPdfWithDecompressedStreams ( const wxString & aPdfPath,
std::string & aOutBuffer )

Read a PDF file and append best-effort decompressed contents of any Flate streams to the returned buffer to make text searches easier.

Returns
true on success; false if file cannot be opened or read.

Definition at line 141 of file pdf_test_utils.cpp.

References append_decompressed_streams().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().