32 , documentResourceManager(0)
40 if (! gcStack.isEmpty() && !gcStack.top()->isResolutionFrame) {
42 warnFlake <<
"the context stack is not empty (current count" << gcStack.size() <<
", expected 0)";
54 QHash<QString, const KoColorProfile*>
profiles;
65 Q_ASSERT(
d->documentResourceManager);
74 if (
d->gcStack.isEmpty())
77 return d->gcStack.top();
86 if (!
d->gcStack.isEmpty() && inherit) {
101 if (!element.isNull()) {
102 if (element.hasAttribute(
"transform")) {
105 QTransform mat =
p.transform();
109 if (element.hasAttribute(
"xml:base"))
110 gc->
xmlBaseDir = element.attribute(
"xml:base");
111 if (element.hasAttribute(
"xml:space"))
122 delete(
d->gcStack.pop());
127 d->initialXmlBaseDir = baseDir;
138 QFileInfo info(href);
139 if (! info.isRelative())
144 return d->initialXmlBaseDir;
146 QString baseDir =
d->initialXmlBaseDir;
150 QFileInfo pathInfo(QFileInfo(baseDir).filePath());
152 QString relFile = href;
153 while (relFile.startsWith(QLatin1String(
"../"))) {
154 relFile.remove(0, 3);
155 pathInfo.setFile(pathInfo.dir(), QString());
158 QString absFile = pathInfo.absolutePath() +
'/' + relFile;
166 if (!gc)
return href;
168 QString result = href;
170 QFileInfo info(href);
171 if (info.isRelative())
176 result = QDir(gc->
xmlBaseDir).relativeFilePath(href);
177 }
else if (!
d->initialXmlBaseDir.isEmpty()) {
178 result = QDir(
d->initialXmlBaseDir).relativeFilePath(href);
181 return QDir::cleanPath(result);
192 d->loadedShapes.insert(
id, shape);
197 return d->loadedShapes.value(
id);
202 const QString
id = element.attribute(
"id");
203 if (
id.isEmpty() ||
d->definitions.contains(
id))
205 d->definitions.insert(
id, element);
210 return d->definitions.value(
id);
215 return d->definitions.contains(
id);
220 d->cssStyles.parseStylesheet(styleSheet);
225 return d->cssStyles.matchStyles(element);
230 return *
d->styleParser;
235 const QString href = element.attribute(
"xlink:href");
236 const QByteArray uniqueId = QByteArray::fromHex(element.attribute(
"local").toLatin1());
237 const QString name = element.attribute(
"name");
239 if (element.attribute(
"rendering-intent",
"auto") !=
"auto") {
241 warnFlake <<
"WARNING: we do *not* treat rendering intents attributes of the profile!";
244 if (
d->profiles.contains(name)) {
252 if (!profile &&
d->fileFetcher) {
257 const QByteArray profileData =
d->fileFetcher(fileName);
258 if (!profileData.isEmpty()) {
261 if (profile->
uniqueId() != uniqueId) {
262 warnFlake <<
"WARNING: ProfileID of the attached profile doesn't match the one mentioned in SVG element";
267 warnFlake <<
"WARNING: couldn't fetch the ICCprofile file!" << fileName;
273 d->profiles.insert(name, profile);
287 for (
auto it =
d->gcStack.begin(); it !=
d->gcStack.end(); it++) {
300 return d->gcStack.size() == 1;
305 d->fileFetcher = func;
310 return d->fileFetcher ?
d->fileFetcher(url) : QByteArray();
static KoColorSpaceEngineRegistry * instance()
T get(const QString &id) const
void resetNonInheritableToDefault()
void inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve=false)
QString clipPathId
the current clip path id
QString xmlBaseDir
the current base directory (used for loading external content)
bool preserveWhitespace
preserve whitespace in element text
KoSvgTextProperties textProperties
Stores textProperties.
bool display
controls display of shape
QTransform matrix
the current transformation matrix
QString filterId
the current filter id
QString paintOrder
String list indicating paint order;.
QString clipMaskId
the current clip mask id
qreal opacity
the shapes opacity
Contains data used for loading svg.
void addDefinition(const QDomElement &element)
Adds a definition for later use.
void setInitialXmlBaseDir(const QString &baseDir)
Sets the initial xml base dir, i.e. the directory the svg file is read from.
SvgGraphicsContext * pushGraphicsContext(const QDomElement &element=QDomElement(), bool inherit=true)
Pushes a new graphics context to the stack.
QString relativeFilePath(const QString &href)
QByteArray fetchExternalFile(const QString &url)
std::function< QByteArray(const QString &) FileFetcherFunc)
void registerShape(const QString &id, KoShape *shape)
Registers a shape so it can be referenced later.
QStack< SvgGraphicsContext * > gcStack
KoDocumentResourceManager * documentResourceManager
bool isRootContext() const
void popGraphicsContext()
Pops the current graphics context from the stack.
void addStyleSheet(const QDomElement &styleSheet)
Adds a css style sheet.
QString xmlBaseDir() const
Returns the current xml base dir.
QHash< QString, KoShape * > loadedShapes
QScopedPointer< Private > d
QString initialXmlBaseDir
QStringList matchingCssStyles(const QDomElement &element) const
Returns list of css styles matching to the specified element.
KoShape * shapeById(const QString &id)
Returns shape with specified id.
QDomElement definition(const QString &id) const
Returns the definition with the specified id.
FileFetcherFunc fileFetcher
QString absoluteFilePath(const QString &href)
Constructs an absolute file path from the given href and current xml base directory.
QHash< QString, const KoColorProfile * > profiles
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
void parseProfile(const QDomElement &element)
parses 'color-profile' tag and saves it in the context
SvgLoadingContext(KoDocumentResourceManager *documentResourceManager)
void setFileFetcher(FileFetcherFunc func)
SvgStyleParser * styleParser
bool hasDefinition(const QString &id) const
Checks if a definition with the specified id exists.
int nextZIndex()
Returns the next z-index.
QHash< QString, QDomElement > definitions
virtual QByteArray uniqueId() const =0
virtual const KoColorProfile * addProfile(const QString &filename)=0
static KoColorSpaceRegistry * instance()
const KoColorProfile * profileByUniqueId(const QByteArray &id) const