1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/*
* Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "SVGTransformable.h"
#include "AffineTransform.h"
#include "FloatConversion.h"
#include "SVGElement.h"
#include "SVGNames.h"
#include "SVGParserUtilities.h"
#include "SVGTransform.h"
#include <wtf/text/StringParsingBuffer.h>
#include <wtf/text/StringView.h>
namespace WebCore {
SVGTransformable::~SVGTransformable() = default;
template<typename CharacterType> static constexpr std::array<CharacterType, 5> skewXDesc { 's', 'k', 'e', 'w', 'X' };
template<typename CharacterType> static constexpr std::array<CharacterType, 5> skewYDesc { 's', 'k', 'e', 'w', 'Y' };
template<typename CharacterType> static constexpr std::array<CharacterType, 5> scaleDesc { 's', 'c', 'a', 'l', 'e' };
template<typename CharacterType> static constexpr std::array<CharacterType, 9> translateDesc { 't', 'r', 'a', 'n', 's', 'l', 'a', 't', 'e' };
template<typename CharacterType> static constexpr std::array<CharacterType, 6> rotateDesc { 'r', 'o', 't', 'a', 't', 'e' };
template<typename CharacterType> static constexpr std::array<CharacterType, 6> matrixDesc { 'm', 'a', 't', 'r', 'i', 'x' };
template<typename CharacterType> static std::optional<SVGTransformValue::SVGTransformType> parseTransformTypeGeneric(StringParsingBuffer<CharacterType>& buffer)
{
if (buffer.atEnd())
return std::nullopt;
if (*buffer == 's') {
if (skipCharactersExactly(buffer, std::span { skewXDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_SKEWX;
if (skipCharactersExactly(buffer, std::span { skewYDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_SKEWY;
if (skipCharactersExactly(buffer, std::span { scaleDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_SCALE;
return std::nullopt;
}
if (skipCharactersExactly(buffer, std::span { translateDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_TRANSLATE;
if (skipCharactersExactly(buffer, std::span { rotateDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_ROTATE;
if (skipCharactersExactly(buffer, std::span { matrixDesc<CharacterType> }))
return SVGTransformValue::SVG_TRANSFORM_MATRIX;
return std::nullopt;
}
std::optional<SVGTransformValue::SVGTransformType> SVGTransformable::parseTransformType(StringView string)
{
return readCharactersForParsing(string, [](auto buffer) {
return parseTransformType(buffer);
});
}
std::optional<SVGTransformValue::SVGTransformType> SVGTransformable::parseTransformType(StringParsingBuffer<LChar>& buffer)
{
return parseTransformTypeGeneric(buffer);
}
std::optional<SVGTransformValue::SVGTransformType> SVGTransformable::parseTransformType(StringParsingBuffer<char16_t>& buffer)
{
return parseTransformTypeGeneric(buffer);
}
}
|