Exemplo n.º 1
0
        } // Validate

        public uint?GetTableRecordIndex(OTTag tag)
        {
            if (_tableMap == null)
            {
                throw new OTInvalidOperationException("GetTableRecordIndex method error: cannot retrieve table records when Offset table has not yet been read");
            }

            uint index;

            if (_tableMap.TryGetValue(tag.ToString(), out index))
            {
                return(index);
            }
            else
            {
                return(null);
            }
        } // GetTableRecordIndex
Exemplo n.º 2
0
        public static bool IsSupportedTableType(OTTag tag)
        {
            switch (tag.ToString())
            {
            case "COLR":
            case "fmtx":
            //case "fvar":
            //case "GPOS":
            //case "GSUB":
            case "head":
            case "hhea":
            case "maxp":
                //case "name":
                //case "OS/2":
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool IsKnownTableType(OTTag tag)
        {
            switch (tag.ToString())
            {
            // OT tables
            case "avar":
            case "BASE":
            case "CBDT":
            case "CBLC":
            case "CFF ":
            case "CFF2":
            case "cmap":
            case "COLR":
            case "CPAL":
            case "cvar":
            case "cvt ":
            case "DSIG":
            case "EBDT":
            case "EBLC":
            case "EBSC":
            case "fpgm":
            case "fvar":
            case "gasp":
            case "GDEF":
            case "glyf":
            case "GPOS":
            case "GSUB":
            case "gvar":
            case "hdmx":
            case "head":
            case "hhea":
            case "hmtx":
            case "HVAR":
            case "JSTF":
            case "kern":
            case "loca":
            case "LTSH":
            case "MATH":
            case "maxp":
            case "MERG":
            case "meta":
            case "MVAR":
            case "name":
            case "OS/2":
            case "PCLT":
            case "post":
            case "prep":
            case "sbix":
            case "STAT":
            case "SVG ":
            case "VDMX":
            case "vhea":
            case "vmtx":
            case "VORG":
            case "VVAR":

            // Apple-specific tables
            case "acnt":
            case "ankr":
            case "bdat":
            case "bhed":
            case "bloc":
            case "bsln":
            case "fdsc":
            case "feat":
            case "fmtx":
            case "fond":
            case "gcid":
            case "hsty":
            case "just":
            case "lcar":
            case "ltag":
            case "mort":
            case "morx":
            case "opbd":
            case "prop":
            case "trak":
            case "xref":
            case "Zapf":

            // Graphite-specific tables
            case "Feat":
            case "Glat":
            case "Gloc":
            case "Sill":
            case "Silf":

            // VOLT source table
            case "TSIV":

            // VTT source tables
            case "TSI0":
            case "TSI1":
            case "TSI2":
            case "TSI3":
            case "TSI5":
                return(true);

            default:
                return(false);
            }
        }
Exemplo n.º 4
0
        public void ReadFromFile(FileInfo fileInfo)
        {
            // save fileinfo for later reference
            _fi = fileInfo;

            // Check that file exists. (Handle FileStream exception in advance.)
            if (!_fi.Exists)
            {
                throw new FileNotFoundException("File " + _fi.FullName + " was not found.", _fi.FullName);
            }

            // read file as a byte array, then construct memory stream from byte array
            {
                byte[] bytes;
                try
                {
                    // File.ReadAllBytes opens a filestream and then ensures it is closed
                    bytes = File.ReadAllBytes(_fi.FullName);
                    _ms   = new MemoryStream(bytes, 0, bytes.Length, false, true);
                }
                catch (IOException e)
                {
                    throw e;
                }
            }

            // Read sfntVersion tag
            try
            {
                _sfntVersionTag = OTTag.ReadTag(_ms);
            }
            catch (OTDataIncompleteReadException e)
            {
                throw new OTFileParseException("OT parse error: unable to read sfnt tag", e);
            }

            // supported format?
            if (!IsSupportedSfntVersion(_sfntVersionTag))
            {
                _validationStatus = OTFileValidation_SfntVersionNotSupported;
                throw new OTFileParseException("OT parse error: not a known and supported sfnt type (sfnt tag = " + _sfntVersionTag.ToString());
            }

            _validationStatus = OTFile.OTFileValidation_PartialValidation;

            // TTC? get TTC header
            if (_sfntVersionTag == (OTTag)"ttcf")
            {
                try
                {
                    _ttcHeader.ReadTtcHeader(_ms); // will set read position to start of file
                }
                catch (OTException e)
                {
                    _validationStatus = _ttcHeader.ValidationStatus;
                    throw new OTFileParseException("OT parse error: unable to read TTC header", e);
                }

                _numFonts = _ttcHeader.NumFonts;
            }
            else
            {
                _numFonts = 1;
            }

            // initialize new font object(s); this will get the font headers for each font resource
            _fonts = new OTFont[_numFonts];
            if (_sfntVersionTag == (OTTag)"ttcf")
            {
                for (uint i = 0; i < _numFonts; i++)
                {
                    _fonts[i] = new OTFont(this, _ttcHeader.OffsetTableOffsets[i], i);
                }
            }
            else // single font
            {
                _fonts[0] = new OTFont(this);
            }

            // got TTC header; created font objects and got all the header info for each
            // caller can now poke individual fonts to get additional info as needed

            // finally, get validation status on ttc header, offset tables
            _validationStatusOfFonts = new UInt64[_numFonts];
            for (int i = 0; i < _numFonts; i++)
            {
                // simple validations -- full validation on a table-by-table basis
                _fonts[i].Validate(_ms.Length, true);
            }

            if (_sfntVersionTag == (OTTag)"ttcf")
            {
                // treat ttc header validation as part of the file validation
                _validationStatus |= _ttcHeader.Validate(_ms.Length);

                // check for validation issues in any of the font resources
                for (int i = 0; i < _numFonts; i++)
                {
                    if ((_fonts[i].ValidationStatus & OTFile.OTFileValidation_ValidationIssueMask) != 0)
                    {
                        _validationStatus |= OTFile.OTFileValidation_ValidationIssueInChildStructure;
                        break;
                    }
                }
            }
            else
            {
                // treat font resource validation as part of the file validation
                _validationStatus |= (_fonts[0].ValidationStatus & OTFile.OTFileValidation_ValidationIssueMask);
            }
        } // ReadFromFile