We make extensive use of Java Page co-ordinates in JPedal, which we convert both into PDF co-ordinates and also relative offsets. I have been changing this code recently and it has been anything but straight-forward so I have recorded my experiences. I hope you find them helpful.
With the expansion of the search functionality to the multipage views the next logical step is to allow the user to manually select text to highlight using the mouse.
To begin with this looked like a relatively simple task as we have saved the displayed text on page area and since the search code was expanded we can now store highlighted areas for multiple pages. Surely it’s just a matter of finding the area dragged with the mouse on the component and comparing it to the stored text areas. Simple, yes?
Well actually no. Things are never as simple as they appear are they. There were bound to be complications.
First, all the original highlight code was written for single display mode. The methods to handle highlighting via the mouse or, originally, any other form of highlight whether it be pro grammatically or via the mouse. The code would attempt to highlight only those areas that are within the specified area on the current page from when you began the highlighting. This would not allow for multiple pages. This admittedly was simple enough to solve. Modifying the listener to pass through the current page was no big step. From here we go to the addHighlights method and allow for highlight areas spreading across pages by comparing page offsets with the highlight area and applying the area for each overlapped page separately.
Still however the functionality is refusing to function correctly. This is because the coordinates for the text is based on the page area using the pages x and y values as it’s 0,0. Now when we pass through the coords the highlighting fails unless you are on the first page as we are comparing the mouse dragged area on the component with the position on page.
The next step is to remove the page offsets from the mouse in order to get the mouse dragged area as on page coordinates. This caused further complications was the offsets have various values applied to it that need to be taken into account such as page insets, scaling and DPI of the page.
So far we have highlighting in continuous mode using the mouse. The functionality may be functioning correctly but there are still some issues with the highlight coordinates.
Another article will be posted when the final issues have been resolved and the functionality is ready for release.
Watch this space.
Latest posts by Kieran France (see all)
- How Java 10 will improve performance - April 17, 2018
- Pros and Cons of Bitbucket Pipelines - March 15, 2018
- Off Screen Rendering Improvements to JPedal Viewer - February 2, 2018
- How to use Cipher streams in Java - January 10, 2018
- Improved Shape Rendering with Soft Clipping - August 24, 2017