[Gtk-sharp-list] RE: Inserting attributes into a Pango.Layout
Tiago Lima
tiago.lima@vianw.pt
Tue, 24 Feb 2004 13:28:22 +0000
I think the problem appears to be that when:
Pango.Layout layout = dc.CreatePangoLayout("Hello There");
the "layout.Attributes" in my case is NULL !!! which I had to make:
layout.Attribute = new AttrList();
but in this case one wonders what needs to be initialized appart from this
"new" statement... Should it be NULL ? Is it NULL in your case ? Try making
an "if (layout.Attributes == null) <something>" right after the
CreatePangoLayout to see if its null or so...
Oh, I'm using Gtk# 0.16... didnt try with 0.15 though...
Thanks,
Tiago Lima
On Tuesday 24 February 2004 12:44, Willem J.W. Semmelink wrote:
> 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.
>
> I use Pango as follows:
>
> //dc is a global Gtk.DrawingArea
> pixmap = new
> Gdk.Pixmap(dc.GdkWindow,dc.Allocation.width,dc.Allocation.height,-1);
> Pango.FontDescription fontdesc = new Pango.FontDescription();
> fontdesc.Family = "Sans";
> fontdesc.Size = 16;
> fontdesc.Style = Pango.Style.Italic;
> fontdesc.Stretch = Pango.Stretch.Normal;
> Pango.Layout layout = dc.CreatePangoLayout("Hello There");
> layout.FontDescription = fontdesc;
> pixmap.DrawLayout(dc.Style.BlackGC,10,100,layout);
>
> The above runs fine.
>
> I tried the following code from your example:
> Pango.Attribute attribute = Pango.Attr.ForegroundNew(0xff, 0, 0); // red
> attribute.start_index = 0;
> attribute.end_index = 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. It reported the following
> to the command-line, without crashing.
>
> ** (<unknown>:216): CRITICAL **: file pango-attributes.c: line 895
> (pango_attr_l ist_insert): assertion `list != NULL' failed
>
> ** (<unknown>:216): CRITICAL **: file pango-attributes.c: line 895
> (pango_attr_l ist_insert): assertion `list != 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
> attributes are inserted (I guess) but when it comes to draw the layout (in
> Gdk.Drawable.DrawLayout it gives me a null pointer exception inside the
> "unmanaged" code (i think in the C code ?)...
>
> Unhandled Exception: System.Reflection.TargetInvocationException: Exception
> has been thrown by the target of an invocation. --->
> System.NullReferenceException: A null value was found where an object
> instance was required
> in (unmanaged) (wrapper managed-to-native) Gdk.Drawable:gdk_draw_layout
> (intptr,intptr,int,int,intptr)
> in <0x00004> (wrapper managed-to-native) Gdk.Drawable:gdk_draw_layout
> (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 = _gtkDrawingArea.CreatePangoLayout("some text");
> _pangoLayout.Attributes = new AttrList(); // because
> _pangoLayout.Attributes is null !
> _pangoLayout.SetText("hello this is a test text");
>
> Pango.Attribute attribute = Pango.Attr.ForegroundNew(0xff, 0, 0); // red
> color
> attribute.start_index = 0;
> attribute.end_index = 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, _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
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list