Pango/Cairo: Problems with Pango Layout & markup, and a Font size issue



Hello,

I have some questions regarding the usage of Pango and some of its Functions.
At first a bief project description of whats this about, again I think ;-).
I'm working on a text engine for the use in the field of the digital humanities. The input data is processed manually using some selfwritten algorithms for line breaking, hyphenation and text positioning. For the calculation of the text size I use a part of Pango/Cairo, and the output as PDF is done through the PDFSurface Interface given in the Pango/Cairo Namespace. Development platform is .net, main language F#, and C# for some utils and the program loaders. We try to keep in sight to develop this tool so that it is useable with Mono, but thats still in development, at the moment it is only Windows. The access to the libraries is done through some wrapper-libraries, provided by the mono-project, if I'm correct.

During the development several problems occurred, I will try to describe them and hope that there is some cure for this.

The Font size issue.
Font sizes in the input data are given in point, it may look loke this one, as an attribute in an xml element:

font-family="Linux Libertine Display" font-size="12.0pt"

So, the font config data is stored and later set through some markup settings with the original text.
This looks something like this in code:

let PangoLayout:Pango.Layout = Pango.CairoHelper.CreateLayout(ctx)

PangoLayout.Justify             <- true
PangoLayout.Width               <- (blockWidth * Pango.Scale.PangoScale)
PangoLayout.Wrap                <- Pango.WrapMode.Word
PangoLayout.Indent              <- 0
PangoLayout.SingleParagraphMode <- true
PangoLayout.Alignment           <- Alignment.Left

PangoLayout.SetMarkup(markupString)
(return PangoLayout)

The content of markupString looks like this

<span face="Linux Biolinum" foreground="black" size="16384" >Ansileubus: Pal. Lat. </span>

or, a little longer ( one whole line over an A4 page width with margin )

<span face="Linux Libertine Display" foreground="black" size="12288" >Ab inventrice vocatum. Isis enim regina· aeg y ptiorum· id genus </span>

The class libraries produce layout lines from this input, and the layout line is then placed onto a PDFSurface using some other method calls.

This in general works nice, font loading, even OpenType is with the correct font naming no problem, and print result looks really nice ;-). The font size problem became visible at first when I compared a bigger document, one edition processed with apache fop, one with my own engine. The fop-Variant was about 600 pages long, my variant went up to a thousand pages, with the same content, same font, same size settings. Looking for an error, I found that the font size in my document is reproducible about one third larger than the value I specified in the input. We tried several ways of setting the font properties, from setting it directly into the Pango Layout through the attributes and methods provided, using the FontDescription.FromString() Method or as now done setting it through the pango markup feature. During the processing of the input values, there is no conversion of data types that would alter the value of the font size, only at the last point where the operation "value * PangoScale" is done before setting the value. PangoScale seems to have tha value 1024 on my windows computer. The effect is also reproducable on other machines, it is not limited to mine. Searching through the net I found one entry in a mailing list, http://go-mono.com/forums/#nabble-td1502761 , but the suggested method won't help me, and I also had no success getting some of the GTK-Print examples to work.

So now I ask here: Where is my error in this procedure, is there anyone else with this kind of problem ? One naive workaround was to adjust all given values so that this "one-third" gets cut of, but that is - honestly - at first very dirty, and produces more problems than needed, as there will be a lot of uneven numbers created.

The second problem occurrs in the same position of the code.

as you see, we use the pango markup to set Font properties, and we use it for underlining, color, superposition or lower positioning and so on. For our typesetting we need to support justification for the text. Pango supports this, and as you see even the Justify flag is set, in a dirty hardcoded way at the moment. I have found out that the justification kind of breaks when the input text contains any kind of markup. If there is markup, the text is automatically aligned to the left, "ragged margin" seems to be the translation for the german "Flattersatz". If I remove the markup and provide only pure text I get a perfect justified text.

So the next question: Why is that so, and what can I do to solve it ?

While writing this essay, some more questions I got my mind into, I may ask this one here as I writing this ;-)

Is there a way to configure mixed text that is aligned both left and right, like a mixed text with one part English and the other part Hebrew, like for a dictionary ?


So, thats it for now. I hope you have some idea what I am doing wrong while abusing libraries ;-)

Thanks for your help !

Greetings,

roland schwarz


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]