示例#1
0
        public override int GetCharWidth(PDFFont pdfFont, TTFontData data,
                                         char charCode)
        {
            InitLibrary();

            int aint = (int)charCode;

            if (data.Widths.IndexOfKey(charCode) >= 0)
            {
                return(data.Widths[charCode]);
            }
            LogFontFt cfont = data.LogFont;

            cfont.OpenFont();

            int awidth = 0;

            Monitor.Enter(flag);
            try
            {
                if (data.Widths.IndexOfKey(charCode) >= 0)
                {
                    awidth = data.Widths[charCode];
                }
                else
                {
                    if (0 == FT.FT_Load_Char(cfont.iface, (uint)charCode, (int)FT.FT_LOAD_NO_SCALE))
                    {
                        FT_FaceRec      aface  = (FT_FaceRec)Marshal.PtrToStructure(cfont.iface, typeof(FT_FaceRec));
                        FT_GlyphSlotRec aglyph = (FT_GlyphSlotRec)Marshal.PtrToStructure(aface.glyph, typeof(FT_GlyphSlotRec));
                        ushort          width1 = (ushort)(aglyph.linearHoriAdvance >> 16);
                        ushort          width2 = (ushort)(aglyph.linearHoriAdvance & 0x0000FFFF);
                        double          dwidth = width1 + width2 / (double)65535;
                        awidth = System.Convert.ToInt32(Math.Round(cfont.widthmult * dwidth));
                    }
                    data.Widths[charCode] = awidth;
                    data.Glyphs[charCode] = System.Convert.ToInt32(FT.FT_Get_Char_Index(cfont.iface, charCode));
                    if (data.FirstLoaded > aint)
                    {
                        data.FirstLoaded = aint;
                    }
                    if (data.LastLoaded < aint)
                    {
                        data.LastLoaded = aint;
                    }
                }
            }
            finally
            {
                Monitor.Exit(flag);
            }
            return(awidth);
        }
示例#2
0
        public override int GetKerning(PDFFont pdfFont, TTFontData data,
                                       char leftChar, char rightChar)
        {
            LogFontFt cfont = data.LogFont;

            if (!cfont.havekerning)
            {
                return(0);
            }
            int nresult = 0;
            //string nkerning = ""+leftChar+rightChar;
            ulong nkerning = (ulong)((int)leftChar << 32) + (ulong)rightChar;

            if (data.Kernings.IndexOfKey(nkerning) >= 0)
            {
                return(data.Kernings[nkerning]);
            }
            cfont.OpenFont();
            Monitor.Enter(flag);
            try
            {
                if (data.Kernings.IndexOfKey(nkerning) >= 0)
                {
                    nresult = data.Kernings[nkerning];
                }
                uint w1 = FT.FT_Get_Char_Index(cfont.iface, (uint)leftChar);
                if (w1 > 0)
                {
                    uint w2 = FT.FT_Get_Char_Index(cfont.iface, (uint)rightChar);
                    if (w2 > 0)
                    {
                        FT_Vector akerning;
                        CheckFreeType(FT.FT_Get_Kerning(cfont.iface, w1, w2, (uint)FT_Kerning_Flags.FT_KERNING_UNSCALED, out akerning));
                        nresult = System.Convert.ToInt32(Math.Round(cfont.widthmult * -akerning.x));
                    }
                    else
                    {
                        data.Kernings.Add(nkerning, 0);
                    }
                }
                else
                {
                    data.Kernings.Add(nkerning, 0);
                }
            }
            finally
            {
                Monitor.Exit(flag);
            }
            return(nresult);
        }