int svgTopng(char* inputFile,char* outputFile){ hmin=99999999; hmax=0; parseSVG(inputFile); createCanvas(); save(outputFile); return 0; }
void SkDrawPath::onEndElement(SkAnimateMaker& ) { if (d.size() > 0) { parseSVG(); d.reset(); fDirty = false; return; } if (fChildHasID == false) { for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++) delete *part; fParts.reset(); fDirty = false; } }
int main( int argc, char* const argv[] ) { // global setup... int result = Catch::Session().run( argc, argv ); // global clean-up... const auto path = std::string{ "/Users/razvanpascalau/dev/test.svg" }; //TODO add a logging framework instead of printf if (argc < 2) { printf("Too few parameters: we need to pass the configuration file as parameter"); return 1; } parseSVG(path, argv[1]); return result; }
SkPath& SkDrawPath::getPath() { if (fDirty == false) return fPath; if (d.size() > 0) { parseSVG(); d.reset(); } else { fPath.reset(); for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++) (*part)->add(); } fDirty = false; return fPath; }
void SVGPathElement::parseMappedAttribute(MappedAttribute* attr) { if (attr->name() == SVGNames::dAttr) { ExceptionCode ec; pathSegList()->clear(ec); if (!parseSVG(attr->value(), true)) document()->accessSVGExtensions()->reportError("Problem parsing d=\"" + attr->value() + "\""); } else if (attr->name() == SVGNames::pathLengthAttr) { m_pathLength = attr->value().toFloat(); if (m_pathLength < 0.0f) document()->accessSVGExtensions()->reportError("A negative value for path attribute <pathLength> is not allowed"); } else { if (SVGTests::parseMappedAttribute(attr)) return; if (SVGLangSpace::parseMappedAttribute(attr)) return; if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) return; SVGStyledTransformableElement::parseMappedAttribute(attr); } }
void Intersection_Tests() { int testsRun = 0; #if 0 CubicIntersection_OneOffTest(); CubicIntersection_SelfTest(); QuadraticIntersection_IntersectionFinder(); QuadraticIntersection_OneOffTest(); CubicIntersection_IntersectionFinder(); CubicUtilities_Test(); #endif SimplifyNew_Test(); CubicsToQuadratics_OneOffTest(); CubicIntersection_OneOffTest(); // CubicIntersection_OneOffTests(); #if 0 parseSVG(); #endif // QuadraticIntersection_PointFinder(); ShapeOps4x4CubicsThreaded_Test(testsRun); CubicToQuadratics_Test(); QuadraticIntersection_Test(); QuarticRoot_Test(); CubicIntersection_RandTest(); CubicsToQuadratics_RandTest(); Simplify4x4RectsThreaded_Test(testsRun); Simplify4x4QuadraticsThreaded_Test(testsRun); QuadLineIntersectThreaded_Test(testsRun); SimplifyNondegenerate4x4TrianglesThreaded_Test(testsRun); SimplifyDegenerate4x4TrianglesThreaded_Test(testsRun); Simplify4x4QuadralateralsThreaded_Test(testsRun); ShapeOps4x4RectsThreaded_Test(testsRun); SkDebugf("%s total testsRun=%d\n", __FUNCTION__, testsRun); LineQuadraticIntersection_Test(); MiniSimplify_Test(); SimplifyAngle_Test(); QuadraticBezierClip_Test(); SimplifyFindNext_Test(); SimplifyFindTop_Test(); QuadraticReduceOrder_Test(); SimplifyAddIntersectingTs_Test(); cubecode_test(1); convert_testx(); // tests are in dependency / complexity order Inline_Tests(); ConvexHull_Test(); ConvexHull_X_Test(); LineParameter_Test(); LineIntersection_Test(); LineCubicIntersection_Test(); SimplifyQuadraticPaths_Test(); SimplifyPolygonPaths_Test(); SimplifyRectangularPaths_Test(); SimplifyQuadralateralPaths_Test(); // ActiveEdge_Test(); QuadraticCoincidence_Test(); QuadraticIntersection_Test(); CubicParameterization_Test(); CubicCoincidence_Test(); CubicReduceOrder_Test(); CubicBezierClip_Test(); CubicIntersection_Test(); }
void ShapePlug::parseGroupProperties(QDomNode &DOC, double &minXCoor, double &minYCoor, double &maxXCoor, double &maxYCoor, bool &firstCheck) { QString FillCol = "White"; QString StrokeCol = "Black"; while(!DOC.isNull()) { double x1, y1, x2, y2; FPointArray PoLine; PoLine.resize(0); QDomElement pg = DOC.toElement(); QString STag = pg.tagName(); if (STag == "svg:line") { x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion; PoLine.addPoint(x1, y1); PoLine.addPoint(x1, y1); PoLine.addPoint(x2, y2); PoLine.addPoint(x2, y2); } else if (STag == "svg:rect") { x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion; static double rect[] = {0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }; for (int a = 0; a < 29; a += 4) { double xa = x2 * rect[a]; double ya = y2 * rect[a+1]; double xb = x2 * rect[a+2]; double yb = y2 * rect[a+3]; PoLine.addPoint(x1+xa, y1+ya); PoLine.addPoint(x1+xb, y1+yb); } } else if ((STag == "svg:polygon") || (STag == "svg:polyline")) { bool bFirst = true; double x = 0.0; double y = 0.0; QString points = pg.attribute( "points" ).simplified().replace(',', " "); QStringList pointList = points.split(' ', QString::SkipEmptyParts); FirstM = true; for( QStringList::Iterator it1 = pointList.begin(); it1 != pointList.end(); it1++ ) { x = ScCLocale::toDoubleC(*(it1++)); y = ScCLocale::toDoubleC(*it1); if( bFirst ) { svgMoveTo(x * Conversion, y * Conversion); bFirst = false; WasM = true; } else { svgLineTo(&PoLine, x * Conversion, y * Conversion); } } if (STag == "svg:polygon") svgClosePath(&PoLine); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } } else if (STag == "svg:circle") { x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1; y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1; x1 *= 2.0; y1 *= 2.0; static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0, 0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235, 0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0, 0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765 }; for (int a = 0; a < 29; a += 4) { double xa = x1 * rect[a]; double ya = y1 * rect[a+1]; double xb = x1 * rect[a+2]; double yb = y1 * rect[a+3]; PoLine.addPoint(x2+xa, y2+ya); PoLine.addPoint(x2+xb, y2+yb); } } else if (STag == "svg:ellipse") { x1 = ScCLocale::toDoubleC(pg.attribute("rx")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("ry")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1; y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1; x1 *= 2.0; y1 *= 2.0; static double rect[] = {1.0, 0.5, 1.0, 0.77615235,0.5, 1.0, 0.77615235, 1.0, 0.5, 1.0, 0.22385765, 1.0, 0.0, 0.5, 0.0, 0.77615235, 0.0, 0.5, 0.0, 0.22385765, 0.5, 0.0, 0.22385765, 0.0, 0.5, 0.0, 0.77615235, 0.0, 1.0, 0.5, 1.0, 0.22385765 }; for (int a = 0; a < 29; a += 4) { double xa = x1 * rect[a]; double ya = y1 * rect[a+1]; double xb = x1 * rect[a+2]; double yb = y1 * rect[a+3]; PoLine.addPoint(x2+xa, y2+ya); PoLine.addPoint(x2+xb, y2+yb); } } else if (STag == "svg:path") { parseSVG( pg.attribute( "d" ), &PoLine ); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } } else if (STag == "svg:g") { QDomNode child = DOC.firstChild(); parseGroupProperties(child, minXCoor, minYCoor, maxXCoor, maxYCoor, firstCheck); } if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } FPoint tp2(getMinClipF(&PoLine)); PoLine.translate(-tp2.x(), -tp2.y()); FPoint wh(getMaxClipF(&PoLine)); if (firstCheck) { minXCoor = tp2.x(); minYCoor = tp2.y(); maxXCoor = tp2.x() + wh.x(); maxYCoor = tp2.y() + wh.y(); firstCheck = false; } else { minXCoor = qMin(minXCoor, tp2.x()); minYCoor = qMin(minYCoor, tp2.y()); maxXCoor = qMax(maxXCoor, tp2.x() + wh.x()); maxYCoor = qMax(maxYCoor, tp2.y() + wh.y()); } DOC = DOC.nextSibling(); } }
void ShapePlug::parseGroup(QDomNode &DOC) { QString tmp = ""; QString FillCol = "White"; QString StrokeCol = "Black"; QString defFillCol = "White"; QString defStrokeCol = "Black"; QColor stroke = Qt::black; QColor fill = Qt::white; // Qt::PenStyle Dash = Qt::SolidLine; Qt::PenCapStyle LineEnd = Qt::FlatCap; Qt::PenJoinStyle LineJoin = Qt::MiterJoin; // int fillStyle = 1; double strokewidth = 0.1; // bool poly = false; while(!DOC.isNull()) { double x1, y1, x2, y2; StrokeCol = defStrokeCol; FillCol = defFillCol; stroke = Qt::black; fill = Qt::white; // fillStyle = 1; strokewidth = 1.0; // Dash = Qt::SolidLine; LineEnd = Qt::FlatCap; LineJoin = Qt::MiterJoin; FPointArray PoLine; PoLine.resize(0); QDomElement pg = DOC.toElement(); QString STag = pg.tagName(); QString style = pg.attribute( "style", "" ).simplified(); if (style.isEmpty()) style = pg.attribute( "svg:style", "" ).simplified(); QStringList substyles = style.split(';', QString::SkipEmptyParts); for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it ) { QStringList substyle = (*it).split(':', QString::SkipEmptyParts); QString command(substyle[0].trimmed()); QString params(substyle[1].trimmed()); if (command == "fill") { if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default") || (params == "inverse"))) { if (params == "nofill") FillCol = CommonStrings::None; else { fill.setNamedColor( params ); FillCol = "FromDia"+fill.name(); ScColor tmp; tmp.fromQColor(fill); tmp.setSpotColor(false); tmp.setRegistrationColor(false); QString fNam = m_Doc->PageColors.tryAddColor(FillCol, tmp); if (fNam == FillCol) importedColors.append(FillCol); FillCol = fNam; } } } else if (command == "stroke") { if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default")) || (params == "inverse")) { stroke.setNamedColor( params ); StrokeCol = "FromDia"+stroke.name(); ScColor tmp; tmp.fromQColor(stroke); tmp.setSpotColor(false); tmp.setRegistrationColor(false); QString fNam = m_Doc->PageColors.tryAddColor(StrokeCol, tmp); if (fNam == StrokeCol) importedColors.append(StrokeCol); StrokeCol = fNam; } } else if (command == "stroke-width") strokewidth = ScCLocale::toDoubleC(params); else if( command == "stroke-linejoin" ) { if( params == "miter" ) LineJoin = Qt::MiterJoin; else if( params == "round" ) LineJoin = Qt::RoundJoin; else if( params == "bevel" ) LineJoin = Qt::BevelJoin; } else if( command == "stroke-linecap" ) { if( params == "butt" ) LineEnd = Qt::FlatCap; else if( params == "round" ) LineEnd = Qt::RoundCap; else if( params == "square" ) LineEnd = Qt::SquareCap; } } if (STag == "svg:line") { x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion; PoLine.addPoint(x1, y1); PoLine.addPoint(x1, y1); PoLine.addPoint(x2, y2); PoLine.addPoint(x2, y2); int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol); m_Doc->Items->at(z)->PoLine = PoLine.copy(); finishItem(m_Doc->Items->at(z)); } else if (STag == "svg:rect") { x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion; y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion; int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol); m_Doc->Items->at(z)->setLineJoin(LineJoin); m_Doc->Items->at(z)->setLineEnd(LineEnd); finishItem(m_Doc->Items->at(z)); } else if ((STag == "svg:polygon") || (STag == "svg:polyline")) { bool bFirst = true; double x = 0.0; double y = 0.0; QString points = pg.attribute( "points" ).simplified().replace(',', " "); QStringList pointList = points.split(' ', QString::SkipEmptyParts); FirstM = true; for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ ) { x = ScCLocale::toDoubleC(*(it++)); y = ScCLocale::toDoubleC(*it); if( bFirst ) { svgMoveTo(x * Conversion, y * Conversion); bFirst = false; WasM = true; } else { svgLineTo(&PoLine, x * Conversion, y * Conversion); } } if (STag == "svg:polygon") svgClosePath(&PoLine); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } int z; if (STag == "svg:polygon") z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol); else z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol); m_Doc->Items->at(z)->PoLine = PoLine.copy(); finishItem(m_Doc->Items->at(z)); } else if ((STag == "svg:circle") || (STag == "svg:ellipse")) { x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion; x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1; y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1; x1 *= 2.0; y1 *= 2.0; int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol); m_Doc->Items->at(z)->setLineJoin(LineJoin); m_Doc->Items->at(z)->setLineEnd(LineEnd); finishItem(m_Doc->Items->at(z)); } else if (STag == "svg:path") { // poly = parseSVG( pg.attribute( "d" ), &PoLine ); if (PoLine.size() < 4) { DOC = DOC.nextSibling(); continue; } int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol); m_Doc->Items->at(z)->PoLine = PoLine.copy(); finishItem(m_Doc->Items->at(z)); } else if (STag == "svg:g") { int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseX, 1, 1, 0, CommonStrings::None, CommonStrings::None); PageItem *neu = m_Doc->Items->at(z); Elements.append(neu); if (groupStack.count() > 0) groupStack.top().append(neu); QList<PageItem*> gElements; groupStack.push(gElements); QDomNode child = DOC.firstChild(); parseGroup(child); if (gElements.count() == 0) { groupStack.pop(); Elements.removeAll(neu); groupStack.top().removeAll(neu); Selection tmpSelection(m_Doc, false); tmpSelection.addItem(neu); m_Doc->itemSelection_DeleteItem(&tmpSelection); } else { QList<PageItem*> gElem = groupStack.pop(); double minx = std::numeric_limits<double>::max(); double miny = std::numeric_limits<double>::max(); double maxx = -std::numeric_limits<double>::max(); double maxy = -std::numeric_limits<double>::max(); for (int gr = 0; gr < gElements.count(); ++gr) { PageItem* currItem = gElem.at(gr); double x1, x2, y1, y2; currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2); minx = qMin(minx, x1); miny = qMin(miny, y1); maxx = qMax(maxx, x2); maxy = qMax(maxy, y2); } double gx = minx; double gy = miny; double gw = maxx - minx; double gh = maxy - miny; neu->setXYPos(gx, gy, true); neu->setWidthHeight(gw, gh, true); neu->SetRectFrame(); neu->Clip = FlattenPath(neu->PoLine, neu->Segments); neu->setItemName( tr("Group%1").arg(m_Doc->GroupCounter)); neu->AutoName = false; neu->gXpos = neu->xPos() - gx; neu->gYpos = neu->yPos() - gy; neu->groupWidth = gw; neu->groupHeight = gh; for (int gr = 0; gr < gElem.count(); ++gr) { PageItem* currItem = gElem.at(gr); currItem->gXpos = currItem->xPos() - gx; currItem->gYpos = currItem->yPos() - gy; currItem->gWidth = gw; currItem->gHeight = gh; currItem->Parent = neu; neu->groupItemList.append(currItem); m_Doc->Items->removeAll(currItem); Elements.removeAll(currItem); } neu->setRedrawBounding(); neu->setTextFlowMode(PageItem::TextFlowDisabled); m_Doc->GroupCounter++; } } DOC = DOC.nextSibling(); } }