Example #1
0
        public static GlyphPath Load(uint gid, FontModel fontModel, byte[] fontSource)
        {
            var cff = new CffCharString();

            if (fontModel.IsCidFont)
            {
                var fdIndex = fontModel.TopDict.FDSelect[gid];
                var fdDict  = fontModel.TopDict.FDArray[fdIndex];
                cff._lsubrs       = fdDict.Subrs;
                cff._lsubrsBias   = cff._lsubrs == null ? 0 : CompactFontFormatTable.GetSubrBias(cff._lsubrs.Length);
                cff._width        = fdDict.DefaultWidthX;
                cff._normalWidthX = fdDict.NormalWidthX;
            }
            else
            {
                cff._lsubrs       = fontModel.TopDict.Subrs;
                cff._lsubrsBias   = cff._lsubrs == null ? 0 : CompactFontFormatTable.GetSubrBias(cff._lsubrs.Length);
                cff._width        = fontModel.TopDict.DefaultWidthX;
                cff._normalWidthX = fontModel.TopDict.NormalWidthX;
            }

            cff._gsubrs = fontModel.GSubrs;

            if (cff._gsubrs != null)
            {
                cff._gsubrsBias = CompactFontFormatTable.GetSubrBias(cff._gsubrs.Length);
            }

            var seg = fontModel.GetCharString(gid);

            cff.Load(seg, fontSource);
            fontModel._glyphs[gid] = new GlyphInfo((ushort)cff._width, fontModel._glyphs[gid].LeftSideBearing);

            return(cff._path);
        }
Example #2
0
        public static TopDict LoadTopDict(byte[] data, uint offset, uint count, ByteSegment[] stringIndex)
        {
            var values = new List <decimal>();

            var d = new TopDict();

            var i = offset;

            while (i < offset + count)
            {
                var b0 = data[i++];

                if (ParseValue(b0, data, ref i, values))
                {
                    continue;
                }

                if (b0 == 12)
                {
                    // Key
                    var b1 = data[i++];
                    if (b0 == 12)
                    {
                        if (b1 == 0)
                        {
                            d.Copyright = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                        }
                        else if (b1 == 1)
                        {
                            d.IsFixedPitch = values[0] != 0;
                        }
                        else if (b1 == 2)
                        {
                            d.ItalicAngle = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 3)
                        {
                            d.UnderlinePosition = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 4)
                        {
                            d.UnderlineThickness = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 5)
                        {
                            d.PaintType = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 6)
                        {
                            d.CharStringType = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 7)
                        {
                            d.FontMatrix = values.Select(decimal.ToSingle).ToArray();
                        }
                        else if (b1 == 8)
                        {
                            d.StrokeWidth = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 12)
                        {
                            d.StemSnapH = (int)values[0];
                        }
                        else if (b1 == 13)
                        {
                            d.StemSnapV = (int)values[0];
                        }
                        else if (b1 == 14)
                        {
                            d.ForceBold = values[0] != 0;
                        }
                        else if (b1 == 17)
                        {
                            d.LanguageGroup = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 18)
                        {
                            d.ExpansionFactor = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 19)
                        {
                            d.InitialRoundSeed = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 20)
                        {
                            d.SyntheticBase = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 21)
                        {
                            d.PostScript = (int)values[0];
                        }
                        else if (b1 == 22)
                        {
                            d.BaseFontName = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                        }
                        else if (b1 == 23)
                        {
                            d.BaseFontBlend = values.Select(decimal.ToInt32).ToArray();
                        }
                        else if (b1 == 30)
                        {
                            d.ROS = (
                                CompactFontFormatTable.GetString((int)values[0], stringIndex, data),
                                CompactFontFormatTable.GetString((int)values[1], stringIndex, data),
                                (int)values[2]);
                        }
                        else if (b1 == 31)
                        {
                            d.CIDFontVersion = values[0].ToString();
                        }
                        else if (b1 == 32)
                        {
                            d.CIDFontRevision = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 33)
                        {
                            d.CIDFontType = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 34)
                        {
                            d.CIDCount = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 35)
                        {
                            d.UIDBase = decimal.ToInt32(values[0]);
                        }
                        else if (b1 == 36)
                        {
                            d.FDArrayIndex = (uint)values[0];
                        }
                        else if (b1 == 37)
                        {
                            d.FDSelectIndex = (uint)values[0];
                        }
                        else if (b1 == 38)
                        {
                            d.FontName = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                        }
                    }

                    values.Clear();
                }
                else if (b0 <= 21)
                {
                    // Key
                    if (b0 == 0)
                    {
                        d.Version = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                    }
                    if (b0 == 1)
                    {
                        d.Notice = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                    }
                    if (b0 == 2)
                    {
                        d.FullName = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                    }
                    if (b0 == 3)
                    {
                        d.FamilyName = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                    }
                    if (b0 == 4)
                    {
                        d.Weight = CompactFontFormatTable.GetString((int)values[0], stringIndex, data);
                    }
                    if (b0 == 5)
                    {
                        d.FontBBox = values.Select(decimal.ToSingle).ToArray();
                    }
                    if (b0 == 6)
                    {
                        d.BlueValues = values.Select(decimal.ToInt32).ToArray();
                    }
                    if (b0 == 7)
                    {
                        d.OtherBlues = values.Select(decimal.ToInt32).ToArray();
                    }
                    if (b0 == 8)
                    {
                        d.FamilyBlues = values.Select(decimal.ToInt32).ToArray();
                    }
                    if (b0 == 9)
                    {
                        d.FamilyOtherBlues = values.Select(decimal.ToInt32).ToArray();
                    }
                    if (b0 == 10)
                    {
                        d.StdHW = decimal.ToInt32(values[0]);
                    }
                    if (b0 == 11)
                    {
                        d.StdVW = decimal.ToInt32(values[0]);
                    }
                    if (b0 == 13)
                    {
                        d.UniqueId = decimal.ToInt32(values[0]);
                    }
                    if (b0 == 14)
                    {
                        d.XUID = values.Select(decimal.ToInt32).ToArray();
                    }
                    if (b0 == 15)
                    {
                        d.Charset = (uint)values[0];
                    }
                    if (b0 == 16)
                    {
                        d.Encoding = (uint)values[0];
                    }
                    if (b0 == 17)
                    {
                        d.CharStrings = (uint)values[0];
                    }
                    if (b0 == 18)
                    {
                        d.Private = values.Select(decimal.ToUInt32).ToArray();
                    }

                    values.Clear();
                }
                else
                {
                    throw new FontException(string.Format("Invalid data: {0}(0x{0:X2})", b0));
                }
            }

            return(d);
        }