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

throw exception using Face#GetSfntName(uint idx) and some method such as Face#GetPSFontInfo(), Face#GetPostscriptName() #96

Open
nghiaiosdev opened this issue Dec 6, 2016 · 6 comments

Comments

@nghiaiosdev
Copy link

when i using following codes, Visual Studio throw exceptio with messege: "An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Library lib = new Library();
Face face = new Face(lib, "Slabo27px-Regular.ttf");
int sfntCount = (int)face.GetSfntNameCount();
for (int i = 0; i < sfntCount; i++)
{
SfntName sfnt = face.GetSfntName(0);
}

And anyone can fix it? Thanks you so much.

@HinTak
Copy link
Contributor

HinTak commented Dec 6, 2016

Your usage. Try this instead:

Face face = lib.NewFace("Slabo27px-Regular.ttf",0);

That said, maybe new Face(lib,...) should be made to work too...

@Robmaister
Copy link
Owner

@HinTak The constructors are indeed overloaded. It's the primary method of creating new objects. lib.NewFace just calls the constructor.

@eitguide emailed me earlier with this and one other exception, the second one being a bug in Face.GetPSFontInfo where there is one extra level of indirection in the out parameter. This would lead me to believe I've made a similar mistake with the SFNT API. Both should be relatively simple fixes, and I have a few minutes of spare time right now, so expect a fix in a few minutes.

Robmaister added a commit that referenced this issue Dec 6, 2016
APIs fixed: Face.GetSfntName, Face.GetPSFontInfo, and Face.GetPSFontPrivate
@Robmaister
Copy link
Owner

Also found that Face.GetPSFontPrivate had an error. I'll do a pass through the API later to see if there are any other areas where this bug exists.

@nghianguyeniosdev
Copy link

Thank you so much. If I detect any bugs in lib, I will feedback for you. Thanks.

@Robmaister
Copy link
Owner

Digging deeper, I found that the SfntName.String property can be a string of any format, so I added some overloads.

To maintain backwards compatibility, String returns a UTF-16 encoded string, StringAnsi returns an ANSI encoded string, and StringPtr returns the IntPtr to allow for any other encoding format. This commit should be pushed up in a minute

@Robmaister
Copy link
Owner

As for the exception in GetPSFontInto and GetPSPrivate, these are not problems in SharpFont. You are trying to access PostScript data for a TrueType font.

The exception I got from a sample program was a FreeTypeException for "Invalid argument", which in this case means the font does not support the function you tried to call on it. I downloaded a separate, free PS Type1 font to test this on, and the values now appear to be reasonable. Here is the test case I'm using:

static void Main(string[] args)
{
	Library lib = new Library();
	Face face = new Face(lib, "Slabo27px-Regular.ttf");
	uint sfntCount = face.GetSfntNameCount();
	for (uint i = 0; i < sfntCount; i++)
	{
		SfntName sfnt = face.GetSfntName(i);
	}

	face = new Face(lib, "ugqb.pfa");
	FontInfo info = face.GetPSFontInfo();
	string name = face.GetPostscriptName();
}

Robmaister added a commit that referenced this issue Dec 7, 2016
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

4 participants