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

KHTML

  • 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
37namespace WebCore {
38
39SVGFitToViewBox::SVGFitToViewBox()
40 : m_viewBox()
41 , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
42{
43}
44
45SVGFitToViewBox::~SVGFitToViewBox()
46{
47}
48
49ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(SVGFitToViewBox, FloatRect, Rect, rect, ViewBox, viewBox, SVGNames::viewBoxAttr, m_viewBox)
50ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(SVGFitToViewBox, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
51
52bool 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
85AffineTransform 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
96bool 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
115bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName)
116{
117 return (attrName == SVGNames::viewBoxAttr ||
118 attrName == SVGNames::preserveAspectRatioAttr);
119}
120
121}
122
123#endif // ENABLE(SVG)
AffineTransform.h
FloatRect.h
SVGDocumentExtensions.h
SVGFitToViewBox.h
SVGNames.h
SVGParserUtilities.h
SVGPreserveAspectRatio.h
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
end
const KShortcut & end()
WebCore
Definition: CSSHelper.h:7
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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