cables-gl / cables_docs

cables documentation docs.cables.gl
https://cables.gl/docs/docs
45 stars 16 forks source link

TextTexture inconsistent behaviour #652

Closed esperanc closed 9 months ago

esperanc commented 10 months ago

Describe the bug I detected two inconsistencies in the way TextTexture behaves.

  1. The computed line height varies unpredictably. By looking at the op code, I noticed that the height of every line is computed as the maximum over the heights of all lines in the text, as estimated by fields actualBoundingBoxAscent and actualBoundingBoxDescent of the font metrics object. This gives widely varying results even with text containing the same mixture of characters.
  2. The font and background colors are not checked for change, which makes color animation unfeasible.

I prepared a demo for the problem, together with a fixed custom TextTexture op in https://cables.gl/edit/vr_wmP

Here's a screenshot: cables_202415_144652

How To Reproduce

  1. Use the TextTexture op with fixed width and height, disable "auto line breaks", use a fixed width font like Courier or Monospace with a small size such as 10 or 20. Also, use a fairly big text with many lines. Line heights should be equal. The demo showcases this by creating random texts with uppercase and lowercase letters.
  2. Try to animate either the font color or background color.

Platform

marioepsley commented 10 months ago

Noticed the same, I guess I should be writing bugs here as opposed to discussions. My bad https://github.com/cables-gl/cables_docs/discussions/593

always happy to go through this with you as and when

esperanc commented 10 months ago

The fix I proposed to the line height issue is to use fontBoundingBoxAscent and fontBoundingBoxDescent rather than actualXXX. Also, I found that computing this on all lines is overkill, i.e., a single line is enough, or even better, a fixed string. Take a look at the modified op in the included demo.

pandrr commented 10 months ago

i did not use that, because firefox did not support it, looks like it does since august 23: https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics/fontBoundingBoxAscent

will look into your fix next week! thanks!!

pandrr commented 10 months ago
steam0r commented 9 months ago

this went to cables.gl with the latest release