You are not logged in.

#1 2019-09-18 11:52:04

vdrummer
Member
Registered: 2013-10-16
Posts: 14

[SOLVED] fontconfig: Substituting font in PDF with local font

I'm not sure in which sub-forum to post this, so feel free to move this thread to a more appropriate location.

I'm trying to substitute fonts wanted by a PDF (not embedded) with appropriate fonts installed on my system. However, fontconfig doesn't seem to read the user rules, I defined.

The fonts in the PDF are:

$ pdffonts keigo.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
MS-Mincho                            CID TrueType      90ms-RKSJ-H      no  no  no      78  0
MS-Gothic                            CID TrueType      90ms-RKSJ-H      no  no  no      90  0

I'm trying to do the following replacements:
MS-Mincho --> IPAMincho
MS-Gothic --> IPAGothic

Both target fonts are installed:

$ fc-list | grep -E "IPA(Mincho|Gothic)" 
/usr/share/fonts/OTF/ipam.ttf: IPAMincho,IPA明朝:style=Regular
/usr/share/fonts/OTF/ipag.ttf: IPAGothic,IPAゴシック:style=Regular

I wrote the following rules

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <match target="pattern">
    <test name="family" qual="any" >
      <string>MS-Mincho</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>IPAMincho</string>
    </edit>
  </match>

  <match target="pattern">
    <test name="family" qual="any" >
      <string>MS-Gothic</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>IPAGothic</string>
    </edit>
  </match>

</fontconfig>

and tried placing this code in the following files:

~/.config/fontconfig/fonts.conf
~/.config/fontconfig/conf.d/00-japanese.conf
/etc/fonts/conf.d/99-japanese.conf

After that, I tried

fc-list -f

and even rebooting, but I keep getting

$ fc-match "MS-Gothic"
DejaVuSans.ttf: "DejaVu Sans" "Book"

Any ideas on how to convince fontconfig that I want MS-(Mincho|Gothic) replaced?

Last edited by vdrummer (2019-09-18 15:30:51)

Offline

#2 2019-09-18 13:48:49

seth
Member
Registered: 2012-09-03
Posts: 49,993

Re: [SOLVED] fontconfig: Substituting font in PDF with local font

Bogus test, try

fc-match "MS\-Gothic"

I'd not hold my breath that this carries over to the pdf (maybe depending on the viewer)

Offline

#3 2019-09-18 14:44:22

vdrummer
Member
Registered: 2013-10-16
Posts: 14

Re: [SOLVED] fontconfig: Substituting font in PDF with local font

Wow, that actually works! I didn't think "-" was a character that needs to be escaped...
Unfortunately, this doesn't carry over to the PDF (using evince), so it's still displayed in the fallback font.

But now that I know the "-" is the problem, I could just get rid of it and change my rule:

$ sed -i 's/MS-Gothic/MSGothic/g;s/MS-Mincho/MSMincho/g' keigo.pdf
$ cat .config/fontconfig/fonts.conf 
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <match target="pattern">
    <test name="family" qual="any" >
      <string>MSMincho</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>IPAMincho</string>
    </edit>
  </match>

  <match target="pattern">
    <test name="family" qual="any" >
      <string>MSGothic</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>IPAGothic</string>
    </edit>
  </match>

</fontconfig>
$ fc-cache -f

Not the most elegant solution, but at least I now can read my PDF the way it's supposed to be.

Offline

#4 2019-09-18 15:13:52

seth
Member
Registered: 2012-09-03
Posts: 49,993

Re: [SOLVED] fontconfig: Substituting font in PDF with local font

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

#5 2019-09-18 15:31:01

vdrummer
Member
Registered: 2013-10-16
Posts: 14

Re: [SOLVED] fontconfig: Substituting font in PDF with local font

Done. Thanks for the reminder.
And thanks for your help!

Last edited by vdrummer (2019-09-18 15:31:15)

Offline

Board footer

Powered by FluxBB