Exemplo n.º 1
0
        public smallGlyphMetrics GetSmallMetrics(Table_EBLC.indexSubTable cIndexSubTable, uint nGlyphIndex, uint nStartGlyphIndex)
        {
            smallGlyphMetrics sgm = null;
            int nIndexFormat      = cIndexSubTable.header.indexFormat;
            int nImageFormat      = cIndexSubTable.header.imageFormat;

            Debug.Assert(nImageFormat == 1 || nImageFormat == 2 || nImageFormat == 8);

            // 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 );
            // commented out the above assert because batang.ttc violates this too much

            if (nImageFormat == 1 || nImageFormat == 2 || nImageFormat == 8)
            {
                if (nGlyphIndex >= nStartGlyphIndex)
                {
                    //EBDT table starts off with a version data so it would never be possible for this to be set to 0
                    uint nImageFormatOffset = getImageFormatOffset(cIndexSubTable, nGlyphIndex, nStartGlyphIndex);

                    if (nImageFormatOffset != 0)
                    {
                        // All of the supported image formats start with this data first
                        sgm          = new smallGlyphMetrics();
                        sgm.height   = m_bufTable.GetByte(nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.height);
                        sgm.width    = m_bufTable.GetByte(nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.width);
                        sgm.BearingX = m_bufTable.GetSbyte(nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.BearingX);
                        sgm.BearingY = m_bufTable.GetSbyte(nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.BearingY);
                        sgm.Advance  = m_bufTable.GetByte(nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.Advance);
                    }
                }
            }

            return(sgm);
        }
Exemplo n.º 2
0
        public bool Validate_Format2(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 small metrics
                smallGlyphMetrics sgm = null;
                try {
                    sgm = GetSmallMetrics(ist, idGlyph, ista.firstGlyphIndex);
                }
                catch (Exception e)
                {
                    v.ApplicationError(T.EBDT_GlyphImageData, E._Table_E_Exception, m_tag, "EBDT.Format2: " + e.Message);
                    bOk = false;
                    return(bOk);
                }
                if (sgm != null)
                {
                    smallGlyphMetrics_val sgm_val = smallGlyphMetrics_val.CreateFromSmallGlyphMetrics(sgm);
                    if (!sgm_val.Validate(v, sIdentity + ", idGlyph=" + idGlyph, this))
                    {
                        bOk = false;
                    }

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

            return(bOk);
        }
Exemplo n.º 3
0
        public bool Validate_Format1(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 small metrics
                smallGlyphMetrics sgm = GetSmallMetrics(ist, idGlyph, ista.firstGlyphIndex);
                if (sgm != null)
                {
                    smallGlyphMetrics_val sgm_val = smallGlyphMetrics_val.CreateFromSmallGlyphMetrics(sgm);
                    if (!sgm_val.Validate(v, sIdentity + ", idGlyph=" + idGlyph, this))
                    {
                        bOk = false;
                    }

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

            return(bOk);
        }
Exemplo n.º 4
0
            public static smallGlyphMetrics_val CreateFromSmallGlyphMetrics(smallGlyphMetrics sgm)
            {
                smallGlyphMetrics_val sgm_val = new smallGlyphMetrics_val();

                sgm_val.height   = sgm.height;
                sgm_val.width    = sgm.width;
                sgm_val.BearingX = sgm.BearingX;
                sgm_val.BearingY = sgm.BearingY;
                sgm_val.Advance  = sgm.Advance;

                return sgm_val;
            }
Exemplo n.º 5
0
            public static smallGlyphMetrics_val CreateFromSmallGlyphMetrics(smallGlyphMetrics sgm)
            {
                smallGlyphMetrics_val sgm_val = new smallGlyphMetrics_val();

                sgm_val.height   = sgm.height;
                sgm_val.width    = sgm.width;
                sgm_val.BearingX = sgm.BearingX;
                sgm_val.BearingY = sgm.BearingY;
                sgm_val.Advance  = sgm.Advance;

                return(sgm_val);
            }
Exemplo n.º 6
0
            public object Clone()
            {
                smallGlyphMetrics sgm = new smallGlyphMetrics();

                sgm.height   = height;
                sgm.width    = width;
                sgm.BearingX = BearingX;
                sgm.BearingY = BearingY;
                sgm.Advance  = Advance;


                return(sgm);
            }
Exemplo n.º 7
0
            public object Clone()
            {
                smallGlyphMetrics sgm = new smallGlyphMetrics();
                sgm.height = height;
                sgm.width = width;
                sgm.BearingX = BearingX;
                sgm.BearingY = BearingY;
                sgm.Advance = Advance;
            

                return sgm;
            }
Exemplo n.º 8
0
        public smallGlyphMetrics GetSmallMetrics( Table_EBLC.indexSubTable cIndexSubTable, uint nGlyphIndex, uint nStartGlyphIndex )
        {
            smallGlyphMetrics sgm = null;
            int nIndexFormat = cIndexSubTable.header.indexFormat;
            int nImageFormat = cIndexSubTable.header.imageFormat;

            Debug.Assert( nImageFormat == 1 || nImageFormat == 2 || nImageFormat == 8);

            // 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 ); 
            // commented out the above assert because batang.ttc violates this too much

            if (nImageFormat == 1 || nImageFormat == 2 || nImageFormat == 8)
            {
                if( nGlyphIndex >= nStartGlyphIndex )
                {
                    //EBDT table starts off with a version data so it would never be possible for this to be set to 0
                    uint nImageFormatOffset = getImageFormatOffset( cIndexSubTable, nGlyphIndex, nStartGlyphIndex );                    
                    
                    if( nImageFormatOffset != 0 )
                    {
                        // All of the supported image formats start with this data first
                        sgm = new smallGlyphMetrics();
                        sgm.height   = m_bufTable.GetByte( nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.height );
                        sgm.width    = m_bufTable.GetByte( nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.width );
                        sgm.BearingX = m_bufTable.GetSbyte( nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.BearingX );
                        sgm.BearingY = m_bufTable.GetSbyte( nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.BearingY );
                        sgm.Advance  = m_bufTable.GetByte( nImageFormatOffset + (uint)smallGlyphMetrics.FieldOffsets.Advance );
                    }
                }
            }

            return sgm;
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public bool Validate_Format8(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 small metrics
                smallGlyphMetrics sgm = GetSmallMetrics(ist, idGlyph, ista.firstGlyphIndex);
                if (sgm != null)
                {
                    smallGlyphMetrics_val sgm_val = smallGlyphMetrics_val.CreateFromSmallGlyphMetrics(sgm);
                    if (!sgm_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);
        }