Skip to content

letter-spacing: normal on an inline element is ignored at the start of a block #684

Open

Description

@gravitypdf-bot

An inline element that sets letter-spacing: normal inside a block with letter spacing is drawn with the block's spacing when its text is the first thing in the block. The same element later in the block is drawn without spacing, as it should be.

Reproduction

$mpdf = new \Mpdf\Mpdf(['default_font' => 'dejavusans']);
$mpdf->WriteHTML('<div style="letter-spacing: 2pt; font-size: 20pt">
  <p><span style="letter-spacing: normal">x</span>b</p>
  <p>c<span style="letter-spacing: normal">y</span></p>
</div>');

Text operators of the page, uncompressed:

BT 42.520 776.346 Td  2.000 Tc [(x) ] TJ  ET   <- should have no Tc
BT 56.360 776.346 Td  2.000 Tc [(b) ] TJ  ET
BT 42.520 727.407 Td  2.000 Tc [(c) ] TJ  ET
BT 55.520 727.407 Td  (y) Tj ET                <- correct

A browser draws x and y both without spacing.

Where

Both CSS modes give the same output, on gravitypdf before and after #683.

In Mpdf::printbuffer(), a chunk that carries a letter-spacing sets lSpacingCSS from it, but only converts it into fixedlSpacing when it is a length. A chunk carrying normal leaves fixedlSpacing as it was. For the first chunk of a block that is the block's own spacing, which the standard mode now puts back before the buffer is drawn (TextSpacing::setFromBlock()), and which the legacy mode had left there from the block's saved text state. Later chunks are not affected because the spacing is reset to none after each chunk is written. word-spacing: normal has the same shape, through minwSpacing.

setCSS() behaves the same way at write time: LETTER-SPACING: normal sets lSpacingCSS without resetting fixedlSpacing.

Fix

Resetting fixedlSpacing to false and minwSpacing to 0 when a chunk's spacing is normal would fix it. That changes the legacy mode's output too, so the fix should decide whether legacy keeps the old drawing or takes the correction, and say so in the changelog.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions