• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics.pdf.component;
18 
19 import android.annotation.ColorInt;
20 import android.annotation.FlaggedApi;
21 import android.annotation.NonNull;
22 import android.graphics.Path;
23 import android.graphics.pdf.flags.Flags;
24 
25 /**
26  * Represents a path object on a PDF page. This class extends
27  * {@link PdfPageObject} and provides methods to access and modify the
28  * path's content, such as its shape, fill color, stroke color and line width.
29  */
30 @FlaggedApi(Flags.FLAG_ENABLE_EDIT_PDF_PAGE_OBJECTS)
31 public final class PdfPagePathObject extends PdfPageObject {
32     private final Path mPath;
33     private @ColorInt int mStrokeColor;
34     private float mStrokeWidth;
35     private @ColorInt int mFillColor;
36     private @PdfPageObjectRenderMode.Type int mRenderMode;
37 
38     /**
39      * Constructor for the PdfPagePathObject. Sets the object type
40      * to {@link PdfPageObjectType#PATH}.
41      */
PdfPagePathObject(@onNull Path path)42     public PdfPagePathObject(@NonNull Path path) {
43         super(PdfPageObjectType.PATH);
44         this.mPath = path;
45         this.mRenderMode = PdfPageObjectRenderMode.FILL;
46     }
47 
48     /**
49      * Returns the path of the object.
50      * The returned path object might be an approximation of the one used to
51      * create the original one if the original object has elements with curvature.
52      * <p>
53      * Note: The path is immutable because the underlying library does
54      * not allow modifying the path once it is created.
55      *
56      * @return The path.
57      */
58     @NonNull
toPath()59     public Path toPath() {
60         return new Path(mPath);
61     }
62 
63     /**
64      * Returns the stroke color of the object.
65      *
66      * @return The stroke color of the object.
67      */
getStrokeColor()68     public @ColorInt int getStrokeColor() {
69         return mStrokeColor;
70     }
71 
72     /**
73      * Sets the stroke color of the object.
74      *
75      * @param strokeColor The stroke color of the object.
76      */
setStrokeColor(@olorInt int strokeColor)77     public void setStrokeColor(@ColorInt int strokeColor) {
78         this.mStrokeColor = strokeColor;
79     }
80 
81     /**
82      * Returns the stroke width of the object.
83      *
84      * @return The stroke width of the object.
85      */
getStrokeWidth()86     public float getStrokeWidth() {
87         return mStrokeWidth;
88     }
89 
90     /**
91      * Sets the stroke width of the object.
92      *
93      * @param strokeWidth The stroke width of the object.
94      */
setStrokeWidth(float strokeWidth)95     public void setStrokeWidth(float strokeWidth) {
96         this.mStrokeWidth = strokeWidth;
97     }
98 
99     /**
100      * Returns the fill color of the object.
101      *
102      * @return The fill color of the object.
103      */
getFillColor()104     public @ColorInt int getFillColor() {
105         return mFillColor;
106     }
107 
108     /**
109      * Sets the fill color of the object.
110      *
111      * @param fillColor The fill color of the object.
112      */
setFillColor(@olorInt int fillColor)113     public void setFillColor(@ColorInt int fillColor) {
114         this.mFillColor = fillColor;
115     }
116 
117     /**
118      * Returns the {@link PdfPageObjectRenderMode} of the object.
119      * Returns {@link PdfPageObjectRenderMode#FILL} by default
120      * if {@link PdfPagePathObject#mRenderMode} is not set.
121      *
122      * @return The {@link PdfPageObjectRenderMode} of the object.
123      */
getRenderMode()124     public @PdfPageObjectRenderMode.Type int getRenderMode() {
125         return mRenderMode;
126     }
127 
128     /**
129      * Sets the {@link PdfPageObjectRenderMode} of the object.
130      *
131      * @param renderMode The {@link PdfPageObjectRenderMode} to be set.
132      */
setRenderMode(@dfPageObjectRenderMode.Type int renderMode)133     public void setRenderMode(@PdfPageObjectRenderMode.Type int renderMode) {
134         mRenderMode = renderMode;
135     }
136 }
137