Hi Martin,

Thanks for the reply - in fact those methods have just been recently added
by Esteban who very kindly sent me the answers!

Cheers,
Stewart

On Sun, Jan 30, 2022 at 1:06 AM Martin Dias <[email protected]> wrote:

> Hello Stewart,
>
> I didn't know how to answer your question, but I've found an
> implementation of the same call. See the send of #listFamilies:count:
> message in:
>
> https://github.com/pharo-spec/gtk-bindings/blob/9cda0f563023c68714c6c54e6c5f77f3c57b6c90/src/Pango/PangoFontMap.class.st#L53
>
> Cheers,
> Martìn
>
> On Tue, Jan 25, 2022 at 7:36 AM Stewart MacLean <[email protected]>
> wrote:
> >
> > Hi,
> >
> > I'm trying to figure out how to implement code to retrieve a list of
> font families using the Pango libraries. The key function definition is:
> >
> >  https://docs.gtk.org/Pango/method.FontMap.list_families.html
> >
> > void
> > pango_font_map_list_families (
> >   PangoFontMap* fontmap,
> >   PangoFontFamily*** families,
> >   int* n_families
> > )
> >
> > I've found some C code, which is shown below. The tricky  bit is the
> ***. I've managed to get this working in VisualWorks (code also below), but
> can't figure out how to do this using the Pharo FFI.
> >
> > I've managed to get the basic Pango functionality going, but I can't
> figure out how to use ExternalAddress to do this. Running on a MacMini M1.
> >
> > Any pointers (:)) appreciated!
> >
> > Thanks,
> >
> > Stew
> >
> > C Version
> > ----------------
> >  #include <glib.h>
> > #include <pango/pangocairo.h>
> >
> > static void
> > list_fonts ()
> > {
> >     int i;
> >     PangoFontFamily ** families;
> >     int n_families;
> >     PangoFontMap * fontmap;
> >
> >     fontmap = pango_cairo_font_map_get_default();
> >     pango_font_map_list_families (fontmap, & families, & n_families);
> >     printf ("There are %d families\n", n_families);
> >     for (i = 0; i < n_families; i++) {
> >         PangoFontFamily * family = families[i];
> >         const char * family_name;
> >
> >         family_name = pango_font_family_get_name (family);
> >         printf ("Family %d: %s\n", i, family_name);
> >     }
> >     g_free (families);
> > }
> >
> > int main (int argc, char ** argv)
> > {
> >     list_fonts ();
> >     return 0;
> > }
> >
> > =================================
> > VisualWorks Version
> > ---------------------------
> > availableFamilyNames
> > "
> > Transcript clear.
> > (FontFamily availableFamilyNames asSortedCollection: [: a : b | a < b])
> do: [: each | Transcript cr; show: each].
> >
> > NamedFontSelector open
> > "
> >
> > "08/09/20 SIM. Modified to work on 64bit.
> > Clues obtained from:
> > XSurface class >>displaySurface:
> > DisplaySurface>>cairoVisual
> > PDFSurface class>>versions"
> >
> > | listPointer sizePointer ffPointers result |
> >
> > ObjectMemory is64Bit
> >   ifTrue:
> >     [listPointer := CIntegerType unsignedLongLong gcMalloc.
> >     sizePointer := listPointer sizeof gcCopyToHeap]
> > ifFalse:
> >    [listPointer := 0 gcCopyToHeap.
> >    sizePointer := 0 gcCopyToHeap].
> >
> > LibPango default
> > pango_font_map_list_families: LibPango default
> pango_cairo_font_map_get_default
> > with: listPointer
> > with: sizePointer.
> >
> > ffPointers :=
> > (ObjectMemory is64Bit
> >    ifTrue: [CIntegerType unsignedLongLong]
> >    ifFalse: [ CIntegerType unsignedInt])
> >         newPointerToAddress: listPointer contents.
> >
> > result := OrderedCollection new: sizePointer contents.
> > sizePointer contents timesRepeat:
> >      [result
> >          add: (LibPango default pango_font_family_get_name: ffPointers
> contents) utf8.
> >       ffPointers += 1].
> > LibPango default g_free: listPointer contents.
> > ^result
> >
> >
>

Reply via email to