Commit 6db1bbd9 authored by violet's avatar violet
Browse files

Bug 1370646 - Honor the maxTextRunSize if it's within reasonable range r=heycam

If the maximal and minimal font-size in a SVGTextFrame have a huge difference,
previously we chose mFontSizeScaleFactor to satisfy the minimal one. That's
problematic, because the maximal one might be a reasonable size, while the minimal
one is extremely small. We should honor the maximal one if this is the case.

Differential Revision: https://phabricator.services.mozilla.com/D24494

--HG--
extra : moz-landing-system : lando
parent 177f4b29
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -5222,9 +5222,20 @@ bool SVGTextFrame::UpdateFontSizeScaleFactor() {
    mFontSizeScaleFactor = contextScale;
  } else if (maxSize / minSize > CLAMP_MAX_SIZE / CLAMP_MIN_SIZE) {
    // We can't scale the font sizes so that all of the text frames lie
    // within our ideal font size range, so we treat the minimum as more
    // important and just scale so that minSize = CLAMP_MIN_SIZE.
    // within our ideal font size range.
    // Heuristically, if the maxTextRunSize is within the CLAMP_MAX_SIZE
    // as a reasonable value, it's likely to be the user's intent to
    // get a valid font for the maxTextRunSize one, we should honor it.
    // The same for minTextRunSize.
    if (maxTextRunSize <= CLAMP_MAX_SIZE) {
      mFontSizeScaleFactor = CLAMP_MAX_SIZE / maxSize;
    } else if (minTextRunSize >= CLAMP_MIN_SIZE) {
      mFontSizeScaleFactor = CLAMP_MIN_SIZE / minSize;
    } else {
      // So maxTextRunSize is too big, minTextRunSize is too small,
      // we can't really do anything for this case, just leave it as is.
      mFontSizeScaleFactor = contextScale;
    }
  } else if (minTextRunSize < CLAMP_MIN_SIZE) {
    mFontSizeScaleFactor = CLAMP_MIN_SIZE / minSize;
  } else {
+1 −0
Original line number Diff line number Diff line
@@ -11,4 +11,5 @@ support-files =
  file_yellow_black.svg

[test_hover_near_text.html]
[test_multiple_font_size.html]
[test_use_tree_cycle.html]
+26 −0
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1370646">Mozilla Bug 1370646</a>

<svg xmlns="http://www.w3.org/2000/svg" width="440" height="100" viewBox="0 0 440 100">
  <text>
    <tspan id="a" style="font-size:100px">3</tspan>
  </text>
  <text>
    <tspan id="b" style="font-size:100px">3</tspan>
    <tspan style="font-size:0.1px">0</tspan>
  </text>
</svg>

<script type="application/javascript">
  SimpleTest.waitForExplicitFinish();

  let alen = document.getElementById("a").getComputedTextLength(),
      blen = document.getElementById("b").getComputedTextLength();

  SimpleTest.isfuzzy(alen, blen, 5, "lengths should be close");

  SimpleTest.finish();
</script>