Skip to content

Arithmetic operation resulted in an overflow #121

@ststeiger

Description

@ststeiger

On .NET-Core 2.0 x64, I get "Arithmetic operation resulted in an overflow." on reading the ascender...

/// <summary>
/// Gets the ascender in 26.6 fractional pixels.
/// </summary>
/// <see cref="Face"/>
public Fixed26Dot6 Ascender
{
    get
    {
        // Here => (int)
        return Fixed26Dot6.FromRawValue((int)rec.ascender);
    }
}

I don't get what you're doing there - casting an int64 to an int32 ?
This can't work...

SharpFont.Native.Init();

SharpFont.Library lib = new SharpFont.Library();
SharpFont.Face fontFace = new SharpFont.Face(lib, @"C:\Windows\Fonts\tahoma.ttf");
            
float size = 12;
if (fontFace!= null)
    // fontFace.SetCharSize(0, size, 0, 96);
    fontFace.SetCharSize(size, size, 96, 96);

System.Console.WriteLine(fontFace.Size.Metrics.Ascender.ToDouble()); // kaboom...
System.Console.WriteLine(fontFace.Size.Metrics.Descender.ToSingle());
System.Console.WriteLine(fontFace.Size.Metrics.Height.ToSingle());

Dll's from SharpFont\Dependencies\freetype2\2.6-alldeps\msvc12\x64


namespace SharpFont
{


    public class Native
    {

        public static void Init()
        {
            if (System.Environment.OSVersion.Platform == System.PlatformID.Unix)
                return;

            System.Reflection.Assembly ass = typeof(Native).Assembly;
            string dir = System.IO.Path.GetDirectoryName(ass.Location);
            int bitness = System.IntPtr.Size * 8;
            string[] embeddedResources = ass.GetManifestResourceNames();
            string freetypeLib = "freetype6.x86-" + bitness.ToString() + ".dll";
            string fileName = System.IO.Path.Combine(dir, "freetype6.dll");

            string found = null;
            for (int i = 0; i < embeddedResources.Length; ++i)
            {
                if (embeddedResources[i].EndsWith(freetypeLib, System.StringComparison.OrdinalIgnoreCase))
                {
                    found = embeddedResources[i];
                    break;
                }
            } // Next i 

            if (string.IsNullOrEmpty(found))
                throw new System.Exception("Resource \"" + freetypeLib + "\"not found");

            using (System.IO.Stream strm = ass.GetManifestResourceStream(found))
            {
                using (System.IO.Stream output = System.IO.File.Create(fileName))
                {
                    strm.CopyTo(output);
                } // End Using output 

            } // End Using strm 

        } // End Sub Init 


    } // End Class Native 


} // End Namespace SharpFont 

Note:
On Linux with the same code, this runs just fine (font file path changed of course).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions