Skip to content

Canvases elements have extraneous padding #10726

Closed as not planned
Closed as not planned

Description

@jdm

Firefox:
screen shot 2016-04-19 at 6 49 59 pm
Servo:
screen shot 2016-04-19 at 6 50 16 pm

<style>
canvas {
  border: 1px solid black;
  margin: 0;
  padding: 0;
}
span {
  width: 32px;
  height: 32px;
  display: inline-block;
  border: 1px solid black;
}
</style>
<canvas width="32" height="32"></canvas><br><canvas width="32" height="32"></canvas>
<div></div>
<span></span><br><span></span>

Activity

  1. added
    C-has-manual-testcase
    on Apr 19, 2016
  2. jdm commented on Apr 19, 2016

    @jdm
    MemberAuthor

    With an encapsulating div that forces a particular height it looks slightly better:
    Firefox:
    screen shot 2016-04-19 at 6 51 31 pm
    Servo:
    screen shot 2016-04-19 at 6 51 26 pm

    <style>
    canvas {
      border: 1px solid black;
      margin: 0;
      padding: 0;
    }
    span {
      width: 32px;
      height: 32px;
      display: inline-block;
      border: 1px solid black;
    }
    </style>
    <div style="height: 32px"><canvas width="32" height="32"></canvas></div><canvas width="32" height="32"></canvas>
    <div></div>
    <span></span><br><span></span>
  3. self-assigned this
    on Apr 27, 2016
  4. added
    C-assigned
    on Apr 27, 2016
  5. notriddle commented on Apr 28, 2016

    @notriddle
    Contributor

    Those "margins" are actually the space intended for the font's descenders. In both Chrome, these canvases are touching:

    <style>
    canvas {
      border: 1px solid black;
      margin: 0;
      padding: 0;
    }
    </style>
    <canvas width="32" height="32"></canvas><br><canvas width="32" height="32"></canvas>

    image

    But these canvases have a "margin" between them:

    <style>
    canvas {
      border: 1px solid black;
      margin: 0;
      padding: 0;
    }
    </style>
    <canvas width="32" height="32"></canvas>no descenders<br><canvas width="32" height="32"></canvas>

    image

    In Servo, the space between them is identical.

  6. notriddle commented on Apr 28, 2016

    @notriddle
    Contributor

    The culprit code is InlineFlow::compute_minimum_ascent_and_descent. It seems to mine the font metrics for minimum values even when there is no actual text (also, its comment claims that it works on a line-by-line basis, but it seems to give a result to the entire flow).

  7. notriddle commented on May 4, 2016

    @notriddle
    Contributor

    Since #10691 landed, @jdm's original test case now looks like this:

    image

  8. added a commit that references this issue on May 20, 2016
    f319391
  9. added 2 commits that reference this issue on Jun 2, 2016
    85232a6
    4bfb5be
  10. notriddle commented on Jun 18, 2016

    @notriddle
    Contributor

    Firefox matches Servo's current behavior when a <!DOCTYPE html> declaration is added.

    That's why I couldn't find anything in the base CSS spec to justify the behavior; it's in the Quirks Mode spec! That's also why I found tests that seemed to rely on the behavior that this issue reports as a bug; because the tests are running with DOCTYPEs!

    :headdesk:

  11. notriddle commented on Jun 18, 2016

    @notriddle
    Contributor
    <!DOCTYPE html>
    <style>
    canvas {
      border: 1px solid black;
      margin: 0;
      padding: 0;
    }
    span {
      width: 32px;
      height: 32px;
      display: inline-block;
      border: 1px solid black;
    }
    </style>
    <canvas width="32" height="32"></canvas><br><canvas width="32" height="32"></canvas>
    <div></div>
    <span></span><br><span></span>

    screenshot from 2016-06-17 21-54-15

    screenshot from 2016-06-17 21-55-03

    screenshot from 2016-06-17 21-58-13

  12. removed their assignment
    on Jun 18, 2016
  13. removed
    C-assigned
    on Jun 18, 2016
  14. dralley commented on Apr 1, 2020

    @dralley
    Contributor

    The original minimal reproducer still works -- didn't try the others.

  15. lumiscosity commented on Jul 25, 2025

    @lumiscosity
    Member

    All test cases appear to work the same as Chromium, at least, so this is probably fixed. Pic attached is the first test case, tested on Arch Linux x86_64, servo built against commit id 9d29017, compared against Firefox 141.0, Epiphany 48.5 and Chromium 138.0.7204.168 (ordered left to right).

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/inlineC-has-manual-testcase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions