1 /* 2 * Copyright 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 androidx.pdf.service 18 19 import android.graphics.Bitmap 20 import android.graphics.pdf.PdfRenderer 21 import android.graphics.pdf.content.PdfPageGotoLinkContent 22 import android.graphics.pdf.content.PdfPageImageContent 23 import android.graphics.pdf.content.PdfPageLinkContent 24 import android.graphics.pdf.content.PdfPageTextContent 25 import android.graphics.pdf.models.PageMatchBounds 26 import android.graphics.pdf.models.selection.PageSelection 27 import android.graphics.pdf.models.selection.SelectionBoundary 28 import android.os.Build 29 import androidx.annotation.RequiresApi 30 import androidx.annotation.RequiresExtension 31 import androidx.annotation.RestrictTo 32 33 @RestrictTo(RestrictTo.Scope.LIBRARY) 34 @RequiresExtension(extension = Build.VERSION_CODES.S, version = 13) 35 @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) 36 internal class PdfPageWrapperPostV(private val page: PdfRenderer.Page) : PdfPageWrapper { 37 38 override val height = page.height 39 override val width = page.width 40 renderPagenull41 override fun renderPage(bitmap: Bitmap) { 42 page.render(bitmap, null, null, getRenderParams()) 43 } 44 renderTilenull45 override fun renderTile( 46 bitmap: Bitmap, 47 left: Int, 48 top: Int, 49 scaledPageWidth: Int, 50 scaledPageHeight: Int 51 ) { 52 val transformationMatrix = 53 getTransformationMatrix( 54 left, 55 top, 56 scaledPageWidth.toFloat(), 57 scaledPageHeight.toFloat(), 58 width, 59 height 60 ) 61 page.render(bitmap, null, transformationMatrix, getRenderParams()) 62 } 63 getPageTextContentsnull64 override fun getPageTextContents(): List<PdfPageTextContent> { 65 return page.textContents 66 } 67 getPageImageContentsnull68 override fun getPageImageContents(): List<PdfPageImageContent> { 69 return page.imageContents 70 } 71 selectPageTextnull72 override fun selectPageText(start: SelectionBoundary, stop: SelectionBoundary): PageSelection? { 73 return page.selectContent(start, stop) 74 } 75 searchPageTextnull76 override fun searchPageText(query: String): List<PageMatchBounds> { 77 return page.searchText(query) 78 } 79 getPageLinksnull80 override fun getPageLinks(): List<PdfPageLinkContent> { 81 return page.linkContents 82 } 83 getPageGotoLinksnull84 override fun getPageGotoLinks(): List<PdfPageGotoLinkContent> { 85 return page.gotoLinks 86 } 87 closenull88 override fun close() { 89 page.close() 90 } 91 } 92