Open nghiaiosdev opened 8 years ago
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...
@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.
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.
Thank you so much. If I detect any bugs in lib, I will feedback for you. Thanks.
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
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();
}
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.