Ejemplo n.º 1
0
        public Table_vmtx(OTTag tag, MBOBuffer buf, Table_vhea vheaTable, ushort nGlyphsInTheFont) : base(tag, buf)
        {
            m_vheaTable        = vheaTable;
            m_nGlyphsInTheFont = nGlyphsInTheFont;

            Debug.Assert(m_vheaTable != null);

            m_nLongVerMetrics = m_vheaTable.numOfLongVerMetrics;
        }
Ejemplo n.º 2
0
        public Table_hmtx(OTTag tag, MBOBuffer buf, Table_hhea hheaTable, ushort nGlyphsInTheFont) : base(tag, buf)
        {
            m_hheaTable = hheaTable;
            m_nGlyphsInTheFont = nGlyphsInTheFont;

            Debug.Assert(m_hheaTable != null);

            m_nNumberOfHMetrics = m_hheaTable.numberOfHMetrics;            
        }
Ejemplo n.º 3
0
        public Table_hmtx(OTTag tag, MBOBuffer buf, Table_hhea hheaTable, ushort nGlyphsInTheFont) : base(tag, buf)
        {
            m_hheaTable        = hheaTable;
            m_nGlyphsInTheFont = nGlyphsInTheFont;

            Debug.Assert(m_hheaTable != null);

            m_nNumberOfHMetrics = m_hheaTable.numberOfHMetrics;
        }
Ejemplo n.º 4
0
        public Table_vmtx(OTTag tag, MBOBuffer buf, Table_vhea vheaTable, ushort nGlyphsInTheFont) : base(tag, buf)
        {
            m_vheaTable = vheaTable;
            m_nGlyphsInTheFont = nGlyphsInTheFont;

            Debug.Assert(m_vheaTable != null);

            m_nLongVerMetrics = m_vheaTable.numOfLongVerMetrics;            
        }
Ejemplo n.º 5
0
 public void SetTag(OTTag tag, uint offset)
 {
     byte [] buf = tag.GetBytes();
     for (int i = 0; i < 4; i++)
     {
         m_buf[offset + i] = buf[i];
     }
     m_bValidChecksumAvailable = false;
 }
Ejemplo n.º 6
0
        /*
         *        CONSTRUCTORS
         */
    /*
        public ValidationInfo(ValInfoType VIType, string StringName, OTTag tag, string stringTestName):
            base(VIType, StringName, null, "OTFontFile.ValStrings", "OTFontFile", tag, stringTestName)
        {
        }
    */

        /// <summary>Hardwires <c>OTFontFileVal.ValStrings</c> as
        /// the <c>nameFileErrs</c> and <c>OTFontFileVal</c> as
        /// the <c>nameAsmFileErrs</c> in the underlying
        /// <c>ValInfoBasic</c>.
        /// </summary>
        public ValidationInfo( ValInfoType VIType, 
                               string StringName, 
                               OTTag tag, 
                               string StringDetails, 
                               string stringTestName):
            base(VIType, StringName, StringDetails, 
                 "OTFontFileVal.ValStrings", "OTFontFileVal", 
                 tag, stringTestName)
        {
        }
Ejemplo n.º 7
0
 /// <summary>Does not appear to be called.</summary>
 public ValidationInfo(ValInfoType type, 
                       string stringName,
                       string stringValueUser,
                       string nameFileErrs,
                       string nameAsmFileErrs,
                       OTTag tagPrincipal,
                       string stringTestName):
     base(type,stringName,stringValueUser,nameFileErrs,
          nameAsmFileErrs,tagPrincipal, stringTestName)
 {
 }
Ejemplo n.º 8
0
 public DirectoryEntry(DirectoryEntry obj)
 {
     if (m_buf == null)
     {
         m_buf = new MBOBuffer(16);
     }
     tag      = new OTTag(obj.tag.GetBytes());
     checkSum = obj.checkSum;
     offset   = obj.offset;
     length   = obj.length;
 }
Ejemplo n.º 9
0
            public OTTag GetBaselineTag(uint i)
            {
                OTTag tag = null;

                if (i < BaseTagCount)
                {
                    tag = m_bufTable.GetTag(m_offsetBaseTagListTable + (uint)FieldOffsets.BaselineTagArray + i * 4);
                }

                return(tag);
            }
Ejemplo n.º 10
0
        //protected OTTag m_OTTagRelated;

        // constructors
        public ValInfoBasic()
        {
            this.m_Type=ValInfoType.Info;
            this.m_StringName=null;
            this.m_StringValueName=null;
            this.m_StringValueUser=null;
            this.m_NameFileErrs=null;
            this.m_NameAsmFileErrs=null;
            this.m_OTTagPrincipal=null;
            this.m_StringTestName=null;
            //this.m_OTTagRelated=null;
        }
Ejemplo n.º 11
0
 public ValInfoBasic(ValInfoBasic viBasic) 
 {
     Debug.Assert(viBasic!=null);
     this.m_Type=viBasic.TypeBasic;
     this.m_StringName=viBasic.Name;
     this.m_StringValueName=null;
     this.m_StringValueUser=viBasic.ValueUser;
     this.m_NameFileErrs=viBasic.NameFileErrs;
     this.m_NameAsmFileErrs=viBasic.NameAsmFileErrs;
     this.m_OTTagPrincipal=viBasic.TagPrincipal;
     this.m_StringTestName=viBasic.m_StringTestName;
     //this.m_OTTagRelated=viBasic.TagRelated;
 }
Ejemplo n.º 12
0
        /// <summary>Rmove a table to an non-file based table. Throws
        /// exception if table is not in font.
        /// </summary>
        public void RemoveTable(OTTag tag)
        {
            if (m_File != null)
            {
                throw new ApplicationException("attempted to remove a table from a file-based OTFont object");
            }

            if (GetDirectoryEntry(tag) == null)
            {
                throw new ArgumentException("the specified table doesn't doesn't exist in the font");
            }


            // remove the directory entry

            for (int i = 0; i < m_OffsetTable.DirectoryEntries.Count; i++)
            {
                DirectoryEntry de = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                if (tag == de.tag)
                {
                    m_OffsetTable.DirectoryEntries.RemoveAt(i);
                    m_OffsetTable.numTables--;
                    break;
                }
            }


            // remove the table from the list of tables in memory

            for (int i = 0; i < MemBasedTables.Count; i++)
            {
                OTTable t = (OTTable)MemBasedTables[i];
                if (tag == t.m_tag)
                {
                    MemBasedTables.RemoveAt(i);
                    break;
                }
            }

            string sTable = (string)tag;

            if (sTable == "CFF ")
            {
                m_OutlineType = OutlineType.OUTLINE_INVALID;
            }
            else if (sTable == "glyf")
            {
                m_OutlineType = OutlineType.OUTLINE_INVALID;
            }
        }
Ejemplo n.º 13
0
        /// <summary>Return the first table with tag == <c>tag</c>
        /// or null if there is no such table.
        /// </summary>
        public OTTable GetTable(OTTag tag)
        {
            OTTable table = null;

            // find the directory entry in this font that matches the tag
            DirectoryEntry de = GetDirectoryEntry(tag);

            if (de != null)
            {
                table = GetTable(de);
            }

            return(table);
        }
        /************************
         * public methods
         */

        public override OTTable CreateTableObject(OTTag tag, MBOBuffer buf)
        {
            OTTable table = null;

            string sName = GetUnaliasedTableName(tag);

            switch (sName)
            {
                case "BASE": table = new val_BASE(tag, buf); break;
                case "CFF ": table = new val_CFF(tag, buf); break;
                case "cmap": table = new val_cmap(tag, buf); break;
                case "cvt ": table = new val_cvt(tag, buf); break;
                case "DSIG": table = new val_DSIG(tag, buf); break;
                case "EBDT": table = new val_EBDT(tag, buf); break;
                case "EBLC": table = new val_EBLC(tag, buf); break;
                case "EBSC": table = new val_EBSC(tag, buf); break;
                case "fpgm": table = new val_fpgm(tag, buf); break;
                case "gasp": table = new val_gasp(tag, buf); break;
                case "GDEF": table = new val_GDEF(tag, buf); break;
                case "glyf": table = new val_glyf(tag, buf); break;
                case "GPOS": table = new val_GPOS(tag, buf); break;
                case "GSUB": table = new val_GSUB(tag, buf); break;
                case "hdmx": table = new val_hdmx(tag, buf); break;
                case "head": table = new val_head(tag, buf); break;
                case "hhea": table = new val_hhea(tag, buf); break;
                case "hmtx": table = new val_hmtx(tag, buf); break;
                case "JSTF": table = new val_JSTF(tag, buf); break;
                case "kern": table = new val_kern(tag, buf); break;
                case "loca": table = new val_loca(tag, buf); break;
                case "LTSH": table = new val_LTSH(tag, buf); break;
                case "maxp": table = new val_maxp(tag, buf); break;
                case "name": table = new val_name(tag, buf); break;
                case "OS/2": table = new val_OS2(tag, buf); break;
                case "PCLT": table = new val_PCLT(tag, buf); break;
                case "post": table = new val_post(tag, buf); break;
                case "prep": table = new val_prep(tag, buf); break;
                case "SVG ": table = new val_SVG(tag, buf); break;
                case "VDMX": table = new val_VDMX(tag, buf); break;
                case "vhea": table = new val_vhea(tag, buf); break;
                case "vmtx": table = new val_vmtx(tag, buf); break;
                case "VORG": table = new val_VORG(tag, buf); break;
                //case "Zapf": table = new val_Zapf(tag, buf); break;

                default: table = new val__Unknown(tag, buf); break;
            }

            return table;
        }
Ejemplo n.º 15
0
        /// <summary>Return <c>true</c> iff table has not been deselected
        /// and user has not cancelled.
        /// </summary>
        public bool TestTable(OTTag tagTable)
        {
            bool bTest = true;  // if the table hasn't been deselected, then it will default to getting tested

            if (m_hashTestsToPerform.ContainsKey((string)tagTable))
            {
                bTest = (bool)m_hashTestsToPerform[(string)tagTable];
            }

            if (CancelFlag)
            {
                bTest = false;
            }

            return bTest;
        }
Ejemplo n.º 16
0
        public static bool IsKnownOTTableType(OTTag tag)
        {
            bool bFound = false;

            string [] sTables = GetKnownOTTableTypes();
            for (uint i=0; i<sTables.Length; i++)
            {
                if (sTables[i] == (string)tag)
                {
                    bFound = true;
                    break;
                }
            }

            return bFound;
        }
Ejemplo n.º 17
0
        public string GetUnaliasedTableName(OTTag tag)
        {
            if (tag == null) return "";

            string sName = tag;
            if (sName == "bloc")
            {
                sName = "EBLC";
            }
            else if (sName == "bdat")
            {
                sName = "EBDT";
            }
            
            return sName;
        }
Ejemplo n.º 18
0
        static public bool IsKnownOTTableType(OTTag tag)
        {
            bool bFound = false;

            string [] sTables = GetKnownOTTableTypes();
            for (uint i = 0; i < sTables.Length; i++)
            {
                if (sTables[i] == (string)tag)
                {
                    bFound = true;
                    break;
                }
            }

            return(bFound);
        }
Ejemplo n.º 19
0
        /// <summary>Check magic bytes at beginning of file</summary>
        public static bool IsValidSfntVersion(uint sfnt)
        {
            bool bRet = false;

            OTTag tag = sfnt;

            if (tag == 0x00010000 ||     // from MS OpenType spec
                (string)tag == "OTTO" || // from MS OpenType spec
                (string)tag == "true" || // from Apple TrueType Reference
                (string)tag == "typ1")   // from Apple TrueType Reference
            {
                bRet = true;
            }

            return(bRet);
        }
Ejemplo n.º 20
0
 public ValInfoBasic(ValInfoType type, 
     string stringName,
     string stringValueUser,
     string nameFileErrs,
     string nameAsmFileErrs,
     OTTag tagPrincipal,
     string stringTestName)
 {
     this.m_Type=type;
     this.m_StringName=stringName;
     this.m_StringValueName=null;
     this.m_StringValueUser=stringValueUser;
     this.m_NameFileErrs=nameFileErrs;
     this.m_NameAsmFileErrs=nameAsmFileErrs;
     this.m_OTTagPrincipal=tagPrincipal;
     this.m_StringTestName=stringTestName;
     //this.m_OTTagRelated=tagRelated;
 }
Ejemplo n.º 21
0
        public string GetUnaliasedTableName(OTTag tag)
        {
            if (tag == null)
            {
                return("");
            }

            string sName = tag;

            if (sName == "bloc")
            {
                sName = "EBLC";
            }
            else if (sName == "bdat")
            {
                sName = "EBDT";
            }

            return(sName);
        }
Ejemplo n.º 22
0
        /// <summary>Return the first directory entry with
        /// tag == <c>tag</c>
        /// or null if there is no such entry.
        /// </summary>
        public DirectoryEntry GetDirectoryEntry(OTTag tag)
        {
            Debug.Assert(m_OffsetTable != null);

            DirectoryEntry de = null;

            if (m_OffsetTable != null)
            {
                for (int i = 0; i < m_OffsetTable.DirectoryEntries.Count; i++)
                {
                    DirectoryEntry temp = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                    if (temp.tag == tag)
                    {
                        de = temp;
                        break;
                    }
                }
            }

            return(de);
        }
Ejemplo n.º 23
0
        /// <summary>Return the first directory entry with
        /// tag == <c>tag</c>
        /// or null if there is no such entry.
        /// </summary>
        public DirectoryEntry GetDirectoryEntry(OTTag tag)
        {
            Debug.Assert(m_OffsetTable != null);

            DirectoryEntry de = null;

            if (m_OffsetTable != null)
            {
                for (int i = 0; i < m_OffsetTable.DirectoryEntries.Count; i++)
                {
                    DirectoryEntry temp = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                    if (temp.tag == tag)
                    {
                        de = temp;
                        break;
                    }
                }

                // Try aliases after direct match
                if (de == null)
                {
                    for (int i = 0; i < m_OffsetTable.DirectoryEntries.Count; i++)
                    {
                        DirectoryEntry temp = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                        if (((temp.tag == "bloc" || temp.tag == "CBLC") && tag == "EBLC") ||
                            ((temp.tag == "bdat" || temp.tag == "CBDT") && tag == "EBDT"))
                        {
                            de = temp;
                            break;
                        }
                    }
                }
            }

            return(de);
        }
Ejemplo n.º 24
0
        /************************
         * public static methods
         */
        public static TTCHeader ReadTTCHeader(OTFile file)
        {
            TTCHeader ttc = null;

            const int SIZEOF_FIRSTTHREEFIELDS = 12;
            const int SIZEOF_UINT             = 4;

            // read the first three fields of the TTC Header
            // starting at the beginning of the file

            MBOBuffer buf = file.ReadPaddedBuffer(0, SIZEOF_FIRSTTHREEFIELDS);

            OTTag tag            = null;
            uint  version        = 0;
            uint  DirectoryCount = 0;

            if (buf != null)
            {
                tag            = new OTTag(buf.GetBuffer());
                version        = buf.GetUint(4);
                DirectoryCount = buf.GetUint(8);
            }


            // if the tag and the version and the dir count seem correct then
            // allocate a TTCHeader object and try to read the rest of the header
            if ((string)tag == "ttcf" &&
                (version == 0x00010000 || version == 0x00020000) &&
                12 + DirectoryCount * SIZEOF_UINT < file.GetFileLength())
            {
                ttc                = new TTCHeader();
                ttc.TTCTag         = tag;
                ttc.version        = version;
                ttc.DirectoryCount = DirectoryCount;

                // Directory offsets
                buf = file.ReadPaddedBuffer(SIZEOF_FIRSTTHREEFIELDS, DirectoryCount * SIZEOF_UINT);
                if (buf != null)
                {
                    for (uint i = 0; i < ttc.DirectoryCount; i++)
                    {
                        uint offset = buf.GetUint(i * SIZEOF_UINT);
                        ttc.DirectoryOffsets.Add(offset);
                    }
                }

                // only read Dsig fields if version 2.0 and last buffer was successfully read
                if ((version == 0x00010000 || version == 0x00020000) && buf != null)
                {
                    uint filepos = SIZEOF_FIRSTTHREEFIELDS + DirectoryCount * SIZEOF_UINT;
                    buf = file.ReadPaddedBuffer(filepos, 3 * SIZEOF_UINT);
                    if (buf != null)
                    {
                        // DsigTag
                        ttc.DsigTag = new OTTag(buf.GetBuffer());
                        if ((version == 0x00010000) && ((string)ttc.DsigTag != "DSIG"))
                        {
                            // failed v1 trial - reset & bail
                            ttc.DsigTag = null;
                            return(ttc);
                        }

                        // DsigLength
                        ttc.DsigLength = buf.GetUint(4);

                        // DsigOffset
                        ttc.DsigOffset = buf.GetUint(8);
                    }
                }
            }

            return(ttc);
        }
Ejemplo n.º 25
0
        public bool IsKnownFeatureTag(OTTag tag)
        {
            string [] sTags = 
            {
                "aalt", // Access All Alternates"
                "abvf", // Above-base Forms"
                "abvm", // Above-base Mark Positioning"
                "abvs", // Above-base Substitutions"
                "afrc", // Alternative Fractions"
                "akhn", // Akhands"
                "blwf", // Below-base Forms"
                "blwm", // Below-base Mark Positioning"
                "blws", // Below-base Substitutions"
                "c2pc", // Petite Capitals From Capitals"
                "c2sc", // Small Capitals From Capitals"
                "calt", // Connection Forms"
                "case", // Case-Sensitive Forms"
                "ccmp", // Glyph Composition/Decomposition"
                "clig", // Contextual Ligatures"
                "cpsp", // Capital Spacing"
                "cswh", // Contextual Swash"
                "curs", // Cursive Positioning"
                "dflt", // Default Processing"
                "dist", // Distances"
                "dlig", // Discretionary Ligatures"
                "dnom", // Denominators"
                "dpng", // Diphthongs"
                "expt", // Expert Forms"
                "falt", // Final glyph Alternates"
                "fina", // Terminal Forms"
                "fin2", // Terminal Forms #2"
                "fin3", // Terminal Forms #3"
                "frac", // Fractions"
                "fwid", // Full Width"
                "half", // Half Forms"
                "haln", // Halant Forms"
                "halt", // Alternate Half Width"
                "hist", // Historical Forms"
                "hkna", // Horizontal Kana Alternates"
                "hlig", // Historical Ligatures"
                "hngl", // Hangul"
                "hwid", // Half Width"
                "init", // Initial Forms"
                "isol", // Isolated Forms"
                "ital", // Italics"
                "jajp", // Japanese Forms"
                "jalt", // Justification Alternatives"
                "jp78", // JIS78 Forms"
                "jp83", // JIS83 Forms"
                "jp90", // JIS90 Forms"
                "kern", // Kerning"
                "lfbd", // Left Bounds"
                "liga", // Standard Ligatures"
                "ljmo", // Leading Jamo Forms"
                "lnum", // Lining Figures"
                "locl", // Localized Forms"
                "mark", // Mark Positioning"
                "medi", // Medial Forms"
                "med2", // Medial Forms #2"
                "mgrk", // Mathematical Greek"
                "mkmk", // Mark to Mark Positioning"
                "mset", // Mark Positioning via Substitution"
                "nalt", // Alternate Annotation Forms"
                "nukt", // Nukta Forms"
                "numr", // Numerators"
                "onum", // Old Style Figures"
                "opbd", // Optical Bounds"
                "ordn", // Ordinals"
                "ornm", // Ornaments"
                "palt", // Proportional Alternate Width"
                "pcap", // Petite Capitals"
                "pnum", // Proportional Figures"
                "pref", // Pre-base Forms"
                "pres", // Pre-base Substitutions"
                "pstf", // Post-base Forms"
                "psts", // Post-base Substitutions"
                "pwid", // Proportional Widths"
                "qwid", // Quarter Widths"
                "rand", // Randomize"
                "rlig", // Required Ligatures"
                "rphf", // Reph Form"
                "rtbd", // Right Bounds"
                "rtbd", // Right-to-left Alternates"
                "ruby", // Ruby Notation Forms"
                "salt", // Stylistic Alternates"
                "sinf", // Scientific Inferiors"
                "size", // Optical Size"
                "smcp", // Small Capitals"
                "smpl", // Simplified Forms"
                "subs", // Subscript"
                "sups", // Superscript"
                "swsh", // Swash"
                "titl", // Titling"
                "tjmo", // Trailing Jamo Forms"
                "tnam", // Traditional Name Forms"
                "tnum", // Tabular Figures"
                "trad", // Traditional Forms"
                "twid", // Third Widths"
                "unic", // Unicase"
                "valt", // Alternate Vertical Metrics"
                "vatu", // Vattu Variants"
                "vert", // Vertical Writing"
                "vhal", // Alternate Vertical Half Metrics"
                "vjmo", // Vowel Jamo Forms"
                "vkna", // Vertical Kana Alternates"
                "vkrn", // Vertical Kerning"
                "vpal", // Proportional Alternate Vertical Metrics"
                "vrt2", // Vertical Rotation"
                "zero", // Slashed Zero"
            };

            for (uint i=0; i<sTags.Length; i++)
            {
                if ((string)tag == sTags[i])
                    return true;
            }

            return false;
        }
Ejemplo n.º 26
0
 /************************
  * constructors
  */
 
 
 /// <summary>Just pass data to base class</summary>
 public Table_cmap(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 27
0
 public Table_glyf(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 28
0
        /// <summary>Write a single OTF to a disk file, with tables in
        /// proper order, checksums set, etc.
        /// </summary>
        public static bool WriteSfntFile(FileStream fs, OTFont font)
        {
            bool bRet = true;


            OTFixed     sfntVersion = new OTFixed(1, 0);
            ushort      numTables   = font.GetNumTables();
            OffsetTable ot          = new OffsetTable(sfntVersion, numTables);


            // order tables in fastfont order

            string [] arrOrderedNames = null;
            string [] ttNames         =
            {
                "head", "hhea", "maxp", "OS/2", "hmtx", "LTSH", "VDMX", "hdmx", "cmap", "fpgm",
                "prep", "cvt ", "loca", "glyf", "kern", "name", "post", "gasp", "PCLT"
            };
            string [] psNames =
            {
                "head", "hhea", "maxp", "OS/2", "name", "cmap", "post", "CFF "
            };

            if (font.ContainsTrueTypeOutlines())
            {
                arrOrderedNames = ttNames;
            }
            else if (font.ContainsPostScriptOutlines())
            {
                arrOrderedNames = psNames;
            }

            OTTable[] OrderedTables = new OTTable[numTables];
            for (ushort i = 0; i < numTables; i++)
            {
                OrderedTables[i] = font.GetTable(i);
            }

            if (arrOrderedNames != null)
            {
                ushort curpos = 0;
                for (int iName = 0; iName < arrOrderedNames.Length; iName++)
                {
                    for (ushort i = curpos; i < numTables; i++)
                    {
                        if (arrOrderedNames[iName] == (string)OrderedTables[i].m_tag)
                        {
                            OTTable temp = OrderedTables[curpos];
                            OrderedTables[curpos] = OrderedTables[i];
                            OrderedTables[i]      = temp;
                            curpos++;
                            break;
                        }
                    }
                }
            }


            // update the modified date in the head table

            for (int i = 0; i < OrderedTables.Length; i++)
            {
                if ((string)OrderedTables[i].m_tag == "head")
                {
                    // get the cache
                    Table_head            headTable = (Table_head)OrderedTables[i];
                    Table_head.head_cache headCache = (Table_head.head_cache)headTable.GetCache();

                    // set the 'modified' field to the current date and time
                    DateTime dt = DateTime.Now;
                    headCache.modified = headTable.DateTimeToSecondsSince1904(dt);

                    // generate a new table and replace the head table in the list of ordered tables
                    Table_head newHead = (Table_head)headCache.GenerateTable();
                    OrderedTables[i] = newHead;

                    break;
                }
            }


            // build a list of directory entries

            long TableFilePos = 12 + numTables * 16;

            for (ushort i = 0; i < numTables; i++)
            {
                OTTable table = OrderedTables[i];
                OTTag   tag   = table.m_tag;

                // build a new directory entry
                DirectoryEntry de = new DirectoryEntry();
                de.tag      = new OTTag(tag.GetBytes());
                de.checkSum = table.CalcChecksum();
                de.offset   = (uint)TableFilePos;
                de.length   = table.GetLength();

                ot.DirectoryEntries.Add(de);

                TableFilePos += table.GetBuffer().GetPaddedLength();
            }


            // sort the directory entries

            if (numTables > 1)
            {
                for (int i = 0; i < numTables - 1; i++)
                {
                    for (int j = i + 1; j < numTables; j++)
                    {
                        if (((DirectoryEntry)(ot.DirectoryEntries[i])).tag > ((DirectoryEntry)(ot.DirectoryEntries[j])).tag)
                        {
                            DirectoryEntry temp = (DirectoryEntry)ot.DirectoryEntries[i];
                            ot.DirectoryEntries[i] = (DirectoryEntry)ot.DirectoryEntries[j];
                            ot.DirectoryEntries[j] = temp;
                        }
                    }
                }
            }


            // update the font checksum in the head table

            for (int i = 0; i < OrderedTables.Length; i++)
            {
                if ((string)OrderedTables[i].m_tag == "head")
                {
                    // calculate the checksum
                    uint sum = 0;
                    sum += ot.CalcOffsetTableChecksum();
                    sum += ot.CalcDirectoryEntriesChecksum();
                    for (int j = 0; j < OrderedTables.Length; j++)
                    {
                        sum += OrderedTables[j].CalcChecksum();
                    }

                    // get the cache
                    Table_head            headTable = (Table_head)OrderedTables[i];
                    Table_head.head_cache headCache = (Table_head.head_cache)headTable.GetCache();

                    // set the checkSumAdujustment field
                    headCache.checkSumAdjustment = 0xb1b0afba - sum;

                    // generate a new table and replace the head table in the list of ordered tables
                    Table_head newHead = (Table_head)headCache.GenerateTable();
                    OrderedTables[i] = newHead;

                    break;
                }
            }


            // write the offset table

            fs.Write(ot.m_buf.GetBuffer(), 0, (int)ot.m_buf.GetLength());


            // write the directory entries

            for (int i = 0; i < numTables; i++)
            {
                DirectoryEntry de = (DirectoryEntry)ot.DirectoryEntries[i];
                fs.Write(de.m_buf.GetBuffer(), 0, (int)de.m_buf.GetLength());
            }


            // write the tables

            for (ushort i = 0; i < numTables; i++)
            {
                OTTable table = OrderedTables[i];

                fs.Write(table.m_bufTable.GetBuffer(), 0, (int)table.GetBuffer().GetPaddedLength());
            }


            return(bRet);
        }
Ejemplo n.º 29
0
        /************************
         * constructors
         */


        public Table_cvt(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 30
0
        /// <summary>Return the first table with tag == <c>tag</c>
        /// or null if there is no such table.
        /// </summary>
        public OTTable GetTable(OTTag tag)
        {
            OTTable table = null;

            // find the directory entry in this font that matches the tag
            DirectoryEntry de = GetDirectoryEntry(tag);

            if (de != null)
            {
                table = GetTable(de);
            }

            return table;
        }
Ejemplo n.º 31
0
        public virtual OTTable CreateTableObject(OTTag tag, MBOBuffer buf)
        {
            OTTable table = null;

            string sName = GetUnaliasedTableName(tag);

            switch (sName)
            {
            case "BASE": table = new Table_BASE(tag, buf); break;

            case "CFF ": table = new Table_CFF(tag, buf); break;

            case "cmap": table = new Table_cmap(tag, buf); break;

            case "cvt ": table = new Table_cvt(tag, buf); break;

            case "DSIG": table = new Table_DSIG(tag, buf); break;

            case "EBDT": table = new Table_EBDT(tag, buf); break;

            case "EBLC": table = new Table_EBLC(tag, buf); break;

            case "EBSC": table = new Table_EBSC(tag, buf); break;

            case "fpgm": table = new Table_fpgm(tag, buf); break;

            case "gasp": table = new Table_gasp(tag, buf); break;

            case "GDEF": table = new Table_GDEF(tag, buf); break;

            case "glyf": table = new Table_glyf(tag, buf); break;

            case "GPOS": table = new Table_GPOS(tag, buf); break;

            case "GSUB": table = new Table_GSUB(tag, buf); break;

            case "hdmx": table = new Table_hdmx(tag, buf); break;

            case "head": table = new Table_head(tag, buf); break;

            case "hhea": table = new Table_hhea(tag, buf); break;

            case "hmtx": table = new Table_hmtx(tag, buf); break;

            case "JSTF": table = new Table_JSTF(tag, buf); break;

            case "kern": table = new Table_kern(tag, buf); break;

            case "loca": table = new Table_loca(tag, buf); break;

            case "LTSH": table = new Table_LTSH(tag, buf); break;

            case "maxp": table = new Table_maxp(tag, buf); break;

            case "name": table = new Table_name(tag, buf); break;

            case "OS/2": table = new Table_OS2(tag, buf); break;

            case "PCLT": table = new Table_PCLT(tag, buf); break;

            case "post": table = new Table_post(tag, buf); break;

            case "prep": table = new Table_prep(tag, buf); break;

            case "VDMX": table = new Table_VDMX(tag, buf); break;

            case "vhea": table = new Table_vhea(tag, buf); break;

            case "vmtx": table = new Table_vmtx(tag, buf); break;

            case "VORG": table = new Table_VORG(tag, buf); break;

            //case "Zapf": table = new Table_Zapf(tag, buf); break;
            default: table = new Table__Unknown(tag, buf); break;
            }

            return(table);
        }
Ejemplo n.º 32
0
 /************************
  * constructors
  */
 
 
 public val_head(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 33
0
 public Table_hdmx(OTTag tag, MBOBuffer buf, ushort nNumGlyphs ) : base(tag, buf)
 {
     m_numGlyphs = nNumGlyphs;
 }
Ejemplo n.º 34
0
 /************************
  * constructors
  */
 
 public Table_name(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 35
0
        /************************
         * constructors
         */


        public Table_fpgm(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 36
0
        /// <summary>Write a TTC (TT Collection) to a disk file.</summary>
        public static bool WriteTTCFile(FileStream fs, OTFont[] fonts)
        {
            bool bRet = true;


            // build the TTC header

            OTTag TTCtag         = (OTTag)"ttcf";
            uint  version        = 0x00020000;
            uint  DirectoryCount = (uint)fonts.Length;

            uint [] TableDirectory = new uint[fonts.Length];
            uint    ulDsigTag      = 0;
            uint    ulDsigLength   = 0;
            uint    ulDsigOffset   = 0;

            uint TTCHeaderLen = 12 + DirectoryCount * 4 + 12; // length of version 2.0 header


            // build an array of offset tables
            OffsetTable[] otArr = new OffsetTable[fonts.Length];
            for (int iFont = 0; iFont < fonts.Length; iFont++)
            {
                otArr[iFont] = new OffsetTable(new OTFixed(1, 0), fonts[iFont].GetNumTables());
            }

            // build an array of head tables that will contain the updated modified field and font checksum
            Table_head[] arrHeadTables = new Table_head[fonts.Length];
            for (int i = 0; i < fonts.Length; i++)
            {
                // get the cache
                Table_head            headTable = (Table_head)fonts[i].GetTable("head");
                Table_head.head_cache headCache = (Table_head.head_cache)headTable.GetCache();

                // set the 'modified' field to the current date
                DateTime dt = DateTime.Now;
                headCache.modified = headTable.DateTimeToSecondsSince1904(dt);

                // generate a new table and add it to the array
                Table_head newHead = (Table_head)headCache.GenerateTable();
                arrHeadTables[i] = newHead;
            }



            // build a list of directory entries for each font

            long FilePos = TTCHeaderLen;

            for (int iFont = 0; iFont < fonts.Length; iFont++)
            {
                ushort numTables = fonts[iFont].GetNumTables();
                TableDirectory[iFont] = (uint)FilePos;
                FilePos += 12 + numTables * 16;

                uint PrevFilePos = 0;
                for (ushort i = 0; i < numTables; i++)
                {
                    OTTable table = fonts[iFont].GetTable(i);
                    OTTag   tag   = table.m_tag;

                    if ((string)tag == "head")
                    {
                        table = arrHeadTables[iFont];
                    }

                    // check if this table is a duplicate of a table in a previous font

                    PrevFilePos = 0;
                    if (iFont > 0)
                    {
                        for (int iPrevFont = 0; iPrevFont < iFont; iPrevFont++)
                        {
                            for (int iTable = 0; iTable < fonts[iPrevFont].GetNumTables(); iTable++)
                            {
                                OTTable PrevTable = fonts[iPrevFont].GetTable(table.m_tag);
                                if (PrevTable != null)
                                {
                                    if (MBOBuffer.BinaryEqual(table.m_bufTable, PrevTable.m_bufTable))
                                    {
                                        // get the file position for the previous table
                                        for (int iDe = 0; iDe < otArr[iPrevFont].DirectoryEntries.Count; iDe++)
                                        {
                                            DirectoryEntry dePrev = (DirectoryEntry)otArr[iPrevFont].DirectoryEntries[iDe];
                                            if (dePrev.tag == table.m_tag)
                                            {
                                                PrevFilePos = dePrev.offset;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }


                    // build a new directory entry

                    DirectoryEntry de = new DirectoryEntry();
                    de.tag      = new OTTag(tag.GetBytes());
                    de.checkSum = table.CalcChecksum();
                    de.length   = table.GetLength();
                    if (PrevFilePos != 0)
                    {
                        de.offset = (uint)PrevFilePos;
                    }
                    else
                    {
                        de.offset = (uint)FilePos;
                        FilePos  += table.GetBuffer().GetPaddedLength();
                    }

                    otArr[iFont].DirectoryEntries.Add(de);
                }


                // sort the directory entries

                if (numTables > 1)
                {
                    for (int i = 0; i < numTables - 1; i++)
                    {
                        for (int j = i + 1; j < numTables; j++)
                        {
                            if (((DirectoryEntry)otArr[iFont].DirectoryEntries[i]).tag > ((DirectoryEntry)otArr[iFont].DirectoryEntries[j]).tag)
                            {
                                DirectoryEntry temp = (DirectoryEntry)otArr[iFont].DirectoryEntries[i];
                                otArr[iFont].DirectoryEntries[i] = (DirectoryEntry)otArr[iFont].DirectoryEntries[j];
                                otArr[iFont].DirectoryEntries[j] = temp;
                            }
                        }
                    }
                }
            }


            // update each font's checksum in the head table

            for (int iFont = 0; iFont < fonts.Length; iFont++)
            {
                ushort numTables = fonts[iFont].GetNumTables();

                // calculate the checksum
                uint sum = 0;
                sum += otArr[iFont].CalcOffsetTableChecksum();
                sum += otArr[iFont].CalcDirectoryEntriesChecksum();
                for (ushort i = 0; i < numTables; i++)
                {
                    DirectoryEntry de    = (DirectoryEntry)otArr[iFont].DirectoryEntries[i];
                    OTTable        table = fonts[iFont].GetTable(de.tag);
                    if ((string)de.tag == "head")
                    {
                        table = arrHeadTables[iFont];
                    }
                    sum += table.CalcChecksum();
                }

                // get the cache
                Table_head            headTable = arrHeadTables[iFont];
                Table_head.head_cache headCache = (Table_head.head_cache)headTable.GetCache();

                // set the checkSumAdujustment field
                headCache.checkSumAdjustment = 0xb1b0afba - sum;

                // generate a new table and replace the head table in the array of head tables
                Table_head newHead = (Table_head)headCache.GenerateTable();
                arrHeadTables[iFont] = newHead;
            }



            // write the TTC header

            WriteUint32MBO(fs, (uint)TTCtag);
            WriteUint32MBO(fs, version);
            WriteUint32MBO(fs, DirectoryCount);
            for (int i = 0; i < fonts.Length; i++)
            {
                WriteUint32MBO(fs, TableDirectory[i]);
            }
            WriteUint32MBO(fs, ulDsigTag);
            WriteUint32MBO(fs, ulDsigLength);
            WriteUint32MBO(fs, ulDsigOffset);


            // write out each font

            for (int iFont = 0; iFont < fonts.Length; iFont++)
            {
                ushort numTables = fonts[iFont].GetNumTables();

                // write the offset table

                fs.Write(otArr[iFont].m_buf.GetBuffer(), 0, (int)otArr[iFont].m_buf.GetLength());


                // write the directory entries

                for (int i = 0; i < numTables; i++)
                {
                    DirectoryEntry de = (DirectoryEntry)otArr[iFont].DirectoryEntries[i];
                    fs.Write(de.m_buf.GetBuffer(), 0, (int)de.m_buf.GetLength());
                }


                // write out each table unless a shared version has been written

                for (ushort i = 0; i < numTables; i++)
                {
                    DirectoryEntry de = (DirectoryEntry)otArr[iFont].DirectoryEntries[i];
                    if (fs.Position == de.offset)
                    {
                        OTTable table = fonts[iFont].GetTable(de.tag);
                        if ((string)table.m_tag == "head")
                        {
                            table = arrHeadTables[iFont];
                        }
                        fs.Write(table.m_bufTable.GetBuffer(), 0, (int)table.GetBuffer().GetPaddedLength());
                    }
                }
            }


            return(bRet);
        }
Ejemplo n.º 37
0
 public LookupTable_val(ushort offset, MBOBuffer bufTable, OTTag tag) : base(offset, bufTable, tag)
 {
 }
Ejemplo n.º 38
0
        /// <summary>Rmove a table to an non-file based table. Throws
        /// exception if table is not in font.
        /// </summary>
        public void RemoveTable(OTTag tag)
        {
            if (m_File != null)
            {
                throw new ApplicationException("attempted to remove a table from a file-based OTFont object");
            }

            if (GetDirectoryEntry(tag) == null)
            {
                throw new ArgumentException("the specified table doesn't doesn't exist in the font");
            }


            // remove the directory entry

            for (int i=0; i<m_OffsetTable.DirectoryEntries.Count; i++)
            {
                DirectoryEntry de = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                if (tag == de.tag)
                {
                    m_OffsetTable.DirectoryEntries.RemoveAt(i);
                    m_OffsetTable.numTables--;
                    break;
                }
            }
            

            // remove the table from the list of tables in memory

            for (int i=0; i<MemBasedTables.Count; i++)
            {
                OTTable t = (OTTable)MemBasedTables[i];
                if (tag == t.m_tag)
                {
                    MemBasedTables.RemoveAt(i);
                    break;
                }
            }

            string sTable = (string)tag;
            if (sTable == "CFF ")
            {
                m_OutlineType = OutlineType.OUTLINE_INVALID;
            }
            else if (sTable == "glyf")
            {
                m_OutlineType = OutlineType.OUTLINE_INVALID;
            }
        }
Ejemplo n.º 39
0
        /************************
         * constructors
         */


        public Table_head(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 40
0
 /************************
  * constructors
  */
 public Table_vmtx(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
     m_nLongVerMetrics  = 0;
     m_nGlyphsInTheFont = 0;
 }
Ejemplo n.º 41
0
 public val_cmap(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 42
0
        /************************
         * constructors
         */


        public Table__Unknown(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 43
0
 /************************
  * constructors
  */
 
 
 public Table_hdmx(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
     m_numGlyphs = 0;
 }
Ejemplo n.º 44
0
        /************************
         * constructors
         */


        public Table_EBSC(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 45
0
 /************************
  * constructors
  */
 
 
 public val_fpgm(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 46
0
        /************************
         * constructors
         */


        public Table_DSIG(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 47
0
        /// <summary>Return the first directory entry with 
        /// tag == <c>tag</c>
        /// or null if there is no such entry.
        /// </summary>
        public DirectoryEntry GetDirectoryEntry(OTTag tag)
        {
            Debug.Assert(m_OffsetTable != null);

            DirectoryEntry de = null;

            if (m_OffsetTable != null)
            {
                for (int i = 0; i<m_OffsetTable.DirectoryEntries.Count; i++)
                {
                    DirectoryEntry temp = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                    if (temp.tag == tag)
                    {
                        de = temp;
                        break;
                    }
                }

                // Try aliases after direct match
                if ( de == null )
                    for (int i = 0; i<m_OffsetTable.DirectoryEntries.Count; i++)
                    {
                        DirectoryEntry temp = (DirectoryEntry)m_OffsetTable.DirectoryEntries[i];
                        if ( ( (temp.tag == "bloc" || temp.tag == "CBLC") && tag == "EBLC")
                             || ( (temp.tag == "bdat" || temp.tag == "CBDT" ) && tag == "EBDT") )
                        {
                            de = temp;
                            break;
                        }
                    }
            }

            return de;
        }
Ejemplo n.º 48
0
 /************************
  * constructors
  */
 
 
 public Table_vhea(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 49
0
 public Table_SVG(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 50
0
        /************************
         * constructors
         */

        public Table_name(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 51
0
 /************************
  * constructors
  */
 
 
 public Table_EBDT(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 52
0
        /************************
         * constructors
         */


        public Table_maxp(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 53
0
        /************************
         * constructors
         */


        public Table_kern(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 54
0
 public Table_glyf(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 55
0
 /************************
  * constructors
  */
 
 
 public val_PCLT(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 56
0
        /************************
         * constructors
         */


        public Table_PCLT(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 57
0
 /************************
  * constructors
  */
 
 
 public Table_VDMX(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 58
0
        /************************
         * constructors
         */


        public Table_LTSH(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }
Ejemplo n.º 59
0
 /************************
  * constructors
  */
 
 
 public val_VDMX(OTTag tag, MBOBuffer buf) : base(tag, buf)
 {
 }
Ejemplo n.º 60
0
        /************************
         * constructors
         */

        public Table_GDEF(OTTag tag, MBOBuffer buf) : base(tag, buf)
        {
        }