[Mono-list] Fontsize in Pango.Layout

Aaron Bockover abockover at novell.com
Thu Jun 5 13:02:28 EDT 2008


I didn't actually read your code, but when using Cairo to render Pango layouts, you must inform Cairo of the DPI setting, otherwise you will see a scaling difference between Cairo and Gdk. Cairo defaults to 96 DPI.

You need to call pango_cairo_context_set_resolution to do this (on the Pango context). You can get the resolution easily through the Screen.Resolution property of a Gtk.Widget.

http://svn.gnome.org/svn/banshee/trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
http://svn.gnome.org/svn/banshee/trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui/PangoCairoHelper.cs

See CreateLayout in CairoExtensions.cs. 

All of this should be possible by using more recent Gtk# and Mono.Cairo. We just need to run on older Gtk# releases, so some of the functionality is bound manually in Banshee. 

--Aaron

>>> Elmar Haneke <elmar at haneke.de> 06/05/08 6:39 AM >>>
Fontsize management in Pango.Layout seems to be broken.

The Code below does print using Pango and using Cairo directly, the
fortsizes are obviously different.

Is there any problem in my Code?

Where to file this bug?


class PrintTest {

	public static void Main (string[] args) {
		Cairo.PdfSurface surface=
		new Cairo.PdfSurface("Test.pdf",mm(210),mm(297));
		Cairo.Context cc=new Cairo.Context(surface);

		Test1(cc,20,20,"Arial",8);
		Test1(cc,20,30,"Arial",10);
		Test1(cc,20,40,"Arial",12);
		Test1(cc,20,50,"Times New Roman",8);
		Test1(cc,20,60,"Times New Roman",10);
		Test1(cc,20,70,"Times New Roman",12);
		
		Test2(cc,80,20,"Arial",8);
		Test2(cc,80,30,"Arial",10);
		Test2(cc,80,40,"Arial",12);
		Test2(cc,80,50,"Times New Roman",8);
		Test2(cc,80,60,"Times New Roman",10);
		Test2(cc,80,70,"Times New Roman",12);

		surface.Finish();
	}

	static void Test1(
		Cairo.Context cc,
		double xCor,
		double yCor,
		string FontName,
		double FontSize
	) {
		Pango.Layout layout =
			Pango.CairoHelper.CreateLayout(cc);
		
		layout.FontDescription =
			Pango.FontDescription.FromString(FontName);
		layout.FontDescription.Size=
			(int)(FontSize * Pango.Scale.PangoScale);
		
		layout.SetText(FontName + " " + FontSize.ToString());
		
		cc.MoveTo (mm(xCor),mm(yCor));
		
		Pango.CairoHelper.ShowLayout(cc,layout);
	}
	
	static void Test2(
		Cairo.Context cc,
		double xCor,
		double yCor,
		string FontName,
		double FontSize
	) {
		cc.SelectFontFace(
			FontName,
			Cairo.FontSlant.Normal,
			Cairo.FontWeight.Normal);
		cc.SetFontSize(FontSize);
		cc.MoveTo(mm(xCor),mm(yCor));
		cc.TextPath(FontName + " " + FontSize.ToString());
		cc.Fill();
	}
	
	static double mm(double mmVal) {
		return mmVal*72.0/25.4;
	}
}
_______________________________________________
Mono-list maillist  -  Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list