Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.usermodel;
  16. import static org.junit.Assert.assertEquals;
  17. import java.awt.Dimension;
  18. import java.io.FileOutputStream;
  19. import org.apache.poi.ss.ITestDataProvider;
  20. import org.apache.poi.ss.util.ImageUtils;
  21. import org.apache.poi.util.Units;
  22. /**
  23. * @author Yegor Kozlov
  24. */
  25. public abstract class BaseTestPicture {
  26. private final ITestDataProvider _testDataProvider;
  27. protected BaseTestPicture(ITestDataProvider testDataProvider) {
  28. _testDataProvider = testDataProvider;
  29. }
  30. public void baseTestResize(Picture input, Picture compare, double scaleX, double scaleY) {
  31. input.resize(scaleX, scaleY);
  32. ClientAnchor inpCA = input.getClientAnchor();
  33. ClientAnchor cmpCA = compare.getClientAnchor();
  34. Dimension inpDim = ImageUtils.getDimensionFromAnchor(input);
  35. Dimension cmpDim = ImageUtils.getDimensionFromAnchor(compare);
  36. double emuPX = Units.EMU_PER_PIXEL;
  37. assertEquals("the image height differs", inpDim.getHeight(), cmpDim.getHeight(), emuPX*6);
  38. assertEquals("the image width differs", inpDim.getWidth(), cmpDim.getWidth(), emuPX*6);
  39. assertEquals("the starting column differs", inpCA.getCol1(), cmpCA.getCol1());
  40. assertEquals("the column x-offset differs", inpCA.getDx1(), cmpCA.getDx1(), 1);
  41. assertEquals("the column y-offset differs", inpCA.getDy1(), cmpCA.getDy1(), 1);
  42. assertEquals("the ending columns differs", inpCA.getCol2(), cmpCA.getCol2());
  43. // can't compare row heights because of variable test heights
  44. input.resize();
  45. inpDim = ImageUtils.getDimensionFromAnchor(input);
  46. Dimension imgDim = input.getImageDimension();
  47. assertEquals("the image height differs", imgDim.getHeight(), inpDim.getHeight()/emuPX, 1);
  48. assertEquals("the image width differs", imgDim.getWidth(), inpDim.getWidth()/emuPX, 1);
  49. }
  50. }