File indexing completed on 2024-05-12 04:06:10

0001 /*
0002     SPDX-FileCopyrightText: 2007 Mark A. Taff <kde@marktaff.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef _KGAMESVGDOCUMENT_P_H_
0008 #define _KGAMESVGDOCUMENT_P_H_
0009 
0010 /* @file
0011     This file contains the regexs for parsing the transform attribute of
0012     an SVG file using DOM.
0013 
0014     @see: http://www.w3.org/TR/SVG/coords.html#TransformAttribute
0015 */
0016 
0017 /**
0018  * @brief A regex that matches a single whitespace
0019  */
0020 static const QString WSP = QStringLiteral("\\s");
0021 
0022 /**
0023  * @brief A regex that matches zero or more whitespace
0024  */
0025 static const QString WSP_ASTERISK = WSP + QLatin1String("*");
0026 
0027 /**
0028  * @brief A regex that matches a comma
0029  */
0030 static const QLatin1Char COMMA = QLatin1Char(',');
0031 
0032 /**
0033  * @brief A regex that matches a comma or whitespace
0034  */
0035 static const QString COMMA_WSP =
0036     QLatin1String("(?:(?:") + WSP + QLatin1Char('+') + COMMA + QLatin1Char('?') + WSP + QLatin1String("*)|(?:") + COMMA + WSP + QLatin1String("*))");
0037 
0038 /**
0039  * @brief A regex that matches a number
0040  */
0041 static const QString NUMBER = QStringLiteral("(?:(?:[-|\\+]?\\d+(?:\\.)*\\d*(?:e)?[-|\\+]?\\d*)|(?:[-|\\+]?(?:\\.)+\\d*(?:e)?[-|\\+]?\\d*))");
0042 // Do not wrap the above line!
0043 
0044 /**
0045  * @brief A regex that matches opening parenthesis
0046  */
0047 static const QString OPEN_PARENS = QStringLiteral("\\(");
0048 
0049 /**
0050  * @brief A regex that matches closing parenthesis
0051  */
0052 static const QString CLOSE_PARENS = QStringLiteral("\\)");
0053 
0054 // clang-format off
0055 /**
0056  * @brief A regex that matches a matrix transform
0057  */
0058 static const QString MATRIX = QLatin1String("(matrix)" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
0059                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0060                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0061                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0062                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0063                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0064                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + WSP_ASTERISK + CLOSE_PARENS;
0065 
0066 /**
0067  * @brief A regex that matches a translate transform
0068  */
0069 static const QString TRANSLATE = QLatin1String("(translate)" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
0070                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) +
0071                 QLatin1String( "(?:" ) + COMMA_WSP + QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + QLatin1String( ")?" ) + WSP_ASTERISK + CLOSE_PARENS;
0072 
0073 /**
0074  * @brief A regex that matches scale transform
0075  */
0076 static const QString SCALE = QLatin1String("(scale)" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
0077                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) +
0078                 QLatin1String( "(?:" ) + COMMA_WSP + QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + QLatin1String( ")?" ) + WSP_ASTERISK + CLOSE_PARENS;
0079 
0080 /**
0081  * @brief A regex that matches rotate transform
0082  */
0083 static const QString ROTATE = QLatin1String("(rotate)" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
0084                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + QLatin1String( "(?:" ) + COMMA_WSP +
0085                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + COMMA_WSP +
0086                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) +  QLatin1String( ")?" ) + WSP_ASTERISK + CLOSE_PARENS;
0087 
0088 /**
0089  * @brief A regex that matches skewX transform
0090  */
0091 static const QString SKEW_X = QLatin1String( "(skewX)" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
0092                 QLatin1Char( '(' ) + NUMBER + QLatin1Char( ')' ) + WSP_ASTERISK + CLOSE_PARENS;
0093 
0094 /**
0095  * @brief A regex that matches skewY transform
0096  */
0097 static const QString SKEW_Y =
0098     QLatin1String("(skewY)") + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK + QLatin1Char('(') + NUMBER + QLatin1Char(')') + WSP_ASTERISK + CLOSE_PARENS;
0099 
0100 /**
0101  * @brief A regex that matches any single transform
0102  */
0103 static const QString TRANSFORM = QLatin1String("(?:" ) + MATRIX + QLatin1String( "|" ) + TRANSLATE + QLatin1String( "|" ) + SCALE + QLatin1String( "|" ) +
0104                 ROTATE + QLatin1String( "|" ) + SKEW_X + QLatin1String( "|" ) + SKEW_Y + QLatin1String( ")");
0105 
0106 /**
0107  * @brief A regex that matches the entire transform attribute
0108  */
0109 static const QString TRANSFORMS = QLatin1String("(?:" ) + TRANSFORM + QLatin1String( "|" ) + QLatin1String( "(?:" ) + TRANSFORM +
0110                 COMMA_WSP + QLatin1String( "+)*" ) + TRANSFORM + QLatin1String( ")");
0111 // clang-format on
0112 
0113 #endif // _KGAMESVGDOCUMENT_P_H_