Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1722900 - ghostscript stops enumerating fonts on the first font which fontconfig returns mismatch for
Summary: ghostscript stops enumerating fonts on the first font which fontconfig return...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: ghostscript
Version: 31
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Zdenek Dohnal
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1812284 1813228
TreeView+ depends on / blocked
 
Reported: 2019-06-21 16:18 UTC by H. Peter Anvin
Modified: 2020-04-06 11:14 UTC (History)
4 users (show)

Fixed In Version: ghostscript-9.27-3.fc31
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1812284 (view as bug list)
Environment:
Last Closed: 2020-03-18 02:22:07 UTC
Type: Bug


Attachments (Terms of Use)
Test case described in bug report (179.91 KB, application/x-xz)
2019-06-21 16:19 UTC, H. Peter Anvin
no flags Details

Description H. Peter Anvin 2019-06-21 16:18:48 UTC
Description of problem:

Ghostscript is compiled with fontconfig support according to its help message, but ghostscript fails to actually use it. Therefore, gs only uses fonts available in the ghostscript font path. However, the ghostscript font path does *not* include /usr/share/fonts!

This breaks any use of external fonts except the basic fonts provided by the libgs package, and a few more which seem to have been oddly enough have been added to the default fontpath explicitly?

gs -h shows in part:

Search path:
   /home/hpa/.fonts : /usr/share/ghostscript/Resource/Init :
   /usr/share/ghostscript/lib : /usr/share/ghostscript/Resource/Font :
   /usr/share/ghostscript/fonts : /usr/share/fonts/urw-base35 :
   /usr/share/fonts/google-droid
Ghostscript is also using fontconfig to search for font files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Version-Release number of selected component (if applicable):

ghostscript-9.26-4.fc30.x86_64
libgs-9.26-4.fc30.x86_64


This does not only affect ghostscript proper, but any (or at least many) tools that invokes ghostscript or libgs to process PostScript or PDF.



How reproducible:

100%.



Steps to Reproduce:
1. Install adobe-source-serif-pro-fonts and adobe-source-code-pro-fonts
2. xz -d nasmdoc.ps.xz
3. gs nasmdoc.ps
4. GS_FONTPATH=/usr/share/fonts gs nasmdoc.ps



Actual results:
Step 3 will display text in either Helvetica or Courier, with completely wrong font metrics.

Step 4 will display the file correctly.



Expected results:

Step 3 and step 4 should produce identical output.



Additional info:

Explicitly setting GS_FONTPATH results in bad performance as Ghostscript has to search every subdirectory and every font file in /usr/share/fonts. Therefore, this solution is not acceptable.

If gs fontconfig functionality cannot be restored, then a package hook would have to be provided to either generate/update a Fontmap file or create/delete symlinks in /usr/share/ghostscript/Resources/Font to map PostScript names to font files in the "traditional" way. I don't know which one of these has better performance, but I would expect the latter.

Comment 1 H. Peter Anvin 2019-06-21 16:19:55 UTC
Created attachment 1583322 [details]
Test case described in bug report

Comment 2 Zdenek Dohnal 2020-03-11 15:09:51 UTC
Hi,

thank you for the report!

The fix will be in the next update - ghostscript-9.50-1

Comment 3 Zdenek Dohnal 2020-03-12 09:41:18 UTC
The issue is quite tricky one - loading fonts from /usr/share/fonts actually works. 

I created test which installs needed fonts and it passes during testing for old gs version, but, curious enough, there are messages about missing fonts when I run it manually.

Output of test:
Querying operating system for font files...                                                                                                                                                   
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Bold.                                                                                                 
Can't find (or can't open) font file SourceCodePro-Bold.                                                                                                                                      
Loading SourceCodePro-Bold font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Bold.otf... 4373016 2751779 3419148 2102168 1 done.                                                 
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Regular.                                                                                              
Can't find (or can't open) font file SourceCodePro-Regular.                                                                                                                                   
Loading SourceCodePro-Regular font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Regular.otf... 4373016 2753334 3780924 2461019 1 done.                                           
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Semibold.                                                                                             
Can't find (or can't open) font file SourceCodePro-Semibold.                                                                                                                                  
Loading SourceCodePro-Semibold font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Semibold.otf... 4373016 2754915 4143484 2823442 1 done.                                         
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Bold.                                                                                                 
Can't find (or can't open) font file SourceSansPro-Bold.                                                                                                                                      
Loading SourceSansPro-Bold font from /usr/share/fonts/source-sans-pro/SourceSansPro-Bold.otf... 4401664 2787229 4713004 3368423 1 done.                                                       
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-BoldIt.                                                                                               
Can't find (or can't open) font file SourceSansPro-BoldIt.                                                                                                                                    
Loading SourceSansPro-BoldIt font from /usr/share/fonts/source-sans-pro/SourceSansPro-BoldIt.otf... 4401664 2788784 5122556 3780337 1 done.                                                   
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-It.                                                                                                   
Can't find (or can't open) font file SourceSansPro-It.                                                                                                                                        
Loading SourceSansPro-It font from /usr/share/fonts/source-sans-pro/SourceSansPro-It.otf... 4401664 2790334 5530252 4181005 1 done.                                                           
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Regular.                                                                                              
Can't find (or can't open) font file SourceSansPro-Regular.                                                                                                                                   
Loading SourceSansPro-Regular font from /usr/share/fonts/source-sans-pro/SourceSansPro-Regular.otf... 4401664 2791889 6056588 4702973 1 done.                                                 
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Semibold.                                                                                             
Can't find (or can't open) font file SourceSansPro-Semibold.                                                                                                                                  
Loading SourceSansPro-Semibold font from /usr/share/fonts/source-sans-pro/SourceSansPro-Semibold.otf... 4401664 2793446 6604404 5236666 1 done.                                               
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-SemiboldIt.                                                                                           
Can't find (or can't open) font file SourceSansPro-SemiboldIt.                                                                                                                                
Loading SourceSansPro-SemiboldIt font from /usr/share/fonts/source-sans-pro/SourceSansPro-SemiboldIt.otf... 4401664 2795005 7013172 5642454 1 done.

All fonts are loaded from /usr/share/fonts successfully even with old gs!

Then I ran it manually:

Querying operating system for font files...                                                                                                                                                   
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Bold.                                                                                                 
Can't find (or can't open) font file SourceCodePro-Bold.                                                                                                                                      
Loading SourceCodePro-Bold font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Bold.otf... 4373016 2748577 3253392 1936940 1 done.                                                 
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Regular.                                                                                              
Can't find (or can't open) font file SourceCodePro-Regular.                                                                                                                                   
Loading SourceCodePro-Regular font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Regular.otf... 4373016 2750132 3615168 2295687 1 done.                                           
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Semibold.                                                                                             
Can't find (or can't open) font file SourceCodePro-Semibold.                                                                                                                                  
Loading SourceCodePro-Semibold font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Semibold.otf... 4373016 2751713 3977728 2658006 1 done.                                         
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Bold.                                                                                                 
Can't find (or can't open) font file SourceSansPro-Bold.                                                                                                                                      
Didn't find this font on the system!                                                                                                                                                          
Substituting font Helvetica-Bold for SourceSansPro-Bold.                                                                                                                                      
Loading NimbusSans-Bold font from /usr/share/ghostscript/Resource/Font/NimbusSans-Bold... 4406360 2899798 3997928 2673171 1 done.                                                             
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-BoldIt.                                                                                               
Can't find (or can't open) font file SourceSansPro-BoldIt.                                                                                                                                    
Didn't find this font on the system!                                                                                                                                                          
Substituting font Helvetica-BoldOblique for SourceSansPro-BoldIt.                                                                                                                             
Loading NimbusSans-BoldItalic font from /usr/share/ghostscript/Resource/Font/NimbusSans-BoldItalic... 4472472 3083363 4018128 2685391 1 done.                                                 
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-It.                                                                                                   
Can't find (or can't open) font file SourceSansPro-It.                                                                                                                                        
Didn't find this font on the system!                                                                                                                                                          
Substituting font Helvetica-Oblique for SourceSansPro-It.                                                                                                                                     
Loading NimbusSans-Italic font from /usr/share/ghostscript/Resource/Font/NimbusSans-Italic... 4599184 3274797 4018128 2694157 1 done.                                                         
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Regular.                                                                                              
Can't find (or can't open) font file SourceSansPro-Regular.                                                                                                                                   
Didn't find this font on the system!                                                                                                                                                          
Substituting font Courier for SourceSansPro-Regular.                                                                                                                                          
Loading NimbusMonoPS-Regular font from /usr/share/ghostscript/Resource/Font/NimbusMonoPS-Regular... 4847096 3517570 4038328 2706745 1 done.                                                   
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-Semibold.                                                                                             
Can't find (or can't open) font file SourceSansPro-Semibold.                                                                                                                                  
Didn't find this font on the system!                                                                                                                                                          
Substituting font Helvetica-Bold for SourceSansPro-Semibold.                                                                                                                                  
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceSansPro-SemiboldIt.                                                                                           
Can't find (or can't open) font file SourceSansPro-SemiboldIt.                                                                                                                                
Didn't find this font on the system!                                                                                                                                                          
Substituting font Helvetica-BoldOblique for SourceSansPro-SemiboldIt.

Some fonts were not loaded now, why? Then I saw the message:
....
Can't find (or can't open) font file /usr/share/ghostscript/Resource/Font/SourceCodePro-Semibold.                                                                                             
Can't find (or can't open) font file SourceCodePro-Semibold.                                                                                                                                  
Loading SourceCodePro-Semibold font from /usr/share/fonts/adobe-source-code-pro/SourceCodePro-Semibold.otf... 4373016 2751713 3977728 2658006 1 done.
....

What? Successful load from /usr/share/fonts? It seems the problem is not about gs is not able to read fonts from /usr/share/fonts, but it is rather connected to the issue I found yesterday:

When fontconfig returns error for one of existing fonts, gs does not continue in loading other fonts.

So the issue is rooted in the font/fontconfig, but improper error handling in gs causes no loading of other fonts found by fontconfig. But I'm not sure why fontfonfig returns different value during testing than ran manually.

Comment 4 Zdenek Dohnal 2020-03-12 11:59:11 UTC
Silly mistake - difference between running in test and running it manually is that font which I put into /usr/share/fonts is cleaned up...

Comment 5 Zdenek Dohnal 2020-03-12 14:51:37 UTC
In the end, the fix can be backported.

Comment 6 Zdenek Dohnal 2020-03-12 14:54:46 UTC
Moving to F31, the update will be in the stable repo faster, so the bug will be closed faster. The fix will be for F30 too, but I'm not sure how fast will it be (depends on the number of willing tester on F30).

Comment 7 Fedora Update System 2020-03-12 15:17:33 UTC
FEDORA-2020-5ba7efcc1c has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2020-5ba7efcc1c

Comment 8 Fedora Update System 2020-03-12 22:59:51 UTC
ghostscript-9.27-3.fc31 has been pushed to the Fedora 31 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2020-5ba7efcc1c

Comment 9 Akira TAGOH 2020-03-13 09:28:31 UTC
The fix may works as a workaround but it looks like the fixed code stops supporting (a part of) variable fonts.

Comment 10 Zdenek Dohnal 2020-03-13 09:37:19 UTC
(In reply to Akira TAGOH from comment #9)
> The fix may works as a workaround but it looks like the fixed code stops
> supporting (a part of) variable fonts.

To be precise - it does not stop support of variable fonts since it seems there was no support of them to begin with.

As I wrote in #1813187, would you mind helping me how it should be taken care of properly? I don't have much experience in fonts.

Or, if you are willing, join me at #ghostscript at irc.freenode.net and talk with upstream about it?

Comment 11 Akira TAGOH 2020-03-13 10:46:00 UTC
I added a comment there. and yes, that's true. that's why I wrote it as "a part of". in fact, currently only named-instances are supported. I can't say more details how to do it because I don't know how ghostscript use those values from FcPattern and render.

They may also need to use the proper API from freetype to support variable fonts. see around this https://www.freetype.org/freetype2/docs/reference/ft2-multiple_masters.html#ft_mm_var

Comment 12 Fedora Update System 2020-03-18 02:22:07 UTC
ghostscript-9.27-3.fc31 has been pushed to the Fedora 31 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.