1
//----------------------------------------------------------------------------
2
// Anti-Grain Geometry - Version 2.3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5
// Permission to copy, use, modify, sell and distribute this software
6
// is granted provided this copyright notice appears in all copies.
7
// This software is provided "as is" without express or implied
8
// warranty, and with no claim as to its suitability for any purpose.
10
//----------------------------------------------------------------------------
11
// Contact: mcseem@antigrain.com
12
// mcseemagg@yahoo.com
13
// http://www.antigrain.com
14
//----------------------------------------------------------------------------
16
// SVG path tokenizer.
18
//----------------------------------------------------------------------------
19
#ifndef AGG_SVG_PATH_TOKENIZER_INCLUDED
20
#define AGG_SVG_PATH_TOKENIZER_INCLUDED
22
#include "agg_svg_exception.h"
28
// SVG path tokenizer.
31
// agg::svg::path_tokenizer tok;
33
// tok.set_str("M-122.304 84.285L-122.304 84.285 122.203 86.179 ");
36
// printf("command='%c' number=%f\n",
37
// tok.last_command(),
38
// tok.last_number());
41
// The tokenizer does all the routine job of parsing the SVG paths.
42
// It doesn't recognize any graphical primitives, it even doesn't know
43
// anything about pairs of coordinates (X,Y). The purpose of this class
44
// is to tokenize the numeric values and commands. SVG paths can
45
// have single numeric values for Horizontal or Vertical line_to commands
46
// as well as more than two coordinates (4 or 6) for Bezier curves
47
// depending on the semantics of the command.
48
// The behaviour is as follows:
50
// Each call to next() returns true if there's new command or new numeric
51
// value or false when the path ends. How to interpret the result
52
// depends on the sematics of the command. For example, command "C"
53
// (cubic Bezier curve) implies 6 floating point numbers preceded by this
54
// command. If the command assumes no arguments (like z or Z) the
55
// the last_number() values won't change, that is, last_number() always
56
// returns the last recognized numeric value, so does last_command().
57
//===============================================================
63
void set_path_str(const char* str);
66
double next(char cmd);
68
char last_command() const { return m_last_command; }
69
double last_number() const { return m_last_number; }
73
static void init_char_mask(char* mask, const char* char_set);
75
bool contains(const char* mask, unsigned c) const
77
return (mask[(c >> 3) & (256/8-1)] & (1 << (c & 7))) != 0;
80
bool is_command(unsigned c) const
82
return contains(m_commands_mask, c);
85
bool is_numeric(unsigned c) const
87
return contains(m_numeric_mask, c);
90
bool is_separator(unsigned c) const
92
return contains(m_separators_mask, c);
97
char m_separators_mask[256/8];
98
char m_commands_mask[256/8];
99
char m_numeric_mask[256/8];
102
double m_last_number;
105
static const char s_commands[];
106
static const char s_numeric[];
107
static const char s_separators[];
111
} //namespace mapserver