undefomizing ghostscript?

Is removing defoma safe for ghostscript? If not, how can we fix a problem?

Summary

fontconfig?

Debian ghostscript 8.70 supports fontconfig. But unfortunately, it won't work as we expected.

Well, even the fontname matches a target PSfont of PS file, it won't work yet.

$ grep IPA article9-f.ps
/RYUMIN { /IPAMincho-Unknown findfont exch dup
$ gs article9-f.ps
 ...
Can't find (or can't open) font file /usr/share/ghostscript/8.70/Resource/Font/IPAMincho-Unknown.
Can't find (or can't open) font file IPAMincho-Unknown.
Didn't find this font on the system!
Substituting font Courier for IPAMincho-Unknown.

I suspect the fontconfig support works.

FAPI?

FAPI is a freetype rendering structure and is disabled by default on Debian. It is quite different from the fontconfig font management and seems very beginning, doesn't reach the product level.

CIDFnmap?

This fontmap is absolutely obsolete, because the patch to use this file is dropped from Debian source. I don't know what this fontmap and patch made at the first.

CMap

CMap is a table between some encoding characters and CID code points, mainly for Chinese/Japanese/Korean. They had been distributed under Adobe's restricted license. Fortunatelly now they are relicensed under BSD license.

There are some packages have CMap; poppler-data, cmap-adobe-japan1, cmap-adobe-japan2, cmap-adobe-cns1, cmap-adobe-gb1, cmap-adobe-korea1, xpdf-japanese, xpdf-chinese-simplified, xpdf-chinese-traditional, xpdf-korean, and gs-cjk-resource. They include completely same files. The difference is only their locations. poppler-data package looks the best, because it has active upstream and active maintainer.

ghostscript has /usr/share/ghostscript/8.70/Resource/CMap/. Currently this directory links /var/lib/defoma/gs.d/CMap/. Because ghostscript doesn't find subdirectories, just linking to poppler-data won't work. Flat symlinking is needed.

Fontmap

Fontmap is a map for Latin Type1 fonts (*.pfb). There are 2 types.

fontpath is absolute or relative path. Because ghostscript finds /usr/share/fonts/type1/gsfonts also, Fontmap isn't necessary to define. On the other hand, Fontmap is important key to define aliases. Currently these aliases are managed by defoma. So we have to make them by another way.

/HelveticaNarrow-BoldOblique /NimbusSanL-BoldCondItal ; 
/Times-Bold /NimbusRomNo9L-Medi ; 
/Courier-Oblique /NimbusMonL-ReguObli ; 
/Palatino-Italic /URWPalladioL-Ital ; 
/Helvetica /NimbusSanL-Regu ; 
/Helvetica-Narrow-BoldOblique /NimbusSanL-BoldCondItal ; 
/NewCenturySchlbk-BoldItalic /CenturySchL-BoldItal ; 
/Helvetica-BoldOblique /NimbusSanL-BoldItal ; 
/AvantGarde-Book /URWGothicL-Book ; 
/NewCenturySchlbk-Roman /CenturySchL-Roma ; 
/Times-BoldItalic /NimbusRomNo9L-MediItal ; 
/Courier-Bold /NimbusMonL-Bold ; 
/Palatino-Bold /URWPalladioL-Bold ; 
/AvantGarde-BookOblique /URWGothicL-BookObli ; 
/AvantGarde-Demi /URWGothicL-Demi ; 
/Bookman-Demi /URWBookmanL-DemiBold ; 
/Courier /NimbusMonL-Regu ; 
/HelveticaNarrow-Oblique /NimbusSanL-ReguCondItal ; 
/Bookman-LightItalic /URWBookmanL-LighItal ; 
/NewCenturySchlbk-Bold /CenturySchL-Bold ; 
/Helvetica-Oblique /NimbusSanL-ReguItal ; 
/Helvetica-Narrow-Bold /NimbusSanL-BoldCond ; 
/AvantGarde-DemiOblique /URWGothicL-DemiObli ; 
/HelveticaNarrow /NimbusSanL-ReguCond ; 
/NewCenturySchlbk-Italic /CenturySchL-Ital ; 
/Palatino-BoldItalic /URWPalladioL-BoldItal ; 
/Times-Roman /NimbusRomNo9L-Regu ; 
/Palatino-Roman /URWPalladioL-Roma ; 
/Helvetica-Narrow-Oblique /NimbusSanL-ReguCondItal ; 
/HelveticaNarrow-Bold /NimbusSanL-BoldCond ; 
/Times-Italic /NimbusRomNo9L-ReguItal ; 
/Bookman-DemiItalic /URWBookmanL-DemiBoldItal ; 
/Helvetica-Bold /NimbusSanL-Bold ; 
/ZapfDingbats /Dingbats ; 
/Courier-BoldOblique /NimbusMonL-BoldObli ; 
/Bookman-Light /URWBookmanL-Ligh ; 
/ZapfChancery-MediumItalic /URWChanceryL-MediItal ; 
/Helvetica-Narrow /NimbusSanL-ReguCond ; 

cidfmap

cidfmap is a map for TrueType/CID fonts. There are some types but we use only two types as usual.

SubfontID is for TTC/OTF and chooses which font will be used from such multiple fonts collection.

LANGV is a CMap group; such as Japan1, Japan2, CNS1, GB1, or Korea1.

VERSION is a character set version. Larger version includes more glyphs. Japan1 font will take from 1 to 6, but it is very rare that free Japanese font supports 5 or 6. Well, what does 0 mean? It would be nice if we can get this number automatically from the font file.

/VL-PGothic-Regular << /FileType /TrueType /Path (/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf) /SubfontID 0 /CSI [(Japan1) 0] >> ;
/IPA-Mincho-Regular << /FileType /TrueType /Path (/usr/share/fonts/opentype/ipafont/ipam.otf) /SubfontID 0 /CSI [(Japan1) 0] >> ;
/SazanamiGothic-Regular-JaH << /FileType /TrueType /Path (/usr/share/fonts/truetype/sazanami/sazanami-gothic.ttf) /SubfontID 0 /CSI [(Japan2) 0] >> ;
/SazanamiGothic-Regular << /FileType /TrueType /Path (/usr/share/fonts/truetype/sazanami/sazanami-gothic.ttf) /SubfontID 0 /CSI [(Japan1) 0] >> ;
/Adobe-Japan1-Bold /VL-PGothic-Regular ;
/Ryumin-Light /SazanamiMincho-Regular ;
/GothicBBB-Medium /VL-PGothic-Regular ;
/Adobe-Japan1 /VL-PGothic-Regular ;
/HeiseiKakuGo-W5 /VL-PGothic-Regular ;
/HeiseiMin-W3 /SazanamiMincho-Regular ;

There are some important aliases for Japanese language:

Chinese (CNS1):

Chinese (GB1):

Korean:

So how can we indicate this alias to proper TTF/OTF font?

Here is a separeted cidfmap sample.

%!
% Don't change following line. We should ensure that the original one is surely loaded.
(cidfmap.GS) .runlibfile
% following lines are for CJK fonts.
(cidfmap.ja) .runlibfileifexists
(cidfmap.ko) .runlibfileifexists
(cidfmap.zh_CN) .runlibfileifexists
(cidfmap.zh_TW) .runlibfileifexists
% must be at the bottom of line to allow people overriding everything.
(cidfmap.local) .runlibfileifexists

Unfortunatelly maintaining cidmap.* is manual. Gentoo and Fedora simply provides static files.

% cidfmap.ja
/Kochi-Gothic                   << /FileType /TrueType /Path (/usr/share/fonts/kochi-substitute/kochi-gothic-subst.ttf) /CSI [(Japan1) 6] >> ;
/Kochi-Gothic-Regular           /Kochi-Gothic ;
/Kochi-Gothic-JaH               << /FileType /TrueType /Path (/usr/share/fonts/kochi-substitute/kochi-gothic-subst.ttf) /CSI [(Japan2) 0] >> ;
/Kochi-Gothic-Regular-JaH       /Kochi-Gothic-JaH ;
/Kochi-Mincho                   << /FileType /TrueType /Path (/usr/share/fonts/kochi-substitute/kochi-mincho-subst.ttf) /CSI [(Japan1) 6] >> ;
/Kochi-Mincho-Regular           /Kochi-Mincho ;
/Kochi-Mincho-JaH               << /FileType /TrueType /Path (/usr/share/fonts/kochi-substitute/kochi-mincho-subst.ttf) /CSI [(Japan2) 0] >> ;
/Kochi-Mincho-Regular-JaH       /Kochi-Mincho-JaH ;
/Ryumin-Light                   /Kochi-Mincho ;
/GothicBBB-Medium               /Kochi-Gothic ;
/Adobe-Japan1                   /Kochi-Gothic ;
/Adobe-Japan2                   /Kochi-Gothic-JaH ;

update-gsfontmap?

(kmuto's personal idea)

font package configuration

The number of affected packages may be very few.

1. Modify postinst to call update-gsfontmap.

   configure)
       if [ -x /usr/sbin/update-gsfontmap ]; then
           update-gsfontmap
       fi
   ;;

2. Modify prerm also.

   remove|upgrade|deconfigure)
       if [ -x /usr/sbin/update-gsfontmap ]; then
           update-gsfontmap
       fi
   ;;

3. Write conf file as debian/NN<package-name><-optionalAsYouLike>.conf.

% otf-ipafont sample (50otf-ipafont.conf)
/IPA-Mincho-Regular << /FileType /TrueType /Path (/usr/share/fonts/opentype/ipafont/ipam.otf) /SubfontID 0 /CSI [(Japan1) 0] >> ;
/IPA-Gothic-Regular << /FileType /TrueType /Path (/usr/share/fonts/opentype/ipafont/ipag.otf) /SubfontID 0 /CSI [(Japan1) 0] >> ;

4. Modify rules (and maybe dirs also) to copy conf file to /etc/ghostscript/cidfmap.d/ or /etc/ghostscript/fontmap.d/.

(debian/rules)
install: build
        ...
        install -m 644 $(CURDIR)/debian/50otf-ipafont.conf $(CURDIR)/debian/etc/ghostscript/cidfmap.d/
        ...

(debian/dirs)
...
etc/ghostscript/cidfmap.d

5. Remove defoma hint file. (TODO: should we remove old defoma files on prerm or postinst?)

6. Remove things of defoma from rules, postinst, prerm and control.