1 /* 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 28 #if ENABLE(SVG) 29 #include "SVGResourceMarker.h" 30 31 #include "AffineTransform.h" 32 #include "GraphicsContext.h" 33 #include "RenderSVGViewportContainer.h" 34 #include "TextStream.h" 35 #include <wtf/StdLibExtras.h> 36 37 namespace WebCore { 38 39 SVGResourceMarker::SVGResourceMarker() 40 : SVGResource() 41 , m_angle(-1) // just like using setAutoAngle() 42 , m_renderer(0) 43 , m_useStrokeWidth(true) 44 { 45 } 46 47 SVGResourceMarker::~SVGResourceMarker() 48 { 49 } 50 51 AffineTransform SVGResourceMarker::markerTransformation(const FloatPoint& origin, float angle, float strokeWidth) const 52 { 53 ASSERT(m_renderer); 54 55 AffineTransform transform; 56 transform.translate(origin.x(), origin.y()); 57 transform.rotate(m_angle == -1 ? angle : m_angle); 58 transform = m_renderer->markerContentTransformation(transform, m_referencePoint, m_useStrokeWidth ? strokeWidth : -1); 59 return transform; 60 } 61 62 void SVGResourceMarker::draw(RenderObject::PaintInfo& paintInfo, const AffineTransform& transform) 63 { 64 if (!m_renderer) 65 return; 66 67 DEFINE_STATIC_LOCAL(HashSet<SVGResourceMarker*>, currentlyDrawingMarkers, ()); 68 69 // avoid drawing circular marker references 70 if (currentlyDrawingMarkers.contains(this)) 71 return; 72 73 currentlyDrawingMarkers.add(this); 74 ASSERT(!m_renderer->drawsContents()); 75 RenderObject::PaintInfo info(paintInfo); 76 info.context->save(); 77 applyTransformToPaintInfo(info, transform); 78 m_renderer->setDrawsContents(true); 79 m_renderer->paint(info, 0, 0); 80 m_renderer->setDrawsContents(false); 81 info.context->restore(); 82 83 currentlyDrawingMarkers.remove(this); 84 } 85 86 TextStream& SVGResourceMarker::externalRepresentation(TextStream& ts) const 87 { 88 ts << "[type=MARKER]" 89 << " [angle="; 90 91 if (angle() == -1) 92 ts << "auto" << "]"; 93 else 94 ts << angle() << "]"; 95 96 ts << " [ref x=" << m_referencePoint.x() << " y=" << m_referencePoint.y() << "]"; 97 return ts; 98 } 99 100 SVGResourceMarker* getMarkerById(Document* document, const AtomicString& id, const RenderObject* object) 101 { 102 SVGResource* resource = getResourceById(document, id, object); 103 if (resource && resource->isMarker()) 104 return static_cast<SVGResourceMarker*>(resource); 105 106 return 0; 107 } 108 109 } // namespace WebCore 110 111 #endif 112