26#include <wx/filename.h>
36wxString plotFilledShape(
const COLOR4D& aColor )
38 wxFileName tempFile( wxFileName::CreateTempFileName( wxT(
"kicad_svg_plotter" ) ) );
39 tempFile.SetExt( wxT(
"svg" ) );
58 wxFFile file( tempFile.GetFullPath(), wxT(
"r" ) );
62 file.ReadAll( &content );
65 wxRemoveFile( tempFile.GetFullPath() );
72std::set<std::string> fillOpacities(
const wxString& aSvg )
74 const std::string doc = aSvg.ToStdString();
75 const std::string key =
"fill-opacity:";
76 std::set<std::string> values;
78 for(
size_t pos = doc.find( key ); pos != std::string::npos; pos = doc.find( key, pos + 1 ) )
80 size_t start = pos + key.size();
81 size_t end = doc.find_first_not_of(
"0123456789.", start );
83 values.insert( doc.substr( start,
end - start ) );
97 std::set<std::string> values = fillOpacities( plotFilledShape(
COLOR4D( 1.0, 0.0, 0.0, 0.5 ) ) );
107 std::set<std::string> values = fillOpacities( plotFilledShape(
COLOR4D( 0.0, 0.0, 1.0, 1.0 ) ) );
109 BOOST_REQUIRE_EQUAL( values.count(
"1.0000" ), 1 );
112 for(
const std::string& value : values )
119 const std::vector<std::pair<double, std::string>> cases = {
120 { 0.0,
"0.0000" }, { 0.25,
"0.2500" }, { 0.5,
"0.5000" }, { 0.75,
"0.7500" },
124 for(
const auto& [alpha,
expected] : cases )
128 std::set<std::string> values =
129 fillOpacities( plotFilledShape(
COLOR4D( 0.5, 0.5, 0.5, alpha ) ) );
134 for(
const auto& [otherAlpha, other] : cases )
136 if( other !=
expected && other !=
"1.0000" )
A color representation with 4 components: red, green, blue, alpha.
Describe the page size and margins of a paper page on which to eventually print or plot.
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)
virtual void SetColorMode(bool aColorMode)
Plot in B/W or color.
virtual void SetColor(const COLOR4D &color) override
The SetColor implementation is split with the subclasses: the PSLIKE computes the rgb values,...
virtual bool StartPlot(const wxString &aPageNumber) override
Create SVG file header.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
virtual bool EndPlot() override
@ FILLED_SHAPE
Fill with object color.
Plotting engines similar to ps (PostScript, Gerber, svg)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_AUTO_TEST_CASE(FillOpacityMatchesColorAlpha)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I