Giter Site home page Giter Site logo

Comments (2)

corliss avatar corliss commented on July 17, 2024

This turned out to be easy - just declare both types as struct and change the marshaling code to:

		public GlyphInfo[] GlyphInfo()
		{
			int length;
			IntPtr glyphInfoPtr = HB.hb_buffer_get_glyph_infos(reference, out length);
			var glyphInfos = new GlyphInfo[length];
			for (int i = 0; i < length; ++i)
			{
				glyphInfos[i] = Marshal.PtrToStructure<GlyphInfo>(glyphInfoPtr + 20 * i);
			}

			return glyphInfos;
		}
		public GlyphPosition[] GlyphPositions()
		{
			int length;
			IntPtr glyphPositionPtr = HB.hb_buffer_get_glyph_positions(reference, out length);
			var glyphPositions = new GlyphPosition[length];
			for (int i = 0; i < length; ++i)
			{
				glyphPositions[i] = Marshal.PtrToStructure<GlyphPosition>(glyphPositionPtr + 20 * i);
			}

			return glyphPositions;
		}

Note: It would be even better to directly marshal the result of HB.hb_buffer_get_glyph_infos() and HB.hb_buffer_get_glyph_positions() into c# arrays, thereby avoiding the loop. Haven't figured out how to do that, but seems like a common enough situation so it should be possible. But at least this fixes the issue of allocating lots of tiny classes.

from sharpfont.harfbuzz.

Robmaister avatar Robmaister commented on July 17, 2024

Yes! Good catch! Arrays like this should be possible, my P/Invoke knowledge is a bit rusty but I'll see if I can make it work

from sharpfont.harfbuzz.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.