コード例 #1
0
            //-----------------------------------------------------------------------
            internal void finishCurve(char lc)
            {
                int n;

                if (lc == 'c' || lc == 'C' || lc == 's' || lc == 'S')
                {
                    n = 3;
                }
                else if (lc == 'q' || lc == 'Q' || lc == 't' || lc == 'T')
                {
                    n = 2;
                }
                else
                {
                    n = curve.size() - 1;
                }

                for (int i = 0; i < curve.size(); i += n)
                {
                    if (i + 3 >= curve.size())
                    {
                        break;
                    }
                    BezierCurve2 bc2 = new BezierCurve2();
                    bc2.setNumSeg(mNumSeg);
                    bc2.addPoint(curve[i + 0]);
                    bc2.addPoint(curve[i + 1]);
                    bc2.addPoint(curve[i + 2]);
                    bc2.addPoint(curve[i + 3]);
                    Shape bc2shape = bc2.realizeShape();
                    //Vector2 lp = shape.getPoint(shape.getPoints().size() - 1);
                    Vector2 lp = shape.getPoint(shape.getPointCount() - 1);
                    //for (std::vector<Vector2>::iterator iter = bc2shape.getPoints().begin(); iter != bc2shape.getPoints().end(); iter++)
                    for (int j = 0; j < bc2shape.getPointCount(); j++)
                    {
                        //if (iter == bc2shape.getPoints().begin())
                        if (j == 0)
                        {
                            //if (*iter != lp) shape.addPoint(*iter);
                            if (bc2shape.getPointsReference()[j] != lp)
                            {
                                shape.addPoint(bc2shape.getPointsReference()[j]);
                            }
                        }
                        else
                        {
                            shape.addPoint(bc2shape.getPointsReference()[j]);//shape.addPoint(*iter);
                        }
                    }
                }
                curve.clear();
            }
コード例 #2
0
//    *
//	 * Build a MultiShape from chars (one Shape per character)
//	 * \exception Ogre::InternalErrorException Freetype error
//	 * \todo Need to split shapes of multi region chars. For example the letter \c O
//	 * has two shapes, but they are connected to one shape.
//
        public MultiShape realizeShapes()
        {
            MultiShape retVal = new MultiShape();

            FT_Library   ftlib = new FT_Library();
            FT_Face      face  = new FT_Face();
            FT_GlyphSlot slot  = new FT_GlyphSlot();

            FT_Error error = FT_Init_FreeType(ftlib);

            if (error == 0)
            {
                error = FT_New_Face(ftlib, getFontFileByName().c_str(), 0, face);
                if (error == FT_Err_Unknown_File_Format)
                {
                    //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __LINE__ macro:
                    //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __FILE__ macro:
                    throw ExceptionFactory.create(Mogre.ExceptionCodeType <Mogre.Exception.ExceptionCodes.ERR_INTERNAL_ERROR>(), "FreeType ERROR: FT_Err_Unknown_File_Format", "Procedural::TextShape::realizeShapes()", __FILE__, __LINE__);
                    ;
                }
                else if (error != null)
                {
                    //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __LINE__ macro:
                    //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __FILE__ macro:
                    throw ExceptionFactory.create(Mogre.ExceptionCodeType <Mogre.Exception.ExceptionCodes.ERR_INTERNAL_ERROR>(), "FreeType ERROR: FT_New_Face - " + StringConverter.toString(error), "Procedural::TextShape::realizeShapes()", __FILE__, __LINE__);
                    ;
                }
                else
                {
                    FT_Set_Pixel_Sizes(face, 0, mFontSize);

                    int px = 0;
                    int py = 0;
                    slot = face.glyph;

                    for (int n = 0; n < mText.length(); n++)
                    {
                        error = FT_Load_Char(face, mText[n], FT_LOAD_NO_BITMAP);
                        if (error != null)
                        {
                            continue;
                        }

                        Shape s = new Shape();

                        int         nContours = face.glyph.outline.n_contours;
                        int         startPos  = 0;
                        string      tags      = face.glyph.outline.tags;
                        FT_Vector[] vec       = face.glyph.outline.points;

                        for (int k = 0; k < nContours; k++)
                        {
                            if (k > 0)
                            {
                                startPos = face.glyph.outline.contours[k - 1] + 1;
                            }
                            int endPos = face.glyph.outline.contours[k] + 1;

                            Vector2 lastPoint = Vector2.ZERO;
                            for (int j = startPos; j < endPos; j++)
                            {
                                if (FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_ON)
                                {
                                    lastPoint = Vector2((float)vec[j].x, (float)vec[j].y);
                                    s.addPoint(lastPoint / 64.0f);
                                }
                                else
                                {
                                    if (FT_CURVE_TAG(tags[j]) == FT_CURVE_TAG_CUBIC)
                                    {
                                        int prevPoint = j - 1;
                                        if (j == 0)
                                        {
                                            prevPoint = endPos - 1;
                                        }
                                        int nextIndex = j + 1;
                                        if (nextIndex >= endPos)
                                        {
                                            nextIndex = startPos;
                                        }
                                        Vector2[] nextPoint = new Vector2[nextIndex]((float)vec.x, (float)vec[nextIndex].y);
                                        if ((FT_CURVE_TAG(tags[prevPoint]) != FT_CURVE_TAG_ON) && (FT_CURVE_TAG(tags[prevPoint]) == FT_CURVE_TAG_CUBIC))
                                        {
                                            BezierCurve2 bc = new BezierCurve2();
                                            bc.addPoint(Vector2((float)vec[prevPoint].x, (float)vec[prevPoint].y) / 64.0f);
                                            bc.addPoint(Vector2((float)vec[j].x, (float)vec[j].y) / 64.0f);
                                            bc.addPoint(Vector2((float)vec[nextIndex].x, (float)vec[nextIndex].y) / 64.0f);
                                            s.appendShape(bc.realizeShape());
                                        }
                                    }
                                    else
                                    {
                                        Vector2[] conicPoint = new Vector2[j]((float)vec.x, (float)vec[j].y);
                                        if (j == startPos)
                                        {
                                            if ((FT_CURVE_TAG(tags[endPos - 1]) != FT_CURVE_TAG_ON) && (FT_CURVE_TAG(tags[endPos - 1]) != FT_CURVE_TAG_CUBIC))
                                            {
                                                Vector2[] lastConnic = new Vector2[endPos - 1]((float)vec.x, (float)vec[endPos - 1].y);
                                                lastPoint = (conicPoint + lastConnic) / 2;
                                            }
                                        }

                                        int nextIndex = j + 1;
                                        if (nextIndex >= endPos)
                                        {
                                            nextIndex = startPos;
                                        }

                                        Vector2[] nextPoint = new Vector2[nextIndex]((float)vec.x, (float)vec[nextIndex].y);

                                        bool nextIsConnic = (FT_CURVE_TAG(tags[nextIndex]) != FT_CURVE_TAG_ON) && (FT_CURVE_TAG(tags[nextIndex]) != FT_CURVE_TAG_CUBIC);
                                        if (nextIsConnic)
                                        {
                                            nextPoint = (conicPoint + nextPoint) / 2;
                                        }

                                        int          pc = s.getPointCount();
                                        BezierCurve2 bc = new BezierCurve2();
                                        if (pc == 0)
                                        {
                                            bc.addPoint(Vector2.ZERO);
                                        }
                                        else
                                        {
                                            bc.addPoint(s.getPoint(pc - 1));
                                        }
                                        bc.addPoint(lastPoint / 64.0f);
                                        bc.addPoint(conicPoint / 64.0f);
                                        bc.addPoint(nextPoint / 64.0f);
                                        if (pc == 0)
                                        {
                                            s.appendShape(bc.realizeShape());
                                        }
                                        else
                                        {
                                            List <Vector2> subShape = bc.realizeShape().getPoints();
                                            for (List <Vector2> .Enumerator iter = subShape.GetEnumerator(); iter.MoveNext(); iter++)
                                            {
                                                if (iter != subShape.GetEnumerator())
                                                {
                                                    s.addPoint(iter.Current);
                                                }
                                            }
                                        }

                                        if (nextIsConnic)
                                        {
//
//ORIGINAL LINE: lastPoint = nextPoint;
                                            lastPoint = (nextPoint);
                                        }
                                    }
                                }
                            }
                        }

                        s.close();
                        s.translate((float)px, (float)py);
                        retVal.addShape(s);

                        px += slot.advance.x >> 6;
                        py += slot.advance.y >> 6;
                    }
                    FT_Done_Face(face);
                }
                FT_Done_FreeType(ftlib);
            }
            else
            {
                //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __LINE__ macro:
                //C++ TO C# CONVERTER TODO TASK: There is no direct equivalent in C# to the C++ __FILE__ macro:
                throw ExceptionFactory.create(Mogre.ExceptionCodeType <Mogre.Exception.ExceptionCodes.ERR_INTERNAL_ERROR>(), "FreeType ERROR: FT_Init_FreeTyp", "Procedural::TextShape::realizeShapes()", __FILE__, __LINE__);
                ;
            }

            return(retVal);
        }
コード例 #3
0
            void parseArcTo(bool rel, bool next)
            {
                if (next)
                {
                    index++;
                }
                float rx = 0.0f;

                if (!parseReal(ref rx))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float ry = 0.0f;

                if (!parseReal(ref ry))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float x_axis_rotation = 0.0f;

                if (!parseReal(ref x_axis_rotation))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float large_arc_flag = 0.0f;

                if (!parseReal(ref large_arc_flag))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float sweep_flag = 0.0f;

                if (!parseReal(ref sweep_flag))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float x = 0.0f;

                if (!parseReal(ref x))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }
                float y = 0.0f;

                if (!parseReal(ref y))
                {
                    OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo");
                }

                float RadiansPerDegree = Math.PI / 180.0f;
                float epx       = rel ? point.x + x : x;
                float epy       = rel ? point.y + y : y;
                bool  largeArc  = (large_arc_flag > 0);
                bool  clockwise = (sweep_flag > 0);

                if (epx == point.x && epy == point.y)
                {
                    return;
                }

                if (rx == 0.0f && ry == 0.0f)
                {
                    point = new Vector2(epx, epy);
                    shape.addPoint(point);
                    return;
                }

                float sinPhi = sin(x_axis_rotation * RadiansPerDegree);
                float cosPhi = cos(x_axis_rotation * RadiansPerDegree);

                float x1dash = cosPhi * (point.x - epx) / 2.0f + sinPhi * (point.y - epy) / 2.0f;
                float y1dash = -sinPhi * (point.x - epx) / 2.0f + cosPhi * (point.y - epy) / 2.0f;

                float root;
                float numerator = rx * rx * ry * ry - rx * rx * y1dash * y1dash - ry * ry * x1dash * x1dash;

                if (numerator < 0.0)
                {
                    float s = (float)sqrt(1.0f - numerator / (rx * rx * ry * ry));

                    rx  *= s;
                    ry  *= s;
                    root = 0.0f;
                }
                else
                {
                    root = ((largeArc && clockwise) || (!largeArc && !clockwise) ? -1.0f : 1.0f) * sqrt(numerator / (rx * rx * y1dash * y1dash + ry * ry * x1dash * x1dash));
                }

                float cxdash = root * rx * y1dash / ry;
                float cydash = -root * ry * x1dash / rx;

                float cx = cosPhi * cxdash - sinPhi * cydash + (point.x + epx) / 2.0f;
                float cy = sinPhi * cxdash + cosPhi * cydash + (point.y + epy) / 2.0f;

                float theta1 = CalculateVectorAngle(1.0f, 0.0f, (x1dash - cxdash) / rx, (y1dash - cydash) / ry);
                float dtheta = CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx, (-y1dash - cydash) / ry);

                if (!clockwise && dtheta > 0)
                {
                    dtheta -= 2.0f * Math.PI;
                }
                else if (clockwise && dtheta < 0)
                {
                    dtheta += 2.0f * Math.PI;
                }

                int   segments = (int)ceil((double)abs(dtheta / (Math.PI / 2.0f)));
                float delta    = dtheta / segments;
                float t        = 8.0f / 3.0f * sin(delta / 4.0f) * sin(delta / 4.0f) / sin(delta / 2.0f);

                float startX = point.x;
                float startY = point.y;

                BezierCurve2 bezier = new BezierCurve2();

                bezier.addPoint(startX, startY);
                for (int i = 0; i < segments; ++i)
                {
                    float cosTheta1 = cos(theta1);
                    float sinTheta1 = sin(theta1);
                    float theta2    = theta1 + delta;
                    float cosTheta2 = cos(theta2);
                    float sinTheta2 = sin(theta2);

                    float endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx;
                    float endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy;

                    float dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1);
                    float dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1);

                    float dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2);
                    float dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2);

                    bezier.addPoint(startX + dx1, startY + dy1);
                    bezier.addPoint(endpointX + dxe, endpointY + dye);

                    theta1 = theta2;
                    startX = endpointX;
                    startY = endpointY;
                }
                point = new Vector2(epx, epy);
                bezier.addPoint(point);
                bezier.setNumSeg(mNumSeg);
                std_vector <Vector2> pointList = bezier.realizeShape().getPointsReference();//getPoints();
                Vector2 lp = shape.getPoint(shape.getPoints().Length - 1);

                //for (std::vector<Vector2>::iterator iter = pointList.begin(); iter != pointList.end(); iter++)
                for (int ii = 0; ii < pointList.size(); ii++)
                {
                    //if (iter == pointList.begin())
                    if (ii == 0)
                    {
                        //if (*iter != lp) shape.addPoint(*iter);
                        if (pointList[ii] != lp)
                        {
                            shape.addPoint(pointList[ii]);
                        }
                    }
                    else
                    {
                        shape.addPoint(pointList[ii]);//shape.addPoint(*iter);
                    }
                }
            }