awesome_map_marker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/app/assets/fonts/fa-brands-400.ttf +0 -0
- data/app/assets/fonts/fa-regular-400.ttf +0 -0
- data/app/assets/fonts/fa-solid-900.ttf +0 -0
- data/app/assets/images/base.png +0 -0
- data/app/assets/images/icon-base.png +0 -0
- data/awesome_map_marker.gemspec +45 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/fab.yml +829 -0
- data/config/far.yml +303 -0
- data/config/fas.yml +1871 -0
- data/lib/awesome_map_marker/version.rb +3 -0
- data/lib/awesome_map_marker.rb +137 -0
- metadata +137 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require 'awesome_map_marker/version'
|
4
|
+
require 'mini_magick'
|
5
|
+
require 'yaml'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
# ##########################################
|
9
|
+
# AwesomeMapMarker
|
10
|
+
# Version 0.1.0
|
11
|
+
# 2019-02-04
|
12
|
+
# Author Kazuomatz
|
13
|
+
# ##########################################
|
14
|
+
module AwesomeMapMarker
|
15
|
+
class Error < StandardError; end
|
16
|
+
|
17
|
+
def self.generate(type: :fas,
|
18
|
+
name: 'fa-map-marker-alt',
|
19
|
+
size: 128,
|
20
|
+
fill_color: '#e45340')
|
21
|
+
|
22
|
+
size = 1024 if size > 1024
|
23
|
+
return nil if size <= 0
|
24
|
+
|
25
|
+
font_image = FontAwesome.generate(type: type, name: name, size: size * 0.6)
|
26
|
+
return nil if font_image.nil?
|
27
|
+
|
28
|
+
tmp_file = Tempfile.new(%w[icon .png])
|
29
|
+
tmp_file.close
|
30
|
+
|
31
|
+
MiniMagick::Tool::Convert.new do |magick|
|
32
|
+
magick << File.expand_path('../app/assets/images/icon-base.png', __dir__)
|
33
|
+
magick.resize("#{size}x#{size}")
|
34
|
+
magick.fuzz '100%'
|
35
|
+
magick.fill fill_color
|
36
|
+
magick.opaque '#0000FF'
|
37
|
+
magick << tmp_file.path
|
38
|
+
end
|
39
|
+
|
40
|
+
base_image = MiniMagick::Image.open(tmp_file.path)
|
41
|
+
|
42
|
+
tmp_file.unlink
|
43
|
+
base_image.composite(font_image) do |composite|
|
44
|
+
composite.compose 'over'
|
45
|
+
composite.gravity 'center'
|
46
|
+
composite.geometry "+0-#{size * 0.04}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Convert web-font to PNG
|
52
|
+
#
|
53
|
+
class FontAwesome
|
54
|
+
class << self
|
55
|
+
def generate(type: :fas,
|
56
|
+
name: 'map-marker',
|
57
|
+
size: 128,
|
58
|
+
fill_color: '#FFFFFF')
|
59
|
+
|
60
|
+
# MiniMagick.logger.level = Logger::DEBUG
|
61
|
+
|
62
|
+
name.delete_prefix!('fa-')
|
63
|
+
icon_data = icon_data(type.to_s, name.to_s)
|
64
|
+
return nil if icon_data.nil?
|
65
|
+
|
66
|
+
x = 0
|
67
|
+
y = (size / 12.8) * -1
|
68
|
+
|
69
|
+
font_size = (size * 0.76).ceil
|
70
|
+
|
71
|
+
unicode = icon_data[:unicode]
|
72
|
+
char = [Integer("0x#{unicode}")].pack('U*')
|
73
|
+
path = font_path(icon_type(type))
|
74
|
+
|
75
|
+
image = MiniMagick::Image.open(
|
76
|
+
File.expand_path('../app/assets/images/base.png', __dir__)
|
77
|
+
)
|
78
|
+
image.combine_options do |config|
|
79
|
+
config.resize "#{size}x#{size}"
|
80
|
+
config.font path
|
81
|
+
config.gravity 'center'
|
82
|
+
config.pointsize font_size
|
83
|
+
config.kerning 0
|
84
|
+
config.stroke 'transparent'
|
85
|
+
config.fill fill_color
|
86
|
+
config.draw "text #{x},#{y} '#{char}'"
|
87
|
+
end
|
88
|
+
image
|
89
|
+
end
|
90
|
+
|
91
|
+
def icons(type)
|
92
|
+
icons_data_yml(icon_type(type).to_s)
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def icon_data(type, name)
|
98
|
+
icons_data_yml(icon_type(type).to_s).select do |icon|
|
99
|
+
icon[:id] == name
|
100
|
+
end.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def icon_type(type)
|
104
|
+
return :fas if type.nil?
|
105
|
+
|
106
|
+
case type.to_s
|
107
|
+
when 'far', 'regular'
|
108
|
+
:far
|
109
|
+
when 'fab', 'brand'
|
110
|
+
:fab
|
111
|
+
else
|
112
|
+
:fas
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def icons_data_yml(type)
|
117
|
+
yml_path = File.expand_path(
|
118
|
+
"../../config/#{icon_type(type)}.yml",
|
119
|
+
__FILE__
|
120
|
+
)
|
121
|
+
YAML.load_file(yml_path)
|
122
|
+
end
|
123
|
+
|
124
|
+
def font_path(type)
|
125
|
+
path = File.expand_path('../app/assets/fonts', __dir__)
|
126
|
+
case icon_type(type).to_s
|
127
|
+
when 'far'
|
128
|
+
File.join(path, 'fa-regular-400.ttf')
|
129
|
+
when 'fab'
|
130
|
+
File.join(path, 'fa-brands-400.ttf')
|
131
|
+
else # fas
|
132
|
+
File.join(path, 'fa-solid-900.ttf')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awesome_map_marker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuo Matsunaga
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
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: mini_magick
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.8'
|
83
|
+
description: 'Generate marker for plotting on maps such as Google Map, Open Street
|
84
|
+
Map and iOS App etc. '
|
85
|
+
email:
|
86
|
+
- getlasterror@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- app/assets/fonts/fa-brands-400.ttf
|
101
|
+
- app/assets/fonts/fa-regular-400.ttf
|
102
|
+
- app/assets/fonts/fa-solid-900.ttf
|
103
|
+
- app/assets/images/base.png
|
104
|
+
- app/assets/images/icon-base.png
|
105
|
+
- awesome_map_marker.gemspec
|
106
|
+
- bin/console
|
107
|
+
- bin/setup
|
108
|
+
- config/fab.yml
|
109
|
+
- config/far.yml
|
110
|
+
- config/fas.yml
|
111
|
+
- lib/awesome_map_marker.rb
|
112
|
+
- lib/awesome_map_marker/version.rb
|
113
|
+
homepage: https://github.com/kazuomatz
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.7.6
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: AwesomeMapMarker is a library that generates markers from Fontawesome 5.
|
137
|
+
test_files: []
|