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

📄 definefont2.java

📁 java解析flash。对于flash在java上应用非常有帮助。比如解析flash到服务器端
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * JSwiff is an open source Java API for Macromedia Flash file generation
 * and manipulation
 *
 * Copyright (C) 2004-2008 Ralf Terdic (contact@jswiff.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.jswiff.swfrecords.tags;

import com.jswiff.io.InputBitStream;
import com.jswiff.io.OutputBitStream;
import com.jswiff.swfrecords.KerningRecord;
import com.jswiff.swfrecords.LangCode;
import com.jswiff.swfrecords.Rect;
import com.jswiff.swfrecords.Shape;

import java.io.IOException;


/**
 * This tag is used to supply font information. Unlike with
 * <code>DefineFont</code>, fonts defined with this tag can be used for
 * dynamic text. Font metrics for improved layout can be supplied. Mapping to
 * device fonts is also possible.
 *
 * @since SWF 3.
 */
public class DefineFont2 extends DefinitionTag {
  private boolean shiftJIS;
  private boolean smallText;
  private boolean ansi;
  private boolean italic;
  private boolean bold;
  private LangCode languageCode;
  private String fontName;
  private Shape[] glyphShapeTable;
  private char[] codeTable;
  private short ascent;
  private short descent;
  private short leading;
  private short[] advanceTable;
  private Rect[] boundsTable;
  private KerningRecord[] kerningTable;
  private int numGlyphs;
  private boolean hasLayout;

  /**
   * <p>
   * Creates a new DefineFont2 tag. Requires the font's character ID and name,
   * a glyph shape table and a code table.
   * </p>
   * 
   * <p>
   * The shape table contains one shape for each glyph. When using dynamic
   * device text, the shape table can be empty (set to <code>null</code>). In
   * this case, the code table is ignored.
   * </p>
   * 
   * <p>
   * The code table is an array of characters equal in size to the shape table.
   * It assigns a character to each glyph.
   * </p>
   *
   * @param characterId character ID of the font
   * @param fontName font name, either direct, e.g. 'Times New Roman', or
   *        indirect, like '_serif'
   * @param glyphShapeTable array of shapes (for each glyph one)
   * @param codeTable array of chars (for each glyph one)
   *
   * @throws IllegalArgumentException if code table is different from glyph
   *         count
   */
  public DefineFont2(
    int characterId, String fontName, Shape[] glyphShapeTable, char[] codeTable) {
    code               = TagConstants.DEFINE_FONT_2;
    this.characterId   = characterId;
    this.fontName      = fontName;
    if (glyphShapeTable != null) {
      this.glyphShapeTable   = glyphShapeTable;
      numGlyphs              = glyphShapeTable.length;
      if (codeTable.length != numGlyphs) {
        throw new IllegalArgumentException(
          "Size of codeTable must be equal to glyph count!");
      }
      this.codeTable = codeTable;
    }
  }

  DefineFont2() {
    // empty
  }

  /**
   * Sets the value of the ANSI flag. If ANSI is set, the shiftJIS flag is
   * cleared. If neither ANSI nor shiftJIS are set, UCS-2 is used.
   *
   * @param ansi <code>true</code> if flag set, else <code>false</code>
   */
  public void setANSI(boolean ansi) {
    this.ansi = ansi;
    if (ansi) {
      shiftJIS = false;
    }
  }

  /**
   * Checks if the ANSI flag is set. If neither ANSI nor shiftJIS are set,
   * UCS-2 is used.
   *
   * @return <code>true</code> if flag set, else <code>false</code>
   */
  public boolean isANSI() {
    return ansi;
  }

  /**
   * Returns an array containing the advance value for each glyph of the font.
   *
   * @return advance table
   */
  public short[] getAdvanceTable() {
    return advanceTable;
  }

  /**
   * Returns the font's ascent. The ascent is the distance from the baseline to
   * the ascender line (i.e. to the highest ascender of the font).
   *
   * @return font ascent (in EM square coords)
   */
  public short getAscent() {
    return ascent;
  }

  /**
   * Sets/clears bold style.
   *
   * @param bold <code>true</code> for bold, otherwise <code>false</code>
   */
  public void setBold(boolean bold) {
    this.bold = bold;
  }

  /**
   * Checks if the text is bold.
   *
   * @return <code>true</code> if text is bold, otherwise <code>false</code>
   */
  public boolean isBold() {
    return bold;
  }

  /**
   * Returns the font's bounds table.
   *
   * @return bounds table.
   */
  public Rect[] getBoundsTable() {
    return boundsTable;
  }

  /**
   * Sets the font's code table containing a character for each glyph.
   *
   * @param codeTable font's code table
   */
  public void setCodeTable(char[] codeTable) {
    this.codeTable = codeTable;
  }

  /**
   * Returns the font's code table containing a character for each glyph.
   *
   * @return code table of font
   */
  public char[] getCodeTable() {
    return codeTable;
  }

  /**
   * Returns the font's descent. The descent is the space below the baseline
   * required by the lowest descender (distance between base line and
   * descender line).
   *
   * @return font descent (in EM square coords)
   */
  public short getDescent() {
    return descent;
  }

  /**
   * Sets the name of the font. This can be either a direct (e.g. 'Times New
   * Roman') or an indirect font name (e.g. '_serif').
   *
   * @param fontName string containing the font's name
   */
  public void setFontName(String fontName) {
    this.fontName = fontName;
  }

  /**
   * Returns the name of the font. This can be either a direct (e.g. 'Times New
   * Roman') or an indirect font name (e.g. '_serif').
   *
   * @return font name as string
   */
  public String getFontName() {
    return fontName;
  }

  /**
   * Sets the glyph shape table, containing a shape for each defined glyph.
   *
   * @param glyphShapeTable glyph shapes array
   */
  public void setGlyphShapeTable(Shape[] glyphShapeTable) {
    this.glyphShapeTable = glyphShapeTable;
  }

  /**
   * Returns the glyph shape table, containing a shape for each defined glyph.
   *
   * @return glyph shapes array
   */
  public Shape[] getGlyphShapeTable() {
    return glyphShapeTable;
  }

  /**
   * Sets/clears italic style.
   *
   * @param italic <code>true</code> for italic, otherwise <code>false</code>
   */
  public void setItalic(boolean italic) {
    this.italic = italic;
  }

  /**
   * Checks if the text is italic.
   *
   * @return <code>true</code> if text is italic, otherwise <code>false</code>
   */
  public boolean isItalic() {
    return italic;
  }

  /**
   * Returns the font's kerning table.
   *
   * @return kerning table
   */
  public KerningRecord[] getKerningTable() {
    return kerningTable;
  }

  /**
   * Sets the language code of this font.
   *
   * @param languageCode a language code
   */
  public void setLanguageCode(LangCode languageCode) {
    this.languageCode = languageCode;
  }

  /**
   * Returns the font's language code.
   *
   * @return a language code
   */
  public LangCode getLanguageCode() {
    return languageCode;
  }

  /**
   * <p>
   * Sets layout information for dynamic glyph text.
   * </p>
   * 
   * <p>
   * The <code>ascent</code> is the distance from the baseline to the ascender
   * line (i.e. to the highest ascender of the font).
   * </p>
   * 
   * <p>
   * The <code>descent</code> is the space below the baseline required by the
   * lowest descender.
   * </p>

⌨️ 快捷键说明

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