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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef QA_UTILS_PDF_TEST_UTILS_H
25#define QA_UTILS_PDF_TEST_UTILS_H
26
27#include <memory>
28#include <string>
29
30#include <wx/string.h>
31
32#include <gal/color4d.h>
33#include <render_settings.h>
35#include <font/stroke_font.h>
36
40wxString MakeTempPdfPath( const wxString& aPrefix );
41
46{
47public:
49
50 KIGFX::COLOR4D GetColor( const KIGFX::VIEW_ITEM*, int ) const override;
51 const KIGFX::COLOR4D& GetBackgroundColor() const override { return m_background; }
52 void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) override { m_background = aColor; }
53 const KIGFX::COLOR4D& GetGridColor() override { return m_grid; }
54 const KIGFX::COLOR4D& GetCursorColor() override { return m_cursor; }
55
56private:
60};
61
70TEXT_ATTRIBUTES BuildTextAttributes( int aSizeIu = 3000, int aStrokeWidth = 300,
71 bool aBold = false, bool aItalic = false );
72
76std::unique_ptr<KIFONT::STROKE_FONT> LoadStrokeFontUnique();
77
84bool ReadPdfWithDecompressedStreams( const wxString& aPdfPath, std::string& aOutBuffer );
85
89int CountOccurrences( const std::string& aHaystack, const std::string& aNeedle );
90
94inline bool PdfContains( const std::string& aBuffer, const char* aNeedle )
95{
96 return aBuffer.find( aNeedle ) != std::string::npos;
97}
98
109bool RasterizePdfCountDark( const wxString& aPdfPath, int aDpi, int aNearWhiteThresh,
110 long& aOutDarkPixels );
111
115void MaybeRemoveFile( const wxString& aPath, const wxString& aEnvVar = wxT( "KICAD_KEEP_TEST_PDF" ) );
116
117#endif // QA_UTILS_PDF_TEST_UTILS_H
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
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:86
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).