KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pdf_test_utils.cpp File Reference
#include <qa_utils/pdf_test_utils.h>
#include <gal/color4d.h>
#include <wx/filename.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

wxString MakeTempPdfPath (const wxString &aPrefix)
 Make a temporary file path with .pdf extension using a given prefix.
 
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.
 
void MaybeRemoveFile (const wxString &aPath, const wxString &aEnvVar)
 Remove a file unless the given environment variable is set (defaults to KICAD_KEEP_TEST_PDF).
 

Function Documentation

◆ append_decompressed_streams()

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

Definition at line 75 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 )

Build a commonly used set of text attributes for plotting text in tests.

Parameters
aSizeIuSize in internal units (both X and Y)
aStrokeWidthStroke width in internal units (0 for outline fonts)
aBoldBold flag
aItalicItalic flag

Definition at line 55 of file pdf_test_utils.cpp.

References ANGLE_0, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_BOTTOM, TEXT_ATTRIBUTES::m_Angle, TEXT_ATTRIBUTES::m_Bold, TEXT_ATTRIBUTES::m_Halign, TEXT_ATTRIBUTES::m_Italic, TEXT_ATTRIBUTES::m_Mirrored, TEXT_ATTRIBUTES::m_Multiline, TEXT_ATTRIBUTES::m_Size, TEXT_ATTRIBUTES::m_StrokeWidth, and TEXT_ATTRIBUTES::m_Valign.

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(), and BOOST_AUTO_TEST_CASE().

◆ CountOccurrences()

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

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

Definition at line 144 of file pdf_test_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ LoadStrokeFontUnique()

std::unique_ptr< KIFONT::STROKE_FONT > LoadStrokeFontUnique ( )

Load the default stroke font and return a unique_ptr for RAII deletion.

Definition at line 70 of file pdf_test_utils.cpp.

References KIFONT::STROKE_FONT::LoadFont().

Referenced by 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().

◆ MakeTempPdfPath()

wxString MakeTempPdfPath ( const wxString & aPrefix)

Make a temporary file path with .pdf extension using a given prefix.

Definition at line 36 of file pdf_test_utils.cpp.

Referenced by getTempPdfPath().

◆ MaybeRemoveFile()

void MaybeRemoveFile ( const wxString & aPath,
const wxString & aEnvVar )

Remove a file unless the given environment variable is set (defaults to KICAD_KEEP_TEST_PDF).

Definition at line 213 of file pdf_test_utils.cpp.

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(), and BOOST_AUTO_TEST_CASE().

◆ 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 164 of file pdf_test_utils.cpp.

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 126 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(), and BOOST_AUTO_TEST_CASE().