vectory 0.8.0 → 0.8.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docs.yml +59 -0
  3. data/.github/workflows/links.yml +99 -0
  4. data/.github/workflows/rake.yml +5 -1
  5. data/.github/workflows/release.yml +7 -3
  6. data/.gitignore +5 -0
  7. data/.rubocop.yml +11 -3
  8. data/.rubocop_todo.yml +252 -0
  9. data/Gemfile +4 -2
  10. data/README.adoc +23 -1
  11. data/Rakefile +13 -0
  12. data/docs/Gemfile +18 -0
  13. data/docs/_config.yml +179 -0
  14. data/docs/features/conversion.adoc +205 -0
  15. data/docs/features/external-dependencies.adoc +305 -0
  16. data/docs/features/format-detection.adoc +173 -0
  17. data/docs/features/index.adoc +205 -0
  18. data/docs/getting-started/core-concepts.adoc +214 -0
  19. data/docs/getting-started/index.adoc +37 -0
  20. data/docs/getting-started/installation.adoc +318 -0
  21. data/docs/getting-started/quick-start.adoc +160 -0
  22. data/docs/guides/error-handling.adoc +400 -0
  23. data/docs/guides/index.adoc +197 -0
  24. data/docs/index.adoc +146 -0
  25. data/docs/lychee.toml +25 -0
  26. data/docs/reference/api.adoc +355 -0
  27. data/docs/reference/index.adoc +189 -0
  28. data/docs/understanding/architecture.adoc +277 -0
  29. data/docs/understanding/index.adoc +148 -0
  30. data/docs/understanding/inkscape-wrapper.adoc +270 -0
  31. data/lib/vectory/capture.rb +165 -37
  32. data/lib/vectory/cli.rb +2 -0
  33. data/lib/vectory/configuration.rb +177 -0
  34. data/lib/vectory/conversion/ghostscript_strategy.rb +77 -0
  35. data/lib/vectory/conversion/inkscape_strategy.rb +124 -0
  36. data/lib/vectory/conversion/strategy.rb +58 -0
  37. data/lib/vectory/conversion.rb +104 -0
  38. data/lib/vectory/datauri.rb +1 -1
  39. data/lib/vectory/emf.rb +17 -5
  40. data/lib/vectory/eps.rb +45 -3
  41. data/lib/vectory/errors.rb +25 -0
  42. data/lib/vectory/file_magic.rb +2 -2
  43. data/lib/vectory/ghostscript_wrapper.rb +160 -0
  44. data/lib/vectory/image_resize.rb +2 -2
  45. data/lib/vectory/inkscape_wrapper.rb +205 -0
  46. data/lib/vectory/pdf.rb +76 -0
  47. data/lib/vectory/platform.rb +105 -0
  48. data/lib/vectory/ps.rb +47 -3
  49. data/lib/vectory/svg.rb +46 -3
  50. data/lib/vectory/svg_document.rb +40 -24
  51. data/lib/vectory/system_call.rb +36 -9
  52. data/lib/vectory/vector.rb +3 -23
  53. data/lib/vectory/version.rb +1 -1
  54. data/lib/vectory.rb +16 -11
  55. metadata +34 -3
  56. data/lib/vectory/inkscape_converter.rb +0 -141
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "singleton"
4
- require "tmpdir"
5
- require_relative "system_call"
6
-
7
- module Vectory
8
- class InkscapeConverter
9
- include Singleton
10
-
11
- def self.convert(uri, output_extension, option)
12
- instance.convert(uri, output_extension, option)
13
- end
14
-
15
- def convert(uri, output_extension, option)
16
- exe = inkscape_path_or_raise_error
17
- uri = external_path uri
18
- exe = external_path exe
19
- cmd = %(#{exe} #{option} #{uri})
20
-
21
- call = SystemCall.new(cmd).call
22
-
23
- output_path = find_output(uri, output_extension)
24
- raise_conversion_error(call) unless output_path
25
-
26
- output_path
27
- end
28
-
29
- def height(content, format)
30
- query_integer(content, format, "--query-height")
31
- end
32
-
33
- def width(content, format)
34
- query_integer(content, format, "--query-width")
35
- end
36
-
37
- private
38
-
39
- def inkscape_path_or_raise_error
40
- inkscape_path or raise(InkscapeNotFoundError,
41
- "Inkscape missing in PATH, unable to " \
42
- "convert image. Aborting.")
43
- end
44
-
45
- def inkscape_path
46
- @inkscape_path ||= find_inkscape
47
- end
48
-
49
- def find_inkscape
50
- cmds.each do |cmd|
51
- extensions.each do |ext|
52
- paths.each do |path|
53
- exe = File.join(path, "#{cmd}#{ext}")
54
-
55
- return exe if File.executable?(exe) && !File.directory?(exe)
56
- end
57
- end
58
- end
59
-
60
- nil
61
- end
62
-
63
- def cmds
64
- ["inkscapecom", "inkscape"]
65
- end
66
-
67
- def extensions
68
- ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
69
- end
70
-
71
- def paths
72
- ENV["PATH"].split(File::PATH_SEPARATOR)
73
- end
74
-
75
- def find_output(source_path, output_extension)
76
- basenames = [File.basename(source_path, ".*"),
77
- File.basename(source_path)]
78
-
79
- paths = basenames.map do |basename|
80
- "#{File.join(File.dirname(source_path), basename)}.#{output_extension}"
81
- end
82
-
83
- paths.find { |p| File.exist?(p) }
84
- end
85
-
86
- def raise_conversion_error(call)
87
- raise Vectory::ConversionError,
88
- "Could not convert with Inkscape. " \
89
- "Inkscape cmd: '#{call.cmd}',\n" \
90
- "status: '#{call.status}',\n" \
91
- "stdout: '#{call.stdout.strip}',\n" \
92
- "stderr: '#{call.stderr.strip}'."
93
- end
94
-
95
- def external_path(path)
96
- win = !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) ||
97
- (RUBY_PLATFORM =~ /mswin|mingw/))
98
- if win
99
- path.gsub!(%{/}, "\\")
100
- path[/\s/] ? "\"#{path}\"" : path
101
- else
102
- path
103
- end
104
- end
105
-
106
- def query_integer(content, format, options)
107
- query(content, format, options).to_f.round
108
- end
109
-
110
- def query(content, format, options)
111
- exe = inkscape_path_or_raise_error
112
-
113
- with_file(content, format) do |path|
114
- cmd = "#{external_path(exe)} #{options} #{external_path(path)}"
115
-
116
- call = SystemCall.new(cmd).call
117
- raise_query_error(call) if call.stdout.empty?
118
-
119
- call.stdout
120
- end
121
- end
122
-
123
- def with_file(content, extension)
124
- Dir.mktmpdir do |dir|
125
- path = File.join(dir, "image.#{extension}")
126
- File.binwrite(path, content)
127
-
128
- yield path
129
- end
130
- end
131
-
132
- def raise_query_error(call)
133
- raise Vectory::InkscapeQueryError,
134
- "Could not query with Inkscape. " \
135
- "Inkscape cmd: '#{call.cmd}',\n" \
136
- "status: '#{call.status}',\n" \
137
- "stdout: '#{call.stdout.strip}',\n" \
138
- "stderr: '#{call.stderr.strip}'."
139
- end
140
- end
141
- end