Flutter Engine
 
Loading...
Searching...
No Matches
path_measure.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cmath>
8
16
17namespace flutter {
18
19typedef CanvasPathMeasure PathMeasure;
20
22
23void CanvasPathMeasure::Create(Dart_Handle wrapper,
24 const CanvasPath* path,
25 bool forceClosed) {
28 fml::MakeRefCounted<CanvasPathMeasure>();
29 if (path) {
30 const SkPath& skPath = path->path().GetSkPath();
31 SkScalar resScale = 1;
32 pathMeasure->path_measure_ =
33 std::make_unique<SkContourMeasureIter>(skPath, forceClosed, resScale);
34 } else {
35 pathMeasure->path_measure_ = std::make_unique<SkContourMeasureIter>();
36 }
37 pathMeasure->AssociateWithDartWrapper(wrapper);
38}
39
40CanvasPathMeasure::CanvasPathMeasure() {}
41
43
44void CanvasPathMeasure::setPath(const CanvasPath* path, bool isClosed) {
45 path_measure_->reset(path->path().GetSkPath(), isClosed);
46}
47
48double CanvasPathMeasure::getLength(int contour_index) {
49 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
50 contour_index) < measures_.size()) {
51 return measures_[contour_index]->length();
52 }
53 return -1;
54}
55
56tonic::Float32List CanvasPathMeasure::getPosTan(int contour_index,
57 double distance) {
58 tonic::Float32List posTan(Dart_NewTypedData(Dart_TypedData_kFloat32, 5));
59 posTan[0] = 0; // dart code will check for this for failure
60 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
61 contour_index) >= measures_.size()) {
62 return posTan;
63 }
64
65 SkPoint pos;
66 SkVector tan;
67 float fdistance = SafeNarrow(distance);
68 bool success = measures_[contour_index]->getPosTan(fdistance, &pos, &tan);
69
70 if (success) {
71 posTan[0] = 1; // dart code will check for this for success
72 posTan[1] = pos.x();
73 posTan[2] = pos.y();
74 posTan[3] = tan.x();
75 posTan[4] = tan.y();
76 }
77
78 return posTan;
79}
80
81void CanvasPathMeasure::getSegment(Dart_Handle path_handle,
82 int contour_index,
83 double start_d,
84 double stop_d,
85 bool start_with_move_to) {
86 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
87 contour_index) >= measures_.size()) {
88 CanvasPath::Create(path_handle);
89 }
90 SkPath dst;
91 bool success = measures_[contour_index]->getSegment(
92 SafeNarrow(start_d), SafeNarrow(stop_d), &dst, start_with_move_to);
93 if (!success) {
94 CanvasPath::Create(path_handle);
95 } else {
96 CanvasPath::CreateFrom(path_handle, dst);
97 }
98}
99
100bool CanvasPathMeasure::isClosed(int contour_index) {
101 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
102 contour_index) < measures_.size()) {
103 return measures_[contour_index]->isClosed();
104 }
105 return false;
106}
107
109 auto measure = path_measure_->next();
110 if (measure) {
111 measures_.push_back(std::move(measure));
112 return true;
113 }
114 return false;
115}
116
117} // namespace flutter
static void CreateFrom(Dart_Handle path_handle, const SkPath &src)
Definition path.h:25
static fml::RefPtr< CanvasPath > Create(Dart_Handle wrapper)
Definition path.h:31
bool isClosed(int contour_index)
void setPath(const CanvasPath *path, bool isClosed)
void getSegment(Dart_Handle path_handle, int contour_index, double start_d, double stop_d, bool start_with_move_to)
const SkContourMeasureIter & pathMeasure() const
double getLength(int contour_index)
static void Create(Dart_Handle wrapper, const CanvasPath *path, bool forceClosed)
tonic::Float32List getPosTan(int contour_index, double distance)
static void ThrowIfUIOperationsProhibited()
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switch_defs.h:52
static float SafeNarrow(double value)
CanvasPathMeasure PathMeasure
Definition dart_ui.cc:52