image_size icon indicating copy to clipboard operation
image_size copied to clipboard

support EMF

Open opoudjis opened this issue 3 years ago • 1 comments

Support of Microsoft EMF format:

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-emf/e4a35c41-e8e3-43f9-bc07-a18e99bb866d

https://stackoverflow.com/questions/3391087/extracting-width-height-dimensions-from-emf-image-files

opoudjis avatar Oct 21 '22 10:10 opoudjis

Thank you for your extremely diligent feedback. You are a better human being than I am. :-)

opoudjis avatar Oct 25 '22 13:10 opoudjis

Few small things left: CHANGELOG entry, description in gemspec and legacy ruby doesn't understand L< 😞.

I've checked few variants and did a benchmark:

require 'securerandom'
require 'benchmark'

STRINGS = 1_000_000.times.map do
  SecureRandom.random_bytes(16)
end

UMAX = 256**4
SMAX = UMAX / 2

Benchmark.bmbm do |x|
  x.report('repack') do
    STRINGS.map{ |s| s.unpack('V*').pack('L*').unpack('l*') }
  end

  x.report('conditional') do
    STRINGS.map{ |s| s.unpack('V*').map{ |u| u < SMAX ? u : u - UMAX } }
  end

  x.report('arythemical') do
    STRINGS.map{ |s| s.unpack('V*').map{ |u| (u + SMAX) % UMAX - SMAX } }
  end
end

outputs:

Rehearsal -----------------------------------------------
repack        4.400000   0.080000   4.480000 (  4.480014)
conditional   2.860000   0.070000   2.930000 (  2.934557)
arythemical   3.200000   0.030000   3.230000 (  3.228823)
------------------------------------- total: 10.640000sec

                  user     system      total        real
repack        4.590000   0.050000   4.640000 (  4.641003)
conditional   2.500000   0.010000   2.510000 (  2.510647)
arythemical   3.000000   0.020000   3.020000 (  3.012003)

not sure which is better from clarity/readability and maybe there is another option. Alternative can be conditionally used for RUBY_VERSION < '1.9'.

toy avatar Oct 30 '22 14:10 toy

Also forgot to attach non square emf converted from svg using Inkscape + changed values to also be negative 74x77.emf.zip (zip as emf is not supported for upload)

toy avatar Oct 30 '22 15:10 toy

Thank you, will get to these.

opoudjis avatar Nov 01 '22 00:11 opoudjis

Happy for you to squash merge.

opoudjis avatar Nov 01 '22 23:11 opoudjis

And can I say again, Ivan, you are a very good human being, and I'm honoured to have contributed to your gem. Thank you for your help and diligence!

opoudjis avatar Nov 02 '22 02:11 opoudjis

Thank you for taking time to contribute to the gem!

I've released version 3.2.0

toy avatar Nov 02 '22 23:11 toy