Exemplo n.º 1
0
 bool GetFace(uint codepoint, out uint index, out IntPtr face)
 {
     //use our font!
     index = FT.FT_Get_Char_Index(facePtr, codepoint);
     if (index != 0)
     {
         face = facePtr;
         return(true);
     }
     //try fallback font
     if (context.Fallback == IntPtr.Zero)
     {
         face = IntPtr.Zero;
         return(false);
     }
     FT.FT_Set_Char_Size(context.Fallback,
                         FTMath.To26Dot6(0),
                         size26d6,
                         0,
                         96
                         );
     index = FT.FT_Get_Char_Index(context.Fallback, codepoint);
     if (index != 0)
     {
         face = context.Fallback;
         return(true);
     }
     //none of the fonts have this mysterious character
     face = IntPtr.Zero;
     return(false);
 }
Exemplo n.º 2
0
        public Font(FontContext ctx, string filename, float size)
        {
            context  = ctx;
            size26d6 = FTMath.To26Dot6(size);
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Font not found " + filename, filename);
            }

            var err = FT.FT_New_Face(context.Library, filename, 0, out facePtr);

            if (err != 0)
            {
                throw new Exception("Freetype Error");
            }

            FT.FT_Set_Char_Size(facePtr,
                                FTMath.To26Dot6(0),
                                size26d6,
                                0,
                                96
                                );
            //get metrics
            var faceRec = Marshal.PtrToStructure <FT.FaceRec> (facePtr);
            var szRec   = Marshal.PtrToStructure <FT.SizeRec> (faceRec.size);

            lineHeight = (int)FTMath.From26Dot6(szRec.metrics.height);
            pages.Add(new Texture(
                          PAGE_SIZE, PAGE_SIZE
                          ));

            //Rasterize standard ASCII
            for (int i = 32; i < 127; i++)
            {
                AddCharacter((uint)i);
            }
        }