⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.java

📁 java版本的flash文件(swf)播放器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        throws NoGlyphException 
    {
        return new Chars( chars, fontSize );
    }
    
    protected FontDefinition.Glyph getGlyph( int code, int[] index )
        throws NoGlyphException 
    {
        Integer codeI = new Integer(code);
        FontDefinition.Glyph g = (FontDefinition.Glyph)glyphs.get( codeI );
        
        if( g != null ) 
        {
            if( index != null )
            {
                Integer idx = (Integer)indices.get( codeI );
                index[0] = idx.intValue();
            }
            
            return g;
        }
        
        g = fontDef.getGlyph( code );
        
        if( g == null ) throw new NoGlyphException( code );
        
        int idx = addGlyph( g );
        if( index != null ) index[0] = idx;

        return g;
    }

    /**
     * Add a glyph and return the index
     */
    public int addGlyph( FontDefinition.Glyph glyph )
    {
        int idx = glyphs.size();
        
        if( glyph.getCode() > 0 )
        {
            Integer codeI = new Integer( glyph.getCode() );
            indices.put( codeI, new Integer( idx ));
            glyphs.put( codeI, glyph );
        }
        
        glyphList.add( glyph );
        
        return idx;
    }
    
    /**
     * Set the code for the glyph at the given index
     */
    public void setCode( int index, int code )
    {
        if( index >= glyphList.size() ) return;

        FontDefinition.Glyph g = (FontDefinition.Glyph)glyphList.get( index );
        g.setCode( code );
        
        Integer codeI = new Integer( code );
        indices.put( codeI, new Integer( index ));
        glyphs.put( codeI, g );        
    }
    
    protected int define( boolean textFont, Movie movie, SWFTagTypes tagwriter )
        throws IOException
    {
        Integer integerId = textFont ? 
                                (Integer)movie.definedSymbols.get( font1Key ) :
                                (Integer)movie.definedSymbols.get( font2Key );
                
        if( integerId == null )
        {
            if( textFont )
            {
                integerId = new Integer( defineFont1( movie, tagwriter ) );
                movie.definedSymbols.put( font1Key, integerId );
            }
            else
            {
                integerId = new Integer( defineFont2( movie, tagwriter ) );
                movie.definedSymbols.put( font2Key, integerId );
            }
        }

        id = integerId.intValue();
        return id;        
    }

    protected int defineFont1( Movie movie, SWFTagTypes tagwriter ) 
        throws IOException
    {
        int id = getNextId( movie );
        
        SWFVectors vecs = tagwriter.tagDefineFont( id, glyphList.size() );
        
        for( Iterator it = glyphList.iterator(); it.hasNext(); )
        {
            FontDefinition.Glyph g = (FontDefinition.Glyph)it.next();
            
            Shape s = g.getShape();
            
            s.writeGlyph( vecs );
        }
      
        if( fontDef.getName() != null )
        {
            int flags = 0;

            if( fontDef.isUnicode()  ) flags |= SWFConstants.FONT_UNICODE;
            if( fontDef.isShiftJIS() ) flags |= SWFConstants.FONT_SHIFTJIS;
            if( fontDef.isAnsi()     ) flags |= SWFConstants.FONT_ANSI;
            if( fontDef.isItalic()   ) flags |= SWFConstants.FONT_ITALIC;
            if( fontDef.isBold()     ) flags |= SWFConstants.FONT_BOLD;
        
        	//write fontInfo2 for Flash MX+, if needed
            if( movie.getVersion() >= SWFConstants.FLASH_MX_VERSION 
             && languageCode != SWFConstants.LANGUAGE_CODE_NONE ) {             	
				tagwriter.tagDefineFontInfo2( id, fontDef.getName(), flags, getCodes(), languageCode );
            } else {            	
				tagwriter.tagDefineFontInfo( id, fontDef.getName(), flags, getCodes() );            	
            }            
        }
        
        return id;
    }
    
    protected int defineFont2( Movie movie, SWFTagTypes tagwriter ) 
        throws IOException
    {
        int id = getNextId( movie );

        int glyphCount  = glyphList.size();
        int[]  codes    = new int [ glyphCount ];
        Rect[] bounds   = new Rect[ glyphCount ];
        int[]  advances = new int [ glyphCount ];
        
        //--Gather glyph info
        int i = 0;
        for( Iterator it = glyphList.iterator(); it.hasNext(); )
        {
            FontDefinition.Glyph g = (FontDefinition.Glyph)it.next();
            
            codes[i]    = g.getCode();
            advances[i] = (int)(g.getAdvance() * SWFConstants.TWIPS);
            
            double[] bound = g.getShape().getBoundingRectangle();
            
            bounds[i] = new Rect( (int)(bound[0] * SWFConstants.TWIPS),
                                  (int)(bound[1] * SWFConstants.TWIPS),
                                  (int)(bound[2] * SWFConstants.TWIPS),
                                  (int)(bound[3] * SWFConstants.TWIPS) );
            
            i++;
        }
        
        //--Gather kerning info
        ArrayList kerns = fontDef.getKerningPairList();
        int kernCount = kerns.size();
        int[] kern1   = new int[ kernCount ];
        int[] kern2   = new int[ kernCount ];
        int[] kernOff = new int[ kernCount ];
        
        i = 0;
        for( Iterator it = kerns.iterator(); it.hasNext(); )
        {
            FontDefinition.KerningPair pair = (FontDefinition.KerningPair)it.next();
            
            kern1[i]   = pair.getCode1();
            kern2[i]   = pair.getCode2();
            kernOff[i] = (int)(pair.getAdjustment() * SWFConstants.TWIPS );
                
            i++;
        }
        
        int flags = 0;
        if( fontDef.hasMetrics() ) flags |= SWFConstants.FONT2_HAS_LAYOUT;
        if( fontDef.isShiftJIS() ) flags |= SWFConstants.FONT2_SHIFTJIS;
        if( fontDef.isUnicode()  ) flags |= SWFConstants.FONT2_UNICODE;
        if( fontDef.isAnsi()     ) flags |= SWFConstants.FONT2_ANSI;
        if( fontDef.isItalic()   ) flags |= SWFConstants.FONT2_ITALIC;
        if( fontDef.isBold()     ) flags |= SWFConstants.FONT2_BOLD; 
        
        SWFVectors vecs = tagwriter.tagDefineFont2( 
                                  id, flags, fontDef.getName(), glyphCount,
                                  (int)(fontDef.getAscent() * SWFConstants.TWIPS),
                                  (int)(fontDef.getDescent() * SWFConstants.TWIPS),
                                  (int)(fontDef.getLeading() * SWFConstants.TWIPS),
                                  codes, advances, bounds, kern1, kern2, kernOff );

        for( Iterator it = glyphList.iterator(); it.hasNext(); )
        {
            FontDefinition.Glyph g = (FontDefinition.Glyph)it.next();
            
            Shape s = g.getShape();
            
            s.writeGlyph( vecs );
        }
        
        return id;
    }
    
    /**
     * Get the codes of the current set of glyphs
     */
    protected int[] getCodes()
    {
        int[] codes = new int[glyphList.size()];
        
        for( int i = 0; i < codes.length; i++ )
        {
            FontDefinition.Glyph g = (FontDefinition.Glyph)glyphList.get(i);
            codes[i] = g.getCode();
        }
        
        return codes;
    }
    
    protected int defineSymbol( Movie movie, 
                                SWFTagTypes timelineWriter,
                                SWFTagTypes definitionwriter ) throws IOException
    {
        return id;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -