You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Dan Caprioara (JIRA)" <ji...@apache.org> on 2017/07/26 12:10:00 UTC

[jira] [Commented] (FOP-2731) Position:fixed uses a bad reference area

    [ https://issues.apache.org/jira/browse/FOP-2731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16101599#comment-16101599 ] 

Dan Caprioara commented on FOP-2731:
------------------------------------

Possible fix:

{code}
Index: BlockContainerLayoutManager.java
===================================================================
--- BlockContainerLayoutManager.java	(revision 161373)
+++ BlockContainerLayoutManager.java	(working copy)
@@ -744,7 +744,57 @@
         }
         return new Point(x, y);
     }
+    
+    // PATCH START -  FOP-2731 Using the page as reference for fixed positioning  
+    
+    /**
+     * Gets the offset of the box, when having a position: fixed.
+     * The reference area is the page. 
+     * 
+     * @return The coordinate in the page.
+     */
+    private Point getFixedOffset() {
+        int x = 0;
+        int y = 0;
+        
+        if (abProps.left.getEnum() != EN_AUTO) {
+            x = abProps.left.getValue(this);
+        } else if (abProps.right.getEnum() != EN_AUTO
+                && width.getEnum() != EN_AUTO) {
+            x = getPageWidth()
+                - abProps.right.getValue(this) - width.getValue(this);
+        }
+        if (abProps.top.getEnum() != EN_AUTO) {
+            y = abProps.top.getValue(this);
+        } else if (abProps.bottom.getEnum() != EN_AUTO
+                && height.getEnum() != EN_AUTO) {
+            y = getReferenceAreaForFixedBPD()
+                - abProps.bottom.getValue(this) - height.getValue(this);
+        }
+        return new Point(x, y);
+    }
 
+
+    /**
+     * Gets the width of the page.
+     * 
+     * @return the width of the page.
+     */
+    public int getPageWidth() {
+      return (int) getCurrentPV().getViewArea().getWidth(); 
+    }
+
+    /**
+     * Gets the height of the page.
+     * 
+     * @return the height of the page.
+     */
+    protected int getReferenceAreaForFixedBPD() {
+      return (int) getCurrentPV().getViewArea().getHeight(); 
+    }
+    
+    // PATCH END
+
     /** {@inheritDoc} */
     @Override
     public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
@@ -884,14 +934,29 @@
             viewportBlockArea.setCTM(absoluteCTM);
             viewportBlockArea.setClip(needClip());
 
-            if (abProps.absolutePosition == EN_ABSOLUTE
-                    || abProps.absolutePosition == EN_FIXED) {
+            
+            // PATCH START - FOP-2731 Using the page as reference for fixed positioning  
+
+//            if (abProps.absolutePosition == EN_ABSOLUTE
+//                    || abProps.absolutePosition == EN_FIXED) {
+//                Point offset = getAbsOffset();
+//                viewportBlockArea.setXOffset(offset.x);
+//                viewportBlockArea.setYOffset(offset.y);
+//            } else {
+//                //nop
+//            }
+            if (abProps.absolutePosition == EN_ABSOLUTE) {
                 Point offset = getAbsOffset();
                 viewportBlockArea.setXOffset(offset.x);
                 viewportBlockArea.setYOffset(offset.y);
+            } else if (abProps.absolutePosition == EN_FIXED) {
+                Point offset = getFixedOffset();
+                viewportBlockArea.setXOffset(offset.x);
+                viewportBlockArea.setYOffset(offset.y);
             } else {
                 //nop
             }
+            // PATCH END  
 
             referenceArea = new Block();
             referenceArea.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);

{code}

> Position:fixed uses a bad reference area
> ----------------------------------------
>
>                 Key: FOP-2731
>                 URL: https://issues.apache.org/jira/browse/FOP-2731
>             Project: FOP
>          Issue Type: Bug
>          Components: layout/block
>    Affects Versions: 2.2
>            Reporter: Dan Caprioara
>         Attachments: position-fixed-bad-reference-area.png
>
>
> When trying to place some elements to the corners of the page, it seems that FOP uses some wrong dimensions. Take a look at the attached screenshot, showing the difference between FOP and AntennaHouse.
> {code}
> <?xml version="1.0" encoding="UTF-8"?>
> <fo:root
>     xml:lang="dflt"
>     xmlns:css="http://www.w3.org/1998/CSS"
>     xmlns:fo="http://www.w3.org/1999/XSL/Format">
>     <fo:layout-master-set>
>         <!-- Page: css2fo-default-->
>         <fo:page-sequence-master
>             master-name="css2fo-default">
>             <fo:repeatable-page-master-alternatives>
>                 <fo:conditional-page-master-reference
>                     blank-or-not-blank="any"
>                     master-reference="spm-css2fo-default"
>                     odd-or-even="any"
>                     page-position="any"/>
>             </fo:repeatable-page-master-alternatives>
>         </fo:page-sequence-master>
>         <fo:simple-page-master
>             master-name="spm-css2fo-default"
>             page-height="8.27in"
>             page-width="5.83in">
>             <fo:region-body
>                 border-bottom-color="orange"
>                 border-bottom-style="solid"
>                 border-bottom-width="2pt"
>                 border-left-color="orange"
>                 border-left-style="solid"
>                 border-left-width="2pt"
>                 border-right-color="orange"
>                 border-right-style="solid"
>                 border-right-width="2pt"
>                 border-top-color="orange"
>                 border-top-style="solid"
>                 border-top-width="2pt"
>                 margin-bottom="1in"
>                 margin-left="1in"
>                 margin-right="1in"
>                 margin-top="1in"/>
>             <fo:region-before
>                 extent="1in"
>                 region-name="sc-before"/>
>             <fo:region-after
>                 extent="1in"
>                 region-name="sc-after"/>
>             <fo:region-start
>                 extent="1in"
>                 region-name="sc-start"/>
>             <fo:region-end
>                 extent="1in"
>                 region-name="sc-end"/>
>         </fo:simple-page-master>
>     </fo:layout-master-set>
>     <fo:declarations>
>         <x:xmpmeta
>             xmlns:x="adobe:ns:meta/">
>             <rdf:RDF
>                 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>                 <rdf:Description>
>                     <xmp:CreatorTool
>                         xmlns:xmp="http://ns.adobe.com/xap/1.0/">oXygen PDF Chemistry</xmp:CreatorTool>
>                 </rdf:Description>
>             </rdf:RDF>
>         </x:xmpmeta>
>     </fo:declarations>
>     <fo:page-sequence
>         force-page-count="no-force"
>         id="last-page-sequence"
>         line-height-shift-adjustment="disregard-shifts"
>         master-reference="css2fo-default">
>         <fo:flow
>             flow-name="xsl-region-body">
>             <fo:block
>                 font-family="serif"
>                 font-size="12pt">
>                 <fo:block
>                     font-size="larger"
>                     font-style="oblique">An element with position: fixed is positioned relative to its
>                     page.</fo:block>
>                 <fo:block>1. Normal div.</fo:block>
>                 <fo:block-container
>                     border-bottom-color="red"
>                     border-bottom-style="solid"
>                     border-bottom-width="3pt"
>                     border-left-color="red"
>                     border-left-style="solid"
>                     border-left-width="3pt"
>                     border-right-color="red"
>                     border-right-style="solid"
>                     border-right-width="3pt"
>                     border-top-color="red"
>                     border-top-style="solid"
>                     border-top-width="3pt"
>                     height="100pt"
>                     left="10pt"
>                     position="fixed"
>                     top="10pt"
>                     width="100pt">
>                     <fo:block
>                         end-indent="0"
>                         start-indent="0">Fixed top left.</fo:block>
>                 </fo:block-container>
>                 <fo:block-container
>                     border-bottom-color="red"
>                     border-bottom-style="solid"
>                     border-bottom-width="3pt"
>                     border-left-color="red"
>                     border-left-style="solid"
>                     border-left-width="3pt"
>                     border-right-color="red"
>                     border-right-style="solid"
>                     border-right-width="3pt"
>                     border-top-color="red"
>                     border-top-style="solid"
>                     border-top-width="3pt"
>                     height="100pt"
>                     position="fixed"
>                     right="10pt"
>                     top="10pt"
>                     width="100pt">
>                     <fo:block
>                         end-indent="0"
>                         start-indent="0">Fixed top right.</fo:block>
>                 </fo:block-container>
>                 <fo:block-container
>                     border-bottom-color="red"
>                     border-bottom-style="solid"
>                     border-bottom-width="3pt"
>                     border-left-color="red"
>                     border-left-style="solid"
>                     border-left-width="3pt"
>                     border-right-color="red"
>                     border-right-style="solid"
>                     border-right-width="3pt"
>                     border-top-color="red"
>                     border-top-style="solid"
>                     border-top-width="3pt"
>                     bottom="10pt"
>                     height="100pt"
>                     left="10pt"
>                     position="fixed"
>                     width="100pt">
>                     <fo:block
>                         end-indent="0"
>                         start-indent="0">Fixed bottom left.</fo:block>
>                 </fo:block-container>
>                 <fo:block-container
>                     border-bottom-color="red"
>                     border-bottom-style="solid"
>                     border-bottom-width="3pt"
>                     border-left-color="red"
>                     border-left-style="solid"
>                     border-left-width="3pt"
>                     border-right-color="red"
>                     border-right-style="solid"
>                     border-right-width="3pt"
>                     border-top-color="red"
>                     border-top-style="solid"
>                     border-top-width="3pt"
>                     bottom="10pt"
>                     height="100pt"
>                     position="fixed"
>                     right="10pt"
>                     width="100pt">
>                     <fo:block
>                         end-indent="0"
>                         start-indent="0">Fixed bottom right.</fo:block>
>                 </fo:block-container>
>                 <fo:block>2. Normal div.</fo:block>
>                 <fo:block>3. Normal div.</fo:block>
>             </fo:block>
>         </fo:flow>
>     </fo:page-sequence>
> </fo:root>
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)