|
| 1 | +/* |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | + contributor license agreements. See the NOTICE file distributed with |
| 5 | + this work for additional information regarding copyright ownership. |
| 6 | + The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | + (the "License"); you may not use this file except in compliance with |
| 8 | + the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +
|
| 18 | + */ |
| 19 | +package org.apache.batik.bridge; |
| 20 | + |
| 21 | +import org.apache.xmlgraphics.util.UnitConv; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import static org.junit.Assert.assertEquals; |
| 25 | + |
| 26 | +public class UserAgentAdapterTestCase { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testEqualResolution_72() { |
| 30 | + checkGetMediumFontSize(72f, 72f, 9f); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testEqualResolution_96() { |
| 35 | + checkGetMediumFontSize(96f, 96f, 9f); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testDiffResolution_72_96() { |
| 40 | + checkGetMediumFontSize(72f, 96f, 6.74f); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testDiffResolution_96_72() { |
| 45 | + checkGetMediumFontSize(96f, 72f, 12f); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testPixelMM_72() { |
| 50 | + checkGetPixelUnitToMillimeter(72f, 72f); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testPixelMM_96() { checkGetPixelUnitToMillimeter(96f, 96f); } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testPixelMM_72_96() { checkGetPixelUnitToMillimeter(72f, 96f); } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testPixelMM_96_72() { |
| 61 | + checkGetPixelUnitToMillimeter(96f, 72f); |
| 62 | + } |
| 63 | + |
| 64 | + private void checkGetMediumFontSize(float sourceRes, float targetRes, float expectedSize) { |
| 65 | + UserAgentAdapter adapter = new UserAgentAdapter(); |
| 66 | + adapter.setSourceResolution(sourceRes); |
| 67 | + adapter.setTargetResolution(targetRes); |
| 68 | + |
| 69 | + // Size must be calculated based on the dpi settings |
| 70 | + assertEquals(expectedSize, adapter.getMediumFontSize(), 0.01); |
| 71 | + } |
| 72 | + |
| 73 | + private void checkGetPixelUnitToMillimeter(float sourceRes, float targetRes) { |
| 74 | + UserAgentAdapter adapter = new UserAgentAdapter(); |
| 75 | + adapter.setSourceResolution(sourceRes); |
| 76 | + adapter.setTargetResolution(targetRes); |
| 77 | + |
| 78 | + // Pixel unit to mm must be calculated using the resolution set in the conf |
| 79 | + // instead of assuming what the resolution is |
| 80 | + assertEquals(UnitConv.IN2MM / sourceRes, adapter.getPixelUnitToMillimeter(), 0.01); |
| 81 | + } |
| 82 | +} |
0 commit comments