<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>P.S. FWIW, jextract should generate an FT_CharMap layout in
      freetype_h as well that you could use instead of POINTER:<br>
      <br>
      <font face="monospace">        // Let's now iterate over the
        structs and print the encoding (which is problematic)<br>
                MemorySegment arrPointer =
        FT_FaceRec.charmaps$get(faceMemory);<br>
                arrPointer<br>
                    .reinterpret(FT_CharMap</font><font face="monospace">.byteSize()
        * num) // it's an array of FT_CharMap</font><br>
      <font face="monospace">             .elements(FT_CharMap</font><font face="monospace">) // the elements are FT_CharMaps</font><br>
      <font face="monospace">             .map(s -> s.get(FT_CharMap</font><font face="monospace">, 0)) // 's' is a slice of the array. Get an </font><font face="monospace">FT_CharMap</font><font face="monospace"> </font><font face="monospace">from the array<br>
                    .forEach(Test::printCharMap);</font></p>
    <p>Jorn<br>
    </p>
    <div class="moz-cite-prefix">On 13/11/2023 11:59, Jorn Vernee wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:e189a162-3de7-42bd-ae52-8670837e9261@oracle.com">
      
      <p>Hey Alessandro,<br>
        <br>
        I think there is a bug in this section of your code:<br>
        <br>
        <font face="monospace">        // Let's now iterate over the
          structs and print the encoding (which is problematic)<br>
                  MemorySegment arrPointer =
          FT_FaceRec.charmaps$get(faceMemory);<br>
                  arrPointer.get(POINTER, 0)<br>
                      .reinterpret(FT_CharMapRec_.$LAYOUT().byteSize() *
          num)<br>
                      .elements(FT_CharMapRec_.$LAYOUT())<br>
                      .forEach(Test::printCharMap);</font></p>
      <p>Looking at the documentation: [1], [2]. The 'charmaps' field of
        a face is an array of _pointers_ to FT_CharMapRec_ (note that
        FT_CharMap is a pointer to a FT_CharMapRec_), not an array of
        FT_CharMapRec_. Your code, however, is getting the pointer to
        the first struct from the array, and then reinterpreting that
        pointer as an array of structs, while it's actually just a
        pointer to a single FT_CharMapRec_ struct (not an array). That
        explains why the first element looks valid, but the second
        doesn't.<br>
        <br>
        Treating the array as an array of pointers instead, I think this
        should work:<br>
        <br>
        <font face="monospace">        // Let's now iterate over the
          structs and print the encoding (which is problematic)<br>
                  MemorySegment arrPointer =
          FT_FaceRec.charmaps$get(faceMemory);<br>
                  arrPointer<br>
                      .reinterpret(POINTER.byteSize() * num) // it's an
          array of pointers<br>
                      .elements(</font><font face="monospace">POINTER</font><font face="monospace">) // the elements are pointers<br>
                      .map(s -> s.get(POINTER, 0)) // 's' is a slice
          of the array. Get a pointer to a struct from the array<br>
                      .forEach(Test::printCharMap);</font><br>
      </p>
      <p>HTH,<br>
        Jorn</p>
      <p>[1]:
        <a class="moz-txt-link-freetext" href="https://freetype.org/freetype2/docs/reference/ft2-face_creation.html#ft_facerec" moz-do-not-send="true">https://freetype.org/freetype2/docs/reference/ft2-face_creation.html#ft_facerec</a><br>
        [2]:
        <a class="moz-txt-link-freetext" href="https://freetype.org/freetype2/docs/reference/ft2-character_mapping.html#ft_charmap" moz-do-not-send="true">https://freetype.org/freetype2/docs/reference/ft2-character_mapping.html#ft_charmap</a><br>
      </p>
      <div class="moz-cite-prefix">On 13/11/2023 11:11, Alessandro
        Parisi wrote:<br>
      </div>
      <blockquote type="cite" cite="mid:CAFpXZFzgZtZco-+k+5ORoohpm33wDnL=qGHY2E-bnT3M1KpcHQ@mail.gmail.com">
        <div dir="ltr">Hello everyone,<br>
          In the recent weeks, I've been experimenting with Project
          Panama on JDK 21. I'm trying to create a wrapper for the
          Freetype font library written in C, but I'm having some
          issues, probably because I still don't understand very well
          the FFM API.
          <div>While using the code generated by JExtract, I noticed
            that it fails to parse the <i>charmaps</i> array from the <a href="https://freetype.org/freetype2/docs/reference/ft2-face_creation.html#ft_facerec" moz-do-not-send="true">FT_FaceRec</a> struct. With the TTF
            font, I'm testing, there are two <i>charmaps</i>, the
            values of the first one are the same printed by the
            native code too, but for the second, the values are
            completely randomic</div>
          <div>Here is a little reproducer: <a href="https://www.dropbox.com/scl/fi/gitugnyxe3kyomm4m0pke/FreetypeMRE.zip?rlkey=tvnrsb5ernwasmxj6cgrjyqqq&dl=0" moz-do-not-send="true">FreetypeMRE</a></div>
          <div>Running the Test class will print the two <i>charmaps</i>.
            There is also a little .exe I built to check the output of
            native code, it's located in the src/native directory (there
            is also the C src code)<br>
            Am I doing something wrong, or is this a bug?</div>
        </div>
      </blockquote>
    </blockquote>
  </body>
</html>