[Gtk-sharp-list] RE: Inserting attributes into a Pango.Layout

Willem J.W. Semmelink willems@digicore.co.za
Tue, 24 Feb 2004 14:44:03 +0200


Hi Tiago
I tried some of the code that you had a problem with, and I also get an =
error result, although not a Null Exception.=20

I use Pango as follows:

//dc is a global Gtk.DrawingArea
pixmap =3D new =
Gdk.Pixmap(dc.GdkWindow,dc.Allocation.width,dc.Allocation.height,-1);
Pango.FontDescription fontdesc =3D new Pango.FontDescription();
fontdesc.Family =3D "Sans";
fontdesc.Size =3D 16;
fontdesc.Style =3D Pango.Style.Italic;
fontdesc.Stretch =3D Pango.Stretch.Normal;
Pango.Layout layout =3D dc.CreatePangoLayout("Hello There");
layout.FontDescription =3D fontdesc;
pixmap.DrawLayout(dc.Style.BlackGC,10,100,layout);

The above runs fine.=20

I tried the following code from your example:
Pango.Attribute attribute =3D Pango.Attr.ForegroundNew(0xff, 0, 0); // =
red=20
attribute.start_index =3D 0;
attribute.end_index =3D 1;
layout.Attributes.Insert(attribute);

I inserted the above extract from your code just before my last line =
(before the DrawLayout statement)
The application executed. The text was still displayed, but not with the =
red attribute. =20
It reported the following to the command-line, without crashing.=20

** (<unknown>:216): CRITICAL **: file pango-attributes.c: line 895 =
(pango_attr_l
ist_insert): assertion `list !=3D NULL' failed

** (<unknown>:216): CRITICAL **: file pango-attributes.c: line 895 =
(pango_attr_l
ist_insert): assertion `list !=3D NULL' failed

I compiled with Visual Studio with .NET 1.1, and executed on Gtk# 0.15.
I then executed it with Mono 0.30 and I also got the above message to =
the command-line.

Regards
Willem

-----Original Message-----
   1. Inserting attributes into a Pango.Layout (Tiago Lima)

Message: 1
From: Tiago Lima <tiago.lima@vianw.pt>
To: gtk-sharp-list@lists.ximian.com
Date: Mon, 23 Feb 2004 15:08:37 +0000
Subject: [Gtk-sharp-list] Inserting attributes into a Pango.Layout

Hi,

I have some problems inserting Attributes into the Pango.Layout. Well, =
the=20
attributes are inserted (I guess) but when it comes to draw the layout =
(in=20
Gdk.Drawable.DrawLayout it gives me a null pointer exception inside the=20
"unmanaged" code (i think in the C code ?)...

Unhandled Exception: System.Reflection.TargetInvocationException: =
Exception=20
has been thrown by the target of an invocation. --->=20
System.NullReferenceException: A null value was found where an object=20
instance was required
in (unmanaged) (wrapper managed-to-native) Gdk.Drawable:gdk_draw_layout=20
(intptr,intptr,int,int,intptr)
in <0x00004> (wrapper managed-to-native) Gdk.Drawable:gdk_draw_layout=20
(intptr,intptr,int,int,intptr)
in <0x00061> Gdk.Drawable:DrawLayout (Gdk.GC,int,int,Pango.Layout)

Is this a bug or should I initialize some more things before ?

For example, I'm doing this:

	_pangoLayout =3D _gtkDrawingArea.CreatePangoLayout("some text");
	_pangoLayout.Attributes =3D new AttrList();  // because =
_pangoLayout.Attributes=20
is null !
	_pangoLayout.SetText("hello this is a test text");
=09
	Pango.Attribute attribute =3D Pango.Attr.ForegroundNew(0xff, 0, 0); // =
red=20
color
	attribute.start_index =3D 0;
	attribute.end_index =3D 1;
	_pangoLayout.Attributes.Insert(attribute);

This is ok, now when it draws:

		protected void OnExpose(object sender, ExposeEventArgs args)
		{
			_gtkDrawingArea.GdkWindow.DrawLayout(_gtkDrawingArea.Style.BlackGC, =
0, 0,=20
_pangoLayout);
		}

it gives the exception (inside the DrawLayout function).

Do you want me to post a bug on this ?

Is anyone using Pango right now? Anybody experiencing this?

Thanks,
	Tiago Lima