Return-Path: Delivered-To: apmail-xmlgraphics-fop-commits-archive@www.apache.org Received: (qmail 2081 invoked from network); 27 Dec 2007 10:34:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Dec 2007 10:34:56 -0000 Received: (qmail 19277 invoked by uid 500); 27 Dec 2007 10:34:45 -0000 Delivered-To: apmail-xmlgraphics-fop-commits-archive@xmlgraphics.apache.org Received: (qmail 19247 invoked by uid 500); 27 Dec 2007 10:34:45 -0000 Mailing-List: contact fop-commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: fop-dev@xmlgraphics.apache.org Delivered-To: mailing list fop-commits@xmlgraphics.apache.org Received: (qmail 19236 invoked by uid 99); 27 Dec 2007 10:34:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2007 02:34:45 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Dec 2007 10:34:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 12A0B1A983A; Thu, 27 Dec 2007 02:34:28 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r607032 [2/2] - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/ src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/extensions/ src/java/org/apache/fop/fo/f... Date: Thu, 27 Dec 2007 10:34:18 -0000 To: fop-commits@xmlgraphics.apache.org From: jeremias@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071227103429.12A0B1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=607032&r1=607031&r2=607032&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java Thu Dec 27 02:34:15 2007 @@ -21,61 +21,26 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.datatypes.Numeric; import org.apache.fop.area.AreaTreeHandler; -import org.apache.fop.area.AreaTreeModel; -import org.apache.fop.area.IDTracker; -import org.apache.fop.area.PageViewport; import org.apache.fop.area.LineArea; -import org.apache.fop.area.Resolvable; - -import org.apache.fop.fo.Constants; -import org.apache.fop.fo.flow.Marker; -import org.apache.fop.fo.flow.RetrieveMarker; - import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.PageSequenceMaster; import org.apache.fop.fo.pagination.SideRegion; import org.apache.fop.fo.pagination.StaticContent; import org.apache.fop.layoutmgr.inline.ContentLayoutManager; -import java.util.List; - /** * LayoutManager for a PageSequence. This class is instantiated by * area.AreaTreeHandler for each fo:page-sequence found in the * input document. */ -public class PageSequenceLayoutManager extends AbstractLayoutManager { +public class PageSequenceLayoutManager extends AbstractPageSequenceLayoutManager { private static Log log = LogFactory.getLog(PageSequenceLayoutManager.class); - /** - * AreaTreeHandler which activates the PSLM and controls - * the rendering of its pages. - */ - private AreaTreeHandler areaTreeHandler; - - /** - * fo:page-sequence formatting object being - * processed by this class - */ - private PageSequence pageSeq; - private PageProvider pageProvider; - private IDTracker idTracker; - - /** - * Current page with page-viewport-area being filled by - * the PSLM. - */ - private Page curPage; - - private int startPageNum = 0; - private int currentPageNum = 0; - /** * Constructor * @@ -83,20 +48,10 @@ * @param pseq fo:page-sequence to process */ public PageSequenceLayoutManager(AreaTreeHandler ath, PageSequence pseq) { - super(pseq); - this.areaTreeHandler = ath; - this.idTracker = ath.getIDTracker(); - this.pageSeq = pseq; + super(ath, pseq); this.pageProvider = new PageProvider(ath, pseq); } - /** - * @return the LayoutManagerMaker object associated to the areaTreeHandler - */ - public LayoutManagerMaker getLayoutManagerMaker() { - return areaTreeHandler.getLayoutManagerMaker(); - } - /** @return the PageProvider applicable to this page-sequence. */ public PageProvider getPageProvider() { return this.pageProvider; @@ -106,25 +61,27 @@ * @return the PageSequence being managed by this layout manager */ protected PageSequence getPageSequence() { - return pageSeq; + return (PageSequence)pageSeq; } /** - * Activate the layout of this page sequence. - * PageViewports corresponding to each page generated by this - * page sequence will be created and sent to the AreaTreeModel - * for rendering. + * Provides access to this object + * @return this PageSequenceLayoutManager instance */ + public PageSequenceLayoutManager getPSLM() { + return this; + } + + /** {@inheritDoc} */ public void activateLayout() { - startPageNum = pageSeq.getStartingPageNumber(); - currentPageNum = startPageNum - 1; + initialize(); LineArea title = null; - if (pageSeq.getTitleFO() != null) { + if (getPageSequence().getTitleFO() != null) { try { ContentLayoutManager clm = getLayoutManagerMaker(). - makeContentLayoutManager(this, pageSeq.getTitleFO()); + makeContentLayoutManager(this, getPageSequence().getTitleFO()); title = (LineArea) clm.getParentArea(null); } catch (IllegalStateException e) { // empty title; do nothing @@ -145,9 +102,7 @@ finishPage(); } - /** - * Finished the page-sequence and notifies everyone about it. - */ + /** {@inheritDoc} */ public void finishPageSequence() { if (pageSeq.hasId()) { idTracker.signalIDProcessed(pageSeq.getId()); @@ -157,11 +112,11 @@ (currentPageNum - startPageNum) + 1); areaTreeHandler.notifyPageSequenceFinished(pageSeq, (currentPageNum - startPageNum) + 1); - pageSeq.releasePageSequence(); + getPageSequence().releasePageSequence(); // If this sequence has a page sequence master so we must reset // it in preparation for the next sequence - String masterReference = pageSeq.getMasterReference(); + String masterReference = getPageSequence().getMasterReference(); PageSequenceMaster pageSeqMaster = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(masterReference); if (pageSeqMaster != null) { @@ -173,229 +128,18 @@ } } - /** - * Provides access to the current page. - * @return the current Page - */ - public Page getCurrentPage() { - return curPage; - } - - /** - * Provides access for setting the current page. - * @param currentPage the new current Page - */ - protected void setCurrentPage(Page currentPage) { - this.curPage = currentPage; - } - - /** - * Provides access to the current page number - * @return the current page number - */ - protected int getCurrentPageNum() { - return currentPageNum; - } - - /** - * Provides access to the current page viewport. - * @return the current PageViewport - *//* - public PageViewport getCurrentPageViewport() { - return curPage.getPageViewport(); - }*/ - - /** - * Provides access to this object - * @return this PageSequenceLayoutManager instance - */ - public PageSequenceLayoutManager getPSLM() { - return this; + /** {@inheritDoc} */ + protected Page createPage(int pageNumber, boolean isBlank) { + return pageProvider.getPage(isBlank, + pageNumber, PageProvider.RELTO_PAGE_SEQUENCE); } - /** - * This returns the first PageViewport that contains an id trait - * matching the idref argument, or null if no such PV exists. - * - * @param idref the idref trait needing to be resolved - * @return the first PageViewport that contains the ID trait - */ - public PageViewport getFirstPVWithID(String idref) { - List list = idTracker.getPageViewportsContainingID(idref); - if (list != null && list.size() > 0) { - return (PageViewport) list.get(0); - } - return null; - } - - /** - * This returns the last PageViewport that contains an id trait - * matching the idref argument, or null if no such PV exists. - * - * @param idref the idref trait needing to be resolved - * @return the last PageViewport that contains the ID trait - */ - public PageViewport getLastPVWithID(String idref) { - List list = idTracker.getPageViewportsContainingID(idref); - if (list != null && list.size() > 0) { - return (PageViewport) list.get(list.size() - 1); - } - return null; - } - - /** - * Add an ID reference to the current page. - * When adding areas the area adds its ID reference. - * For the page layout manager it adds the id reference - * with the current page to the area tree. - * - * @param id the ID reference to add - */ - public void addIDToPage(String id) { - if (id != null && id.length() > 0) { - idTracker.associateIDWithPageViewport(id, curPage.getPageViewport()); - } - } - - /** - * Add an id reference of the layout manager in the AreaTreeHandler, - * if the id hasn't been resolved yet - * @param id the id to track - * @return a boolean indicating if the id has already been resolved - * TODO Maybe give this a better name - */ - public boolean associateLayoutManagerID(String id) { - if (log.isDebugEnabled()) { - log.debug("associateLayoutManagerID(" + id + ")"); - } - if (!idTracker.alreadyResolvedID(id)) { - idTracker.signalPendingID(id); - return false; - } else { - return true; - } - } - - /** - * Notify the areaTreeHandler that the LayoutManagers containing - * idrefs have finished creating areas - * @param id the id for which layout has finished - */ - public void notifyEndOfLayout(String id) { - idTracker.signalIDProcessed(id); - } - - /** - * Identify an unresolved area (one needing an idref to be - * resolved, e.g. the internal-destination of an fo:basic-link) - * for both the AreaTreeHandler and PageViewport object. - * - * The IDTracker keeps a document-wide list of idref's - * and the PV's needing them to be resolved. It uses this to - * send notifications to the PV's when an id has been resolved. - * - * The PageViewport keeps lists of id's needing resolving, along - * with the child areas (page-number-citation, basic-link, etc.) - * of the PV needing their resolution. - * - * @param id the ID reference to add - * @param res the resolvable object that needs resolving - */ - public void addUnresolvedArea(String id, Resolvable res) { - curPage.getPageViewport().addUnresolvedIDRef(id, res); - idTracker.addUnresolvedIDRef(id, curPage.getPageViewport()); - } - - /** - * Bind the RetrieveMarker to the corresponding Marker subtree. - * If the boundary is page then it will only check the - * current page. For page-sequence and document it will - * lookup preceding pages from the area tree and try to find - * a marker. - * If we retrieve a marker from a preceding page, - * then the containing page does not have a qualifying area, - * and all qualifying areas have ended. - * Therefore we use last-ending-within-page (Constants.EN_LEWP) - * as the position. - * - * @param rm the RetrieveMarker instance whose properties are to - * used to find the matching Marker. - * @return a bound RetrieveMarker instance, or null if no Marker - * could be found. - */ - public RetrieveMarker resolveRetrieveMarker(RetrieveMarker rm) { - AreaTreeModel areaTreeModel = areaTreeHandler.getAreaTreeModel(); - String name = rm.getRetrieveClassName(); - int pos = rm.getRetrievePosition(); - int boundary = rm.getRetrieveBoundary(); - - // get marker from the current markers on area tree - Marker mark = (Marker)getCurrentPV().getMarker(name, pos); - if (mark == null && boundary != EN_PAGE) { - // go back over pages until mark found - // if document boundary then keep going - boolean doc = boundary == EN_DOCUMENT; - int seq = areaTreeModel.getPageSequenceCount(); - int page = areaTreeModel.getPageCount(seq) - 1; - while (page < 0 && doc && seq > 1) { - seq--; - page = areaTreeModel.getPageCount(seq) - 1; - } - while (page >= 0) { - PageViewport pv = areaTreeModel.getPage(seq, page); - mark = (Marker)pv.getMarker(name, Constants.EN_LEWP); - if (mark != null) { - break; - } - page--; - if (page < 0 && doc && seq > 1) { - seq--; - page = areaTreeModel.getPageCount(seq) - 1; - } - } - } - - if (mark == null) { - log.debug("found no marker with name: " + name); - return null; - } else { - rm.bindMarker(mark); - return rm; - } - } - - /** - * Makes a new page - * - * @param bIsBlank whether this page is blank or not - * @param bIsLast whether this page is the last page or not - * @return a new page - */ - protected Page makeNewPage(boolean bIsBlank, boolean bIsLast) { - if (curPage != null) { - finishPage(); - } - - currentPageNum++; - - curPage = pageProvider.getPage(bIsBlank, - currentPageNum, PageProvider.RELTO_PAGE_SEQUENCE); - - if (log.isDebugEnabled()) { - log.debug("[" + curPage.getPageViewport().getPageNumberString() - + (bIsBlank ? "*" : "") + "]"); - } - - addIDToPage(pageSeq.getId()); - return curPage; - } - private void layoutSideRegion(int regionID) { SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID); if (reg == null) { return; } - StaticContent sc = pageSeq.getStaticContent(reg.getRegionName()); + StaticContent sc = getPageSequence().getStaticContent(reg.getRegionName()); if (sc == null) { return; } @@ -406,94 +150,15 @@ lm.doLayout(); } - private void finishPage() { - if (log.isTraceEnabled()) { - curPage.getPageViewport().dumpMarkers(); - } + /** {@inheritDoc} */ + protected void finishPage() { // Layout side regions layoutSideRegion(FO_REGION_BEFORE); layoutSideRegion(FO_REGION_AFTER); layoutSideRegion(FO_REGION_START); layoutSideRegion(FO_REGION_END); - // Try to resolve any unresolved IDs for the current page. - // - idTracker.tryIDResolution(curPage.getPageViewport()); - // Queue for ID resolution and rendering - areaTreeHandler.getAreaTreeModel().addPage(curPage.getPageViewport()); - if (log.isDebugEnabled()) { - log.debug("page finished: " + curPage.getPageViewport().getPageNumberString() - + ", current num: " + currentPageNum); - } - curPage = null; + super.finishPage(); } - /** - * Act upon the force-page-count trait, - * in relation to the initial-page-number trait of the following page-sequence. - * @param nextPageSeqInitialPageNumber initial-page-number trait of next page-sequence - */ - public void doForcePageCount(Numeric nextPageSeqInitialPageNumber) { - - int forcePageCount = pageSeq.getForcePageCount(); - - // xsl-spec version 1.0 (15.oct 2001) - // auto | even | odd | end-on-even | end-on-odd | no-force | inherit - // auto: - // Force the last page in this page-sequence to be an odd-page - // if the initial-page-number of the next page-sequence is even. - // Force it to be an even-page - // if the initial-page-number of the next page-sequence is odd. - // If there is no next page-sequence - // or if the value of its initial-page-number is "auto" do not force any page. - - // if force-page-count is auto then set the value of forcePageCount - // depending on the initial-page-number of the next page-sequence - if (nextPageSeqInitialPageNumber != null && forcePageCount == Constants.EN_AUTO) { - if (nextPageSeqInitialPageNumber.getEnum() != 0) { - // auto | auto-odd | auto-even - int nextPageSeqPageNumberType = nextPageSeqInitialPageNumber.getEnum(); - if (nextPageSeqPageNumberType == Constants.EN_AUTO_ODD) { - forcePageCount = Constants.EN_END_ON_EVEN; - } else if (nextPageSeqPageNumberType == Constants.EN_AUTO_EVEN) { - forcePageCount = Constants.EN_END_ON_ODD; - } else { // auto - forcePageCount = Constants.EN_NO_FORCE; - } - } else { // for explicit page number - int nextPageSeqPageStart = nextPageSeqInitialPageNumber.getValue(); - // spec rule - nextPageSeqPageStart = (nextPageSeqPageStart > 0) ? nextPageSeqPageStart : 1; - if (nextPageSeqPageStart % 2 == 0) { // explicit even startnumber - forcePageCount = Constants.EN_END_ON_ODD; - } else { // explicit odd startnumber - forcePageCount = Constants.EN_END_ON_EVEN; - } - } - } - - if (forcePageCount == Constants.EN_EVEN) { - if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have an odd number of pages - curPage = makeNewPage(true, false); - } - } else if (forcePageCount == Constants.EN_ODD) { - if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have an even number of pages - curPage = makeNewPage(true, false); - } - } else if (forcePageCount == Constants.EN_END_ON_EVEN) { - if (currentPageNum % 2 != 0) { // we are now on an odd page - curPage = makeNewPage(true, false); - } - } else if (forcePageCount == Constants.EN_END_ON_ODD) { - if (currentPageNum % 2 == 0) { // we are now on an even page - curPage = makeNewPage(true, false); - } - } else if (forcePageCount == Constants.EN_NO_FORCE) { - // i hope: nothing special at all - } - - if (curPage != null) { - finishPage(); - } - } } Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java?rev=607032&view=auto ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java (added) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java Thu Dec 27 02:34:15 2007 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr; + +import org.apache.fop.datatypes.Numeric; + +/** + * This interface is implemented by top-level layout managers such as the ones for fo:page-sequence + * and fox:external-document. + */ +public interface TopLevelLayoutManager { + + /** + * Activate the layout of this page sequence. + * PageViewports corresponding to each page generated by this + * page sequence will be created and sent to the AreaTreeModel + * for rendering. + */ + public void activateLayout(); + + /** + * Act upon the force-page-count trait, + * in relation to the initial-page-number trait of the following page-sequence. + * @param nextPageSeqInitialPageNumber initial-page-number trait of next page-sequence + */ + public void doForcePageCount(Numeric nextPageSeqInitialPageNumber); + + /** + * Finished the page-sequence and notifies everyone about it. + */ + public void finishPageSequence(); + +} \ No newline at end of file Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TopLevelLayoutManager.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java?rev=607032&r1=607031&r2=607032&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java Thu Dec 27 02:34:15 2007 @@ -19,12 +19,12 @@ package org.apache.fop.layoutmgr.inline; -import java.awt.geom.Rectangle2D; +import java.awt.Dimension; +import java.awt.Rectangle; import java.util.LinkedList; import org.apache.fop.area.Area; import org.apache.fop.area.inline.Viewport; -import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.LengthBase; import org.apache.fop.fo.FObj; import org.apache.fop.fo.flow.AbstractGraphics; @@ -57,180 +57,29 @@ * @return the viewport inline area */ private Viewport getInlineArea() { + Dimension intrinsicSize = new Dimension( + fobj.getIntrinsicWidth(), + fobj.getIntrinsicHeight()); - // viewport size is determined by block-progression-dimension - // and inline-progression-dimension + //TODO Investigate if the line-height property has to be taken into the calculation + //somehow. There was some code here that hints in this direction but it was disabled. - // if replaced then use height then ignore block-progression-dimension - //int h = this.propertyList.get("height").getLength().mvalue(); - - // use specified line-height then ignore dimension in height direction - boolean hasLH = false; //propertyList.get("line-height").getSpecifiedValue() != null; - - Length len; - - int bpd = -1; - int ipd = -1; - if (hasLH) { - bpd = fobj.getLineHeight().getOptimum(this).getLength().getValue(this); - } else { - // this property does not apply when the line-height applies - // isn't the block-progression-dimension always in the same - // direction as the line height? - len = fobj.getBlockProgressionDimension().getOptimum(this).getLength(); - if (len.getEnum() != EN_AUTO) { - bpd = len.getValue(this); - } else { - len = fobj.getHeight(); - if (len.getEnum() != EN_AUTO) { - bpd = len.getValue(this); - } - } - } - - len = fobj.getInlineProgressionDimension().getOptimum(this).getLength(); - if (len.getEnum() != EN_AUTO) { - ipd = len.getValue(this); - } else { - len = fobj.getWidth(); - if (len.getEnum() != EN_AUTO) { - ipd = len.getValue(this); - } - } - - // if auto then use the intrinsic size of the content scaled - // to the content-height and content-width - int cwidth = -1; - int cheight = -1; - len = fobj.getContentWidth(); - if (len.getEnum() != EN_AUTO) { - switch (len.getEnum()) { - case EN_SCALE_TO_FIT: - if (ipd != -1) { - cwidth = ipd; - } - break; - case EN_SCALE_DOWN_TO_FIT: - if (ipd != -1 && fobj.getIntrinsicWidth() > ipd) { - cwidth = ipd; - } - break; - case EN_SCALE_UP_TO_FIT: - if (ipd != -1 && fobj.getIntrinsicWidth() < ipd) { - cwidth = ipd; - } - break; - default: - cwidth = len.getValue(this); - } - } - len = fobj.getContentHeight(); - if (len.getEnum() != EN_AUTO) { - switch (len.getEnum()) { - case EN_SCALE_TO_FIT: - if (bpd != -1) { - cheight = bpd; - } - break; - case EN_SCALE_DOWN_TO_FIT: - if (bpd != -1 && fobj.getIntrinsicHeight() > bpd) { - cheight = bpd; - } - break; - case EN_SCALE_UP_TO_FIT: - if (bpd != -1 && fobj.getIntrinsicHeight() < bpd) { - cheight = bpd; - } - break; - default: - cheight = len.getValue(this); - } - } - - int scaling = fobj.getScaling(); - if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) { - if (cwidth == -1 && cheight == -1) { - cwidth = fobj.getIntrinsicWidth(); - cheight = fobj.getIntrinsicHeight(); - } else if (cwidth == -1) { - if (fobj.getIntrinsicHeight() == 0) { - cwidth = 0; - } else { - cwidth = (int)(fobj.getIntrinsicWidth() * (double)cheight - / fobj.getIntrinsicHeight()); - } - } else if (cheight == -1) { - if (fobj.getIntrinsicWidth() == 0) { - cheight = 0; - } else { - cheight = (int)(fobj.getIntrinsicHeight() * (double)cwidth - / fobj.getIntrinsicWidth()); - } - } else { - // adjust the larger - if (fobj.getIntrinsicWidth() == 0 || fobj.getIntrinsicHeight() == 0) { - cwidth = 0; - cheight = 0; - } else { - double rat1 = (double) cwidth / fobj.getIntrinsicWidth(); - double rat2 = (double) cheight / fobj.getIntrinsicHeight(); - if (rat1 < rat2) { - // reduce cheight - cheight = (int)(rat1 * fobj.getIntrinsicHeight()); - } else if (rat1 > rat2) { - cwidth = (int)(rat2 * fobj.getIntrinsicWidth()); - } - } - } - } - - if (ipd == -1) { - ipd = cwidth; - } - if (bpd == -1) { - bpd = cheight; - } - - boolean clip = false; - if (cwidth > ipd || cheight > bpd) { - int overflow = fobj.getOverflow(); - if (overflow == EN_HIDDEN) { - clip = true; - } else if (overflow == EN_ERROR_IF_OVERFLOW) { - log.error("Object overflows the viewport: clipping"); - clip = true; - } - } - - int xoffset = fobj.computeXOffset(ipd, cwidth); - int yoffset = fobj.computeYOffset(bpd, cheight); + ImageLayout imageLayout = new ImageLayout(fobj, this, intrinsicSize); + Rectangle placement = imageLayout.getPlacement(); CommonBorderPaddingBackground borderProps = fobj.getCommonBorderPaddingBackground(); - //Determine extra BPD from borders etc. + //Determine extra BPD from borders and padding int beforeBPD = borderProps.getPadding(CommonBorderPaddingBackground.BEFORE, false, this); - beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, - false); - int afterBPD = borderProps.getPadding(CommonBorderPaddingBackground.AFTER, false, this); - afterBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.AFTER, false); + beforeBPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.BEFORE, false); - yoffset += beforeBPD; - //bpd += beforeBPD; - //bpd += afterBPD; + placement.y += beforeBPD; - //Determine extra IPD from borders etc. - int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, - false, this); - startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, - false); - int endIPD = borderProps.getPadding(CommonBorderPaddingBackground.END, false, this); - endIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.END, false); + //Determine extra IPD from borders and padding + int startIPD = borderProps.getPadding(CommonBorderPaddingBackground.START, false, this); + startIPD += borderProps.getBorderWidth(CommonBorderPaddingBackground.START, false); - xoffset += startIPD; - //ipd += startIPD; - //ipd += endIPD; - - Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); + placement.x += startIPD; Area viewportArea = getChildArea(); TraitSetter.setProducerID(viewportArea, fobj.getId()); @@ -238,10 +87,10 @@ Viewport vp = new Viewport(viewportArea); TraitSetter.setProducerID(vp, fobj.getId()); - vp.setIPD(ipd); - vp.setBPD(bpd); + vp.setIPD(imageLayout.getViewportSize().width); + vp.setBPD(imageLayout.getViewportSize().height); vp.setContentPosition(placement); - vp.setClip(clip); + vp.setClip(imageLayout.isClipped()); vp.setOffset(0); // Common Border, Padding, and Background Properties @@ -254,9 +103,7 @@ return vp; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { Viewport areaCurrent = getInlineArea(); @@ -264,9 +111,7 @@ return super.getNextKnuthElements(context, alignment); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ protected AlignmentContext makeAlignmentContext(LayoutContext context) { return new AlignmentContext( get(context).getAllocBPD() Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java?rev=607032&view=auto ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java (added) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java Thu Dec 27 02:34:15 2007 @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.layoutmgr.inline; + +import java.awt.Dimension; +import java.awt.Rectangle; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.PercentBaseContext; +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.GraphicsProperties; + +public class ImageLayout implements Constants { + + /** logging instance */ + protected static Log log = LogFactory.getLog(ImageLayout.class); + + //Input + private GraphicsProperties props; + private PercentBaseContext percentBaseContext; + private Dimension intrinsicSize; + + //Output + private Rectangle placement; + private Dimension viewportSize = new Dimension(-1, -1); + private boolean clip; + + public ImageLayout(GraphicsProperties props, PercentBaseContext percentBaseContext, + Dimension intrinsicSize) { + this.props = props; + this.percentBaseContext = percentBaseContext; + this.intrinsicSize = intrinsicSize; + + doLayout(); + } + + protected void doLayout() { + Length len; + + int bpd = -1; + int ipd = -1; + + len = props.getBlockProgressionDimension().getOptimum(percentBaseContext).getLength(); + if (len.getEnum() != EN_AUTO) { + bpd = len.getValue(percentBaseContext); + } else { + len = props.getHeight(); + if (len.getEnum() != EN_AUTO) { + bpd = len.getValue(percentBaseContext); + } + } + + len = props.getInlineProgressionDimension().getOptimum(percentBaseContext).getLength(); + if (len.getEnum() != EN_AUTO) { + ipd = len.getValue(percentBaseContext); + } else { + len = props.getWidth(); + if (len.getEnum() != EN_AUTO) { + ipd = len.getValue(percentBaseContext); + } + } + + // if auto then use the intrinsic size of the content scaled + // to the content-height and content-width + int cwidth = -1; + int cheight = -1; + len = props.getContentWidth(); + if (len.getEnum() != EN_AUTO) { + switch (len.getEnum()) { + case EN_SCALE_TO_FIT: + if (ipd != -1) { + cwidth = ipd; + } + break; + case EN_SCALE_DOWN_TO_FIT: + if (ipd != -1 && intrinsicSize.width > ipd) { + cwidth = ipd; + } + break; + case EN_SCALE_UP_TO_FIT: + if (ipd != -1 && intrinsicSize.width < ipd) { + cwidth = ipd; + } + break; + default: + cwidth = len.getValue(percentBaseContext); + } + } + len = props.getContentHeight(); + if (len.getEnum() != EN_AUTO) { + switch (len.getEnum()) { + case EN_SCALE_TO_FIT: + if (bpd != -1) { + cheight = bpd; + } + break; + case EN_SCALE_DOWN_TO_FIT: + if (bpd != -1 && intrinsicSize.height > bpd) { + cheight = bpd; + } + break; + case EN_SCALE_UP_TO_FIT: + if (bpd != -1 && intrinsicSize.height < bpd) { + cheight = bpd; + } + break; + default: + cheight = len.getValue(percentBaseContext); + } + } + + int scaling = props.getScaling(); + if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) { + if (cwidth == -1 && cheight == -1) { + cwidth = intrinsicSize.width; + cheight = intrinsicSize.height; + } else if (cwidth == -1) { + if (intrinsicSize.height == 0) { + cwidth = 0; + } else { + cwidth = (int)(intrinsicSize.width * (double)cheight + / intrinsicSize.height); + } + } else if (cheight == -1) { + if (intrinsicSize.width == 0) { + cheight = 0; + } else { + cheight = (int)(intrinsicSize.height * (double)cwidth + / intrinsicSize.width); + } + } else { + // adjust the larger + if (intrinsicSize.width == 0 || intrinsicSize.height == 0) { + cwidth = 0; + cheight = 0; + } else { + double rat1 = (double) cwidth / intrinsicSize.width; + double rat2 = (double) cheight / intrinsicSize.height; + if (rat1 < rat2) { + // reduce cheight + cheight = (int)(rat1 * intrinsicSize.height); + } else if (rat1 > rat2) { + cwidth = (int)(rat2 * intrinsicSize.width); + } + } + } + } + + if (ipd == -1) { + ipd = cwidth; + } + if (bpd == -1) { + bpd = cheight; + } + + this.clip = false; + if (cwidth > ipd || cheight > bpd) { + int overflow = props.getOverflow(); + if (overflow == EN_HIDDEN) { + this.clip = true; + } else if (overflow == EN_ERROR_IF_OVERFLOW) { + //TODO Don't use logging to report error! + log.error("Object overflows the viewport: clipping"); + this.clip = true; + } + } + + int xoffset = computeXOffset(ipd, cwidth); + int yoffset = computeYOffset(bpd, cheight); + + //Build calculation results + this.viewportSize.setSize(ipd, bpd); + this.placement = new Rectangle(xoffset, yoffset, cwidth, cheight); + } + + /** + * Given the ipd and the content width calculates the + * required x offset based on the text-align property + * @param ipd the inline-progression-dimension of the object + * @param cwidth the calculated content width of the object + * @return the X offset + */ + public int computeXOffset (int ipd, int cwidth) { + int xoffset = 0; + switch (props.getTextAlign()) { + case EN_CENTER: + xoffset = (ipd - cwidth) / 2; + break; + case EN_END: + xoffset = ipd - cwidth; + break; + case EN_START: + break; + case EN_JUSTIFY: + default: + break; + } + return xoffset; + } + + /** + * Given the bpd and the content height calculates the + * required y offset based on the display-align property + * @param bpd the block-progression-dimension of the object + * @param cheight the calculated content height of the object + * @return the Y offset + */ + public int computeYOffset(int bpd, int cheight) { + int yoffset = 0; + switch (props.getDisplayAlign()) { + case EN_BEFORE: + break; + case EN_AFTER: + yoffset = bpd - cheight; + break; + case EN_CENTER: + yoffset = (bpd - cheight) / 2; + break; + case EN_AUTO: + default: + break; + } + return yoffset; + } + + public Rectangle getPlacement() { + return this.placement; + } + + public Dimension getViewportSize() { + return this.viewportSize; + } + + public Dimension getIntrinsicSize() { + return this.intrinsicSize; + } + + public boolean isClipped() { + return this.clip; + } + +} \ No newline at end of file Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=607032&r1=607031&r2=607032&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java Thu Dec 27 02:34:15 2007 @@ -199,7 +199,8 @@ log.warn("Using default simple-page-master from page-sequence-master..."); PageSequenceMaster master = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference); - this.pagemaster = master.getNextSimplePageMaster(false, false, false, false); + this.pagemaster = master.getNextSimplePageMaster( + false, false, false, false, false); } } Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java?rev=607032&r1=607031&r2=607032&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/xml/XMLRenderer.java Thu Dec 27 02:34:15 2007 @@ -524,7 +524,9 @@ addAttribute("key", page.getKey()); addAttribute("nr", page.getPageNumber()); addAttribute("formatted-nr", page.getPageNumberString()); - addAttribute("simple-page-master-name", page.getSimplePageMasterName()); + if (page.getSimplePageMasterName() != null) { + addAttribute("simple-page-master-name", page.getSimplePageMasterName()); + } if (page.isBlank()) { addAttribute("blank", "true"); } Modified: xmlgraphics/fop/trunk/status.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=607032&r1=607031&r2=607032&view=diff ============================================================================== --- xmlgraphics/fop/trunk/status.xml (original) +++ xmlgraphics/fop/trunk/status.xml Thu Dec 27 02:34:15 2007 @@ -29,6 +29,11 @@ + Added new extension element: fox:external-document. It allows to add whole documents + such as multi-page TIFF images to be inserted as peers to a page-sequence. Each image + will make up an entire page. See the documentation for details. + + Added support for scale-down-to-fit and scale-up-to-fit (introduced in XSL 1.1). Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_1.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_1.xml?rev=607032&view=auto ============================================================================== --- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_1.xml (added) +++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_1.xml Thu Dec 27 02:34:15 2007 @@ -0,0 +1,53 @@ + + + + + +

+ This test checks the basics of fox:external-document. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_1.xml ------------------------------------------------------------------------------ svn:keywords = Id Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_2.xml URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_2.xml?rev=607032&view=auto ============================================================================== --- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_2.xml (added) +++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_2.xml Thu Dec 27 02:34:15 2007 @@ -0,0 +1,81 @@ + + + + + +

+ This test checks fox:external-document. +

+
+ + + + + + + + + + + + Just a normal page-sequence in between... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/fox_external-document_2.xml ------------------------------------------------------------------------------ svn:keywords = Id --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org