diff options
author | Keiron Liddle <keiron@apache.org> | 2002-03-21 09:37:15 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-03-21 09:37:15 +0000 |
commit | 2d11da7573ee45c0b882bbba45b626410a75434b (patch) | |
tree | fd06e7eaf440e14d5e4d4c010b42045a9c4706f5 /src/org/apache | |
parent | 5bbf82caf4d455907eb5581c6993b4d30fc19ac9 (diff) | |
download | xmlgraphics-fop-2d11da7573ee45c0b882bbba45b626410a75434b.tar.gz xmlgraphics-fop-2d11da7573ee45c0b882bbba45b626410a75434b.zip |
a simple impl of getting ipd and line height
some adjustments to user agent
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194714 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r-- | src/org/apache/fop/fo/FOText.java | 16 | ||||
-rw-r--r-- | src/org/apache/fop/fo/FOUserAgent.java | 18 | ||||
-rw-r--r-- | src/org/apache/fop/fo/FObjMixed.java | 10 | ||||
-rw-r--r-- | src/org/apache/fop/fo/TextInfo.java | 37 | ||||
-rw-r--r-- | src/org/apache/fop/fo/flow/Block.java | 21 | ||||
-rw-r--r-- | src/org/apache/fop/fo/flow/InstreamForeignObject.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/image/ImageLoader.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/XMLReader.java | 2 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/AbstractLayoutManager.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/BlockLayoutManager.java | 30 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/LayoutManager.java | 1 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/LineLayoutManager.java | 18 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/PageLayoutManager.java | 10 | ||||
-rw-r--r-- | src/org/apache/fop/layoutmgr/TextLayoutManager.java | 45 | ||||
-rw-r--r-- | src/org/apache/fop/render/RendererContext.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFXMLHandler.java | 10 |
17 files changed, 157 insertions, 85 deletions
diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index e020ccfa1..ac18fb1c7 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -35,22 +35,6 @@ public class FOText extends FObj { protected int start; protected int length; TextInfo textInfo; - - public static class TextInfo { - public FontState fs; - public float red; - public float green; - public float blue; - public int wrapOption; - public int whiteSpaceCollapse; - public int verticalAlign; - - // Textdecoration - public boolean underlined = false; - public boolean overlined = false; - public boolean lineThrough = false; - } - TextState ts; public FOText(char[] chars, int s, int e, TextInfo ti) { diff --git a/src/org/apache/fop/fo/FOUserAgent.java b/src/org/apache/fop/fo/FOUserAgent.java index 2dbf98c1a..4736ed51f 100644 --- a/src/org/apache/fop/fo/FOUserAgent.java +++ b/src/org/apache/fop/fo/FOUserAgent.java @@ -44,14 +44,25 @@ public class FOUserAgent { return log; } - public void setBaseDirectory(String b) { + public void setBaseURL(String b) { base = b; } - public String getBaseDirectory() { + public String getBaseURL() { return base; } + public float getPixelToMM() { + return 0.35277777777777777778f; + } + + /** + * If to create hot links to footnotes and before floats. + */ + public boolean linkToFootnotes() { + return true; + } + /** * Set the default xml handler for the given mime type. */ @@ -92,10 +103,11 @@ public class FOUserAgent { handler.handleXML(ctx, doc, namespace); } catch (Throwable t) { // could not handle document - ctx.getLogger().error("Could not render XML", t); + log.error("Could not render XML", t); } } else { // no handler found for document + log.debug("No handler defined for XML: " + namespace); } } } diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java index d525fb243..ac1489b8f 100644 --- a/src/org/apache/fop/fo/FObjMixed.java +++ b/src/org/apache/fop/fo/FObjMixed.java @@ -20,7 +20,7 @@ import org.apache.fop.datatypes.ColorType; * and their processing */ public class FObjMixed extends FObj { - FOText.TextInfo textInfo = null; + TextInfo textInfo = null; FontInfo fontInfo=null; public FObjMixed(FONode parent) { @@ -33,7 +33,7 @@ public class FObjMixed extends FObj { protected void addCharacters(char data[], int start, int length) { if(textInfo == null) { - textInfo = new FOText.TextInfo(); + textInfo = new TextInfo(); try { textInfo.fs = propMgr.getFontState(fontInfo); @@ -43,9 +43,7 @@ public class FObjMixed extends FObj { } ColorType c = getProperty("color").getColorType(); - textInfo.red = c.red(); - textInfo.green = c.green(); - textInfo.blue = c.blue(); + textInfo.color = c; textInfo.verticalAlign = getProperty("vertical-align").getEnum(); @@ -98,7 +96,5 @@ public class FObjMixed extends FObj { return new RecursiveCharIterator(this); } - - } diff --git a/src/org/apache/fop/fo/TextInfo.java b/src/org/apache/fop/fo/TextInfo.java new file mode 100644 index 000000000..868c843f6 --- /dev/null +++ b/src/org/apache/fop/fo/TextInfo.java @@ -0,0 +1,37 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources." + */ + +package org.apache.fop.fo; + +// FOP +import org.apache.fop.layout.Area; +import org.apache.fop.layout.BlockArea; +import org.apache.fop.layout.FontState; +import org.apache.fop.layout.*; +import org.apache.fop.datatypes.*; +import org.apache.fop.fo.properties.*; +import org.apache.fop.apps.FOPException; +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.TextLayoutManager; + +import java.util.NoSuchElementException; + +/** + */ + public class TextInfo { + public FontState fs; + public ColorType color; + public int wrapOption; + public int whiteSpaceCollapse; + public int verticalAlign; + + // Textdecoration + public boolean underlined = false; + public boolean overlined = false; + public boolean lineThrough = false; + } + diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 3dc075b97..43f56705a 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -367,15 +367,30 @@ public class Block extends FObjMixed { } public LayoutManager getLayoutManager() { - return new BlockLayoutManager(this); - } +BlockLayoutManager blm = new BlockLayoutManager(this); +TextInfo ti = new TextInfo(); + +/* try { + ti.fs = propMgr.getFontState(fontInfo); + } catch (FOPException fopex) { + log.error("Error setting FontState for characters: " + + fopex.getMessage()); + }*/ + + ColorType c = getProperty("color").getColorType(); + ti.color = c; + ti.verticalAlign = + getProperty("vertical-align").getEnum(); + +blm.setBlockTextInfo(ti); + return blm; + } public boolean generatesInlineAreas() { return false; } - public void addChild(FONode child) { // Handle whitespace based on values of properties // Handle a sequence of inline-producing children in diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java index 84c623075..915e97bc3 100644 --- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -133,6 +133,10 @@ public class InstreamForeignObject extends FObj { ForeignObject foreign = new ForeignObject(doc, ns); areaCurrent = new Viewport(foreign); + areaCurrent.setWidth((int)size.getX() * 1000); + areaCurrent.setHeight((int)size.getY() * 1000); + areaCurrent.setOffset(0); + return areaCurrent; } diff --git a/src/org/apache/fop/image/ImageLoader.java b/src/org/apache/fop/image/ImageLoader.java index 679cf2325..5c836368b 100644 --- a/src/org/apache/fop/image/ImageLoader.java +++ b/src/org/apache/fop/image/ImageLoader.java @@ -30,7 +30,7 @@ class ImageLoader { if (!valid || image != null) { return image; } - String base = userAgent.getBaseDirectory(); + String base = userAgent.getBaseURL(); image = ImageFactory.loadImage(url, base, userAgent); if (image == null) { cache.invalidateImage(url, userAgent); diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index 8791b3420..e4416d33e 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -164,8 +164,7 @@ public class SVGReader implements ImageReader { Element e = ((SVGDocument) doc).getRootElement(); String s; SVGUserAgent userAg = - new SVGUserAgent(new AffineTransform()); - userAg.setLogger(ua.getLogger()); + new SVGUserAgent(ua, new AffineTransform()); BridgeContext ctx = new BridgeContext(userAg); UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); diff --git a/src/org/apache/fop/image/analyser/XMLReader.java b/src/org/apache/fop/image/analyser/XMLReader.java index ab66be981..5bce255f7 100644 --- a/src/org/apache/fop/image/analyser/XMLReader.java +++ b/src/org/apache/fop/image/analyser/XMLReader.java @@ -82,7 +82,7 @@ public class XMLReader implements ImageReader { } } } catch (Exception e) { - e.printStackTrace(); + //e.printStackTrace(); try { is.reset(); } catch (IOException ioe) { } diff --git a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java index deb7027fe..df6d58a45 100644 --- a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -30,6 +30,9 @@ public abstract class AbstractLayoutManager implements LayoutManager { this.parentLM = lm; } + public int getContentIPD() { + return 0; + } /** * Propagates to lower level layout managers. It iterates over the diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index 291f05d2a..416506a89 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -8,6 +8,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.TextInfo; import org.apache.fop.area.Area; import org.apache.fop.area.BlockParent; import org.apache.fop.area.Block; @@ -26,17 +27,21 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { super(fobj); } - // DESIGN. Potential alternative to getParentArea() scheme - // /** - // * Called by child layout manager to get the available space for - // * content in the inline progression direction. - // * Note that a manager may need to ask its parent for this. - // * For a block area, available IPD is determined by indents. - // */ - // public int getContentIPD() { - // getArea(); // make if not existing - // return blockArea.getIPD(); - // } + public void setBlockTextInfo(TextInfo ti) { + + } + + /** + * Called by child layout manager to get the available space for + * content in the inline progression direction. + * Note that a manager may need to ask its parent for this. + * For a block area, available IPD is determined by indents. + */ + public int getContentIPD() { + // adjust for side floats and indents + //getParentArea(null); // make if not existing + return curBlockArea.getIPD(); + } /** * Generate areas by tellings all layout managers for its FO's @@ -77,8 +82,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { curBlockArea = new Block(); // Set up dimensions // Must get dimensions from parent area - //MinOptMax referenceIPD = parentLM.getReferenceIPD(); Area parentArea = parentLM.getParentArea(curBlockArea); + int referenceIPD = parentArea.getIPD(); + curBlockArea.setIPD(referenceIPD); // Get reference IPD from parentArea setCurrentArea(curBlockArea); // ??? for generic operations } diff --git a/src/org/apache/fop/layoutmgr/LayoutManager.java b/src/org/apache/fop/layoutmgr/LayoutManager.java index 7f8b4756b..4d3878b99 100644 --- a/src/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LayoutManager.java @@ -20,4 +20,5 @@ public interface LayoutManager { public void addChild (Area childArea); public boolean splitArea(Area areaToSplit, SplitContext context); public void setParentLM(LayoutManager lm); + public int getContentIPD(); } diff --git a/src/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/org/apache/fop/layoutmgr/LineLayoutManager.java index 4d87d859d..c7829fbdf 100644 --- a/src/org/apache/fop/layoutmgr/LineLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineLayoutManager.java @@ -15,6 +15,8 @@ import org.apache.fop.area.MinOptMax; import org.apache.fop.area.inline.InlineArea; import java.util.ListIterator; +import java.util.List; +import java.util.Iterator; /** * LayoutManager for lines. It builds one or more lines containing @@ -29,6 +31,7 @@ public class LineLayoutManager extends AbstractLayoutManager { private boolean bFirstLine; private LayoutManager curLM; private MinOptMax remainingIPD; + private int lineHeight = 14000; public LineLayoutManager(ListIterator fobjIter) { super(null); @@ -68,7 +71,17 @@ public class LineLayoutManager extends AbstractLayoutManager { if (lineArea != null) { // Adjust spacing as necessary // Calculate height, based on content (or does the Area do this?) - lineArea.setHeight(14000); + int maxHeight = lineHeight; + List inlineAreas = lineArea.getInlineAreas(); + for(Iterator iter = inlineAreas.iterator(); iter.hasNext(); ) { + InlineArea inline = (InlineArea)iter.next(); + int h = inline.getHeight(); + if(h > maxHeight) { + maxHeight = h; + } + } + lineArea.setHeight(maxHeight); + parentLM.addChild(lineArea); lineArea = null; } @@ -96,8 +109,7 @@ public class LineLayoutManager extends AbstractLayoutManager { // lineArea.setContentIPD(parent.getContentIPD()); // remainingIPD = parent.getContentIPD(); // OR??? - // remainingIPD = parentLM.getContentIPD(); - remainingIPD = new MinOptMax(300000); // TESTING!!! + remainingIPD = new MinOptMax(parentLM.getContentIPD()); this.bFirstLine = false; } diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index caa55a4f8..d88d5d410 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -130,13 +130,12 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // for a float. When? } - - private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) { finishPage(); try { curPage = ((PageSequence) fobj).createPage(bIsBlank, bIsLast); } catch (FOPException fopex) { /* ???? */ + fopex.printStackTrace(); } curBody = (BodyRegion) curPage.getPage(). getRegion( RegionReference.BODY).getRegion(); @@ -306,10 +305,9 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable curBody.setMainReference(new MainReference()); } - - private Flow createFlow() { curFlow = new Flow(); + curFlow.setIPD(curSpan.getIPD()); // adjust for columns // Set IPD and max BPD on the curFlow from curBody curSpan.addFlow(curFlow); return curFlow; @@ -328,6 +326,10 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // } // else newpos = new MinOptMax(); curSpan = new Span(numCols); + // get Width or Height as IPD for span + curSpan.setIPD((int) curPage.getPage(). getRegion( + RegionReference.BODY).getViewArea().getWidth()); + //curSpan.setPosition(BPD, newpos); curBody.getMainReference().addSpan(curSpan); createFlow(); diff --git a/src/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/org/apache/fop/layoutmgr/TextLayoutManager.java index 635aa8792..73594a7d7 100644 --- a/src/org/apache/fop/layoutmgr/TextLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/TextLayoutManager.java @@ -8,9 +8,9 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; -import org.apache.fop.fo.FOText; // For TextInfo: TODO: make independent! +import org.apache.fop.fo.TextInfo; import org.apache.fop.area.Area; -import org.apache.fop.area.Property; +import org.apache.fop.area.Trait; import org.apache.fop.area.inline.Word; import org.apache.fop.area.inline.Space; import org.apache.fop.util.CharUtilities; @@ -26,7 +26,7 @@ import java.util.ListIterator; public class TextLayoutManager extends LeafNodeLayoutManager { private char[] chars; - private FOText.TextInfo textInfo; + private TextInfo textInfo; private static final char NEWLINE = '\n'; private static final char RETURN = '\r'; @@ -42,7 +42,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { protected static final int TEXT = 2; public TextLayoutManager(FObj fobj, char[] chars, - FOText.TextInfo textInfo) { + TextInfo textInfo) { super(fobj); this.chars = chars; this.textInfo = textInfo; @@ -72,7 +72,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { // With CID fonts, space isn't neccesary currentFontState.width(32) int whitespaceWidth = CharUtilities.getCharWidth(' ', textInfo.fs); - int wordStart = 0; + int wordStart = -1; int wordLength = 0; int wordWidth = 0; int spaceWidth = 0; @@ -152,15 +152,8 @@ public class TextLayoutManager extends LeafNodeLayoutManager { // spaces. Split the word and add Space // as necessary. All spaces inside the word // Have a fixed width. - Word curWordArea = new Word(); - curWordArea.setWidth(wordWidth); - curWordArea.setWord( new String(chars, wordStart + 1, - wordLength)); - Property prop = new Property(); - prop.propType = Property.FONT_STATE; - prop.data = textInfo.fs; - curWordArea.addProperty(prop); - parentLM.addChild(curWordArea); + parentLM.addChild(createWord(new String(chars, wordStart + 1, + wordLength), wordWidth)); // reset word width wordWidth = 0; @@ -221,21 +214,27 @@ public class TextLayoutManager extends LeafNodeLayoutManager { wordLength = chars.length - 1 - wordStart; } - Word curWordArea = new Word(); - curWordArea.setWidth(wordWidth); - curWordArea.setWord( - new String(chars, wordStart + 1, wordLength)); - Property prop = new Property(); - prop.propType = Property.FONT_STATE; - prop.data = textInfo.fs; - curWordArea.addProperty(prop); - parentLM.addChild(curWordArea); + parentLM.addChild(createWord(new String(chars, wordStart + 1, wordLength), wordWidth)); } chars = null; } + protected Word createWord(String str, int width) { + Word curWordArea = new Word(); + curWordArea.setWidth(width); + curWordArea.setHeight(textInfo.fs.getAscender() - textInfo.fs.getDescender()); + curWordArea.setOffset(textInfo.fs.getAscender()); + + curWordArea.setWord(str); + Trait prop = new Trait(); + prop.propType = Trait.FONT_STATE; + prop.data = textInfo.fs; + curWordArea.addTrait(prop); + return curWordArea; + } + /** Try to split the word area by hyphenating the word. */ public boolean splitArea(Area areaToSplit, SplitContext context) { context.nextArea = areaToSplit; diff --git a/src/org/apache/fop/render/RendererContext.java b/src/org/apache/fop/render/RendererContext.java index 2049a95a1..3706935aa 100644 --- a/src/org/apache/fop/render/RendererContext.java +++ b/src/org/apache/fop/render/RendererContext.java @@ -6,6 +6,8 @@ */ package org.apache.fop.render; +import org.apache.fop.fo.FOUserAgent; + import org.apache.log.Logger; import java.util.HashMap; @@ -17,7 +19,7 @@ import java.util.HashMap; */ public class RendererContext { String mime; - Logger log; + FOUserAgent userAgent; HashMap props = new HashMap(); public RendererContext(String m) { @@ -28,12 +30,12 @@ public class RendererContext { return mime; } - public void setLogger(Logger logger) { - log = logger; + public void setUserAgent(FOUserAgent ua) { + userAgent = ua; } - public Logger getLogger() { - return log; + public FOUserAgent getUserAgent() { + return userAgent; } public void setProperty(String name, Object val) { diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java index da936ec4c..521c09fd3 100644 --- a/src/org/apache/fop/render/pdf/PDFXMLHandler.java +++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java @@ -12,6 +12,7 @@ import org.apache.fop.render.XMLHandler; import org.apache.fop.render.RendererContext; import org.apache.fop.pdf.*; import org.apache.fop.svg.*; +import org.apache.fop.svg.SVGUserAgent; import org.apache.fop.layout.FontState; import org.apache.log.Logger; @@ -104,9 +105,8 @@ public static final String PDF_YPOS = "ypos"; float sx = 1, sy = 1; int xOffset = pdfInfo.x, yOffset = pdfInfo.y; - org.apache.fop.svg.SVGUserAgent ua - = new org.apache.fop.svg.SVGUserAgent(new AffineTransform()); - ua.setLogger(context.getLogger()); + SVGUserAgent ua + = new SVGUserAgent(context.getUserAgent(), new AffineTransform()); GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(ua); @@ -122,7 +122,7 @@ public static final String PDF_YPOS = "ypos"; try { root = builder.build(ctx, doc); } catch (Exception e) { - context.getLogger().error("svg graphic could not be built: " + context.getUserAgent().getLogger().error("svg graphic could not be built: " + e.getMessage(), e); return; } @@ -168,7 +168,7 @@ public static final String PDF_YPOS = "ypos"; root.paint(graphics); pdfInfo.currentStream.add(graphics.getString()); } catch (Exception e) { - context.getLogger().error("svg graphic could not be rendered: " + context.getUserAgent().getLogger().error("svg graphic could not be rendered: " + e.getMessage(), e); } |