Problems with bah.cairo ...

BlitzMax Forums/Brucey's Modules/Problems with bah.cairo ...

mic_pringle(Posted 2008) [#1]
Hi,

I've been trying to use the bah.cairo module but have run into several issues that I can't seem to resolve.

It only happens when running the following examples ...

pattern_fill
text
text_align_center
text_extents
clock_image
clock
pdf_output
clock_gtk_panel_pixmap

When I first installed the modules, they would crash immediately on launch and I would get the 'report to apple' popup (I'm on Leopard 10.5.5 by the way) so I searched the forums and found that a newer version of FreeType should sort it. I have downloaded and installed this newer version as the thread instructed (by Brucey), and rebuilt all modules, but now instead of crashing on launch i just get the spinning beach-ball until I hit 'stop' or use force quit.

Any ideas on how I can get this working ?

Thanks

-Mic


mic_pringle(Posted 2008) [#2]
Any ideas anyone ? Brucey ?

Thanks

-Mic


Brucey(Posted 2008) [#3]
I think the issue may be related to fontconfig.

Having a rummage through the latest cairo code (and mailing list, and google searching), it seems that it *may* be possible to build Cairo with FreeType support but without fontconfig. But I will need to experiment, since finding snippets like this in the code :
    /* If making this compile without fontconfig, use:
     * index = FT_Get_Char_Index (face, ucs4); */
    index = FcFreeTypeCharIndex (face, ucs4);

don't fill me with much excitement...
(whatever happened to compiler directives??)

Anyway... when fontconfig first initialises, it attempts to cache all the fonts (on your system), creating a rather large font cache file, which it will then use on subsequent starts. This can take a while (depending on your computer/no of fonts), and does indeed cause the spinning beach ball to appear.
This may be what it is trying to do for you.

However, if I can remove altogether the fontconfig option, it would be my preferred route.


mic_pringle(Posted 2008) [#4]
Hi Brucey,

Thanks for the update.

Please keep me posted if you decide to go down this route and release a new version without the dependency on FontConfig as I'd really like to make use of this module.

Also, when do you expect the GraphicsMagick module to be released ?

Thanks

-Mic


Difference(Posted 2008) [#5]
Is this the same problem: http://blitzmax.com/Community/posts.php?topic=72173 ?

(BTW. that topic could be moved here to Brucey's Modules)


Brucey(Posted 2008) [#6]
if you decide to go down this route

Well, I've managed to get the latest code (cairo 1.8.4) to build without fontconfig, although currently it crashes when trying to do anything with text - which is to be expected really, since I haven't plugged in any code to replace that which is missing. However, the rest of it seems to be working as before, so there is still hope.
The next task would be to work out how to re-apply text support without the help of fontconfig (which takes care of 1) finding fonts, 2) configuring the correct font options). We'll have to see how that goes...

when do you expect the GraphicsMagick module to be released ?

When it's done... :-p
There's a WIP available from SVN if you want to have a play with it in the mean time. (bah.magick - also requires bah.libxml)
So far it has built-in pixmap Loader support, which allows you to do the usual things such as,
Local image:TImage = LoadImage("incbin::hippo.jpg")

So if you want to use it as a drop-in replacement for loading images, it currently works as expected.
But there's lots and lots still to do on the image manipulation front. But it's going quite well for now.


Brucey(Posted 2008) [#7]
Well, by jove... I think I've cracked it... :-)

More or less...

Currently, you might do something like this to choose a font :
cairo.SelectFontFace( "arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)


My current hack involves the following extra gumph :
Extern
	Function cairo_ft_font_face_create_for_ft_face:Byte Ptr(ft_face:Byte Ptr, loadFlags:Int)
End Extern

Local ft_face:Byte Ptr = loadft("chiller.ttf")
If Not ft_face
	DebugLog "crap"
	End
End If

Local cface:TCairoFontFace = TCairoFontFace._create(cairo_ft_font_face_create_for_ft_face(ft_face, 0))
cairo.SetFontFace(cface)

...

...


' and some glue for loading FT fonts ripped from freetypefont.bmx
Function LoadFT:Byte Ptr( src$ )

	Global ft_lib:Byte Ptr
	
	If Not ft_lib
		If FT_Init_FreeType( Varptr ft_lib ) Return Null
	EndIf

	Local buf:Byte Ptr,buf_size:Int
			
	Local ft_face:Byte Ptr

	If src.Find( "::" )>0
		Local tmp:Byte[]=LoadByteArray( src )
		buf_size=tmp.length
		If Not buf_size Return Null
		buf=MemAlloc( buf_size )
		MemCopy buf,tmp,buf_size
		If FT_New_Memory_Face( ft_lib,buf,buf_size,0,Varptr ft_face )
			MemFree buf
			Return Null
		EndIf
	Else
		If FT_New_Face( ft_lib,src$,0,Varptr ft_face ) Return Null
	EndIf
	
	Return ft_face

End Function


... and it all worked first time, which was a little surprising.

Not sure if any of the bold/italic etc will work now, without adding some more code (somewhere), and I need to put it all somewhere.
I'm thinking that it can hide behind the current function "SelectFontFace", unless someone has any better ideas?


Brucey(Posted 2008) [#8]
Ah... of course, italics and bold are usually in separate font files, which is kind of what fontconfig looks after for you.

Is it a huge loss for you to have to be more exact with your font name? Or would you prefer to keep fontconfig for that use, and deal with the fact that it requires time to cache fonts etc.

I'm happy to leave out fontconfig if it makes cairo (generally) faster.

Any thoughts?


Brucey(Posted 2008) [#9]
Amazingly, it all compiled and ran first time on the Mac (Intel)... who'd have thunk it...


Brucey(Posted 2008) [#10]
Hokay. I've committed it to SVN.

If someone would like to have a go and see if it works for them?

The linux build uses the system libcairo etc, so there should be no change on that platform.


Difference(Posted 2008) [#11]
The new version seems perfect.

All text examples runs fast and without problems on Windows Xp on a Intel MacBook.

Great work as usual, 1000 * thanks.


mic_pringle(Posted 2008) [#12]
Fantastic ... will try this as soon as I get home tonight ?

So does this mean that Bah.Cairo now has no dependencies what so ever ?

Thanks

-Mic


Brucey(Posted 2008) [#13]
So does this mean that Bah.Cairo now has no dependencies what so ever ?

Just some of the default BlitzMax modules.
Nothing else.


mic_pringle(Posted 2008) [#14]
Brilliant ... looking forward to have a play around with this. Thanks for putting in the time to do this Brucey, it's greatly appreciated.

Thanks

-Mic


Space_guy(Posted 2008) [#15]
this is great news. i put of using cairo becourse of those problems.


mic_pringle(Posted 2008) [#16]
Checked out, compiled and it works like a charm. Fantastic !

Thanks again for the great work.

-Mic