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

For isocp.shx the font has incorrect bulge and weird vertical alignment #3

Open
NikhilSP opened this issue Dec 27, 2022 · 0 comments
Open

Comments

@NikhilSP
Copy link

NikhilSP commented Dec 27, 2022

The solution to weird vertical alignment:

// Add code as parameter
private static TextShape _ParseCode(ShxFile file, uint code, byte[] data, double scale)
    {
        var currentP = new Point();
        var polyLines = new List<PolyLine>();
        var currentPolyLine = new List<Point>();
        var sp = new Stack<Point>();
        var isPenDown = false;

        for (int i = 0; i < data.Length; i++)
        {
            var cb = data[i];

            if (i == 0 && cb == code) continue; // add this

            switch (cb)
            {
                case 0x00:
                    break;

Solution for bulge (Problem was radian and center of bulge are not calculated properly) :

 private static IEnumerable<Point> _GenerateArcPoints(Point start, Vector2 distance, double bulge)
    {
        var end = start + distance;
        var isClockwise = bulge < 0;
        var isLargeAngle = false;
        bulge = Math.Abs(bulge);
        var halfLength = Vector2.Distance(distance, Vector2.Zero) / 2;
        var h = halfLength * bulge;
        var radian = 4 * Math.Atan(bulge);// Add This for correct radian
        var normal = new Vector2(distance.Y, -distance.X);
        normal.Normalize();

        var radius = Math.Abs(halfLength / Math.Sin(radian / 2));
        var temp = Math.Sqrt((radius * radius) - (halfLength * halfLength)); // Add This for correct center
        normal *= temp; // Add This for correct center

        var center = start + distance / 2;
        if (isLargeAngle ^ isClockwise)
            center += normal;
        else center -= normal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant