mupdf.js icon indicating copy to clipboard operation
mupdf.js copied to clipboard

Annotation: Support for get/set rich media attributes on text

Open jamie-lemon opened this issue 1 year ago • 4 comments

Adobe supply this kind of widget in their UI to style annotation text:

Screenshot 2024-03-07 at 17 34 10

However we are unable to read/write to these rich media objects.

jamie-lemon avatar Mar 07 '24 17:03 jamie-lemon

@ccxvii I think the "text alignment" value that is often required is the text alignment set from this kind of rich media.

If I try getQuadding() with the current API on annotation text which has its text alignment changed this way it always returns 0.

jamie-lemon avatar Mar 18 '24 23:03 jamie-lemon

We support rendering rich media styled text in mupdf core, BUT ONLY IF it is built to include the HTML engine.

  1. We do not build the HTML engine for WASM, as this adds a lot of bloat to the binary.

  2. The rich style property (RS) is essentially a string of CSS property syntax, which is applied to the rich content (RC) which is a subset of HTML syntax. In theory any changes to the RS and RC should also be reflected into the basic non-rich style properties that we already support. This is not an easy task, because to do so we'd need to parse, generate, and EDIT both CSS and HTML content using the proposed functions.

Parsing we can currently do with the HTML engine, but only enough to get us rendered content. Editing the HTML and CSS is far out of scope for our HTML layout engine.

I suggest we close this as WONTFIX.

ccxvii avatar Aug 13 '24 15:08 ccxvii

Is there currently a way of adding text alignment properties to the insertText() method? It doesn't look like from the docs. A nice implementation with using the already present type Point = [x: number, y: number] would be to:

  • Align left naturally uses x as the starting point
  • Align center uses x as the middle point that is based on the full width of the text. (If x is 100 and the text width is 25, then 12.5 of the text goes before the x and the remaining goes after)
  • Align right uses x as the right most place for the text. (If x is 100 and the text width is 25, then no text is present after x === 100 and the right most part of the last char of the text is at x === 100

Something like:

mupdfJSPage.insertText("Hello world!",
               [100,100],
               alignRight,
               "Times-Roman",
               24);

Not really interested in this one but

  • Justify would need a (x and max width) OR (x1 and x2) approach I think? The former might be better to avoid confusion and still rely on the currently implemented point parameter

MrVoshel avatar Mar 05 '25 22:03 MrVoshel

Is there currently a way of adding text alignment properties to the insertText() method? It doesn't look like from the docs. A nice implementation with using the already present type Point = [x: number, y: number] would be to:

* **Align left** naturally uses `x` as the starting point

* **Align center** uses `x` as the middle point that is based on the full width of the text. (If `x` is 100 and the text width is 25, then 12.5 of the text goes before the `x` and the remaining goes after)

* **Align right** uses `x` as the right most place for the text. (If `x` is 100 and the text width is 25, then no text is present after `x === 100` and the right most part of the last char of the text is at `x === 100`

Something like:

mupdfJSPage.insertText("Hello world!",
               [100,100],
               alignRight,
               "Times-Roman",
               24);

Not really interested in this one but

* **Justify** would need a (`x` and `max width`) OR (`x1` and `x2`) approach I think? The former might be better to avoid confusion and still rely on the currently implemented point parameter

I need this as well. Would there maybe be a way to calculate the width of a single glyph of a specified font family and size? If so, then this would be implementable by summing together the glyph widths + the letter spacing * (glyph count - 1), which would yield the entire width and then just subtracting this entire width from the x coordinate.

lbirkert avatar Mar 14 '25 05:03 lbirkert