You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractPathOrientedRendererTestCase.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render;
  19. import java.awt.Color;
  20. import java.awt.Rectangle;
  21. import java.awt.geom.AffineTransform;
  22. import java.awt.geom.Rectangle2D;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import static org.junit.Assert.assertEquals;
  28. import static org.mockito.Mockito.mock;
  29. import org.apache.xmlgraphics.image.loader.ImageInfo;
  30. import org.apache.xmlgraphics.image.loader.ImageSize;
  31. import org.apache.fop.apps.FOUserAgent;
  32. import org.apache.fop.area.CTM;
  33. import org.apache.fop.area.Trait;
  34. public class AbstractPathOrientedRendererTestCase {
  35. @Before
  36. public void setUp() throws Exception {
  37. }
  38. @Test
  39. public void testDrawBackgroundWithTargetImageSizes() {
  40. FOUserAgent userAgent = mock(FOUserAgent.class);
  41. MyAPOR myAPOR = new MyAPOR(userAgent);
  42. ImageSize imgSize = new ImageSize(300, 300, 300);
  43. imgSize.setSizeInMillipoints(72000, 72000);
  44. ImageInfo imgInfo = new ImageInfo(null, null);
  45. imgInfo.setSize(imgSize);
  46. Trait.Background background = new Trait.Background();
  47. background.setImageTargetWidth(300000);
  48. background.setImageTargetHeight(300000);
  49. background.setImageInfo(imgInfo);
  50. myAPOR.drawBackground(0, 0, 600, 900, background, null, null, null, null);
  51. String expected = "[x=0.0,y=0.0,w=3.0,h=3.0][x=0.0,y=3.0,w=3.0,h=3.0][x=0.0,y=6.0,w=3.0,h=3.0]"
  52. + "[x=0.0,y=9.0,w=3.0,h=3.0][x=3.0,y=0.0,w=3.0,h=3.0][x=3.0,y=3.0,w=3.0,h=3.0]"
  53. + "[x=3.0,y=6.0,w=3.0,h=3.0][x=3.0,y=9.0,w=3.0,h=3.0][x=6.0,y=0.0,w=3.0,h=3.0]"
  54. + "[x=6.0,y=3.0,w=3.0,h=3.0][x=6.0,y=6.0,w=3.0,h=3.0][x=6.0,y=9.0,w=3.0,h=3.0]";
  55. assertEquals(expected, myAPOR.getActual().replaceAll("00000", ""));
  56. myAPOR.resetActual();
  57. background.setImageTargetWidth(0);
  58. myAPOR.drawBackground(0, 0, 600, 900, background, null, null, null, null);
  59. assertEquals(expected, myAPOR.getActual().replaceAll("00000", ""));
  60. myAPOR.resetActual();
  61. background.setImageTargetWidth(300000);
  62. background.setImageTargetHeight(0);
  63. myAPOR.drawBackground(0, 0, 600, 900, background, null, null, null, null);
  64. assertEquals(expected, myAPOR.getActual().replaceAll("00000", ""));
  65. }
  66. private class MyAPOR extends AbstractPathOrientedRenderer {
  67. private String actual = "";
  68. public MyAPOR(FOUserAgent userAgent) {
  69. super(userAgent);
  70. }
  71. public String getActual() {
  72. return actual;
  73. }
  74. public void resetActual() {
  75. actual = "";
  76. }
  77. public String getMimeType() {
  78. return null;
  79. }
  80. protected void concatenateTransformationMatrix(AffineTransform at) {
  81. }
  82. protected void restoreStateStackAfterBreakOut(List breakOutList) {
  83. }
  84. protected List breakOutOfStateStack() {
  85. return null;
  86. }
  87. protected void saveGraphicsState() {
  88. }
  89. protected void restoreGraphicsState() {
  90. }
  91. protected void beginTextObject() {
  92. }
  93. protected void endTextObject() {
  94. }
  95. protected void clip() {
  96. }
  97. protected void clipRect(float x, float y, float width, float height) {
  98. }
  99. protected void moveTo(float x, float y) {
  100. }
  101. protected void lineTo(float x, float y) {
  102. }
  103. protected void closePath() {
  104. }
  105. protected void fillRect(float x, float y, float width, float height) {
  106. }
  107. protected void updateColor(Color col, boolean fill) {
  108. }
  109. protected void drawImage(String url, Rectangle2D pos, Map foreignAttributes) {
  110. String s = pos.toString();
  111. actual += s.substring(s.indexOf('['));
  112. }
  113. protected void drawBorderLine(float x1, float y1, float x2, float y2, boolean horz,
  114. boolean startOrBefore, int style, Color col) {
  115. }
  116. protected void startVParea(CTM ctm, Rectangle clippingRect) {
  117. }
  118. protected void endVParea() {
  119. }
  120. protected void startLayer(String layer) {
  121. }
  122. protected void endLayer() {
  123. }
  124. }
  125. }