Question & Answer
Question
How to create a custom font match with fontconfig
Answer
TARGET AUDIENCE:
Users requiring a customized font family name to match an existing AIX X11 font
OBJECTIVE:
Provide basic fontconfig guidance and examples to use "Match, Test, Edit" function
OVERVIEW:
Some Java/GUI applications which use fontconfig for font configuration may require an alias for existing X11 fonts.
If there is no customized JVM fontconfig.properties file, as of Java 7, the default behavior to select logical fonts is to use the system's libfontconfig if it is installed. AIX does not ship fontconfig, but it is available on the AIX Toolbox
See http://www-03.ibm.com/systems/power/software/aix/linux/toolbox/alpha.html#F
Fontconfig contains two essential modules:
1) A configuration module which builds an internal configuration from XML file
2) A matching module which accepts font patterns and returns the nearest matching font
If you have a requirement for a font family which is not part of the fonts available on AIX, and have a suitable AIX font for replacement, you can use the "match, test, edit" function of fontconfig to replace the font names.
You can replace system wide, or for a user only, by using the "Match, Test, Edit" function of fontconfig.
PROCEDURES:
In the following example, we will match "MyJapaneseFont" family font to a World Type Font shipped on AIX.
Required Font Family Name | MyJapaneseFont |
Available AIX X11 Font Family Name | WT SansDuo J |
Delivering Fileset | X11.fnt.ucs.ttf |
Font File | /usr/lpp/X11/lib/X11/fonts/TrueType/wtsdj__b.ttf |
Alias Links | /usr/lpp/X11/lib/X11/fonts/TrueType/mtsansdw.ttf ->
/usr/lpp/X11/lib/X11/fonts/TrueType/mtsansdj.ttf ->
|
First, we will examine the files in /opt/freeware/etc/fonts/conf.d :
- Each file in this directory is a fontconfig configuration file.
- This directory is scanned, and loaded in numerical order.
- Fontconfig scans this directory, loading all files of the form [0-9][0-9]*.conf.
- These files are installed in /opt/freeware/share/fontconfig/conf.avail and then symlinked here, allowing them to be easily installed and then enabled/disabled by adjusting the symlinks.
Enable User Level: 50-user.conf -> /opt/freeware/etc/fonts/conf.avail/50-user.conf
Enable System Wide: 51-local.conf -> /opt/freeware/share/fontconfig/conf.avail/51-local.conf
Notice these files don't exist by default. Creating them in the shared conf.avail will "enable" them
OPTION A: USER SPECIFIC CONFIGURATION
1) Create or edit /opt/freeware/share/fontconfig/conf.avail/50-user.conf (enables fonts.conf)
# mkdir -p /opt/freeware/share/fontconfig/conf.avail
# vi /opt/freeware/share/fontconfig/conf.avail/50-user.conf
It should contain, at a minimum:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <include ignore_missing="yes" prefix="xdg">fontconfig/fonts.conf</include> </fontconfig> |
This file, and the contents above will enable the user fonts.conf
2) Next, create or edit ~/.config/fontconfig/fonts.conf to contain the text from the custom xml.
# mkdir -p ~/.config/fontconfig/
# vi ~/.config/fontconfig/fonts.conf
3) Add the text from the custom xml section below. If the fonts.conf file already exists, add only the code between these lines:
<!-- BEGIN MATCH MyJapaneseFont to WT SansDuo J -->
<!-- END MATCH MyJapaneseFont to WT SansDuo J -->
Be sure to insert the stanzas between <fontconfig> and </fontconfig>
OPTION B: SYSTEM WIDE CONFIGURATION
1) Create or edit /opt/freeware/share/fontconfig/conf.avail/51-local.conf (enables the local.conf)
# mkdir -p /opt/freeware/share/fontconfig/conf.avail/
# vi /opt/freeware/share/fontconfig/conf.avail/51-local.conf
2) Add the custom xml below. If this file already exists, add only the code between these lines:
<!-- BEGIN MATCH MyJapaneseFont to WT SansDuo J -->
<!-- END MATCH MyJapaneseFont to WT SansDuo J -->
Be sure to insert the stanzas between <fontconfig> and </fontconfig>
custom xml |
Copy the xml below to the custom 51-local.conf or user fonts.conf. Begin at the "xml version" line which must be first line of the configuration file |
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <!-- ############################################## --> <!-- BEGIN MATCH MyJapaneseFont to WT SansDuo J --> <!-- ############################################## --> <!-- WT SansDuo J : wtsdj__b.ttf : X11.fnt.ucs.ttf--> <match> <test name="family"><string>MyJapaneseFont</string></test> <edit name="family" mode="assign" binding="strong"> <string>WT SansDuo J</string> </edit> </match> <!-- ############################################## --> <!-- END MATCH MyJapaneseFont to WT SansDuo J --> <!-- ############################################## --> </fontconfig> |
Now, test for the new assigned font family name. You should now see the assigned font at the top of the match list:
- # fc-match -s MyJapaneseFont
- --> mtsansdw.ttf: "WT SansDuo J" "Regular"
REFERENCES:
- Fontconfig Project Site
CATEGORY:
WWMISC
SUPPORT:
If additional assistance is required after completing all of the instructions provided in this document, please follow the step-by-step instructions below to contact IBM to open a service request (PMR) for software under warranty or with an active and valid support contract. The technical support specialist assigned to your support call will confirm that you have completed these steps.
a. Document and/or take screen shots of all symptoms, errors, and/or messages that might have occurred
b. Capture any logs or data relevant to the situation
c. Contact IBM to open a support call (PMR):
- For electronic support, please visit the web page:
- For telephone support, please visit the web page:
- Please visit the IBM Support Portal web page for additional resources:
https://www-947.ibm.com/support/servicerequest/newServiceRequest.action
http://www.ibm.com/planetwide
https://www-947.ibm.com/support/entry/myportal/support
d. Provide a good description of your issue and reference this technote
e. Upload all of the details and data to your support call (PMR):
Please visit this web page for instructions: https://www.secure.ecurep.ibm.com/app/upload
FEEDBACK:
Quality documentation is important to IBM and its customers. If you have feedback specific to this article, please send an detailed message to the email address:
- aix_feedback@wwpdl.vnet.ibm.com
- This email address is monitored for feedback purposes only.
- No support for any IBM products or services will be provided through this email.
- To receive support, please follow the step-by-step instructions in the above "SUPPORT" section.
Was this topic helpful?
Document Information
More support for:
AIX
Software version:
Version Independent
Operating system(s):
AIX
Document number:
630989
Modified date:
15 September 2021
UID
isg3T1025114