2020-10-15 22:10:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSVGDOM_DEFINED
|
|
|
|
#define SkSVGDOM_DEFINED
|
|
|
|
|
2020-11-10 20:24:59 +00:00
|
|
|
#include "include/core/SkFontMgr.h"
|
2020-10-15 22:10:29 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
2021-01-26 23:45:34 +00:00
|
|
|
#include "modules/skresources/include/SkResources.h"
|
2020-10-15 22:10:29 +00:00
|
|
|
#include "modules/svg/include/SkSVGIDMapper.h"
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
class SkDOM;
|
|
|
|
class SkStream;
|
|
|
|
class SkSVGNode;
|
2020-11-10 20:24:59 +00:00
|
|
|
class SkSVGSVG;
|
2020-10-15 22:10:29 +00:00
|
|
|
|
|
|
|
class SkSVGDOM : public SkRefCnt {
|
|
|
|
public:
|
2020-11-10 20:24:59 +00:00
|
|
|
class Builder final {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Specify a font manager for loading SVG fonts.
|
|
|
|
*/
|
|
|
|
Builder& setFontManager(sk_sp<SkFontMgr>);
|
2020-10-15 22:10:29 +00:00
|
|
|
|
2021-01-26 23:45:34 +00:00
|
|
|
/**
|
|
|
|
* Specify a resource provider for loading images etc.
|
|
|
|
*/
|
|
|
|
Builder& setResourceProvider(sk_sp<skresources::ResourceProvider>);
|
|
|
|
|
2020-11-10 20:24:59 +00:00
|
|
|
sk_sp<SkSVGDOM> make(SkStream&) const;
|
|
|
|
|
|
|
|
private:
|
2021-01-26 23:45:34 +00:00
|
|
|
sk_sp<SkFontMgr> fFontMgr;
|
|
|
|
sk_sp<skresources::ResourceProvider> fResourceProvider;
|
2020-11-10 20:24:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static sk_sp<SkSVGDOM> MakeFromStream(SkStream& str) {
|
|
|
|
return Builder().make(str);
|
|
|
|
}
|
2020-10-15 22:10:29 +00:00
|
|
|
|
2021-06-04 18:31:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the root (outermost) SVG element.
|
|
|
|
*/
|
|
|
|
SkSVGSVG* getRoot() const { return fRoot.get(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify a "container size" for the SVG dom.
|
|
|
|
*
|
|
|
|
* This is used to resolve the initial viewport when the root SVG width/height are specified
|
|
|
|
* in relative units.
|
|
|
|
*
|
|
|
|
* If the root dimensions are in absolute units, then the container size has no effect since
|
|
|
|
* the initial viewport is fixed.
|
|
|
|
*/
|
2020-10-15 22:10:29 +00:00
|
|
|
void setContainerSize(const SkSize&);
|
|
|
|
|
2021-06-04 18:31:06 +00:00
|
|
|
/**
|
|
|
|
* DEPRECATED: use getRoot()->intrinsicSize() to query the root element intrinsic size.
|
|
|
|
*
|
|
|
|
* Returns the SVG dom container size.
|
|
|
|
*
|
|
|
|
* If the client specified a container size via setContainerSize(), then the same size is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* When unspecified by clients, this returns the intrinsic size of the root element, as defined
|
|
|
|
* by its width/height attributes. If either width or height is specified in relative units
|
|
|
|
* (e.g. "100%"), then the corresponding intrinsic size dimension is zero.
|
|
|
|
*/
|
|
|
|
const SkSize& containerSize() const;
|
|
|
|
|
2020-10-15 22:10:29 +00:00
|
|
|
// Returns the node with the given id, or nullptr if not found.
|
|
|
|
sk_sp<SkSVGNode>* findNodeById(const char* id);
|
|
|
|
|
|
|
|
void render(SkCanvas*) const;
|
|
|
|
|
|
|
|
private:
|
2021-01-26 23:45:34 +00:00
|
|
|
SkSVGDOM(sk_sp<SkSVGSVG>, sk_sp<SkFontMgr>, sk_sp<skresources::ResourceProvider>,
|
|
|
|
SkSVGIDMapper&&);
|
2020-10-15 22:10:29 +00:00
|
|
|
|
2021-01-26 23:45:34 +00:00
|
|
|
const sk_sp<SkSVGSVG> fRoot;
|
|
|
|
const sk_sp<SkFontMgr> fFontMgr;
|
|
|
|
const sk_sp<skresources::ResourceProvider> fResourceProvider;
|
|
|
|
const SkSVGIDMapper fIDMapper;
|
2020-10-15 22:10:29 +00:00
|
|
|
|
2020-11-10 20:24:59 +00:00
|
|
|
SkSize fContainerSize;
|
2020-10-15 22:10:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkSVGDOM_DEFINED
|