svg-path-parser.h revision 684a5fa4464dc8650d34718e955869846b34bb3f
/**
* \file
* \brief parse SVG path specifications
*
* Copyright 2007 MenTaLguY <mental@rydia.net>
* Copyright 2007 Aaron Spike <aaron@ekips.org>
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
*/
#ifndef LIB2GEOM_SEEN_SVG_PATH_PARSER_H
#define LIB2GEOM_SEEN_SVG_PATH_PARSER_H
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <vector>
/** @brief Read SVG path data and feed it to a PathSink
*
* This class provides an interface to an SVG path data parser written in Ragel.
* It supports parsing the path data either at once or block-by-block.
* Use the parse() functions to parse complete data and the feed() and finish()
* functions to parse partial data.
*
* The parser will call the appropriate methods on the PathSink supplied
* at construction. To store the path in memory as a PathVector, pass
* a PathBuilder. You can also use one of the freestanding helper functions
* if you don't need to parse data block-by-block.
*
* @ingroup Paths
*/
~SVGPathParser();
/** @brief Reset internal state.
* Discards the internal state associated with partially parsed data,
* letting you start from scratch. Note that any partial data written
* to the path sink is not affected - you need to clear it yourself. */
void reset();
/** @brief Parse a C-style string.
* The path sink is flushed and the internal state is reset after this call.
* Note that the state is not reset before this method, so you can use it to
* process the last block of partial data.
* @param str String to parse
* @param len Length of string or -1 if null-terminated */
/** @brief Parse an STL string. */
/** @brief Parse a part of path data stored in a C-style string.
* This method does not reset internal state, so it can be called multiple
* times to parse successive blocks of a longer SVG path data string.
* To finish parsing, call finish() after the final block or call parse()
* with the last block of data.
* @param str String to parse
* @param len Length of string or -1 if null-terminated */
/** @brief Parse a part of path data stored in an STL string. */
/** @brief Finalize parsing.
* After the last block of data was submitted with feed(), call this method
* to finalize parsing, flush the path sink and reset internal state.
* You should not call this after parse(). */
void finish();
/** @brief Set the threshold for considering the closing segment degenerate.
* When the current point was reached by a relative command, is closer
* to the initial point of the path than the specified threshold
* and a 'z' is encountered, the last segment will be adjusted instead so that
* the closing segment has exactly zero length. This is useful when reading
* SVG 1.1 paths that have non-linear final segments written in relative
* coordinates, which always suffer from some loss of precision. SVG 2
* allows alternate placement of 'z' which does not have this problem. */
bool _absolute;
int cs;
bool _pop_flag();
Point _pop_point();
void _closePath();
void _pushCurve(Curve *c);
};
/** @brief Feed SVG path data to the specified sink
* @ingroup Paths */
/** @brief Feed SVG path data to the specified sink
* @ingroup Paths */
}
/** Feed SVG path data from a C stream to the specified sink
* @ingroup Paths */
/** @brief Create path vector from SVG path data stored in a C string
* @ingroup Paths */
return ret;
}
/** @brief Create path vector from a C stream with SVG path data
* @ingroup Paths */
return ret;
}
/** @brief Create path vector from SVG path data stored in a file
* @ingroup Paths */
return out;
}
} // end namespace Geom
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :