bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream* stream, float length, unsigned& pathSeg) { ASSERT(stream); if (stream->isEmpty()) return false; PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength); SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(traversalState, length); SVGPathByteStreamSource source(stream); SVGPathParser* parser = globalSVGPathParser(&source, builder); bool ok = parser->parsePathDataFromSource(NormalizedParsing); pathSeg = builder->pathSegmentIndex(); parser->cleanup(); return ok; }
bool SVGPathParserFactory::buildSVGPathByteStreamFromString(const String& d, OwnPtr<SVGPathByteStream>& result, PathParsingMode parsingMode) { if (result) result->clear(); else result = SVGPathByteStream::create(); if (d.isEmpty()) return false; SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result.get()); OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); SVGPathParser* parser = globalSVGPathParser(source.get(), builder); bool ok = parser->parsePathDataFromSource(parsingMode); parser->cleanup(); return ok; }
bool appendSVGPathByteStreamFromSVGPathSeg(PassRefPtr<SVGPathSeg> pathSeg, SVGPathByteStream* result, PathParsingMode parsingMode) { ASSERT(result); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! ASSERT(parsingMode == UnalteredParsing); SVGPathSegList appendedItemList(PathSegUnalteredRole); appendedItemList.append(pathSeg); auto appendedByteStream = std::make_unique<SVGPathByteStream>(); SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(appendedByteStream.get()); auto source = std::make_unique<SVGPathSegListSource>(appendedItemList); SVGPathParser* parser = globalSVGPathParser(source.get(), builder); bool ok = parser->parsePathDataFromSource(parsingMode, false); parser->cleanup(); if (ok) result->append(appendedByteStream.get()); return ok; }
bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream* result, PathParsingMode parsingMode) { ASSERT(result); result->clear(); if (d.isEmpty()) return false; // The string length is typically a minor overestimate of eventual byte stream size, so it avoids us a lot of reallocs. result->reserveInitialCapacity(d.length()); SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); SVGPathParser* parser = globalSVGPathParser(source.get(), builder); bool ok = parser->parsePathDataFromSource(parsingMode); parser->cleanup(); result->shrinkToFit(); return ok; }