<?xml version="1.0" encoding="UTF-8"?>
<!--
  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$ -->
<testcase>
  <info>
    <p>
      This test checks external-graphics with size properties.
    </p>
  </info>
  <fo>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="normal">
        <fo:flow flow-name="xsl-region-body">
          <fo:block>
            <fo:external-graphic src="../resources/images/big-image.png"
                block-progression-dimension.maximum="4in"
                inline-progression-dimension.maximum="auto"
                content-width="scale-down-to-fit" content-height="scale-down-to-fit"
                overflow="hidden" background-color="yellow" id="big1"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/big-image.png"
              block-progression-dimension.maximum="4in"
              inline-progression-dimension.maximum="4in"
              content-width="scale-down-to-fit" content-height="scale-down-to-fit"
              overflow="hidden" scaling="non-uniform" background-color="yellow" id="big2"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/big-image.png"
              block-progression-dimension.maximum="4in"
              inline-progression-dimension.maximum="4in"
              overflow="hidden" background-color="yellow" id="big3"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/box1.png"
              inline-progression-dimension.minimum="1in"
              content-width="scale-to-fit"
              overflow="hidden" background-color="yellow" id="box1"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/box1.png"
              inline-progression-dimension.minimum="1in"
              overflow="hidden" background-color="yellow" id="box2"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/box1.png"
              inline-progression-dimension.minimum="1in"
              inline-progression-dimension.optimum="2in"
              overflow="hidden" background-color="yellow" id="box3"/>
          </fo:block>
          <fo:block>
            <fo:external-graphic src="../resources/images/box1.png"
              inline-progression-dimension.minimum="1in"
              inline-progression-dimension.optimum="2in"
              content-width="scale-up-to-fit"
              overflow="hidden" background-color="yellow" id="box4"/>
          </fo:block>
          <fo:block>EOF</fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </fo>
  <checks>
    <!-- uniform fitting down to the maximum viewport size -->
    <eval expected="203795" xpath="//viewport[@prod-id='big1']/@ipd"/>
    <eval expected="288000" xpath="//viewport[@prod-id='big1']/@bpd"/>
    <eval expected="0 0 203795 288000" xpath="//viewport[@prod-id='big1']/@pos"/>

    <!-- non-uniform fitting -->
    <eval expected="288000" xpath="//viewport[@prod-id='big2']/@ipd"/>
    <eval expected="288000" xpath="//viewport[@prod-id='big2']/@bpd"/>
    <eval expected="0 0 288000 288000" xpath="//viewport[@prod-id='big2']/@pos"/>
    
    <!-- content is clipped -->
    <eval expected="288000" xpath="//viewport[@prod-id='big3']/@ipd"/>
    <eval expected="288000" xpath="//viewport[@prod-id='big3']/@bpd"/>
    <eval expected="0 0 597172 843913" xpath="//viewport[@prod-id='big3']/@pos"/>
    <eval expected="true" xpath="//viewport[@prod-id='big3']/@clip"/>

    <!-- uniform fitting up to the minimum viewport size -->
    <eval expected="72000" xpath="//viewport[@prod-id='box1']/@ipd"/>
    <eval expected="72000" xpath="//viewport[@prod-id='box1']/@bpd"/>
    <eval expected="0 0 72000 72000" xpath="//viewport[@prod-id='box1']/@pos"/>

    <!-- minimum viewport but not fitting -->
    <eval expected="72000" xpath="//viewport[@prod-id='box2']/@ipd"/>
    <eval expected="40009" xpath="//viewport[@prod-id='box2']/@bpd"/>
    <eval expected="0 0 40009 40009" xpath="//viewport[@prod-id='box2']/@pos"/>

    <!-- minimum/optimum viewport but not fitting -->
    <eval expected="144000" xpath="//viewport[@prod-id='box3']/@ipd"/>
    <eval expected="40009" xpath="//viewport[@prod-id='box3']/@bpd"/>
    <eval expected="0 0 40009 40009" xpath="//viewport[@prod-id='box3']/@pos"/>
            
    <!-- minimum/optimum viewport with fitting -->
    <eval expected="144000" xpath="//viewport[@prod-id='box4']/@ipd"/>
    <eval expected="144000" xpath="//viewport[@prod-id='box4']/@bpd"/>
    <eval expected="0 0 144000 144000" xpath="//viewport[@prod-id='box4']/@pos"/>
            
  </checks>
</testcase>
