2016-07-27 01:46:34 +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 SkSVGRenderContext_DEFINED
|
|
|
|
#define SkSVGRenderContext_DEFINED
|
|
|
|
|
|
|
|
#include "SkPaint.h"
|
2016-08-08 18:38:55 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkSize.h"
|
2016-08-11 16:16:29 +00:00
|
|
|
#include "SkSVGAttribute.h"
|
2016-09-13 00:06:47 +00:00
|
|
|
#include "SkSVGIDMapper.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
#include "SkTLazy.h"
|
2016-08-08 18:38:55 +00:00
|
|
|
#include "SkTypes.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
class SkCanvas;
|
2016-08-03 17:21:11 +00:00
|
|
|
class SkSVGLength;
|
|
|
|
|
|
|
|
class SkSVGLengthContext {
|
|
|
|
public:
|
2016-08-17 21:51:03 +00:00
|
|
|
SkSVGLengthContext(const SkSize& viewport, SkScalar dpi = 90)
|
|
|
|
: fViewport(viewport), fDPI(dpi) {}
|
2016-08-03 17:21:11 +00:00
|
|
|
|
|
|
|
enum class LengthType {
|
|
|
|
kHorizontal,
|
|
|
|
kVertical,
|
|
|
|
kOther,
|
|
|
|
};
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
const SkSize& viewPort() const { return fViewport; }
|
2016-08-03 17:21:11 +00:00
|
|
|
void setViewPort(const SkSize& viewport) { fViewport = viewport; }
|
|
|
|
|
|
|
|
SkScalar resolve(const SkSVGLength&, LengthType) const;
|
2016-08-08 18:38:55 +00:00
|
|
|
SkRect resolveRect(const SkSVGLength& x, const SkSVGLength& y,
|
|
|
|
const SkSVGLength& w, const SkSVGLength& h) const;
|
2016-08-03 17:21:11 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-17 21:51:03 +00:00
|
|
|
SkSize fViewport;
|
|
|
|
SkScalar fDPI;
|
2016-08-03 17:21:11 +00:00
|
|
|
};
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-11 16:16:29 +00:00
|
|
|
struct SkSVGPresentationContext {
|
2016-08-08 18:38:55 +00:00
|
|
|
SkSVGPresentationContext();
|
2016-08-11 16:16:29 +00:00
|
|
|
SkSVGPresentationContext(const SkSVGPresentationContext&) = default;
|
|
|
|
SkSVGPresentationContext& operator=(const SkSVGPresentationContext&) = default;
|
2016-08-08 18:38:55 +00:00
|
|
|
|
2016-08-11 16:16:29 +00:00
|
|
|
// Inherited presentation attributes, computed for the current node.
|
|
|
|
SkSVGPresentationAttributes fInherited;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-11 16:16:29 +00:00
|
|
|
// Cached paints, reflecting the current presentation attributes.
|
|
|
|
SkPaint fFillPaint;
|
|
|
|
SkPaint fStrokePaint;
|
2016-08-08 18:38:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkSVGRenderContext {
|
|
|
|
public:
|
2016-09-13 00:06:47 +00:00
|
|
|
SkSVGRenderContext(SkCanvas*, const SkSVGIDMapper&, const SkSVGLengthContext&,
|
|
|
|
const SkSVGPresentationContext&);
|
2016-08-08 18:38:55 +00:00
|
|
|
SkSVGRenderContext(const SkSVGRenderContext&);
|
|
|
|
~SkSVGRenderContext();
|
|
|
|
|
|
|
|
const SkSVGLengthContext& lengthContext() const { return *fLengthContext; }
|
|
|
|
SkSVGLengthContext* writableLengthContext() { return fLengthContext.writable(); }
|
|
|
|
|
|
|
|
SkCanvas* canvas() const { return fCanvas; }
|
|
|
|
|
2016-09-20 22:45:57 +00:00
|
|
|
enum ApplyFlags {
|
|
|
|
kLeaf = 1 << 0, // the target node doesn't have descendants
|
|
|
|
};
|
|
|
|
void applyPresentationAttributes(const SkSVGPresentationAttributes&, uint32_t flags);
|
2016-08-11 16:16:29 +00:00
|
|
|
|
2016-09-13 00:06:47 +00:00
|
|
|
const SkSVGNode* findNodeById(const SkString&) const;
|
|
|
|
|
2016-08-11 16:16:29 +00:00
|
|
|
const SkPaint* fillPaint() const;
|
|
|
|
const SkPaint* strokePaint() const;
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
private:
|
|
|
|
// Stack-only
|
|
|
|
void* operator new(size_t) = delete;
|
|
|
|
void* operator new(size_t, void*) = delete;
|
|
|
|
SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete;
|
|
|
|
|
2016-09-20 22:45:57 +00:00
|
|
|
void applyOpacity(SkScalar opacity, uint32_t flags);
|
|
|
|
|
2016-09-13 00:06:47 +00:00
|
|
|
const SkSVGIDMapper& fIDMapper;
|
2016-08-08 18:38:55 +00:00
|
|
|
SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext;
|
|
|
|
SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext;
|
|
|
|
SkCanvas* fCanvas;
|
|
|
|
// The save count on 'fCanvas' at construction time.
|
|
|
|
// A restoreToCount() will be issued on destruction.
|
|
|
|
int fCanvasSaveCount;
|
2016-07-27 01:46:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SkSVGRenderContext_DEFINED
|