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.cts.module; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.graphics.Bitmap; 22 import android.graphics.Matrix; 23 import android.graphics.pdf.component.PdfPageImageObject; 24 import android.graphics.pdf.component.PdfPageObjectType; 25 import android.graphics.pdf.flags.Flags; 26 import android.platform.test.annotations.RequiresFlagsEnabled; 27 import android.platform.test.flag.junit.CheckFlagsRule; 28 import android.platform.test.flag.junit.DeviceFlagsValueProvider; 29 30 import androidx.test.runner.AndroidJUnit4; 31 32 import org.junit.Rule; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 36 @RunWith(AndroidJUnit4.class) 37 @RequiresFlagsEnabled(Flags.FLAG_ENABLE_EDIT_PDF_PAGE_OBJECTS) 38 public class PdfPageImageObjectTest { 39 40 @Rule 41 public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); 42 43 private static final Bitmap BITMAP = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); 44 private static final Bitmap NEW_BITMAP = Bitmap.createBitmap(5, 5, Bitmap.Config.ARGB_8888); 45 private static final Matrix MATRIX = new Matrix(); 46 47 @Test testPdfPageImageObject()48 public void testPdfPageImageObject() { 49 PdfPageImageObject pdfPageImageObject = new PdfPageImageObject(BITMAP); 50 assertThat(pdfPageImageObject.getBitmap()).isEqualTo(BITMAP); 51 assertThat(pdfPageImageObject.getPdfObjectType()).isEqualTo(PdfPageObjectType.IMAGE); 52 53 pdfPageImageObject.setBitmap(NEW_BITMAP); 54 assertThat(pdfPageImageObject.getBitmap()).isEqualTo(NEW_BITMAP); 55 56 assertThat(pdfPageImageObject.getMatrix()) 57 .isEqualTo(new float[] {1, 0, 0, 0, 1, 0, 0, 0, 1}); 58 59 float[] expectedMatrixArray = {1, 2, 3, 4, 5, 6, 0, 0, 1}; 60 MATRIX.setValues(expectedMatrixArray); 61 pdfPageImageObject.setMatrix(MATRIX); 62 63 float[] receivedArray = pdfPageImageObject.getMatrix(); 64 assertThat(receivedArray.length).isEqualTo(expectedMatrixArray.length); 65 66 for (int i = 0; i < receivedArray.length; i++) { 67 assertThat(receivedArray[i]).isEqualTo(expectedMatrixArray[i]); 68 } 69 } 70 71 @Test testPageObjectTransform()72 public void testPageObjectTransform() { 73 PdfPageImageObject pdfPageImageObject = new PdfPageImageObject(BITMAP); 74 75 float a = 0.0F, b = 1.0F, c = 2.0F, d = 3.0F, e = 4.0F, f = 5.0F; 76 float[] expectedMatrix = {a, e, d, c, b, f, 0, 0, 1}; 77 pdfPageImageObject.transform(a, b, c, d, e, f); 78 79 float[] transformedMatrix = pdfPageImageObject.getMatrix(); 80 assertThat(expectedMatrix.length).isEqualTo(transformedMatrix.length); 81 for (int i = 0; i < expectedMatrix.length; i++) { 82 assertThat(expectedMatrix[i]).isEqualTo(transformedMatrix[i]); 83 } 84 } 85 } 86