diff options
Diffstat (limited to 'svg-flatten/src')
-rw-r--r-- | svg-flatten/src/out_flattener.cpp | 4 | ||||
-rw-r--r-- | svg-flatten/src/svg_color.cpp | 7 | ||||
-rw-r--r-- | svg-flatten/src/svg_doc.cpp | 56 |
3 files changed, 36 insertions, 31 deletions
diff --git a/svg-flatten/src/out_flattener.cpp b/svg-flatten/src/out_flattener.cpp index 0eae854..600584b 100644 --- a/svg-flatten/src/out_flattener.cpp +++ b/svg-flatten/src/out_flattener.cpp @@ -139,6 +139,8 @@ Flattener &Flattener::operator<<(GerberPolarityToken pol) { if (pol == GRB_POL_DARK) { render_out_clear_polys(); } + + m_sink << pol; } return *this; @@ -147,8 +149,6 @@ Flattener &Flattener::operator<<(GerberPolarityToken pol) { Flattener &Flattener::operator<<(const LayerNameToken &layer_name) { flush_polys_to_sink(); m_sink << layer_name; - cerr << "Flattener forwarding layer name to sink: \"" << layer_name.m_name << "\"" << endl; - return *this; } diff --git a/svg-flatten/src/svg_color.cpp b/svg-flatten/src/svg_color.cpp index 637a65f..87aae3a 100644 --- a/svg-flatten/src/svg_color.cpp +++ b/svg-flatten/src/svg_color.cpp @@ -41,14 +41,17 @@ enum gerber_color gerbolyze::svg_color_to_gerber(string color, string opacity, e } if (color.empty()) { + //cerr << " -> default" << endl; return default_val; } if (color == "none") { + //cerr << " -> none" << endl; return GRB_NONE; } if (color.rfind("url(#", 0) != string::npos) { + //cerr << " -> pattern" << endl; return GRB_PATTERN_FILL; } @@ -60,16 +63,20 @@ enum gerber_color gerbolyze::svg_color_to_gerber(string color, string opacity, e alpha = rgba.a; if (alpha < 0.5f) { + //cerr << " -> none" << endl; return GRB_NONE; } if ((hsv.v >= 0.5) != rset.flip_color_interpretation) { + //cerr << " -> clear" << endl; return GRB_CLEAR; } else { + //cerr << " -> dark" << endl; return GRB_DARK; } } + //cerr << " -> dark" << endl; return GRB_DARK; } diff --git a/svg-flatten/src/svg_doc.cpp b/svg-flatten/src/svg_doc.cpp index 7ff0a11..42338e8 100644 --- a/svg-flatten/src/svg_doc.cpp +++ b/svg-flatten/src/svg_doc.cpp @@ -116,7 +116,7 @@ bool IDElementSelector::match(const pugi::xml_node &node, bool is_toplevel, bool if (is_toplevel && layers) { bool layer_match = std::find(layers->begin(), layers->end(), id) != layers->end(); if (!layer_match) { - cerr << "Rejecting layer \"" << id << "\"" << endl; + //cerr << "Rejecting layer \"" << id << "\"" << endl; return false; } } @@ -185,7 +185,6 @@ void gerbolyze::SVGDocument::export_svg_group(RenderContext &ctx, const pugi::xm if (name == "g") { if (ctx.root()) { /* Treat top-level groups as "layers" like inkscape does. */ - cerr << "Forwarding layer name to sink: \"" << node.attribute("id").value() << "\"" << endl; LayerNameToken tok { node.attribute("id").value() }; elem_ctx.sink() << tok; } @@ -258,34 +257,34 @@ void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml bool has_fill = fill_color; bool has_stroke = stroke_color && stroke_width > 0.0; - /* Skip filling for transparent fills. In outline mode, skip filling if a stroke is also set to avoid double lines. - */ - if (has_fill && !(ctx.settings().outline_mode && has_stroke)) { - /* In outline mode, identify drills before applying clip */ - if (ctx.settings().outline_mode && fill_color != GRB_PATTERN_FILL) { - /* Polsby-Popper test */ - for (auto &p : fill_paths) { - Polygon_i geom_poly(p.size()); - for (size_t i=0; i<p.size(); i++) { - geom_poly[i] = { p[i].X, p[i].Y }; - } + /* In outline mode, identify drills before applying clip */ + if (ctx.settings().outline_mode && has_fill && fill_color != GRB_PATTERN_FILL) { + /* Polsby-Popper test */ + for (auto &p : fill_paths) { + Polygon_i geom_poly(p.size()); + for (size_t i=0; i<p.size(); i++) { + geom_poly[i] = { p[i].X, p[i].Y }; + } - double area = nopencv::polygon_area(geom_poly); - double polsby_popper = 4*M_PI * area / pow(nopencv::polygon_perimeter(geom_poly), 2); - polsby_popper = fabs(fabs(polsby_popper) - 1.0); - if (polsby_popper < ctx.settings().drill_test_polsby_popper_tolerance) { - d2p centroid = nopencv::polygon_centroid(geom_poly); - centroid[0] /= clipper_scale; - centroid[1] /= clipper_scale; - double diameter = sqrt(4*fabs(area)/M_PI) / clipper_scale; - diameter = ctx.mat().doc2phys_dist(diameter); /* FIXME is this correct w.r.t. PolygonScaler? */ - diameter = round(diameter * 1000.0) / 1000.0; /* Round to micrometer precsion; FIXME: make configurable */ - ctx.sink() << ApertureToken(diameter) << DrillToken(ctx.mat().doc2phys(centroid)); - } + double area = nopencv::polygon_area(geom_poly); + double polsby_popper = 4*M_PI * area / pow(nopencv::polygon_perimeter(geom_poly), 2); + polsby_popper = fabs(fabs(polsby_popper) - 1.0); + if (polsby_popper < ctx.settings().drill_test_polsby_popper_tolerance) { + d2p centroid = nopencv::polygon_centroid(geom_poly); + centroid[0] /= clipper_scale; + centroid[1] /= clipper_scale; + double diameter = sqrt(4*fabs(area)/M_PI) / clipper_scale; + diameter = ctx.mat().doc2phys_dist(diameter); /* FIXME is this correct w.r.t. PolygonScaler? */ + diameter = round(diameter * 1000.0) / 1000.0; /* Round to micrometer precsion; FIXME: make configurable */ + ctx.sink() << ApertureToken(diameter) << DrillToken(ctx.mat().doc2phys(centroid)); } - return; } + return; + } + /* Skip filling for transparent fills. In outline mode, skip filling if a stroke is also set to avoid double lines. + */ + if (has_fill && !(ctx.settings().outline_mode && has_stroke)) { /* Clip paths. Consider all paths closed for filling. */ if (!ctx.clip().empty()) { Clipper c; @@ -332,7 +331,7 @@ void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml if (ctx.settings().outline_mode && !out.empty()) out.push_back(out[0]); - ctx.sink() << ApertureToken() << (fill_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << out; + ctx.sink() << (fill_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << ApertureToken() << out; } } } @@ -418,8 +417,7 @@ void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml } else if (!ctx.settings().outline_mode) { Paths s_polys; dehole_polytree(ptree, s_polys); - - ctx.sink() << ApertureToken() << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << s_polys; + ctx.sink() << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << ApertureToken() << s_polys; } } } |