Pages

July 15, 2010

Firefox 3.6 with pretty fonts in Debian Squeeze (easier version)

[Update 2011-06-25: You should consider this post obsolete. See this post for more info.] 
 
If all the Mercurial and Namoroka in my previous posts about building and installing Firefox 3.6 in Squeeze has your head spinning a bit, here's a simplified version that gets the sources via FTP. As was the case in the previous build, this version enables cairo so you get nicer font rendering. This version also configures the build to use official Mozilla Firefox branding so you don't get Deer Park icons and such.

Preproduction
1) Create a working directory. Use a file manger or whatever you are comfortable with to do this. I called mine ~/firefox-release.

2) Get all the tools and things you need to build Firefox. In a terminal as root (using su):

# apt-get build-dep iceweasel
# apt-get install libasound2-dev libcurl4-openssl-dev libnotify-dev libxt-dev libiw-dev mesa-common-dev autoconf2.13 yasm
# apt-get install libidl-dev


Get and build
1) Get the source code. Open a web browser or ftp client and go to ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/3.6.6/source/. Download firefox-3.6.6.source.tar.bz2 into ~/firefox-release. (If 3.6.6 is no longer the most recent version, then replace 3.6.6 above with whatever the most recent 3.6 happens to be.)

2) Extract the archive you downloaded. Use tar -jxvf *.tar.bz2 on the command line or whatever GUI tool you are comfortable with. This will give you a mozilla-1.9.2 directory inside ~/firefox-release.

3) Make a configuration file. Create a new file inside ~/firefox-release/mozilla-1.9.2 called mozconfig. Open mozconfig inside a text editor and paste in the following text:

. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/ff-release
#mk_add_options MOZ_MAKE_FLAGS="-j4"
ac_add_options --disable-debug
ac_add_options --disable-tests
ac_add_options --enable-optimize
ac_add_options --enable-official-branding
ac_add_options --enable-system-cairo

Save the file and exit the editor.

3) Build the beast by opening a terminal in ~/firefox-release/mozilla-1.9.2 and entering the following command:

make -f client.mk

Once the compile is done, the binaries will be in
~/firefox-release/mozilla-1.9.2/ff-release/dist/bin/.
As a test, execute the file firefox to make it go.

"Install"
1) Copy the contents of the bin directory to /opt, converting links to actual files. Do not try to copy the files with a file manager because it probably won't convert the links to files--which will render your "install" nonfunctional. Instead, open a terminal and go to ~/firefox-release/mozilla-1.9.2/ff-release/dist/. Then become root (using su) and do:

# cp -R -L bin /opt/firefox-release
# chown root:root -R /opt/firefox-release


You should now have a new directory in /opt called firefox-release. Inside it will be an executable file called firefox. If all went well, executing this file (NOT as root) will launch the browser.

2) Create a command that lets you launch the browser. As root, make a softlink from /usr/local/bin/firefox to /opt/firefox-release/firefox:

# ln -s /opt/firefox-release/firefox /usr/local/bin/firefox

3) Create a desktop file to introduce the new stuff to the menu. As root, create a file called firefox-release.desktop in /usr/local/share/applications (adding any directories that aren't already present.) Paste the following into firefox-release.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Firefox Release
Comment=Browse the World Wide Web
GenericName=Web Browser
X-GNOME-FullName=Firefox Web Browser
Exec=firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/opt/firefox-release/icons/mozicon128.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;
StartupWMClass=Firefox-bin
StartupNotify=true
Name[en_US]=Firefox Release

Save the file and exit the editor.

You're done.

July 14, 2010

Fixing OpenOffice.org font rendering in Debian Squeeze

I guess I'm on a roll with font rendering improvements...

After patching libcario2 in Squeeze, I noticed font rendering in OpenOffice.org was really awful. It may have been equally awful before and I never noticed. In any case, it's now something that needs attention.

Ugly fonts in OO.org have been reported under Ubuntu and other distributions as well. A good explanation of the problem (in Ubuntu, at least) and a workable solution is offered by Mike Kasic about halfway down the bug report at https://bugs.launchpad.net/ubuntu/+source/cairo/+bug/271283. I tried his suggestions on my Squeeze installation, and it worked. If you don't want to be bothered filtering through the bug report, here's the executive summary.

Fixing just the session
Open a terminal and do:
echo "Xft.lcdfilter: lcddefault" | xrdb -merge

Making the fix persist across sessions
echo "Xft.lcdfilter: lcddefault" >> ~/.Xresources

Apply the fix for all users all the time
As root:
# sudo sh -c 'echo "Xft.lcdfilter: lcddefault" > /etc/X11/Xresources/lcd-filter-lcddefault'

Note: I have only tried the first two above. I have not tested applying the change to all users.

The fix also works on my Sabayon Linux 5 install that uses the lcdpatch in cairo.

"Installing" handmade Firefox 3.6 in Debian Squeeze

[Update 2011-06-25: You should consider this post obsolete. See this post for more info.]

Yesterday we saw how to build Firefox 3.6 from sources. This post shows you how to "install" it.

The reason I put "install" in quotes is because it's arguable that what we're going to do is a real installation. In a real Linux installation, you splay the various bits and pieces of your app into /usr/local/bin, /usr/local/share, /usr/local/lib, and various other places (or /usr/bin, /usr/share, /usr/lib if it's an official distribution package). What we are going to do here is take the easy way out--but a way that lots of "packages" take. We're going to dump stuff into /opt.

If you open up {whatever}/firefox-mercurial/192src/objdir-ff-release/dist/bin/ (or wherever you built your sources), you'll see that quite a few of the items in the bin directory are relative links to resources outside bin. If we try a conventional copy of the bin directory to /opt, what we get won't work because the targets of those links won't be copied. You could copy the whole objdir-ff-release to /opt, which will copy the needed link targets, but this will produce something many MB more than we need. The solution is to convert the links into targets themselves when you copy the file. This is actually pretty easy to do using the command line.

Copy the bin
Open a terminal in {whatever}/firefox-mercurial/192src/objdir-ff-release/dist. From there, become root (using su) and then:

# cp -R -L bin /opt/ff-from-src
# chown root:root -R /opt/ff-from-src


You should now have a new directory in /opt called ff-from-src. Inside it will be an executable file called firefox, and what used to be links will now be actual files. If all went well, executing this file (NOT as root) will launch the browser.

Making commands
We will next do a couple things to let you launch your new Firefox as a command and add an item to your menu.

1. Using whatever mechanism you are most comfortable with, make a softlink called firefox in /usr/local/bin to /opt/ff-from-src/firefox. You'll need to do this as root.

2. Add a png icon called firefox-namoroka.png to /usr/local/share/pixmaps/mozilla. You'll probably need to add the pixmaps and mozilla directories. Again you'll have to be root to do this. The icon can be whatever you want the icon to be in your menu. I used this one, even though it's the same one that Swiftfox uses. I wanted an icon that said "Firefox" but that differentiated itself from the stock FF icon. I scaled the icon to 128x128. Another nice icon is this one, but in spite of the attribution given on the page, I'm not sure it's actually GPL or where it originally came from.

3. Create a file called firefox-namoroka.desktop in /usr/local/share/applications again adding any directories you need and again as root. Copy/paste the following into firefox-namoroka.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Firefox Namoroka
Comment=Browse the World Wide Web
GenericName=Web Browser
X-GNOME-FullName=Firefox Web Browser
Exec=firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/usr/local/share/pixmaps/mozilla/firefox-namoroka.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;
StartupWMClass=Firefox-bin
StartupNotify=true
Name[en_US]=Firefox Namoroka

You should now have an entry in your desktop menu and other desktop integration niceness.

July 13, 2010

Firefox 3.6 with pretty fonts in Debian Squeeze

[Update 2011-06-25: You should consider this post obsolete. See this post for more info.] 

Iceweasel 3.6 has yet to trickle down to Debian Testing and very well may not make it before the freeze. However, some of us would like to have some 3.6iness in spite of this. If you've tried downloading SwiftFox, IceCat or the Firefox 3.6 binaries, you know that you get a 3.6, but the font rendering looks poopy.

Here's what I did to compile FF 3.6 from sources and get the same smooth font rendering that you get with Iceweasel 3.5 from the Squeeze repo. I'm not an expert, but this seems to have worked.

The following is based mostly on Mozilla's documentation on a Simple Firefox Build and Linux Prerequisites.

Preproduction
First, create a working directory. I called mine firefox-mercurial. The reason for the name will become obvious shortly.

Next, get the tools you need to build stuff. Since there's no firefox package in the Debian repos, I used (as root):

# apt-get build-dep iceweasel

Then install a bunch of other stuff that is supposedly needed:

# apt-get install mercurial libasound2-dev libcurl4-openssl-dev libnotify-dev libxt-dev libiw-dev mesa-common-dev autoconf2.13 yasm

You will also have to add:

# apt-get install libidl-dev

This isn't documented anywhere that I know of. I found this out the hard way after my first attempts to compile failed.

Get sources
With a regular user terminal open in firefox-mercurial, use mercurial to get the sources:

hg clone http://hg.mozilla.org/releases/mozilla-1.9.2/ 192src

This will get you the latest, most update, bleeding edge version of 3.6--which may or may not be the same as the release version. For example, at the time of this writing, the latest version is 3.6.8pre and the latest release is 3.6.6. To specify the exact version you want, use #{tag}, where {tag} is  one of tags listed at http://hg.mozilla.org/releases/mozilla-1.9.2/. For example, to get and build FF 3.6.6:

hg clone http://hg.mozilla.org/releases/mozilla-1.9.2/#FIREFOX_3_6_6_RELEASE 192src

Getting the sources will take a long time, but not nearly as long as compiling will later on.

Next we need to move into the 192src directory and set up the mozconfig file that tells the system how to build firefox:

cd 192src
echo '. $topsrcdir/browser/config/mozconfig' > mozconfig
echo 'mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/objdir-ff-release' >> mozconfig
echo 'mk_add_options MOZ_MAKE_FLAGS="-j4"' >> mozconfig
echo 'ac_add_options --disable-debug' >> mozconfig
echo 'ac_add_options --disable-tests' >> mozconfig
echo 'ac_add_options --enable-optimize' >> mozconfig
echo 'ac_add_options --enable-system-cairo' >> mozconfig


The objdir-ff-release is the name of the directory that built stuff will end up in. You can change this name if you want. The line with --enable-optimize is optional. The last option above, --enable-system-cairo, I found looking through the list of available options, and I'm pretty sure it's what gives you nice font rendering in GTK+ environments.

Build the beast with

make -f client.mk

The build will take forever. Once the compile is done, the binaries will be in
{whatever}/firefox-mercurial/192src/objdir-ff-release/dist/bin/.
Execute the file firefox to make it go.

When you make it go, you'll notice that the app is identified by its code name, Namoroka.

Updating
I have not yet tried this, but according to Mozilla's documentation, to build a new version you'll need to update the sources with

hg pull -r default
hg update


I suspect you do this in the 192src directory and I suspect you'll need to rebuild as above afterward. Also, I suspect that in place of default above you'll want to use a valid tag (as when you first cloned the sources), but until I actually update I won't be able to say for sure.

Extra credit
Once I've done some more testing, I will be move the built files to /opt/firefox and add a *.desktop entry for it. The big question is whether I should call it 'Firefox' or 'Namoroka'.

July 09, 2010

Ubuntu font rendering in Debian Squeeze

[Update 2011-06-25: Confirmed. Updating Iceweasel from http://mozilla.debian.net/ fixes fonts. See this post for more info. So there's no longer any real need to do what's below.]
[Update 2011-06-24: This whole business may be unnecessary as it appears installing a recent version of Iceweasel from http://mozilla.debian.net/ also installs new libcairo2 with decent font rendering. I've yet to do careful comparisons, but it's possible that this solves both "ugly rendering in general" as well as "ugly rendering in Firefox" issues.]
[Update 2011-03-08:]  Reader datSilencer points out that the location of the Arch patch has moved. Therefore, the process for extracting and applying the Arch patch won't work. I am updating the script but I won't be updating this post. If you want to do things manually, please consult the script for the needed changes.]
[Update 2010-09-23: I made a script to semi-automate a lot of the following.]

I love Debian. I really do. But one thing I don't love about Debian is the way it renders fonts in GTK. Or rather, the way Ubuntu renders fonts has spoiled me. After reading about how some people have successfully patched their libraries to use the same changes used by Ubuntu, I've finally succeeded myself. It's been so gratifying and such a good learning experience that I wanted to share.

The process below is based on information from the CrunchBang Linux Forums and from one quanliking. Huge, huge thanks to those people.

To get Ubuntu font rendering in Debian Squeeze, we need to download, patch, rebuild, and reinstall the libcairo2 package. If this breaks your system don't sue me. I am not an expert nor do I play one on TV.

Pre-production
Begin by making sure downloading of package sources is enabled for apt. The line below should be in /etc/apt/sources.list and not commented out:

deb-src http://ftp.us.debian.org/debian/ squeeze main non-free contrib

The actual address will differ depending on which mirror you set up your system to use, but there should be a line that begins "deb-src", has a mirror's address in the middle, and ends with "squeeze main non-free contrib" or "testing main non-free contrib".

Install the needed build tools (as root):

# apt-get install build-essential devscripts fakeroot
# apt-get build-dep cairo


As a regular user, create a new directory called patched-packages in your home directory.

Get the patches
Open the patched-packages directory you created above in a terminal (i.e., the prompt should read something like username@computername:~/patched-packages$).

At the command prompt:

mkdir libcairo2
cd libcairo2
mkdir downloaded-patches


We now need to get two sets of patches, one from Ubuntu and the other from Arch Linux. To get the Ubuntu patches, go to http://packages.ubuntu.com/lucid/libcairo2 and look at the list of links on the right. We want the file cairo_1.8.10-{#}ubuntu1.debian.tar.gz. Download it into ~/patched-packages/downloaded-patches and expand it. This should produce a new directory inside ~/patched-packages/downloaded-patches called debian (i.e., you should now have a ~/patched-packages/downloaded-patches/debian).

I'm not yet sure what the original source of the Arch Linux patch is, but apparently we need it. So go to http://aur.archlinux.org/packages.php?ID=17327 and download the file cairo-respect-fontconfig.patch into ~/patched-packages/downloaded-patches

You're done getting patches.

Get the sources
We now need to get the Debian source package for libcairo2. In a terminal inside ~/patched-packages/libcario2,

mkdir deb-sources
cd deb-sources
apt-get source cairo
cd ./cairo-*


Then copy the patches we downloaded earlier to the Debian package's patches directory:

cp ../../downloaded-patches/cairo-respect-fontconfig.patch ./debian/patches/
cp ../../downloaded-patches/debian/patches/04_lcd_filter.patch ./debian/patches/
cp ../../downloaded-patches/debian/patches/06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch ./debian/patches/


Next, apply the patches to the sources:

patch -p1 -i ./debian/patches/cairo-respect-fontconfig.patch
patch -p1 -i ./debian/patches/04_lcd_filter.patch
patch -p1 -i ./debian/patches/06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch


We now need to modify the changelog to indicate that we've diddled with the package and set a version increment:

dch -i

This will open a text editor. Once there, add

David Turner's ClearType-like LCD filtering patch and fix.

after the asterisk at the top and then save and exit.

(Note: Instead of dch -i above you can also use dch -l {your initials}.)

Build and install
Time to build it. Continuing from where we were in the terminal above (i.e., inside something like ~/patched-packages/libcairo2/deb-sources/cairo-1.8.10) do

dpkg-buildpackage -rfakeroot -us -uc

The result should be a bunch of new packages inside ~/patched-packages/libcairo2/deb-sources/

Look if you don't believe me. All that's left is to install. Open a root terminal and go to the ~/patched-packages/libcairo2/deb-sources/ directory. Then do:

# dpkg -i *.deb

This will install all the debs that were made, of which you may actually only need a subset. Apart from taking up some disk space the extra packages won't hurt anything, and if you install a package in the future that needs one of these, you'l be glad you installed them now.

Congrats. You should now have (IMHO) much improved font rendering. This should hold you until Debian releases a new libcairo2. If the new libcairo2 release doesn't have the "Ubuntu patches" already built in, you'll have to repeat the above process, making sure you get patches that are appropriate for the new version and that there are no additional patch files. (If there are, you will need to copy/add them before rebuilding.)

Rolling back your system to the original Debian packages should be as easy as using Synaptic to "Package -> Force Version..." to the original libcairo2 packages.

Happy building.

July 04, 2010

Debranding Firefox in PCLinuxOS

I'm not a huge fan of third-party branding. One of my (minor, when put into perspective) gripes about PCLinuxOS is that they sorta go nuts with it. One of the apps that's the target of their branding is Firefox. If you are equally bugged by this, debranding the default profile used as the template for new profiles isn't that hard.
  1. Download the official firefox-3.{whatever}.tar.bz2 archive from Mozilla's servers. Be sure to download the version that's the same as the one that is already installed on your machine.
  2. As root, deflate the archive. I am pretending we're in /opt and got a /opt/firefox directory:
    # tar -jxvf firefox-3.{whatever}.tar.bz2
  3. Again as root, replace /usr/lib/firefox-3.{whatever}/defaults/profile with /opt/firefox/defaults/profile
Now you can delete the profiles in ~/.mozilla/firefox. (This will of course wipe out all your old bookmarks, etc. Jump through the needed hoops now if you want to save anything.) When you restart Firefox you'll now get the profile defaults, links, etc. that the Mozilla upstream devs thought you would want. The same will be true for any new users or profiles you create from now on.

The downside to this is that to keep the PCLinuxOS branding at bay you'll need to repeat steps 1-3 every time a new FF update is installed.

July 03, 2010

Fixing ugly fonts in Sabayon Firefox

I've been taking the Gentoo-based Sabayon rolling release distribution for a spin. One of the things that you'll notice is that some fonts in Firefox look ghastly horrible. Luckily, there's an easy fix. The problem involves the rendering of Helvetica, Lucida, and Times fonts and is discussed (and solved) on the Gentoo mailing list.

Instead of editing /etc/fonts/local.conf, I changed my ~/.fonts.conf file. I got better results using "Sans" than "DejaVu Sans" and in a similar spirit I used "Serif" instead of "DejaVu Serif". My entire .fonts.config looks like:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

<!-- see http://www.mail-archive.com/gentoo-user@lists.gentoo.org/msg83300.html -->
<!-- Replace Helvetica with DejaVu Sans -->
<match target="pattern" name="family">
        <test name="family" qual="any"><string>Helvetica</string></test>
        <edit name="family" mode="assign">
                <string>Sans</string>
        </edit>
</match>

<!-- Replace Lucida with DejaVu Sans -->
<match target="pattern" name="family">
        <test name="family" qual="any"><string>Lucida</string></test>
        <edit name="family" mode="assign">
                <string>Sans</string>
        </edit>
</match>

<!-- Replace Times with DejaVu Serif -->
<match target="pattern" name="family">
        <test name="family" qual="any"><string>Times</string></test>
        <edit name="family" mode="assign">
                <string>Serif</string>
        </edit>
</match>
<!-- -->

<match target="font" >
  <edit mode="assign" name="hinting" >
   <bool>true</bool>
  </edit>
</match>
<match target="font" >
  <edit mode="assign" name="hintstyle" >
<!--
   <const>hintmedium</const>
-->
   <const>hintslight</const>
  </edit>
</match>
<match target="font" >
  <edit mode="assign" name="rgba" >
   <const>rgb</const>
  </edit>
</match>
<match target="font" >
  <edit mode="assign" name="antialias" >
   <bool>true</bool>
  </edit>
</match>

</fontconfig>

Speaking of font rendering, Sabayon has default font rendering that's almost as nice as Ubuntu's. IMHO the only thing that gives Ubuntu the edge is a bit more contrast. If I find a fix for this, I will post this as well.