Behdad Esfahbod's daily notes on GNOME, Pango, Fedora, Persian Computing, Bob Dylan, and Dan Bern!

My Photo
Name:
Location: Toronto, Ontario, Canada

Ask Google.

Contact info
Google
Hacker Emblem Become a Friend of GNOME I Power Blogger
follow me on Twitter
Archives
July 2003
August 2003
October 2003
November 2003
December 2003
March 2004
April 2004
May 2004
July 2004
August 2004
September 2004
November 2004
March 2005
April 2005
May 2005
June 2005
July 2005
August 2005
September 2005
October 2005
November 2005
December 2005
January 2006
February 2006
March 2006
April 2006
May 2006
June 2006
July 2006
August 2006
September 2006
October 2006
November 2006
December 2006
January 2007
February 2007
March 2007
April 2007
May 2007
June 2007
July 2007
August 2007
September 2007
October 2007
November 2007
December 2007
January 2008
February 2008
March 2008
April 2008
May 2008
June 2008
July 2008
August 2008
October 2008
November 2008
December 2008
January 2009
March 2009
April 2009
May 2009
June 2009
July 2009
August 2009
November 2009
December 2009
March 2010
April 2010
May 2010
June 2010
July 2010
October 2010
November 2010
April 2011
May 2011
August 2011
September 2011
October 2011
November 2011
November 2012
June 2013
January 2014
May 2015
Current Posts
McEs, A Hacker Life
Wednesday, May 02, 2007
 Justified text with Pango

...is not unsupported anymore.

pango-view-justify

The first paragraph has positive letter spacing, and then justified. As you see the third line didn't hvae any space chars and so is justified by applying more letter spacing. Now the Latin part has unfairly long words and short lines, but Arabic works much better than I expected.

It's a very simple greedy algorithm. Mathias Hasselmann start writing patches, and hours later and three ~100 line patches, I've got it all working and nicely interacting with letter-spacing too.

Six year old bugzilla entry here.

Labels: , ,

Comments:
Now there is just the hyphenation left ;-)
 
Yeah, thinking about that.
 
Simple (greedy) algorithms are often the best, but I remember being told that you can apply Bresenham's algorithm to justify text evenly, such as breaking 8px into three gaps as 3+2+3 rather than the unbalanced 3+3+2 that a naive greedy algorithm would deliver. In this case, we would be calculating widths of inter-word spaces, rather than counting contiguous pixels for each row of a rendered line segment (for a line that is wider than it is tall), but the idea is the same.

I don't know if it's worth the effort of coding it up, but I thought you might be interested by the analogy.
 
Thanks for the comment. My implementation gives 3+2+3. It works by:

round(1 * 8./3) - 0 = 3
round(2 * 8./3) - 3 = 2
round(3 * 8./3) - 5 = 3
 
Rock! You can't imagine how much pain the lack of justification caused Tomas when porting abiword 2.5 to Pango! Very cool (it's too late to get it in AbiWord 2.6 though).

Now if only you can add a proper UCS4 API to pango instead of the current UTF8 only one, that'd be awesome :D (we have to do constant conversions when rendering, as AbiWord is UCS4 only internally for speed). This is one of the reasons why our pango renderer is slower (no hard numbers, sorry) than our own renderer. - uwog
 
Thanks a lot for your amazing work. Fonts in gnome are improving a lot.
 
Excellent, many thanks Behdad. I assume proper justification for Arabic (not using word spacing) is in the works ?
 
Totally in the works.

UTF-32 API too, I'll give it a shot.
 
What about kashida-justified text as imagined by Microsoft?
 
Soon.
 
Congratulations for making gnome better with your work!
 
Great. Thanks for your work. It works well for Thai, too, except that I wish character spacing were applied in every line, not just the ones without space. As spaces are rare in Thai texts, when there is one, it's extraordinarily wide. Distributing spaces in characters as well would help reduce it. (screenshot)
 
What about the TeX line-breaking algorith? What about hyphenation?
 
TeX-style h&j at some point... who knows..
 
I grabbed the latest pango release today
(1.17.3) but I can't get it work. when
I run pango-view --justify
test-justify.txt I get a hughe window and
the span is not removed. No line breaks
at all. I thought the justification code
is in this release. Whats wrong?

Regards,
yaleo
 
Ah, sorry, I fount out how it works.

Regards,
yaleo
 
You need to set a width too. Try --width=500
 
Post a Comment

Links to this post:

Create a Link



<< Archive
<< Home