Unable to measure text in pixel and render bitmap using PangoSharp, GTK Sharp

56 Views Asked by At

I am trying to measure text and render text to bitmap using PangoSharp, GTKSharp and CairoSharp in ASP.NET Core (.Net 6). I searched for the sample code and try to modify as per functionalities I am trying to implement. I am not sure how to assign FontMap using type and also use and load font files uploaded by the user.

When I am running code, I am getting following error while executing "layout.GetPixelSize(out width, out height);": **Pango-CRITICAL : 23:02:48.618: pango_font_map_load_fontset: assertion 'fontmap != NULL' failed

In legacy code FontMap set as follows:

PangoFontMap *fontmap = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);

pango_context_set_font_map(context, fontmap);

Search suggested to initialize FontMap like:

var fontMap = new PangoCairo.FontMap();

fontMap = PangoCairo.FontMap.NewForFontType(Cairo.FontType.Toy);

But in my Visual Studio 2022, getting an error that PangoCairo can't resolve.

Could anyone of you help me with code examples of PangoSharp, GTKSharp and CairoSharp to measure text in pixels while setting font files and descriptions provided by users?

Nuget packages I used:

  1. PangoSharp 3.24.24.95
  2. CairoSharp 3.24.24.95
  3. GTKSharp 3.24.24.95
  4. GLibSharp 3.24.24.95

Please let me know if you need more details.

0

There are 0 best solutions below