• 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.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.graphics.Matrix;
22 import android.graphics.pdf.flags.Flags;
23 
24 /**
25  * Represents a page object on a page of a pdf document.
26  * This abstract class provides a base implementation for
27  * different types of PDF page objects.
28  */
29 @FlaggedApi(Flags.FLAG_ENABLE_EDIT_PDF_PAGE_OBJECTS)
30 public abstract class PdfPageObject {
31     // Possible Values are {@link PdfPageObjectType}
32     private final int mType;
33 
34     // Transformation matrix of page object
35     private Matrix mTransform;
36 
37     /**
38      * Constructor for the PageObject.
39      *
40      * @param type The type of the page object.
41      */
PdfPageObject(int type)42     PdfPageObject(int type) {
43         this.mType = type;
44         this.mTransform = new Matrix(); // Initialize with identity matrix
45     }
46 
47     /**
48      * Returns the type of the page object.
49      *
50      * @return The type of the page object.
51      */
getPdfObjectType()52     public int getPdfObjectType() {
53         return mType;
54     }
55 
56     /**
57      * Transform the page object
58      * The matrix is composed as:
59      * |a c e|
60      * |b d f|
61      * and can be used to scale, rotate, shear and translate the |page_object|.
62      */
transform(float a, float b, float c, float d, float e, float f)63     public void transform(float a, float b, float c, float d, float e, float f) {
64         Matrix matrix = new Matrix();
65         matrix.setValues(new float[]{a, e, d, c, b, f, 0, 0, 1}); // Set the matrix values
66         this.mTransform.postConcat(matrix); // Apply the transformation
67     }
68 
69     /**
70      * Returns the transformation matrix of the object.
71      *
72      * @return The transformation matrix of the object.
73      */
74     @NonNull
getMatrix()75     public float[] getMatrix() {
76         float[] value = new float[9];
77         this.mTransform.getValues(value);
78         return value;
79     }
80 
81     /**
82      * Sets the transformation matrix of the object.
83      *
84      * @param matrix The transformation matrix of the object.
85      */
setMatrix(@onNull Matrix matrix)86     public void setMatrix(@NonNull Matrix matrix) {
87         this.mTransform = matrix;
88     }
89 }
90