Skip to content

Problem moving to version v3.0.0 #26

@CalvinWilkinson

Description

@CalvinWilkinson

Hello!

First off, thanks for the library! I have been using this ever since I introduced text rendering into my game framework.
I greatly appreciate the work you have done with this!

I have run into an issue while moving to v3.0.0 of your library from version v2.2.0.

Here is what I have going on here. I have a class that acts as a thin wrapper for the most part around
your library. The reason that I do this is to act as a thin wrapper for testing and usage purposes.

With this "wrapper", I am calling the FT.FT_Set_Char_Size() method. When calling this method,
I am getting the FT_Err_Invalid_Size_Handle error.

Everything of course was working fine with version v2.2.0. Currently, I am making changes to accommodate
all of the API/breaking changes that are in v3.0.0. I have figured out most of these are
structs instead of pointers.

Due to this, I am thinking that I am doing something wrong. I will show you the before and after so you can see what
it was with version v2.2.0 compared to what I am trying to do now for version v3.0.0.

Below, this is the wrapper method that I have to wrap the FT.FT_Set_Char_Size() method. This is being invoked by another
class.

Method with version v2.2.0:

public void FT_Set_Char_Size(nint face, nint char_width, nint char_height, uint horz_resolution, uint vert_resolution)
{
    EnsureThat.PointerIsNotNull(face);
    EnsureThat.PointerIsNotNull(char_width);
    EnsureThat.PointerIsNotNull(char_height);

    var error = FT.FT_Set_Char_Size(face, char_width, char_height, horz_resolution, vert_resolution);

    if (error != FT_Error.FT_Err_Ok)
    {
        this.OnError?.Invoke(this, new FreeTypeErrorEventArgs(CreateErrorMessage(error.ToString())));
    }
}

Method with version v3.0.0:

public void FT_Set_Char_Size(ref FT_FaceRec_ face, nint char_width, nint char_height, uint horz_resolution, uint vert_resolution)
{
    EnsureThat.PointerIsNotNull(char_width);
    EnsureThat.PointerIsNotNull(char_height);

    unsafe
    {
        fixed (FT_FaceRec_* facePtr = &face)
        {
            EnsureThat.PointerIsNotNull((nint)facePtr);

            var error = FT.FT_Set_Char_Size(facePtr, char_width, char_height, horz_resolution, vert_resolution);

            if (error != FT_Error.FT_Err_Ok)
            {
                this.OnError?.Invoke(this, new FreeTypeErrorEventArgs(CreateErrorMessage(error.ToString())));
            }
        }
    }
}

The code that is calling my FT_Set_Char_Size() method are shown below:

Caller method with version v2.2.0:

public void SetFontSize(nint facePtr, uint sizeInPoints)
{
    if (sizeInPoints <= 0)
    {
        throw new ArgumentException("The font size must be larger than 0.", nameof(sizeInPoints));
    }

    var sizeInPointsPtr = (nint)(sizeInPoints << 6);

    this.freeTypeInvoker.FT_Set_Char_Size(
        facePtr,
        sizeInPointsPtr,
        sizeInPointsPtr,
        (uint)this.sysDisplayService.MainDisplay.HorizontalDPI,
        (uint)this.sysDisplayService.MainDisplay.VerticalDPI);
}

Caller method with version v3.0.0:

public void SetFontSize(FT_FaceRec_ face, uint sizeInPoints)
{
    if (sizeInPoints <= 0)
    {
        throw new ArgumentException("The font size must be larger than 0.", nameof(sizeInPoints));
    }

    var sizeInPointsPtr = (nint)(sizeInPoints << 6);

    this.freeTypeInvoker.FT_Set_Char_Size(
        ref face,
        sizeInPointsPtr,
        sizeInPointsPtr,
        (uint)this.sysDisplayService.MainDisplay.HorizontalDPI,
        (uint)this.sysDisplayService.MainDisplay.VerticalDPI);
}

I have been looking to see if there was a change to the original FreeType library to see if maybe
you upgraded to a later version of FreeType with your v3.0.0 release, but I had no luck. Maybe something was changing with the original C library that was causing issues.

Your release notes don't have any information about breaking changes, or versions that you might have moved to
so I could not get any information there either.

I tried to figure out what version of the original FreeType C lib you were pointing to, but it was quite
the trail due to you having a reference to the Fork of the GitHub mirror of the original lib from GitLab.

I also ran out of time trying to figure this out. 😀

My gut feeling here is that I am simply doing something wrong here in regards to the changes with version v3.0.0.

Also, if you are interested, my project Velaptor is open source so you can
take a look if you want to.

If you need more questions from me, please don't hesitate to ask!!

Thanks!!

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