Example #1
0
        public static float MeasureString(int[] b, int[] GlyphWidths, TKerningTable Kern, float UnitsPerEm, bool[] Ignore)
        {
            float Result = 0;

            if (b.Length <= 0)
            {
                return(Result);
            }

            int si1 = b[0];

            if (!Ignore[0])
            {
                Result += GlyphWidth(si1, GlyphWidths) * 1000 / UnitsPerEm;
            }

            for (int i = 1; i < b.Length; i++)
            {
                int    si  = b[i];
                float  k   = 0;
                UInt32 key = MakeHash(si1, si);
                if (Kern != null && Kern.ContainsKey(key))
                {
                    k = Kern[key] * 1000 / UnitsPerEm;
                }
                if (!Ignore[i])
                {
                    Result += GlyphWidth(si, GlyphWidths) * 1000 / UnitsPerEm + k;
                }
                si1 = si;
            }

            return(Result);
        }
Example #2
0
        public static TKernedString[] KernString(string Text, int[] b, TKerningTable Kern, float UnitsPerEm)
        {
            if (b.Length <= 0)
            {
                return(new TKernedString[0]);
            }

            List <TKernedString> Result = new List <TKernedString>();

            int LastPos = 0;
            int pos     = 1;
            int LastK   = 0;

            while (pos < b.Length)
            {
                UInt32 key = MakeHash(b[pos], b[pos - 1]);
                if (Kern != null && Kern.ContainsKey(key))
                {
                    Result.Add(new TKernedString(LastK, Text.Substring(LastPos, pos - LastPos)));
                    LastK   = (int)Math.Round(Kern[key] * 1000 / UnitsPerEm);
                    LastPos = pos;
                }
                pos++;
            }

            if (LastPos < b.Length)
            {
                Result.Add(new TKernedString(LastK, Text.Substring(LastPos, b.Length - LastPos)));
            }

            return(Result.ToArray());
        }
Example #3
0
        public TPdfInternalFont(Font aFont, int aId, bool aUseKerning, TPdfResources aResources) : base(aFont, aId, aUseKerning, aResources)
        {
            //LOGFONT lf = new LOGFONT();  This does not work, and it is unmanaged also!

            string FontName = ";" + aFont.Name.Replace(" ", String.Empty).ToUpper(CultureInfo.InvariantCulture) + ";";

            if (TPdfTokens.GetString(TPdfToken.StSymbolFonts).IndexOf(FontName) >= 0)
            {
                FFontName = TPdfTokens.GetString(TPdfToken.PsSymbol);
                FFontType = TFontType.Symbol;
            }
            else
            if (TPdfTokens.GetString(TPdfToken.StSerifFonts).IndexOf(FontName) >= 0)
            {
                FFontName = TPdfTokens.GetString(TPdfToken.PsTimes);
                FFontType = TFontType.Times;
            }
            else
            if (TPdfTokens.GetString(TPdfToken.StFixedFonts).IndexOf(FontName) >= 0)
            {
                FFontName = TPdfTokens.GetString(TPdfToken.PsCourier);
                FFontType = TFontType.Courier;
            }
            else
            {
                FFontName = TPdfTokens.GetString(TPdfToken.PsHelvetica);
                FFontType = TFontType.Helvetica;
            }

            Width = TInternalFontMetrics.Width(FFontType, FFontStyle);
            if (FUseKerning)
            {
                Kern = TInternalFontMetrics.Kern(FFontType, FFontStyle);
            }
        }