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.

HemfPlusExtractorTest.java 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.hemf.hemfplus.extractor;
  16. import static org.junit.Assert.assertEquals;
  17. import java.io.InputStream;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import org.apache.poi.POIDataSamples;
  21. import org.apache.poi.hemf.record.emf.HemfComment.EmfComment;
  22. import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataPlus;
  23. import org.apache.poi.hemf.record.emf.HemfRecord;
  24. import org.apache.poi.hemf.record.emfplus.HemfPlusHeader;
  25. import org.apache.poi.hemf.record.emfplus.HemfPlusRecord;
  26. import org.apache.poi.hemf.record.emfplus.HemfPlusRecordType;
  27. import org.apache.poi.hemf.usermodel.HemfPicture;
  28. import org.junit.Test;
  29. public class HemfPlusExtractorTest {
  30. @Test
  31. public void testBasic() throws Exception {
  32. //test header
  33. EmfCommentDataPlus emfPlus = getCommentRecord("SimpleEMF_windows.emf", 0);
  34. List<HemfPlusRecord> records = emfPlus.getRecords();
  35. assertEquals(1, records.size());
  36. assertEquals(HemfPlusRecordType.header, records.get(0).getEmfPlusRecordType());
  37. HemfPlusHeader header = (HemfPlusHeader)records.get(0);
  38. assertEquals(240, header.getLogicalDpiX());
  39. assertEquals(240, header.getLogicalDpiY());
  40. assertEquals(1, header.getFlags());
  41. assertEquals(1, header.getEmfPlusFlags());
  42. //test that the HemfCommentEMFPlus record at offset 1
  43. //contains 6 HemfCommentEMFPlus records within it
  44. List<HemfPlusRecordType> expected = new ArrayList<>();
  45. expected.add(HemfPlusRecordType.setPixelOffsetMode);
  46. expected.add(HemfPlusRecordType.setAntiAliasMode);
  47. expected.add(HemfPlusRecordType.setCompositingQuality);
  48. expected.add(HemfPlusRecordType.setPageTransform);
  49. expected.add(HemfPlusRecordType.setInterpolationMode);
  50. expected.add(HemfPlusRecordType.getDC);
  51. emfPlus = getCommentRecord("SimpleEMF_windows.emf", 1);
  52. records = emfPlus.getRecords();
  53. assertEquals(expected.size(), records.size());
  54. for (int i = 0; i < expected.size(); i++) {
  55. assertEquals(expected.get(i), records.get(i).getEmfPlusRecordType());
  56. }
  57. }
  58. private EmfCommentDataPlus getCommentRecord(String testFileName, int recordIndex) throws Exception {
  59. EmfCommentDataPlus returnRecord = null;
  60. try (InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream(testFileName)) {
  61. HemfPicture ex = new HemfPicture(is);
  62. int i = 0;
  63. for (HemfRecord record : ex) {
  64. if (i == recordIndex) {
  65. EmfComment commentRecord = ((EmfComment) record);
  66. returnRecord = (EmfCommentDataPlus) commentRecord.getCommentData();
  67. break;
  68. }
  69. i++;
  70. }
  71. }
  72. return returnRecord;
  73. }
  74. }