Skip to content

Commit

Permalink
Merge pull request kyamagu#24 from kyamagu/add-path-effects
Browse files Browse the repository at this point in the history
Add path effects
  • Loading branch information
kyamagu authored Apr 21, 2020
2 parents 010cabd + 70d9d2b commit c8b623e
Show file tree
Hide file tree
Showing 8 changed files with 932 additions and 131 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Documentation
-------------

.. toctree::
:maxdepth: 3
:maxdepth: 2

build
usage
Expand Down
130 changes: 129 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,132 @@
Reference
---------
=========

.. automodule:: skia

.. currentmodule:: skia

.. rubric:: Classes

.. autosummary::
:toctree: _generate
:nosignatures:
:template: class.rst

.. rubric:: Classes

AlphaType
ApplyPerspectiveClip
AutoCanvasRestore
BBoxHierarchy
BackingFit
Bitmap
BlendMode
BlendModeCoeff
Budgeted
Canvas
Canvas.SaveLayerFlags
Canvas.SrcRectConstraint
Canvas.PointMode
Canvas.QuadAAFlags
Canvas.SaveLayerRec
Canvas.Lattice
Canvas.Lattice.RectType
ClipOp
Color4f
ColorFilter
ColorInfo
ColorSpace
ColorType
CornerPathEffect
DashPathEffect
Data
DeserialProcs
DiscretePathEffect
EncodedImageFormat
FilterQuality
Flattanable
Font
FontArguments
FontHinting
FontMetrics
FontMgr
FontStyle
FontStyleSet
GrBackendApi
GrBackendSemaphore
GrBackendTexture
GrContext
GrFlushFlags
GrGLBackendState
GrGLInterface
GrMipMapped
GrProtected
GrRenderable
GrSemaphoresSubmitted
GrSurfaceOrigin
IPoint
IRect
ISize
Image
ImageFilter
ImageInfo
M44
MaskFilter
Matrix
MatrixPathEffect
MergePathEffect
Paint
Path
Path.Iter
Path.RawIter
Path.ArcSize
Path.AddPathMode
Path.SegmentMask
Path.Verb
PathConvexityType
PathDirection
PathEffect
PathEffect.DashInfo
PathEffect.DashType
PathEffect.PointData
PathEffect.PointData.PointFlags
Path1DPathEffect
Path1DPathEffect.Style
Path2DPathEffect
PathFillType
PathSegmentMask
PathVerb
Picture
PictureRecorder
PixelGeometry
Pixmap
Point
Point3
RRect
RSXform
Rect
Region
Shader
Size
StrokePathEffect
StrokeRec
Surface
Surface.AsyncReadResult
Surface.ContentChangeMode
Surface.BackendHandleAccess
Surface.RescaleGamma
Surface.BackendSurfaceAccess
Surface.FlushFlags
SurfaceCharacterization
SurfaceProps
SurfaceProps.Flags
SurfaceProps.InitType
TextBlob
TextBlobBuilder
TextEncoding
TileMode
TrimPathEffect
TrimPathEffect.Mode
Typeface
Vertices
YUVColorSpace
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
os.path.join('src', 'skia', 'Matrix.cpp'),
os.path.join('src', 'skia', 'Paint.cpp'),
os.path.join('src', 'skia', 'Path.cpp'),
os.path.join('src', 'skia', 'PathEffect.cpp'),
os.path.join('src', 'skia', 'Picture.cpp'),
os.path.join('src', 'skia', 'Pixmap.cpp'),
os.path.join('src', 'skia', 'Point.cpp'),
Expand Down
90 changes: 72 additions & 18 deletions src/skia/Paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ const int SkPaint::kStyleCount;
const int SkPaint::kCapCount;
const int SkPaint::kJoinCount;


class PyFlattanable : public SkFlattenable {
using SkFlattenable::SkFlattenable;
Factory getFactory() const override {
PYBIND11_OVERLOAD_PURE(
Factory,
SkFlattenable,
getFactory,
);
}
const char* getTypeName() const override {
PYBIND11_OVERLOAD_PURE(const char*, SkFlattenable, getTypeName);
}
Type getFlattenableType() const override {
PYBIND11_OVERLOAD_PURE(Type, SkFlattenable, getFlattenableType);
}
};


void initPaint(py::module &m) {
// Paint
py::class_<SkPaint> paint(m, "Paint", R"docstring(
Expand Down Expand Up @@ -189,9 +208,61 @@ paint
"Compares a and b, and returns true if a and b are not equivalent.")
;

py::class_<SkFlattenable, PyFlattanable, sk_sp<SkFlattenable>> flattanable(
m, "Flattanable",
R"docstring(
:py:class:`Flattenable` is the base class for objects that need to be
flattened into a data stream for either transport or as part of the key to
the font cache.
)docstring");

py::enum_<SkFlattenable::Type>(flattanable, "Type")
.value("kColorFilter", SkFlattenable::Type::kSkColorFilter_Type)
.value("kDrawable", SkFlattenable::Type::kSkDrawable_Type)
.value("kDrawLooper", SkFlattenable::Type::kSkDrawLooper_Type)
.value("kImageFilter", SkFlattenable::Type::kSkImageFilter_Type)
.value("kMaskFilter", SkFlattenable::Type::kSkMaskFilter_Type)
.value("kPathEffect", SkFlattenable::Type::kSkPathEffect_Type)
.value("kPixelRef", SkFlattenable::Type::kSkPixelRef_Type)
.value("kUnused4", SkFlattenable::Type::kSkUnused_Type4)
.value("kShaderBase", SkFlattenable::Type::kSkShaderBase_Type)
.value("kUnused", SkFlattenable::Type::kSkUnused_Type)
.value("kUnused2", SkFlattenable::Type::kSkUnused_Type2)
.value("kUnused3", SkFlattenable::Type::kSkUnused_Type3)
.export_values();

flattanable
// .def("getFactory", &SkFlattenable::getFactory)
.def("getTypeName", &SkFlattenable::getTypeName,
R"docstring(
Returns the name of the object's class.
Implemented in :py:class:`~skia.Drawable`.
)docstring")
// .def("flatten", &SkFlattenable::flatten)
.def("getFlattenableType", &SkFlattenable::getFlattenableType)
.def("serialize",
[] (const SkFlattenable& flattanable) {
return flattanable.serialize();
})
.def("unique", &SkFlattenable::unique)
.def("ref", &SkFlattenable::ref)
.def("unref", &SkFlattenable::unref)
// .def_static("NameToFactory", &SkFlattenable::NameToFactory)
// .def_static("FactoryToName", &SkFlattenable::FactoryToName)
// .def_static("Register", &SkFlattenable::Register)
.def_static("Deserialize",
[] (SkFlattenable::Type type, py::buffer b) {
auto info = b.request();
size_t size = (info.ndim) ? info.shape[0] * info.strides[0] : 0;
return SkFlattenable::Deserialize(type, info.ptr, size);
})
;

// Shader
// TODO: Need a wrapper class for pure virtual functions.
py::class_<SkShader, sk_sp<SkShader>> shader(m, "Shader", R"docstring(
py::class_<SkShader, sk_sp<SkShader>, SkFlattenable> shader(
m, "Shader", R"docstring(
Shaders specify the source color(s) for what is being drawn.
If a paint has no shader, then the paint's color is used. If the paint has a
Expand Down Expand Up @@ -224,21 +295,6 @@ py::enum_<SkShader::GradientType>(shader, "GradientType", R"docstring(
.value("kLast", SkShader::GradientType::kLast_GradientType)
.export_values();

py::enum_<SkShader::Type>(shader, "Type")
.value("kSkColorFilter", SkShader::Type::kSkColorFilter_Type)
.value("kSkDrawable", SkShader::Type::kSkDrawable_Type)
.value("kSkDrawLooper", SkShader::Type::kSkDrawLooper_Type)
.value("kSkImageFilter", SkShader::Type::kSkImageFilter_Type)
.value("kSkMaskFilter", SkShader::Type::kSkMaskFilter_Type)
.value("kSkPathEffect", SkShader::Type::kSkPathEffect_Type)
.value("kSkPixelRef", SkShader::Type::kSkPixelRef_Type)
.value("kSkUnused4", SkShader::Type::kSkUnused_Type4)
.value("kSkShaderBase", SkShader::Type::kSkShaderBase_Type)
.value("kSkUnused", SkShader::Type::kSkUnused_Type)
.value("kSkUnused2", SkShader::Type::kSkUnused_Type2)
// .value("kSkUnused3", SkShader::Type::kSkUnused_Type3)
.export_values();

shader
.def("isOpaque", &SkShader::isOpaque,
"Returns true if the shader is guaranteed to produce only opaque "
Expand Down Expand Up @@ -282,8 +338,6 @@ shader
;
// ColorFilter
py::class_<SkColorFilter, sk_sp<SkColorFilter>>(m, "ColorFilter");
// PathEffect
py::class_<SkPathEffect, sk_sp<SkPathEffect>>(m, "PathEffect");
// MaskFilter
py::class_<SkMaskFilter, sk_sp<SkMaskFilter>>(m, "MaskFilter");
// ImageFilter
Expand Down
17 changes: 17 additions & 0 deletions src/skia/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ m.def("PathFillType_IsEvenOdd", &SkPathFillType_IsEvenOdd);
m.def("PathFillType_IsInverse", &SkPathFillType_IsInverse);
m.def("PathFillType_ConvertToNonInverse", &SkPathFillType_ConvertToNonInverse);


py::enum_<SkPathOp>(m, "PathOp", R"docstring(
The logical operations that can be performed when combining two paths.
)docstring")
.value("kDifference", SkPathOp::kDifference_SkPathOp,
"subtract the op path from the first path")
.value("kIntersect", SkPathOp::kIntersect_SkPathOp,
"intersect the two paths")
.value("kUnion", SkPathOp::kUnion_SkPathOp,
"union (inclusive-or) the two paths")
.value("kXOR", SkPathOp::kXOR_SkPathOp,
"exclusive-or the two paths")
.value("kReverseDifference", SkPathOp::kReverseDifference_SkPathOp,
"subtract the first path from the op path")
.export_values();


// Path
py::class_<SkPath> path(m, "Path", R"docstring(
:py:class:`Path` contain geometry.
Expand Down
Loading

0 comments on commit c8b623e

Please sign in to comment.