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

📄 fontinfo.java

📁 使用servlet开发的动态生成GIF图像
💻 JAVA
字号:
import java.io.*;
import java.util.zip.*;

/**
 * FontInfo. Font descriptor (Zipped ARBG + Font Size + Index).
 * @version    1.0
 * @author	   S.H.
 * @company    JavaZOOM.
 * @date       01/2000.
 *
 * Use of this source and binary code is permitted only for non-commercial purposes.
 * Modification is allowed with this copyright notice and the following disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
public class fontinfo implements Serializable
{

  private int			_width = -1;
  private int			_height = -1;
  private int 			_yspacing = -1;
  private String		_index = null;
  private String		_filename = null;
  private byte[]		_data = null;
  private int			_imageW = -1;
  private int			_imageH = -1;

  /**
   * Constructor.
   */
  public fontinfo(int width, int height, int yspc, String index, String filename, byte[] data, int imageW, int imageH)
  {
		_width = width;
		_height = height;
		_yspacing = yspc;
		_index = index;
		_filename = filename;
		_data = data;
		_imageW = imageW;
		_imageH = imageH;
  }

  /**
   * Returns Image width.
   */
  public int getImageWidth()
  {
	  return _imageW;
  }

  /**
   * Returns Image height.
   */
  public int getImageHeight()
  {
	  return _imageH;
  }

  /**
   * Returns font width.
   */
  public int getWidth()
  {
	  return _width;
  }

  /**
   * Returns font height.
   */
  public int getHeight()
  {
	  return _height;
  }

  /**
   * Returns font YSpacing.
   */
  public int getYSpacing()
  {
	  return _yspacing;
  }

  /**
   * Returns font width.
   */
  public String getIndex()
  {
	  return _index;
  }

  /**
   * Returns font filename.
   */
  public String getFilename()
  {
	  return _filename;
  }

  /**
   * Returns pixel(byte) array.
   */
  public byte[] getByteData()
  {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	int bytesRead = 0;
	byte[] swap = new byte[1024];
	byte[] unzipped = null;

	/*-- Unzip Data --*/
	try
	{
		ByteArrayInputStream bais = new ByteArrayInputStream(_data);
		GZIPInputStream gzis = new GZIPInputStream(bais);
		while (true)
		{
			bytesRead = gzis.read(swap,0,swap.length);
			if (bytesRead==-1) break;
			baos.write(swap,0,bytesRead);
		}
		gzis.close();
		unzipped = baos.toByteArray();
		baos.close();
	} catch (Exception e)
	  {
		  System.err.println("Unzip Error : "+e.getMessage());
	  }
	return unzipped;
  }

  /**
   *  Returns pixel(int) array.
   */
  public int[] getData()
  {
	byte[] unzipped = getByteData();
	int[] pixels = new int[unzipped.length/4];
	int p = 0;
	for (int m=0;m<pixels.length;m++)
	{
		int A = (unzipped[p++]<<24)&0xFF000000;
		int R = (unzipped[p++]<<16)&0x00FF0000;
		int G = (unzipped[p++]<<8)&0x0000FF00;
		int B = (unzipped[p++])&0x000000FF;
		pixels[m] = A | R | G | B;
    }
	return pixels;
  }

}

⌨️ 快捷键说明

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