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

Replace SharpFont with minimal direct FreeType bindings #16279

Merged
merged 3 commits into from Mar 14, 2019

Conversation

@pchote
Copy link
Member

commented Mar 7, 2019

SharpFont presents us with two problems in the short term:

  • It depends on System.Drawing, blocking #15955
  • It doesn't target .net Standard, blocking #15954

Closes #15955.

The maintenance status of SharpFont isn't clear - a couple of patches were merged during 2018, but Robmaister/SharpFont#126 has not received any response. The project doesn't build under mono, which is a significant barrier to developing our own forked version and trying to contribute patches back upstream.

We only use a tiny part of the FreeType API, so IMO the simplest path forward is to ship our own minimal native binding, like we did for OpenGL (#10288). The FreeType interactions are based in part on SceneFlipEngine/font.c and in part by inspecting the SharpFont source.

Test builds are available from https://github.com/pchote/OpenRA/releases/tag/pkgtest-20190307, which i've already verified work under macOS/Linux/Windows.

@pchote pchote added this to the Next + 1 milestone Mar 7, 2019

internal const uint OK = 0x00;
internal const int FT_LOAD_RENDER = 0x04;

internal static readonly int FaceRecGlyphOffset = IntPtr.Size == 8 ? 152 : 84; // offsetof(FT_FaceRec, glyph)

This comment has been minimized.

Copy link
@pchote

pchote Mar 7, 2019

Author Member

These offsets were generated using a simple C program:

#include <ft2build.h>
#include FT_FREETYPE_H

int main(int argc, char** argv)
{
    printf("FaceRecGlyphOffset %lu\n", offsetof(FT_FaceRec, glyph));
    printf("GlyphSlotMetricsOffset %lu\n", offsetof(FT_GlyphSlotRec, metrics));
    printf("GlyphSlotBitmapOffset %lu\n", offsetof(FT_GlyphSlotRec, bitmap));
    printf("GlyphSlotBitmapLeftOffset %lu\n", offsetof(FT_GlyphSlotRec, bitmap_left));
    printf("GlyphSlotBitmapTopOffset %lu\n", offsetof(FT_GlyphSlotRec, bitmap_top));
    printf("MetricsWidthOffset %lu\n", offsetof(FT_Glyph_Metrics, width));
    printf("MetricsHeightOffset %lu\n", offsetof(FT_Glyph_Metrics, height));
    printf("MetricsAdvanceOffset %lu\n", offsetof(FT_Glyph_Metrics, horiAdvance));
    printf("BitmapPitchOffset %lu\n", offsetof(FT_Bitmap, pitch));
    printf("BitmapBufferOffset %lu\n", offsetof(FT_Bitmap, buffer));
    
    return 0;
}

compiled and run as both 32 and 64 bit.

@pchote pchote force-pushed the pchote:freetype branch from ac693cc to 945068e Mar 7, 2019

@pchote pchote force-pushed the pchote:freetype branch from 945068e to 5d5e50c Mar 12, 2019

@pchote pchote removed the PR: Rebase me! label Mar 12, 2019

@pchote

This comment has been minimized.

Copy link
Member Author

commented Mar 12, 2019

Rebased.

@reaperrr

This comment has been minimized.

Copy link
Contributor

commented Mar 14, 2019

Needs another rebase, unfortunately. Probably the last one, though.

@pchote pchote force-pushed the pchote:freetype branch from 5d5e50c to ff7b78a Mar 14, 2019

@pchote pchote removed the PR: Rebase me! label Mar 14, 2019

@pchote

This comment has been minimized.

Copy link
Member Author

commented Mar 14, 2019

Rebased.

@@ -81,6 +81,7 @@
<HintPath>..\thirdparty\download\SharpFont.dll</HintPath>

This comment has been minimized.

Copy link
@reaperrr

reaperrr Mar 14, 2019

Contributor

This and line 79 above still reference SharpFont.dll...?

@pchote pchote force-pushed the pchote:freetype branch from ff7b78a to 16ad996 Mar 14, 2019

@pchote

This comment has been minimized.

Copy link
Member Author

commented Mar 14, 2019

Rebase fail. Fixed.

@reaperrr
Copy link
Contributor

left a comment

Can't say much about the code, but everything seems to work fine, so LGTM

@reaperrr reaperrr merged commit aa9724c into OpenRA:bleed Mar 14, 2019

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@pchote pchote deleted the pchote:freetype branch Aug 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.