byte[] bytes; // Instructions. n is the number of BYTE items that fit in the size of the table.

        public FontProgram(OpenTypeFontface fontData)
            : base(fontData, Tag)
        {
            DirectoryEntry.Tag = TableTagNames.Fpgm;
            DirectoryEntry     = fontData.TableDictionary[TableTagNames.Fpgm];
            Read();
        }
        FWord[] array; // List of n values referenceable by instructions. n is the number of FWORD items that fit in the size of the table.

        public ControlValueTable(OpenTypeFontface fontData)
            : base(fontData, Tag)
        {
            DirectoryEntry.Tag = TableTagNames.Cvt;
            DirectoryEntry     = fontData.TableDictionary[TableTagNames.Cvt];
            Read();
        }
Exemple #3
0
 internal OpenTypeDescriptor(string fontDescriptorKey, string idName, byte[] fontData)
     : base(fontDescriptorKey)
 {
     try
     {
         FontFace = new OpenTypeFontface(fontData, idName);
         // Try to get real name form name table
         if (idName.Contains("XPS-Font-") && FontFace.name != null && FontFace.name.Name.Length != 0)
         {
             string tag = String.Empty;
             if (idName.IndexOf('+') == 6)
             {
                 tag = idName.Substring(0, 6);
             }
             idName = tag + "+" + FontFace.name.Name;
             if (FontFace.name.Style.Length != 0)
             {
                 idName += "," + FontFace.name.Style;
             }
             //idName = idName.Replace(" ", "");
         }
         FontName = idName;
         Initialize();
     }
     catch (Exception)
     {
         GetType();
         throw;
     }
 }
Exemple #4
0
 /// <summary>
 /// New...
 /// </summary>
 public OpenTypeDescriptor(string fontDescriptorKey, string name, XFontStyle stlye, OpenTypeFontface fontface, XPdfFontOptions options)
     : base(fontDescriptorKey)
 {
     FontFace = fontface;
     FontName = name;
     Initialize();
 }
Exemple #5
0
 public GlyphSubstitutionTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry.Tag = TableTagNames.GSUB;
     DirectoryEntry = fontData.TableDictionary[TableTagNames.GSUB];
     Read();
 }
 /// <summary>
 /// New...
 /// </summary>
 public OpenTypeDescriptor(string fontDescriptorKey, string name, XFontStyle stlye, OpenTypeFontface fontface, XPdfFontOptions options)
     : base(fontDescriptorKey)
 {
     FontFace = fontface;
     FontName = name;
     Initialize();
 }
 public void Read(OpenTypeFontface fontData)
 {
     Tag      = fontData.ReadTag();
     CheckSum = fontData.ReadULong();
     Offset   = fontData.ReadLong();
     Length   = (int)fontData.ReadULong();
 }
 internal OpenTypeDescriptor(string fontDescriptorKey, string idName, byte[] fontData)
     : base(fontDescriptorKey)
 {
     try
     {
         FontFace = new OpenTypeFontface(fontData, idName);
         // Try to get real name form name table
         if (idName.Contains("XPS-Font-") && FontFace.name != null && FontFace.name.Name.Length != 0)
         {
             string tag = String.Empty;
             if (idName.IndexOf('+') == 6)
                 tag = idName.Substring(0, 6);
             idName = tag + "+" + FontFace.name.Name;
             if (FontFace.name.Style.Length != 0)
                 idName += "," + FontFace.name.Style;
             //idName = idName.Replace(" ", "");
         }
         FontName = idName;
         Initialize();
     }
     catch (Exception)
     {
         GetType();
         throw;
     }
 }
Exemple #9
0
 public OpenTypeFontTable(OpenTypeFontface fontData, string tag)
 {
     _fontData = fontData;
     if (fontData != null && fontData.TableDictionary.ContainsKey(tag))
         DirectoryEntry = fontData.TableDictionary[tag];
     else
         DirectoryEntry = new TableDirectoryEntry(tag);
     DirectoryEntry.FontTable = this;
 }
 /// <summary>
 /// Tries to get fontface by its check sum.
 /// </summary>
 public static bool TryGetFontface(ulong checkSum, out OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         bool result = Singleton._fontfacesByCheckSum.TryGetValue(checkSum, out fontface);
         return(result);
     }
     finally { Lock.ExitFontFactory(); }
 }
 /// <summary>
 /// Tries to get fontface by its key.
 /// </summary>
 public static bool TryGetFontface(string key, out OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         bool result = Singleton._fontfaceCache.TryGetValue(key, out fontface);
         return result;
     }
     finally { Lock.ExitFontFactory(); }
 }
 /// <summary>
 /// Tries to get fontface by its check sum.
 /// </summary>
 public static bool TryGetFontface(ulong checkSum, out OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         bool result = Singleton._fontfacesByCheckSum.TryGetValue(checkSum, out fontface);
         return result;
     }
     finally { Lock.ExitFontFactory(); }
 }
Exemple #13
0
        /// <summary>
        /// Creates and reads a TableDirectoryEntry from the font image.
        /// </summary>
        public static TableDirectoryEntry ReadFrom(OpenTypeFontface fontData)
        {
            TableDirectoryEntry entry = new TableDirectoryEntry();

            entry.Tag      = fontData.ReadTag();
            entry.CheckSum = fontData.ReadULong();
            entry.Offset   = fontData.ReadLong();
            entry.Length   = (int)fontData.ReadULong();
            return(entry);
        }
 /// <summary>
 /// Tries to get fontface by its key.
 /// </summary>
 public static bool TryGetFontface(string key, out OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         bool result = Singleton._fontfaceCache.TryGetValue(key, out fontface);
         return(result);
     }
     finally { Lock.ExitFontFactory(); }
 }
Exemple #15
0
 public OpenTypeFontTable(OpenTypeFontface fontData, string tag)
 {
     _fontData = fontData;
     if (fontData != null && fontData.TableDictionary.ContainsKey(tag))
     {
         DirectoryEntry = fontData.TableDictionary[tag];
     }
     else
     {
         DirectoryEntry = new TableDirectoryEntry(tag);
     }
     DirectoryEntry.FontTable = this;
 }
 public static OpenTypeFontface AddFontface(OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         OpenTypeFontface fontfaceCheck;
         if (TryGetFontface(fontface.FullFaceName, out fontfaceCheck))
         {
             if (fontfaceCheck.CheckSum != fontface.CheckSum)
                 throw new InvalidOperationException("OpenTypeFontface with same signature but different bytes.");
             return fontfaceCheck;
         }
         Singleton._fontfaceCache.Add(fontface.FullFaceName, fontface);
         Singleton._fontfacesByCheckSum.Add(fontface.CheckSum, fontface);
         return fontface;
     }
     finally { Lock.ExitFontFactory(); }
 }
Exemple #17
0
 public static OpenTypeFontface AddFontface(OpenTypeFontface fontface)
 {
     try
     {
         Lock.EnterFontFactory();
         if (TryGetFontface(fontface.FullFaceName, out OpenTypeFontface fontfaceCheck))
         {
             if (fontfaceCheck.CheckSum != fontface.CheckSum)
             {
                 throw new InvalidOperationException("OpenTypeFontface with same signature but different bytes.");
             }
             return(fontfaceCheck);
         }
         Singleton._fontfaceCache.Add(fontface.FullFaceName, fontface);
         Singleton._fontfacesByCheckSum.Add(fontface.CheckSum, fontface);
         return(fontface);
     }
     finally { Lock.ExitFontFactory(); }
 }
Exemple #18
0
        /// <summary>
        /// Caches a font source under its face name and its key.
        /// </summary>
        public static XFontSource CacheNewFontSource(string typefaceKey, XFontSource fontSource)
        {
            // Debug.Assert(!FontSourcesByFaceName.ContainsKey(fontSource.FaceName));

            // Check whether an identical font source with a different face name already exists.
            XFontSource existingFontSource;
            if (FontSourcesByKey.TryGetValue(fontSource.Key, out existingFontSource))
            {
                //// Fonts have same length and check sum. Now check byte by byte identity.
                //int length = fontSource.Bytes.Length;
                //for (int idx = 0; idx < length; idx++)
                //{
                //    if (existingFontSource.Bytes[idx] != fontSource.Bytes[idx])
                //    {
                //        goto FontsAreNotIdentical;
                //    }
                //}
                return existingFontSource;

                ////// The bytes are really identical. Register font source again with the new face name
                ////// but return the existing one to save memory.
                ////FontSourcesByFaceName.Add(fontSource.FaceName, existingFontSource);
                ////return existingFontSource;

                //FontsAreNotIdentical:
                //// Incredible rare case: Two different fonts have the same size and check sum.
                //// Give the new one a new key until it do not clash with an existing one.
                //while (FontSourcesByKey.ContainsKey(fontSource.Key))
                //    fontSource.IncrementKey();
            }

            OpenTypeFontface fontface = fontSource.Fontface;
            if (fontface == null)
            {
                fontface = new OpenTypeFontface(fontSource);
                fontSource.Fontface = fontface;  // Also sets the font name in fontSource
            }

            FontSourcesByName.Add(typefaceKey, fontSource);
            FontSourcesByName.Add(fontSource.FontName, fontSource);
            FontSourcesByKey.Add(fontSource.Key, fontSource);

            return fontSource;
        }
Exemple #19
0
 public PostScriptTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #20
0
 public VerticalHeaderTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #21
0
 public VerticalMetricsTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
     throw new NotImplementedException("VerticalMetricsTable");
 }
Exemple #22
0
        public ushort[] glyphIdArray;    // Glyph index array (arbitrary length)

        public CMap4(OpenTypeFontface fontData, WinEncodingId encodingId)
            : base(fontData, "----")
        {
            this.encodingId = encodingId;
            Read();
        }
Exemple #23
0
 public HorizontalHeaderTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #24
0
 public VerticalHeaderTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #25
0
 public VerticalMetricsTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
     throw new NotImplementedException("VerticalMetricsTable");
 }
Exemple #26
0
        // Implementation Notes
        // OpenTypeFontface represents a 'decompiled' font file in memory.
        //
        // * An OpenTypeFontface can belong to more than one 
        //   XGlyphTypeface because of StyleSimulations.
        //
        // * Currently there is a one to one relationship to XFontSource.
        // 
        // * Consider OpenTypeFontface as an decompiled XFontSource.
        //
        // http://www.microsoft.com/typography/otspec/

        /// <summary>
        /// Shallow copy for font subset.
        /// </summary>
        OpenTypeFontface(OpenTypeFontface fontface)
        {
            _offsetTable = fontface._offsetTable;
            _fullFaceName = fontface._fullFaceName;
        }
Exemple #27
0
 public HorizontalHeaderTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #28
0
 public GlyphSubstitutionTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry.Tag = TableTagNames.GSUB;
     DirectoryEntry = fontData.TableDictionary[TableTagNames.GSUB];
     Read();
 }
Exemple #29
0
 public HorizontalMetricsTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
 public IndexToLocationTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry = _fontData.TableDictionary[TableTagNames.Loca];
     Read();
 }
Exemple #31
0
 public GlyphDataTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry.Tag = TableTagNames.Glyf;
     Read();
 }
Exemple #32
0
        public ushort[] glyphIdArray;     // Glyph index array (arbitrary length)

        public CMap4(OpenTypeFontface fontData, WinEncodingId encodingId)
            : base(fontData, "----")
        {
            this.encodingId = encodingId;
            Read();
        }
Exemple #33
0
 /// <summary>
 /// Creates and reads a TableDirectoryEntry from the font image.
 /// </summary>
 public static TableDirectoryEntry ReadFrom(OpenTypeFontface fontData)
 {
     TableDirectoryEntry entry = new TableDirectoryEntry();
     entry.Tag = fontData.ReadTag();
     entry.CheckSum = fontData.ReadULong();
     entry.Offset = fontData.ReadLong();
     entry.Length = (int)fontData.ReadULong();
     return entry;
 }
 public IndexToLocationTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry = _fontData.TableDictionary[TableTagNames.Loca];
     Read();
 }
Exemple #35
0
 public GlyphDataTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry.Tag = TableTagNames.Glyf;
     Read();
 }
Exemple #36
0
 public HorizontalMetricsTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
        // Implementation Notes
        // OpenTypeFontface represents a 'decompiled' font file in memory.
        //
        // * An OpenTypeFontface can belong to more than one
        //   XGlyphTypeface because of StyleSimulations.
        //
        // * Currently there is a one to one relationship to XFontSource.
        //
        // * Consider OpenTypeFontface as an decompiled XFontSource.
        //
        // http://www.microsoft.com/typography/otspec/

        /// <summary>
        /// Shallow copy for font subset.
        /// </summary>
        OpenTypeFontface(OpenTypeFontface fontface)
        {
            _offsetTable  = fontface._offsetTable;
            _fullFaceName = fontface._fullFaceName;
        }
Exemple #38
0
 public VerticalMetrics(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #39
0
        byte[] bytes; // Set of instructions executed whenever point size or font or transformation change. n is the number of BYTE items that fit in the size of the table.

        public ControlValueProgram(OpenTypeFontface fontData)
            : base(fontData, Tag)
        {
            DirectoryEntry.Tag = TableTagNames.Prep;
            DirectoryEntry = fontData.TableDictionary[TableTagNames.Prep];
            Read();
        }
Exemple #40
0
 public MaximumProfileTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #41
0
 public MaximumProfileTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #42
0
 public OS2Table(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #43
0
 public IRefFontTable(OpenTypeFontface fontData, OpenTypeFontTable fontTable)
     : base(null, fontTable.DirectoryEntry.Tag)
 {
     _fontData = fontData;
     _irefDirectoryEntry = fontTable.DirectoryEntry;
 }
        /// <summary>
        /// Creates a new font image that is a subset of this font image containing only the specified glyphs.
        /// </summary>
        public OpenTypeFontface CreateFontSubSet(Dictionary <int, object> glyphs, bool cidFont)
        {
            // Create new font image
            OpenTypeFontface fontData = new OpenTypeFontface(this);

            // Create new loca and glyf table
            IndexToLocationTable locaNew = new IndexToLocationTable();

            locaNew.ShortIndex = loca.ShortIndex;
            GlyphDataTable glyfNew = new GlyphDataTable();

            // Add all required tables
            //fontData.AddTable(os2);
            if (!cidFont)
            {
                fontData.AddTable(cmap);
            }
            if (cvt != null)
            {
                fontData.AddTable(cvt);
            }
            if (fpgm != null)
            {
                fontData.AddTable(fpgm);
            }
            fontData.AddTable(glyfNew);
            fontData.AddTable(head);
            fontData.AddTable(hhea);
            fontData.AddTable(hmtx);
            fontData.AddTable(locaNew);
            if (maxp != null)
            {
                fontData.AddTable(maxp);
            }
            //fontData.AddTable(name);
            if (prep != null)
            {
                fontData.AddTable(prep);
            }

            // Get closure of used glyphs.
            glyf.CompleteGlyphClosure(glyphs);

            // Create a sorted array of all used glyphs.
            int glyphCount = glyphs.Count;

            int[] glyphArray = new int[glyphCount];
            glyphs.Keys.CopyTo(glyphArray, 0);
            Array.Sort(glyphArray);

            // Calculate new size of glyph table.
            int size = 0;

            for (int idx = 0; idx < glyphCount; idx++)
            {
                size += glyf.GetGlyphSize(glyphArray[idx]);
            }
            glyfNew.DirectoryEntry.Length = size;

            // Create new loca table
            int numGlyphs = maxp.numGlyphs;

            locaNew.LocaTable = new int[numGlyphs + 1];

            // Create new glyf table
            glyfNew.GlyphTable = new byte[glyfNew.DirectoryEntry.PaddedLength];

            // Fill new glyf and loca table
            int glyphOffset = 0;
            int glyphIndex  = 0;

            for (int idx = 0; idx < numGlyphs; idx++)
            {
                locaNew.LocaTable[idx] = glyphOffset;
                if (glyphIndex < glyphCount && glyphArray[glyphIndex] == idx)
                {
                    glyphIndex++;
                    byte[] bytes  = glyf.GetGlyphData(idx);
                    int    length = bytes.Length;
                    if (length > 0)
                    {
                        Buffer.BlockCopy(bytes, 0, glyfNew.GlyphTable, glyphOffset, length);
                        glyphOffset += length;
                    }
                }
            }
            locaNew.LocaTable[numGlyphs] = glyphOffset;

            // Compile font tables into byte array
            fontData.Compile();

            return(fontData);
        }
Exemple #45
0
 public VerticalMetrics(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #46
0
 public PostScriptTable(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #47
0
        byte[] bytes; // Instructions. n is the number of BYTE items that fit in the size of the table.

        public FontProgram(OpenTypeFontface fontData)
            : base(fontData, Tag)
        {
            DirectoryEntry.Tag = TableTagNames.Fpgm;
            DirectoryEntry = fontData.TableDictionary[TableTagNames.Fpgm];
            Read();
        }
Exemple #48
0
 public void Read(OpenTypeFontface fontData)
 {
     Tag = fontData.ReadTag();
     CheckSum = fontData.ReadULong();
     Offset = fontData.ReadLong();
     Length = (int)fontData.ReadULong();
 }
Exemple #49
0
 public OS2Table(OpenTypeFontface fontData)
     : base(fontData, Tag)
 {
     Read();
 }
Exemple #50
0
 public IRefFontTable(OpenTypeFontface fontData, OpenTypeFontTable fontTable)
     : base(null, fontTable.DirectoryEntry.Tag)
 {
     _fontData           = fontData;
     _irefDirectoryEntry = fontTable.DirectoryEntry;
 }
Exemple #51
0
        /// <summary>
        /// Creates a new font image that is a subset of this font image containing only the specified glyphs.
        /// </summary>
        public OpenTypeFontface CreateFontSubSet(Dictionary<int, object> glyphs, bool cidFont)
        {
            // Create new font image
            OpenTypeFontface fontData = new OpenTypeFontface(this);

            // Create new loca and glyf table
            IndexToLocationTable locaNew = new IndexToLocationTable();
            locaNew.ShortIndex = loca.ShortIndex;
            GlyphDataTable glyfNew = new GlyphDataTable();

            // Add all required tables
            //fontData.AddTable(os2);
            if (!cidFont)
                fontData.AddTable(cmap);
            if (cvt != null)
                fontData.AddTable(cvt);
            if (fpgm != null)
                fontData.AddTable(fpgm);
            fontData.AddTable(glyfNew);
            fontData.AddTable(head);
            fontData.AddTable(hhea);
            fontData.AddTable(hmtx);
            fontData.AddTable(locaNew);
            if (maxp != null)
                fontData.AddTable(maxp);
            //fontData.AddTable(name);
            if (prep != null)
                fontData.AddTable(prep);

            // Get closure of used glyphs.
            glyf.CompleteGlyphClosure(glyphs);

            // Create a sorted array of all used glyphs.
            int glyphCount = glyphs.Count;
            int[] glyphArray = new int[glyphCount];
            glyphs.Keys.CopyTo(glyphArray, 0);
            Array.Sort(glyphArray);

            // Calculate new size of glyph table.
            int size = 0;
            for (int idx = 0; idx < glyphCount; idx++)
                size += glyf.GetGlyphSize(glyphArray[idx]);
            glyfNew.DirectoryEntry.Length = size;

            // Create new loca table
            int numGlyphs = maxp.numGlyphs;
            locaNew.LocaTable = new int[numGlyphs + 1];

            // Create new glyf table
            glyfNew.GlyphTable = new byte[glyfNew.DirectoryEntry.PaddedLength];

            // Fill new glyf and loca table
            int glyphOffset = 0;
            int glyphIndex = 0;
            for (int idx = 0; idx < numGlyphs; idx++)
            {
                locaNew.LocaTable[idx] = glyphOffset;
                if (glyphIndex < glyphCount && glyphArray[glyphIndex] == idx)
                {
                    glyphIndex++;
                    byte[] bytes = glyf.GetGlyphData(idx);
                    int length = bytes.Length;
                    if (length > 0)
                    {
                        Buffer.BlockCopy(bytes, 0, glyfNew.GlyphTable, glyphOffset, length);
                        glyphOffset += length;
                    }
                }
            }
            locaNew.LocaTable[numGlyphs] = glyphOffset;

            // Compile font tables into byte array
            fontData.Compile();

            return fontData;
        }