Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG: Incorrect fonts #1393

Closed
takesson opened this issue Jul 11, 2021 · 11 comments
Closed

SVG: Incorrect fonts #1393

takesson opened this issue Jul 11, 2021 · 11 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@takesson
Copy link

The font selection within SVG seems inconsistent.

In the following sample I believe:

  • HTML text correctly uses Arial
  • SVG line 1: seems like Arial
  • SVG remaining lines are not using the expected fonts.
System: Darwin
Machine: x86_64
Version: Darwin Kernel Version 19.6.0: Thu May  6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64
Release: 19.6.0

WeasyPrint version: 53.0b2
Python version: 3.9.5
Pydyf version: 0.0.3
Pango version: 14805
@takesson
Copy link
Author

fonts.zip

@liZe liZe closed this as completed in 08f3a59 Jul 12, 2021
@liZe liZe added the bug Existing features not working as expected label Jul 12, 2021
@liZe liZe added this to the 53.0 milestone Jul 12, 2021
@liZe
Copy link
Member

liZe commented Jul 12, 2021

Hello, and thanks a lot for the report!

We do some nasty things with CSS in SVG, that’s bad, and there’s actually a TODO about that in code. We may meet other strange problems with that in the future, until we really use computed values instead of re-parsing the CSS rules.

At least 08f3a59 fixes your problem with fonts. There’s a lot of work to test and clean the new SVG support, we’ll definitely improve it in future versions.

@takesson
Copy link
Author

Yes, tested on master which produces the correct output.

However the PDF becomes 2MB, likely related to:

WARNING: Unable to optimize font

@liZe
Copy link
Member

liZe commented Jul 28, 2021

However the PDF becomes 2MB, likely related to:

WARNING: Unable to optimize font

Do you have this problem with the document included in fonts.zip?

@takesson
Copy link
Author

However the PDF becomes 2MB, likely related to:

WARNING: Unable to optimize font

Do you have this problem with the document included in fonts.zip?

Yes.

@liZe
Copy link
Member

liZe commented Jul 28, 2021

Yes

Hmm… Could you please share your PDF?

@takesson
Copy link
Author

fonts.20210717.pdf

@liZe liZe closed this as completed in 08583d3 Jul 29, 2021
@liZe
Copy link
Member

liZe commented Jul 29, 2021

This bug is fixed, thanks for the report! The problem was caused by one of your fonts, stored as a TrueType Collection. Font collections are now correctly optimized and stored in the PDF, reducing the PDF size (and the time needed to write the PDF on disk).

@takesson
Copy link
Author

Nice! Thanks for the fix! I can confirm that the fonts sample PDF is now 63KB instead of 2MB.

Also, a manual that I am doing some early testing with went from 201MB (garbled titles) to 26MB (readable titles). Seems like the "Helvetica Neue" font is a TrueType Collection on macOS (many fonts are ttc in macOS).

Any thoughts on how this issue could generate 175MB embedded fonts in a PDF? There were 2 warnings logged and one of them was likely related to Helvetica Neue (6,2MB ttc) which would also be included in fonts PDF.

@takesson
Copy link
Author

takesson commented Jul 29, 2021

The answer to the last question is: It included the Apple Emoji font collection, for some reason (I have some very experimental CSS).


obj 329 0
 Type: 
 Referencing: 208 0 R, 328 0 R

  <<
    /Count 121
    /First 208 0 R
    /Last 328 0 R
  >>


obj 330 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length1 6171680
    /Filter /FlateDecode
    /Length 1969704
  >>


obj 331 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length1 207931344
    /Filter /FlateDecode
    /Length 181863731
  >>


obj 332 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length1 24056
    /Filter /FlateDecode
    /Length 6211
  >>


obj 333 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length1 7216
    /Filter /FlateDecode
    /Length 4633
  >>


obj 334 0
 Type: /FontDescriptor
 Referencing: 330 0 R

  <<
    /Type /FontDescriptor
    /FontName /GRHJRG+HelveticaNeue
    /FontFamily (Helvetica Neue)
    /Flags 4
    /FontBBox [ -3 -191 499 325 ]
    /ItalicAngle 0
    /Ascent 974
    /Descent -216
    /CapHeight 325
    /StemV 80
    /StemH 80
    /FontFile2 330 0 R
  >>


obj 335 0
 Type: /Font
 Referencing: 334 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /GRHJRG+HelveticaNeue
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 3 [ 277 ]
    15 [ 277 ]
    17 [ 277 351 ]
    36 [ 666 703 721 721 629 592 758 ]
    44 [ 277 ]
    47 [ 574 888 721 759 666 759 703 647 592 721 610 943 647 ]
    68 [ 555 610 555 610 555 314 592 574 240 240 536 240 869 574 592 610 610 351 518 333 574 518 777 536 518 499 ]
    226 [ 277 ]
    240 [ 555 555 499 ]
    ] /FontDescriptor 334 0 R
  >>


obj 336 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 1102
  >>


obj 337 0
 Type: /Font
 Referencing: 335 0 R, 336 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /GRHJRG+HelveticaNeue
    /Encoding /Identity-H
    /DescendantFonts [ 335 0 R ]
    /ToUnicode 336 0 R
  >>


obj 338 0
 Type: /FontDescriptor
 Referencing: 330 0 R

  <<
    /Type /FontDescriptor
    /FontName /STXCLD+HelveticaNeue
    /FontFamily (Helvetica Neue)
    /Flags 4
    /FontBBox [ -17 -21 172 713 ]
    /ItalicAngle 0
    /Ascent 952
    /Descent -213
    /CapHeight 713
    /StemV 80
    /StemH 80
    /FontFile2 330 0 R
  >>


obj 339 0
 Type: /Font
 Referencing: 338 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /STXCLD+HelveticaNeue
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 3 [ 277 ]
    8 [ 258 425 ]
    12 [ 999 ]
    14 [ 277 258 258 ]
    18 [ 599 277 388 277 332 ]
    33 [ 277 277 ]
    37 [ 599 555 ]
    40 [ 647 684 721 703 610 573 758 721 258 518 666 555 870 721 759 647 759 684 647 573 721 610 925 610 647 ]
    70 [ 499 ]
    72 [ 536 592 536 592 536 295 573 555 221 221 518 221 852 555 573 592 592 332 499 314 555 499 757 517 499 479 ]
    182 [ 499 999 425 425 ]
    187 [ 277 ]
    196 [ 517 517 ]
    584 [ 576 798 ]
    2094 [ 349 ]
    268435455 [ 0 ]
    ] /FontDescriptor 338 0 R
  >>


obj 340 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 1436
  >>


obj 341 0
 Type: /Font
 Referencing: 339 0 R, 340 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /STXCLD+HelveticaNeue
    /Encoding /Identity-H
    /DescendantFonts [ 339 0 R ]
    /ToUnicode 340 0 R
  >>


obj 342 0
 Type: /FontDescriptor
 Referencing: 331 0 R

  <<
    /Type /FontDescriptor
    /FontName /AVMJJJ+AppleColorEmoji
    /FontFamily (Apple Color Emoji)
    /Flags 5
    /FontBBox [ 0 -21 1000 1000 ]
    /ItalicAngle 0
    /Ascent 799
    /Descent -250
    /CapHeight 1000
    /StemV 80
    /StemH 80
    /FontFile2 331 0 R
  >>


obj 343 0
 Type: /Font
 Referencing: 342 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /AVMJJJ+AppleColorEmoji
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 3 [ 999 ]
    5 [ 999 999 999 999 999 999 999 999 999 ]
    44 [ 999 ]
    121 [ 999 ]
    123 [ 999 ]
    ] /FontDescriptor 342 0 R
  >>


obj 344 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 506
  >>


obj 345 0
 Type: /Font
 Referencing: 343 0 R, 344 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /AVMJJJ+AppleColorEmoji
    /Encoding /Identity-H
    /DescendantFonts [ 343 0 R ]
    /ToUnicode 344 0 R
  >>


obj 346 0
 Type: /FontDescriptor
 Referencing: 332 0 R

  <<
    /Type /FontDescriptor
    /FontName /VACLAJ+Arial
    /FontFamily (Arial)
    /Flags 4
    /FontBBox [ 0 0 299 453 ]
    /ItalicAngle 0
    /Ascent 905
    /Descent -211
    /CapHeight 453
    /StemV 80
    /StemH 80
    /FontFile2 332 0 R
  >>


obj 347 0
 Type: /Font
 Referencing: 346 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /VACLAJ+Arial
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 405 [ 354 ]
    ] /FontDescriptor 346 0 R
  >>


obj 348 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 337
  >>


obj 349 0
 Type: /Font
 Referencing: 347 0 R, 348 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /VACLAJ+Arial
    /Encoding /Identity-H
    /DescendantFonts [ 347 0 R ]
    /ToUnicode 348 0 R
  >>


obj 350 0
 Type: /FontDescriptor
 Referencing: 330 0 R

  <<
    /Type /FontDescriptor
    /FontName /KNRPIN+HelveticaNeue
    /FontFamily (Helvetica Neue)
    /Flags 4
    /FontBBox [ -8 -181 499 333 ]
    /ItalicAngle 0
    /Ascent 975
    /Descent -217
    /CapHeight 333
    /StemV 80
    /StemH 80
    /FontFile2 330 0 R
  >>


obj 351 0
 Type: /Font
 Referencing: 350 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /KNRPIN+HelveticaNeue
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 3 [ 277 ]
    9 [ 462 ]
    15 [ 295 295 ]
    18 [ 599 277 406 277 370 ]
    33 [ 277 ]
    38 [ 555 799 684 703 740 740 647 592 758 740 294 555 721 592 906 740 777 666 777 721 648 610 740 629 943 666 666 647 332 ]
    68 [ 332 ]
    70 [ 499 ]
    72 [ 573 610 573 610 573 332 610 592 257 277 573 257 905 592 610 610 610 388 536 351 592 519 813 536 518 518 ]
    99 [ 222 ]
    182 [ 499 ]
    196 [ 610 ]
    ] /FontDescriptor 350 0 R
  >>


obj 352 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 1308
  >>


obj 353 0
 Type: /Font
 Referencing: 351 0 R, 352 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /KNRPIN+HelveticaNeue
    /Encoding /Identity-H
    /DescendantFonts [ 351 0 R ]
    /ToUnicode 352 0 R
  >>


obj 354 0
 Type: /FontDescriptor
 Referencing: 330 0 R

  <<
    /Type /FontDescriptor
    /FontName /QAEHAK+HelveticaNeue
    /FontFamily (Helvetica Neue)
    /Flags 68
    /FontBBox [ -4 -11 500 528 ]
    /ItalicAngle 0
    /Ascent 956
    /Descent -213
    /CapHeight 528
    /StemV 80
    /StemH 80
    /FontFile2 330 0 R
  >>


obj 355 0
 Type: /Font
 Referencing: 354 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /QAEHAK+HelveticaNeue
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 21 [ 277 ]
    42 [ 721 ]
    52 [ 869 ]
    58 [ 647 ]
    72 [ 518 ]
    74 [ 536 ]
    76 [ 536 295 ]
    80 [ 221 ]
    84 [ 851 555 573 ]
    89 [ 332 480 314 555 ]
    96 [ 480 ]
    ] /FontDescriptor 354 0 R
  >>


obj 356 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 562
  >>


obj 357 0
 Type: /Font
 Referencing: 355 0 R, 356 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /QAEHAK+HelveticaNeue
    /Encoding /Identity-H
    /DescendantFonts [ 355 0 R ]
    /ToUnicode 356 0 R
  >>


obj 358 0
 Type: /FontDescriptor
 Referencing: 330 0 R

  <<
    /Type /FontDescriptor
    /FontName /EUVZNK+HelveticaNeue
    /FontFamily (Helvetica Neue)
    /Flags 4
    /FontBBox [ 0 -3 312 699 ]
    /ItalicAngle 0
    /Ascent 971
    /Descent -226
    /CapHeight 699
    /StemV 80
    /StemH 80
    /FontFile2 330 0 R
  >>


obj 359 0
 Type: /Font
 Referencing: 358 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /EUVZNK+HelveticaNeue
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 45 [ 480 ]
    72 [ 499 ]
    84 [ 777 ]
    86 [ 499 ]
    89 [ 351 ]
    91 [ 314 ]
    ] /FontDescriptor 358 0 R
  >>


obj 360 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 407
  >>


obj 361 0
 Type: /Font
 Referencing: 359 0 R, 360 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /EUVZNK+HelveticaNeue
    /Encoding /Identity-H
    /DescendantFonts [ 359 0 R ]
    /ToUnicode 360 0 R
  >>


obj 362 0
 Type: /FontDescriptor
 Referencing: 333 0 R

  <<
    /Type /FontDescriptor
    /FontName /AETFHB+AndaleMono
    /FontFamily (Andale Mono)
    /Flags 5
    /FontBBox [ 0 -13 497 520 ]
    /ItalicAngle 0
    /Ascent 907
    /Descent -217
    /CapHeight 520
    /StemV 80
    /StemH 80
    /FontFile2 333 0 R
  >>


obj 363 0
 Type: /Font
 Referencing: 362 0 R

  <<
    /Type /Font
    /Subtype /CIDFontType2
    /BaseFont /AETFHB+AndaleMono
    /CIDSystemInfo
      <<
        /Registry (Adobe)
        /Ordering (Identity)
        /Supplement 0
      >>
    /W [ 16 [ 600 ]
    29 [ 600 ]
    68 [ 600 600 600 600 600 ]
    79 [ 600 600 600 600 ]
    85 [ 600 600 ]
    ] /FontDescriptor 362 0 R
  >>


obj 364 0
 Type: 
 Referencing: 
 Contains stream

  <<
    /Length 506
  >>


obj 365 0
 Type: /Font
 Referencing: 363 0 R, 364 0 R

  <<
    /Type /Font
    /Subtype /Type0
    /BaseFont /AETFHB+AndaleMono
    /Encoding /Identity-H
    /DescendantFonts [ 363 0 R ]
    /ToUnicode 364 0 R
  >>


obj 366 0
 Type: 
 Referencing: 337 0 R, 341 0 R, 345 0 R, 349 0 R, 353 0 R, 357 0 R, 361 0 R, 365 0 R

  <<
    /GRHJRG 337 0 R
    /STXCLD 341 0 R
    /AVMJJJ 345 0 R
    /VACLAJ 349 0 R
    /KNRPIN 353 0 R
    /QAEHAK 357 0 R
    /EUVZNK 361 0 R
    /AETFHB 365 0 R
  >>

@liZe
Copy link
Member

liZe commented Jul 30, 2021

Emoji fonts can be big, and if they’re included in font collections the whole file can be huge. Moreover, the whole collection was fully included for each variant (bold, italic, etc.) found in the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants