From 099df171a38af938e79459d6d0100cbb4dae43da Mon Sep 17 00:00:00 2001 From: wangwei Date: Thu, 31 Oct 2024 11:16:53 +0800 Subject: [PATCH] pathiterator_ww Signed-off-by: wangwei --- graphic/graphic_2d/native_drawing/BUILD.gn | 1 + .../graphic_2d/native_drawing/drawing_path.h | 16 ++ .../native_drawing/drawing_path_iterator.h | 137 ++++++++++++++++++ .../graphic_2d/native_drawing/drawing_types.h | 8 + .../native_drawing/libnative_drawing.ndk.json | 24 +++ 5 files changed, 186 insertions(+) create mode 100644 graphic/graphic_2d/native_drawing/drawing_path_iterator.h diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index 88c0459bc..126bcd294 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -36,6 +36,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_memory_stream.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path_effect.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_path_iterator.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_pen.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_pixel_map.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_point.h", diff --git a/graphic/graphic_2d/native_drawing/drawing_path.h b/graphic/graphic_2d/native_drawing/drawing_path.h index e10ef145a..507768336 100644 --- a/graphic/graphic_2d/native_drawing/drawing_path.h +++ b/graphic/graphic_2d/native_drawing/drawing_path.h @@ -40,6 +40,7 @@ * @version 1.0 */ +#include "drawing_error_code.h" #include "drawing_types.h" #ifdef __cplusplus @@ -677,6 +678,21 @@ bool OH_Drawing_PathOp(OH_Drawing_Path* path, const OH_Drawing_Path* other, OH_D bool OH_Drawing_PathGetMatrix(OH_Drawing_Path* path, bool forceClosed, float distance, OH_Drawing_Matrix* matrix, OH_Drawing_PathMeasureMatrixFlags flag); +/** + * @brief Get pathIterator from path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param path Indicates the pointer to an OH_Drawing_Path object. + * @param iter Indicates the pointer to an OH_Drawing_PathIterator object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if path or iter is nullptr. + * @since 14 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PathGetPathIterator(OH_Drawing_Path* path, OH_Drawing_PathIterator* iter); + + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_path_iterator.h b/graphic/graphic_2d/native_drawing/drawing_path_iterator.h new file mode 100644 index 000000000..afe802ef0 --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_path_iterator.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_PATH_ITERATOR_H +#define C_INCLUDE_DRAWING_PATH_ITERATOR_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 8 + * @version 1.0 + */ + +/** + * @file drawing_path_iterator.h + * + * @brief Declares functions related to the path object in the drawing module. + * + * @since 14 + * @version 1.0 + */ + +#include "drawing_error_code.h" +#include "drawing_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Types of operation for the path. + * + * @since 14 + * @version 1.0 + */ +typedef enum { + /** move operation */ + PATHITERATOR_VERB_MOVE, + /** line operation */ + PATHITERATOR_VERB_LINE, + /** quad operation */ + PATHITERATOR_VERB_QUAD, + /** conic operation */ + PATHITERATOR_VERB_CONIC, + /** cubic operation */ + PATHITERATOR_VERB_CUBIC, + /** close operation */ + PATHITERATOR_VERB_CLOSE, + /** all operations done */ + PATHITERATOR_VERB_DONE = PATHITERATOR_VERB_CLOSE + 1 +} OH_Drawing_PathIteratorVerb; + +/** + * @brief Creates an OH_Drawing_PathIterator object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @return Returns the pointer to the OH_Drawing_PathIterator object created. + * @since 14 + * @version 1.0 + */ +OH_Drawing_PathIterator* OH_Drawing_PathIteratorCreate(void); + +/** + * @brief Creates an OH_Drawing_PathIterator object with path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Path Indicates the pointer to an OH_Drawing_Path object. + * @return Returns the pointer to the OH_Drawing_PathIterator object created. + * @since 14 + * @version 1.0 + */ +OH_Drawing_PathIterator* OH_Drawing_PathIteratorCreateWithPath(OH_Drawing_Path* path); + +/** + * @brief Destroys an OH_Drawing_PathIterator object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_PathIterator Indicates the pointer to an OH_Drawing_PathIterator object. + * @since 14 + * @version 1.0 + */ +void OH_Drawing_PathIteratorDestroy(OH_Drawing_PathIterator* iter); + +/** + * @brief Get next verb in this iterator's path, and fill entries in the point2D array + * with point data (if any) for that operation, the point2D array size must be 4 or more. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_PathIterator Indicates the pointer to an OH_Drawing_PathIterator object. + * @param OH_Drawing_Point2D Indicates the pointer to an OH_Drawing_Point2D object. + * @param count Indicates the array size of the point2D. + * @param verb Indicates the next verb in this iterator's path. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if count < 4, iter, points or verb is nullptr. + * @since 14 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PathIteratorNext(OH_Drawing_PathIterator* iter, + OH_Drawing_Point2D* points, const uint32_t count, OH_Drawing_PathIteratorVerb* verb); + +/** + * @brief Ger the next verb in the iteration, or PATHITERATOR_VERB_DONE if there are no more elements. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_PathIterator Indicates the pointer to an OH_Drawing_PathIterator object. + * @param verb Indicates the next verb in the iteration. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if iter or verb is nullptr. + * @since 14 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PathIteratorPeek(OH_Drawing_PathIterator* iter, OH_Drawing_PathIteratorVerb* verb); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index 1a4d8499c..e3e59308a 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -89,6 +89,14 @@ typedef struct OH_Drawing_Brush OH_Drawing_Brush; */ typedef struct OH_Drawing_Path OH_Drawing_Path; +/** + * @brief Defines a iterator, which is used to query a given path, to discover operations and point values. + * + * @since 14 + * @version 1.0 + */ +typedef struct OH_Drawing_PathIterator OH_Drawing_PathIterator; + /** * @brief Defines a bitmap, which is a memory that contains the pixel data of a shape. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index 353ce3f53..abb491226 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -438,6 +438,30 @@ "first_introduced": "12", "name": "OH_Drawing_PathGetBounds" }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathGetPathIterator" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathIteratorCreate" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathIteratorDestroy" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathIteratorCreateWithPath" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathIteratorNext" + }, + { + "first_introduced": "14", + "name": "OH_Drawing_PathIteratorPeek" + }, { "first_introduced": "12", "name": "OH_Drawing_PathGetLength" -- Gitee