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 in SharpFont when trying to read the horizontal header of a TrueType font #161

Open
wldevries opened this issue Feb 15, 2023 · 2 comments

Comments

@wldevries
Copy link

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.

The SpaceWizards.SharpFont package combined with SharpFont.Dependencies loads the horizontal header just fine. Robmaister/SharpFont#140

@wldevries
Copy link
Author

The reason might be that the version in this repository might be 2.5.3 (?) and the official SharpFont lib is at 4.0.1 now.

@wldevries
Copy link
Author

The OS/2 table has the same problem:

face.GetSfntTable(SfntTag.HorizontalHeader);

results in

System.TypeLoadException: Cannot marshal field 'panose' of type 'SharpFont.TrueType.lnternal.CS2Rec': This type can only be marshaled in restricted ways.
at System.Runtime.lnteropServices.MarshaI.PtrToStructureHelper(lntPtr ptr, Object structure, Boolean allowValueCIasses)
at System.Runtime.lnteropServices.MarshaI.PtrToStructure(lntPtr ptr, Type structureType)
at SharpFont. reference)
at value)
at SharpFont.TrueType.OS2..ctor(lntPtr reference)
at SharpFont. Face.GetSfntTäble(SfntTag tag)

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

1 participant