max-kammerer / orion-viewer

Orion Viewer is pdf, djvu, xps, cbz and tiff file viewer for Android devices based on mupdf and DjVuLibre libraries
Other
163 stars 54 forks source link

Start End Index Selection of selected text #78

Open iNuman opened 1 month ago

iNuman commented 1 month ago

@max-kammerer is there a ways that I can get the selected texts start and end index as my requirement is I've to search for specific word base on startIndex.

max-kammerer commented 1 month ago

is there a ways that I can get the selected texts start and end index as my requirement is I've to search for specific word base on startIndex.

@iNuman You could look into TextExtractor.kt file, but here you can work just with absolute positions. Text layout in pdf and djvu files are quite complicated, you can see also some details in Djvu/PdfDocument.getText() method and related native support in djvulibre and mupdf libraries.

What feature do you try to implement?

iNuman commented 1 month ago

@max-kammerer Thanks, I added some alterations to TextExtractor class I can now get the start point of selected Text Basically I've comments feature a user can select text and add that text as comment api accepts and returns commented text, start index later one can Click on that comment and user will be move to that selected text and that specific text text will be highlighted. Currently for search it works fine if the all words on page are unique but problem arises when there are multiple occurrences of text it'll highlight all occurrences. Is there anything on the search method i can update so that the rectangle will only draw if the start index matches with text in page

Note: I've made a method using which I can get the whole page Text as well. Any ideas or help will be appreciated. Thank you.

max-kammerer commented 1 month ago

Let's start with discussing and defining feature that you want to implement.

iNuman commented 1 month ago

@max-kammerer

Let's start with discussing and defining feature that you want to implement.

Sure letme know is there any platform like slack, discord where we can discuss stuff?

max-kammerer commented 1 month ago

Sure letme know is there any platform like slack, discord where we can discuss stuff?

@iNuman we can discuss here or by e-mail.

iNuman commented 1 week ago

@max-kammerer I have multiple uris' for single pdf due to maintenance of pagination and performance e.g

but the method below accepts single file uri at time do you have any idea how can i combine the above multiple uri's and pass it to below openFile method? Any help or idea will be appreciated.

  private fun openFile(file: File) {

        GlobalScope.launch(Dispatchers.Main) {
            log("Trying to open file: $file")
            val rootJob = Job()
            val executor = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
            val newDocument = try {
                withContext(executor + rootJob) {
                    FileUtil.openFile(file)
                }
            } catch (e: Exception) {
                executor.close()
                return@launch
            }

            try {
                if (newDocument.pageCount == 0) {
                    newDocument.destroy()
                    return@launch
                }

                val layoutStrategy = SimpleLayoutStrategy.create()
                val controller1 = Controller(
                    this@PdfFragment,
                    newDocument,
                    layoutStrategy,
                    rootJob,
                    context = executor
                )

                val lastPageInfo1 = loadBookParameters(rootJob, file)
                log("Read LastPageInfo for page ${lastPageInfo1.pageNumber}")
                lastPageInfo = lastPageInfo1
                currentBookParameters = lastPageInfo1

                controller = controller1
                bind(binding.view, controller1)

                updateViewOnNewBook((newDocument.title?.takeIf { it.isNotBlank() }
                    ?: file.name.substringBeforeLast(".")))

                val drawView = fullScene.drawView
                controller1.init(lastPageInfo1, drawView.sceneWidth, drawView.sceneHeight)

                subscriptionManager.sendDocOpenedNotification(controller1)

                lastPageInfo1.totalPages = newDocument.pageCount
                onNewBook(file.name)
                doOnLayout(lastPageInfo1)
            } catch (e: Exception) {
                if (controller != null) {
                    log("Exception for page ${e.printStackTrace()}")

                    destroyController()
                } else {
                    newDocument.destroy()
                }
            } finally {
//                 orionApplication.idlingRes.free()
            }
        }
    }

`