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

📄 printercommandset.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * ----------------------
 * PrinterCommandSet.java
 * ----------------------
 * (C)opyright 2003, by Thomas Morgner and Contributoers.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);;
 *
 * $Id: PrinterCommandSet.java,v 1.10.2.1 2003/12/21 23:28:45 taqua Exp $
 *
 * Changes
 * -------
 * 30-Jan-2003 : Initial version
 *
 */
package org.jfree.report.modules.output.pageable.plaintext;

import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.io.IOException;
import java.io.OutputStream;

import org.jfree.report.style.FontDefinition;
import org.jfree.report.util.PageFormatFactory;

/**
 * Implements a printer command set for plain text output. The output is
 * not enriched with any printer specific control sequences.
 * <p>
 * Due to the architecture of matrix printers, the vertical borders
 * are given in 1/1440th of an inch, while the horizontal borders are
 * given in characters.
 *
 * @author Thomas Morgner
 */
public strictfp class PrinterCommandSet
{
  /** the roman font. */
  public static final byte SELECT_FONT_ROMAN = 0x00;

  /** the swiss font. */
  public static final byte SELECT_FONT_SWISS = 0x01;

  /** the courier font. */
  public static final byte SELECT_FONT_COURIER = 0x02;

  /** the prestige font. */
  public static final byte SELECT_FONT_PRESTIGE = 0x03;

  /** the OCR-A font. */
  public static final byte SELECT_FONT_OCR_A = 0x05;

  /** the OCR-B font. */
  public static final byte SELECT_FONT_OCR_B = 0x06;

  /** the orator font. */
  public static final byte SELECT_FONT_ORATOR = 0x07;

  /** the swiss-bold font. */
  public static final byte SELECT_FONT_SWISS_BOLD = 0x7A;

  /** the gothic font. */
  public static final byte SELECT_FONT_GOTHIC = 0x7C;

  /** selects the font, which is selected on the printer menu. */
  public static final byte SELECT_FONT_FROM_MENU = 0x7F;

  /**
   * the Carriage Return control character,
   * the printer carriage returns to the start of the line.
   */
  public static final byte CARRIAGE_RETURN = 0x0D;

  /** scrolls the paper up a single line. */
  public static final byte LINE_FEED = 0x0A;

  /** the form feed character, ejects the current page and starts the next page. */
  public static final byte FORM_FEED = 0x0C;

  /** the space character. */
  public static final byte SPACE = 0x20;

  /** the output stream. */
  private final OutputStream out;

  /** the font selector byte. */
  private byte font;

  /** character width. */
  private byte characterWidth;

  /** the paper height in lines. */
  private int paperSize;

  /** the current bold state for the font. */
  private boolean bold;

  /** the current italic state for the font. */
  private boolean italic;

  /** the current underline state for the font. */
  private boolean underline;

  /** the current strikethrough state for the font. */
  private boolean strikethrough;

  /** the left border in characters. */
  private int borderLeft;

  /** the right border in characters. */
  private int borderRight;

  /** the upper border in lines. */
  private int borderTop;

  /** the bottom border in lines. */
  private int borderBottom;

  /** the current codepage. */
  private String codepage;

  /** the current linespacing in 1/1440 inches. */
  private int lineSpacing;

  /** the AutoLF state. */
  private boolean autoLf;

  /** the printQuality flag, true for letter quality. */
  private boolean letterQuality;

  /** the lines per inch for this page. */
  private final int defaultLPI;

  /** the characters per inch for this page. */
  private final int defaultCPI;

  /** the pageformat used in this page. */
  private final PageFormat pageFormat;

//  /** the emptyCellCounter is used to optimize the printing. */
//  private int emptyCellCounter;

  /** the encoding header, if any. */
  private byte[] encodingHeader;

  /** A single space character encoded in the current codepage. */
  private byte[] space;

  /**
   * A flag indicating whether this is the first page that is printed with
   * this command set.
   */
  private boolean firstPage;

  /**
   * Creates a new PrinterCommandSet.
   *
   * @param out the target output stream
   * @param format the pageformat of the used report
   * @param defaultCPI the characters-per-inch for the output.
   * @param defaultLPI the lines-per-inch for the output.
   */
  public PrinterCommandSet(final OutputStream out, final PageFormat format,
                           final int defaultCPI, final int defaultLPI)
  {
    this.out = out;
    this.defaultLPI = defaultLPI;
    this.defaultCPI = defaultCPI;
    this.pageFormat = format;
    this.firstPage = true;
    //setVerticalBorder();
  }

  /**
   * Gets the pageformat used in this command set.
   * @return the pageformat.
   */
  public PageFormat getPageFormat()
  {
    return pageFormat;
  }

  /**
   * Gets the default character width in CPI.
   *
   * @return the default character width in CPI.
   */
  public int getDefaultCPI()
  {
    return defaultCPI;
  }

  /**
   * Gets the default character height in CPI.
   *
   * @return the default character height in CPI.
   */
  public int getDefaultLPI()
  {
    return defaultLPI;
  }

  /**
   * Gets the outputstream that is used to write the generated content.
   *
   * @return the output stream.
   */
  protected OutputStream getOut()
  {
    return out;
  }

  /**
   * Defines the font. Does nothing.
   *
   * @param fontSelection the font selection byte.
   * @throws java.io.IOException is not thrown here.
   */
  public void setFont(final byte fontSelection) throws IOException
  {
    this.font = fontSelection;
  }

  /**
   * Returns the defined font selection byte.
   * @return the font selection byte.
   */
  public byte getFont()
  {
    return font;
  }

  /**
   * Defines the character width for the current font. The width is specified in
   * Characters-per-inch. Valid values are 10, 12, 15, 17 and 20 cpi.
   *
   * @param charWidth the character width in CPI.
   * @throws java.io.IOException if there was an IOError while writing the command or if the
   *   character width is not supported by the printer.
   */
  public void setCharacterWidth(final byte charWidth) throws IOException
  {
    this.characterWidth = charWidth;
  }

  /**
   * Gets the character width in CPI.
   * @return the character width.
   */
  public byte getCharacterWidth()
  {
    return characterWidth;
  }

  /**
   * Defines the font style for the printed text. The IBM-CommandSet does not
   * support strike-through.
   *
   * @param bold true, if the text should be printed in bold mode.
   * @param italic true, if the text should be italic, false otherwise
   * @param underline true, if the text should be underlined, false otherwise
   * @param strike true, if the text should be strikethrough, false otherwise
   * @throws java.io.IOException if there was an IOError while writing the command
   */
  public void setFontStyle(final boolean bold, final boolean italic,
                           final boolean underline, final boolean strike)
      throws IOException
  {
    this.bold = bold;
    this.italic = italic;
    this.underline = underline;
    this.strikethrough = strike;
  }

  /**
   * Gets the strikethrough format flag.
   *
   * @return the strikethrough font format flag.
   */
  public boolean isStrikethrough()
  {
    return strikethrough;
  }

  /**
   * Gets the underline format flag.
   *
   * @return the underline font format flag.
   */
  public boolean isUnderline()
  {
    return underline;
  }

  /**
   * Gets the italic format flag.
   *
   * @return the italic font format flag.
   */
  public boolean isItalic()
  {
    return italic;
  }

  /**
   * Gets the bold format flag.
   *
   * @return the bold font format flag.
   */
  public boolean isBold()
  {
    return bold;
  }

  /**
   * Defines the papersize in lines.
   *
   * @param lines the number of lines that could be printed on a single page.
   * @throws java.io.IOException if there was an IOError while writing the command
   */
  public void setPaperSize(final int lines) throws IOException
  {
    this.paperSize = lines;
  }

  /**
   * Returns the paper size in lines.
   * @return the page height in lines.
   */
  public int getPaperSize()
  {
    return paperSize;
  }

  /**
   * Defines the horizontal borders for the current paper. The borders are given
   * in characters.
   *
   * @param left the number of spaces printed on the start of a line.
   * @param right the number of spaces left free on the right paper border.
   * @throws java.io.IOException if an IOException occured while updating the printer state.
   */
  public void setHorizontalBorder(final int left, final int right) throws IOException
  {
    this.borderLeft = left;
    this.borderRight = right;

⌨️ 快捷键说明

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