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 360B07EF37 for ; Mon, 3 Aug 2015 14:58:36 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ivg@ieee.org) identity=pra; client-ip=209.85.220.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ivg@ieee.org designates 209.85.220.175 as permitted sender) identity=mailfrom; client-ip=209.85.220.175; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qk0-f175.google.com) identity=helo; client-ip=209.85.220.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="postmaster@mail-qk0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DzAACyZL9Vm6/cVdFSCRkBAYNTaakpCwaTQoFhhXkCgShMAQEBAQEBEgEBAQEBBgsLCSEuhCQBAQEDEhVHCxALGAklDwEEIAEFASITIogMBQimPYEuPjGhIAEBAQEBBQIBGwQKhhWELoEChCQIXAeELAWUeYE/gzyHUYFHgTSCbIJjjzI1gRcXgh0cgW9TAYJLAQEB X-IPAS-Result: A0DzAACyZL9Vm6/cVdFSCRkBAYNTaakpCwaTQoFhhXkCgShMAQEBAQEBEgEBAQEBBgsLCSEuhCQBAQEDEhVHCxALGAklDwEEIAEFASITIogMBQimPYEuPjGhIAEBAQEBBQIBGwQKhhWELoEChCQIXAeELAWUeYE/gzyHUYFHgTSCbIJjjzI1gRcXgh0cgW9TAYJLAQEB X-IronPort-AV: E=Sophos;i="5.15,601,1432591200"; d="scan'208";a="141905563" Received: from mail-qk0-f175.google.com ([209.85.220.175]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Aug 2015 14:58:35 +0200 Received: by qkdv3 with SMTP id v3so50215731qkd.3 for ; Mon, 03 Aug 2015 05:58:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=FUlVRQyPGognG5cLKnkmoIOm7GQ0tsYO48I0yL/vcFE=; b=afLkLNf8lPu1F8ML9vopsJocfyyRe5Ynv+V4/FpP+ptY5qOs6x5FmWDLUkowC9GIaf 9a9JKIiYCoi3kbl4V75HprhrwE8ChGVZf0YiyFR80AjmPzw4ylCSm1G7VI+aZ8wOgPzp aQg0pBpnbRkG/0kpOh6P4DougaZlleEYC0ie3/+ZMmkCaz5fKLbUyc0IE1v17o0BybtM Kt55OpDmqF/Ra5NkDxRUDgJsda0b0KlkSuD5nzmqKwifW2snmef444/SWGFEX7N1218F rF4ytN6D7OntaOnY/RoZq1xUBq0juq1yoEUGYof+zyZHrQOrIt8weEqfJGWvINSTaXZJ Gl3Q== X-Gm-Message-State: ALoCoQlhwTPoUcMaSjlgbJfUYwarQH7gOfNDzm9YmtBLobR/P0U/HztQhXQB9h0gM/F/oj3e1BhK X-Received: by 10.55.24.199 with SMTP id 68mr8622787qky.50.1438606713624; Mon, 03 Aug 2015 05:58:33 -0700 (PDT) Received: from zulu.ivg@ieee.org (CWILL-CYLAB.WV.CC.CMU.EDU. [128.237.199.230]) by smtp.gmail.com with ESMTPSA id d30sm6815464qkh.45.2015.08.03.05.58.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Aug 2015 05:58:32 -0700 (PDT) From: Ivan To: Hendrik Boom Cc: "caml-list\@inria.fr" References: <20150803014654.GA30848@topoi.pooq.com> <5EF3DBC5-DA38-44C9-AFEC-F5E009D869E8@ieee.org> Date: Mon, 03 Aug 2015 09:00:11 -0400 In-Reply-To: <5EF3DBC5-DA38-44C9-AFEC-F5E009D869E8@ieee.org> (Ivan Gotovchits's message of "Mon, 3 Aug 2015 06:52:56 -0400") Message-ID: <87oaiottlw.fsf@ieee.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] Using Pango with Cairo in Ocaml Ivan Gotovchits writes: > > > > >> On Aug 2, 2015, at 9:46 PM, Hendrik Boom wrote: >> >> 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. > > There is an unsafe way to do this, that you should only do, if you > understand, what you're doing. It is a typecasting in fact: > > external pango_of_cairo : Cairo.context -> Pango.context = "%identity" > > This will define a function that will create (typecast) pango context from a cairo. > > If underneath they're different type, then at best you will get segfault. I checked the source code, and it looks to me, that the types are different, so it wouldn't be safe to use this conversion. Looks like, that currently cairo library doesn't support this functionality, i.e., there is no way to get pango context from cairo. You can fix this, by stubbing `pango_cairo_create_context` function directly or using OCaml cstubs library. Or you can create an issue on a cairo2 issue tracker.