emf2svg 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58349fd10f19ee509fc7cf20602f619dcb9c4b45d65e4ac84f9c7a4cddc178fe
4
- data.tar.gz: ef2081e0fe533572dfb963816f83ff022b9b1ebe3d9827966d91bb1b9954acb3
3
+ metadata.gz: 2f40393f8fd1ee8fac3c0bac60dd57cdffa37e7c29fe4c84654a1c09fd3eddc6
4
+ data.tar.gz: 1177ab6679786bfaa7ee08dec8c38ac52cf7c9367c83a2c8197569950266c7df
5
5
  SHA512:
6
- metadata.gz: ba52fc1c6c6e285d5d10401fbad1723410f807ac3977b334137cbc9f226afcc32fd505aff2c4f3bce67464bb4583b8368fabf523c2d5e7c07d0a57f365d6325a
7
- data.tar.gz: 41da88dbc8a1f9598cffec8750d73f8a3bbf683be8b924373721781f8e055098c56de23ba27049a3bd2840d87f07eab60765020b7609a43d4e5f5a980cafdfed
6
+ metadata.gz: a969bc6a4061541d00b0385951622f0d640d96f2d03a5a9081e9b583b4b60e4527e331ea88c287a9049ace569e85f9473bfaca9d029a5ed0122091ef43778f5c
7
+ data.tar.gz: 688381d0362f87e799bbe26a18d673a3eda30f2eaa4e7c2e39d3e925f90304726d97b32d5d8e195c6fd1493c0dddc5643e08e1a0973d710eb3e1dbe2512690f3
@@ -1,16 +1,69 @@
1
- name: Ruby
1
+ name: main
2
2
 
3
- on: [push,pull_request]
3
+ on:
4
+ push:
5
+ branches: [ main, master ]
6
+ pull_request:
4
7
 
5
8
  jobs:
6
- build:
7
- runs-on: ubuntu-latest
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
8
15
  steps:
9
16
  - uses: actions/checkout@v2
10
- - name: Set up Ruby
11
- uses: ruby/setup-ruby@v1
17
+
18
+ - uses: ruby/setup-ruby@v1
12
19
  with:
13
20
  ruby-version: 2.6.6
14
21
  bundler-cache: true
15
- - name: Run the default task
16
- run: bundle exec rake
22
+
23
+ - run: bundle exec rake
24
+
25
+ build-gem:
26
+ runs-on: ubuntu-18.04
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+
30
+ - uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: '2.6'
33
+
34
+ - run: bundle config set path 'vendor/bundle'
35
+
36
+ - run: bundle install --jobs 4 --retry 3
37
+
38
+ - run: bundle exec rake build
39
+
40
+ - uses: actions/upload-artifact@v2
41
+ with:
42
+ name: pkg
43
+ path: pkg/*.gem
44
+
45
+ test-gem:
46
+ needs: build-gem
47
+ runs-on: ${{ matrix.os }}
48
+ strategy:
49
+ fail-fast: false
50
+ matrix:
51
+ os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ]
52
+ steps:
53
+ - uses: actions/checkout@v2
54
+
55
+ - uses: actions/download-artifact@v2
56
+ with:
57
+ name: pkg
58
+ path: pkg
59
+
60
+ - uses: ruby/setup-ruby@v1
61
+ with:
62
+ ruby-version: '2.6'
63
+
64
+ - name: Install gem
65
+ run: gem install --no-document pkg/emf2svg-*.gem
66
+
67
+ - name: Test conversion
68
+ run: |
69
+ ruby -remf2svg -e "puts File.write('output.svg', Emf2svg.from_file('spec/examples/image1.emf'), mode: 'wb')"
@@ -0,0 +1,36 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-18.04
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: '2.6'
17
+
18
+ - run: bundle config set path 'vendor/bundle'
19
+
20
+ - run: bundle install --jobs 4 --retry 3
21
+
22
+ - run: bundle exec rake
23
+
24
+ - name: Publish to rubygems.org
25
+ env:
26
+ RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
27
+ run: |
28
+ gem install gem-release
29
+ touch ~/.gem/credentials
30
+ cat > ~/.gem/credentials << EOF
31
+ ---
32
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
33
+ EOF
34
+ chmod 0600 ~/.gem/credentials
35
+ git status
36
+ gem release
data/.gitignore CHANGED
@@ -6,6 +6,15 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /ports/
10
+ /Gemfile.lock
11
+ *.installed
12
+ *.dll
13
+ *.dylib
14
+ *.so
9
15
 
10
16
  # rspec failure tracking
11
17
  .rspec_status
18
+
19
+ # remote file cache
20
+ .rubocop-*
data/.rubocop.yml CHANGED
@@ -1,13 +1,5 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
1
+ inherit_from:
2
+ - 'https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml'
7
3
 
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
data/README.adoc CHANGED
@@ -22,12 +22,80 @@ Or add it to your `Gemfile`:
22
22
  gem 'emf2svg'
23
23
  ----
24
24
 
25
+ === Dependencies
26
+
27
+ * libiconv
28
+ * libpng
29
+ * libfontconfig
30
+ * libfreetype
31
+
32
+ ==== Windows
33
+
34
+ On Windows all necessary libraries are precompiled but you'll need Visual
35
+ Studio 2019 with C++ Build Tools, which can be downloaded
36
+ https://visualstudio.microsoft.com/downloads/[here], or installed with
37
+ Chocolatey:
38
+
39
+ [source,sh]
40
+ ----
41
+ choco install visualstudio2019buildtools -y --no-progress --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.18362"
42
+ ----
43
+
44
+ ==== macOS
45
+
46
+ [source,sh]
47
+ ----
48
+ brew install cmake
49
+ ----
50
+
51
+ ==== Linux
52
+
53
+ ===== Debian
54
+
55
+ [source,sh]
56
+ ----
57
+ # compiler
58
+ apt-get install gcc g++
59
+ # or
60
+ apt-get install clang
61
+
62
+ # build deps
63
+ apt-get install cmake pkg-config
64
+
65
+ # library deps with their headers
66
+ apt-get install libpng-dev libc6-dev libfontconfig1-dev libfreetype6-dev zlib1g-dev
67
+ ----
68
+
69
+ ===== Fedora
70
+
71
+ [source,sh]
72
+ ----
73
+ yum install cmake libpng-devel freetype-devel fontconfig-devel gcc-c++ gcc
74
+ ----
75
+
25
76
  == Usage
26
77
 
27
78
  This gem embeds libemf2svg, allowing your Ruby code to utilize EMF to SVG
28
79
  conversion facilities.
29
80
 
30
- TODO.
81
+ [source,ruby]
82
+ ----
83
+ require "emf2svg"
84
+
85
+ data = Emf2svg.from_file("example.emf")
86
+ File.write("output.svg", data, mode: "wb")
87
+ ----
88
+
89
+ It also can use content of emf as an input:
90
+
91
+ [source,ruby]
92
+ ----
93
+ require "emf2svg"
94
+
95
+ emf_content = File.read("example.emf", mode: "rb")
96
+ svg_data = Emf2svg.from_binary_string(emf_content)
97
+ File.write("output.svg", svg_data, mode: "wb")
98
+ ----
31
99
 
32
100
  == Development
33
101
 
@@ -41,6 +109,25 @@ release a new version, update the version number in `version.rb`, and then run
41
109
  git commits and the created tag, and push the `.gem` file to
42
110
  https://rubygems.org[rubygems.org].
43
111
 
112
+ === Releasing
113
+
114
+ Releasing is done automatically with GitHub Actions. Just bump and tag with
115
+ `gem-release`.
116
+
117
+ For a patch release (0.0.x) use:
118
+
119
+ [source,sh]
120
+ ----
121
+ gem bump --version patch --tag --push
122
+ ----
123
+
124
+ For a minor release (0.x.0) use:
125
+
126
+ [source,sh]
127
+ ----
128
+ gem bump --version minor --tag --push
129
+ ----
130
+
44
131
  == Contributing
45
132
 
46
133
  Bug reports and pull requests are welcome on GitHub at
data/Rakefile CHANGED
@@ -10,3 +10,8 @@ require "rubocop/rake_task"
10
10
  RuboCop::RakeTask.new
11
11
 
12
12
  task default: %i[spec rubocop]
13
+
14
+ task :compile do
15
+ require_relative "ext/extconf"
16
+ end
17
+ task spec: :compile
data/bin/emf2svg ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "emf2svg"
6
+
7
+ svg = Emf2svg.from_file(ARGV[0])
8
+ File.write(ARGV[1], svg, mode: "wb")
data/emf2svg.gemspec CHANGED
@@ -17,15 +17,21 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata["source_code_uri"] = "https://github.com/metanorma/emf2svg-ruby"
18
18
  spec.metadata["changelog_uri"] = "https://github.com/metanorma/emf2svg-ruby"
19
19
 
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
20
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{\A(?:test|spec|features)/})
23
+ end
24
24
  end
25
25
  spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- # Uncomment to register a new dependency of your gem
30
- # spec.add_dependency "example-gem", "~> 1.0"
29
+ spec.add_runtime_dependency "ffi", "~> 1.0"
30
+ spec.add_runtime_dependency "mini_portile2", "~> 2.6"
31
+
32
+ spec.add_development_dependency "rubocop", "1.5.2"
33
+ spec.add_development_dependency "rubocop-performance"
34
+ spec.add_development_dependency "rubocop-rails"
35
+
36
+ spec.extensions = ["ext/extconf.rb"]
31
37
  end
data/exe/emf2svg ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "emf2svg"
5
+
6
+ svg = Emf2svg.from_file(ARGV[0])
7
+ File.write(ARGV[1], svg, mode: "wb")
data/ext/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ # dummy Makefile, it is required to build an extension
2
+ all:
3
+ clean:
4
+ install:
data/ext/extconf.rb ADDED
@@ -0,0 +1,6 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
2
+
3
+ require "emf2svg/recipe"
4
+
5
+ recipe = Emf2svg::Recipe.new
6
+ recipe.cook
@@ -0,0 +1,92 @@
1
+ require "mini_portile2"
2
+ require "pathname"
3
+ require "tmpdir"
4
+
5
+ module Emf2svg
6
+ class Recipe < MiniPortileCMake
7
+ ROOT = Pathname.new(File.expand_path("../..", __dir__))
8
+
9
+ def initialize
10
+ super("libemf2svg", "1.3.0")
11
+
12
+ @files << {
13
+ url: "https://github.com/metanorma/libemf2svg/releases/download/1.3.0/libemf2svg.tar.gz",
14
+ sha256: "aacbf001701e3f863e97c6c117146ee710636283851d866b715de653fb79343e", # rubocop:disable Layout/LineLength
15
+ }
16
+
17
+ @target = ROOT.join(@target).to_s
18
+ @printed = {}
19
+ end
20
+
21
+ def cook_if_not
22
+ cook unless File.exist?(checkpoint)
23
+ end
24
+
25
+ def cook
26
+ super
27
+
28
+ FileUtils.touch(checkpoint)
29
+ end
30
+
31
+ def checkpoint
32
+ File.join(@target, "#{name}-#{version}-#{host}.installed")
33
+ end
34
+
35
+ def configure_defaults
36
+ opts = []
37
+
38
+ opts << "-DCMAKE_BUILD_TYPE=Release"
39
+
40
+ if MiniPortile.windows?
41
+ opts << "-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
42
+ opts << "-GVisual Studio 16 2019"
43
+ end
44
+
45
+ opts
46
+ end
47
+
48
+ def compile
49
+ execute("compile", "#{make_cmd} --target emf2svg")
50
+ end
51
+
52
+ def make_cmd
53
+ "cmake --build #{File.expand_path(work_path)} --config Release"
54
+ end
55
+
56
+ def install
57
+ libs = if MiniPortile.windows?
58
+ Dir.glob(File.join(work_path, "Release", "*.dll"))
59
+ else
60
+ Dir.glob(File.join(work_path, "libemf2svg.{so,dylib}"))
61
+ .grep(/\/(?:lib)?[a-zA-Z0-9\-]+\.(?:so|dylib)$/)
62
+ end
63
+
64
+ FileUtils.cp_r(libs, ROOT.join("lib", "emf2svg"), verbose: true)
65
+ end
66
+
67
+ def execute(action, command, command_opts = {})
68
+ super(action, command, command_opts.merge(debug: true))
69
+ end
70
+
71
+ def message(text)
72
+ return super unless text.start_with?("\rDownloading")
73
+
74
+ match = text.match(/(\rDownloading .*)\(\s*\d+%\)/)
75
+ pattern = match ? match[1] : text
76
+ return if @printed[pattern]
77
+
78
+ @printed[pattern] = true
79
+ super
80
+ end
81
+
82
+ private
83
+
84
+ def tmp_path
85
+ @tmp_path ||= Dir.mktmpdir
86
+ end
87
+
88
+ def port_path
89
+ "port"
90
+ end
91
+ end
92
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emf2svg
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/emf2svg.rb CHANGED
@@ -1,8 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ffi"
3
4
  require_relative "emf2svg/version"
4
5
 
5
6
  module Emf2svg
6
7
  class Error < StandardError; end
7
- # Your code goes here...
8
+
9
+ class GeneratorOptions < FFI::Struct
10
+ layout :nameSpace, :string,
11
+ :verbose, :bool,
12
+ :emfplus, :bool,
13
+ :svgDelimiter, :bool,
14
+ :imgHeight, :double,
15
+ :imgWidth, :double
16
+ end
17
+
18
+ extend FFI::Library
19
+
20
+ lib_filename = if FFI::Platform.windows?
21
+ "emf2svg.dll"
22
+ elsif FFI::Platform.mac?
23
+ "libemf2svg.dylib"
24
+ else
25
+ "libemf2svg.so"
26
+ end
27
+
28
+ ffi_lib File.expand_path("emf2svg/#{lib_filename}", __dir__)
29
+ .gsub("/", File::ALT_SEPARATOR || File::SEPARATOR)
30
+
31
+ attach_function :emf2svg,
32
+ [
33
+ :pointer,
34
+ :size_t,
35
+ :pointer,
36
+ :pointer,
37
+ GeneratorOptions.by_ref,
38
+ ],
39
+ :int
40
+
41
+ class << self
42
+ def from_file(path)
43
+ content = File.read(path, mode: "rb")
44
+ from_binary_string(content)
45
+ end
46
+
47
+ def from_binary_string(content)
48
+ svg_out = FFI::MemoryPointer.new(:pointer)
49
+ svg_out_len = FFI::MemoryPointer.new(:pointer)
50
+ content_ptr = FFI::MemoryPointer.from_string(content)
51
+
52
+ ret = emf2svg(content_ptr, content.size, svg_out, svg_out_len, options)
53
+ raise Error, "emf2svg failed with error code: #{ret}" unless ret == 1
54
+
55
+ svg_out.read_pointer.read_bytes(svg_out_len.read_int)
56
+ end
57
+
58
+ private
59
+
60
+ def options
61
+ GeneratorOptions.new.tap do |opts|
62
+ opts[:verbose] = false
63
+ opts[:emfplus] = true
64
+ opts[:svgDelimiter] = true
65
+ opts[:imgHeight] = 0
66
+ opts[:imgWidth] = 0
67
+ end
68
+ end
69
+ end
8
70
  end
metadata CHANGED
@@ -1,23 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emf2svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-02 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_portile2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-performance
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
14
84
  email:
15
85
  - open.source@ribose.com
16
- executables: []
17
- extensions: []
86
+ executables:
87
+ - emf2svg
88
+ extensions:
89
+ - ext/extconf.rb
18
90
  extra_rdoc_files: []
19
91
  files:
20
92
  - ".github/workflows/main.yml"
93
+ - ".github/workflows/release.yml"
21
94
  - ".gitignore"
22
95
  - ".rspec"
23
96
  - ".rubocop.yml"
@@ -26,9 +99,14 @@ files:
26
99
  - README.adoc
27
100
  - Rakefile
28
101
  - bin/console
102
+ - bin/emf2svg
29
103
  - bin/setup
30
104
  - emf2svg.gemspec
105
+ - exe/emf2svg
106
+ - ext/Makefile
107
+ - ext/extconf.rb
31
108
  - lib/emf2svg.rb
109
+ - lib/emf2svg/recipe.rb
32
110
  - lib/emf2svg/version.rb
33
111
  homepage: https://github.com/metanorma/emf2svg-ruby
34
112
  licenses: []
@@ -36,7 +114,7 @@ metadata:
36
114
  homepage_uri: https://github.com/metanorma/emf2svg-ruby
37
115
  source_code_uri: https://github.com/metanorma/emf2svg-ruby
38
116
  changelog_uri: https://github.com/metanorma/emf2svg-ruby
39
- post_install_message:
117
+ post_install_message:
40
118
  rdoc_options: []
41
119
  require_paths:
42
120
  - lib
@@ -51,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
129
  - !ruby/object:Gem::Version
52
130
  version: '0'
53
131
  requirements: []
54
- rubygems_version: 3.0.3
55
- signing_key:
132
+ rubygems_version: 3.0.3.1
133
+ signing_key:
56
134
  specification_version: 4
57
135
  summary: Ruby interface to libemf2svg.
58
136
  test_files: []