itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

Cannot see text rendered with font embedded during same iModel session

Open Alfonso-Martello opened this issue 1 year ago • 6 comments

Describe the bug If you embed a font file into an iModel and then attempt to render text with that newly embedded font, the text does not appear.

Only if you close and then reopen the iModel/application does text render with the newly embedded font appear.

To Reproduce I have pushed a branch called fontRenderIssue. It contains a minimal reproduction in display-test-app.

Steps to reproduce behavior:

  1. Checkout the branch fontRenderIssue.
  2. Start display-test-app.
  3. Open the provided .bim file. Download bim.
  4. Swap to the view called "fontRenderIssue".
  5. Initialize the text with dta text init 0x20000000015.
  6. Set the font to Arial with dta text font "Arial".
  7. Render some text with dta text text "Behold, this is text".
  8. Embed one of the 5 open-source fonts added to the git branch. You will need to provide the absolute path to the font file. a. dta text embed "<path-to-your-dta>\public\Fonts\render-issue-fonts\ABeeZee-regular.ttf" b. dta text embed "<path-to-your-dta>\public\Fonts\render-issue-fonts\Big Shoulders Stencil Text-regular.ttf" c. dta text embed "<path-to-your-dta>\public\Fonts\render-issue-fonts\Emblema One-regular.ttf" d. dta text embed "<path-to-your-dta>\public\Fonts\render-issue-fonts\Raleway Dots-regular.ttf" e. dta text embed "<path-to-your-dta>\public\Fonts\render-issue-fonts\Roboto Serif-regular.ttf"
  9. Switch to the newly embedded font. From this point on, the example reproduction will assume you embedded Big Shoulders Stencil Text. dta text font "Big Shoulders Stencil Text"
  10. Attempt to render text with the newly embedded font. dta text text "This is new text".
  11. Observe that you do not see any new text.
  12. Close and then reopen display-test-app.
  13. Repeat steps 3 -7, skip step 8, then repeat steps 9-10.
  14. See that text now renders with the font embedded during the previous session.

Expected behavior After a font is embedded into the iModel, you should be able to render text with the embedded font immediately.

Screenshots In the drawing production test app

  • Text in Arial font:

Image

  • Selecting a new font (“Courier New”). This embeds the font:

Image

  • Observe that the text has disappeared

Image

  • After closing and reopening the iModel, text appears as a strange rectangle:

Image

  • Clicking on text causes produceTextAnnotationGeometry to fire. Text now renders with newly embedded font:

Image

In display-test-app

  • Text in Arial font:

Image

  • Adding text "This is new text" in Big Shoulders Stencil Text font after embedding (cannot see new text):

Image

  • After closing and re-opening display-test-app, text now renders with newly embedded font:

Image

Desktop (please complete the applicable information):

  • OS: Windows 11
  • Browser: Electron
  • iTwin.js Version: Most recent. Issue exists on master branch.

Additional context

  • The Uint8Array produced by requestElementGraphics is very large for text that renders (~260,000 entries for the string "Behold, this is text"). When producing text graphics for a font embedded in the same iModel session, requestElementGraphics produces an array with only ~400 entries.
  • You may notice, when embedding a new font, the deprecated FontMap won’t include the newly embedded font. When starting a new iModel session (closing and re-opening the app), the FontMap is populated with the fonts embedded during the previous session. Manually adding the newly embedded fonts to the FontMap does not change the rendering behavior.

Alfonso-Martello avatar Mar 12 '25 20:03 Alfonso-Martello

@pmconne, pinging so you are aware of this.

Alfonso-Martello avatar Mar 12 '25 20:03 Alfonso-Martello

The native font caches are supposed to update when you embed a new font, I'll investigate what's going wrong. The caches don't update when you undo/redo a font embedding, we should fix that too. Probably don't react when applying a changeset containing a font either.

pmconne avatar Mar 18 '25 11:03 pmconne

Hello @pmconne, I just wanted to follow up to see if you have had a chance to investigate this or if it is still on your radar? It’s not super urgent yet, since the font logic is in 5.x, and drawing production is still technically targeting 4.x, but I wanted to make sure this does not get lost. Thank you!

Alfonso-Martello avatar Apr 17 '25 15:04 Alfonso-Martello

Afaik, all text/font based updates will be in 5.x and not bp'd to 4.x

aruniverse avatar Apr 17 '25 16:04 aruniverse

Yes, you are correct, sorry for any confusion!

The point I wanted to make, is that my font integration into Drawing Production in on a branch targeting 5.x, but Drawing Production's development branch is still targeting 4.x, so my font branch will not be merged into Drawing Production in the near future.

Basically, I just wanted to say "I understand there are other features for 5.x that may be more pressing, I will not be merging the font integration soon, so no huge rush"

Alfonso-Martello avatar Apr 17 '25 16:04 Alfonso-Martello

Still on my radar

pmconne avatar Apr 17 '25 16:04 pmconne

Hi @pmconne, this issue has come up several times recently in discussions with @Josh-Schifter and the rest of the drawing production team. Josh mentioned you have been looking for ways to support us and realized he had not included this issue. I just wanted to let you know that getting this fixed is a priority for us as we prepare to get drawing production in the hands of users. The workaround of “close and reopen the iModel after adding a font” is quite jarring from a UX perspective

Alfonso-Martello avatar Sep 18 '25 19:09 Alfonso-Martello

Hello @pmconne, I just wanted to follow up once more on this issue as it continues to come up regularly and as we approach our release deadline. I don’t know if @Josh-Schifter has communicated this yet, but we are aiming to be MVP release ready by November 15. If there is anything I can do to help move things along on our end, I am happy to assist!

Alfonso-Martello avatar Oct 20 '25 19:10 Alfonso-Martello

On it.

pmconne avatar Oct 20 '25 20:10 pmconne

Actually, I may have a workaround that is sufficient for Drawing Production MVP.

Since Drawing Production MVP is only allowing a small list of curated "safe" fonts, I am able to embed all the fonts during iModel setup/provisioning. After provisioning the iModel, the changes are pushed. After pushing, the text seems to be working without requiring an iModel re-open.

When embedding fonts during copying of sheet templates with the iModel transformer those fonts were not being picked up by text even after re-opening the iModel. It seemed as if those fonts would appear in the font map but text would not use them. I tried out just embedding all the fonts up front and that seemed to work for both the transformer and general text like reported in this issue. I give this back story to point out that there is something more going on with the font caches that is unclear to me, but the above workaround seems to do the job

Alfonso-Martello avatar Oct 21 '25 20:10 Alfonso-Martello

@pmconne FYI - wanted to make sure you were notified of my previous comment

Alfonso-Martello avatar Oct 21 '25 21:10 Alfonso-Martello

Fixed by https://github.com/iTwin/imodel-native/pull/1257.

pmconne avatar Oct 27 '25 19:10 pmconne