Skip to main content.
Find on this site:

Me as a baby.Mark A. Taff
Location: Home Code Viewer
  1.  /** @file
  2.   * This file contains the regexs for parsing the transform attribute of
  3.   * an SVG file using DOM.
  4.   *
  5.   * @see: http://www.w3.org/TR/SVG/coords.html#TransformAttribute
  6.   */
  7.  
  8.  /***************************************************************************
  9.   * Copyright (C) 2007 Mark A. Taff <kde@marktaff.com> *
  10.   * *
  11.   * This program is free software; you can redistribute it and/or modify *
  12.   * it under the terms of the GNU Library General Public License *
  13.   * version 2 as published by the Free Software Foundation *
  14.   * *
  15.   * This program is distributed in the hope that it will be useful, *
  16.   * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  17.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  18.   * GNU Library General Public License for more details. *
  19.   * *
  20.   * You should have received a copy of the GNU Library General Public *
  21.   * License along with this program; if not, write to the *
  22.   * Free Software Foundation, Inc., *
  23.   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  24.   ***************************************************************************/
  25.  
  26.  #ifndef _KGAMESVGDOCUMENT_P_H_
  27.  #define _KGAMESVGDOCUMENT_P_H_
  28.  
  29.  
  30.  /**
  31.  * @brief A regex that matches a single whitespace
  32.  */
  33.  static const QString WSP = QString("\\s");
  34.  
  35.  /**
  36.  * @brief A regex that matches zero or more whitespace
  37.  */
  38.  static const QString WSP_ASTERISK = QString(WSP + '*');
  39.  
  40.  /**
  41.  * @brief A regex that matches a comma
  42.  */
  43.  static const char COMMA = ',';
  44.  
  45.  /**
  46.  * @brief A regex that matches a comma or whitespace
  47.  */
  48.  static const QString COMMA_WSP = QString("(?:(?:" + WSP + '+' + COMMA + '?' +
  49.   WSP + "*)|(?:" + COMMA + WSP + "*))");
  50.  
  51.  /**
  52.  * @brief A regex that matches a number
  53.  */
  54.  static const QString NUMBER = QString("(?:(?:[-|\\+]?\\d+(?:\\.)*\\d*(?:e)?[-|\\+]?\\d*)|(?:[-|\\+]?(?:\\.)+\\d*(?:e)?[-|\\+]?\\d*))");
  55.  // Do not wrap the above line!
  56.  
  57.  /**
  58.  * @brief A regex that matches opening parenthesis
  59.  */
  60.  static const QString OPEN_PARENS = QString("\\(");
  61.  
  62.  /**
  63.  * @brief A regex that matches closing parenthesis
  64.  */
  65.  static const QString CLOSE_PARENS = QString("\\)");
  66.  
  67.  /**
  68.  * @brief A regex that matches a matrix transform
  69.  */
  70.  static const QString MATRIX = QString("(matrix)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  71.   '(' + NUMBER + ')' + COMMA_WSP +
  72.   '(' + NUMBER + ')' + COMMA_WSP +
  73.   '(' + NUMBER + ')' + COMMA_WSP +
  74.   '(' + NUMBER + ')' + COMMA_WSP +
  75.   '(' + NUMBER + ')' + COMMA_WSP +
  76.   '(' + NUMBER + ')' + WSP_ASTERISK + CLOSE_PARENS);
  77.  
  78.  /**
  79.  * @brief A regex that matches a translate transform
  80.  */
  81.  static const QString TRANSLATE = QString("(translate)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  82.   '(' + NUMBER + ')' +
  83.   "(?:" + COMMA_WSP + '(' + NUMBER + ')' + ")?" + WSP_ASTERISK + CLOSE_PARENS);
  84.  
  85.  /**
  86.  * @brief A regex that matches scale transform
  87.  */
  88.  static const QString SCALE = QString("(scale)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  89.   '(' + NUMBER + ')' +
  90.   "(?:" + COMMA_WSP + '(' + NUMBER + ')' + ")?" + WSP_ASTERISK + CLOSE_PARENS);
  91.  
  92.  /**
  93.  * @brief A regex that matches rotate transform
  94.  */
  95.  static const QString ROTATE = QString("(rotate)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  96.   '(' + NUMBER + ')' + "(?:" + COMMA_WSP +
  97.   '(' + NUMBER + ')' + COMMA_WSP +
  98.   '(' + NUMBER + ')' + ")?" + WSP_ASTERISK + CLOSE_PARENS);
  99.  
  100.  /**
  101.  * @brief A regex that matches skewX transform
  102.  */
  103.  static const QString SKEW_X = QString("(skewX)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  104.   '(' + NUMBER + ')' + WSP_ASTERISK + CLOSE_PARENS);
  105.  
  106.  /**
  107.  * @brief A regex that matches skewY transform
  108.  */
  109.  static const QString SKEW_Y = QString("(skewY)" + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK +
  110.   '(' + NUMBER + ')' + WSP_ASTERISK + CLOSE_PARENS);
  111.  
  112.  /**
  113.  * @brief A regex that matches any single transform
  114.  */
  115.  static const QString TRANSFORM = QString("(?:" + MATRIX + "|" + TRANSLATE + "|" + SCALE + "|" +
  116.   ROTATE + "|" + SKEW_X + "|" + SKEW_Y + ")");
  117.  
  118.  /**
  119.  * @brief A regex that matches the entire transform attribute
  120.  */
  121.  static const QString TRANSFORMS = QString("(?:" + TRANSFORM + "|" + "(?:" + TRANSFORM +
  122.   COMMA_WSP + "+)*" + TRANSFORM + ")");
  123.  
  124.  #endif // _KGAMESVGDOCUMENT_P_H_
CC-GNU GPL
Photos & software licensed under the CC-GNU GPL
unless otherwise noted in the JPEG comments field or source code.