What I want to do

I need to access the consola.ttf file which I have included in my Assets folder as a file.

What I have done

Method 1:

Trying to access the file as a Stream using this code:

AssetManager assets = MainActivity.Context.Assets; using (var stream = assets.Open("Fonts/consola.ttf")) { font = new SdlFont(ToBytes(stream), 15); }

ToBytes method used above

static byte[] ToBytes(Stream stream) { byte[] b; using (var ms = new MemoryStream()) { stream.CopyTo(ms); ms.Flush(); ms.Position=0; b = ms.ToArray(); } return b; }

which I had found here, is not possible as I am using the "SDL_ttf" library which apparently does not like byte streams directly.

My SDLFont Wrapper method

public SdlFont(byte[] data, int fontSize) { Handle = OpenFontRW(OS.RWFromMemory(data, data.Length), 1, fontSize); }

Using the SDLfont method calls this function of TTF through my wrapper:

[DllImport(libTTF, EntryPoint = "TTF_OpenFontRW", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr OpenFontRW(IntPtr src, int freesrc, int ptsize);

This TTF method is documented here. Using this will simply throw and unhandled exception and crash the application.

Method 2:

Trying to get the path in Runtime:

var fontname = "consola.ttf"; var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts); var fontpath = System.IO.Path.Combine(path,fontname); font = new SdlFont( fontpath , 15);

Here are their values in runtime:

This too does not work.

An Alternate solution would be accessing any font file (.ttf) from the system itself that it not included by me. However being able to use my own font would be preferable.

If anyone knows how I can access the path to a System font in Android, that too would be useful to me.

Thank you.