Skip to content

Commit

Permalink
Added path effects to the C API
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jul 13, 2016
1 parent d4d0d1f commit e31d35b
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/c/xamarin/sk_x_paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ SK_API sk_path_t* sk_paint_get_pos_text_path(sk_paint_t* cpaint, const void* tex
* Also get the font metrics for the current typeface and type size if cfontmetrics is not null.
*/
SK_API float sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetrics, float scale);
/**
* Return the paint's patheffect object
*/
SK_API sk_path_effect_t* sk_paint_get_path_effect(sk_paint_t* cpaint);
/**
* Sets the paint's patheffect object
*/
SK_API void sk_paint_set_path_effect(sk_paint_t* cpaint, sk_path_effect_t* effect);

SK_C_PLUS_PLUS_END_GUARD

Expand Down
9 changes: 8 additions & 1 deletion include/c/xamarin/sk_x_patheffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

SK_C_PLUS_PLUS_BEGIN_GUARD

//
SK_API sk_path_effect_t* sk_path_effect_create_compose(sk_path_effect_t* outer, sk_path_effect_t* inner);
SK_API sk_path_effect_t* sk_path_effect_create_sum(sk_path_effect_t* first, sk_path_effect_t* second);
SK_API sk_path_effect_t* sk_path_effect_create_discrete(float segLength, float deviation, uint32_t seedAssist /*0*/);
SK_API sk_path_effect_t* sk_path_effect_create_corner(float radius);
SK_API sk_path_effect_t* sk_path_effect_create_1d_path(const sk_path_t* path, float advance, float phase, sk_path_effect_1d_style_t style);
SK_API sk_path_effect_t* sk_path_effect_create_2d_line(float width, const sk_matrix_t* matrix);
SK_API sk_path_effect_t* sk_path_effect_create_2d_path(const sk_matrix_t* matrix, const sk_path_t* path);
SK_API sk_path_effect_t* sk_path_effect_create_dash(const float intervals[], int count, float phase);

SK_C_PLUS_PLUS_END_GUARD

Expand Down
10 changes: 9 additions & 1 deletion include/c/xamarin/sk_x_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ typedef enum {
APPEND_ADD_MODE,
EXTEND_ADD_MODE,
} sk_path_add_mode_t;


typedef enum {
TRANSLATE_SK_PATH_EFFECT_1D_STYLE,
ROTATE_SK_PATH_EFFECT_1D_STYLE,
MORPH_SK_PATH_EFFECT_1D_STYLE,
} sk_path_effect_1d_style_t;

typedef struct sk_path_effect_t sk_path_effect_t;

SK_C_PLUS_PLUS_END_GUARD

#endif
18 changes: 18 additions & 0 deletions src/c/sk_c_from_to.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ static inline bool find_c(SKType from, CType* to) {
return false;
}

static inline SKType find_sk_default(CType from, SKType def) {
for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) {
if (CTypeSkTypeMap[i].fC == from) {
return CTypeSkTypeMap[i].fSK;
}
}
return def;
}

static inline CType find_c_default(SKType from, CType def) {
for (size_t i = 0; i < SK_ARRAY_COUNT(CTypeSkTypeMap); ++i) {
if (CTypeSkTypeMap[i].fSK == from) {
return CTypeSkTypeMap[i].fC;
}
}
return def;
}

#undef CType
#undef SKType
#undef CTypeSkTypeMap
7 changes: 7 additions & 0 deletions src/c/xamarin/sk_x_paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,10 @@ float sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetric
return paint->getFontMetrics(AsFontMetrics(cfontmetrics), scale);
}

sk_path_effect_t* sk_paint_get_path_effect(sk_paint_t* cpaint) {
return ToPathEffect(AsPaint(cpaint)->getPathEffect());
}

void sk_paint_set_path_effect(sk_paint_t* cpaint, sk_path_effect_t* effect) {
AsPaint(cpaint)->setPathEffect(AsPathEffect(effect));
}
2 changes: 0 additions & 2 deletions src/c/xamarin/sk_x_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,3 @@ void sk_path_add_path_reverse (sk_path_t* cpath, sk_path_t* other)
{
as_path (cpath)->reverseAddPath (AsPath (*other));
}


54 changes: 53 additions & 1 deletion src/c/xamarin/sk_x_patheffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,63 @@
* found in the LICENSE file.
*/

#include "SkPathEffect.h"
#include "../../include/effects/SkDiscretePathEffect.h"
#include "../../include/effects/SkCornerPathEffect.h"
#include "../../include/effects/Sk1DPathEffect.h"
#include "../../include/effects/Sk2DPathEffect.h"
#include "../../include/effects/SkDashPathEffect.h"
#include "SkPath.h"

#include "xamarin/sk_x_patheffect.h"

#include "../sk_types_priv.h"
#include "sk_x_types_priv.h"

//
sk_path_effect_t* sk_path_effect_create_compose(sk_path_effect_t* outer, sk_path_effect_t* inner)
{
return ToPathEffect(SkComposePathEffect::Create(AsPathEffect(outer), AsPathEffect(inner)));
}

sk_path_effect_t* sk_path_effect_create_sum(sk_path_effect_t* first, sk_path_effect_t* second)
{
return ToPathEffect(SkSumPathEffect::Create(AsPathEffect(first), AsPathEffect(second)));
}

sk_path_effect_t* sk_path_effect_create_discrete(float segLength, float deviation, uint32_t seedAssist /*0*/)
{
return ToPathEffect(SkDiscretePathEffect::Create(segLength, deviation, seedAssist));
}

sk_path_effect_t* sk_path_effect_create_corner(float radius)
{
return ToPathEffect(SkCornerPathEffect::Create(radius));
}

sk_path_effect_t* sk_path_effect_create_1d_path(const sk_path_t* path, float advance, float phase, sk_path_effect_1d_style_t style)
{
return ToPathEffect(SkPath1DPathEffect::Create(AsPath(*path), advance, phase, find_sk_default(style, SkPath1DPathEffect::kTranslate_Style)));
}

sk_path_effect_t* sk_path_effect_create_2d_line(float width, const sk_matrix_t* cmatrix)
{
SkMatrix matrix;
if (cmatrix) {
from_c(cmatrix, &matrix);
}
return ToPathEffect(SkLine2DPathEffect::Create(width, matrix));
}

sk_path_effect_t* sk_path_effect_create_2d_path(const sk_matrix_t* cmatrix, const sk_path_t* path)
{
SkMatrix matrix;
if (cmatrix) {
from_c(cmatrix, &matrix);
}
return ToPathEffect(SkPath2DPathEffect::Create(matrix, AsPath(*path)));
}

sk_path_effect_t* sk_path_effect_create_dash(const float intervals[], int count, float phase)
{
return ToPathEffect(SkDashPathEffect::Create(intervals, count, phase));
}
31 changes: 31 additions & 0 deletions src/c/xamarin/sk_x_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../../include/effects/SkDisplacementMapEffect.h"
#include "../../include/effects/SkDropShadowImageFilter.h"
#include "../../include/effects/SkMatrixConvolutionImageFilter.h"
#include "../../include/effects/Sk1DPathEffect.h"

#include "sk_path.h"
#include "sk_paint.h"
Expand Down Expand Up @@ -377,6 +378,19 @@ const struct {
#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_region_op_t)
#include "../sk_c_from_to.h"

const struct {
sk_path_effect_1d_style_t fC;
SkPath1DPathEffect::Style fSK;
} MAKE_FROM_TO_NAME(sk_path_effect_1d_style_t)[] = {
{ TRANSLATE_SK_PATH_EFFECT_1D_STYLE, SkPath1DPathEffect::kTranslate_Style },
{ ROTATE_SK_PATH_EFFECT_1D_STYLE, SkPath1DPathEffect::kRotate_Style },
{ MORPH_SK_PATH_EFFECT_1D_STYLE, SkPath1DPathEffect::kMorph_Style },
};
#define CType sk_path_effect_1d_style_t
#define SKType SkPath1DPathEffect::Style
#define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_path_effect_1d_style_t)
#include "../sk_c_from_to.h"

static inline SkRect* AsRect(sk_rect_t* crect) {
return reinterpret_cast<SkRect*>(crect);
}
Expand Down Expand Up @@ -737,4 +751,21 @@ static inline SkPath::RawIter* AsPathRawIter(sk_path_rawiterator_t* iter) {
static inline sk_path_rawiterator_t* ToPathRawIter(SkPath::RawIter* iter) {
return reinterpret_cast<sk_path_rawiterator_t*>(iter);
}

static inline const SkPathEffect* AsPathEffect(const sk_path_effect_t* p) {
return reinterpret_cast<const SkPathEffect*>(p);
}

static inline SkPathEffect* AsPathEffect(sk_path_effect_t* p) {
return reinterpret_cast<SkPathEffect*>(p);
}

static inline sk_path_effect_t* ToPathEffect(SkPathEffect* p) {
return reinterpret_cast<sk_path_effect_t*>(p);
}

static inline const sk_path_effect_t* ToPathEffect(const SkPathEffect* p) {
return reinterpret_cast<const sk_path_effect_t*>(p);
}

#endif

0 comments on commit e31d35b

Please sign in to comment.