cheapredwine 0.2.0 → 0.3.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 +7 -0
- data/.travis.yml +10 -0
- data/README.md +9 -19
- data/lib/cheapredwine/image/params.rb +1 -1
- data/lib/cheapredwine/image/writer.rb +1 -1
- data/lib/cheapredwine/info.rb +1 -1
- data/lib/cheapredwine/version.rb +2 -2
- data/lib/cheapredwine.rb +32 -34
- data/spec/cheapredwine_spec.rb +4 -4
- data/spec/image/params_spec.rb +2 -4
- data/spec/image/writer_spec.rb +4 -6
- data/spec/info_spec.rb +2 -4
- metadata +14 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0db300cc3cd1f51a506262396b30650345609de
|
4
|
+
data.tar.gz: d48412833b31a5bfbfceaca49fbdc39cd62e3d45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d1f414e15102ad639243999c88d0b4db26949225fc94512e916bb88750dc1e13f18d153498197faaf8cf7b383e51e22b550e1d503e932c893282afae6856258
|
7
|
+
data.tar.gz: 8814e6f52930c0dd488c612a77a952cd67b260fb1cf41bd1375c005caddbbf86aeecc628e2b053e889b8b2c2e3e5f7722efd645a2f93057b8b3ce26f24e4fe7e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -18,22 +18,25 @@ It assumes the following is installed and in the case where it applies, accessib
|
|
18
18
|
|
19
19
|
* [cairo](http://www.cairographics.org/releases/)
|
20
20
|
* [harfbuzz](http://www.freedesktop.org/software/harfbuzz/release/)
|
21
|
-
* [ttx](https://github.com/mcolyer/fonttools)
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
24
|
#### Getting a font object from a simple ttf or otf file:
|
26
25
|
|
27
|
-
font = CheapRedWine.
|
26
|
+
font = CheapRedWine.new font_file
|
28
27
|
font.name # => "Font Name"
|
28
|
+
font.family # => "Font Family"
|
29
|
+
font.style # => "Bold Italic"
|
29
30
|
font.features # => ["liga", "onum", "dlig", … "salt"]
|
30
31
|
|
31
32
|
#### Generating images with text for the font:
|
32
33
|
|
33
|
-
image =
|
34
|
-
|
35
|
-
|
34
|
+
image = font.image "some text", options
|
35
|
+
# ... do something with image ...
|
36
|
+
image.close
|
36
37
|
|
38
|
+
**Caveat:** `image` is an IO object that can then be use to write to disk. You are responsible to close that object.
|
39
|
+
|
37
40
|
##### Options
|
38
41
|
|
39
42
|
options = {
|
@@ -43,18 +46,6 @@ It assumes the following is installed and in the case where it applies, accessib
|
|
43
46
|
features: [liga, salt] # list of otf features to be applied
|
44
47
|
}
|
45
48
|
|
46
|
-
##### Configuration
|
47
|
-
|
48
|
-
CheapRedWine needs to know where to put ttx files
|
49
|
-
|
50
|
-
CheapRedWine::TTX.configure do |config|
|
51
|
-
config.output_folder = '/path/to/folder'
|
52
|
-
end
|
53
|
-
|
54
|
-
You can also change the output_folder dynamically through
|
55
|
-
|
56
|
-
CheapRedWine.ttx_output_folder = "path/to/folder"
|
57
|
-
|
58
49
|
## Contributing
|
59
50
|
|
60
51
|
1. Fork it
|
@@ -65,5 +56,4 @@ You can also change the output_folder dynamically through
|
|
65
56
|
|
66
57
|
## TODO
|
67
58
|
|
68
|
-
1.
|
69
|
-
2. Replace hb-view by something more appropriate (C Extension).
|
59
|
+
1. Replace hb-view by something more appropriate (C Extension).
|
data/lib/cheapredwine/info.rb
CHANGED
data/lib/cheapredwine/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class CheapRedWine
|
2
|
+
VERSION = "0.3.1"
|
3
3
|
end
|
data/lib/cheapredwine.rb
CHANGED
@@ -2,56 +2,54 @@ require "cheapredwine/version"
|
|
2
2
|
require "cheapredwine/info"
|
3
3
|
require "cheapredwine/image"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
class CheapRedWine
|
6
|
+
extend Forwardable
|
7
|
+
attr_accessor :font
|
8
|
+
def_delegators :@font, :file, :name, :family, :style, :features
|
9
|
+
|
10
|
+
def initialize(file)
|
11
|
+
info = Info.new file
|
12
|
+
@font = Font.new do |font|
|
13
|
+
font.name = info.font_name
|
14
|
+
font.family = info.family_name
|
15
|
+
font.features = info.features
|
16
|
+
font.style = info.style
|
17
|
+
font.path = file
|
18
|
+
font
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
parser = Info.new file
|
21
|
-
Meta.new do |meta|
|
22
|
-
meta.name = parser.font_name
|
23
|
-
meta.family = parser.family_name
|
24
|
-
meta.features = parser.features
|
25
|
-
meta.style = parser.style
|
26
|
-
meta.path = file
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.image(font, text, options = {})
|
22
|
+
def image(text, options = {})
|
31
23
|
features = merge_features(font.features, options.fetch(:features) { [] })
|
32
|
-
|
24
|
+
|
25
|
+
params = options.merge({
|
33
26
|
features: features,
|
34
27
|
font: font.file,
|
35
28
|
text: text
|
36
29
|
})
|
37
|
-
params = Image::Params.new(options)
|
38
|
-
Image::Writer.new(params).exec
|
39
|
-
end
|
40
30
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.ttx_output_folder
|
46
|
-
CheapRedWine::TTX.configuration.output_folder
|
31
|
+
params = Image::Params.new(params)
|
32
|
+
Image::Writer.new(params).exec
|
47
33
|
end
|
48
34
|
|
49
35
|
private
|
50
36
|
|
51
|
-
def
|
37
|
+
def merge_features(all_features, selected_features)
|
52
38
|
all_features.map do |feature|
|
53
39
|
prefix = selected_features.include?(feature) ? '+' : '-'
|
54
40
|
prefix + feature
|
55
41
|
end
|
56
42
|
end
|
43
|
+
|
44
|
+
class Font
|
45
|
+
attr_accessor :name, :family, :features, :path, :style
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
yield(self) if block_given?
|
49
|
+
end
|
50
|
+
|
51
|
+
def file
|
52
|
+
File.new(path)
|
53
|
+
end
|
54
|
+
end
|
57
55
|
end
|
data/spec/cheapredwine_spec.rb
CHANGED
@@ -3,16 +3,16 @@ require 'tempfile'
|
|
3
3
|
|
4
4
|
describe CheapRedWine do
|
5
5
|
let(:file) { File.new('spec/fixtures/hobo.otf') }
|
6
|
-
let(:
|
6
|
+
let(:wine) { CheapRedWine.new(file) }
|
7
7
|
|
8
8
|
it "gets meta information from a font file" do
|
9
|
-
|
10
|
-
|
9
|
+
wine.name.should eq "Hobo Std Medium"
|
10
|
+
wine.file.path.should match file.path
|
11
11
|
end
|
12
12
|
|
13
13
|
it "can create images from text" do
|
14
14
|
options = { size: 26, features: ['liga', 'frac'] }
|
15
|
-
image =
|
15
|
+
image = wine.image 'ffi 1/2', options
|
16
16
|
tempfile = Tempfile.new('image')
|
17
17
|
tempfile.write(image.read)
|
18
18
|
tempfile.close
|
data/spec/image/params_spec.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'cheapredwine/image/params'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe Params do
|
3
|
+
describe CheapRedWine::Image::Params do
|
6
4
|
it "takes a bunch of options" do
|
7
5
|
font = double
|
8
6
|
features = ['kern', 'aalt', 'onum', 'liga']
|
9
7
|
|
10
|
-
params = Params.new(
|
8
|
+
params = CheapRedWine::Image::Params.new(
|
11
9
|
font: font,
|
12
10
|
color: 'black',
|
13
11
|
features: features,
|
data/spec/image/writer_spec.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'cheapredwine/image/writer'
|
2
2
|
require 'cheapredwine/image/params'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
describe Writer do
|
4
|
+
describe CheapRedWine::Image::Writer do
|
7
5
|
let(:font) { double("font", path: "spec/fixtures/lato-regular.ttf") }
|
8
|
-
let(:image) { Params.new(font: font, text: "Lorem ipsum") }
|
6
|
+
let(:image) { CheapRedWine::Image::Params.new(font: font, text: "Lorem ipsum") }
|
9
7
|
|
10
8
|
it "builds a command from a Params object" do
|
11
|
-
writer = Writer.new(image)
|
9
|
+
writer = CheapRedWine::Image::Writer.new(image)
|
12
10
|
writer.args[0].should eq "--font-file=spec/fixtures/lato-regular.ttf"
|
13
11
|
end
|
14
12
|
|
15
13
|
it "generates a image of given text" do
|
16
14
|
file = File.new('spec/fixtures/test.png')
|
17
15
|
|
18
|
-
writer = Writer.new(image)
|
16
|
+
writer = CheapRedWine::Image::Writer.new(image)
|
19
17
|
tempfile = writer.exec
|
20
18
|
FileUtils.compare_file(tempfile, file)
|
21
19
|
end
|
data/spec/info_spec.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'cheapredwine/info'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
describe Info do
|
3
|
+
describe CheapRedWine::Info do
|
6
4
|
it "get info out of an otf or ttf font file" do
|
7
5
|
font = 'spec/fixtures/hobo.otf'
|
8
|
-
info = Info.new font
|
6
|
+
info = CheapRedWine::Info.new font
|
9
7
|
info.font_name.should eq "Hobo Std Medium"
|
10
8
|
info.family_name.should eq "Hobo Std"
|
11
9
|
info.style.should eq "Regular"
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheapredwine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Hugo Bastien
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: tipo
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: I needed a way to test fonts on the web. I based this library on myfonts.com.
|
@@ -70,6 +63,7 @@ extensions: []
|
|
70
63
|
extra_rdoc_files: []
|
71
64
|
files:
|
72
65
|
- .gitignore
|
66
|
+
- .travis.yml
|
73
67
|
- Gemfile
|
74
68
|
- LICENSE.txt
|
75
69
|
- README.md
|
@@ -94,27 +88,26 @@ files:
|
|
94
88
|
- spec/info_spec.rb
|
95
89
|
homepage: https://github.com/hugobast/cheapredwine
|
96
90
|
licenses: []
|
91
|
+
metadata: {}
|
97
92
|
post_install_message:
|
98
93
|
rdoc_options: []
|
99
94
|
require_paths:
|
100
95
|
- lib
|
101
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
97
|
requirements:
|
104
|
-
- -
|
98
|
+
- - '>='
|
105
99
|
- !ruby/object:Gem::Version
|
106
100
|
version: '0'
|
107
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
102
|
requirements:
|
110
|
-
- -
|
103
|
+
- - '>='
|
111
104
|
- !ruby/object:Gem::Version
|
112
105
|
version: '0'
|
113
106
|
requirements: []
|
114
107
|
rubyforge_project:
|
115
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.0.3
|
116
109
|
signing_key:
|
117
|
-
specification_version:
|
110
|
+
specification_version: 4
|
118
111
|
summary: I needed a way to test fonts on the web. I based this library on myfonts.com.
|
119
112
|
CheapRedWine makes use to Harfbuzz' hb-view utility to generate images from fonts
|
120
113
|
with a slew of different parameters. It also uses fontTools' ttx utility for font
|