• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGViewSpec.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 Rob Buis <buis@kde.org>
3 
4  This file is part of the KDE project
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "config.h"
23 #include "wtf/Platform.h"
24 #if ENABLE(SVG)
25 #include "SVGViewSpec.h"
26 
27 #include "PlatformString.h"
28 #include "SVGParserUtilities.h"
29 #include "SVGPreserveAspectRatio.h"
30 #include "SVGSVGElement.h"
31 #include "SVGTransformList.h"
32 #include "SVGTransformable.h"
33 
34 namespace WebCore {
35 
36 SVGViewSpec::SVGViewSpec(const SVGSVGElement* contextElement)
37  : SVGFitToViewBox()
38  , SVGZoomAndPan()
39  , m_transform(SVGTransformList::create(SVGNames::transformAttr))
40  , m_contextElement(contextElement)
41 {
42 }
43 
44 SVGViewSpec::~SVGViewSpec()
45 {
46 }
47 
48 void SVGViewSpec::setTransform(const String& transform)
49 {
50  SVGTransformable::parseTransformAttribute(m_transform.get(), transform);
51 }
52 
53 void SVGViewSpec::setViewBoxString(const String& viewBox)
54 {
55  float x, y, w, h;
56  const UChar* c = viewBox.characters();
57  const UChar* end = c + viewBox.length();
58  if (!parseViewBox(c, end, x, y, w, h, false))
59  return;
60  setViewBoxBaseValue(FloatRect(x, y, w, h));
61 }
62 
63 void SVGViewSpec::setPreserveAspectRatioString(const String& preserve)
64 {
65  const UChar* c = preserve.characters();
66  const UChar* end = c + preserve.length();
67  preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
68 }
69 
70 void SVGViewSpec::setViewTargetString(const String& viewTargetString)
71 {
72  m_viewTargetString = viewTargetString;
73 }
74 
75 SVGElement* SVGViewSpec::viewTarget() const
76 {
77  return static_cast<SVGElement*>(m_contextElement->ownerDocument()->getElementById(m_viewTargetString));
78 }
79 
80 const SVGElement* SVGViewSpec::contextElement() const
81 {
82  return m_contextElement;
83 }
84 
85 static const UChar svgViewSpec[] = {'s','v','g','V', 'i', 'e', 'w'};
86 static const UChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'};
87 static const UChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'};
88 static const UChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm'};
89 static const UChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', 'a', 'n'};
90 static const UChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g', 'e', 't'};
91 
92 bool SVGViewSpec::parseViewSpec(const String& viewSpec)
93 {
94  const UChar* currViewSpec = viewSpec.characters();
95  const UChar* end = currViewSpec + viewSpec.length();
96 
97  if (currViewSpec >= end)
98  return false;
99 
100  if (!skipString(currViewSpec, end, svgViewSpec, sizeof(svgViewSpec) / sizeof(UChar)))
101  return false;
102 
103  if (currViewSpec >= end || *currViewSpec != '(' )
104  return false;
105  currViewSpec++;
106 
107  while (currViewSpec < end && *currViewSpec != ')') {
108  if (*currViewSpec == 'v') {
109  if (skipString(currViewSpec, end, viewBoxSpec, sizeof(viewBoxSpec) / sizeof(UChar))) {
110  if (currViewSpec >= end || *currViewSpec != '(')
111  return false;
112  currViewSpec++;
113  float x, y, w, h;
114  if (!parseViewBox(currViewSpec, end, x, y, w, h, false))
115  return false;
116  setViewBoxBaseValue(FloatRect(x, y, w, h));
117  if (currViewSpec >= end || *currViewSpec != ')')
118  return false;
119  currViewSpec++;
120  } else if (skipString(currViewSpec, end, viewTargetSpec, sizeof(viewTargetSpec) / sizeof(UChar))) {
121  if (currViewSpec >= end || *currViewSpec != '(')
122  return false;
123  const UChar* viewTargetStart = ++currViewSpec;
124  while (currViewSpec < end && *currViewSpec != ')')
125  currViewSpec++;
126  if (currViewSpec >= end)
127  return false;
128  setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart));
129  currViewSpec++;
130  } else
131  return false;
132  } else if (*currViewSpec == 'z') {
133  if (!skipString(currViewSpec, end, zoomAndPanSpec, sizeof(zoomAndPanSpec) / sizeof(UChar)))
134  return false;
135  if (currViewSpec >= end || *currViewSpec != '(')
136  return false;
137  currViewSpec++;
138  if (!parseZoomAndPan(currViewSpec, end))
139  return false;
140  if (currViewSpec >= end || *currViewSpec != ')')
141  return false;
142  currViewSpec++;
143  } else if (*currViewSpec == 'p') {
144  if (!skipString(currViewSpec, end, preserveAspectRatioSpec, sizeof(preserveAspectRatioSpec) / sizeof(UChar)))
145  return false;
146  if (currViewSpec >= end || *currViewSpec != '(')
147  return false;
148  currViewSpec++;
149  if (!preserveAspectRatioBaseValue()->parsePreserveAspectRatio(currViewSpec, end, false))
150  return false;
151  if (currViewSpec >= end || *currViewSpec != ')')
152  return false;
153  currViewSpec++;
154  } else if (*currViewSpec == 't') {
155  if (!skipString(currViewSpec, end, transformSpec, sizeof(transformSpec) / sizeof(UChar)))
156  return false;
157  if (currViewSpec >= end || *currViewSpec != '(')
158  return false;
159  currViewSpec++;
160  SVGTransformable::parseTransformAttribute(m_transform.get(), currViewSpec, end);
161  if (currViewSpec >= end || *currViewSpec != ')')
162  return false;
163  currViewSpec++;
164  } else
165  return false;
166 
167  if (currViewSpec < end && *currViewSpec == ';')
168  currViewSpec++;
169  }
170 
171  if (currViewSpec >= end || *currViewSpec != ')')
172  return false;
173 
174  return true;
175 }
176 
177 }
178 
179 #endif // ENABLE(SVG)
SVGViewSpec.h
SVGParserUtilities.h
WebCore::SVGNames::transformAttr
DOM::QualifiedName transformAttr
Definition: SVGNames.cpp:312
SVGSVGElement.h
SVGPreserveAspectRatio.h
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
SVGTransformList.h
SVGTransformable.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
end
const KShortcut & end()
PlatformString.h
WebCore::skipString
bool skipString(const QChar *&ptr, const QChar *end, const QChar *name, int length)
Definition: ParserUtilities.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal