Commit 9b476f36 authored by krit@webkit.org's avatar krit@webkit.org

2010-08-07 Dirk Schulze <krit@webkit.org>

        Reviewed by Nikolas Zimmermann.

        Come up with a more efficient way to represent Path segments
        https://bugs.webkit.org/show_bug.cgi?id=41159

        Introduce SVGPathByteStream as a fast and efficient way to organize the synchronization
        of Path, SVG path data string and SVGPathSegList in normalized and unaltered modes.
        Extended SVGPathParserFactory to accept SVGPathByteStreams as input source and to create
        a SVGPathByteStream from a SVG path data string.

        Doesn't affect any tests.

        * Android.mk:
        * CMakeLists.txt:
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * svg/SVGAllInOne.cpp:
        * svg/SVGPathByteStream.h: Added.
        (WebCore::):
        (WebCore::SVGPathByteStream::create):
        (WebCore::SVGPathByteStream::data):
        (WebCore::SVGPathByteStream::begin):
        (WebCore::SVGPathByteStream::end):
        (WebCore::SVGPathByteStream::append):
        (WebCore::SVGPathByteStream::clear):
        (WebCore::SVGPathByteStream::isEmpty):
        (WebCore::SVGPathByteStream::SVGPathByteStream):
        * svg/SVGPathByteStreamBuilder.cpp: Added.
        (WebCore::SVGPathByteStreamBuilder::SVGPathByteStreamBuilder):
        (WebCore::SVGPathByteStreamBuilder::moveTo):
        (WebCore::SVGPathByteStreamBuilder::lineTo):
        (WebCore::SVGPathByteStreamBuilder::lineToHorizontal):
        (WebCore::SVGPathByteStreamBuilder::lineToVertical):
        (WebCore::SVGPathByteStreamBuilder::curveToCubic):
        (WebCore::SVGPathByteStreamBuilder::curveToCubicSmooth):
        (WebCore::SVGPathByteStreamBuilder::curveToQuadratic):
        (WebCore::SVGPathByteStreamBuilder::curveToQuadraticSmooth):
        (WebCore::SVGPathByteStreamBuilder::arcTo):
        (WebCore::SVGPathByteStreamBuilder::closePath):
        * svg/SVGPathByteStreamBuilder.h: Added.
        (WebCore::SVGPathByteStreamBuilder::setCurrentByteStream):
        (WebCore::SVGPathByteStreamBuilder::writeType):
        (WebCore::SVGPathByteStreamBuilder::writeFlag):
        (WebCore::SVGPathByteStreamBuilder::writeFloat):
        (WebCore::SVGPathByteStreamBuilder::writeFloatPoint):
        (WebCore::SVGPathByteStreamBuilder::writeSegmentType):
        * svg/SVGPathByteStreamSource.cpp: Added.
        (WebCore::SVGPathByteStreamSource::SVGPathByteStreamSource):
        (WebCore::SVGPathByteStreamSource::~SVGPathByteStreamSource):
        (WebCore::SVGPathByteStreamSource::hasMoreData):
        (WebCore::SVGPathByteStreamSource::parseFloat):
        (WebCore::SVGPathByteStreamSource::parseFlag):
        (WebCore::SVGPathByteStreamSource::parseSVGSegmentType):
        (WebCore::SVGPathByteStreamSource::nextCommand):
        * svg/SVGPathByteStreamSource.h: Added.
        (WebCore::SVGPathByteStreamSource::create):
        (WebCore::SVGPathByteStreamSource::readType):
        (WebCore::SVGPathByteStreamSource::readFlag):
        (WebCore::SVGPathByteStreamSource::readFloat):
        (WebCore::SVGPathByteStreamSource::readSVGSegmentType):
        (WebCore::SVGPathByteStreamSource::readFloatPoint):
        * svg/SVGPathParserFactory.cpp:
        (WebCore::globalSVGPathByteStreamBuilder):
        (WebCore::SVGPathParserFactory::buildPathFromByteStream):
        (WebCore::SVGPathParserFactory::buildSVGPathSegListFromByteStream):
        (WebCore::SVGPathParserFactory::buildSVGPathByteStreamFromString):
        * svg/SVGPathParserFactory.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64909 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c41bff82
......@@ -871,6 +871,8 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
svg/SVGPaint.cpp \
svg/SVGParserUtilities.cpp \
svg/SVGPathBuilder.cpp \
svg/SVGPathByteStreamBuilder.cpp \
svg/SVGPathByteStreamSource.cpp \
svg/SVGPathElement.cpp \
svg/SVGPathParser.cpp \
svg/SVGPathParserFactory.cpp \
......
......@@ -1679,6 +1679,8 @@ IF (ENABLE_SVG)
svg/SVGPaint.cpp
svg/SVGParserUtilities.cpp
svg/SVGPathBuilder.cpp
svg/SVGPathByteStreamBuilder.cpp
svg/SVGPathByteStreamSource.cpp
svg/SVGPathElement.cpp
svg/SVGPathParser.cpp
svg/SVGPathParserFactory.cpp
......
2010-08-07 Dirk Schulze <krit@webkit.org>
Reviewed by Nikolas Zimmermann.
Come up with a more efficient way to represent Path segments
https://bugs.webkit.org/show_bug.cgi?id=41159
Introduce SVGPathByteStream as a fast and efficient way to organize the synchronization
of Path, SVG path data string and SVGPathSegList in normalized and unaltered modes.
Extended SVGPathParserFactory to accept SVGPathByteStreams as input source and to create
a SVGPathByteStream from a SVG path data string.
Doesn't affect any tests.
* Android.mk:
* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* svg/SVGAllInOne.cpp:
* svg/SVGPathByteStream.h: Added.
(WebCore::):
(WebCore::SVGPathByteStream::create):
(WebCore::SVGPathByteStream::data):
(WebCore::SVGPathByteStream::begin):
(WebCore::SVGPathByteStream::end):
(WebCore::SVGPathByteStream::append):
(WebCore::SVGPathByteStream::clear):
(WebCore::SVGPathByteStream::isEmpty):
(WebCore::SVGPathByteStream::SVGPathByteStream):
* svg/SVGPathByteStreamBuilder.cpp: Added.
(WebCore::SVGPathByteStreamBuilder::SVGPathByteStreamBuilder):
(WebCore::SVGPathByteStreamBuilder::moveTo):
(WebCore::SVGPathByteStreamBuilder::lineTo):
(WebCore::SVGPathByteStreamBuilder::lineToHorizontal):
(WebCore::SVGPathByteStreamBuilder::lineToVertical):
(WebCore::SVGPathByteStreamBuilder::curveToCubic):
(WebCore::SVGPathByteStreamBuilder::curveToCubicSmooth):
(WebCore::SVGPathByteStreamBuilder::curveToQuadratic):
(WebCore::SVGPathByteStreamBuilder::curveToQuadraticSmooth):
(WebCore::SVGPathByteStreamBuilder::arcTo):
(WebCore::SVGPathByteStreamBuilder::closePath):
* svg/SVGPathByteStreamBuilder.h: Added.
(WebCore::SVGPathByteStreamBuilder::setCurrentByteStream):
(WebCore::SVGPathByteStreamBuilder::writeType):
(WebCore::SVGPathByteStreamBuilder::writeFlag):
(WebCore::SVGPathByteStreamBuilder::writeFloat):
(WebCore::SVGPathByteStreamBuilder::writeFloatPoint):
(WebCore::SVGPathByteStreamBuilder::writeSegmentType):
* svg/SVGPathByteStreamSource.cpp: Added.
(WebCore::SVGPathByteStreamSource::SVGPathByteStreamSource):
(WebCore::SVGPathByteStreamSource::~SVGPathByteStreamSource):
(WebCore::SVGPathByteStreamSource::hasMoreData):
(WebCore::SVGPathByteStreamSource::parseFloat):
(WebCore::SVGPathByteStreamSource::parseFlag):
(WebCore::SVGPathByteStreamSource::parseSVGSegmentType):
(WebCore::SVGPathByteStreamSource::nextCommand):
* svg/SVGPathByteStreamSource.h: Added.
(WebCore::SVGPathByteStreamSource::create):
(WebCore::SVGPathByteStreamSource::readType):
(WebCore::SVGPathByteStreamSource::readFlag):
(WebCore::SVGPathByteStreamSource::readFloat):
(WebCore::SVGPathByteStreamSource::readSVGSegmentType):
(WebCore::SVGPathByteStreamSource::readFloatPoint):
* svg/SVGPathParserFactory.cpp:
(WebCore::globalSVGPathByteStreamBuilder):
(WebCore::SVGPathParserFactory::buildPathFromByteStream):
(WebCore::SVGPathParserFactory::buildSVGPathSegListFromByteStream):
(WebCore::SVGPathParserFactory::buildSVGPathByteStreamFromString):
* svg/SVGPathParserFactory.h:
2010-08-07 Dirk Schulze <krit@webkit.org>
Not reviewed. Sort XCode project file.
......@@ -4074,6 +4074,11 @@ webcore_sources += \
WebCore/svg/SVGParserUtilities.h \
WebCore/svg/SVGPathBuilder.cpp \
WebCore/svg/SVGPathBuilder.h \
WebCore/svg/SVGPathByteStream.h \
WebCore/svg/SVGPathByteStreamBuilder.cpp \
WebCore/svg/SVGPathByteStreamBuilder.h \
WebCore/svg/SVGPathByteStreamSource.cpp \
WebCore/svg/SVGPathByteStreamSource.h \
WebCore/svg/SVGPathConsumer.h \
WebCore/svg/SVGPathElement.cpp \
WebCore/svg/SVGPathElement.h \
......
......@@ -3828,6 +3828,11 @@
'svg/SVGParserUtilities.h',
'svg/SVGPathBuilder.cpp',
'svg/SVGPathBuilder.h',
'svg/SVGPathByteStream.h',
'svg/SVGPathByteStreamBuilder.cpp',
'svg/SVGPathByteStreamBuilder.h',
'svg/SVGPathByteStreamSource.cpp',
'svg/SVGPathByteStreamSource.h',
'svg/SVGPathConsumer.h',
'svg/SVGPathElement.cpp',
'svg/SVGPathElement.h',
......
......@@ -2853,6 +2853,8 @@ contains(DEFINES, ENABLE_SVG=1) {
svg/SVGPaint.cpp \
svg/SVGParserUtilities.cpp \
svg/SVGPathBuilder.cpp \
svg/SVGPathByteStreamBuilder.cpp \
svg/SVGPathByteStreamSource.cpp \
svg/SVGPathElement.cpp \
svg/SVGPathParser.cpp \
svg/SVGPathParserFactory.cpp \
......
......@@ -49440,6 +49440,18 @@
RelativePath="..\svg\SVGPathBuilder.h"
>
</File>
<File
RelativePath="..\svg\SVGPathByteStream.h"
>
</File>
<File
RelativePath="..\svg\SVGPathByteStreamBuilder.h"
>
</File>
<File
RelativePath="..\svg\SVGPathByteStreamSource.h"
>
</File>
<File
RelativePath="..\svg\SVGPathConsumer.h"
>
......@@ -1432,6 +1432,11 @@
81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; };
82B658981189E39200E052A1 /* InspectorCSSStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 82B658971189E39200E052A1 /* InspectorCSSStore.h */; settings = {ATTRIBUTES = (Private, ); }; };
82B6589A1189E47600E052A1 /* InspectorCSSStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82B658991189E47600E052A1 /* InspectorCSSStore.cpp */; };
8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2A4120D92D000141F8F /* SVGPathByteStream.h */; };
8419D2A8120D92D000141F8F /* SVGPathByteStreamBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2A5120D92D000141F8F /* SVGPathByteStreamBuilder.cpp */; };
8419D2A9120D92D000141F8F /* SVGPathByteStreamBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2A6120D92D000141F8F /* SVGPathByteStreamBuilder.h */; };
8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */; };
8419D2AD120D92FC00141F8F /* SVGPathByteStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */; };
841FDC261178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */; };
841FDC271178C9BE00F8AC9B /* RenderSVGResourceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */; };
84224183107E77F400766A87 /* JSSVGFEMorphologyElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */; };
......@@ -7261,6 +7266,11 @@
81BE20A811F4B66F00915DFA /* JSIDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBCursor.h; sourceTree = "<group>"; };
82B658971189E39200E052A1 /* InspectorCSSStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSStore.h; sourceTree = "<group>"; };
82B658991189E47600E052A1 /* InspectorCSSStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSStore.cpp; sourceTree = "<group>"; };
8419D2A4120D92D000141F8F /* SVGPathByteStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStream.h; sourceTree = "<group>"; };
8419D2A5120D92D000141F8F /* SVGPathByteStreamBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathByteStreamBuilder.cpp; sourceTree = "<group>"; };
8419D2A6120D92D000141F8F /* SVGPathByteStreamBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStreamBuilder.h; sourceTree = "<group>"; };
8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathByteStreamSource.cpp; sourceTree = "<group>"; };
8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStreamSource.h; sourceTree = "<group>"; };
841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGResourceFilter.cpp; sourceTree = "<group>"; };
841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGResourceFilter.h; sourceTree = "<group>"; };
84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGFEMorphologyElement.cpp; sourceTree = "<group>"; };
......@@ -15301,6 +15311,11 @@
B22278C10D00BF200071B782 /* SVGParserUtilities.h */,
8476C9E711DF6A2900555B02 /* SVGPathBuilder.cpp */,
8476C9E811DF6A2900555B02 /* SVGPathBuilder.h */,
8419D2A4120D92D000141F8F /* SVGPathByteStream.h */,
8419D2A5120D92D000141F8F /* SVGPathByteStreamBuilder.cpp */,
8419D2A6120D92D000141F8F /* SVGPathByteStreamBuilder.h */,
8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */,
8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */,
8476C9E911DF6A2900555B02 /* SVGPathConsumer.h */,
B22278C20D00BF200071B782 /* SVGPathElement.cpp */,
B22278C30D00BF200071B782 /* SVGPathElement.h */,
......@@ -19810,6 +19825,9 @@
B2227A540D00BF220071B782 /* SVGPaint.h in Headers */,
B2227A570D00BF220071B782 /* SVGParserUtilities.h in Headers */,
8476C9EB11DF6A2900555B02 /* SVGPathBuilder.h in Headers */,
8419D2A7120D92D000141F8F /* SVGPathByteStream.h in Headers */,
8419D2A9120D92D000141F8F /* SVGPathByteStreamBuilder.h in Headers */,
8419D2AD120D92FC00141F8F /* SVGPathByteStreamSource.h in Headers */,
8476C9EC11DF6A2900555B02 /* SVGPathConsumer.h in Headers */,
B2227A590D00BF220071B782 /* SVGPathElement.h in Headers */,
8476C9F011DF6A5800555B02 /* SVGPathParser.h in Headers */,
......@@ -22273,6 +22291,8 @@
B2227A530D00BF220071B782 /* SVGPaint.cpp in Sources */,
B2227A560D00BF220071B782 /* SVGParserUtilities.cpp in Sources */,
8476C9EA11DF6A2900555B02 /* SVGPathBuilder.cpp in Sources */,
8419D2A8120D92D000141F8F /* SVGPathByteStreamBuilder.cpp in Sources */,
8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */,
B2227A580D00BF220071B782 /* SVGPathElement.cpp in Sources */,
8476C9EF11DF6A5800555B02 /* SVGPathParser.cpp in Sources */,
84300BD3120C9A710021954A /* SVGPathParserFactory.cpp in Sources */,
......@@ -108,6 +108,8 @@
#include "SVGPaint.cpp"
#include "SVGParserUtilities.cpp"
#include "SVGPathBuilder.cpp"
#include "SVGPathByteStreamBuilder.cpp"
#include "SVGPathByteStreamSource.cpp"
#include "SVGPathElement.cpp"
#include "SVGPathParser.cpp"
#include "SVGPathParserFactory.cpp"
......
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* 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.
*/
#ifndef SVGPathByteStream_h
#define SVGPathByteStream_h
#if ENABLE(SVG)
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
// Type definitions for the byte stream data
typedef union {
bool value;
unsigned char bytes[sizeof(bool)];
} BoolByte;
typedef union {
float value;
unsigned char bytes[sizeof(float)];
} FloatByte;
typedef union {
unsigned short value;
unsigned char bytes[sizeof(unsigned short)];
} UnsignedShortByte;
class SVGPathByteStream : public Noncopyable {
public:
static PassOwnPtr<SVGPathByteStream> create()
{
return adoptPtr(new SVGPathByteStream);
}
typedef Vector<unsigned char> Data;
typedef Data::const_iterator DataIterator;
DataIterator begin() { return m_data.begin(); }
DataIterator end() { return m_data.end(); }
void append(unsigned char byte) { m_data.append(byte); }
void clear() { m_data.clear(); }
bool isEmpty() const { return !m_data.size(); }
private:
SVGPathByteStream() { }
Data m_data;
};
} // namespace WebCore
#endif // ENABLE(SVG)
#endif // SVGPathByteStream_h
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* 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"
#if ENABLE(SVG)
#include "SVGPathByteStreamBuilder.h"
#include "SVGPathParser.h"
#include "SVGPathSeg.h"
#include "SVGPathStringSource.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
SVGPathByteStreamBuilder::SVGPathByteStreamBuilder()
: m_byteStream(0)
{
}
void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : PathSegMoveToAbs);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs);
writeFloat(x);
}
void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs);
writeFloat(y);
}
void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs);
writeFloatPoint(point1);
writeFloatPoint(point2);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs);
writeFloatPoint(point2);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs);
writeFloatPoint(point1);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
{
ASSERT(m_byteStream);
writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs);
writeFloat(r1);
writeFloat(r2);
writeFloat(angle);
writeFlag(largeArcFlag);
writeFlag(sweepFlag);
writeFloatPoint(targetPoint);
}
void SVGPathByteStreamBuilder::closePath()
{
ASSERT(m_byteStream);
writeSegmentType(PathSegClosePath);
}
} // namespace WebCore
#endif // ENABLE(SVG)
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* 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.
*/
#ifndef SVGPathByteStreamBuilder_h
#define SVGPathByteStreamBuilder_h
#if ENABLE(SVG)
#include "FloatPoint.h"
#include "PlatformString.h"
#include "SVGPathByteStream.h"
#include "SVGPathConsumer.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
class SVGPathByteStreamBuilder : public SVGPathConsumer {
public:
SVGPathByteStreamBuilder();
void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; }
private:
// Used in UnalteredParsing/NormalizedParsing modes.
virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode);
virtual void lineTo(const FloatPoint&, PathCoordinateMode);
virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode);
virtual void closePath();
private:
// Only used in UnalteredParsing mode.
virtual void lineToHorizontal(float, PathCoordinateMode);
virtual void lineToVertical(float, PathCoordinateMode);
virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode);
virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode);
virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode);
virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode);
private:
template<typename ByteType>
void writeType(const ByteType& type)
{
size_t typeSize = sizeof(ByteType);
for (size_t i = 0; i < typeSize; ++i)
m_byteStream->append(type.bytes[i]);
}
void writeFlag(bool value)
{
BoolByte data;
data.value = value;
writeType(data);
}
void writeFloat(float value)
{
FloatByte data;
data.value = value;
writeType(data);
}
void writeFloatPoint(const FloatPoint& point)
{
writeFloat(point.x());
writeFloat(point.y());
}
void writeSegmentType(unsigned short value)
{
UnsignedShortByte data;
data.value = value;
writeType(data);
}
SVGPathByteStream* m_byteStream;
};
} // namespace WebCore
#endif // ENABLE(SVG)
#endif // SVGPathByteStreamBuilder_h
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* 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"
#if ENABLE(SVG)
#include "SVGPathByteStreamSource.h"
#include "PlatformString.h"
namespace WebCore {
SVGPathByteStreamSource::SVGPathByteStreamSource(SVGPathByteStream* stream)
: m_stream(stream)
, m_streamCurrent(stream->begin())
, m_streamEnd(stream->end())
{
ASSERT(stream);
}
SVGPathByteStreamSource::~SVGPathByteStreamSource()
{
}
bool SVGPathByteStreamSource::hasMoreData() const
{
return (m_streamCurrent < m_streamEnd);
}
bool SVGPathByteStreamSource::parseFloat(float& result)
{
result = readFloat();
return true;
}
bool SVGPathByteStreamSource::parseFlag(bool& result)
{
result = readFlag();
return true;
}
bool SVGPathByteStreamSource::parseSVGSegmentType(SVGPathSegType& pathSegType)
{
pathSegType = static_cast<SVGPathSegType>(readSVGSegmentType());
return true;
}
SVGPathSegType SVGPathByteStreamSource::nextCommand(SVGPathSegType)
{
return static_cast<SVGPathSegType>(readSVGSegmentType());
}
}
#endif // ENABLE(SVG)
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* 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.
*/
#ifndef SVGPathByteStreamSource_h
#define SVGPathByteStreamSource_h
#if ENABLE(SVG)
#include "FloatPoint.h"
#include "SVGPathByteStream.h"
#include "SVGPathSource.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
class SVGPathByteStreamSource : public SVGPathSource {
public:
static PassOwnPtr<SVGPathByteStreamSource> create(SVGPathByteStream* stream)
{
return adoptPtr(new SVGPathByteStreamSource(stream));
}
virtual ~SVGPathByteStreamSource();
virtual bool hasMoreData() const;
virtual bool moveToNextToken();
virtual bool parseFloat(float& result);
virtual bool parseFlag(bool& result);
virtual bool parseSVGSegmentType(SVGPathSegType&);
virtual SVGPathSegType nextCommand(SVGPathSegType);
private:
SVGPathByteStreamSource(SVGPathByteStream*);
template<typename DataType, typename ByteType>
DataType readType()
{
ByteType data;
size_t typeSize = sizeof(ByteType);
for (size_t i = 0; i < typeSize; ++i) {
ASSERT(m_streamCurrent < m_streamEnd);
data.bytes[i] = *m_streamCurrent;
++m_streamCurrent;
}
return data.value;
}
bool readFlag()
{
return readType<bool, BoolByte>();
}
float readFloat()
{