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

📄 chinesetexttest.java

📁 JAVA报表
💻 JAVA
字号:
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.object-refinery.com/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.
 *
 * ------------------------------
 * ChineseTextTest.java
 * ------------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: ChineseTextTest.java,v 1.4 2003/09/09 10:27:58 taqua Exp $
 *
 * Changes
 * -------------------------
 * 09.06.2003 : Initial version
 *
 */

package org.jfree.report.ext.junit.bugs;

import java.awt.geom.Rectangle2D;
import java.net.URL;
import java.util.Iterator;

import org.jfree.report.Element;
import org.jfree.report.ElementAlignment;
import org.jfree.report.JFreeReport;
import org.jfree.report.elementfactory.LabelElementFactory;
import org.jfree.report.modules.output.pageable.pdf.PDFOutputTarget;
import org.jfree.report.modules.parser.base.ReportGenerator;
import org.jfree.report.style.ElementStyleSheet;
import org.jfree.report.style.FontDefinition;
import org.jfree.report.util.Log;

public class ChineseTextTest
{
  public ChineseTextTest()
  {
  }

  public JFreeReport getReport()
  {
    // The chinese text, as unicode character sequence ...
    final char[] text = {
      34987, 31216, 20026, 32593, 32476, 26102, 20195,
      30340, 36135, 24065, 65292, 23436, 20840, 22522,
      20110, 30340, 32593, 19978, 25903, 20184, 24179,
      21488, 65292, 21019, 24314, 20110, 24180, 24213,
      12290, 23427, 37027, 23436, 20840, 21311, 21517,
      65292, 24555, 25463, 65292, 26041, 20415, 65292,
      24443, 24213, 31881, 30862, 22320, 22495, 27010,
      24565, 30340, 31181, 31181, 29305, 28857, 19982,
      20248, 21183, 65292, 20351, 20043, 22312, 30701,
      30701, 24180, 30340, 26102, 38388, 37324, 65292,
      24471, 21040, 20102, 36805, 29467, 30340, 21457,
      23637, 22269, 38469, 19978, 36234, 26469, 36234,
      22810, 30340, 20844, 21496, 21644, 32593, 32476,
      21830, 24215, 24320, 22987, 25509, 21463, 25903,
      20184, 26041, 24335, 12290, 23427, 24050, 32463,
      25104, 20026, 20154, 20204, 36827, 34892, 30005,
      23376, 21830, 21153, 24378, 26377, 21147, 30340,
      24037, 20855, 12290, 21253, 25324, 35937, 38597,
      34382, 65292, 20122, 39532, 36874, 31561, 24456,
      22810, 32593, 32476, 20844, 21496, 37117, 24320,
      36890, 20102, 25903, 20184, 20132, 26131, 26041,
      24335, 65292, 20320, 21482, 38656, 33457, 19977,
      20998, 38047, 23601, 21487, 20197, 20813, 36153,
      30003, 35831, 19968, 20010, 36134, 21495, 65292,
      36134, 21495, 20043, 38388, 20114, 30456, 36716,
      36134, 21482, 38656, 31186, 38047, 65292, 20320,
      20063, 21487, 20197, 23558, 29616, 37329, 36890,
      36807, 38134, 34892, 30452, 25509, 36716, 21040,
      20320, 30340, 36134, 21495, 65292, 20063, 21487,
      20197, 25226, 36134, 21495, 37324, 30340, 25910,
      20837, 36716, 21040, 20840, 29699, 20219, 20309,
      19968, 23478, 38134, 34892, 20320, 30340, 31169,
      20154, 36134, 25143, 37324, 65292, 32780, 19981,
      35770, 20320, 36523, 23621, 20309, 22320, 12289,
      36523, 22788, 20309, 26041, 65281, 23427, 20197,
      40644, 37329, 20316, 20026, 31561, 20215, 22522,
      30784, 65292, 23436, 20840, 33073, 31163, 20219,
      20309, 22269, 23478, 20869, 37096, 36130, 25919,
      30340, 24433, 21709, 12290};
    final JFreeReport report = new JFreeReport();
    report.getReportHeader().addElement(LabelElementFactory.createLabelElement(
        null, new Rectangle2D.Float(0, 0, -100, 12), null,
        ElementAlignment.LEFT, null,
        "4 lines with chinese text follows ..."));

    // This font is a chinese font ... if you dont have this font, replace
    // it with another font, which is able to display chinese characters ...
    report.getReportHeader().addElement(LabelElementFactory.createLabelElement
        (null, new Rectangle2D.Float(0, 12, -100, 48),
            null, ElementAlignment.LEFT,
            new FontDefinition("mhya9gjp", 10), new String(text)));

    // Embedding the fonts increases the size of the PDF file, but makes
    // sure, that everbody can read the file. If all users have all the fonts
    // installed, which were used to create the report, then you can remove
    // the font-embedding flag.
    //
    // Embedding can also be enabled for single elements (using a FontDefinition
    // object).
    report.getReportConfiguration().setConfigProperty
        (PDFOutputTarget.PDFTARGET_EMBED_FONTS, "true");

    // Make the PDF file an Unicode file. Without this, you would only see
    // ascii characters, all other characters would not be displayed.
    report.getReportConfiguration().setConfigProperty
        (PDFOutputTarget.PDFTARGET_ENCODING, "Identity-H");
    return report;
  }

  public static void main(final String[] args) throws Exception
  {
    /*
    final JFreeReport report = new ChineseTextTest().getReport();
    PDFReportUtil.createPDF(report, "/tmp/chinese-text.pdf");
    */

    final String URLNAME = "/org/jfree/report/ext/junit/bugs/resource/chinese-text.xml";
    final URL in = new Integer(0).getClass().getResource(URLNAME);
    JFreeReport report = ReportGenerator.getInstance().parseReport(in);
    Log.debug ("" + report.getReportHeader().getElementCount());
    Element[] e = report.getReportHeader().getElementArray();
    for (int i = 0; i < e.length; i++)
    {
      Log.debug (e[i].toString());
      ElementStyleSheet es = e[i].getStyle();
      Iterator it = es.getDefinedPropertyNames();
      while (it.hasNext())
      {
        Log.debug ("ES: " + it.next());
      }

      es = e[i].getParent().getBandDefaults();
      it = es.getDefinedPropertyNames();
      while (it.hasNext())
      {
        Log.debug ("BN: " + it.next());
      }
    }

  }
}

⌨️ 快捷键说明

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