QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4967|回复: 8

完美实现网页多字体的显示,包括各种中文字体,英文字体[附图]

[复制链接]
发表于 2007-2-19 23:19:37 | 显示全部楼层 |阅读模式
折腾字体好几天,终于完美实现网页上多字体的显示,包括宋体,仿宋,华文新魏,等等,还有英文的好几种字体。网页显示不再只是简单的SimSun和Tahoma搭配,丰富多样的字体终于展现在我们面前。


为了实现 只用宋体显示英文、宋体显示中文-Tahoma显示英文 两种显示方式,我关掉了一些设置,因此,宋体显示小号英文时会出现破粹,体现在图上的mrxvt上面,平常用的时候只要把Tahoma强加在SimSun前面掉就可以解决这个问题了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 发表于 2007-2-19 23:20:08 | 显示全部楼层

这是用Tahoma强加在SimSun之后的图

这里是在匹配的字体列表中把Tahoma强加在SimSun之后的图,由于把英文强行替换成Tahoma了,所以英文就不会再用宋体来显示了,但这时破粹的问题会解决,请看旁边的mrxvt,效果好多了。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复

使用道具 举报

 楼主| 发表于 2007-2-19 23:20:45 | 显示全部楼层

再贴一下我的local.conf

再贴一下网页多字体显示,并且小粗体英文不会破粹的配置。
[code:1]
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- local.conf file to configure local fonts -->
<fontconfig>


        <!-- 中文字体目录 -->
        <dir>/usr/X11R6/lib/X11/fonts/TrueType</dir>
        <dir>/usr/X11R6/lib/X11/fonts/msfonts</dir>
        <dir>/usr/X11R6/lib/X11/fonts/wqyfonts</dir>


        <!-- LCD子像素渲染 -->
        <match target="font">
                <edit name="rgba" mode="assign">
                        <const>none</const>
                </edit>
        </match>


        <!-- 支持伪斜体 -->
        <match target="font">
                <!-- check to see if the font is roman -->
                <test name="slant">
                        <const>roman</const>
                </test>
                <!-- check to see if the pattern requested non-roman -->
                <test target="pattern" name="slant" compare="not_eq">
                        <const>roman</const>
                </test>
                <!-- multiply the matrix to slant the font -->
                <edit name="matrix" mode="assign">
                        <times>
                                <name>matrix</name>
                                <matrix>
                                        <double>1</double><double>0.2</double>
                                        <double>0</double><double>1</double>
                                </matrix>
                        </times>
                </edit>
                <!-- pretend the font is oblique now -->
                <edit name="slant" mode="assign">
                        <const>oblique</const>
                </edit>
        </match>


        <!-- 支持伪粗体 -->
        <match target="font">
                <!-- check to see if the font is just regular -->
                <test name="weight" compare="less_eq">
                        <int>100</int>
                </test>
                <!-- check to see if the pattern requests bold -->
                <test target="pattern" name="weight" compare="more_eq">
                        <int>180</int>
                </test>
                <!-- set the embolden flag -->
                <edit name="embolden" mode="assign">
                        <bool>true</bool>
                </edit>
        </match>


        <!-- 支持抗锯齿效果 -->
        <match target="font" >
                <edit mode="assign" name="antialias" >
                        <bool>true</bool>
                </edit>
                <edit mode="assign" name="hintstyle" >
                        <const>hintfull</const>
                </edit>
                <edit mode="assign" name="hinting" >
                        <bool>true</bool>
                </edit>
                <edit mode="assign" name="autohint" >
                        <bool>true</bool>
                </edit>
        </match>


        <!-- 关闭普通CJK文字8-17号的AA,斜体不关 -->
        <match target="font" >
                <test compare="contains" name="lang" >
                        <string>zh</string>
                        <string>ja</string>
                        <string>ko</string>
                </test>
                <test target="pattern" name="slant" compare="eq">
                        <const>roman</const>
                </test>
                <test compare="more_eq" name="pixelsize" qual="any" >
                        <double>8</double>
                </test>
                <test compare="less_eq" name="pixelsize" qual="any" >
                        <double>17</double>
                </test>
                <edit mode="assign" name="antialias" >
                        <bool>false</bool>
                </edit>
        </match>


        <!-- 解决中英文间距过宽的问题 -->
        <match target="font">
                <test compare="contains" name="lang" >
                        <string>zh</string>
                        <string>ja</string>
                        <string>ko</string>
                </test>
                <edit name="spacing">
                        <const>proportional</const>
                </edit>
                <edit name="globaladvance">
                        <bool>false</bool>
                </edit>
        </match>


        <!-- 设置最小字号 -->
        <match target="font" >
                <!--
                <test compare="contains" name="lang" >
                        <string>zh</string>
                        <string>ja</string>
                        <string>ko</string>
                </test>
                -->
                <test compare="more_eq" name="pixelsize" >
                        <int>8</int>
                </test>
                <test compare="less_eq" name="pixelsize" >
                        <int>12</int>
                </test>
                <edit compare="eq" name="pixelsize" >
                        <int>12</int>
                </edit>
        </match>


        <!-- 设置宽字体最小字号 -->
        <match target="pattern" >
                <test name="family" >
                        <string>Monospace</string>
                </test>
                <test compare="more_eq" name="pixelsize" >
                        <int>8</int>
                </test>
                <test compare="less_eq" name="pixelsize" >
                        <int>13</int>
                </test>
                <edit compare="eq" name="pixelsize" >
                        <int>13</int>
                </edit>
        </match>


        <!-- 个人喜好设置 -->
        <alias>
                <family>serif</family>
                <prefer>
                        <family>WenQuanYi Bitmap Song</family>
                        <family>Bitstream Vera Serif</family>
                        <family>Times New Roman</family>
                        <family>Thorndale AMT</family>
                        <family>Luxi Serif</family>
                        <family>Nimbus Roman No9 L</family>
                        <family>Times</family>
                        <family>Frank Ruehl</family>
                        <family>Kochi Mincho</family>
                        <family>AR PL SungtiL GB</family>
                        <family>AR PL Mingti2L Big5</family>
                        <family>MS 明朝</family>
                        <family>Baekmuk Batang</family>
                        <family>FreeSerif</family>
                </prefer>
        </alias>
        <alias>
                <family>sans-serif</family>
                <prefer>
                        <family>Tahoma</family>
                        <family>Verdana</family>
                        <family>SimSun</family>
                        <family>黑体</family>
                        <family>楷体_GB2312</family>
                        <family>仿宋_GB2312</family>
                        <family>幼圆</family>
                        <family>隶书</family>
                        <family>华文宋体</family>
                        <family>华文中宋</family>
                        <family>华文细黑</family>
                        <family>华文楷体</family>
                        <family>华文行楷</family>
                        <family>华文仿宋</family>
                        <family>华文隶书</family>
                        <family>华文彩云</family>
                        <family>华文琥珀</family>
                        <family>华文新魏</family>
                        <family>Bitstream Vera Sans</family>
                        <family>Arial</family>
                        <family>Albany AMT</family>
                        <family>Luxi Sans</family>
                        <family>Nimbus Sans L</family>
                        <family>Helvetica</family>
                        <family>Nachlieli</family>
                        <family>Kochi Gothic</family>
                        <family>AR PL KaitiM GB</family>
                        <family>AR PL KaitiM Big5</family>
                        <family>MS ゴシック</family>
                        <family>Baekmuk Dotum</family>
                        <family>FreeSans</family>
                </prefer>
        </alias>
        <alias>
                <family>monospace</family>
                <prefer>
                        <family>Courier</family>
                        <family>Courier New</family>
                        <family>Bitstream Vera Sans Mono</family>
                        <family>NSimSun</family>
                        <family>Andale Mono</family>
                        <family>Cumberland AMT</family>
                        <family>Luxi Mono</family>
                        <family>Nimbus Mono L</family>
                        <family>Miriam Mono</family>
                        <family>Kochi Gothic</family>
                        <family>AR PL KaitiM GB</family>
                        <family>Baekmuk Dotum</family>
                        <family>FreeMono</family>
                </prefer>
        </alias>


        <!-- 设置网页字体显示,英文用Tahoma/Verdana,中文用SimSun -->
        <match target="pattern">
                <test name="family">
                        <string>SimSun</string>
                </test>
                <edit name="family" mode="prepend_first" binding="strong">
                        <string>Verdana</string>
                </edit>
        </match>


        <!-- 设置宽字体的优先顺序 -->
        <match target="pattern">
                <test name="family" >
                        <string>NSimSun</string>
                </test>
                <edit name="family" mode="prepend_first" binding="strong">
                        <string>Courier</string>
                </edit>
        </match>


        <!-- 当文泉驿字号超过17时,用SimSun替换 -->
        <match target="pattern" >
                <test name="family">
                        <string>WenQuanYi Bitmap Song</string>
                </test>
                <test compare="more_eq" name="pixelsize" >
                        <int>17</int>
                </test>
                <edit name="family" mode="assign" >
                        <string>SimSun</string>
                </edit>
        </match>


        <!-- 当粗体Tahoma/Verdana字号超过17时,用SimSun替换 -->
        <match target="pattern">
                <test name="family" >
                        <string>Tahoma</string>
                </test>
                <test name="weight" compare="more_eq">
                        <int>180</int>
                </test>
                <test compare="more_eq" name="pixelsize" >
                        <int>17</int>
                </test>
                <edit name="family" mode="assign">
                        <string>SimSun</string>
                </edit>
        </match>


        <!-- 当粗体Tahoma/Verdana字号超过17时,用SimSun替换 -->
        <match target="pattern">
                <test name="family" >
                        <string>Verdana</string>
                </test>
                <test name="weight" compare="more_eq">
                        <int>180</int>
                </test>
                <test compare="more_eq" name="pixelsize" >
                        <int>17</int>
                </test>
                <edit name="family" mode="assign">
                        <string>SimSun</string>
                </edit>
        </match>


        <!-- Tahoma/Verdana不使用自动微调功能 -->
        <match target="font">
                <test compare="contains" name="family" >
                        <string>Tahoma</string>
                        <string>Verdana</string>
                </test>
                <edit mode="assign" name="autohint" >
                        <bool>false</bool>
                </edit>
        </match>


</fontconfig>
[/code:1]
回复

使用道具 举报

发表于 2007-2-24 14:27:34 | 显示全部楼层
      <edit mode="assign" name="hinting" >
         <bool>true</bool>
      </edit>
      <edit mode="assign" name="autohint" >
         <bool>true</bool>
      </edit>

两种hint一起开啊
   <!-- 设置最小字号 -->
   <match target="font" >
      <!--
      <test compare="contains" name="lang" >
         <string>zh</string>
         <string>ja</string>
         <string>ko</string>
      </test>
      -->
      <test compare="more_eq" name="pixelsize" >
         <int>8</int>
      </test>
      <test compare="less_eq" name="pixelsize" >
         <int>12</int>
      </test>
      <edit compare="eq" name="pixelsize" >
         <int>12</int>
      </edit>
   </match>


   <!-- 设置宽字体最小字号 -->
   <match target="pattern" >
      <test name="family" >
         <string>Monospace</string>
      </test>
      <test compare="more_eq" name="pixelsize" >
         <int>8</int>
      </test>
      <test compare="less_eq" name="pixelsize" >
         <int>13</int>
      </test>
      <edit compare="eq" name="pixelsize" >
         <int>13</int>
      </edit>
   </match>

为啥对待中日韩和别的字体,以及等宽和非等宽的设置不同啊?有何特殊意义吗?
回复

使用道具 举报

发表于 2007-2-24 19:58:32 | 显示全部楼层
好长,收起来慢慢看
回复

使用道具 举报

 楼主| 发表于 2007-2-24 22:19:54 | 显示全部楼层
回3n,“设置最小字号”是针对全局字体来设置的,“设置宽字体(包括Courier New)最小字号”主要是由于论坛中 [ code ]部分字体一般为Courier New,这里最小值较大,可以方便在论坛中阅读代码。

我现整理出一个Windows细腻效果的配置,一个带AA效果适合阅读的配置,稍后发上来供大家参考,并附上详细注释。
回复

使用道具 举报

 楼主| 发表于 2007-2-25 01:50:21 | 显示全部楼层
回3n,我最新的local.conf中有两种hint一起开的情况,发现中文两种hint一起开效果好,还有Courier new两种hint一起开效果也很好。呵呵,参见我最新的贴子,有图示:)
回复

使用道具 举报

 楼主| 发表于 2007-2-25 02:07:04 | 显示全部楼层
建议版主将此贴加精去掉!另外一篇写的更详细,见:字体配置local.conf详解[带Win效果和AA效果]
回复

使用道具 举报

发表于 2007-2-25 18:33:18 | 显示全部楼层
留着吧,作为借鉴互相参考
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 13:29 , Processed in 0.121594 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表