Example #1
0
        public bool Validate_Format7(Validator v, string sIdentity, Table_EBLC.indexSubTable ist)
        {
            bool bOk = true;

            Table_EBLC.indexSubTableArray ista = ist.GetIndexSubTableArray();

            for (ushort idGlyph = ista.firstGlyphIndex; idGlyph <= ista.lastGlyphIndex; idGlyph++)
            {
                // validate big metrics
                bigGlyphMetrics bgm = GetBigMetrics(ist, idGlyph, ista.firstGlyphIndex);
                if (bgm != null)
                {
                    bigGlyphMetrics_val bgm_val = bigGlyphMetrics_val.CreateFromBigGlyphMetrics(bgm);
                    if (!bgm_val.Validate(v, sIdentity + ", idGlyph=" + idGlyph, this))
                    {
                        bOk = false;
                    }

                    // validate image data
                    // - this is just bitmap data, any values should be valid
                }
            }

            return(bOk);
        }
Example #2
0
            public object Clone()
            {
                bigGlyphMetrics bgm = new bigGlyphMetrics();
                bgm.height = height;
                bgm.width = width;
                bgm.horiBearingX = horiBearingX;
                bgm.horiBearingY = horiBearingY;
                bgm.horiAdvance = horiAdvance;
                bgm.vertBearingX = vertBearingX;
                bgm.vertBearingY = vertBearingY;
                bgm.vertAdvance = vertAdvance;

                return bgm;
            }
Example #3
0
            public static bigGlyphMetrics_val CreateFromBigGlyphMetrics(bigGlyphMetrics bgm)
            {
                bigGlyphMetrics_val bgm_val = new bigGlyphMetrics_val();
                bgm_val.height       = bgm.height;
                bgm_val.width        = bgm.width;
                bgm_val.horiBearingX = bgm.horiBearingX;
                bgm_val.horiBearingY = bgm.horiBearingY;
                bgm_val.horiAdvance  = bgm.horiAdvance;
                bgm_val.vertBearingX = bgm.vertBearingX;
                bgm_val.vertBearingY = bgm.vertBearingY;
                bgm_val.vertAdvance  = bgm.vertAdvance;

                return bgm_val;
            }
Example #4
0
            public object Clone()
            {
                bigGlyphMetrics bgm = new bigGlyphMetrics();

                bgm.height       = height;
                bgm.width        = width;
                bgm.horiBearingX = horiBearingX;
                bgm.horiBearingY = horiBearingY;
                bgm.horiAdvance  = horiAdvance;
                bgm.vertBearingX = vertBearingX;
                bgm.vertBearingY = vertBearingY;
                bgm.vertAdvance  = vertAdvance;

                return(bgm);
            }
Example #5
0
            public static bigGlyphMetrics_val CreateFromBigGlyphMetrics(bigGlyphMetrics bgm)
            {
                bigGlyphMetrics_val bgm_val = new bigGlyphMetrics_val();

                bgm_val.height       = bgm.height;
                bgm_val.width        = bgm.width;
                bgm_val.horiBearingX = bgm.horiBearingX;
                bgm_val.horiBearingY = bgm.horiBearingY;
                bgm_val.horiAdvance  = bgm.horiAdvance;
                bgm_val.vertBearingX = bgm.vertBearingX;
                bgm_val.vertBearingY = bgm.vertBearingY;
                bgm_val.vertAdvance  = bgm.vertAdvance;

                return(bgm_val);
            }
Example #6
0
        public bigGlyphMetrics GetBigMetrics(Table_EBLC.indexSubTable cIndexSubTable, uint nGlyphIndex, uint nStartGlyphIndex)
        {
            bigGlyphMetrics bgm          = null;
            int             nIndexFormat = cIndexSubTable.header.indexFormat;
            int             nImageFormat = cIndexSubTable.header.imageFormat;

            Debug.Assert(nImageFormat == 6 || nImageFormat == 7 || nImageFormat == 9);

            // These images all have the same metrics as described in the indexSubTable so should have the proper image format
            //Debug.Assert( nIndexFormat != 2 && nIndexFormat != 5 );

            if (nImageFormat == 6 || nImageFormat == 7 || nImageFormat == 9)
            {
                if (nGlyphIndex >= nStartGlyphIndex)
                {
                    try
                    {
                        uint nImageFormatOffset = getImageFormatOffset(cIndexSubTable, nGlyphIndex, nStartGlyphIndex);

                        if (nImageFormatOffset != 0 && nImageFormatOffset + bigGlyphMetrics.bufSize <= m_bufTable.GetLength())
                        {
                            // All of the supported image formats start with this data first
                            bgm              = new bigGlyphMetrics();
                            bgm.height       = m_bufTable.GetByte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.height);
                            bgm.width        = m_bufTable.GetByte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.width);
                            bgm.horiBearingX = m_bufTable.GetSbyte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiBearingX);
                            bgm.horiBearingY = m_bufTable.GetSbyte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiBearingY);
                            bgm.horiAdvance  = m_bufTable.GetByte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiAdvance);
                            bgm.vertBearingX = m_bufTable.GetSbyte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertBearingX);
                            bgm.vertBearingY = m_bufTable.GetSbyte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertBearingY);
                            bgm.vertAdvance  = m_bufTable.GetByte(nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertAdvance);
                        }
                    }
                    catch (Exception)
                    {
                        bgm = null;
                    }
                }
            }

            return(bgm);
        }
Example #7
0
        public bigGlyphMetrics GetBigMetrics( Table_EBLC.indexSubTable cIndexSubTable, uint nGlyphIndex, uint nStartGlyphIndex )
        {
            bigGlyphMetrics bgm = null;
            int nIndexFormat = cIndexSubTable.header.indexFormat;
            int nImageFormat = cIndexSubTable.header.imageFormat;

            Debug.Assert(nImageFormat == 6 || nImageFormat == 7 || nImageFormat == 9);

            // These images all have the same metrics as described in the indexSubTable so should have the proper image format
            //Debug.Assert( nIndexFormat != 2 && nIndexFormat != 5 );

            if (nImageFormat == 6 || nImageFormat == 7 || nImageFormat == 9)
            {
                
                if( nGlyphIndex >= nStartGlyphIndex )
                {                    
                    try
                    {
                        uint nImageFormatOffset = getImageFormatOffset( cIndexSubTable, nGlyphIndex, nStartGlyphIndex );

                        if( nImageFormatOffset != 0 && nImageFormatOffset + bigGlyphMetrics.bufSize <= m_bufTable.GetLength())
                        {
                            // All of the supported image formats start with this data first
                            bgm = new bigGlyphMetrics();
                            bgm.height       = m_bufTable.GetByte ( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.height );
                            bgm.width        = m_bufTable.GetByte ( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.width );
                            bgm.horiBearingX = m_bufTable.GetSbyte( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiBearingX );
                            bgm.horiBearingY = m_bufTable.GetSbyte( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiBearingY );
                            bgm.horiAdvance  = m_bufTable.GetByte ( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.horiAdvance );
                            bgm.vertBearingX = m_bufTable.GetSbyte( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertBearingX );
                            bgm.vertBearingY = m_bufTable.GetSbyte( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertBearingY );
                            bgm.vertAdvance  = m_bufTable.GetByte ( nImageFormatOffset + (uint)bigGlyphMetrics.FieldOffsets.vertAdvance );
                        }
                    }
                    catch(Exception)
                    {
                        bgm = null;
                    }
                }
            }

            return bgm;
        }
Example #8
0
        public byte [,] GetBitmapImage(Table_EBLC.bitmapSizeTable bst, ushort glyphID)
        {
            byte [,] bits = null;

            Table_EBLC.indexSubTableArray ista = bst.FindIndexSubTableArray(glyphID);
            if (ista != null)
            {
                Table_EBLC.indexSubTable ist = bst.GetIndexSubTable(ista);

                if (ist.header.imageFormat < 8)
                {
                    // simple bitmap
                    byte [] encodedDataBuf = GetImageData(ist, glyphID, ista.firstGlyphIndex);

                    byte width = 0, height = 0;

                    switch (ist.header.imageFormat)
                    {
                    case 0:
                        throw new ApplicationException("illegal image format: 0");

                    //break;
                    case 1:
                    case 2:
                        smallGlyphMetrics sgm = this.GetSmallMetrics(ist, glyphID, ista.firstGlyphIndex);
                        width  = sgm.width;
                        height = sgm.height;
                        break;

                    case 3:
                    case 4:
                        throw new ApplicationException("illegal image format: " + ist.header.imageFormat);

                    //break;
                    case 5:
                        switch (ist.header.indexFormat)
                        {
                        case 2:
                            Table_EBLC.indexSubTable2 ist2 = (Table_EBLC.indexSubTable2)ist;
                            width  = ist2.bigMetrics.width;
                            height = ist2.bigMetrics.height;
                            break;

                        case 5:
                            Table_EBLC.indexSubTable5 ist5 = (Table_EBLC.indexSubTable5)ist;
                            width  = ist5.bigMetrics.width;
                            height = ist5.bigMetrics.height;
                            break;
                        }
                        break;

                    case 6:
                    case 7:
                        bigGlyphMetrics bgm = this.GetBigMetrics(ist, glyphID, ista.firstGlyphIndex);
                        width  = bgm.width;
                        height = bgm.height;
                        break;
                    }

                    if (encodedDataBuf != null)
                    {
                        bits = DecodeImageData(ist, width, height, bst.bitDepth, encodedDataBuf);
                    }
                    else
                    {
                        //Debug.Assert(false);
                    }
                }
                else if (ist.header.imageFormat < 10)
                {
                    // composite bitmap
                    throw new ApplicationException("TODO: impelement bitmap composites");
                }
                else
                {
                    Debug.Assert(false, "illegal image format");
                }
            }

            return(bits);
        }
Example #9
0
        public bool Validate_Format9(Validator v, string sIdentity, Table_EBLC.indexSubTable ist)
        {
            bool bOk = true;

            Table_EBLC.indexSubTableArray ista = ist.GetIndexSubTableArray();

            for (ushort idGlyph = ista.firstGlyphIndex; idGlyph <= ista.lastGlyphIndex; idGlyph++)
            {
                // validate big metrics
                bigGlyphMetrics bgm = GetBigMetrics(ist, idGlyph, ista.firstGlyphIndex);
                if (bgm != null)
                {
                    bigGlyphMetrics_val bgm_val = bigGlyphMetrics_val.CreateFromBigGlyphMetrics(bgm);
                    if (!bgm_val.Validate(v, sIdentity + ", idGlyph=" + idGlyph, this))
                    {
                        bOk = false;
                    }

                    ushort numComponents = this.GetNumComponents(ist, idGlyph, ista.firstGlyphIndex);

                    // validate component array
                    for (uint i = 0; i < numComponents; i++)
                    {
                        ebdtComponent component = GetComponent(ist, idGlyph, ista.firstGlyphIndex, i);
                        Debug.Assert(component != null);


                        // validate the ebdtComponent

                        // verify that the component's glyph code is less than maxp numGlyphs
                        if (component.glyphCode >= m_nCachedMaxpNumGlyphs)
                        {
                            string sDetails = sIdentity + ", idGlyph=" + idGlyph +
                                              ", component[" + i + "].glyphCode=" + component.glyphCode +
                                              ", maxp.numGlyphs = " + m_nCachedMaxpNumGlyphs;
                            v.Error(T.EBDT_GlyphImageData, E.EBDT_E_GlyphImageData, m_tag, sDetails);
                            bOk = false;
                        }

                        // verify that the component's glyph code isn't 0, which should be reserved as the empty glyph
                        // (technically, someone could use the empty glyph as a component, but it's more likely to be an error)
                        if (component.glyphCode == 0)
                        {
                            string sDetails = sIdentity + ", idGlyph=" + idGlyph +
                                              ", component[" + i + "].glyphCode=" + component.glyphCode;
                            v.Error(T.EBDT_GlyphImageData, E.EBDT_E_GlyphImageData, m_tag, sDetails);
                            bOk = false;
                        }

                        // verify that the component's glyph code isn't the glyph code of its parent
                        if (component.glyphCode == idGlyph)
                        {
                            string sDetails = sIdentity + ", idGlyph=" + idGlyph +
                                              ", component[" + i + "].glyphCode=" + component.glyphCode + " (glyph can't use itself as a component)";
                            v.Error(T.EBDT_GlyphImageData, E.EBDT_E_GlyphImageData, m_tag, sDetails);
                            bOk = false;
                        }
                    }
                }
            }

            return(bOk);
        }