Esempio n. 1
0
        /// <summary>
        /// append data from src to dest, dest data will changed***
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dest"></param>
        internal static void AppendGlyph(TtfGlyph dest, TtfGlyph src)
        {
            int    org_dest_len      = dest._contourEndPoints.Length;
            int    src_contour_count = src._contourEndPoints.Length;
            ushort org_last_point    = (ushort)(dest._contourEndPoints[org_dest_len - 1] + 1); //since start at 0

            dest.glyphPoints       = Utils.ConcatArray(dest.glyphPoints, src.glyphPoints);
            dest._contourEndPoints = Utils.ConcatArray(dest._contourEndPoints, src._contourEndPoints);

            //offset latest append contour  end points
            int newlen = dest._contourEndPoints.Length;

            for (int i = org_dest_len; i < newlen; ++i)
            {
                dest._contourEndPoints[i] += (ushort)org_last_point;
            }
            //calculate new bounds
            Bounds destBound = dest.Bounds;
            Bounds srcBound  = src.Bounds;
            short  newXmin   = (short)Math.Min(destBound.XMin, srcBound.XMin);
            short  newYMin   = (short)Math.Min(destBound.YMin, srcBound.YMin);
            short  newXMax   = (short)Math.Max(destBound.XMax, srcBound.XMax);
            short  newYMax   = (short)Math.Max(destBound.YMax, srcBound.YMax);

            dest._bounds = new Bounds(newXmin, newYMin, newXMax, newYMax);
        }
Esempio n. 2
0
        internal static TtfGlyph Clone(TtfGlyph original)
        {
            //----------------------

            return(new TtfGlyph(
                       Utils.CloneArray(original.glyphPoints),
                       Utils.CloneArray(original._contourEndPoints),
                       original.Bounds,
                       original.GlyphInstructions != null ? Utils.CloneArray(original.GlyphInstructions) : null));
        }
Esempio n. 3
0
        internal static void TransformNormalWith2x2Matrix(TtfGlyph glyph, float m00, float m01, float m10, float m11)
        {
            //http://stackoverflow.com/questions/13188156/whats-the-different-between-vector2-transform-and-vector2-transformnormal-i
            //http://www.technologicalutopia.com/sourcecode/xnageometry/vector2.cs.htm

            //change data on current glyph
            float new_xmin = 0;
            float new_ymin = 0;
            float new_xmax = 0;
            float new_ymax = 0;


            GlyphPointF[] glyphPoints = glyph.glyphPoints;
            for (int i = glyphPoints.Length - 1; i >= 0; --i)
            {
                GlyphPointF p = glyphPoints[i];
                float       x = p.P.X;
                float       y = p.P.Y;

                float newX, newY;
                //please note that this is transform normal***
                glyphPoints[i] = new GlyphPointF(
                    newX       = (float)Math.Round((x * m00) + (y * m10)),
                    newY       = (float)Math.Round((x * m01) + (y * m11)),
                    p.onCurve);

                //short newX = xs[i] = (short)Math.Round((x * m00) + (y * m10));
                //short newY = ys[i] = (short)Math.Round((x * m01) + (y * m11));
                //------
                if (newX < new_xmin)
                {
                    new_xmin = newX;
                }
                if (newX > new_xmax)
                {
                    new_xmax = newX;
                }
                //------
                if (newY < new_ymin)
                {
                    new_ymin = newY;
                }
                if (newY > new_ymax)
                {
                    new_ymax = newY;
                }
            }
            //TODO: review here
            glyph._bounds = new Bounds(
                (short)new_xmin, (short)new_ymin,
                (short)new_xmax, (short)new_ymax);
        }
Esempio n. 4
0
        //--------------

        internal static void OffsetXY(TtfGlyph glyph, short dx, short dy)
        {
            //change data on current glyph
            GlyphPointF[] glyphPoints = glyph.glyphPoints;
            for (int i = glyphPoints.Length - 1; i >= 0; --i)
            {
                glyphPoints[i] = glyphPoints[i].Offset(dx, dy);
            }
            //-------------------------
            Bounds orgBounds = glyph._bounds;

            glyph._bounds = new Bounds(
                (short)(orgBounds.XMin + dx),
                (short)(orgBounds.YMin + dy),
                (short)(orgBounds.XMax + dx),
                (short)(orgBounds.YMax + dy));
        }