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

📄 fstext.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        @return the indentation applied to the text.
        */
    public int getOffsetX() { return offsetX; }

    /** Gets the location of the start of the text relative to the bottom edge of the bounding rectangle in twips.

        @return the location of the text relative to the bottom of the bounding rectangle.
        */
    public int getOffsetY() { return offsetY; }

    /** Gets the height of the text.

        @return the height of the font used to displayed the text.
        */
    public int getHeight() 
    { 
        return height; 
    }

    /** Sets the identifier of the font in which the text will be displayed.

        @param anIdentifier the identifier of the font that the text will be rendered in.
        */
    public void setIdentifier(int anIdentifier)
    {
        identifier = anIdentifier;
    }

    /** Sets the colour of the font in which the text will be displayed.

        @param aColor the colour of the text.
        */
    public void setColor(FSColor aColor)
    {
        color = aColor;
    }

    /** Sets the location of the start of the text relative to the left edge of the bounding rectangle in twips.

        @param xOffset the location of the text relative to the left edge of the bounding rectangle enclosing the text.
        */
    public void setOffsetX(int xOffset)
    {
        offsetX = xOffset;
    }

    /** Sets the location of the start of the text relative to the bottom edge of the bounding rectangle in twips.

        @param yOffset the location of the text relative to the bottom edge of the bounding rectangle enclosing the text.
        */
    public void setOffsetY(int yOffset)
    {
        offsetY = yOffset;
    }

    /** Sets the height of the text.

        @param aHeight the height of the text in the chosen font.
        */
    public void setHeight(int aHeight)
    {
        height = aHeight;
    }

    /** Adds an FSCharacter object to the array of characters.

        @param aCharacter an FSCharacter object.
        */
    public void add(FSCharacter aCharacter)
    {
        characters.add(aCharacter);
    }

    /** Gets the array of characters to be displayed.

        @return the array of FSCharacter objects.
        */
    public ArrayList getCharacters() { return characters; }

    /** Sets the array of characters to be displayed.

        @param anArray an array of FSCharacter objects.
        */
    public void setCharacters(ArrayList anArray)
    {
        characters = anArray;
    }
    
    int glyphBits()
    {
        int numberOfBits = 0;
        
        for (Iterator charIter = characters.iterator(); charIter.hasNext();) 
            numberOfBits = Math.max(numberOfBits, FSCoder.size(((FSCharacter)charIter.next()).getGlyphIndex(), false));
        
        return numberOfBits;
    }

    int advanceBits()
    {
        int numberOfBits = 0;
        
        for (Iterator charIter = characters.iterator(); charIter.hasNext();) 
            numberOfBits = Math.max(numberOfBits, FSCoder.size(((FSCharacter)charIter.next()).getAdvance(), true));
        
        return numberOfBits;
    }

    public Object clone()
    {
        FSText anObject = (FSText)super.clone();
        
        anObject.color = (color != null) ? (FSColor)color.clone() : null;

        anObject.characters = new ArrayList();
        
        for (Iterator i = characters.iterator(); i.hasNext();)
            anObject.characters.add(((FSCharacter)i.next()).clone());

        return anObject;
    }

    public boolean equals(Object anObject)
    {
        boolean result = false;
        
        if (super.equals(anObject))
        {
            FSText typedObject = (FSText)anObject;
            
            result = identifier == typedObject.identifier;

            if (color != null)
                result = result && color.equals(typedObject.color);
            else
                result = result && color == typedObject.color;

            result = result && offsetX == typedObject.offsetX;
            result = result && offsetY == typedObject.offsetY;
            result = result && height == typedObject.height;

            if (characters != null)
                result = characters.equals(typedObject.characters);
            else
                result = characters == typedObject.characters;
        }
        return result;
    }

    public void appendDescription(StringBuffer buffer, int depth)
    {
        buffer.append(name());
        
        if (depth > 0)
        {
            buffer.append(": { ");
            Transform.append(buffer, "identifier", identifier);
            Transform.append(buffer, "color", color, depth);
            Transform.append(buffer, "offsetX", offsetX);
            Transform.append(buffer, "offsetY", offsetY);
            Transform.append(buffer, "height", height);
            Transform.append(buffer, "characters", characters, depth);
            buffer.append("}");
        }
    }

    public int length(FSCoder coder)
    {
        boolean _containsFont = containsFont();
        boolean _containsColor = containsColor();
        boolean _containsOffsetX = containsOffsetX();
        boolean _containsOffsetY = containsOffsetY();
        
        int length = 1;
    
        if (containsStyle())
        {
            length += (_containsFont) ? 2 : 0;
            length += (_containsColor) ? color.length(coder) : 0;
            length += (_containsOffsetY) ? 2 : 0;
            length += (_containsOffsetX) ? 2 : 0;
            length += (_containsFont) ? 2 : 0;
        }
        
        length += 1;

        if (characters.size() > 0)
        {
            int numberOfBits = 0;
            int numberOfGlyphBits = coder.context[FSCoder.NumberOfGlyphBits];
            int numberOfAdvanceBits = coder.context[FSCoder.NumberOfAdvanceBits];
            
            numberOfBits = (numberOfGlyphBits + numberOfAdvanceBits)*characters.size();
            numberOfBits += (numberOfBits % 8 > 0) ? 8 - (numberOfBits % 8) : 0;

            length += numberOfBits >> 3;
        }
        return length;
    }
    
    public void encode(FSCoder coder)
    {
        boolean _containsFont = containsFont();
        boolean _containsColor = containsColor();
        boolean _containsOffsetY = containsOffsetY();
        boolean _containsOffsetX = containsOffsetX();

        coder.writeBits(1, 1);
        coder.writeBits(0, 3);

        coder.writeBits(_containsFont ? 1 : 0, 1);
        coder.writeBits(_containsColor ? 1 : 0, 1);
        coder.writeBits(_containsOffsetY ? 1 : 0, 1);
        coder.writeBits(_containsOffsetX ? 1 : 0, 1);
    
        if (_containsFont)
            coder.writeWord(identifier, 2);
    
        if (_containsColor)
            color.encode(coder);
    
        if (_containsOffsetX)
            coder.writeWord(offsetX, 2);
    
        if (_containsOffsetY)
            coder.writeWord(offsetY, 2);
    
        if (_containsFont)
            coder.writeWord(height, 2);

        coder.writeWord(characters.size(), 1);
        
        for (Iterator charIter = characters.iterator(); charIter.hasNext();) 
            ((FSTransformObject)charIter.next()).encode(coder);
            
        coder.alignToByte();
    }
    
    public void decode(FSCoder coder)
    {
        /* type */ coder.readBits(1, false);
        /* reserved */ coder.readBits(3, false);
        
        boolean _containsFont = coder.readBits(1, false) != 0 ? true : false;
        boolean _containsColor = coder.readBits(1, false) != 0 ? true : false;
        boolean _containsOffsetY = coder.readBits(1, false) != 0 ? true : false;
        boolean _containsOffsetX = coder.readBits(1, false) != 0 ? true : false;

        if (_containsFont)
            identifier = coder.readWord(2, false);

        if (_containsColor)
            color = new FSColor(coder);

        if (_containsOffsetX)
            offsetX = coder.readWord(2, true);

        if (_containsOffsetY)
            offsetY = coder.readWord(2, true);

        if (_containsFont)
            height = coder.readWord(2, false);

        int charCount = coder.readWord(1, false);
        
        characters = new ArrayList(charCount);

        for (int i=0; i<charCount; i++)
            characters.add(new FSCharacter(coder));
        
        coder.alignToByte();
    }
    
    private boolean containsFont()
    {
        return identifier != 0 && height != 0;
    }

    private boolean containsColor()
    {
        return color != null;
    }

    private boolean containsOffsetX()
    {
        return offsetX != Transform.VALUE_NOT_SET;
    }

    private boolean containsOffsetY()
    {
        return offsetY != Transform.VALUE_NOT_SET;
    }

    boolean containsStyle()
    {
        return containsFont() || containsColor() || containsOffsetX() || containsOffsetY();
    }
    
}

⌨️ 快捷键说明

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