[daily][archlinux][fonts] 在linux下管理字体
序:
linux是社区搞出来, 商业应用也都是服务器场景。社区里又都是技术人员。字体又是细节。而且会英文早成了标配。所以没有很多社区以外的人力来搞字体这个毫无回报的东西。
结果很自然的,装linux桌面环境的几个问题之一,就包括了字体。与字体相关的一般问题主要就是中文显示问题。搞定了中文之后基本就不影响使用了。然后当你继续使用下去之后,就会出现更高的要求,就是希望为了美观要求而得到了一个好看的字体。
于是就会牵扯出,分辨率,等宽,高清等问题。但是没关系,因为在搞定中文字体的时候,你已经学会了安装各种各样的字体。然后你就开始疯狂的装字体,微软的,苹果的,安卓的。文泉驿的。。。
那么突然问题就来了,你完全没有办法管理他们,也不知道他们的默认和优先关系。某一个时刻你发现,你的字体失控了。
嗯,以上,就是我此刻遇到的问题。我装了多个字体之后,我的thunderbird中的中文并没有如我预期般的使用 adobe-source-han-sans-cn 作为默认字体,而是不知道一个什么字体,每一撇一捺都在肆意生长。
零: 知识储备
1. 圣教读物
包括了truetype, opentype,bitmap的一般性科普,可以只阅读前边的一小部分。
2. 关于serif, sans serif, monospace Serif和Sans-serif字体的区别
3. 一个大 列表。常用的coding字体,按推荐强度排序。还能preview。
4. 名称解释:Anti-alisaing(抗锯齿)
一: 高清屏下的tty
我有一个24寸2K的显示器。ppi是400? 反正就是很牛逼啦。但是进入tty的时候,特别可怕。字特别的小,几乎瞎掉了我的眼。我就这样眼瞎缭乱的从装arch开始一直到进入了X,在回头去该tty的字体与字号。总之对于高清屏来说,linux tty的默认字体太小太小了。
可是当时,我并没有写blog的习惯,甚至连写笔记的习惯都没有。我还甚甚的以为自己做过的事情永远不会忘记。此刻,我真的忘记了。我只直接,我装了tty下的字体,并且做了一些忘记了是什么样子的设置。嗯,只记得个大概,真的记不得细节。写blog多重要。
首先,我装了个字体。
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [:]
> pacman -Qs terminus
local/terminus-font 4.40-
Monospace bitmap font (for X11 and console)
然后,我设置了这个:
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [:]
> cat /etc/vconsole.conf
FONT=ter-v32n
重启(relogin ??),就设好了。
还有个命令,可以实时生效。好像是setfont,记不太清了。。。
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [:]
> man vconsole.conf /home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [:]
> man setfont
不过,所幸,我们还有邪教读物,来重拾这部分知识。。。
二:中文显示我用谁
之前装过用过一阵子的文泉驿。已经卸载了,现在使用adobe。反正,都差不多吧,对于中文,能显示我就满意了。
/home/tong/Amazon [tong@TStation] [:]
> pacman -Qs adobe-source
local/adobe-source-han-sans-cn-fonts 1.004-
Adobe Source Han Sans Subset OTF - Simplified Chinese OpenType/CFF fonts /home/tong/Amazon [tong@TStation] [:]
>
三:编程字体很纠结
最开始的时候,在windows下面编程的时候,我的配置是:putty + 白色背景 + Courier New + 10号。一直用了好多年,始终是我的最爱。但是到了linux下面字变得很细,很模糊,于是就不用了。
Cousine(ttf-google-fonts-git),据说是courier new的替代品,这个包好大,正在装,还没用。
最近发现的是Terminus,就是前文提到的那一个。在高清屏KDE下konsole里(14号字)使用还是蛮不错的。
惊喜的发现是,竟然在archcn的源里边找到了ttf版本。不过ttf的虽然细腻,但是偏细长,我反而更喜欢bitmap的。
另外Cousine也很好,不过Terminus在笔记本的屏幕上,因为字号设置的比较小,且没有那么细腻,所以并不好看。。。
/home/tong [tong@TStation] [:]
> pacman -Qs Terminus-font-ttf
local/terminus-font-ttf 4.40.-
Monospaced bitmap font designed for long work with computers (TTF version) /home/tong [tong@TStation] [:]
>
上效果图,一张:

再补一张bitmap terminus 14号,非加粗字体的:

四:到底要怎么管理字体
大多数主流软件的font都是有fonts-conf进行管理的。包括了一系列fc开头的软件。
/home/tong [tong@TStation] [:]
> fc- [tabtab...]
fc-cache fc-cat fc-list fc-match fc-pattern fc-query fc-scan fc-validate
fonts-conf 读配置文件,配置文件分4类:
1. ~/.fonts.conf, ~/.fonts.conf.d/, ~/.fontconfig/*.cache-* 这三类配置已经不推荐,在不久的将来也不会被兼容。
2. /etc/fonts/fonts.conf, /etc/fonts/conf.avail/ fonts.conf和conf.avail在软件更新的时候会被覆盖。不要做任何更改。
3. /etc/fonts/conf.d/, /etc/fonts/local.conf 系统全局配置。conf.d里面是从conf.avail中软连接过去的。
4. $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/fonts.d, 用户自定义配置。 在未设置环境变量的情况下,$XDG_CONFIG_HOME默认为 $HONE/.config. 参考内容一,参考内容二。
这还真的挺重要的我觉得,所以我觉得把这段贴出来:
$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be seperated with a colon ':'. If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used. $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be seperated with a colon ':'. If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used. The order of base directories denotes their importance; the first directory listed is the most important. When the same information is defined in multiple places the information defined relative to the more important base directory takes precedent. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS. The base directory defined by $XDG_CONFIG_HOME is considered more important than any of the base directories defined by $XDG_CONFIG_DIRS. $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used. $XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be .
环境变量们
所以,实际上用户的配置位置为:$HOME/.config/fontconfig/* 目录。而在实际系统中,即将被废止的配置文件~/.fonts.conf 也正是指向该目录的链接:
/home/tong [tong@TStation] [:]
> ll .fonts.conf
lrwxrwxrwx tong tong Sep .fonts.conf -> /home/tong/.config/fontconfig/fonts.conf /home/tong [tong@TStation] [:]
>
调整了配置文件之后,运行 fc-cache 命令。新打开的程序就会使用新的字体了。
搞定了wps的问题之后,导致了thunderbird的中文问题。详见:[daily][troubleshoot][archlinux][wps][font] wps文档中的图内容无法显示中文 我现在的目的是,在配置文件中,调整系统默认的中文字体。
首先,我要知道当前的match顺序。使用命令fc-match: 太长了,就不全贴出来了。说实话我也并不太会用这个命令:
[tong@T7:~]
% fc-match -a serif >
[tong@T7:~]
% fc-match -s serif >
[tong@T7:~]
然后,通过man手册中提供的本地文档 /usr/share/doc/fontconfig/fontconfig-user.html , 找到了这样一段内容:
<!--
use WenQuanYi Zen Hei font when serif is requested for Chinese
-->
<match>
<!--
If you don't want to use WenQuanYi Zen Hei font for zh-tw etc,
you can use zh-cn instead of zh.
Please note, even if you set zh-cn, it still matches zh.
if you don't like it, you can use compare="eq"
instead of compare="contains".
-->
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend">
<string>WenQuanYi Zen Hei</string>
</edit>
</match>
依葫芦画瓢,写到用户配置里,如下:
[tong@T7:~]
% cat .config/fontconfig/fonts.conf
<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>~/.fonts</dir> <match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Sans CN</string>
</edit>
</match> <match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>sans</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Sans CN</string>
</edit>
</match> <match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>mono</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Sans CN</string>
</edit>
</match> </fontconfig>
fonts.conf
遗憾的是,并没有用。
顺便读了这个,仅仅用来参考:http://www.cnblogs.com/youxia/p/linux004.html
依据圣教读物,将配置再次做了修改如下:
<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>~/.fonts</dir> <alias>
<family>serif</family>
<prefer>
<family>DejaVu Serif</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> <alias>
<family>sans serif</family>
<prefer>
<family>DejaVu Sans</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> <alias>
<family>sans</family>
<prefer>
<family>DejaVu Sans</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> <alias>
<family>mono</family>
<prefer>
<family>DejaVu Sans Mono</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> </fontconfig>
fonts.conf
配置生效,也达到了调整顺序的目的(通过fc-match的结果与修改之前对比):
[tong@T7:~]
% fc-match -a serif >
[tong@T7:~]
% fc-match -s serif >
[tong@T7:~]
% diff
8a9,
> SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular"
> SourceHanSansCN-Normal.otf: "Source Han Sans CN" "Normal"
> SourceHanSansCN-Light.otf: "Source Han Sans CN" "Light"
> SourceHanSansCN-ExtraLight.otf: "Source Han Sans CN" "ExtraLight"
> SourceHanSansCN-Medium.otf: "Source Han Sans CN" "Medium"
> SourceHanSansCN-Bold.otf: "Source Han Sans CN" "Bold"
> SourceHanSansCN-Heavy.otf: "Source Han Sans CN" "Heavy"
247d253
< SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular"
363d368
< SourceHanSansCN-Normal.otf: "Source Han Sans CN" "Normal"
369d373
< SourceHanSansCN-Light.otf: "Source Han Sans CN" "Light"
372d375
< SourceHanSansCN-ExtraLight.otf: "Source Han Sans CN" "ExtraLight"
377d379
< SourceHanSansCN-Medium.otf: "Source Han Sans CN" "Medium"
527d528
< SourceHanSansCN-Bold.otf: "Source Han Sans CN" "Bold"
553d553
< SourceHanSansCN-Heavy.otf: "Source Han Sans CN" "Heavy"
[tong@T7:~]
% diff ↵
4a5
> SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular"
14d14
< MSJH.TTC: "Microsoft JhengHei" "Normal"
79d78
< SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular"
[tong@T7:~]
对比
[tong@T7:~]
% fc-match -s serif|head -n
DejaVuSerif.ttf: "DejaVu Serif" "Book"
DejaVuSerif-Bold.ttf: "DejaVu Serif" "Bold"
DejaVuSerif-Italic.ttf: "DejaVu Serif" "Italic"
DejaVuSerif-BoldItalic.ttf: "DejaVu Serif" "Bold Italic"
SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular"
times.ttf: "Times New Roman" "Regular"
[tong@T7:~]
%
可是thunderbird的显示依然不正确。这真的让我很为难。。。
又改了一版,因为family名字写错了,serif生效了,另外的没生效。认真阅读/etc/fontconfig/fonts.conf文件,就会发现正确的名字。
<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>~/.fonts</dir> <alias>
<family>serif</family>
<prefer>
<family>DejaVu Serif</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> <alias>
<family>sans-serif</family>
<prefer>
<family>DejaVu Sans</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> <alias>
<family>monospace</family>
<prefer>
<family>DejaVu Sans Mono</family>
<family>Source Han Sans CN</family>
</prefer>
</alias> </fontconfig>
新fonts.conf
查看thunderbird,问题修正。:-)
[daily][archlinux][fonts] 在linux下管理字体的更多相关文章
- Linux 下 netbeans 字体抗锯齿正解
转自:http://leenjewel.blog.163.com/blog/static/601937922010124444051/ 说来这个不难,主要是我看网上有的写的不是很明确,甚至有的写的根本 ...
- [转载]Linux下终端字体颜色设置方法
原文地址:Linux下终端字体颜色设置方法作者:router 网上类似的文章有很多,但是都是转来转去的,没有经过测试,按照很多文章的方法会造成你设置之后的终端在换行和删除输入字符时终端显示会乱七八糟, ...
- linux下终端字体彩色显示
linux下python彩色显示 跨平台彩色显示库https://pypi.python.org/pypi/colorama jlive@MacBook-Pro:py_demo $pytho ...
- linux 下 NetBeans 字体大小设置
在linux mint 12下安装了 NetBeans7.1.2使用之后,觉得字体不好看,字体普遍特别大,分三个方面改NetBeans的字体. 1. 代码字体大小 点击NetBeans菜单,工具--& ...
- laravel 使用PhantomMagick导出pdf ,在Linux下安装字体
git项目地址:https://github.com/anam-hossain/phantommagick sudo apt-get -y install fontconfig xfonts-util ...
- 在linux下管理iphone
场景: linux发行版:ubuntu 14.04 64bit 3.13.0-67-generic(内核版本) iphone型号:iphone 5c (ios 8.1.3 已越狱) 准备工作(一定要先 ...
- Linux下wps字体问题
1.安装symbol-fonts_1.2_all.deb,自行搜索 2.卸载xfonts-mathml字体 sudo apt-get remove xfonts-mathml
- Linux 下查看字体
1.查看所有字体 命令:fc-list 2.查看中文字体 命令:fc-list :lang=zh 3.查看更多字体 命令:fc-match -v "AR PL UKai CN"
- Linux下终端字体颜色设置方法
颜色=\033[代码;前景;背景m 如:\033[1;32;40m表示高亮显示字体为绿色,背景色为黑色 颜色=\[\033[代码;前景;背景m\] echo -e "this is a \0 ...
随机推荐
- iOS UIImageView用代码添加点击事件
image.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]ini ...
- 【转载】Android内存泄露
相信一步步走过来的Android从业者,每个人都会遇到OOM的情况.如何避免和防范OOM的出现,对于每一个程序员来说确实是一门必不可少的能力.今天我们就谈谈在Android平台下内存的管理之道,开始今 ...
- gulp下静态资源的合并、压缩、MD5后缀
var gulp = require('gulp'); var RevAll = require('gulp-rev-all'); var uglify = require('gulp-uglify' ...
- Android中使用Handler造成内存泄露
1.什么是内存泄露? Java使用有向图机制,通过GC自动检查内存中的对象(什么时候检查由虚拟机决定),如果GC发现一个或一组对象为不可到达状态,则将该对象从内存中回收.也就是说,一个对象不被任何引用 ...
- ACM 众数问题
众数问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重 ...
- 巧用translate设置元素垂直水平居中
之前在做手机项目时,用到很多自定义弹窗,然后要求都垂直水平要居中,最开始的时候想用calc来计算,可是css3 的calc兼容性不是很好,于是后来就借助了js来计算, 今天偶然看到别人的一个方法,瞬间 ...
- C# 窗体位置 Show和ShowDialog(转)
CenterParent 窗体在其父窗体中居中. CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定. Manual 窗体的位置由 Location 属性确定. Windows ...
- Linux下memcached安装和启动方法
Linux下memcached安装和启动方法 1. 首先下载memcached 和 libevent 包. Memcached用到了libevent这个库用于Socket的处理.下面是下载的两个包文件 ...
- (转)as3效率优化
1.改进算法无论对于那一种程序,好的算法总是非常重要的,而且能够极大地提高程序性能,所以任何性能的优化第一步就是从算法或者说程序逻辑的优化开始,检查自己的程序是否有多余的运算,是否在没有必要的时候做了 ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...