[HarfBuzz] What is the correct usage of hb_feature_from_string()?

York Todd tjysunset at outlook.com
Sat Jul 21 14:49:52 UTC 2018


Nevermind, it was the managed side's fault after all. The call itself was successful. God knows why the exception was "thrown" in the unit test output. Sorry for the bother.

在 2018/7/21 2:04 上午, York Todd 写道:

Hello everyone,

I'm trying to make a(nother) C# binding for HarfBuzz, and having some troubles with hb_feature_from_string().

Here's how I called it in C#:

```

// platform invoke<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz/PlatformInvoke/Api.Shape.cs#L11>

[DllImport(HarfBuzzDll, CallingConvention = Cdecl)]
public static extern bool hb_feature_from_string(byte[] str, int length, out Feature feature);


// definition of "Feature"<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz/HarfBuzz/Feature.cs>

[StructLayout(LayoutKind.Sequential)]
public struct Feature
{
    private uint _tag;
    public uint Value;
    public uint Start;
    public uint End;
}


// calling hb_feature_to_string (unit test<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz.Test/ShapeTests/Tests.cs#L44> -> constructor<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz/HarfBuzz/Feature.cs#L23>)

var bytes = Encoding.ASCII.GetBytes("valt");
if (!Api.hb_feature_from_string(bytes, bytes.Length, out var feature)) throw new ArgumentException();

```

then the ArgumentException was thrown<https://ci.appveyor.com/project/TJYSunset/hardfuzz/build/0.1.3/tests>, meaning hb_feature_from_string returned false. Also, calling hb_feature_to_string() on the returned `Feature` will result in a random string varying each run, as if read from a wild pointer. However, somehow the `_tag` can be successfully DETAGed as "valt".

From my experience,

  *   platform invoke definition is unlikely to blame; the `out` keyword and the usage of `byte[]` for marshaling `char *` proved to work in other API calls.
  *   maybe the definition of `struct Feature` is incorrect; I had to define hb_glyph_info_t<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz/HarfBuzz/Buffer/GlyphInfo.cs#L10> and hb_glyph_position_t<https://github.com/TJYSunset/HardFuzz/blob/d3fb178d69e8a88e616c7f3a778978b062b99c6d/HardFuzz/HarfBuzz/Buffer/GlyphPosition.cs#L10> as 20-byte-long struct for them to work, even if they only have three or four uint32s. But tried Size=20 with no luck.
  *   the passed string is unlikely to be incorrect according to this third-party documentation<https://github.com/ufyTeX/luaharfbuzz/wiki/Feature-Strings> and my glance at hb-common.cc.

I'm wondering, what part of this process is wrong?

Again, thank you in advance!

Todd

--
Todd J. York (pseudonym)
zh-Hans-CN, en-US | UTC+08:00
Sent from Thunderbird



_______________________________________________
HarfBuzz mailing list
HarfBuzz at lists.freedesktop.org<mailto:HarfBuzz at lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/harfbuzz


--
Todd J. York (pseudonym)
zh-Hans-CN, en-US | UTC+08:00
Sent from Thunderbird
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20180721/d67b7c3a/attachment.html>


More information about the HarfBuzz mailing list