• 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
SVGFitToViewBox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGFitToViewBox.h"
28 
29 #include "AffineTransform.h"
30 #include "FloatRect.h"
31 #include "SVGDocumentExtensions.h"
32 #include "SVGNames.h"
33 #include "SVGParserUtilities.h"
34 #include "SVGPreserveAspectRatio.h"
35 //#include "StringImpl.h"
36 
37 namespace WebCore {
38 
39 SVGFitToViewBox::SVGFitToViewBox()
40  : m_viewBox()
41  , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
42 {
43 }
44 
45 SVGFitToViewBox::~SVGFitToViewBox()
46 {
47 }
48 
49 ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(SVGFitToViewBox, FloatRect, Rect, rect, ViewBox, viewBox, SVGNames::viewBoxAttr, m_viewBox)
50 ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(SVGFitToViewBox, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
51 
52 bool SVGFitToViewBox::parseViewBox(const UChar*& c, const UChar* end, float& x, float& y, float& w, float& h, bool validate)
53 {
54  Document* doc = contextElement()->document();
55  String str(c, end - c);
56 
57  skipOptionalSpaces(c, end);
58 
59  bool valid = (parseNumber(c, end, x) && parseNumber(c, end, y) &&
60  parseNumber(c, end, w) && parseNumber(c, end, h, false));
61  if (!validate)
62  return true;
63  if (!valid) {
64  //FIXME vtokarev doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
65  return false;
66  }
67 
68  if (w < 0.0) { // check that width is positive
69  doc->accessSVGExtensions()->reportError("A negative value for ViewBox width is not allowed");
70  return false;
71  } else if (h < 0.0) { // check that height is positive
72  doc->accessSVGExtensions()->reportError("A negative value for ViewBox height is not allowed");
73  return false;
74  } else {
75  skipOptionalSpaces(c, end);
76  if (c < end) { // nothing should come after the last, fourth number
77  //FIXME vtokarev doc->accessSVGExtensions()->reportWarning("Problem parsing viewBox=\"" + str + "\"");
78  return false;
79  }
80  }
81 
82  return true;
83 }
84 
85 AffineTransform SVGFitToViewBox::viewBoxToViewTransform(float viewWidth, float viewHeight) const
86 {
87  FloatRect viewBoxRect = viewBox();
88  if (!viewBoxRect.width() || !viewBoxRect.height())
89  return AffineTransform();
90 
91  return preserveAspectRatio()->getCTM(viewBoxRect.x(),
92  viewBoxRect.y(), viewBoxRect.width(), viewBoxRect.height(),
93  0, 0, viewWidth, viewHeight);
94 }
95 
96 bool SVGFitToViewBox::parseMappedAttribute(MappedAttribute* attr)
97 {
98  if (attr->name() == SVGNames::viewBoxAttr) {
99  float x = 0.0f, y = 0.0f, w = 0.0f, h = 0.0f;
100  const UChar* c = attr->value().characters();
101  const UChar* end = c + attr->value().length();
102  if (parseViewBox(c, end, x, y, w, h))
103  setViewBoxBaseValue(FloatRect(x, y, w, h));
104  return true;
105  } else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
106  const UChar* c = attr->value().characters();
107  const UChar* end = c + attr->value().length();
108  preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
109  return true;
110  }
111 
112  return false;
113 }
114 
115 bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName)
116 {
117  return (attrName == SVGNames::viewBoxAttr ||
118  attrName == SVGNames::preserveAspectRatioAttr);
119 }
120 
121 }
122 
123 #endif // ENABLE(SVG)
WebCore::SVGNames::preserveAspectRatioAttr
DOM::QualifiedName preserveAspectRatioAttr
Definition: SVGNames.cpp:258
SVGParserUtilities.h
AffineTransform.h
SVGPreserveAspectRatio.h
WebCore::SVGNames::viewBoxAttr
DOM::QualifiedName viewBoxAttr
Definition: SVGNames.cpp:331
SVGFitToViewBox.h
SVGNames.h
FloatRect.h
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
SVGDocumentExtensions.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
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