Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to improve your fonts a simple hack
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Odysseus
Apprentice
Apprentice


Joined: 23 Jun 2004
Posts: 250
Location: Miami, FL. I miss San Francisco!!!

PostPosted: Thu Jul 22, 2004 2:36 am    Post subject: How to improve your fonts a simple hack Reply with quote

OK I'm sure most of you would like to have fonts that look as beautiful in Gentoo as they do in Windows or a Mac. Here is a simple hack that will make your font's look amazing.

Edit: One note however is that I don't believe it works if you're using non-western, asian, chinese or middle eastern fonts (if you have cjk in your USE flags) because to make this hack work we disable the installation of Akito's cjkfonts-patch for autohinting asian fonts.

Many thanks go to David Chester who has done much work to improve the look of Linux fonts. More info can be found on this webpage http://www.cs.mcgill.ca/~dchest/xfthack . Much of his work has been incorporated into the freetype-2 library however a few things were left out that dramatically improve the look of anti-aliased fonts especially in version 2.1.5 that most of us are using. We've all had the problems where the diagnal portions of "k" and "x" fade out or how other letters don't look right with anti-aliasing enabled esp. in KDE. Well through the beauty of portage and making overlays we can make our fonts better.

All you need to do is create a portage overlay for freetype. If you don't already have a portage overlay make one in /usr/local/portage and enable it in your make.conf file. In your portage overlay create the folder "media-libs". Then go to your regular portage directory and copy the folder "freetype" from /usr/portage/media-libs into /usr/local/portage/media-libs.

Inside that folder are a bunch of ebuilds, but we're going to be working with only one, "freetype-2.1.5-r1.ebuild" the other ones can be removed/deleted from your overlay if you want. Now open that ebuild in an editor and it should look like this:
Code:

# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/media-libs/freetype/freetype-2.1.5-r1.ebuild,v 1.12 2004/07/01 07:55:56 eradicator Exp $

inherit eutils flag-o-matic

DESCRIPTION="A high-quality and portable font engine"
HOMEPAGE="http://www.freetype.org/"
SRC_URI="mirror://sourceforge/freetype/${P/_/}.tar.bz2"

LICENSE="FTL | GPL-2"
SLOT="2"
KEYWORDS="x86 ppc sparc mips alpha arm hppa amd64 ia64 ppc64 s390"
IUSE="zlib bindist cjk doc"

DEPEND="virtual/libc
   zlib? ( sys-libs/zlib )"

src_unpack() {
   local SPV="`echo ${PV} | cut -d. -f1,2`"

   unpack ${A}

   cd ${S}
   # add autohint patch from http://www.kde.gr.jp/~akito/patch/freetype2/2.1.5/
   use cjk && epatch ${FILESDIR}/${SPV}/${P}-autohint-cjkfonts-20031105.patch
}

src_compile() {
   use bindist || append-flags -DTT_CONFIG_OPTION_BYTECODE_INTERPRETER

   make setup CFG="--host=${CHOST} --prefix=/usr `use_with zlib`" unix || die

   emake || die

   # Just a check to see if the Bytecode Interpreter was enabled ...
   if [ -z "`grep TT_Goto_CodeRange ${S}/objs/.libs/libfreetype.so`" ]
   then
      ewarn "Bytecode Interpreter is disabled."
   fi

}

src_install() {
   make prefix=${D}/usr install || die

   dodoc ChangeLog README
   dodoc docs/{CHANGES,CUSTOMIZE,DEBUG,*.txt,PATENTS,TODO}

   use doc && dohtml -r docs/*
}


We're just going to edit 2 lines changing

Code:

 # add autohint patch from http://www.kde.gr.jp/~akito/patch/freetype2/2.1.5/
   use cjk && epatch ${FILESDIR}/${SPV}/${P}-autohint-cjkfonts-20031105.patch
}

to
Code:

   # add chesterhint ft-smooth patch from http://www.cs.mcgill.ca/~dchest/xfthack/
   epatch ${FILESDIR}/${SPV}/${P}-ft-smooth-215.diff
}


Save the file. Then download this diff file http://www.cs.mcgill.ca/~dchest/xfthack/ft-smooth-215.diff or copy this code into your favorite text editor and save it in the "files/2.1" directory in your overlay as "freetype-2.1.5-ft-smooth-215.diff".

Code:

diff -ru ../freetype-2.1.5/include/freetype/config/ftoption.h ./include/freetype/config/ftoption.h
--- ../freetype-2.1.5/include/freetype/config/ftoption.h        2003-09-02 17:14:55.000000000 -0400
+++ ./include/freetype/config/ftoption.h        2003-10-23 17:38:34.000000000 -0400
@@ -524,6 +524,23 @@

 #endif /* FT_CONFIG_OPTION_CHESTER_HINTS */

+  /*************************************************************************/
+  /*                                                                       */
+  /*  Define this to always override any available native hinter with      */
+  /*  the autohinter.                                                       */
+
+#define FT_CONFIG_FORCE_AUTOHINT
+
+  /*************************************************************************/
+  /*                                                                       */
+  /*  Define this option to set the default hinting configuration so that  */
+  /*  hinting is applied only to horizontal stems.                         */
+
+#define FT_CONFIG_SMOOTH_HINTING
+
+
+
+
 FT_END_HEADER


diff -ru ../freetype-2.1.5/src/autohint/ahhint.c ./src/autohint/ahhint.c
--- ../freetype-2.1.5/src/autohint/ahhint.c     2003-08-17 19:00:59.000000000 -0400
+++ ./src/autohint/ahhint.c     2003-10-23 17:39:27.000000000 -0400
@@ -31,7 +31,7 @@

 #define AH_USE_IUP
 #define OPTIM_STEM_SNAP
-
+#define FORCE_SMOOTH

   /*************************************************************************/
   /*************************************************************************/
@@ -492,6 +492,7 @@
         }
       }

+
       /* now we will align all stem edges, trying to maintain the */
       /* relative order of stems in the glyph                     */
       for ( edge = edges; edge < edge_limit; edge++ )
@@ -1442,7 +1443,6 @@
     AH_Outline        outline  = hinter->glyph;
     AH_Loader         gloader  = hinter->loader;

-
     /* load the glyph */
     error = FT_Load_Glyph( face, glyph_index, load_flags );
     if ( error )
@@ -1829,6 +1829,16 @@

     ah_loader_rewind( hinter->loader );

+#ifdef FT_CONFIG_SMOOTH_HINTING
+
+    hinter->do_horz_hints    = 0;
+    hinter->do_vert_hints    = 1;
+    hinter->do_horz_snapping = 0;
+    hinter->do_vert_snapping = 0;
+    hinter->do_stem_adjust   = 0;
+
+#else
+
     /* reset hinting flags according to load flags and current render target */
     hinter->do_horz_hints = FT_BOOL( !(load_flags & FT_LOAD_NO_AUTOHINT) );
     hinter->do_vert_hints = FT_BOOL( !(load_flags & FT_LOAD_NO_AUTOHINT) );
@@ -1850,6 +1860,7 @@

     hinter->do_stem_adjust   = FT_BOOL( hint_mode != FT_RENDER_MODE_LIGHT );

+#endif

     load_flags  |= FT_LOAD_NO_SCALE
                  | FT_LOAD_IGNORE_TRANSFORM ;
diff -ru ../freetype-2.1.5/src/base/ftobjs.c ./src/base/ftobjs.c
--- ../freetype-2.1.5/src/base/ftobjs.c 2003-07-05 03:46:49.000000000 -0400
+++ ./src/base/ftobjs.c 2003-10-23 17:38:34.000000000 -0400
@@ -452,6 +452,10 @@
     if ( glyph_index >= (FT_UInt)face->num_glyphs )
       return FT_Err_Invalid_Argument;

+#ifdef FT_CONFIG_FORCE_AUTOHINT
+    load_flags |= FT_LOAD_FORCE_AUTOHINT;
+#endif
+
     slot = face->glyph;
     ft_glyphslot_clear( slot );



After saving the file, just re-emerge freetype, by issuing the "emerge --oneshot freetype" command. Then exit "X" and restart your font server and enjoy your newly beautified anti-aliased fonts. I hope this helps and that you enjoy!! Life is good!

Ciao


Last edited by Odysseus on Thu Jul 22, 2004 8:10 pm; edited 3 times in total
Back to top
View user's profile Send private message
Dolio
l33t
l33t


Joined: 17 Jun 2002
Posts: 650

PostPosted: Thu Jul 22, 2004 4:14 am    Post subject: Reply with quote

:) This actually makes most of my fonts look worse.

I sometimes have weird letter spacing in things like KWord (I guess that's called kearning), and from the sounds of the web page, this patch might improve that.

However, this patch makes my fonts significantly less smooth. It should be noted that I use font sizes of 9 and 10 in most cases, and his tests seem to be in the 12 and up range, so if you use sizes like those, this may work well for you, but unfortunately this didn't work too well for me.

Thanks for the tip, though. I'm always game to try out some new font settings.
_________________
They don't have a good bathroom to do coke in.
Back to top
View user's profile Send private message
Odysseus
Apprentice
Apprentice


Joined: 23 Jun 2004
Posts: 250
Location: Miami, FL. I miss San Francisco!!!

PostPosted: Thu Jul 22, 2004 4:32 am    Post subject: Reply with quote

Worse in what fashion? What dpi fonts are you using 75 or 100? I use 75 which is the default and yes I've got my fonts set to their defaults in KDE of between 10-12 pts as I have only a 17" monitor. And I don't exclude any font sizes from anti-aliasing as that defeats the purpose of this hack. For me it not only gives smooth fonts that rival Windows without any graininess which turning off antialiasing or excluding size ranges creates, but it also gets rid of that annoying "fading" that occurs with diagnals in letters like "k" and "x".

It allows me for the first time to use all of my ttf fonts from Windows to be imported and have them look the same in Linux. I use Tahoma (like MS does) for most purposes Verdana for Window title bars and Arial for other things. I hope this clarifies things a bit.

Ciao
Back to top
View user's profile Send private message
Dolio
l33t
l33t


Joined: 17 Jun 2002
Posts: 650

PostPosted: Thu Jul 22, 2004 12:59 pm    Post subject: Reply with quote

Hmm. Well, our setups are quite different.

I have a 17" monitor, but my resolution is 1440x1080, so naturally my fonts are 100 dpi. I don't really seem to have the fading in k and x, either.

I also don't exclude any sizes from antialiasing.

As for how they were worse... Arial definitely appeared more jagged to me. I don't know if I can explain it, but it was as if in some places the dark pixels were scattered around. For example, if each 0 is a pixel, the left is how I would expect it to be, and the right is how it looked:

Code:

0        0
0          0
0        0
0          0
0        0


Maybe that's how it's supposed to be. I don't know.

Also, when I loaded up Courier New in rxvt-unicode (size 8 ) the antialiasing made it almost fade into the background, which is something of a problem.

Anyhow, maybe I'll experiment a bit more with this later. But on first blush, it didn't work too well for me.
_________________
They don't have a good bathroom to do coke in.
Back to top
View user's profile Send private message
placeholder
Advocate
Advocate


Joined: 07 Feb 2004
Posts: 2500

PostPosted: Sat Jul 24, 2004 2:18 pm    Post subject: Reply with quote

My fonts look crisper and better than they ever did in Windows and I didn't even use the patch. Have you emerge the corefonts yet? :wink:
Back to top
View user's profile Send private message
Odysseus
Apprentice
Apprentice


Joined: 23 Jun 2004
Posts: 250
Location: Miami, FL. I miss San Francisco!!!

PostPosted: Sun Jul 25, 2004 8:08 am    Post subject: Reply with quote

I don't need corefonts (although I do have them installed) because I already have imported all of my Truetype fonts from Windows so I would have them available to me in Linux. I have hundreds of fonts (about 120mb worth) that I installed in /usr/share/fonts/myfonts and made them available to the xfs fontserver. Many of them I paid for so I'll be damned if I'm not going to be able to use them, ;) besides my favorite font Tahoma isn't included in the corefonts package.

I don't know what flavor of Windows you were running, but just as XP's fonts looked light years better than ME's (with just font smoothing as apposed to cleartype font rendering in XP), my fonts now look as good as XP's if not better.

Some people like grainier fonts, some don't, I like mine smooth as silk, it's all a matter of personal preference. Enjoy!

Ciao
Back to top
View user's profile Send private message
tomaw
Guru
Guru


Joined: 26 Mar 2003
Posts: 429
Location: UK

PostPosted: Sun Jul 25, 2004 9:06 am    Post subject: Reply with quote

Things oldly enough seem slower after applying this patch. And I'm really not that sure I prefer the way they look either :?

Not something I'll be using I don't think....
_________________
Tom Wesley
Back to top
View user's profile Send private message
Malakai
Apprentice
Apprentice


Joined: 24 Dec 2002
Posts: 299

PostPosted: Tue Jul 27, 2004 9:08 am    Post subject: Reply with quote

An example screenshot of before the patch with the old freetype, then after the patch with the new one, would be great.
Back to top
View user's profile Send private message
tomchuk
Guru
Guru


Joined: 23 Mar 2003
Posts: 317
Location: Brooklyn, NY

PostPosted: Tue Jul 27, 2004 4:20 pm    Post subject: Reply with quote

I did the same thing last year and after all that work, went back to the default Freetype. The color is far too apparent in the hinting with this patch on an LCD, but is quite nice on a CRT. I'd stay away if you use a LCD, otherwise go for it.
Back to top
View user's profile Send private message
randomusername01
n00b
n00b


Joined: 30 Mar 2004
Posts: 4

PostPosted: Wed Jul 28, 2004 2:32 pm    Post subject: Reply with quote

It looks great apart from the fact that bold fonts have too much hinting. I, sometimes, have to increase the font size to make them readable as a result.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum