informatics-isi-edu / openseadragon-viewer

2D viewer with openseadragon
Apache License 2.0
5 stars 2 forks source link

Font size logic for text drawing #103

Open RFSH opened 1 year ago

RFSH commented 1 year ago

As part of #102, we're adding a text drawing tool. The following is how it works:

  1. Clicking on the "text box " option should activate the text drawing mode.
  2. Users can click anywhere on the page.
  3. After clicking on the page, a blinking icon should appear, indicating that we're waiting for user input and a border box showing where the text will be added.
  4. Given that we're drawing for a specific zoom level, should zoom be disabled?
  5. As the user starts typing, we should show the typed text to the users.

During drawing,

In this issue, we want to explore the heuristics for the default font size and allow users to pick a meaningful font value. We should try to come up with uniform heuristics, so users pick font size values that they are familiar with (12px, 14px) and not the actual pixel size we'll show on the image (we would have to pick 1000px font size for images with multiple zoom levels).

Should the font size heuristics be absolute or relative to the zoom level? In both cases, we would have to factor in the image's size (width/height).

Based on this, we will try the "absolute" method first. We should see if we can develop a heuristic that makes sense for an image with 7 allowed zoom levels. And then see if the same heuristics make sense when we have only 2-3 zoom levels.

The following are the things that came up during the discussion:

nikhiilll commented 1 year ago

For the font-size functionality we are going to try two different ways:

  1. Absolute font-size
  2. Relative font-size(takes zoom into account)

Absolute Font-size For this functionality, we need a mapping between the image font-size and the font-size outside the OpenSeadragon viewer application. This is needed because the pixel density of the images can be very high or low as compared to the rest of the web application. To achieve this we use the OpenSeadragon viewport container size and the dimensions of the image. The formula used to achieve this mapping is:

mappingRatio = max(imageWidth/containerWidth, imageHeight/containerHeight)

We then use this mapping ratio and multiply it by the user selected font-size to obtain the image font-size that would look like regular font-size. Other relative attributes use this font-size as well.

Relative Font-size The idea is to basically incorporate the zoom level, so that the font-size would look same as the web application at all the zoom levels. I'm trying a few approaches for this:

  1. Take the current zoom level and the original zoom level to obtain the size of the image that is displayed. This requires some calculations using the original image size of the image. However, in this approach the zoom levels returned by the OpenSeadragon viewer are not absolute and seem to be calculated somwhat arbitrarily right now.
  2. The other approach is to obtain the image size displayed directly from the OpenSeadragon library. However, no in-built functionality exists for this. So, I'm trying to find the dimensions of the image shown in the image viewport using the viewport dimensions, zoom level, original image, the curren position on the image and much more.

One of these two approaches should work. I'm currently working on this.

nikhiilll commented 1 year ago

Relative Font-size As mentioned in the previous comment, the second proposed method did not work. As we are using multi-image configuration for the OSD viewer application, the values returned by the OSD viewer functions is not accurate and reliable. I went ahead with the first method. In order to obtain the current zoom level, we are taking the current zoom level of the viewport object of the OSD viewer. We are also retrieving the default zoom level that we set while creating the OSD viewer object that is used at the start when the image is loaded. Using the default zoom and the current zoom we calculate a zoom ratio that provides us information about how zoomed-in or zoomed-out an image is. We then use this zoom ratio in the calculations of the font-size formula.

zoomRatio = defaultZoom/currentZoom
mappingRatio = max(imageWidth/containerWidth, imageHeight/containerHeight)
fontSize = currentFontSize * mappingRatio * zoomRatio
RFSH commented 1 year ago

We had a conversation about this, and the following is the summary of what we talked about:

The following are other improvements that came up as part of this discussion:

RFSH commented 1 year ago

We've implemented the "absolute" method that is described above. We should discuss whether we need to make any changes to this logic.