1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/**
* ===========================================
* LibLayout : a free Java layouting library
* ===========================================
*
* Project Info: http://reporting.pentaho.org/liblayout/
*
* (C) Copyright 2006-2007, by Pentaho Corporation 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ------------
* $Id: TestRenderableTextFactory.java,v 1.12 2007/04/02 11:41:22 taqua Exp $
* ------------
* (C) Copyright 2006-2007, by Pentaho Corporation.
*/
package org.jfree.layouting.renderer.text;
import org.jfree.layouting.DefaultLayoutProcess;
import org.jfree.layouting.LayoutProcess;
import org.jfree.layouting.LibLayoutBoot;
import org.jfree.layouting.input.style.keys.font.FontStyleKeys;
import org.jfree.layouting.input.style.values.CSSConstant;
import org.jfree.layouting.layouter.context.ContextId;
import org.jfree.layouting.layouter.context.DefaultLayoutContext;
import org.jfree.layouting.layouter.context.FontSpecification;
import org.jfree.layouting.layouter.context.LayoutContext;
import org.jfree.layouting.modules.output.html.FlowHtmlOutputProcessor;
import org.jfree.layouting.renderer.model.RenderNode;
import org.jfree.layouting.renderer.model.RenderableText;
import org.jfree.layouting.util.AttributeMap;
import org.pentaho.reporting.libraries.fonts.text.whitespace.CollapseWhiteSpaceFilter;
import org.pentaho.reporting.libraries.fonts.text.whitespace.WhiteSpaceFilter;
import org.pentaho.reporting.libraries.fonts.text.breaks.WordBreakProducer;
import org.pentaho.reporting.libraries.fonts.text.breaks.BreakOpportunityProducer;
import org.pentaho.reporting.libraries.fonts.text.font.NoKerningProducer;
import org.pentaho.reporting.libraries.fonts.text.font.KerningProducer;
import org.pentaho.reporting.libraries.fonts.text.font.StaticFontSizeProducer;
import org.pentaho.reporting.libraries.fonts.text.font.FontSizeProducer;
import org.pentaho.reporting.libraries.fonts.text.Spacing;
import org.pentaho.reporting.libraries.fonts.text.StaticSpacingProducer;
import org.pentaho.reporting.libraries.fonts.text.SpacingProducer;
/**
* Creation-Date: 24.06.2006, 13:21:33
*
* @author Thomas Morgner
*/
public class TestRenderableTextFactory extends DefaultRenderableTextFactory
{
public TestRenderableTextFactory(final LayoutProcess layoutProcess)
{
super(layoutProcess);
}
protected SpacingProducer createSpacingProducer(final LayoutContext layoutContext)
{
return new StaticSpacingProducer(Spacing.EMPTY_SPACING);
}
protected FontSizeProducer createFontSizeProducer(final LayoutContext layoutContext)
{
return new StaticFontSizeProducer(5000, 5000, 4000);
}
protected KerningProducer createKerningProducer(final LayoutContext layoutContext)
{
return new NoKerningProducer();
}
protected BreakOpportunityProducer createBreakProducer(final LayoutContext layoutContext)
{
return new WordBreakProducer();
}
protected WhiteSpaceFilter createWhitespaceFilter(final LayoutContext layoutContext)
{
return new CollapseWhiteSpaceFilter();
}
// public static void main(String[] args)
// {
// LibLayoutBoot.getInstance().start();
//
// DefaultElementContext elementContext = new DefaultElementContext(null);
// DefaultLayoutContext layoutContext =
// new DefaultLayoutContext(new ContextId(0, 0,0), "Bah", "buh", null, new AttributeMap());
//
// TestRenderableTextFactory tr = new TestRenderableTextFactory(null);
//
//
// int[] text = new int[]{' ', 'W','o', ' ', 'b', ' ', ' ', '\n' };
// tr.startText();
// RenderableText[] rts = tr.createText
// (text, 0, text.length, layoutContext);
// tr.finishText();
//
// RenderableText rt = rts[0];
// Log.debug("RT: " + rt.getLength());
// printGlyphs(rt);
//
//// RenderNode[] nodes = rt.split(rt.getMinorAxis(), 29000, null);
//// RenderableText text1 = (RenderableText) nodes[0];
//// RenderableText text2 = (RenderableText) nodes[1];
//// Log.debug("RT[0]: " + text1.getLength());
////
//// printGlyphs(text1);
//// Log.debug("RT[1]: " + text2.getLength());
//// printGlyphs(text2);
// }
public static void main(String[] args)
{
LibLayoutBoot.getInstance().start();
DefaultLayoutContext layoutContext =
new DefaultLayoutContext
(new ContextId(0, 0,0), "Bah", "buh", null, new AttributeMap());
layoutContext.getStyle().setValue(FontStyleKeys.FONT_FAMILY, new CSSConstant("helvetica"));
final FontSpecification fontSpecification = layoutContext.getFontSpecification();
fontSpecification.setFontFamily("Arial");
fontSpecification.setFontSize(12);
final FlowHtmlOutputProcessor out =
new FlowHtmlOutputProcessor(LibLayoutBoot.getInstance().getGlobalConfig());
final DefaultLayoutProcess layoutProcess = new DefaultLayoutProcess(out);
TestRenderableTextFactory tr = new TestRenderableTextFactory(layoutProcess);
// int[] text = new int[]{ ' ', 'A',' ', 'B',' '};
int[] text = new int[]{ '1'};
RenderNode[] rts = tr.createText(text, 0, text.length, layoutContext);
final RenderNode[] renderNodes = tr.finishText();
RenderableText rt = (RenderableText) rts[1];
printGlyphs(rt);
}
private static void printGlyphs(final RenderableText text)
{
Glyph[] glyphs = text.getGlyphs();
final int lpos = Math.min(text.getOffset() + text.getLength(), glyphs.length);
for (int i = text.getOffset(); i < lpos; i++)
{
Glyph glyph = glyphs[i];
// Log.debug("BO: " + glyph + ", BW: " + glyph.getBreakWeight());
}
}
}
|