From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 952587EF38 for ; Mon, 3 Aug 2015 12:53:05 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of ivg@ieee.org) identity=pra; client-ip=209.85.213.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of ivg@ieee.org designates 209.85.213.182 as permitted sender) identity=mailfrom; client-ip=209.85.213.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ig0-f182.google.com) identity=helo; client-ip=209.85.213.182; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="postmaster@mail-ig0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DZAADtRr9Vm7bVVdFSCRkBAQGDUmmpNAaDH5AjgWGFeQKBJkwBAQEBAQESAQEBAQEGCwsJIS6EIwEBAQECARIVEzQLBQsLGA0hNAEFAQoSBhMSEId3AwoIBQilUoEuPjGbYgOFOwEBAQEBAQEBAQEBAQEBAQEBGwqGFYQugQKEJAgpMweDGIEUBYVmDI8HhHuHUYFHRoNagmMPjyM1gRcXgh0cgW9TAYJLAQEB X-IPAS-Result: A0DZAADtRr9Vm7bVVdFSCRkBAQGDUmmpNAaDH5AjgWGFeQKBJkwBAQEBAQESAQEBAQEGCwsJIS6EIwEBAQECARIVEzQLBQsLGA0hNAEFAQoSBhMSEId3AwoIBQilUoEuPjGbYgOFOwEBAQEBAQEBAQEBAQEBAQEBGwqGFYQugQKEJAgpMweDGIEUBYVmDI8HhHuHUYFHRoNagmMPjyM1gRcXgh0cgW9TAYJLAQEB X-IronPort-AV: E=Sophos;i="5.15,600,1432591200"; d="scan'208";a="172505077" Received: from mail-ig0-f182.google.com ([209.85.213.182]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Aug 2015 12:53:04 +0200 Received: by igbpg9 with SMTP id pg9so53078295igb.0 for ; Mon, 03 Aug 2015 03:53:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:references:in-reply-to:mime-version :content-transfer-encoding:content-type:message-id:cc:from:subject :date:to; bh=sMJ7/pCk4x9MxnJ6YkTZtQPlpVfJ8FfghBhlqO4ch8I=; b=jrMXuAonL+GKUt+jyEF8AQjXIH/d8tvVTer+X63+SUb00f92M1nvAcXySwAM34azep kY54YdNh9smgynIwAgEzUaLRQ6WLc0MCKdpxMj7Xu/66v6tepJNrt3Phew9bN9Tg/x4m XvBFTTFrPnlJSvD+/DUFvstCUz3XqTdvIO/u0lWQLLsy8gJSSc/lKry2qyGo6TMcNGrY IhG0givVKSYbevftJ168oxtKlYHCenJ0uI+PLH+mW3emuAlD99FrpKIH9wyg35tEGHxH dZPUa7RzQ7RgAQnWMb6XylG27N5wNAIjNkqBNvGA3oViVnJbARIpx69WC8GIfX6BtJUA kzLg== X-Gm-Message-State: ALoCoQk3jwHTIYRUX7IBJmss4+u3uV6pn6Pl8xnN3GpbrSP5Wa7i68LQWO2VYZAqGeYb9b2X5ocX X-Received: by 10.50.30.105 with SMTP id r9mr21446847igh.11.1438599183509; Mon, 03 Aug 2015 03:53:03 -0700 (PDT) Received: from [10.4.40.214] (host-69-95-110-205.cwon.choiceone.net. [69.95.110.205]) by smtp.gmail.com with ESMTPSA id ns7sm5377027igb.0.2015.08.03.03.53.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Aug 2015 03:53:02 -0700 (PDT) References: <20150803014654.GA30848@topoi.pooq.com> In-Reply-To: <20150803014654.GA30848@topoi.pooq.com> Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: <5EF3DBC5-DA38-44C9-AFEC-F5E009D869E8@ieee.org> Cc: "caml-list@inria.fr" X-Mailer: iPad Mail (12F69) From: Ivan Gotovchits Date: Mon, 3 Aug 2015 06:52:56 -0400 To: Hendrik Boom Subject: Re: [Caml-list] Using Pango with Cairo in Ocaml =20 > On Aug 2, 2015, at 9:46 PM, Hendrik Boom wrote: >=20 > I'm writing here because I seem to have exhausted the wisdom of the=20 > ocam-beginners mailing list. If there's a better place for me to have=20 > sent this, and there probably is, please let me know. >=20 >=20 > I'm trying to use Pango with Cairo, and to do it in OCaml. >=20 > I have an example written in C, that draws a multicoloured wheel of=20 > copies of the word "text". I got it from > https://developer.gnome.org/pango/stable/pango-Cairo-Rendering.html >=20 > It works fine in C. >=20 > But I'm running into a snag with the OCaml conversion. >=20 > To make a layout, Pango wants to use a value of type Pango.context, and=20 > all I have from Cairo is a value of type Cairo.context. >=20 > There seems to be no way to obtain a Pango context from a Cairo=20 > context. >=20 > The obvious thing would seem to be to look at the C code to see what it=20 > did, and look for the corresponding function in the OCaml library=20 > source. >=20 > But it turns out the C code just uses the Cairo context as a Pango=20 > context without any conversion at all. Pango, apparently, will just=20 > talk to a Cairo context as if it were a Pango context. Presumably=20 > that's the normal way to use Cairo in C. >=20 > Now I'm not just saying that in the working C code, the Pango context=20 > and the Cairo context are the same type; that would be meaningless=20 > because both aree of the general-purpose gobject type. I'm saying they=20 > are the same *value*, i.e., the same pointer, pointing to the same=20 > thing. >=20 > My immediate question is thus, how to I get Pango.context from a=20 > Cairo.context. I seem to want a type change in OCaml without a change=20 > in value. There is an unsafe way to do this, that you should only do, if you understa= nd, what you're doing. It is a typecasting in fact: external pango_of_cairo : Cairo.context -> Pango.context =3D "%identity" This will define a function that will create (typecast) pango context from = a cairo.=20 If underneath they're different type, then at best you will get segfault.=20 >=20 > Pango.context would appear to be defined in pango.ml:28 >=20 > type context =3D [`pangocontext] obj >=20 >=20 > and for cairo.context I can merely find the line >=20 > type context >=20 > in both cairo.ml1 and cairo.ml. >=20 > (I didn't think type definitions could be this abbreviated, but there=20 > it is. Is this some way of mentioning a type definition elsewhere tht=20 > I haven't found yet?) >=20 >=20 > In the earlier cairo, the one before cairo2, there was a function fo=20 > convert a Cairo context to a Pango context. It is not present in=20 > cairo2. Maybe it is for good reason, I don't know. I need to view the implementatio= n, that is not currently under hand. >=20 > Now it is possibile to obtain a Cairo context from a gtk window, and=20 > also a Pango context. But since cairo can be used independently of gtk=20 > windows (for example, to prooduce a pdf), there should be a mechanism=20 > to obtain a pango context from a cairo context independent of any use=20 > of gtk. >=20 > Or is there some deep secret about OCaml that I haven't divined yet (I=20 > am an OCaml beginner) that there's some way of using the fact that the=20 > two types are the same in C? >=20 > Or is it a bug in Cairo or Pango that this conversion is absent? >=20 > -- hendrik >=20 >=20 >=20 > --=20 > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs