emf 0.2.0-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (448) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +24 -0
  3. data/README.adoc +341 -0
  4. data/exe/emf +125 -0
  5. data/lib/emf/backend.rb +60 -0
  6. data/lib/emf/binary/class_field_accessors.rb +49 -0
  7. data/lib/emf/binary/codec.rb +19 -0
  8. data/lib/emf/binary/float32_le.rb +54 -0
  9. data/lib/emf/binary/types.rb +139 -0
  10. data/lib/emf/binary.rb +10 -0
  11. data/lib/emf/conformance/context.rb +36 -0
  12. data/lib/emf/conformance/diagnostic.rb +18 -0
  13. data/lib/emf/conformance/manifest/emf_bitmap_misc.yml +622 -0
  14. data/lib/emf/conformance/manifest/emf_control_buffers.yml +61 -0
  15. data/lib/emf/conformance/manifest/emf_core.yml +117 -0
  16. data/lib/emf/conformance/manifest/emf_corpus_rules.yml +21 -0
  17. data/lib/emf/conformance/manifest/emf_objects_geometry.yml +229 -0
  18. data/lib/emf/conformance/manifest/emf_plus.yml +357 -0
  19. data/lib/emf/conformance/manifest/emf_plus_core.yml +33 -0
  20. data/lib/emf/conformance/manifest/emf_state_path.yml +403 -0
  21. data/lib/emf/conformance/manifest/emf_text.yml +97 -0
  22. data/lib/emf/conformance/manifest/wmf.yml +874 -0
  23. data/lib/emf/conformance/manifest.rb +79 -0
  24. data/lib/emf/conformance/profile.rb +35 -0
  25. data/lib/emf/conformance/record_types.rb +24 -0
  26. data/lib/emf/conformance/registry.rb +76 -0
  27. data/lib/emf/conformance/report.rb +83 -0
  28. data/lib/emf/conformance/rule.rb +16 -0
  29. data/lib/emf/conformance/rules/emf_bitmap.rb +357 -0
  30. data/lib/emf/conformance/rules/emf_comment_escape.rb +309 -0
  31. data/lib/emf/conformance/rules/emf_control_buffers.rb +137 -0
  32. data/lib/emf/conformance/rules/emf_corpus_named.rb +83 -0
  33. data/lib/emf/conformance/rules/emf_framing.rb +94 -0
  34. data/lib/emf/conformance/rules/emf_geometry.rb +282 -0
  35. data/lib/emf/conformance/rules/emf_header.rb +114 -0
  36. data/lib/emf/conformance/rules/emf_objects.rb +291 -0
  37. data/lib/emf/conformance/rules/emf_parse_recovery.rb +97 -0
  38. data/lib/emf/conformance/rules/emf_path_clip.rb +165 -0
  39. data/lib/emf/conformance/rules/emf_plus.rb +75 -0
  40. data/lib/emf/conformance/rules/emf_plus_common.rb +58 -0
  41. data/lib/emf/conformance/rules/emf_plus_drawing.rb +78 -0
  42. data/lib/emf/conformance/rules/emf_plus_effects.rb +104 -0
  43. data/lib/emf/conformance/rules/emf_plus_fields.rb +169 -0
  44. data/lib/emf/conformance/rules/emf_plus_fields_b.rb +102 -0
  45. data/lib/emf/conformance/rules/emf_plus_framing.rb +172 -0
  46. data/lib/emf/conformance/rules/emf_plus_objects.rb +97 -0
  47. data/lib/emf/conformance/rules/emf_plus_payloads.rb +320 -0
  48. data/lib/emf/conformance/rules/emf_plus_properties.rb +96 -0
  49. data/lib/emf/conformance/rules/emf_plus_state.rb +77 -0
  50. data/lib/emf/conformance/rules/emf_state.rb +244 -0
  51. data/lib/emf/conformance/rules/emf_text.rb +221 -0
  52. data/lib/emf/conformance/rules/emf_transform.rb +85 -0
  53. data/lib/emf/conformance/rules/wmf_buffers.rb +259 -0
  54. data/lib/emf/conformance/rules/wmf_framing.rb +146 -0
  55. data/lib/emf/conformance/rules/wmf_layout_records.rb +112 -0
  56. data/lib/emf/conformance/rules/wmf_objects.rb +168 -0
  57. data/lib/emf/conformance/rules/wmf_records.rb +191 -0
  58. data/lib/emf/conformance/rules/wmf_rejections.rb +184 -0
  59. data/lib/emf/conformance/runner.rb +61 -0
  60. data/lib/emf/conformance/ternary_raster_operations.rb +52 -0
  61. data/lib/emf/conformance.rb +31 -0
  62. data/lib/emf/detector.rb +58 -0
  63. data/lib/emf/emf_plus/binary.rb +8 -0
  64. data/lib/emf/emf_plus/effects/blur.rb +24 -0
  65. data/lib/emf/emf_plus/effects/brightness_contrast.rb +22 -0
  66. data/lib/emf/emf_plus/effects/color_balance.rb +24 -0
  67. data/lib/emf/emf_plus/effects/color_curve.rb +24 -0
  68. data/lib/emf/emf_plus/effects/color_lookup_table.rb +26 -0
  69. data/lib/emf/emf_plus/effects/color_matrix.rb +23 -0
  70. data/lib/emf/emf_plus/effects/effect.rb +50 -0
  71. data/lib/emf/emf_plus/effects/hue_saturation_lightness.rb +24 -0
  72. data/lib/emf/emf_plus/effects/levels.rb +24 -0
  73. data/lib/emf/emf_plus/effects/opaque.rb +19 -0
  74. data/lib/emf/emf_plus/effects/red_eye_correction.rb +35 -0
  75. data/lib/emf/emf_plus/effects/sharpen.rb +24 -0
  76. data/lib/emf/emf_plus/effects/tint.rb +22 -0
  77. data/lib/emf/emf_plus/effects.rb +45 -0
  78. data/lib/emf/emf_plus/frame.rb +41 -0
  79. data/lib/emf/emf_plus/links/effect_link.rb +16 -0
  80. data/lib/emf/emf_plus/links/get_dc_span.rb +18 -0
  81. data/lib/emf/emf_plus/links/link_error.rb +15 -0
  82. data/lib/emf/emf_plus/links.rb +77 -0
  83. data/lib/emf/emf_plus/object_chain.rb +108 -0
  84. data/lib/emf/emf_plus/object_table.rb +182 -0
  85. data/lib/emf/emf_plus/objects/brush.rb +296 -0
  86. data/lib/emf/emf_plus/objects/custom_line_cap.rb +106 -0
  87. data/lib/emf/emf_plus/objects/font.rb +47 -0
  88. data/lib/emf/emf_plus/objects/image.rb +68 -0
  89. data/lib/emf/emf_plus/objects/image_attributes.rb +28 -0
  90. data/lib/emf/emf_plus/objects/opaque.rb +19 -0
  91. data/lib/emf/emf_plus/objects/parts.rb +103 -0
  92. data/lib/emf/emf_plus/objects/path.rb +21 -0
  93. data/lib/emf/emf_plus/objects/pen.rb +132 -0
  94. data/lib/emf/emf_plus/objects/region.rb +39 -0
  95. data/lib/emf/emf_plus/objects/string_format.rb +55 -0
  96. data/lib/emf/emf_plus/objects/typed.rb +50 -0
  97. data/lib/emf/emf_plus/objects.rb +46 -0
  98. data/lib/emf/emf_plus/parser.rb +75 -0
  99. data/lib/emf/emf_plus/records/base.rb +107 -0
  100. data/lib/emf/emf_plus/records/begin_container.rb +31 -0
  101. data/lib/emf/emf_plus/records/begin_container_no_params.rb +20 -0
  102. data/lib/emf/emf_plus/records/body.rb +16 -0
  103. data/lib/emf/emf_plus/records/clear.rb +22 -0
  104. data/lib/emf/emf_plus/records/clip_transform_flags.rb +26 -0
  105. data/lib/emf/emf_plus/records/comment.rb +21 -0
  106. data/lib/emf/emf_plus/records/draw_arc.rb +33 -0
  107. data/lib/emf/emf_plus/records/draw_beziers.rb +31 -0
  108. data/lib/emf/emf_plus/records/draw_closed_curve.rb +34 -0
  109. data/lib/emf/emf_plus/records/draw_curve.rb +38 -0
  110. data/lib/emf/emf_plus/records/draw_driver_string.rb +61 -0
  111. data/lib/emf/emf_plus/records/draw_ellipse.rb +28 -0
  112. data/lib/emf/emf_plus/records/draw_image.rb +42 -0
  113. data/lib/emf/emf_plus/records/draw_image_points.rb +62 -0
  114. data/lib/emf/emf_plus/records/draw_lines.rb +34 -0
  115. data/lib/emf/emf_plus/records/draw_path.rb +23 -0
  116. data/lib/emf/emf_plus/records/draw_pie.rb +33 -0
  117. data/lib/emf/emf_plus/records/draw_rects.rb +30 -0
  118. data/lib/emf/emf_plus/records/draw_string.rb +41 -0
  119. data/lib/emf/emf_plus/records/end_container.rb +20 -0
  120. data/lib/emf/emf_plus/records/end_of_file.rb +17 -0
  121. data/lib/emf/emf_plus/records/fill_brush.rb +21 -0
  122. data/lib/emf/emf_plus/records/fill_closed_curve.rb +38 -0
  123. data/lib/emf/emf_plus/records/fill_ellipse.rb +29 -0
  124. data/lib/emf/emf_plus/records/fill_path.rb +23 -0
  125. data/lib/emf/emf_plus/records/fill_pie.rb +34 -0
  126. data/lib/emf/emf_plus/records/fill_polygon.rb +32 -0
  127. data/lib/emf/emf_plus/records/fill_rects.rb +31 -0
  128. data/lib/emf/emf_plus/records/fill_region.rb +23 -0
  129. data/lib/emf/emf_plus/records/get_dc.rb +18 -0
  130. data/lib/emf/emf_plus/records/header.rb +35 -0
  131. data/lib/emf/emf_plus/records/multiply_world_transform.rb +24 -0
  132. data/lib/emf/emf_plus/records/object.rb +32 -0
  133. data/lib/emf/emf_plus/records/offset_clip.rb +24 -0
  134. data/lib/emf/emf_plus/records/primitives/argb.rb +20 -0
  135. data/lib/emf/emf_plus/records/primitives/bitmap.rb +32 -0
  136. data/lib/emf/emf_plus/records/primitives/bitmap_data.rb +21 -0
  137. data/lib/emf/emf_plus/records/primitives/blend_colors.rb +22 -0
  138. data/lib/emf/emf_plus/records/primitives/blend_factors.rb +21 -0
  139. data/lib/emf/emf_plus/records/primitives/bounded_array.rb +38 -0
  140. data/lib/emf/emf_plus/records/primitives/byte_reader.rb +25 -0
  141. data/lib/emf/emf_plus/records/primitives/character_range.rb +20 -0
  142. data/lib/emf/emf_plus/records/primitives/compressed_image.rb +17 -0
  143. data/lib/emf/emf_plus/records/primitives/focus_scale_data.rb +20 -0
  144. data/lib/emf/emf_plus/records/primitives/graphics_version.rb +21 -0
  145. data/lib/emf/emf_plus/records/primitives/language_identifier.rb +22 -0
  146. data/lib/emf/emf_plus/records/primitives/metafile.rb +19 -0
  147. data/lib/emf/emf_plus/records/primitives/palette.rb +21 -0
  148. data/lib/emf/emf_plus/records/primitives/path.rb +89 -0
  149. data/lib/emf/emf_plus/records/primitives/path_point_type.rb +21 -0
  150. data/lib/emf/emf_plus/records/primitives/path_point_type_rle.rb +23 -0
  151. data/lib/emf/emf_plus/records/primitives/point.rb +18 -0
  152. data/lib/emf/emf_plus/records/primitives/point_array.rb +42 -0
  153. data/lib/emf/emf_plus/records/primitives/point_f.rb +19 -0
  154. data/lib/emf/emf_plus/records/primitives/point_r.rb +19 -0
  155. data/lib/emf/emf_plus/records/primitives/rect.rb +20 -0
  156. data/lib/emf/emf_plus/records/primitives/rect_array.rb +24 -0
  157. data/lib/emf/emf_plus/records/primitives/rect_f.rb +21 -0
  158. data/lib/emf/emf_plus/records/primitives/region_node.rb +68 -0
  159. data/lib/emf/emf_plus/records/primitives/region_node_child_nodes.rb +22 -0
  160. data/lib/emf/emf_plus/records/primitives/region_node_path.rb +37 -0
  161. data/lib/emf/emf_plus/records/primitives/relative_coordinate.rb +32 -0
  162. data/lib/emf/emf_plus/records/primitives/string_format_data.rb +23 -0
  163. data/lib/emf/emf_plus/records/primitives/transform_matrix.rb +23 -0
  164. data/lib/emf/emf_plus/records/primitives.rb +41 -0
  165. data/lib/emf/emf_plus/records/reset_clip.rb +17 -0
  166. data/lib/emf/emf_plus/records/reset_world_transform.rb +17 -0
  167. data/lib/emf/emf_plus/records/restore.rb +20 -0
  168. data/lib/emf/emf_plus/records/rotate_world_transform.rb +24 -0
  169. data/lib/emf/emf_plus/records/save.rb +20 -0
  170. data/lib/emf/emf_plus/records/scale_world_transform.rb +26 -0
  171. data/lib/emf/emf_plus/records/serializable_object.rb +32 -0
  172. data/lib/emf/emf_plus/records/set_anti_alias_mode.rb +25 -0
  173. data/lib/emf/emf_plus/records/set_clip_path.rb +20 -0
  174. data/lib/emf/emf_plus/records/set_clip_rect.rb +24 -0
  175. data/lib/emf/emf_plus/records/set_clip_region.rb +20 -0
  176. data/lib/emf/emf_plus/records/set_compositing_mode.rb +21 -0
  177. data/lib/emf/emf_plus/records/set_compositing_quality.rb +21 -0
  178. data/lib/emf/emf_plus/records/set_interpolation_mode.rb +21 -0
  179. data/lib/emf/emf_plus/records/set_page_transform.rb +25 -0
  180. data/lib/emf/emf_plus/records/set_pixel_offset_mode.rb +21 -0
  181. data/lib/emf/emf_plus/records/set_rendering_origin.rb +22 -0
  182. data/lib/emf/emf_plus/records/set_text_contrast.rb +24 -0
  183. data/lib/emf/emf_plus/records/set_text_rendering_hint.rb +21 -0
  184. data/lib/emf/emf_plus/records/set_ts_clip.rb +40 -0
  185. data/lib/emf/emf_plus/records/set_ts_graphics.rb +88 -0
  186. data/lib/emf/emf_plus/records/set_world_transform.rb +22 -0
  187. data/lib/emf/emf_plus/records/shape_flags.rb +23 -0
  188. data/lib/emf/emf_plus/records/translate_world_transform.rb +26 -0
  189. data/lib/emf/emf_plus/records/unknown.rb +20 -0
  190. data/lib/emf/emf_plus/records.rb +107 -0
  191. data/lib/emf/emf_plus/serializer.rb +20 -0
  192. data/lib/emf/emf_plus/stream/conformance.rb +68 -0
  193. data/lib/emf/emf_plus/stream/editor.rb +21 -0
  194. data/lib/emf/emf_plus/stream/emf_gap.rb +20 -0
  195. data/lib/emf/emf_plus/stream/link_index.rb +30 -0
  196. data/lib/emf/emf_plus/stream/rebuild.rb +47 -0
  197. data/lib/emf/emf_plus/stream/record_handle.rb +26 -0
  198. data/lib/emf/emf_plus/stream/segment.rb +70 -0
  199. data/lib/emf/emf_plus/stream.rb +153 -0
  200. data/lib/emf/emf_plus.rb +18 -0
  201. data/lib/emf/emr/binary/dib_header.rb +142 -0
  202. data/lib/emf/emr/binary/ext_text_out_fields.rb +43 -0
  203. data/lib/emf/emr/binary/extended_pen_buffers.rb +23 -0
  204. data/lib/emf/emr/binary/fast_fill.rb +1164 -0
  205. data/lib/emf/emr/binary/font.rb +159 -0
  206. data/lib/emf/emr/binary/header.rb +41 -0
  207. data/lib/emf/emr/binary/lazy_utf16_array.rb +82 -0
  208. data/lib/emf/emr/binary/pack_plan.rb +144 -0
  209. data/lib/emf/emr/binary/pack_plan_check.rb +75 -0
  210. data/lib/emf/emr/binary/pack_plan_exact.rb +130 -0
  211. data/lib/emf/emr/binary/pack_plan_generate.rb +116 -0
  212. data/lib/emf/emr/binary/pack_plan_values.rb +92 -0
  213. data/lib/emf/emr/binary/palette_body.rb +19 -0
  214. data/lib/emf/emr/binary/palette_entry.rb +18 -0
  215. data/lib/emf/emr/binary/record.rb +50 -0
  216. data/lib/emf/emr/binary/records/abort_path.rb +16 -0
  217. data/lib/emf/emr/binary/records/alpha_blend.rb +60 -0
  218. data/lib/emf/emr/binary/records/angle_arc.rb +19 -0
  219. data/lib/emf/emr/binary/records/arc.rb +19 -0
  220. data/lib/emf/emr/binary/records/arc_to.rb +19 -0
  221. data/lib/emf/emr/binary/records/begin_path.rb +16 -0
  222. data/lib/emf/emr/binary/records/bit_blt.rb +51 -0
  223. data/lib/emf/emr/binary/records/chord.rb +19 -0
  224. data/lib/emf/emr/binary/records/close_figure.rb +16 -0
  225. data/lib/emf/emr/binary/records/color_correct_palette.rb +71 -0
  226. data/lib/emf/emr/binary/records/colormatch_to_target_w.rb +92 -0
  227. data/lib/emf/emr/binary/records/comment.rb +20 -0
  228. data/lib/emf/emr/binary/records/create_brush_indirect.rb +20 -0
  229. data/lib/emf/emr/binary/records/create_colorspace.rb +83 -0
  230. data/lib/emf/emr/binary/records/create_colorspace_w.rb +106 -0
  231. data/lib/emf/emr/binary/records/create_dib_pattern_brush_pt.rb +39 -0
  232. data/lib/emf/emr/binary/records/create_font_indirect_w.rb +22 -0
  233. data/lib/emf/emr/binary/records/create_mono_brush.rb +39 -0
  234. data/lib/emf/emr/binary/records/create_palette.rb +35 -0
  235. data/lib/emf/emr/binary/records/create_pen.rb +20 -0
  236. data/lib/emf/emr/binary/records/delete_colorspace.rb +38 -0
  237. data/lib/emf/emr/binary/records/delete_object.rb +16 -0
  238. data/lib/emf/emr/binary/records/draw_escape.rb +61 -0
  239. data/lib/emf/emr/binary/records/ellipse.rb +18 -0
  240. data/lib/emf/emr/binary/records/end_path.rb +16 -0
  241. data/lib/emf/emr/binary/records/eof.rb +30 -0
  242. data/lib/emf/emr/binary/records/exclude_clip_rect.rb +16 -0
  243. data/lib/emf/emr/binary/records/ext_create_pen.rb +96 -0
  244. data/lib/emf/emr/binary/records/ext_escape.rb +61 -0
  245. data/lib/emf/emr/binary/records/ext_flood_fill.rb +24 -0
  246. data/lib/emf/emr/binary/records/ext_select_clip_rgn.rb +27 -0
  247. data/lib/emf/emr/binary/records/ext_text_out_a.rb +40 -0
  248. data/lib/emf/emr/binary/records/ext_text_out_w.rb +52 -0
  249. data/lib/emf/emr/binary/records/fill_path.rb +16 -0
  250. data/lib/emf/emr/binary/records/fill_rgn.rb +26 -0
  251. data/lib/emf/emr/binary/records/flatten_path.rb +16 -0
  252. data/lib/emf/emr/binary/records/force_ufi_mapping.rb +54 -0
  253. data/lib/emf/emr/binary/records/frame_rgn.rb +27 -0
  254. data/lib/emf/emr/binary/records/gls_bounded_record.rb +77 -0
  255. data/lib/emf/emr/binary/records/gls_record.rb +58 -0
  256. data/lib/emf/emr/binary/records/gradient_fill.rb +26 -0
  257. data/lib/emf/emr/binary/records/intersect_clip_rect.rb +16 -0
  258. data/lib/emf/emr/binary/records/invert_rgn.rb +25 -0
  259. data/lib/emf/emr/binary/records/line_to.rb +16 -0
  260. data/lib/emf/emr/binary/records/mask_blt.rb +83 -0
  261. data/lib/emf/emr/binary/records/modify_world_transform.rb +17 -0
  262. data/lib/emf/emr/binary/records/move_to_ex.rb +16 -0
  263. data/lib/emf/emr/binary/records/named_escape.rb +94 -0
  264. data/lib/emf/emr/binary/records/offset_clip_rgn.rb +16 -0
  265. data/lib/emf/emr/binary/records/paint_rgn.rb +25 -0
  266. data/lib/emf/emr/binary/records/pie.rb +19 -0
  267. data/lib/emf/emr/binary/records/pixel_format.rb +92 -0
  268. data/lib/emf/emr/binary/records/plg_blt.rb +83 -0
  269. data/lib/emf/emr/binary/records/poly_bezier.rb +17 -0
  270. data/lib/emf/emr/binary/records/poly_bezier16.rb +17 -0
  271. data/lib/emf/emr/binary/records/poly_bezier_to.rb +17 -0
  272. data/lib/emf/emr/binary/records/poly_bezier_to16.rb +17 -0
  273. data/lib/emf/emr/binary/records/poly_draw.rb +18 -0
  274. data/lib/emf/emr/binary/records/poly_draw16.rb +18 -0
  275. data/lib/emf/emr/binary/records/poly_polygon.rb +19 -0
  276. data/lib/emf/emr/binary/records/poly_polygon16.rb +19 -0
  277. data/lib/emf/emr/binary/records/poly_polyline.rb +19 -0
  278. data/lib/emf/emr/binary/records/poly_polyline16.rb +19 -0
  279. data/lib/emf/emr/binary/records/poly_textout_a.rb +144 -0
  280. data/lib/emf/emr/binary/records/poly_textout_w.rb +144 -0
  281. data/lib/emf/emr/binary/records/polygon.rb +17 -0
  282. data/lib/emf/emr/binary/records/polygon16.rb +17 -0
  283. data/lib/emf/emr/binary/records/polyline.rb +17 -0
  284. data/lib/emf/emr/binary/records/polyline16.rb +17 -0
  285. data/lib/emf/emr/binary/records/polyline_to.rb +17 -0
  286. data/lib/emf/emr/binary/records/polyline_to16.rb +17 -0
  287. data/lib/emf/emr/binary/records/raw.rb +22 -0
  288. data/lib/emf/emr/binary/records/realize_palette.rb +16 -0
  289. data/lib/emf/emr/binary/records/rectangle.rb +18 -0
  290. data/lib/emf/emr/binary/records/resize_palette.rb +31 -0
  291. data/lib/emf/emr/binary/records/restore_dc.rb +17 -0
  292. data/lib/emf/emr/binary/records/round_rect.rb +19 -0
  293. data/lib/emf/emr/binary/records/save_dc.rb +16 -0
  294. data/lib/emf/emr/binary/records/scale_viewport_ext_ex.rb +19 -0
  295. data/lib/emf/emr/binary/records/scale_window_ext_ex.rb +19 -0
  296. data/lib/emf/emr/binary/records/select_clip_path.rb +20 -0
  297. data/lib/emf/emr/binary/records/select_object.rb +16 -0
  298. data/lib/emf/emr/binary/records/select_palette.rb +17 -0
  299. data/lib/emf/emr/binary/records/set_arc_direction.rb +16 -0
  300. data/lib/emf/emr/binary/records/set_bk_color.rb +16 -0
  301. data/lib/emf/emr/binary/records/set_bk_mode.rb +16 -0
  302. data/lib/emf/emr/binary/records/set_brush_org_ex.rb +16 -0
  303. data/lib/emf/emr/binary/records/set_color_adjustment.rb +136 -0
  304. data/lib/emf/emr/binary/records/set_colorspace.rb +38 -0
  305. data/lib/emf/emr/binary/records/set_dibits_to_device.rb +60 -0
  306. data/lib/emf/emr/binary/records/set_icm_mode.rb +16 -0
  307. data/lib/emf/emr/binary/records/set_icm_profile_a.rb +87 -0
  308. data/lib/emf/emr/binary/records/set_icm_profile_w.rb +87 -0
  309. data/lib/emf/emr/binary/records/set_layout.rb +16 -0
  310. data/lib/emf/emr/binary/records/set_linked_ufis.rb +65 -0
  311. data/lib/emf/emr/binary/records/set_map_mode.rb +16 -0
  312. data/lib/emf/emr/binary/records/set_mapper_flags.rb +16 -0
  313. data/lib/emf/emr/binary/records/set_metargn.rb +16 -0
  314. data/lib/emf/emr/binary/records/set_miter_limit.rb +16 -0
  315. data/lib/emf/emr/binary/records/set_palette_entries.rb +35 -0
  316. data/lib/emf/emr/binary/records/set_pixel_v.rb +18 -0
  317. data/lib/emf/emr/binary/records/set_poly_fill_mode.rb +16 -0
  318. data/lib/emf/emr/binary/records/set_rop2.rb +16 -0
  319. data/lib/emf/emr/binary/records/set_stretch_blt_mode.rb +16 -0
  320. data/lib/emf/emr/binary/records/set_text_align.rb +16 -0
  321. data/lib/emf/emr/binary/records/set_text_color.rb +17 -0
  322. data/lib/emf/emr/binary/records/set_text_justification.rb +23 -0
  323. data/lib/emf/emr/binary/records/set_viewport_ext_ex.rb +16 -0
  324. data/lib/emf/emr/binary/records/set_viewport_org_ex.rb +16 -0
  325. data/lib/emf/emr/binary/records/set_window_ext_ex.rb +16 -0
  326. data/lib/emf/emr/binary/records/set_window_org_ex.rb +16 -0
  327. data/lib/emf/emr/binary/records/set_world_transform.rb +16 -0
  328. data/lib/emf/emr/binary/records/small_text_out.rb +79 -0
  329. data/lib/emf/emr/binary/records/stretch_blt.rb +53 -0
  330. data/lib/emf/emr/binary/records/stretch_dibits.rb +56 -0
  331. data/lib/emf/emr/binary/records/stroke_and_fill_path.rb +16 -0
  332. data/lib/emf/emr/binary/records/stroke_path.rb +16 -0
  333. data/lib/emf/emr/binary/records/transparent_blt.rb +60 -0
  334. data/lib/emf/emr/binary/records/widen_path.rb +16 -0
  335. data/lib/emf/emr/binary/records.rb +260 -0
  336. data/lib/emf/emr/binary/region_data.rb +33 -0
  337. data/lib/emf/emr/binary/state_record_body.rb +33 -0
  338. data/lib/emf/emr/binary/thin_shell.rb +226 -0
  339. data/lib/emf/emr/binary/type_codes.rb +132 -0
  340. data/lib/emf/emr/binary/value_view/layout.rb +101 -0
  341. data/lib/emf/emr/binary/value_view/reader_source.rb +88 -0
  342. data/lib/emf/emr/binary/value_view.rb +173 -0
  343. data/lib/emf/emr/binary/variable_buffers.rb +87 -0
  344. data/lib/emf/emr/binary/with_bounds.rb +15 -0
  345. data/lib/emf/emr/binary.rb +17 -0
  346. data/lib/emf/emr/filled_record.rb +77 -0
  347. data/lib/emf/emr/parser.rb +374 -0
  348. data/lib/emf/emr/path_association.rb +16 -0
  349. data/lib/emf/emr/serializer.rb +23 -0
  350. data/lib/emf/emr.rb +11 -0
  351. data/lib/emf/error.rb +42 -0
  352. data/lib/emf/model/diagnostic.rb +41 -0
  353. data/lib/emf/model/emr/header.rb +132 -0
  354. data/lib/emf/model/emr/records.rb +184 -0
  355. data/lib/emf/model/emr/wire_values.rb +43 -0
  356. data/lib/emf/model/emr.rb +11 -0
  357. data/lib/emf/model/geometry/color.rb +85 -0
  358. data/lib/emf/model/geometry/matrix.rb +52 -0
  359. data/lib/emf/model/geometry/point.rb +41 -0
  360. data/lib/emf/model/geometry/point_f.rb +33 -0
  361. data/lib/emf/model/geometry/point_s.rb +33 -0
  362. data/lib/emf/model/geometry/rect.rb +57 -0
  363. data/lib/emf/model/geometry/rect_s.rb +49 -0
  364. data/lib/emf/model/geometry/size.rb +33 -0
  365. data/lib/emf/model/geometry.rb +16 -0
  366. data/lib/emf/model/metafile.rb +54 -0
  367. data/lib/emf/model/record.rb +19 -0
  368. data/lib/emf/model/visitor.rb +42 -0
  369. data/lib/emf/model/wmf/bitmap_records.rb +155 -0
  370. data/lib/emf/model/wmf/brush_records.rb +45 -0
  371. data/lib/emf/model/wmf/dc_escape_records.rb +67 -0
  372. data/lib/emf/model/wmf/font_record.rb +40 -0
  373. data/lib/emf/model/wmf/geometry_records.rb +107 -0
  374. data/lib/emf/model/wmf/header.rb +36 -0
  375. data/lib/emf/model/wmf/object_records.rb +71 -0
  376. data/lib/emf/model/wmf/palette_records.rb +68 -0
  377. data/lib/emf/model/wmf/records.rb +247 -0
  378. data/lib/emf/model/wmf/region_records.rb +112 -0
  379. data/lib/emf/model/wmf/state_records.rb +188 -0
  380. data/lib/emf/model/wmf/text_records.rb +36 -0
  381. data/lib/emf/model/wmf.rb +11 -0
  382. data/lib/emf/model.rb +13 -0
  383. data/lib/emf/native/bitmap_fields.rb +58 -0
  384. data/lib/emf/native/diagnostic_contract.rb +39 -0
  385. data/lib/emf/native/diagnostics.rb +81 -0
  386. data/lib/emf/native/emf_plus_loader.rb +35 -0
  387. data/lib/emf/native/emf_plus_snapshot.rb +96 -0
  388. data/lib/emf/native/emf_plus_source.rb +20 -0
  389. data/lib/emf/native/emf_plus_stream.rb +150 -0
  390. data/lib/emf/native/fields.rb +369 -0
  391. data/lib/emf/native/font_fields.rb +87 -0
  392. data/lib/emf/native/gradient_fields.rb +23 -0
  393. data/lib/emf/native/header.rb +35 -0
  394. data/lib/emf/native/header_errors.rb +30 -0
  395. data/lib/emf/native/hydrator.rb +151 -0
  396. data/lib/emf/native/lazy_wire.rb +100 -0
  397. data/lib/emf/native/legacy_state_fields.rb +22 -0
  398. data/lib/emf/native/library_path.rb +68 -0
  399. data/lib/emf/native/loader.rb +120 -0
  400. data/lib/emf/native/palette_fields.rb +45 -0
  401. data/lib/emf/native/platforms.json +6 -0
  402. data/lib/emf/native/poly_text_fields.rb +116 -0
  403. data/lib/emf/native/provenance.json +11 -0
  404. data/lib/emf/native/resource_failure.rb +28 -0
  405. data/lib/emf/native/small_text_fields.rb +27 -0
  406. data/lib/emf/native/snapshot.rb +102 -0
  407. data/lib/emf/native/wmf_bitmap_fields.rb +58 -0
  408. data/lib/emf/native/wmf_brush_fields.rb +62 -0
  409. data/lib/emf/native/wmf_fields.rb +117 -0
  410. data/lib/emf/native/wmf_hydrator.rb +143 -0
  411. data/lib/emf/native/wmf_loading.rb +49 -0
  412. data/lib/emf/native/wmf_palette_fields.rb +60 -0
  413. data/lib/emf/native/wmf_region_fields.rb +92 -0
  414. data/lib/emf/native/wmf_rejection.rb +84 -0
  415. data/lib/emf/native/wmf_remaining_fields.rb +70 -0
  416. data/lib/emf/native/wmf_snapshot.rb +51 -0
  417. data/lib/emf/native/wmf_text_fields.rb +56 -0
  418. data/lib/emf/native/x86_64-linux-gnu/libemf_ffi.so +0 -0
  419. data/lib/emf/native.rb +61 -0
  420. data/lib/emf/parse_evidence.rb +57 -0
  421. data/lib/emf/resource_budget/bitmap.rb +66 -0
  422. data/lib/emf/resource_budget/gradient.rb +30 -0
  423. data/lib/emf/resource_budget/poly_text.rb +85 -0
  424. data/lib/emf/resource_budget.rb +382 -0
  425. data/lib/emf/resource_limits/emf_records.rb +130 -0
  426. data/lib/emf/resource_limits.rb +58 -0
  427. data/lib/emf/version.rb +5 -0
  428. data/lib/emf/visitors/dump.rb +61 -0
  429. data/lib/emf/visitors/stats.rb +64 -0
  430. data/lib/emf/visitors.rb +8 -0
  431. data/lib/emf/wmf/binary.rb +158 -0
  432. data/lib/emf/wmf/bitmap_codec.rb +118 -0
  433. data/lib/emf/wmf/brush_codec.rb +102 -0
  434. data/lib/emf/wmf/dc_escape_codec.rb +75 -0
  435. data/lib/emf/wmf/dib.rb +187 -0
  436. data/lib/emf/wmf/embedded_emf.rb +137 -0
  437. data/lib/emf/wmf/escape_views.rb +89 -0
  438. data/lib/emf/wmf/evidence.rb +255 -0
  439. data/lib/emf/wmf/geometry_codec.rb +49 -0
  440. data/lib/emf/wmf/palette_codec.rb +85 -0
  441. data/lib/emf/wmf/parser.rb +158 -0
  442. data/lib/emf/wmf/recovery.rb +95 -0
  443. data/lib/emf/wmf/region_codec.rb +151 -0
  444. data/lib/emf/wmf/serializer.rb +175 -0
  445. data/lib/emf/wmf/text_codec.rb +123 -0
  446. data/lib/emf/wmf.rb +16 -0
  447. data/lib/emf.rb +60 -0
  448. metadata +520 -0
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Emr
6
+ module Records
7
+ # Adapter that wraps a bindata wire record so the Metafile container
8
+ # can hold domain-shape objects even for record types whose dedicated
9
+ # domain class hasn't been written yet (TODO 10). When a real domain
10
+ # class exists, the parser uses it instead.
11
+ #
12
+ # `wire` is the parsed Emf::Emr::Binary::Records::* instance.
13
+ # `offset` is the byte offset within the source stream (for diagnostics).
14
+ class WireAdapter < Emf::Model::Record
15
+ Emf::Model::Visitor.register_visit(:visit_emr_wire_record, self)
16
+ include Emf::Model::Emr::WireValues
17
+
18
+ # Internal native construction path; the source owns copied Ruby data only.
19
+ # One per parsed record, so it skips keyword construction; the suffix
20
+ # is the source's once the wire is made.
21
+ def self.lazy(source:, offset: nil)
22
+ allocate.__send__(:init_lazy, source, offset)
23
+ end
24
+
25
+ # Opt-in construction of a wire record from keyword attributes, with
26
+ # n_size set to the record's size, as `klass.new(**attrs)` followed by
27
+ # `n_size = num_bytes`. For a class with a PackPlan and attributes it
28
+ # accepts (values BinData stores unchanged), the adapter holds only the
29
+ # finished bytes; `to_binary_s` serves them until `#wire` is called,
30
+ # after which the adapter serializes that wire like any other. Any
31
+ # other class or attribute shape, or an error while packing, takes the
32
+ # BinData path unchanged, so the result and the errors are those of
33
+ # `klass.new`.
34
+ def self.build(klass, **attrs)
35
+ filler = Emf::Emr::Binary::FastFill.for_class(klass)
36
+ bytes = filler && packed_bytes(filler, attrs)
37
+ return allocate.__send__(:init_lazy, BuiltBytes.new(klass, filler, bytes), nil) if bytes
38
+
39
+ wire = klass.new(**attrs)
40
+ wire.n_size = wire.num_bytes
41
+ new(wire: wire)
42
+ end
43
+
44
+ def self.packed_bytes(filler, attrs)
45
+ filler.pack_plan&.pack(attrs)
46
+ rescue StandardError
47
+ nil
48
+ end
49
+ private_class_method :packed_bytes
50
+
51
+ # The lazy source of a record built by `build`: its bytes, and a
52
+ # wire read back from them when one is asked for.
53
+ class BuiltBytes
54
+ def initialize(klass, filler, bytes)
55
+ @klass = klass
56
+ @filler = filler
57
+ @bytes = (bytes.encoding == Encoding::BINARY ? bytes : bytes.b).freeze
58
+ end
59
+
60
+ def type_id
61
+ @bytes.unpack1("V")
62
+ end
63
+
64
+ def wire_class
65
+ @klass
66
+ end
67
+
68
+ def value_source
69
+ [@bytes, 0, true]
70
+ end
71
+
72
+ def to_binary_s
73
+ @bytes.dup
74
+ end
75
+
76
+ def append_to(out)
77
+ out << @bytes
78
+ end
79
+
80
+ def materialize
81
+ @filler.call_at(@bytes, 0, @bytes.bytesize)&.first || @klass.read(@bytes)
82
+ end
83
+
84
+ def suffix(_wire)
85
+ EMPTY_SUFFIX
86
+ end
87
+ end
88
+
89
+ # Bytes of a record that follow its typed layout (declared nSize larger
90
+ # than the layout consumes). Kept verbatim beside the wire.
91
+ EMPTY_SUFFIX = "".b.freeze
92
+ private_constant :EMPTY_SUFFIX
93
+
94
+ def self.suffix_of(record_bytes, wire)
95
+ extra = record_bytes.bytesize - wire.num_bytes
96
+ return EMPTY_SUFFIX unless extra.positive?
97
+
98
+ record_bytes.byteslice(-extra, extra).b.freeze
99
+ end
100
+
101
+ def initialize(wire:, offset: nil, suffix: EMPTY_SUFFIX)
102
+ @wire = wire
103
+ @offset = offset
104
+ @suffix = suffix
105
+ end
106
+
107
+ attr_reader :offset
108
+
109
+ def wire
110
+ return @wire if @wire
111
+
112
+ @wire = @wire_source.materialize
113
+ @suffix = @wire_source.suffix(@wire)
114
+ @wire_source = nil
115
+ @wire
116
+ end
117
+
118
+ def suffix
119
+ wire
120
+ @suffix
121
+ end
122
+
123
+ def to_binary_s
124
+ return @wire_source.to_binary_s unless @wire
125
+
126
+ bytes = @wire.to_binary_s
127
+ return bytes if @suffix.empty?
128
+
129
+ bytes[4, 4] = [bytes.bytesize + @suffix.bytesize].pack("V")
130
+ bytes + @suffix
131
+ end
132
+
133
+ # Appends this record's wire bytes to `out` (a binary String). A record
134
+ # still held as bytes appends them without a copy; once `#wire` has
135
+ # been made the wire is the truth and is packed, so an edit is never
136
+ # served from stale bytes.
137
+ def append_to(out)
138
+ return @wire_source.append_to(out) unless @wire
139
+
140
+ return out if @suffix.empty? && @wire.append_built_to?(out)
141
+
142
+ out << to_binary_s
143
+ end
144
+
145
+ def type_id
146
+ @wire ? @wire.i_type : @wire_source.type_id
147
+ end
148
+
149
+ # The wire class of the record, without making the wire.
150
+ def wire_class
151
+ @wire ? @wire.class : @wire_source.wire_class
152
+ end
153
+
154
+ def accept(visitor)
155
+ visitor.visit_emr_wire_record(self)
156
+ end
157
+
158
+ def ==(other)
159
+ other.is_a?(self.class) && to_binary_s == other.to_binary_s
160
+ end
161
+ alias eql? ==
162
+
163
+ def hash
164
+ [self.class, to_binary_s].hash
165
+ end
166
+
167
+ def inspect
168
+ "#<#{self.class.name} type_id=#{type_id} (#{(wire.class.name || '').split('::').last})>"
169
+ end
170
+
171
+ private
172
+
173
+ def init_lazy(source, offset)
174
+ @wire = nil
175
+ @offset = offset
176
+ @suffix = EMPTY_SUFFIX
177
+ @wire_source = source
178
+ self
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Emr
6
+ # `WireAdapter#values`: the record's field values as plain frozen Ruby
7
+ # objects, without making BinData field objects. See
8
+ # Emf::Emr::Binary::ValueView for the shape.
9
+ module WireValues
10
+ # The field values the record holds now, or nil when its wire class
11
+ # has no value view (variable-layout records such as ExtTextOut,
12
+ # strings, bitmaps and Raw): use `wire` for those.
13
+ #
14
+ # A field of the wire not made yet is still the record's bytes, so
15
+ # the values are unpacked from them (one String#unpack; kept and
16
+ # returned again while no field has been made). A field made through
17
+ # `wire` may have been edited, so it is read from the wire and the
18
+ # rest from the bytes. An edit through `wire` is always reflected.
19
+ # Equal on the Ruby and native backends.
20
+ def values
21
+ view = Emf::Emr::Binary::ValueView.for_class(@wire ? @wire.class : @wire_source.wire_class)
22
+ return unless view
23
+
24
+ data, base, untouched = byte_source
25
+ if data
26
+ found = untouched ? (@values ||= view.from_bytes(data, base)) : view.from_mixed(data, base, @wire)
27
+ return found if found
28
+ end
29
+ view.from_wire(wire)
30
+ end
31
+
32
+ private
33
+
34
+ # [data, offset, untouched] of the bytes the record is filled from.
35
+ def byte_source
36
+ return @wire_source.value_source unless @wire
37
+
38
+ @wire.lazy_source if @wire.respond_to?(:lazy_source)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Emr
6
+ autoload :Header, "emf/model/emr/header"
7
+ autoload :WireValues, "emf/model/emr/wire_values"
8
+ autoload :Records, "emf/model/emr/records"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class Color
7
+ # One instantiated ColorRef and its field slots, built on first use.
8
+ module WireTemplate
9
+ module_function
10
+
11
+ def get
12
+ @get ||= begin
13
+ sample = Binary::Types::ColorRef.new
14
+ sample.field_names.each { |name| sample.public_send(name) }
15
+ [sample, Emf::Emr::Binary::WireCopy.slots(sample)].freeze
16
+ end
17
+ end
18
+ end
19
+ private_constant :WireTemplate
20
+
21
+ def initialize(red:, green:, blue:, alpha: 255)
22
+ @red = coerce(red)
23
+ @green = coerce(green)
24
+ @blue = coerce(blue)
25
+ @alpha = coerce(alpha)
26
+ end
27
+
28
+ attr_reader :red, :green, :blue, :alpha
29
+
30
+ def self.from_wire(wire)
31
+ new(red: wire.red, green: wire.green, blue: wire.blue, alpha: wire.reserved.zero? ? 255 : wire.reserved)
32
+ end
33
+
34
+ # Same ColorRef as `ColorRef.new(red:, green:, blue:, reserved:)`,
35
+ # built from a copy of one instantiated ColorRef instead of BinData's
36
+ # lazy construction (the record builders call this once per color).
37
+ def to_wire
38
+ template, slots = WireTemplate.get
39
+ Emf::Emr::Binary::WireCopy.build(template, slots, { red: red, green: green, blue: blue, reserved: alpha })
40
+ end
41
+
42
+ def to_hex
43
+ alpha == 255 ? format("#%02X%02X%02X", red, green, blue) : to_hex_rgba
44
+ end
45
+
46
+ def to_hex_rgba
47
+ format("#%02X%02X%02X%02X", red, green, blue, alpha)
48
+ end
49
+
50
+ def self.black
51
+ new(red: 0, green: 0, blue: 0)
52
+ end
53
+
54
+ def self.white
55
+ new(red: 255, green: 255, blue: 255)
56
+ end
57
+
58
+ def self.transparent
59
+ new(red: 0, green: 0, blue: 0, alpha: 0)
60
+ end
61
+
62
+ def ==(other)
63
+ other.is_a?(self.class) &&
64
+ red == other.red && green == other.green &&
65
+ blue == other.blue && alpha == other.alpha
66
+ end
67
+ alias eql? ==
68
+
69
+ def hash
70
+ [self.class, red, green, blue, alpha].hash
71
+ end
72
+
73
+ def inspect
74
+ "#<#{self.class.name} #{to_hex_rgba}>"
75
+ end
76
+
77
+ private
78
+
79
+ def coerce(value)
80
+ Integer(value)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class Matrix
7
+ IDENTITY = {
8
+ m11: 1.0, m12: 0.0, m21: 0.0, m22: 1.0, dx: 0.0, dy: 0.0
9
+ }.freeze
10
+
11
+ def initialize(m11:, m12:, m21:, m22:, dx:, dy:)
12
+ @m11 = m11.to_f
13
+ @m12 = m12.to_f
14
+ @m21 = m21.to_f
15
+ @m22 = m22.to_f
16
+ @dx = dx.to_f
17
+ @dy = dy.to_f
18
+ end
19
+
20
+ attr_reader :m11, :m12, :m21, :m22, :dx, :dy
21
+
22
+ def self.from_wire(wire)
23
+ new(m11: wire.m11, m12: wire.m12, m21: wire.m21, m22: wire.m22, dx: wire.dx, dy: wire.dy)
24
+ end
25
+
26
+ def to_wire
27
+ Binary::Types::XForm.new(m11: m11, m12: m12, m21: m21, m22: m22, dx: dx, dy: dy)
28
+ end
29
+
30
+ def self.identity
31
+ new(**IDENTITY)
32
+ end
33
+
34
+ def identity?
35
+ m11 == 1.0 && m12 == 0.0 && m21 == 0.0 && m22 == 1.0 && dx == 0.0 && dy == 0.0
36
+ end
37
+
38
+ def ==(other)
39
+ other.is_a?(self.class) &&
40
+ m11 == other.m11 && m12 == other.m12 &&
41
+ m21 == other.m21 && m22 == other.m22 &&
42
+ dx == other.dx && dy == other.dy
43
+ end
44
+ alias eql? ==
45
+
46
+ def hash
47
+ [self.class, m11, m12, m21, m22, dx, dy].hash
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class Point
7
+ def initialize(x:, y:)
8
+ @x = x
9
+ @y = y
10
+ end
11
+
12
+ attr_reader :x, :y
13
+
14
+ def self.from_wire(wire)
15
+ new(x: wire.x, y: wire.y)
16
+ end
17
+
18
+ def to_wire
19
+ Binary::Types::PointL.new(x: x, y: y)
20
+ end
21
+
22
+ def translate(dx, dy)
23
+ self.class.new(x: x + dx, y: y + dy)
24
+ end
25
+
26
+ def ==(other)
27
+ other.is_a?(self.class) && x == other.x && y == other.y
28
+ end
29
+ alias eql? ==
30
+
31
+ def hash
32
+ [self.class, x, y].hash
33
+ end
34
+
35
+ def inspect
36
+ "#<#{self.class.name} x=#{x} y=#{y}>"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class PointF
7
+ def initialize(x:, y:)
8
+ @x = x.to_f
9
+ @y = y.to_f
10
+ end
11
+
12
+ attr_reader :x, :y
13
+
14
+ def self.from_wire(wire)
15
+ new(x: wire.x, y: wire.y)
16
+ end
17
+
18
+ def to_wire
19
+ Binary::Types::PointD.new(x: x, y: y)
20
+ end
21
+
22
+ def ==(other)
23
+ other.is_a?(self.class) && x == other.x && y == other.y
24
+ end
25
+ alias eql? ==
26
+
27
+ def hash
28
+ [self.class, x, y].hash
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class PointS
7
+ def initialize(x:, y:)
8
+ @x = x
9
+ @y = y
10
+ end
11
+
12
+ attr_reader :x, :y
13
+
14
+ def self.from_wire(wire)
15
+ new(x: wire.x, y: wire.y)
16
+ end
17
+
18
+ def to_wire
19
+ Binary::Types::PointS.new(x: x, y: y)
20
+ end
21
+
22
+ def ==(other)
23
+ other.is_a?(self.class) && x == other.x && y == other.y
24
+ end
25
+ alias eql? ==
26
+
27
+ def hash
28
+ [self.class, x, y].hash
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class Rect
7
+ def initialize(left:, top:, right:, bottom:)
8
+ @left = left
9
+ @top = top
10
+ @right = right
11
+ @bottom = bottom
12
+ end
13
+
14
+ attr_reader :left, :top, :right, :bottom
15
+
16
+ def self.from_wire(wire)
17
+ new(left: wire.left, top: wire.top, right: wire.right, bottom: wire.bottom)
18
+ end
19
+
20
+ def to_wire
21
+ Binary::Types::RectL.new(left: left, top: top, right: right, bottom: bottom)
22
+ end
23
+
24
+ def width
25
+ right - left
26
+ end
27
+
28
+ def height
29
+ bottom - top
30
+ end
31
+
32
+ def empty?
33
+ width <= 0 || height <= 0
34
+ end
35
+
36
+ def contains?(point)
37
+ point.x.between?(left, right) && point.y.between?(top, bottom)
38
+ end
39
+
40
+ def ==(other)
41
+ other.is_a?(self.class) &&
42
+ left == other.left && top == other.top &&
43
+ right == other.right && bottom == other.bottom
44
+ end
45
+ alias eql? ==
46
+
47
+ def hash
48
+ [self.class, left, top, right, bottom].hash
49
+ end
50
+
51
+ def inspect
52
+ "#<#{self.class.name} left=#{left} top=#{top} right=#{right} bottom=#{bottom}>"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class RectS
7
+ def initialize(left:, top:, right:, bottom:)
8
+ @left = left
9
+ @top = top
10
+ @right = right
11
+ @bottom = bottom
12
+ end
13
+
14
+ attr_reader :left, :top, :right, :bottom
15
+
16
+ def self.from_wire(wire)
17
+ new(left: wire.left, top: wire.top, right: wire.right, bottom: wire.bottom)
18
+ end
19
+
20
+ def to_wire
21
+ Binary::Types::RectS.new(left: left, top: top, right: right, bottom: bottom)
22
+ end
23
+
24
+ def width
25
+ right - left
26
+ end
27
+
28
+ def height
29
+ bottom - top
30
+ end
31
+
32
+ def empty?
33
+ width <= 0 || height <= 0
34
+ end
35
+
36
+ def ==(other)
37
+ other.is_a?(self.class) &&
38
+ left == other.left && top == other.top &&
39
+ right == other.right && bottom == other.bottom
40
+ end
41
+ alias eql? ==
42
+
43
+ def hash
44
+ [self.class, left, top, right, bottom].hash
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ class Size
7
+ def initialize(cx:, cy:)
8
+ @cx = cx
9
+ @cy = cy
10
+ end
11
+
12
+ attr_reader :cx, :cy
13
+
14
+ def self.from_wire(wire)
15
+ new(cx: wire.cx, cy: wire.cy)
16
+ end
17
+
18
+ def to_wire
19
+ Binary::Types::SizeL.new(cx: cx, cy: cy)
20
+ end
21
+
22
+ def ==(other)
23
+ other.is_a?(self.class) && cx == other.cx && cy == other.cy
24
+ end
25
+ alias eql? ==
26
+
27
+ def hash
28
+ [self.class, cx, cy].hash
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ module Geometry
6
+ autoload :Point, "emf/model/geometry/point"
7
+ autoload :PointF, "emf/model/geometry/point_f"
8
+ autoload :PointS, "emf/model/geometry/point_s"
9
+ autoload :Size, "emf/model/geometry/size"
10
+ autoload :Rect, "emf/model/geometry/rect"
11
+ autoload :RectS, "emf/model/geometry/rect_s"
12
+ autoload :Color, "emf/model/geometry/color"
13
+ autoload :Matrix, "emf/model/geometry/matrix"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emf
4
+ module Model
5
+ class Metafile
6
+ include Enumerable
7
+
8
+ def initialize(format:, header:, records:, errors: [], emf_plus: nil, trailing: "", emf_plus_source: nil, diagnostics: [])
9
+ @format = format
10
+ @header = header
11
+ @records = records.freeze
12
+ @errors = errors.freeze
13
+ @diagnostics = diagnostics.dup.freeze
14
+ @emf_plus = emf_plus
15
+ @trailing = trailing.freeze
16
+ @emf_plus_source = emf_plus_source
17
+ end
18
+
19
+ attr_reader :format, :header, :records, :errors, :emf_plus, :trailing, :diagnostics
20
+
21
+ # Return a new view while retaining backend-specific lazy sources.
22
+ def with_diagnostics(diagnostics)
23
+ copy = dup
24
+ copy.instance_variable_set(:@diagnostics, diagnostics.dup.freeze)
25
+ copy
26
+ end
27
+
28
+ def each(&block)
29
+ return to_enum unless block
30
+
31
+ @records.each(&block)
32
+ end
33
+
34
+ # Typed EMF+ view; nil unless this is an EMF+ metafile. Memoised because
35
+ # the metafile is immutable; `reload: true` rebuilds it from the current comment bytes.
36
+ # A backend may supply `emf_plus_source` (called with the metafile and `reload`);
37
+ # a nil result falls back to the Ruby stream.
38
+ def emf_plus_stream(reload: false)
39
+ return unless format == :emf_plus
40
+
41
+ @emf_plus_stream = nil if reload
42
+ @emf_plus_stream ||= @emf_plus_source&.call(self, reload) || Emf::EmfPlus::Stream.from_metafile(self)
43
+ end
44
+
45
+ def errors?
46
+ !@errors.empty?
47
+ end
48
+
49
+ def ok?
50
+ @errors.empty?
51
+ end
52
+ end
53
+ end
54
+ end