Skip to content

Commit

Permalink
Use CLong and CUlong, thanks Dean
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-cpp committed Nov 22, 2024
1 parent 4c38235 commit 7fce557
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Import(FontDescription options, string fontName)
// Rasterize each character in turn.
foreach (char character in characters)
{
uint glyphIndex = FreeType.FT_Get_Char_Index(face, character);
uint glyphIndex = FreeType.FT_Get_Char_Index(face, new CULong(character));
if (!glyphMaps.TryGetValue(glyphIndex, out GlyphData glyphData))
{
glyphData = ImportGlyph(glyphIndex, face);
Expand All @@ -51,10 +51,10 @@ public void Import(FontDescription options, string fontName)
Glyphs = glyphList;

// Store the font height.
LineSpacing = face->size->metrics.height >> 6;
LineSpacing = face->size->metrics.height.Value >> 6;

// The height used to calculate the Y offset for each character.
YOffsetMin = -face->size->metrics.ascender >> 6;
YOffsetMin = -face->size->metrics.ascender.Value >> 6;

CheckError(FreeType.FT_Done_Face(face));
CheckError(FreeType.FT_Done_FreeType(library));
Expand All @@ -73,10 +73,10 @@ private void CheckError(int error)
{
const uint dpi = 96;

CheckError(FreeType.FT_New_Face(library, fontName, 0, out FT_Face* face));
CheckError(FreeType.FT_New_Face(library, fontName, new CLong(0), out FT_Face* face));

var fixedSize = ((int)options.Size) << 6;
CheckError(FreeType.FT_Set_Char_Size(face, 0, fixedSize, dpi, dpi));
CheckError(FreeType.FT_Set_Char_Size(face, new CLong(0), new CLong(fixedSize), dpi, dpi));

return face;
}
Expand Down Expand Up @@ -127,8 +127,8 @@ private GlyphData ImportGlyph(uint glyphIndex, FT_Face* face)

if (glyphBitmap == null)
{
var gHA = face->glyph->metrics.horiAdvance >> 6;
var gVA = face->size->metrics.height >> 6;
var gHA = face->glyph->metrics.horiAdvance.Value >> 6;
var gVA = face->size->metrics.height.Value >> 6;

gHA = gHA > 0 ? gHA : gVA;
gVA = gVA > 0 ? gVA : gHA;
Expand All @@ -138,18 +138,18 @@ private GlyphData ImportGlyph(uint glyphIndex, FT_Face* face)

// not sure about this at all
var abc = new ABCFloat();
abc.A = face->glyph->metrics.horiBearingX >> 6;
abc.B = face->glyph->metrics.width >> 6;
abc.C = (face->glyph->metrics.horiAdvance >> 6) - (abc.A + abc.B);
abc.A = face->glyph->metrics.horiBearingX.Value >> 6;
abc.B = face->glyph->metrics.width.Value >> 6;
abc.C = (face->glyph->metrics.horiAdvance.Value >> 6) - (abc.A + abc.B);
abc.A -= face->glyph->bitmap_left;
abc.B += face->glyph->bitmap_left;

// Construct the output Glyph object.
return new GlyphData(glyphIndex, glyphBitmap)
{
XOffset = -(face->glyph->advance.x >> 6),
XAdvance = face->glyph->metrics.horiAdvance >> 6,
YOffset = -(face->glyph->metrics.horiBearingY >> 6),
XOffset = -(face->glyph->advance.x.Value >> 6),
XAdvance = face->glyph->metrics.horiAdvance.Value >> 6,
YOffset = -(face->glyph->metrics.horiBearingY.Value >> 6),
CharacterWidths = abc
};
}
Expand Down
59 changes: 23 additions & 36 deletions MonoGame.Framework.Content.Pipeline/Utilities/FreeTypeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ unsafe struct FT_Library
public int version_patch;

public uint num_modules;

public fixed long modules[128];

public FT_ListRec renderers;
public nint cur_renderer;
public nint auto_hinter;

public fixed long debug_hooks[4];

public fixed long lcd_geometry[6];

public int refcount;

};

struct FT_Generic
Expand All @@ -75,7 +62,7 @@ struct FT_Generic

struct FT_BBox
{
public long xMin, yMin, xMax, yMax;
public CLong xMin, yMin, xMax, yMax;
}

struct FT_ListRec
Expand All @@ -85,31 +72,31 @@ struct FT_ListRec

struct FT_Vector
{
public long x, y;
public CLong x, y;
}

struct FT_Matrix
{
public long xx, xy, yx, yy;
public CLong xx, xy, yx, yy;
}

struct FT_Glyph_Metrics
{
public long width, height, horiBearingX, horiBearingY, horiAdvance, vertBearingX, vertBearingY, vertAdvance;
public CLong width, height, horiBearingX, horiBearingY, horiAdvance, vertBearingX, vertBearingY, vertAdvance;
}

struct FT_Size_Metrics
{
public ushort x_ppem;
public ushort y_ppem;

public long x_scale;
public long y_scale;
public CLong x_scale;
public CLong y_scale;

public long ascender;
public long descender;
public long height;
public long max_advance;
public CLong ascender;
public CLong descender;
public CLong height;
public CLong max_advance;
}

unsafe struct FT_Size
Expand Down Expand Up @@ -155,13 +142,13 @@ struct FT_SubGlyph

unsafe struct FT_Face
{
public long num_faces;
public long face_index;
public CLong num_faces;
public CLong face_index;

public long face_flags;
public long style_flags;
public CLong face_flags;
public CLong style_flags;

public long num_glyphs;
public CLong num_glyphs;

public nint family_name;
public nint style_name;
Expand Down Expand Up @@ -212,8 +199,8 @@ unsafe struct FT_GlyphSlot
public FT_Generic generic;

public FT_Glyph_Metrics metrics;
public long linearHoriAdvance;
public long linearVertAdvance;
public CLong linearHoriAdvance;
public CLong linearVertAdvance;
public FT_Vector advance;

public FT_Glyph_Format format;
Expand All @@ -228,10 +215,10 @@ unsafe struct FT_GlyphSlot
public FT_SubGlyph* subglyphs;

public nint control_data;
public long control_len;
public CLong control_len;

public long lsb_delta;
public long rsb_delta;
public CLong lsb_delta;
public CLong rsb_delta;

public nint other;

Expand All @@ -252,15 +239,15 @@ unsafe partial class FreeType

[LibraryImport(Library, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int FT_New_Face(FT_Library* library, string filepathname, long face_index, out FT_Face* aface);
public static partial int FT_New_Face(FT_Library* library, string filepathname, CLong face_index, out FT_Face* aface);

[LibraryImport(Library, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int FT_Done_Face(FT_Face* aface);

[LibraryImport(Library, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial uint FT_Get_Char_Index(FT_Face* face, ulong charcode);
public static partial uint FT_Get_Char_Index(FT_Face* face, CULong charcode);

[LibraryImport(Library, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
Expand All @@ -272,6 +259,6 @@ unsafe partial class FreeType

[LibraryImport(Library, StringMarshalling = StringMarshalling.Utf8)]
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
public static partial int FT_Set_Char_Size(FT_Face* face, long char_width, long char_height, uint horz_resolution, uint vert_resolution);
public static partial int FT_Set_Char_Size(FT_Face* face, CLong char_width, CLong char_height, uint horz_resolution, uint vert_resolution);
}
}

0 comments on commit 7fce557

Please sign in to comment.