ascii_pngfy 0.2.0
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 +7 -0
- data/lib/ascii_pngfy.rb +40 -0
- data/lib/ascii_pngfy/aabb.rb +49 -0
- data/lib/ascii_pngfy/color_rgba.rb +56 -0
- data/lib/ascii_pngfy/exceptions.rb +29 -0
- data/lib/ascii_pngfy/glyphs.rb +118 -0
- data/lib/ascii_pngfy/pngfyer.rb +43 -0
- data/lib/ascii_pngfy/rendering_rules.rb +198 -0
- data/lib/ascii_pngfy/result.rb +25 -0
- data/lib/ascii_pngfy/settings.rb +6 -0
- data/lib/ascii_pngfy/settings/color_setting.rb +44 -0
- data/lib/ascii_pngfy/settings/font_height_setting.rb +74 -0
- data/lib/ascii_pngfy/settings/horizontal_spacing_setting.rb +46 -0
- data/lib/ascii_pngfy/settings/setable_getable.rb +35 -0
- data/lib/ascii_pngfy/settings/setable_getable_settings.rb +85 -0
- data/lib/ascii_pngfy/settings/settings_snapshot.rb +35 -0
- data/lib/ascii_pngfy/settings/text_setting.rb +210 -0
- data/lib/ascii_pngfy/settings/vertical_spacing_setting.rb +46 -0
- data/lib/ascii_pngfy/settings_renderer.rb +41 -0
- data/lib/ascii_pngfy/vec2i.rb +23 -0
- metadata +155 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AsciiPngfy
|
4
|
+
module Settings
|
5
|
+
# Reponsibilities
|
6
|
+
# - Keeps track of the the vertical_spacing setting
|
7
|
+
# - Validates vertical_spacing
|
8
|
+
class VerticalSpacingSetting
|
9
|
+
include SetableGetable
|
10
|
+
|
11
|
+
def initialize(initial_spacing)
|
12
|
+
self.vertical_spacing = 0
|
13
|
+
|
14
|
+
set(initial_spacing)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get
|
18
|
+
vertical_spacing
|
19
|
+
end
|
20
|
+
|
21
|
+
def set(desired_spacing)
|
22
|
+
validated_vertical_spacing = validate_vertical_spacing(desired_spacing)
|
23
|
+
|
24
|
+
self.vertical_spacing = validated_vertical_spacing
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor(:vertical_spacing)
|
30
|
+
|
31
|
+
def vertical_spacing_valid?(some_spacing)
|
32
|
+
some_spacing.is_a?(Integer) && (some_spacing >= 0)
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_vertical_spacing(some_spacing)
|
36
|
+
return some_spacing if vertical_spacing_valid?(some_spacing)
|
37
|
+
|
38
|
+
error_message = String.new
|
39
|
+
error_message << "#{some_spacing} is not a valid vertical spacing. "
|
40
|
+
error_message << 'Must be an Integer in the range (0..).'
|
41
|
+
|
42
|
+
raise AsciiPngfy::Exceptions::InvalidVerticalSpacingError, error_message
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AsciiPngfy
|
4
|
+
# Reponsibilities
|
5
|
+
# - Uses RenderingRules to interpret settings into a Result object
|
6
|
+
# - Uses Glyph designs to plot design data into the result png
|
7
|
+
class SettingsRenderer
|
8
|
+
def initialize(use_glyph_designs: true)
|
9
|
+
self.use_glyph_designs = use_glyph_designs
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_result(settings_snapshot)
|
13
|
+
png = generate_png(settings_snapshot)
|
14
|
+
|
15
|
+
RenderingRules.plot_settings(settings_snapshot, use_glyph_designs, png)
|
16
|
+
|
17
|
+
generate_result(settings_snapshot, png)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_png(settings)
|
23
|
+
ChunkyPNG::Image.new(
|
24
|
+
RenderingRules.png_width(settings),
|
25
|
+
RenderingRules.png_height(settings),
|
26
|
+
RenderingRules.color_rgba_to_chunky_png_integer(settings.background_color)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_result(settings, png)
|
31
|
+
Result.new(
|
32
|
+
png,
|
33
|
+
RenderingRules.render_width(settings),
|
34
|
+
RenderingRules.render_height(settings),
|
35
|
+
settings
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_accessor(:use_glyph_designs)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AsciiPngfy
|
4
|
+
# Reponsibilities
|
5
|
+
# - Helper used to represent integer pixel coordinate pair
|
6
|
+
# - Public getters for each coordinate
|
7
|
+
class Vec2i
|
8
|
+
attr_reader(:x, :y)
|
9
|
+
|
10
|
+
def initialize(initial_x = 0, initial_y = 0)
|
11
|
+
self.x = initial_x
|
12
|
+
self.y = initial_y
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"[#{x}, #{y}]"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_writer(:x, :y)
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ascii_pngfy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sven Garson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chunky_png
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.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.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.14.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.14.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-reporters
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 13.0.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 13.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.9.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.9.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.3
|
97
|
+
description: AsciiPngfy is a Ruby Gem that enables you to render ASCII text into a
|
98
|
+
PNG image up to a resolution of 3840(width) by 2160(height) using a 5x9 monospaced
|
99
|
+
font. Configurable settings that influence the result are font-color, background-color,
|
100
|
+
font-height, horizontal-spacing, vertical-spacing, and text. The result includes
|
101
|
+
the PNG containing the intended image with all the settings applied, a snapshot
|
102
|
+
of the settings used, and render dimensions that define the size the generated png
|
103
|
+
should be rendered at to reflect the font-height settings. The generated png is
|
104
|
+
always the lowest possible resolution. Each monospaced character takes up a 5(width)
|
105
|
+
by 9(height) space to take advantage of scaled rendering and avoid unnecessarily
|
106
|
+
large images. For the best visual results, the resulting png should be rendered
|
107
|
+
in the original dimensions or the render dimensions along with a NEAREST filter.
|
108
|
+
email: sven.garson@outlook.com
|
109
|
+
executables: []
|
110
|
+
extensions: []
|
111
|
+
extra_rdoc_files: []
|
112
|
+
files:
|
113
|
+
- lib/ascii_pngfy.rb
|
114
|
+
- lib/ascii_pngfy/aabb.rb
|
115
|
+
- lib/ascii_pngfy/color_rgba.rb
|
116
|
+
- lib/ascii_pngfy/exceptions.rb
|
117
|
+
- lib/ascii_pngfy/glyphs.rb
|
118
|
+
- lib/ascii_pngfy/pngfyer.rb
|
119
|
+
- lib/ascii_pngfy/rendering_rules.rb
|
120
|
+
- lib/ascii_pngfy/result.rb
|
121
|
+
- lib/ascii_pngfy/settings.rb
|
122
|
+
- lib/ascii_pngfy/settings/color_setting.rb
|
123
|
+
- lib/ascii_pngfy/settings/font_height_setting.rb
|
124
|
+
- lib/ascii_pngfy/settings/horizontal_spacing_setting.rb
|
125
|
+
- lib/ascii_pngfy/settings/setable_getable.rb
|
126
|
+
- lib/ascii_pngfy/settings/setable_getable_settings.rb
|
127
|
+
- lib/ascii_pngfy/settings/settings_snapshot.rb
|
128
|
+
- lib/ascii_pngfy/settings/text_setting.rb
|
129
|
+
- lib/ascii_pngfy/settings/vertical_spacing_setting.rb
|
130
|
+
- lib/ascii_pngfy/settings_renderer.rb
|
131
|
+
- lib/ascii_pngfy/vec2i.rb
|
132
|
+
homepage: https://github.com/SvenGarson/ascii_pngfy
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 2.7.2
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubygems_version: 3.1.4
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Ruby Gem that renders ASCII text into PNGs using a 5x9 monospaced font.
|
155
|
+
test_files: []
|