Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when trying to read the horizontal header of a TrueType font #140

Closed
wldevries opened this issue Feb 14, 2023 · 2 comments
Closed

Comments

@wldevries
Copy link

wldevries commented Feb 14, 2023

Crash in Face when trying to read the horizontal header of a TrueType font.

var library = new Library();
Face face = new Face(library, "c:/windows/fonts/arial.ttf");
face.GetSfntTable(SfntTag.HorizontalHeader);

This results in the following error:

System.TypeLoadException: Cannot marshal field 'Reserved' of type 'SharpFont.TrueType.lnternal.HoriHeaderRec': This type can only be marshaled in restricted ways.
at System.Runtime.lnteropServices.Marshal.PtrToStructureHelper(lntPtr ptr, Object structure, Boolean allowValueClasses)
at System.Runtime.lnteropServices.Marshal.PtrToStructure(lntPtr ptr, Type structureType)
at SharpFont.PlnvokeHelper.PtrToStructure[T](lntPtr reference)
at SharpFont.TrueType.HoriHeader.set_Reference(lntPtr value)
at SharpFont.TrueType.HoriHeader..ctor(lntPtr reference)
at SharpFont.Face.GetSfntTable(SfntTag tag)

I'm trying to get to get access to the LineGap of a font which seems to be present only in the vertical and horizontal headers. The vertical header loads fine.

@HinTak
Copy link
Contributor

HinTak commented Feb 14, 2023

loadfont() does not appear to be a known routine?

@wldevries
Copy link
Author

wldevries commented Feb 15, 2023

I updated the repro code to include how the font is loaded.

After fiddling around with it today I found that this is only a problem in the SharpFont build included in the MonoGame pipeline. It works fine when I use the nuget package SpaceWizards.SharpFont. (the more official SharpFont package does not work on modern .NET versions: #126)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants