Skip to content

Commit fffc089

Browse files
committed
Add Cap and Join enums to Stroke class.
1 parent d0e6f5e commit fffc089

File tree

8 files changed

+130
-18
lines changed

8 files changed

+130
-18
lines changed

Diff for: src/rendering/renderers/ShapeRenderer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "rendering/graphics/Graphic.h"
2828
#include "rendering/graphics/Shape.h"
2929
#include "rendering/utils/PathUtil.h"
30+
#include "rendering/utils/TGFXTypes.h"
3031

3132
namespace pag {
3233

@@ -47,7 +48,7 @@ enum class PaintType { Fill, Stroke, GradientFill, GradientStroke };
4748
*/
4849
struct StrokePaint {
4950
Stroke getStroke() const {
50-
return Stroke(strokeWidth, lineCap, lineJoin, miterLimit);
51+
return Stroke(strokeWidth, ToTGFXCap(lineCap), ToTGFXJoin(lineJoin), miterLimit);
5152
}
5253

5354
float strokeWidth;

Diff for: src/rendering/utils/TGFXTypes.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Tencent is pleased to support the open source community by making libpag available.
4+
//
5+
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
8+
// except in compliance with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// unless required by applicable law or agreed to in writing, software distributed under the
13+
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
14+
// either express or implied. see the license for the specific language governing permissions
15+
// and limitations under the license.
16+
//
17+
/////////////////////////////////////////////////////////////////////////////////////////////////
18+
19+
#include "TGFXTypes.h"
20+
21+
namespace pag {
22+
Stroke::Cap ToTGFXCap(Enum cap) {
23+
switch (cap) {
24+
case LineCap::Round:
25+
return Stroke::Cap::Round;
26+
case LineCap::Square:
27+
return Stroke::Cap::Square;
28+
default:
29+
return Stroke::Cap::Butt;
30+
}
31+
}
32+
33+
Stroke::Join ToTGFXJoin(Enum join) {
34+
switch (join) {
35+
case LineJoin::Round:
36+
return Stroke::Join::Round;
37+
case LineJoin::Bevel:
38+
return Stroke::Join::Bevel;
39+
default:
40+
return Stroke::Join::Miter;
41+
}
42+
}
43+
44+
} // namespace pag

Diff for: src/rendering/utils/TGFXTypes.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Tencent is pleased to support the open source community by making libpag available.
4+
//
5+
// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
8+
// except in compliance with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// unless required by applicable law or agreed to in writing, software distributed under the
13+
// license is distributed on an "as is" basis, without warranties or conditions of any kind,
14+
// either express or implied. see the license for the specific language governing permissions
15+
// and limitations under the license.
16+
//
17+
/////////////////////////////////////////////////////////////////////////////////////////////////
18+
19+
#pragma once
20+
21+
#include "core/Stroke.h"
22+
#include "pag/file.h"
23+
24+
namespace pag {
25+
Stroke::Cap ToTGFXCap(Enum cap);
26+
27+
Stroke::Join ToTGFXJoin(Enum join);
28+
} // namespace pag

Diff for: tgfx/include/core/Stroke.h

+42-5
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,57 @@
1818

1919
#pragma once
2020

21-
#include "pag/file.h"
22-
2321
namespace pag {
2422
/**
2523
* Stroke controls options applied when stroking geometries (paths, glyphs).
2624
*/
2725
class Stroke {
2826
public:
27+
/**
28+
* Cap draws at the beginning and end of an open path contour.
29+
*/
30+
enum class Cap {
31+
/**
32+
* No stroke extension.
33+
*/
34+
Butt,
35+
/**
36+
* Adds circle
37+
*/
38+
Round,
39+
/**
40+
* Adds square
41+
*/
42+
Square
43+
};
44+
45+
/**
46+
* Join specifies how corners are drawn when a shape is stroked. Join affects the four corners
47+
* of a stroked rectangle, and the connected segments in a stroked path. Choose miter join to draw
48+
* sharp corners. Choose round join to draw a circle with a radius equal to the stroke width on
49+
* top of the corner. Choose bevel join to minimally connect the thick strokes.
50+
*/
51+
enum class Join {
52+
/**
53+
* Extends to miter limit.
54+
*/
55+
Miter,
56+
/**
57+
* Adds circle.
58+
*/
59+
Round,
60+
/**
61+
* Connects outside edges.
62+
*/
63+
Bevel
64+
};
65+
2966
Stroke() = default;
3067

3168
/**
3269
* Creates a new Stroke width specified options.
3370
*/
34-
explicit Stroke(float width, Enum cap = LineCap::Butt, Enum join = LineJoin::Miter,
71+
explicit Stroke(float width, Cap cap = Cap::Butt, Join join = Join::Miter,
3572
float miterLimit = 4.0f)
3673
: width(width), cap(cap), join(join), miterLimit(miterLimit) {
3774
}
@@ -44,12 +81,12 @@ class Stroke {
4481
/**
4582
* The geometry drawn at the beginning and end of strokes.
4683
*/
47-
Enum cap = LineCap::Butt;
84+
Cap cap = Cap::Butt;
4885

4986
/**
5087
* The geometry drawn at the corners of strokes.
5188
*/
52-
Enum join = LineJoin::Miter;
89+
Join join = Join::Miter;
5390

5491
/**
5592
* The limit at which a sharp corner is drawn beveled.

Diff for: tgfx/include/gpu/Paint.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,28 @@ class Paint {
110110
/**
111111
* Returns the geometry drawn at the beginning and end of strokes.
112112
*/
113-
Enum getLineCap() const {
113+
Stroke::Cap getLineCap() const {
114114
return stroke.cap;
115115
}
116116

117117
/**
118118
* Sets the geometry drawn at the beginning and end of strokes.
119119
*/
120-
void setLineCap(Enum cap) {
120+
void setLineCap(Stroke::Cap cap) {
121121
stroke.cap = cap;
122122
}
123123

124124
/**
125125
* Returns the geometry drawn at the corners of strokes.
126126
*/
127-
Enum getLineJoin() const {
127+
Stroke::Join getLineJoin() const {
128128
return stroke.join;
129129
}
130130

131131
/**
132132
* Sets the geometry drawn at the corners of strokes.
133133
*/
134-
void setLineJoin(Enum join) {
134+
void setLineJoin(Stroke::Join join) {
135135
stroke.join = join;
136136
}
137137

Diff for: tgfx/include/gpu/YUVTexture.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
namespace pag {
2525

26+
/**
27+
* YUVTexture wraps separate textures in the GPU backend for Y, U, and V planes.
28+
*/
2629
class YUVTexture : public Texture {
2730
public:
2831
/**

Diff for: tgfx/src/core/PathEffect.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "core/PathEffect.h"
2020
#include "core/PathRef.h"
21-
#include "pag/file.h"
21+
#include "core/Stroke.h"
2222

2323
namespace pag {
2424
using namespace pk;
@@ -58,22 +58,22 @@ class StrokePathEffect : public PathEffect {
5858
SkPaint paint = {};
5959
};
6060

61-
static SkPaint::Cap ToSkLineCap(Enum cap) {
61+
static SkPaint::Cap ToSkLineCap(Stroke::Cap cap) {
6262
switch (cap) {
63-
case LineCap::Round:
63+
case Stroke::Cap::Round:
6464
return SkPaint::kRound_Cap;
65-
case LineCap::Square:
65+
case Stroke::Cap::Square:
6666
return SkPaint::kSquare_Cap;
6767
default:
6868
return SkPaint::kButt_Cap;
6969
}
7070
}
7171

72-
static SkPaint::Join ToSkLineJoin(Enum join) {
72+
static SkPaint::Join ToSkLineJoin(Stroke::Join join) {
7373
switch (join) {
74-
case LineJoin::Round:
74+
case Stroke::Join::Round:
7575
return SkPaint::kRound_Join;
76-
case LineJoin::Bevel:
76+
case Stroke::Join::Bevel:
7777
return SkPaint::kBevel_Join;
7878
default:
7979
return SkPaint::kMiter_Join;

Diff for: tgfx/src/gpu/opengl/GLCanvas.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "gpu/ColorShader.h"
2929
#include "gpu/TextureFragmentProcessor.h"
3030
#include "gpu/TextureMaskFragmentProcessor.h"
31-
#include "pag/file.h"
3231

3332
namespace pag {
3433
GLCanvas::GLCanvas(Surface* surface) : Canvas(surface) {

0 commit comments

Comments
 (0)