elefont 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +12 -0
- data/Manifest.txt +8 -0
- data/README.txt +72 -0
- data/Rakefile +11 -0
- data/ext/elefont/elefont.c +40 -0
- data/ext/elefont/extconf.rb +6 -0
- data/lib/elefont.rb +5 -0
- data/test/test_elefont.rb +25 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1cbac479cb7d1201a5b9d1d9790d878f86dc03c3
|
4
|
+
data.tar.gz: 2fc93b2b80416eec7c98993693024c5a05fae87f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b87fcb4f3215588f00b22c4e26c994871739c8233fc9d1b88970ced337a266be7d183c17651ef4d243b989951e7b78a3f994174795f0f2e8f2a35e0b9a65cf02
|
7
|
+
data.tar.gz: 07c7b81b4ff165ff01169d53ab22d511a417198435dac81f9a743cfa88ac49c0be70e1fc522b01902b75852e8ccde56a5ec6865726d7c9edae3aea03c5d9ff3b
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= elefont
|
2
|
+
|
3
|
+
home :: https://github.com/phiggins/elefont
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
The gem that never forgets where your fonts are.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Finds closest matching TrueType font with fontconfig and returns the path.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
>> require 'elefont'
|
16
|
+
=> true
|
17
|
+
>> Elefont.best_match "Menlo"
|
18
|
+
=> "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
19
|
+
>> Elefont.best_match "Courier"
|
20
|
+
=> "/usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf"
|
21
|
+
>> Elefont.best_match "Arial"
|
22
|
+
=> "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
|
23
|
+
>> Elefont.best_match "lolol"
|
24
|
+
=> "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
|
28
|
+
* fontconfig development headers on Linux.
|
29
|
+
|
30
|
+
== INSTALL:
|
31
|
+
|
32
|
+
Linux:
|
33
|
+
|
34
|
+
`sudo apt-get install libfontconfig1-dev`
|
35
|
+
|
36
|
+
On OS X:
|
37
|
+
|
38
|
+
`brew install fontconfig`
|
39
|
+
|
40
|
+
== DEVELOPERS:
|
41
|
+
|
42
|
+
After checking out the source, run:
|
43
|
+
|
44
|
+
$ rake newb
|
45
|
+
|
46
|
+
This task will install any missing dependencies, run the tests/specs,
|
47
|
+
and generate the RDoc.
|
48
|
+
|
49
|
+
== LICENSE:
|
50
|
+
|
51
|
+
(The MIT License)
|
52
|
+
|
53
|
+
Copyright (c) 2016 Pete Higgins
|
54
|
+
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
56
|
+
a copy of this software and associated documentation files (the
|
57
|
+
'Software'), to deal in the Software without restriction, including
|
58
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
59
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
60
|
+
permit persons to whom the Software is furnished to do so, subject to
|
61
|
+
the following conditions:
|
62
|
+
|
63
|
+
The above copyright notice and this permission notice shall be
|
64
|
+
included in all copies or substantial portions of the Software.
|
65
|
+
|
66
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
67
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
68
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
69
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
70
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
71
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
72
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <fontconfig/fontconfig.h>
|
3
|
+
|
4
|
+
#include <stdio.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
|
7
|
+
static VALUE cElefont;
|
8
|
+
|
9
|
+
static VALUE
|
10
|
+
elefont_best_match(VALUE klass, VALUE str)
|
11
|
+
{
|
12
|
+
VALUE fontFile;
|
13
|
+
FcResult result;
|
14
|
+
FcPattern *match, *pat;
|
15
|
+
|
16
|
+
pat = FcNameParse((const FcChar8*)(StringValueCStr(str)));
|
17
|
+
FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8*)"TrueType");
|
18
|
+
|
19
|
+
FcConfigSubstitute(NULL, pat, FcMatchPattern);
|
20
|
+
FcDefaultSubstitute(pat);
|
21
|
+
match = FcFontMatch(NULL, pat, &result);
|
22
|
+
|
23
|
+
if (match) {
|
24
|
+
FcChar8* file = NULL;
|
25
|
+
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch) {
|
26
|
+
fontFile = rb_utf8_str_new_cstr((char*)file);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
FcPatternDestroy(match);
|
31
|
+
FcPatternDestroy(pat);
|
32
|
+
|
33
|
+
return fontFile;
|
34
|
+
}
|
35
|
+
|
36
|
+
void Init_elefont(void)
|
37
|
+
{
|
38
|
+
cElefont = rb_define_class("Elefont", rb_cObject);
|
39
|
+
rb_define_singleton_method(cElefont, "best_match", elefont_best_match, 1);
|
40
|
+
}
|
data/lib/elefont.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
gem "minitest"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "elefont"
|
4
|
+
|
5
|
+
class TestElefont < Minitest::Test
|
6
|
+
def test_best_match_finds_the_best_match_for_common_fonts
|
7
|
+
actual = Elefont.best_match("Menlo")
|
8
|
+
assert_equal 'DejaVuSans.ttf', actual.split('/').last
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_best_match_provides_a_good_default
|
12
|
+
actual = Elefont.best_match("NotARealFontName")
|
13
|
+
assert_equal 'DejaVuSans.ttf', actual.split('/').last
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_best_match_works_with_arial
|
17
|
+
actual = Elefont.best_match("Arial")
|
18
|
+
assert_equal 'Arial.ttf', actual.split('/').last
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_best_match_works_with_courier
|
22
|
+
actual = Elefont.best_match("Courier")
|
23
|
+
assert_equal 'Courier_New.ttf', actual.split('/').last
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elefont
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pete Higgins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.15'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.15'
|
69
|
+
description: The gem that never forgets where your fonts are.
|
70
|
+
email:
|
71
|
+
- pete@peterhiggins.org
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/elefont/extconf.rb
|
75
|
+
extra_rdoc_files:
|
76
|
+
- History.txt
|
77
|
+
- Manifest.txt
|
78
|
+
- README.txt
|
79
|
+
files:
|
80
|
+
- History.txt
|
81
|
+
- Manifest.txt
|
82
|
+
- README.txt
|
83
|
+
- Rakefile
|
84
|
+
- ext/elefont/elefont.c
|
85
|
+
- ext/elefont/extconf.rb
|
86
|
+
- lib/elefont.rb
|
87
|
+
- test/test_elefont.rb
|
88
|
+
homepage: https://github.com/phiggins/elefont
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options:
|
94
|
+
- "--main"
|
95
|
+
- README.txt
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.6.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: The gem that never forgets where your fonts are.
|
114
|
+
test_files: []
|