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

Issue in PathFromGlypth #129

Open
rameshramaswamy opened this issue Mar 4, 2019 · 0 comments
Open

Issue in PathFromGlypth #129

rameshramaswamy opened this issue Mar 4, 2019 · 0 comments

Comments

@rameshramaswamy
Copy link

rameshramaswamy commented Mar 4, 2019

Below is the code snippet that we have written to generate path from glyph.
GlyphToPath works only for 95% of the characters, For some character, it throws array out of index at Line @46. Kindly let me know if you have better approach get a path from Glyph

` private string GlyphToPath(uint inGlyphIndex, bool inSingleStroke)
{
StringBuilder strPath = new StringBuilder();
string glyphPath = string.Empty;

        int flag;
        int flag2;
        int i = 0;
        int lSegmentCount;
        int total = 0;
        bool bClosed;
        FTVector pointFirst;
        FTVector point1;
        FTVector point2;
        FTVector point3;
        FTVector point4;
        string calculatedPath = string.Empty;
        this.FontFace.LoadGlyph(inGlyphIndex, LoadFlags.NoScale, LoadTarget.Normal);

        for (int c = 0; c < this.FontFace.Glyph.Outline.ContoursCount; c++)
        {
            lSegmentCount = 0;
            bClosed = false;
            total = this.FontFace.Glyph.Outline.Contours[c];

            pointFirst = this.FontFace.Glyph.Outline.Points[i];
            calculatedPath = "M " + pointFirst.X.Value + " " + (-pointFirst.Y.Value + this.FontFace.BBox.Top) + " ";
            strPath.Append(calculatedPath);
            for (; i < total;)
            {
                point1 = this.FontFace.Glyph.Outline.Points[i];
                flag = this.FontFace.Glyph.Outline.Tags[i];
                flag2 = this.FontFace.Glyph.Outline.Tags[i + 1];
                i++;
                if ((flag == 1) && (flag2 == 1))
                {
                    point2 = this.FontFace.Glyph.Outline.Points[i];
                    calculatedPath = "L " + point2.X.Value + " " + (-point2.Y.Value + this.FontFace.BBox.Top) + " ";
                    strPath.Append(calculatedPath);
                    lSegmentCount++;
                }
                else if (flag == 1)
                {
                    point2 = this.FontFace.Glyph.Outline.Points[i];
                    i++;
                    if (i > total)
                    {
                        point3 = new FTVector(0, 0);
                    }
                    else
                    {
                        point3 = this.FontFace.Glyph.Outline.Points[i]; // This is line @ 46 throws array out of index exception some character
                    }
                    i++;
                    if (i <= total)
                    {
                        point4 = this.FontFace.Glyph.Outline.Points[i];
                        calculatedPath = "C " + point2.X.Value + " " + (-point2.Y.Value + this.FontFace.BBox.Top) + " " + point3.X.Value + " " + (-point3.Y.Value + this.FontFace.BBox.Top) + " " + point4.X.Value + " " + (-point4.Y.Value + this.FontFace.BBox.Top) + " ";
                        strPath.Append(calculatedPath);
                        lSegmentCount++;
                    }
                    else
                    {
                        calculatedPath = "C " + point2.X.Value + " " + (-point2.Y.Value + this.FontFace.BBox.Top) + " " + point3.X.Value + " " + (-point3.Y.Value + this.FontFace.BBox.Top) + " " + pointFirst.X.Value + " " + (-pointFirst.Y.Value + this.FontFace.BBox.Top) + " ";
                        strPath.Append(calculatedPath);
                        lSegmentCount++;
                        bClosed = true;
                    }
                }
                else
                {
                    break;
                }
            }
            i = this.FontFace.Glyph.Outline.Contours[c] + 1;
            if ((bClosed == false) && (lSegmentCount > 1) && (inSingleStroke == false))
            {
                calculatedPath = "L " + pointFirst.X.Value + " " + (-pointFirst.Y.Value + this.FontFace.BBox.Top) + " ";
               strPath.Append(calculatedPath);
            }

        }
        strPath.Append("Z");
        glyphPath = strPath.ToString();

        return glyphPath;
    }`
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