コード例 #1
0
        // Compute outline for a single glyph
        // if flatten is true convert curve into a list of segments
        // out parameter advance is set to the default glyph advancement
        // if embold <> 0, embold the outline by the desired strength
        public Outline GetGlyphOutline(uint idx, out Outline.Point advance, bool flatten, float embold, int isteps)
        {
            // TODO: add outline caching ?


            // load glyph for c in face slot
            //int code = FT.FT_Load_Char(face_, (uint)c, FT.FT_LOAD_DEFAULT); // FT_LOAD_DEFAULT, FT_LOAD_NO_BITMAP, FT_LOAD_NO_SCALE ?

            int code = FT.FT_Load_Glyph(face_, idx, FT.FT_LOAD_DEFAULT);

            FT.CheckError(code);


            // Check that the glyph is in Outline format

            FT.FT_FaceRec facerec = FT.HandleToRecord <FT.FT_FaceRec>(face_);

            IntPtr slot = facerec.glyph;

            FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord <FT.FT_GlyphSlotRec>(slot);

            if (slotrec.format != FT.GLYPH_FORMAT_OUTLINE)
            {
                throw new FTError(string.Format("Bad glyph format (0x{0:x4})", slotrec.format));
                //throw new FTError("Bad glyph format (" + slotrec.format + ")");
            }

            // Get glyph outline in gptr
            IntPtr gptr;

            code = FT.FT_Get_Glyph(slotrec, out gptr);
            FT.CheckError(code);


            // Embold outline
            if (embold != 0)
            {
                // Console.WriteLine("EMBOLD=" + embold);
                // IntPtr optr = FT.fthelper_glyph_get_outline_address(slot);
                FT.FT_Outline_Embolden(slotrec.outline, (int)(embold * 64 * 100)); // convert to 26.6 fractional format
            }

            // Decompose outline
            Outline outline = null;

            if (flatten)
            {
                outline = Outline.FlattenGlyph(slotrec, vectorScale_, isteps);
            }
            else
            {
                outline = Outline.DecomposeGlyph(slotrec, vectorScale_, isteps);
            }

            FT.FT_Done_Glyph(gptr);

            advance = new Outline.Point(slotrec.advance, vectorScale_);

            return(outline);
        }
コード例 #2
0
        public void Decompose(FT.FT_GlyphSlotRec slot)
        {
            init_funcs();
            decomposer_funcs.delta = 0;
            decomposer_funcs.shift = 0;

            // IntPtr outline = FT.fthelper_glyph_get_outline_address(glyph);

            int code = FT.FT_Outline_Decompose(slot.outline, ref decomposer_funcs, IntPtr.Zero);

            FT.CheckError(code);
        }
コード例 #3
0
        public unsafe UnityEngine.Texture2D RenderIntoTexture(char c)
        {
            int code;

            FT.FT_FaceRec facerec = FT.HandleToRecord <FT.FT_FaceRec>(face_);
            IntPtr        slot    = facerec.glyph;

            code = FT.FT_Load_Char(face_, c, FT.FT_LOAD_RENDER /*|FT.FT_LOAD_TARGET_NORMAL*/);
            if (code != 0)
            {
                return(null);
            }

            FT.FT_GlyphSlotRec   slotrec = FT.HandleToRecord <FT.FT_GlyphSlotRec>(slot);
            FTSharp.FT.FT_Bitmap ftbm    = slotrec.bitmap;

            UnityEngine.Texture2D texbuffer = new UnityEngine.Texture2D((int)ftbm.width, (int)ftbm.rows, UnityEngine.TextureFormat.ARGB32, false);
            if (((int)ftbm.pixel_mode) != 2)
            {
                UnityEngine.Debug.LogError("Unsupported bitmap depth :" + ((int)ftbm.pixel_mode).ToString());
                return(null);
            }
            //  FT_PIXEL_MODE_MONO,
            //FT_PIXEL_MODE_GRAY,

            UnityEngine.Color32 [] clrs = texbuffer.GetPixels32();
            int i = 0;



            // UNSAFE DOES NOT WORK IN THE WEB PLAYER !
            for (int y = 0; y < ftbm.rows; y++)
            {
                long  j  = (((ftbm.rows - (1 + y)) * ftbm.pitch));
                byte *bo = ((byte *)ftbm.buffer);
                for (int x = 0; x < ftbm.width; x++)
                {
                    clrs[i].a = clrs[i].r = clrs[i].g = clrs[i].b = (bo[j + x]);
                    i++;
                }
            }
            texbuffer.SetPixels32(clrs);
            texbuffer.Apply();
            return(texbuffer);
        }
コード例 #4
0
        // Compute the Bounding box of a single glyph
        public BBox Measure(char c, out Outline.Point advance)
        {
            // load glyph for c in face slot
            int code = FT.FT_Load_Char(face_, (uint)c, (int)(FT.FT_LOAD_DEFAULT | (1 << 3))); // FT_LOAD_DEFAULT, FT_LOAD_NO_BITMAP, FT_LOAD_NO_SCALE ?

            FT.CheckError(code);


            // Check that the glyph is in Outline format

            FT.FT_FaceRec facerec = FT.HandleToRecord <FT.FT_FaceRec>(face_);

            IntPtr slot = facerec.glyph;

            FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord <FT.FT_GlyphSlotRec>(slot);

            if (slotrec.format != FT.GLYPH_FORMAT_OUTLINE)
            {
                throw new FTError("Bad glyph format (" + slotrec.format + ")");
            }


            // get glyph in gptr
            IntPtr gptr;

            code = FT.FT_Get_Glyph(slotrec, out gptr);
            FT.CheckError(code);

            FT.FT_BBox ft_bbox;
            FT.FT_Glyph_Get_CBox(gptr, 0, out ft_bbox);

            FT.FT_Done_Glyph(gptr);

            BBox bbox = new BBox(ft_bbox, vectorScale_);

            advance = new Outline.Point(slotrec.advance, vectorScale_);

            return(bbox);
        }
コード例 #5
0
ファイル: Outline.cs プロジェクト: CCCpeggy/unity3d-ttftext
        public static Outline DecomposeGlyph(FT.FT_GlyphSlotRec slot, float scale, int isteps)
        {
            Outline outline = new Outline(isteps);

            if (odecomposer == null)
            {
                odecomposer = new OutlineDecomposer(scale);
            }

            lock (odecomposer)
            {
                odecomposer.scale = scale;

                odecomposer.LineToEv  = outline.LineTo;
                odecomposer.MoveToEv  = outline.MoveTo;
                odecomposer.ConicToEv = outline.ConicTo;
                odecomposer.CubicToEv = outline.CubicTo;

                odecomposer.Decompose(slot);
            }

            return(outline);
        }
コード例 #6
0
        public void RenderText(string text, DrawBitmapF drawBitmap, int penx, int peny)
        {
            int code;

            FT.FT_FaceRec facerec = FT.HandleToRecord <FT.FT_FaceRec>(face_);
            IntPtr        slot    = facerec.glyph;

            foreach (char c in text)
            {
                code = FT.FT_Load_Char(face_, c, FT.FT_LOAD_RENDER /*|FT.FT_LOAD_TARGET_NORMAL*/);
                if (code != 0)
                {
                    continue;
                }

                FT.FT_GlyphSlotRec slotrec = FT.HandleToRecord <FT.FT_GlyphSlotRec>(slot);
                //Bitmap bitmap = new Bitmap(slotrec.bitmap);

                //                drawBitmap(bitmap, penx + slotrec.bitmap_left, peny + slotrec.bitmap_top);
                //drawBitmap(bitmap, penx + slotrec.bitmap_left, peny - slotrec.bitmap_top);
                drawBitmap(slotrec.bitmap, penx + slotrec.bitmap_left, peny - slotrec.bitmap_top);
                penx += (slotrec.advance.x >> 6);
            }
        }
コード例 #7
0
ファイル: FT.cs プロジェクト: CCCpeggy/unity3d-ttftext
 public static extern int FT_Get_Glyph(FT.FT_GlyphSlotRec slot, out IntPtr glyph);