From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 060FE7EEBF for ; Mon, 3 Aug 2015 03:46:55 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of hendrik@topoi.pooq.com) identity=pra; client-ip=69.165.131.134; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="hendrik@topoi.pooq.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of hendrik@topoi.pooq.com) identity=mailfrom; client-ip=69.165.131.134; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="hendrik@topoi.pooq.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@april.topoi.pooq.com) identity=helo; client-ip=69.165.131.134; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="postmaster@april.topoi.pooq.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CZCAADx75V/4aDpUVbGQEBg1NEASS8eoFSD4V5gXEBAQEBAQGBC4RkNAs8NAUYiHINx2IBAQgCII9zZB6DAYEUBZF3gwKEe4dPAk94RoNak2Emgg4cgW8iMQGCSwEBAQ X-IPAS-Result: A0CZCAADx75V/4aDpUVbGQEBg1NEASS8eoFSD4V5gXEBAQEBAQGBC4RkNAs8NAUYiHINx2IBAQgCII9zZB6DAYEUBZF3gwKEe4dPAk94RoNak2Emgg4cgW8iMQGCSwEBAQ X-IronPort-AV: E=Sophos;i="5.15,598,1432591200"; d="scan'208";a="141851565" Received: from topoi.pooq.com (HELO april.topoi.pooq.com) ([69.165.131.134]) by mail3-smtp-sop.national.inria.fr with ESMTP; 03 Aug 2015 03:46:50 +0200 Received: by april.topoi.pooq.com (Postfix, from userid 1001) id 5A8A71A00CE; Sun, 2 Aug 2015 21:46:54 -0400 (EDT) Date: Sun, 2 Aug 2015 21:46:54 -0400 From: Hendrik Boom To: caml-list@inria.fr Cc: Hendrik Boom Message-ID: <20150803014654.GA30848@topoi.pooq.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [Caml-list] Using Pango with Cairo in Ocaml I'm writing here because I seem to have exhausted the wisdom of the ocam-beginners mailing list. If there's a better place for me to have sent this, and there probably is, please let me know. I'm trying to use Pango with Cairo, and to do it in OCaml. I have an example written in C, that draws a multicoloured wheel of copies of the word "text". I got it from https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html It works fine in C. But I'm running into a snag with the OCaml conversion. To make a layout, Pango wants to use a value of type Pango.context, and all I have from Cairo is a value of type Cairo.context. There seems to be no way to obtain a Pango context from a Cairo context. The obvious thing would seem to be to look at the C code to see what it did, and look for the corresponding function in the OCaml library source. But it turns out the C code just uses the Cairo context as a Pango context without any conversion at all. Pango, apparently, will just talk to a Cairo context as if it were a Pango context. Presumably that's the normal way to use Cairo in C. Now I'm not just saying that in the working C code, the Pango context and the Cairo context are the same type; that would be meaningless because both aree of the general-purpose gobject type. I'm saying they are the same *value*, i.e., the same pointer, pointing to the same thing. My immediate question is thus, how to I get Pango.context from a Cairo.context. I seem to want a type change in OCaml without a change in value. Pango.context would appear to be defined in pango.ml:28 type context = [`pangocontext] obj and for cairo.context I can merely find the line type context in both cairo.ml1 and cairo.ml. (I didn't think type definitions could be this abbreviated, but there it is. Is this some way of mentioning a type definition elsewhere tht I haven't found yet?) In the earlier cairo, the one before cairo2, there was a function fo convert a Cairo context to a Pango context. It is not present in cairo2. Now it is possibile to obtain a Cairo context from a gtk window, and also a Pango context. But since cairo can be used independently of gtk windows (for example, to prooduce a pdf), there should be a mechanism to obtain a pango context from a cairo context independent of any use of gtk. Or is there some deep secret about OCaml that I haven't divined yet (I am an OCaml beginner) that there's some way of using the fact that the two types are the same in C? Or is it a bug in Cairo or Pango that this conversion is absent? -- hendrik