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.

HemfWindowing.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.record.emf;
  16. import static org.apache.poi.hemf.record.emf.HemfDraw.readDimensionInt;
  17. import static org.apache.poi.hemf.record.emf.HemfDraw.readPointL;
  18. import static org.apache.poi.hwmf.record.HwmfDraw.normalizeBounds;
  19. import java.io.IOException;
  20. import org.apache.poi.hemf.draw.HemfDrawProperties;
  21. import org.apache.poi.hemf.draw.HemfGraphics;
  22. import org.apache.poi.hwmf.record.HwmfRegionMode;
  23. import org.apache.poi.hwmf.record.HwmfWindowing;
  24. import org.apache.poi.util.LittleEndianConsts;
  25. import org.apache.poi.util.LittleEndianInputStream;
  26. public class HemfWindowing {
  27. /**
  28. * The EMR_SETWINDOWEXTEX record defines the window extent.
  29. */
  30. public static class EmfSetWindowExtEx extends HwmfWindowing.WmfSetWindowExt implements HemfRecord {
  31. @Override
  32. public HemfRecordType getEmfRecordType() {
  33. return HemfRecordType.setWindowExtEx;
  34. }
  35. @Override
  36. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  37. return readDimensionInt(leis, size);
  38. }
  39. }
  40. /**
  41. * The EMR_SETWINDOWORGEX record defines the window origin.
  42. */
  43. public static class EmfSetWindowOrgEx extends HwmfWindowing.WmfSetWindowOrg implements HemfRecord {
  44. @Override
  45. public HemfRecordType getEmfRecordType() {
  46. return HemfRecordType.setWindowOrgEx;
  47. }
  48. @Override
  49. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  50. return readPointL(leis, origin);
  51. }
  52. }
  53. /**
  54. * The EMR_SETVIEWPORTEXTEX record defines the viewport extent.
  55. */
  56. public static class EmfSetViewportExtEx extends HwmfWindowing.WmfSetViewportExt implements HemfRecord {
  57. @Override
  58. public HemfRecordType getEmfRecordType() {
  59. return HemfRecordType.setViewportExtEx;
  60. }
  61. @Override
  62. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  63. return readDimensionInt(leis, extents);
  64. }
  65. }
  66. /**
  67. * The EMR_SETVIEWPORTORGEX record defines the viewport origin.
  68. */
  69. public static class EmfSetViewportOrgEx extends HwmfWindowing.WmfSetViewportOrg implements HemfRecord {
  70. @Override
  71. public HemfRecordType getEmfRecordType() {
  72. return HemfRecordType.setViewportOrgEx;
  73. }
  74. @Override
  75. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  76. return readPointL(leis, origin);
  77. }
  78. }
  79. /**
  80. * The EMR_OFFSETCLIPRGN record moves the current clipping region in the playback device context
  81. * by the specified offsets.
  82. */
  83. public static class EmfSetOffsetClipRgn extends HwmfWindowing.WmfOffsetClipRgn implements HemfRecord {
  84. @Override
  85. public HemfRecordType getEmfRecordType() {
  86. return HemfRecordType.setOffsetClipRgn;
  87. }
  88. @Override
  89. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  90. return readPointL(leis, offset);
  91. }
  92. }
  93. /**
  94. * The EMR_EXCLUDECLIPRECT record specifies a new clipping region that consists of the existing
  95. * clipping region minus the specified rectangle.
  96. */
  97. public static class EmfSetExcludeClipRect extends HwmfWindowing.WmfExcludeClipRect implements HemfRecord {
  98. @Override
  99. public HemfRecordType getEmfRecordType() {
  100. return HemfRecordType.setExcludeClipRect;
  101. }
  102. @Override
  103. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  104. return HemfDraw.readRectL(leis, bounds);
  105. }
  106. }
  107. /**
  108. * The EMR_INTERSECTCLIPRECT record specifies a new clipping region from the intersection of the
  109. * current clipping region and the specified rectangle.
  110. */
  111. public static class EmfSetIntersectClipRect extends HwmfWindowing.WmfIntersectClipRect implements HemfRecord {
  112. @Override
  113. public HemfRecordType getEmfRecordType() {
  114. return HemfRecordType.setIntersectClipRect;
  115. }
  116. @Override
  117. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  118. return HemfDraw.readRectL(leis, normalizeBounds(bounds));
  119. }
  120. }
  121. /**
  122. * The EMR_SCALEVIEWPORTEXTEX record respecifies the viewport for a device context by using the
  123. * ratios formed by the specified multiplicands and divisors.
  124. */
  125. public static class EmfScaleViewportExtEx extends HwmfWindowing.WmfScaleViewportExt implements HemfRecord {
  126. @Override
  127. public HemfRecordType getEmfRecordType() {
  128. return HemfRecordType.scaleViewportExtEx;
  129. }
  130. @Override
  131. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  132. double xNum = leis.readInt();
  133. double xDenom = leis.readInt();
  134. double yNum = leis.readInt();
  135. double yDenom = leis.readInt();
  136. scale.setSize(xNum / xDenom, yNum / yDenom);
  137. return 4*LittleEndianConsts.INT_SIZE;
  138. }
  139. }
  140. /**
  141. * The EMR_SCALEWINDOWEXTEX record respecifies the window for a playback device context by
  142. * using the ratios formed by the specified multiplicands and divisors.
  143. */
  144. public static class EmfScaleWindowExtEx extends HwmfWindowing.WmfScaleWindowExt implements HemfRecord {
  145. @Override
  146. public HemfRecordType getEmfRecordType() {
  147. return HemfRecordType.scaleWindowExtEx;
  148. }
  149. @Override
  150. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  151. double xNum = leis.readInt();
  152. double xDenom = leis.readInt();
  153. double yNum = leis.readInt();
  154. double yDenom = leis.readInt();
  155. scale.setSize(xNum / xDenom, yNum / yDenom);
  156. return 4*LittleEndianConsts.INT_SIZE;
  157. }
  158. }
  159. /**
  160. * The EMR_SELECTCLIPPATH record specifies the current path as a clipping region for a playback
  161. * device context, combining the new region with any existing clipping region using the specified mode.
  162. */
  163. public static class EmfSelectClipPath implements HemfRecord {
  164. protected HwmfRegionMode regionMode;
  165. @Override
  166. public HemfRecordType getEmfRecordType() {
  167. return HemfRecordType.selectClipPath;
  168. }
  169. @Override
  170. public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
  171. // A 32-bit unsigned integer that specifies the way to use the path.
  172. // The value MUST be in the RegionMode enumeration
  173. regionMode = HwmfRegionMode.valueOf(leis.readInt());
  174. return LittleEndianConsts.INT_SIZE;
  175. }
  176. @Override
  177. public void draw(HemfGraphics ctx) {
  178. HemfDrawProperties prop = ctx.getProperties();
  179. ctx.setClip(prop.getPath(), regionMode, false);
  180. }
  181. @Override
  182. public String toString() {
  183. return "{ regionMode: '"+regionMode+"' }";
  184. }
  185. }
  186. }