KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pdf_test_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef QA_UTILS_PDF_TEST_UTILS_H
21#define QA_UTILS_PDF_TEST_UTILS_H
22
23#include <memory>
24#include <string>
25
26#include <wx/string.h>
27
28#include <gal/color4d.h>
29#include <render_settings.h>
31#include <font/stroke_font.h>
32
36wxString MakeTempPdfPath( const wxString& aPrefix );
37
42{
43public:
45
46 KIGFX::COLOR4D GetColor( const KIGFX::VIEW_ITEM*, int ) const override;
47 const KIGFX::COLOR4D& GetBackgroundColor() const override { return m_background; }
48 void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) override { m_background = aColor; }
49 const KIGFX::COLOR4D& GetGridColor() override { return m_grid; }
50 const KIGFX::COLOR4D& GetCursorColor() override { return m_cursor; }
51
52private:
56};
57
66TEXT_ATTRIBUTES BuildTextAttributes( int aSizeIu = 3000, int aStrokeWidth = 300,
67 bool aBold = false, bool aItalic = false );
68
72std::unique_ptr<KIFONT::STROKE_FONT> LoadStrokeFontUnique();
73
80bool ReadPdfWithDecompressedStreams( const wxString& aPdfPath, std::string& aOutBuffer );
81
85int CountOccurrences( const std::string& aHaystack, const std::string& aNeedle );
86
90inline bool PdfContains( const std::string& aBuffer, const char* aNeedle )
91{
92 return aBuffer.find( aNeedle ) != std::string::npos;
93}
94
105bool RasterizePdfCountDark( const wxString& aPdfPath, int aDpi, int aNearWhiteThresh,
106 long& aOutDarkPixels );
107
111void MaybeRemoveFile( const wxString& aPath, const wxString& aEnvVar = wxT( "KICAD_KEEP_TEST_PDF" ) );
112
113#endif // QA_UTILS_PDF_TEST_UTILS_H
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
KIGFX::COLOR4D m_cursor
void SetBackgroundColor(const KIGFX::COLOR4D &aColor) override
Set the background color.
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
KIGFX::COLOR4D m_background
const KIGFX::COLOR4D & GetCursorColor() override
Return current cursor color settings.
const KIGFX::COLOR4D & GetGridColor() override
Return current grid color settings.
KIGFX::COLOR4D GetColor(const KIGFX::VIEW_ITEM *, int) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
int CountOccurrences(const std::string &aHaystack, const std::string &aNeedle)
Count occurrences of a substring in a string (overlapping allowed).
bool PdfContains(const std::string &aBuffer, const char *aNeedle)
Convenience contains check.
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 buf...
std::unique_ptr< KIFONT::STROKE_FONT > LoadStrokeFontUnique()
Load the default stroke font and return a unique_ptr for RAII deletion.
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.
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.
wxString MakeTempPdfPath(const wxString &aPrefix)
Make a temporary file path with .pdf extension using a given prefix.
void MaybeRemoveFile(const wxString &aPath, const wxString &aEnvVar=wxT("KICAD_KEEP_TEST_PDF"))
Remove a file unless the given environment variable is set (defaults to KICAD_KEEP_TEST_PDF).