Flutter Engine
The 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
5#include "flutter/lib/ui/painting/path_measure.h"
6
7#include <cmath>
8
9#include "flutter/lib/ui/floating_point.h"
10#include "flutter/lib/ui/painting/matrix.h"
11#include "flutter/lib/ui/ui_dart_state.h"
16
17namespace flutter {
18
19typedef CanvasPathMeasure PathMeasure;
20
22
24 const CanvasPath* path,
25 bool forceClosed) {
28 fml::MakeRefCounted<CanvasPathMeasure>();
29 if (path) {
30 const SkPath& skPath = path->path();
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 const SkPath& skPath = path->path();
46 path_measure_->reset(skPath, isClosed);
47}
48
49double CanvasPathMeasure::getLength(int contour_index) {
50 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
51 contour_index) < measures_.size()) {
52 return measures_[contour_index]->length();
53 }
54 return -1;
55}
56
57tonic::Float32List CanvasPathMeasure::getPosTan(int contour_index,
58 double distance) {
59 tonic::Float32List posTan(Dart_NewTypedData(Dart_TypedData_kFloat32, 5));
60 posTan[0] = 0; // dart code will check for this for failure
61 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
62 contour_index) >= measures_.size()) {
63 return posTan;
64 }
65
67 SkVector tan;
68 float fdistance = SafeNarrow(distance);
69 bool success = measures_[contour_index]->getPosTan(fdistance, &pos, &tan);
70
71 if (success) {
72 posTan[0] = 1; // dart code will check for this for success
73 posTan[1] = pos.x();
74 posTan[2] = pos.y();
75 posTan[3] = tan.x();
76 posTan[4] = tan.y();
77 }
78
79 return posTan;
80}
81
83 int contour_index,
84 double start_d,
85 double stop_d,
86 bool start_with_move_to) {
87 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
88 contour_index) >= measures_.size()) {
89 CanvasPath::Create(path_handle);
90 }
91 SkPath dst;
92 bool success = measures_[contour_index]->getSegment(
93 SafeNarrow(start_d), SafeNarrow(stop_d), &dst, start_with_move_to);
94 if (!success) {
95 CanvasPath::Create(path_handle);
96 } else {
97 CanvasPath::CreateFrom(path_handle, dst);
98 }
99}
100
101bool CanvasPathMeasure::isClosed(int contour_index) {
102 if (static_cast<std::vector<sk_sp<SkContourMeasure>>::size_type>(
103 contour_index) < measures_.size()) {
104 return measures_[contour_index]->isClosed();
105 }
106 return false;
107}
108
110 auto measure = path_measure_->next();
111 if (measure) {
112 measures_.push_back(std::move(measure));
113 return true;
114 }
115 return false;
116}
117
118} // namespace flutter
SkPoint pos
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 CreateFrom(Dart_Handle path_handle, const SkPath &src)
Definition path.h:25
static fml::RefPtr< CanvasPath > Create(Dart_Handle wrapper)
Definition path.h:31
static void ThrowIfUIOperationsProhibited()
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
@ Dart_TypedData_kFloat32
Definition dart_api.h:2614
DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, intptr_t length)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
float SkScalar
Definition extension.cpp:12
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 switches.h:57
static float SafeNarrow(double value)
CanvasPathMeasure PathMeasure
Definition dart_ui.cc:56
constexpr float y() const
constexpr float x() const