Giter Club home page Giter Club logo

sharpfont's People

Contributors

brisingraerowing avatar corliss avatar dkeetonx avatar drewkeller avatar hintak avatar kakcat avatar kyann avatar mailaender avatar neilt6 avatar petrmahdalicek avatar remo avatar rlokc avatar robmaister avatar stephenmcconnel avatar tamschi avatar thefiddler avatar tzachshabtay avatar varon avatar xdinos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharpfont's Issues

About Windows x64 - Just some notes.

Freetype 2.5.3+ (and possibly a few versions before) work on Win64 as they use the MSVC compiler's native __int64 type. You can see that in ftconfig.h at line 282. I have done a number of tests with SharpFont on Win64, and confirmed that it works.

I am using custom MSVC12 builds of Freetype, with dependencies on Zlib, BZip2, LibPNG, and Harfbuzz. I will share them if you want. I also can build MSVC10/11 versions as well, if you want me to.

Kerning Issue in Example Code

I am having this issue with the example code. The kerning on the A is messed up.

Image1 (using DIN font)
Image2
(using included font)

This is using my own font and the included font in the example code provided in the repo. I have tried one of the release versions and many versions of the freetype dll, but this issue persists. Again, this is using the example code provided by the repo.

SizeRequest.RequestType property is read-only

I need to call RequestSize as follows (F#):
face.RequestSize(SizeRequest(RequestType = SizeRequestType.RealDimensions, Height = (size <<< 6)))

But there is no way to set RequestType - the value is always SizeRequestType.Normal (0).

The patch is trivial:

--- a/SharpFont/SizeRequest.cs
+++ b/SharpFont/SizeRequest.cs
@@ -74,6 +74,11 @@ namespace SharpFont
                        {
                                return requestType;
                        }
+
+                       set
+                       {
+                               requestType = value;
+                       }
                }

                /// <summary>

freetype dependency

Not an error, but probably worth mentioning in the readme:

the freetype6.dll from the Example directory depends on msvcr110.dll, which may be a bit of a problem for those working with older versions of visual studio ...

Documentation

is there any online docs for this project or is it based on freetype?

Include documentation in Nuget Package

At the moment, the NuGet package for SharpFont doesn't include the documentation XML File. This makes discovering the API very challenging.

It shouldn't be complicated to fix, and would greatly enhance the library.

Use struct pointers instead of marshaling IntPtrs

There's a bug in Mono 2.10 that causes crashes with this, but most of the world should have moved off it by now.

The benefit of implementing this is that memory usage for SharpFont drops to 1/2 of what it is now and a lot of complexities with marshaling data disappears.

Before I implement this I need to survey versions of Mono that are being distributed/supported with other software/operating systems.

  • Ubuntu 12.04 LTS (supported until April 2017)
  • Unity3D (5.5.0 started updating Mono backend)
  • Fedora <= 22 (supported until July 19, 2016)
  • Debian Wheezy (supported until May 31, 2018)

I'll keep looking and seeing if there's anything major.

color alpha channel

FTBitmap:ToGdipBitmap(Color color) currently doesn't respect the alpha-cannel of the given color (at least not when target is PixelMode.Gray).

Setting the palette entries with
palette.Entries[i] = Color.FromArgb((int)(color.A * a), (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
fixes the problem.

I'd not be surprised if target PixelMode.Gray4 needs a similar fix, but I got not Idea what's up with the 17s there ...
Not that I understand why the color components are reduced like the alpha channel in the former case.

FTSize is not disposing

I kind of just guessed my way through rendering a spritefont and then rendering text to the screen.

using (FTSize ftSize = face.Size)
{

int height = ftSize.Metrics.NominalHeight;
height -= glyph.freeTypeGlyph.Metrics.HorizontalBearingY / 64;
// freeTypeGlyph is GlyphSlot
// glyph is a class that holds the spriteFont character locations

var position = new XnaFramework.Vector2 (dx, dy + height);
// spriteBatch drawing here

}

I've also tried calling ftSize.Dispose(), and testing the IsDisposed() flag (it tests true).
I'm not sure if I'm abusing FTSize in anyway. Is there another way to get the Nominal Height that I need?

I have a current version of the library off GitHub. I compiled it with Xamarin studio, targeting .Net 2.0 \ x86. I am using the freetype6.dll from the GitHub.

FTBitmap to Bitmap 8bppindexed palette issue

I have downloaded Sharpfont sources and run simple code example on my x86 windows machine and on my ubuntu machine using mono. There's a problem in the function ToGdipBitmap with a bitmap 8bpp and gray pixelmode. After Bitmap palette manipulation the background of the glyph is rendered as a black box instead of transparent after the assignment bmp.Palette = palette

    ColorPalette palette = bmp.Palette;
    for (int i = 0; i < palette.Entries.Length; i++)
        {
            float a = i / 255f;
            palette.Entries[i] = Color.FromArgb(i, (int)(color.R * a), (int)(color.G * a), (int)(color.B * a));
        }                 

        bmp.Palette = palette;

Windows Output
sharpfontwin
Linux Mono Output

sharpfontlin

I was able to workaround the issue with a negative ColorMatrix, but it's really a hack. Does this behaviour depends on Mono or a wrong palette code manipulation?
Thanks a lot in advance

Write a proper NuGet uninstall script

I had a hard enough time getting a newly-added uninstall script to actually show up when I rebuilt the package and an even harder time getting the packaged script to update when I modified the original.

I gave up when I realized my uninstall.ps1 was never being run.

If anyone with more NuGet experience than I would like to tackle this, be my guest. All it requires is removing freetype6.dll and SharpFont.dll.config from the main project folder along with their project references.

Changing the way NuGet builds the package and moving NuGet-related files around is fine.

NewMemoryFace

Hello, I think that the NewMemoryFace method has a potential issue with the byte[] buffer.It is not pinned globally but only shortly with the fixed keyword inside the FontFace constructor body, so potentially the GC can move the memory around.

Mac OSX 10.10

Having an issue with 3.0.1 on Mac OSX 10.10. When instantiating the library it crashes out saying there's a bad parameter in the constructor for FFT_Init_FreeType in libfreetype.6.dylib

This is the library reference if I'm not mistaken so I think the issue is the wrapper trying to load libfreetype.6.dylib and call into it. I tried on both x64 and x86 using Xamarin Studio. My game engine kinda relies on this library right now for font rendering in opengl and would like to see this fixed however, realistically I need to make this a dependency on a tool to build texture fonts and not the engine itself.

FaceRec marshaling crash on Linux x64

The issue was first reported here: MonoGame/MonoGame#2435

This line crashes when executed on Linux, with:

Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) object.__icall_wrapper_mono_string_new_wrapper (intptr) <IL 0x0000d, 0xffffffff>
  at (wrapper unknown) SharpFont.Internal.FaceRec.PtrToStructure (intptr,object) <IL 0x00254, 0xffffffff>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_intptr_object (object,intptr,intptr,intptr) <IL 0x0005c, 0xffffffff>
  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStructure (intptr,System.Type) <IL 0x0000e, 0xffffffff>
  at SharpFont.PInvokeHelper.PtrToStructure<T> (intptr) <IL 0x0000b, 0x0002c>
  at SharpFont.Face.set_Reference (intptr) <IL 0x00026, 0x00033>
  at SharpFont.Face..ctor (SharpFont.Library,string,int) <IL 0x00022, 0x00113>
  at SharpFont.Library.NewFace (string,int) <IL 0x0001b, 0x00047>
...

It could be that the FaceRec struct definition is wrong, possibly caused by LLP64 vs LP64 differences (especially since the same code is working on windows) or by some problem inside PInvokeHelper.PtrToStructure() or in Mono itself.

FTBitmap.ToGdipBitmap does not work for odd-sized images

When trying to generate a glyph atlas, my first attempt was to use ToGdipBitmap to get a few Bitmaps, and then draw them to a larger Bitmap using Graphics.DrawImage.

There seem to be two problems with that:

  1. ToGdipBitmap does not work for some glyphs; I think the reason is that GDI adds padding for certain widths of bitmaps, thus the math in ToGdipBitmap is wrong. Screenshot: https://dl.dropboxusercontent.com/u/11731051/freetype.png
  2. Note the color fringing on glyph edges. PixelMode is Gray; I think using an indexed bitmap is not a very good idea - maybe DrawImage can't handle it properly when blitting to ARGB bitmap.

A naive reimplementation for generating an ARGB bitmap works without issues:

let copyToBitmap (image: FTBitmap) =
    let result = new Bitmap(image.Width, image.Rows, PixelFormat.Format32bppArgb)

    let values: byte[] = Array.zeroCreate (image.Width * image.Rows)

    Marshal.Copy(image.Buffer, values, 0, values.Length)

    for y in 0..image.Rows-1 do
        for x in 0..image.Width-1 do
            result.SetPixel(x, y, Color.FromArgb(int values.[y*image.Width+x], 255, 255, 255))

    result

Nuget package installation fail after Visual Studio Community 2015 Update 1

Just tried to install current package into a new universal windows project to get a monogame pipline to work but installation got rejected.

Microsoft Visual Studio Community 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Community
Visual C# 2015 00322-20000-00000-AA031
Microsoft Visual C# 2015
NuGet Package Manager 3.3.0
Visual Studio Tools for Universal Windows Apps 14.0.24720.00

Antialiasing color problem

As can be seen in the image, but orange temperature values seem to have some green at the outline of the characters, while the character rendered in white, red or green seem to be ok.
The smaller text in orange uses a pixel font which also doesn't exhibit this problem.

freetype-orange-green

Unable to build on Linux x86_64

When I am trying to build this on my 64bit linux, it won't build and throws these errors:

Errors:

/home/lazzu/dev/SharpFont/SharpFont.sln (default targets) ->
(Build target) ->
/home/lazzu/dev/SharpFont/SharpFont/SharpFont.csproj (default targets) ->
/usr/lib/mono/4.0/Microsoft.CSharp.targets (CoreCompile target) ->

    BBox.cs(69,11): error CS0266: Cannot implicitly convert type `System.IntPtr' to `int'. An explicit conversion exists (are you missing a cast?)
    BBox.cs(70,11): error CS0266: Cannot implicitly convert type `System.IntPtr' to `int'. An explicit conversion exists (are you missing a cast?)
    BBox.cs(71,11): error CS0266: Cannot implicitly convert type `System.IntPtr' to `int'. An explicit conversion exists (are you missing a cast?)
    BBox.cs(72,11): error CS0266: Cannot implicitly convert type `System.IntPtr' to `int'. An explicit conversion exists (are you missing a cast?)

     236 Warning(s)
     4 Error(s)

I do not know how to fix this, as I am not experienced with 32bit and 64bit diffirences.

Powershell

Hi. I will also want to thanks for this awesome work.

I was trying to add to this module a class in order to work with Powershell.
I want to get the font name from a bunch of font files.
I don't know too much about C# and i'm trying to do make this work but i can't. I've made a lot of tests, but i can't make it to work.
I'm using the code found in the Example with little changes.

This is the code i'm using

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Management;
using System.Management.Automation;
using SharpFont;

namespace Powershell
{

[Cmdlet(VerbsCommon.Get, "FontNames")]
public class Get_FontNames : System.Management.Automation.PSCmdlet
{
    [Parameter(Position = 0, Mandatory = true, HelpMessage = "The full file name of the archive")]
    [ValidateNotNullOrEmpty]
    public string ArchiveFileName { get; set; }

    //protected override void EndProcessing()

    protected override void ProcessRecord()
    {
        //TODO make several examples in an example browser

        try
        {
            using (Library lib = new Library())
            {
                WriteObject("FreeType version: " + lib.Version + "\n", true);
                using (Face face = lib.NewFace(@ArchiveFileName, 0))
                {
                    WriteObject("Information for font " + face.FamilyName, true);
                    WriteObject("Information for font " + face.GetPostscriptName(), true);
                    WriteObject("====================================", true);
                    WriteObject("Number of faces: " + face.FaceCount, true);
                    WriteObject("Face flags: " + face.FaceFlags, true);
                    WriteObject("Style: " + face.StyleName, true);
                    WriteObject("Style flags: " + face.StyleFlags, true);
                }
            }
        }
        catch (FreeTypeException e)
        {
            WriteObject(e.Error.ToString(), true);
        }

    }
}

}
I don't what I'm doing wrong.
Any help, would be appreciated.

Thank you

FTBitmap Copy issue

I tried to copy a FTBitmap after rendering but failed. It's because of the face.Glyph.Bitmap.Reference" is null. Can you look into it? Almost all methods of FTBitmap are using it. You may need to save it when glyph is rendered.
To test, just add the following line in your Examples:
FTBitmap copy = face.Glyph.Bitmap.Copy(face.Glyph.Library);
after
face.Glyph.RenderGlyph(RenderMode.Normal);
in RenderString(...) function of program.cs.

Hope you are still visiting this place some time...

Errors in Outline.cs

Hi, first I want to thank you for putting together this awesome resource. I was trying to use it to grab glyph outline data, and I found a couple of issues in the implementation of Outline.cs. All of them are related to the size of the data being passed.

First, on line 179, you currently have this:

points[i] = new FTVector(new IntPtr(array.ToInt64() + IntPtr.Size * i));

but it should be:

points[i] = new FTVector(new IntPtr(array.ToInt64() + (IntPtr.Size * i * 2)));

The FTVector consists of two 32 bit values, so you need to advance the pointer accordingly.

Second, on line 216, you currently have:

tags[i] = Marshal.ReadByte(array, IntPtr.Size * i);

but it should be:

tags[i] = Marshal.ReadByte(array, sizeof(byte) * i);

The tag data is only one byte each, so the pointer was being advanced too far for tags after the first.

Finally, on line 245 you have:

contours[i] = Marshal.ReadInt16(array, IntPtr.Size * i);

but it should be:

contours[i] = Marshal.ReadInt16(array, sizeof(short) * i);

Same issue as the tags, the data is smaller than the amount that the pointer is advanced.

With these changes, I am getting the glyph data that I expect.

Thanks again for maintaining this project!

Keywords in NuGet

I think this project would get more visibility inside NuGet if you add more keywords like "freetype", "font", "rendering", etc. Had to navigate to this repo because I didn't remember the name of the project and was unable to find it from NuGet search!

truetype rendering problem

This seems to be a continuation of issue #31 but doesn't happen with all fonts.
The test-font showing the problem is available at https://drive.google.com/file/d/0B_GX6ld_1ZunVXdnSU9kZy1wRVU/edit?usp=sharing
Rendering code is still the same, I've attached a few images to illustrate the problem:

application under windows 7, one page with different sizes, another with different colors:
bradley-scale-win7
bradley-colors-win7

the same under windows 8:
bradley-scale-win8
bradley-colors-win8

For comparison, visualizing the same data as html shown in Google Chrome:
bradley-scale-chrome
bradley-colors-chrome

Firefox is almost the same as Google Chrome, no need for extra images I think.

I tried loading the Glyphs and rendering them with Mono instead of Normal, but got some exception when trying ...

Any idea what's going wrong here?

Shaping support

Hi. Thanks for this awesome work.

I was trying to render a RTL text ("فارسی") with this font and this was the result which is broken and reversed:
helloworld
I know the order and index of characters are just done as an example but I think it would be nice if you provide some API for text shaping [if is not available yet]. For example on a similar bug on libass, this seems what is done about it. This will be actually an easy and excellent answer to this stackoverflow because after having a shaper, configuring the options it can provide is very cool (not needed at first of-course), worth to read article and interesting announcement and generally worth to see comparison between HarfBuzz and Uniscribe which also indicated what languages needs text shaping

So, what do you think? What should be done? Is this feature should considered for a separate project or is doable here?

Thank you

GlyphSlot.Bitmap contains garbage data for small sizes (<15) of Calibri font.

Hello. I'm rendering various font glyphs into a bitmap, and fonts like Arial or Cambria render fine at all possible sizes, yet Calibri (usual MS Office font) behaves weird. If Calibri's font size is greater than 14, then all glyphs are drawn correctly; but if its font size is 14 and smaller, then even for innocent chars like 'a'-'z' GlyphSlot shows empty outline (GlyphSlot.Outline.PointsCount == 0), and at the same time slot's bitmap data has correct width and row count, but its contents are corrupted. I'm attaching the picture to illustrate the situation.

I checked my code lots of times, but it looks correct and works for other fonts and sizes; then I took a look into the SharpFonts sources, but they also look fine. So I'm kinda stumped.

Small snippet which reproduces the problem for me:

using (var lib = new Library())
{
    var face = lib.NewFace(pathToCalibriFontHere, 0);
    face.SetCharSize(0, 14 * 64, 0, 96);
    uint index = face.GetCharIndex('a');
    face.LoadGlyph(index, LoadFlags.Default, LoadTarget.Normal);
    face.Glyph.RenderGlyph(RenderMode.Normal);
    Debug.Assert(face.Glyph.Outline.PointsCount == 0);
}

Does anyone have any ideas on what might have gone wrong?

Problem with small sizes of Calibri font

Wrong Face.SetTransform help text

The help text retains the "Use 0 for the identity matrix" for the first parameter, although only FTMatrix types. It should specify if the valid values for the identity matrix are null, new FMatrix() or new FTMatrix(1, 0, 0, 1).

FTBitmap Reference is IntPtr.Zero

When using the SharpFont library I can successfully generate a few bitmaps, but after awhile I receive an error in the private void FTBitmap::Dispose(bool disposing) function. It would seem that Reference, the bitmap, being passed down to the free type library is IntPtr.Zero.

This can be replicated in the example program by creating a loop around the bitmap generating function RenderString. Below you will find the main function edited to cause this error.

    public static void Main(string[] args)
    {
        //TODO make several examples in an example browser

        try
        {
            using (Library lib = new Library())
            {
                Console.WriteLine("FreeType version: " + lib.Version + "\n");

                using (Face face = lib.NewFace(@"Fonts/Cousine-Regular-Latin.ttf", 0))
                {
                    //attach a finalizer delegate
                    //face.Generic = new Generic(IntPtr.Zero, OnFaceDestroyed);

                    //write out some basic font information
                    Console.WriteLine("Information for font " + face.FamilyName);
                    Console.WriteLine("====================================");
                    Console.WriteLine("Number of faces: " + face.FaceCount);
                    Console.WriteLine("Face flags: " + face.FaceFlags);
                    Console.WriteLine("Style: " + face.StyleName);
                    Console.WriteLine("Style flags: " + face.StyleFlags);

                    face.SetCharSize(0, 32 * 64, 0, 96);

                                            // JTS: Adding this loop causes the error. It would seem that something
                                            // causes the Glyph bitmap to become invalid.
                    for (int i = 0; i < 500; i++)
                    {
                        Console.WriteLine("\nWriting string \"Hello qjgp Wyrld!\":");
                        Bitmap bmp = RenderString(face, "Hello qjgp Wyrld!");

                                                // JTS: Edited this to give different images....this could be remove and the
                                                // images could save over the previous result.
                        bmp.Save("helloworld" + i.ToString() + ".png", ImageFormat.Png);
                        bmp.Dispose();
                    }
                    Console.WriteLine("Done!\n");
                }
            }
        }
        catch (FreeTypeException e)
        {
            Console.Write(e.Error.ToString());
        }

        Console.ReadKey();
    }

SelectCharmap & SetCharmap Not Working?

When creating a new Face, SharpFont/FreeType defaults to the Unicode CharMap as expected. For fonts that don't have a Unicode CharMap (like symbol fonts such as the standard Wingdings), the CharMap is set to null as expected.

However, when I try setting the CharMap with either SelectCharmap or SetCharmap to another CharMap that's in the CharMaps array, it doesn't take. No exceptions are generated, but the Charmap remains null.

Perhaps I'm just missing something, Here's the code that's not's working for symbol fonts:

        fontFace = new Face(lib, Path.Combine(FontDir.Text, FontName.Text));
        if (fontFace.CharMap == null)
        {
            fontFace.SelectCharmap(SharpFont.Encoding.MicrosoftSymbol);

            foreach (CharMap charMap in fontFace.CharMaps)
            {
                if(charMap.PlatformId == SharpFont.TrueType.PlatformId.Microsoft)
                {
                    fontFace.SetCharmap(charMap);
                    break;
                }
            }
        }

I expect SelectCharmap or SetCharmap to set the CharMap appropriately, but neither do.

Subsequent calls to GetCharIndex return 0, which is what I'd expect for a null CharMap.

Is there another step I need to do before attempting to set the CharMap or another way to accomplish this? Or this is just not working in SharpFont?

FTBitmap.ToGdipBitmap seems to render empty for pcf fonts

I had been wondering why the text from my pixel-fonts vanished, and when checking the result of fontFace.Glyph.Bitmap.ToGdipBitmap(charColor); with the image debugger in visual studio, it seemed to be just an empty image without any pixels set.

Crash with SharpFont 2.5.3.0 on Win7x64 with OpenRA

Had this reproducable crash with SharpFont 2.5.3.0 right at launch with https://github.com/OpenRA/OpenRA on Win7x64.
SharpFont 2.5.0.1 works fine.

Crash log:
Tiberian Dawn Mod at Version {DEV_VERSION}
Operating System: Windows (Microsoft Windows NT 6.1.7601 Service Pack 1)
Runtime Version: .NET CLR 4.0.30319.18444
Exception of type System.TypeInitializationException: Der Typeninitialisierer für "OpenRA.Graphics.SpriteFont" hat eine Ausnahme verursacht.
Inner Exception of type System.DllNotFoundException: Die DLL "freetype6.dll": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
TypeName=``
bei SharpFont.FT.FT_Init_FreeType(IntPtr& alibrary)
bei SharpFont.Library..ctor()
bei OpenRA.Graphics.SpriteFont..cctor() in e:\OpenRA_work2\OpenRA.Game\Graphics\SpriteFont.cs:Zeile 22.
bei OpenRA.Graphics.SpriteFont..ctor(String name, Int32 size)
bei OpenRA.Graphics.Renderer.b__1(KeyValuePair2 x) in e:\OpenRA_work2\OpenRA.Game\Graphics\Renderer.cs:Zeile 95. bei System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
bei System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
bei OpenRA.Graphics.Renderer.InitializeFonts(Manifest m) in e:\OpenRA_work2\OpenRA.Game\Graphics\Renderer.cs:Zeile 94.
bei OpenRA.Game.InitializeMod(String mod, Arguments args) in e:\OpenRA_work2\OpenRA.Game\Game.cs:Zeile 303.
bei OpenRA.Game.Initialize(Arguments args) in e:\OpenRA_work2\OpenRA.Game\Game.cs:Zeile 261.
bei OpenRA.Program.Run(String[] args) in e:\OpenRA_work2\OpenRA.Game\Support\Program.cs:Zeile 108.
bei OpenRA.Program.Main(String[] args) in e:\OpenRA_work2\OpenRA.Game\Support\Program.cs:Zeile 39.

Outline.Decompose Error

Hey,

I'm not sure if this is an error or just my misunderstanding how to to use the Decompose Function in the library.

I'm trying to use Decompose to create an SVG path like so:

public void SetSvgPathFromGlyph(GlyphSlot glyph)
{
    var pathString = new StringBuilder();
    var outlineFuncs = new OutlineFuncs(
                new MoveToFunc((to, user) => {
                    pathString.AppendFormat("M{0} {1}\n", to.X, to.Y);
                    return 0; // 0 is success
                }),
                new LineToFunc((to, user) => {
                    pathString.AppendFormat("L{0} {1}\n", to.X, to.Y);
                    return 0;
                }),
                new ConicToFunc((control, to, user) => {
                    pathString.AppendFormat("Q{2} {3} {0} {1}", to.X, to.Y, control.X, control.Y);
                    return 0;
                }),
                new CubicToFunc((control1, control2, to, user) => {
                    pathString.AppendFormat("C{2} {3} {4} {5} {0} {1}", to.X, to.Y, control1.X, control1.Y, control2.X, control2.Y);
                    return 0;
                }),
                0, 0
            );
    var pointer = new IntPtr(0);            
    glyph.Outline.Decompose(outlineFuncs, pointer);

    SvgPath = pathString.ToString();

}

However, when doing so I get an error in Outline.cs:427
Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "line_to"), Marshal.GetFunctionPointerForDelegate(funcInterface.LineFuction));

System.ArgumentException: Field passed in is not a marshaled member of the type 'SharpFont.Internal.OutlineFuncsRec'. Parameter name: fieldName

Thanks, any ideas on how to fix would be appreciated!

Outline decomposition interop

Hey, awesome work on this library. I've been using it in my game, but since I've converted from a raster pipeline to a resolution independent one, I refactored my font rendering code and found out that Outline.Decompose is broken.

As per FreeType's docs, the outline decomposition callbacks expect a pointer-to-struct of type FT_Vector. Currently, the callbacks in SharpFont use a FTVector. This gives garbage values as of the latest release (I noticed it when all X values were abnormally large and always the same [aka they were the pointer to the FT_Vector], while Y was zero in the Move callback).

I hacked together something in my local copy of SharpFont. Basically, I have two sets of callback delegates: the user-facing OutlineFuncs ones stay as-is, but I added a set of internal callbacks that accept FTVector by ref. In Outline.Decompose I create anonymous delegates of the internal callbacks that simply invoke the user-facing ones:

InternalMoveToFunc m = delegate(ref FTVector to, IntPtr u)
{
    return funcInterface.MoveFunction(to, u);
};

InternalLineToFunc l = delegate(ref FTVector to, IntPtr u)
{
    return funcInterface.LineFunction(to, u);
};

InternalConicToFunc q = delegate(ref FTVector control, ref FTVector to, IntPtr u)
{
    return funcInterface.ConicFunction(control, to, u);
};

InternalCubicToFunc c = delegate(ref FTVector control1, ref FTVector control2, ref FTVector to, IntPtr u)
{
    return funcInterface.CubicFunction(control1, control2, to, u);
};

Marshal.WriteIntPtr(funcInterfaceRef, Marshal.GetFunctionPointerForDelegate(m));
Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "lineTo"), Marshal.GetFunctionPointerForDelegate(l));
Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "conicTo"), Marshal.GetFunctionPointerForDelegate(q));
Marshal.WriteIntPtr(funcInterfaceRef, (int)Marshal.OffsetOf(typeof(OutlineFuncsRec), "cubicTo"), Marshal.GetFunctionPointerForDelegate(c));

Also, one little thing, in OutlineFuncs, 'LineFunction' is misspelled as 'LineFuction.'

Hope this helps!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.