extract_ttc 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6d17daa99ebfce9bef022ad42667c35c183a687e0aac23436971dd946a98d45
4
- data.tar.gz: 0e08cddcb9547b00eb95fd54f1df55669cfc5e3572604874f0f208ad93e36034
3
+ metadata.gz: 14bfdf74e01cabae76976c49a69ac06b2309b98c7a892d3379e94a67ae57abfd
4
+ data.tar.gz: e7071d8582ce62b6e9786fc7d5b01cfa987a29b9639bfd98a29979d3a13b6c74
5
5
  SHA512:
6
- metadata.gz: 8b94ad46a8aa508e7a48d310a88de0888ca39cb9c7e0b4e58b9a68327332ce036f82c69fd60ca0da2f00dc828e87b1cc689eecf48b3c4e474d04ba0538bc608c
7
- data.tar.gz: 60d2eec18035282b015ce768900147f2af35852592f050f8c5fa000f1c16da5c0766fe4be2cc279f0b7b13a0100269d48fb4fc4f12567a718a5074a63aaf69bf
6
+ metadata.gz: b469545b5820a5f317f33f672de603cfe10753f402a45d6ffb85814d7bafa3e48d19ca6a30ae57e2fb7aa16f0206948b786472bc817f5480605e5016a970dd80
7
+ data.tar.gz: ef1484c1f208f6d4336fd9e094259b344d65b43a82cd216b0c16bf3f0b553b872acf361c173bd878033abf37d3d5e3da7c7b12796790ce414aa7959ec65d66d7
@@ -1 +1,6 @@
1
- # do nothing, Makefile is already here
1
+ require "mkmf"
2
+ require "rbconfig"
3
+
4
+ CONFIG["LDSHARED"] << " -shared" unless RbConfig::CONFIG["host_os"].match?(/darwin/)
5
+
6
+ create_makefile "stripttc"
metadata CHANGED
@@ -1,29 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extract_ttc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.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.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
17
34
  - - ">="
18
35
  - !ruby/object:Gem::Version
19
- version: '0'
36
+ version: 2.3.22
20
37
  type: :runtime
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.3'
24
44
  - - ">="
25
45
  - !ruby/object:Gem::Version
26
- version: '0'
46
+ version: 2.3.22
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake-compiler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.2'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake-compiler-dock
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.2'
27
89
  - !ruby/object:Gem::Dependency
28
90
  name: rspec
29
91
  requirement: !ruby/object:Gem::Requirement
@@ -42,44 +104,44 @@ dependencies:
42
104
  name: rubocop
43
105
  requirement: !ruby/object:Gem::Requirement
44
106
  requirements:
45
- - - '='
107
+ - - "~>"
46
108
  - !ruby/object:Gem::Version
47
- version: 0.75.0
109
+ version: '1.5'
48
110
  type: :development
49
111
  prerelease: false
50
112
  version_requirements: !ruby/object:Gem::Requirement
51
113
  requirements:
52
- - - '='
114
+ - - "~>"
53
115
  - !ruby/object:Gem::Version
54
- version: 0.75.0
116
+ version: '1.5'
55
117
  - !ruby/object:Gem::Dependency
56
118
  name: rubocop-performance
57
119
  requirement: !ruby/object:Gem::Requirement
58
120
  requirements:
59
- - - ">="
121
+ - - "~>"
60
122
  - !ruby/object:Gem::Version
61
- version: '0'
123
+ version: '1.10'
62
124
  type: :development
63
125
  prerelease: false
64
126
  version_requirements: !ruby/object:Gem::Requirement
65
127
  requirements:
66
- - - ">="
128
+ - - "~>"
67
129
  - !ruby/object:Gem::Version
68
- version: '0'
130
+ version: '1.10'
69
131
  - !ruby/object:Gem::Dependency
70
132
  name: rubocop-rails
71
133
  requirement: !ruby/object:Gem::Requirement
72
134
  requirements:
73
- - - ">="
135
+ - - "~>"
74
136
  - !ruby/object:Gem::Version
75
- version: '0'
137
+ version: '2.9'
76
138
  type: :development
77
139
  prerelease: false
78
140
  version_requirements: !ruby/object:Gem::Requirement
79
141
  requirements:
80
- - - ">="
142
+ - - "~>"
81
143
  - !ruby/object:Gem::Version
82
- version: '0'
144
+ version: '2.9'
83
145
  description: Extract font collection to separate font files
84
146
  email:
85
147
  - operations@ribose.com
@@ -88,26 +150,7 @@ extensions:
88
150
  - ext/stripttc/extconf.rb
89
151
  extra_rdoc_files: []
90
152
  files:
91
- - ".github/workflows/macosx.yml"
92
- - ".github/workflows/ubuntu.yml"
93
- - ".github/workflows/windows.yml"
94
- - ".gitignore"
95
- - ".rspec"
96
- - ".rubocop.yml"
97
- - Gemfile
98
- - LICENSE.adoc
99
- - README.adoc
100
- - Rakefile
101
- - bin/console
102
- - bin/rspec
103
- - bin/setup
104
- - ext/stripttc/LICENSE
105
- - ext/stripttc/Makefile
106
153
  - ext/stripttc/extconf.rb
107
- - ext/stripttc/stripttc.c
108
- - extract_ttc.gemspec
109
- - lib/extract_ttc.rb
110
- - lib/extract_ttc/version.rb
111
154
  homepage: https://github.com/fontist/extract_ttc
112
155
  licenses:
113
156
  - BSD-3-Clause
@@ -115,6 +158,7 @@ metadata:
115
158
  homepage_uri: https://github.com/fontist/extract_ttc
116
159
  source_code_uri: https://github.com/fontist/extract_ttc
117
160
  changelog_uri: https://github.com/fontist/extract_ttc
161
+ rubygems_mfa_required: 'false'
118
162
  post_install_message:
119
163
  rdoc_options: []
120
164
  require_paths:
@@ -123,14 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
167
  requirements:
124
168
  - - ">="
125
169
  - !ruby/object:Gem::Version
126
- version: 2.3.0
170
+ version: 2.6.0
127
171
  required_rubygems_version: !ruby/object:Gem::Requirement
128
172
  requirements:
129
173
  - - ">="
130
174
  - !ruby/object:Gem::Version
131
175
  version: '0'
132
176
  requirements: []
133
- rubygems_version: 3.0.3
177
+ rubygems_version: 3.3.7
134
178
  signing_key:
135
179
  specification_version: 4
136
180
  summary: Extract TTC file to TTF files
@@ -1,30 +0,0 @@
1
- name: macos
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: macos-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install bundler
24
- run: gem install bundler
25
-
26
- - name: Setup
27
- run: bin/setup
28
-
29
- - name: Run tests
30
- run: bin/rspec
@@ -1,30 +0,0 @@
1
- name: ubuntu
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: ubuntu-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Install bundler
24
- run: gem install bundler
25
-
26
- - name: Setup
27
- run: bin/setup
28
-
29
- - name: Run tests
30
- run: bin/rspec
@@ -1,32 +0,0 @@
1
- name: windows
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
- branches:
10
- - master
11
-
12
- jobs:
13
- build:
14
- runs-on: windows-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
-
19
- - uses: actions/setup-ruby@v1
20
- with:
21
- ruby-version: 2.6
22
-
23
- - name: Setup
24
- shell: pwsh
25
- run: |
26
- gem install bundler
27
- bundle config --local path vendor/bundle
28
- bundle install --jobs 4 --retry 3
29
- bundle exec rake compile
30
-
31
- - name: Run tests
32
- run: bundle exec rspec
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
- /ext/**/*.so
11
- /ext/**/*.o
12
-
13
- # remote file cache
14
- .rubocop-*
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,5 +0,0 @@
1
- inherit_from:
2
- - 'https://raw.githubusercontent.com/fontist/oss-guides/master/ci/rubocop.yml'
3
-
4
- Rails:
5
- Enabled: false
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in extract_ttc.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
data/LICENSE.adoc DELETED
@@ -1,13 +0,0 @@
1
- = BSD 3-Clause License
2
-
3
- Copyright (c) 2020 Ribose Inc. All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
-
7
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
-
9
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
-
11
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
-
13
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.adoc DELETED
@@ -1,121 +0,0 @@
1
- = ExtractTtc: Ruby gem to extract TTF from TTC
2
-
3
- == Purpose
4
-
5
- The gem lets you extract individual TrueType font files (`.ttf`) from a TrueType Collection file (`.ttc`).
6
-
7
- `ExtractTtc` wraps functionality provided by `stripttc.c`, originally from the
8
- https://github.com/fontforge/fontforge[FontForge project] as an FFI extension.
9
-
10
- Specifically, `stripttc.c` is part of the `contribs` directory of FontForge, which
11
- is
12
- https://github.com/fontforge/fontforge/blob/21ad4a18fb3d4becfe566d8215eba4483b0ddc4b/contrib/CMakeLists.txt#L1[assigned]
13
- the
14
- https://github.com/fontforge/fontforge/blob/21ad4a18fb3d4becfe566d8215eba4483b0ddc4b/LICENSE#L12-L57[BSD 3-Clause license].
15
-
16
-
17
- == Installation
18
-
19
- Add this line to your application's `Gemfile`:
20
-
21
- [source,ruby]
22
- ----
23
- gem 'extract_ttc'
24
- ----
25
-
26
- And then execute:
27
-
28
- [source,sh]
29
- ----
30
- $ bundle install
31
- ----
32
-
33
- Or install it yourself as:
34
-
35
- [source,sh]
36
- ----
37
- $ gem install extract_ttc
38
- ----
39
-
40
- == Usage
41
-
42
- [source,ruby]
43
- ----
44
- ExtractTtc.extract("path/to/ttc/Helvetica.ttc")
45
- ----
46
-
47
- Would extract contained TTF files from TTC to a current directory.
48
-
49
-
50
- == Development
51
-
52
- We are following Sandi Metz's Rules for this gem, you can read the
53
- http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers[description of the rules here].
54
- All new code should follow these
55
- rules. If you make changes in a pre-existing file that violates these rules you
56
- should fix the violations as part of your contribution.
57
-
58
- === Setup
59
-
60
- Clone the repository:
61
-
62
- [source,sh]
63
- ----
64
- git clone https://github.com/fontist/extract_ttc
65
- ----
66
-
67
- Setup your environment:
68
-
69
- [source,sh]
70
- ----
71
- bin/setup
72
- ----
73
-
74
- Run the test suite:
75
-
76
- [source,sh]
77
- ----
78
- bundle exec rspec
79
- ----
80
-
81
- If any changes are made in the C code, then the extension needs to be recompiled:
82
-
83
- [source,sh]
84
- ----
85
- bundle exec rake recompile
86
- ----
87
-
88
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
-
90
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to https://rubygems.org[rubygems.org].
91
-
92
-
93
- == Contributing
94
-
95
- First, thank you for contributing! We love pull requests from everyone. By
96
- participating in this project, you hereby grant https://www.ribose.com[Ribose Inc.] the
97
- right to grant or transfer an unlimited number of non exclusive licenses or
98
- sub-licenses to third parties, under the copyright covering the contribution
99
- to use the contribution by all means.
100
-
101
- Here are a few technical guidelines to follow:
102
-
103
- 1. Open an https://github.com/fontist/extract_ttc/issues[issue] to discuss a new feature.
104
- 1. Write tests to support your new feature.
105
- 1. Make sure the entire test suite passes locally and on CI.
106
- 1. Open a Pull Request.
107
- 1. https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature[Squash your commits]
108
- after receiving feedback.
109
- 1. Party!
110
-
111
-
112
- == License
113
-
114
- This gem is distributed with a BSD 3-Clause license.
115
-
116
- `stripttc.c` is obtained from:
117
- https://github.com/fontforge/fontforge/blob/master/contrib/fonttools/stripttc.c
118
-
119
- The BSD 3-Clause licence for `stripttc.c` is provided in `ext/stripttc/LICENSE`.
120
-
121
- This gem is developed, maintained and funded by https://www.ribose.com/[Ribose Inc.]
data/Rakefile DELETED
@@ -1,23 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task default: :compile
3
-
4
- desc "Build stripttc C library"
5
- task :compile do
6
- print "Building stripttc..."
7
- Dir.chdir("ext/stripttc") do
8
- `make`
9
- end
10
- puts " done."
11
- end
12
-
13
- desc "Recompile the stripttc C library"
14
- task recompile: %i[clean compile]
15
-
16
- desc "Remove compiled stripttc library"
17
- task :clean do
18
- print "Cleaning stripttc..."
19
- Dir.glob("ext/stripttc/*.{o,so}") do |path|
20
- File.delete(path)
21
- end
22
- puts " done."
23
- end
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "extract_ttc"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/rspec DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require "pathname"
12
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
- Pathname.new(__FILE__).realpath)
14
-
15
- bundle_binstub = File.expand_path("../bundle", __FILE__)
16
-
17
- if File.file?(bundle_binstub)
18
- if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
- load(bundle_binstub)
20
- else
21
- abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
- Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
- end
24
- end
25
-
26
- require "rubygems"
27
- require "bundler/setup"
28
-
29
- load Gem.bin_path("rspec-core", "rspec")
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
- bundle exec rake compile
data/ext/stripttc/LICENSE DELETED
@@ -1,31 +0,0 @@
1
- BSD 3-Clause License for stripttc.c
2
-
3
- Copyright (c) George Williams and FontForge authors. All rights reserved.
4
- https://github.com/fontforge/fontforge/blob/master/AUTHORS
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions
8
- are met:
9
-
10
- Redistributions of source code must retain the above copyright
11
- notice, this list of conditions and the following disclaimer.
12
-
13
- Redistributions in binary form must reproduce the above copyright
14
- notice, this list of conditions and the following disclaimer in the
15
- documentation and/or other materials provided with the distribution.
16
-
17
- The name of the author may not be used to endorse or promote
18
- products derived from this software without specific prior written
19
- permission.
20
-
21
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS
22
- OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27
- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29
- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31
- IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,16 +0,0 @@
1
- # stripttc.c originates from:
2
- # https://github.com/fontforge/fontforge/blob/master/contrib/fonttools/stripttc.c
3
-
4
- default: stripttc.so
5
-
6
- stripttc.so: stripttc.o
7
- gcc -shared -o $@ $<
8
-
9
- stripttc.o: stripttc.c
10
- gcc -c -fPIC -o $@ $<
11
-
12
- install:
13
- : # do nothing, we'll load the lib directly
14
-
15
- clean:
16
- -rm *.so *.o
@@ -1,181 +0,0 @@
1
- #include <stdio.h>
2
- #include <stdlib.h>
3
- #include <string.h>
4
- #include <libgen.h>
5
-
6
- /* This program takes a ttc file and turns it into its component ttf files */
7
- /* This makes two changes to the data: */
8
- /* * The tables are placed at different offsets, therefore */
9
- /* the offset fields in the table header are also different. */
10
- /* * the 'head' table checksumAdjustment field is set correctly */
11
-
12
- #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
13
-
14
- static void putshort(FILE *file,int sval) {
15
- putc((sval>>8)&0xff,file);
16
- putc(sval&0xff,file);
17
- }
18
-
19
- static void putlong(FILE *file,int val) {
20
- putc((val>>24)&0xff,file);
21
- putc((val>>16)&0xff,file);
22
- putc((val>>8)&0xff,file);
23
- putc(val&0xff,file);
24
- }
25
-
26
- static int getushort(FILE *ttf) {
27
- int ch1 = getc(ttf);
28
- int ch2 = getc(ttf);
29
- if ( ch2==EOF )
30
- return( EOF );
31
- return( (ch1<<8)|ch2 );
32
- }
33
-
34
- static int getlong(FILE *ttf) {
35
- int ch1 = getc(ttf);
36
- int ch2 = getc(ttf);
37
- int ch3 = getc(ttf);
38
- int ch4 = getc(ttf);
39
- if ( ch4==EOF )
40
- return( EOF );
41
- return( (ch1<<24)|(ch2<<16)|(ch3<<8)|ch4 );
42
- }
43
-
44
- static unsigned int filecheck(FILE *file) {
45
- unsigned int sum = 0, chunk;
46
-
47
- rewind(file);
48
- while ( 1 ) {
49
- chunk = getlong(file);
50
- if ( feof(file) || ferror(file))
51
- break;
52
- sum += chunk;
53
- }
54
- return( sum );
55
- }
56
-
57
- static void copytable(FILE *ttf,FILE *ttc,int offset,int length) {
58
- int i, ch;
59
-
60
- fseek(ttc,offset,SEEK_SET);
61
- for ( i=0; i<length && (ch=getc(ttc))!=EOF ; ++i )
62
- putc(ch,ttf);
63
- if ( ch==EOF )
64
- fprintf( stderr, "File ended before table\n" );
65
- if ( length&1 ) {
66
- putc('\0',ttf);
67
- ++length;
68
- }
69
- if ( length & 2 ) {
70
- putshort(ttf,0);
71
- }
72
- }
73
-
74
- static int handlefont(char *filename,int which,FILE *ttc,int offset) {
75
- char outfile[2000], *pt;
76
- FILE *ttf;
77
- int i, cnt, *offsets, *lengths, head, tag, pos, headpos;
78
- strcpy(outfile,basename(filename));
79
- pt = strrchr(outfile,'.');
80
- if ( pt==NULL )
81
- pt = outfile + strlen(outfile);
82
- sprintf( pt, "_%02d.ttf", which );
83
-
84
- ttf = fopen( outfile,"wb");
85
- if ( ttf==NULL ) {
86
- fprintf( stderr, "Failed to open %s for output.\n", outfile );
87
- return( -3 );
88
- }
89
- printf ( "%s ", outfile );
90
-
91
- fseek(ttc,offset,SEEK_SET);
92
- putlong(ttf,getlong(ttc)); /* sfnt version */
93
- putshort(ttf,cnt = getushort(ttc)); /* table cnt */
94
- putshort(ttf,getushort(ttc)); /* binary search header */
95
- putshort(ttf,getushort(ttc));
96
- putshort(ttf,getushort(ttc));
97
-
98
- offsets = malloc(cnt*sizeof(int));
99
- lengths = malloc(cnt*sizeof(int));
100
- head = -1;
101
- for ( i=0; i<cnt; ++i ) {
102
- tag = getlong(ttc);
103
- if ( tag==CHR('h','e','a','d'))
104
- head = i;
105
- putlong(ttf,tag);
106
- putlong(ttf,getlong(ttc)); /* checksum */
107
- putlong(ttf,offsets[i] = getlong(ttc)); /* Reserve space for offset, will fix later */
108
- putlong(ttf,lengths[i] = getlong(ttc));
109
- }
110
- headpos = -1;
111
- for ( i=0; i<cnt; ++i ) {
112
- pos = ftell(ttf);
113
- copytable(ttf,ttc,offsets[i],lengths[i]);
114
- if ( i==head ) {
115
- fseek(ttf,pos+8,SEEK_SET);
116
- putlong(ttf,0);
117
- headpos = pos;
118
- }
119
- fseek(ttf,12+i*16+8,SEEK_SET);
120
- putlong(ttf,pos); /* Fix offset here */
121
- fseek(ttf,0,SEEK_END);
122
- }
123
- if ( headpos!=-1 ) {
124
- unsigned int checksum;
125
- checksum = filecheck(ttf);
126
- checksum = 0xb1b0afba-checksum;
127
- fseek(ttf,headpos+2*sizeof(int),SEEK_SET);
128
- putlong(ttf,checksum);
129
- }
130
- fclose(ttf);
131
- free(offsets); free(lengths);
132
- return( 0 );
133
- }
134
-
135
- int handlefile(char *filename) {
136
- FILE *ttc = fopen(filename,"rb");
137
- int version, cnt, e, i;
138
- int *offsets;
139
-
140
- if ( ttc==NULL ) {
141
- fprintf( stderr, "Could not open %s\n", filename );
142
- return( -1 );
143
- }
144
-
145
- version = getlong(ttc);
146
- if ( version!=CHR('t','t','c','f')) {
147
- fprintf( stderr, "%s does not look like a ttc file, bad version.\n", filename );
148
- fclose(ttc);
149
- return( -2 );
150
- }
151
-
152
- version = getlong(ttc);
153
- if ( version!=0x10000 && version != 0x20000 )
154
- fprintf( stderr, "Unexpected ttc version number: %08x\n", (unsigned int)(version) );
155
- cnt = getlong(ttc);
156
- offsets = malloc(cnt*sizeof(int));
157
- for ( i=0; i<cnt; ++i )
158
- offsets[i] = getlong(ttc);
159
- printf( "%s => ", filename );
160
- for ( i=0; i<cnt; ++i )
161
- if ( (e = handlefont(filename,i,ttc,offsets[i])) ) {
162
- fflush(stdout);
163
- fclose(ttc);
164
- free(offsets);
165
- return( e );
166
- };
167
- printf( "\n" );
168
- fflush(stdout);
169
- fclose(ttc);
170
- free(offsets);
171
- return( 0 );
172
- }
173
-
174
- int main(int argc, char *argv[]) {
175
- int e, i;
176
-
177
- for ( i=1; i<argc; ++i )
178
- if ( (e = handlefile(argv[i])) )
179
- return( e );
180
- return( 0 );
181
- }
data/extract_ttc.gemspec DELETED
@@ -1,36 +0,0 @@
1
- require_relative "lib/extract_ttc/version"
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "extract_ttc"
5
- spec.version = ExtractTtc::VERSION
6
- spec.authors = ["Ribose Inc."]
7
- spec.email = ["operations@ribose.com"]
8
-
9
- spec.summary = "Extract TTC file to TTF files"
10
- spec.description = "Extract font collection to separate font files"
11
- spec.homepage = "https://github.com/fontist/extract_ttc"
12
- spec.license = "BSD-3-Clause"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
-
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/fontist/extract_ttc"
17
- spec.metadata["changelog_uri"] = "https://github.com/fontist/extract_ttc"
18
-
19
- spec.files = Dir.chdir(__dir__) do
20
- `git ls-files -z`
21
- .split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
- end
23
-
24
- spec.bindir = "exe"
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ["lib"]
27
-
28
- spec.add_runtime_dependency "ffi"
29
-
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "rubocop", "0.75.0"
32
- spec.add_development_dependency "rubocop-performance"
33
- spec.add_development_dependency "rubocop-rails"
34
-
35
- spec.extensions << "ext/stripttc/extconf.rb"
36
- end
@@ -1,3 +0,0 @@
1
- module ExtractTtc
2
- VERSION = "0.1.0".freeze
3
- end
data/lib/extract_ttc.rb DELETED
@@ -1,67 +0,0 @@
1
- require "extract_ttc/version"
2
- require "ffi"
3
- require "tempfile"
4
-
5
- module ExtractTtc
6
- class Error < StandardError; end
7
- class ReadFileError < Error; end
8
- class InvalidFileError < Error; end
9
- class WriteFileError < Error; end
10
- class UnknownResultError < Error; end
11
-
12
- extend FFI::Library
13
- ffi_lib File.expand_path("../ext/stripttc/stripttc.so", __dir__)
14
- attach_function :handlefile, [:string], :int
15
-
16
- def self.extract(path)
17
- stdout, stderr, code = capture3 do
18
- handlefile(path)
19
- end
20
-
21
- return handle_error(code, stderr) unless code.zero?
22
-
23
- fetch_filenames(stdout)
24
- end
25
-
26
- def self.handle_error(code, stderr)
27
- case code
28
- when -1
29
- raise ReadFileError, stderr
30
- when -2
31
- raise InvalidFileError, stderr
32
- when -3
33
- raise WriteFileError, stderr
34
- else
35
- raise UnknownResultError, "Return code: #{code}"
36
- end
37
- end
38
-
39
- def self.capture3
40
- stderr = status = nil
41
-
42
- stdout = capture_stream($stdout) do
43
- stderr = capture_stream($stderr) do
44
- status = yield
45
- end
46
- end
47
-
48
- [stdout, stderr, status]
49
- end
50
-
51
- def self.capture_stream(stream_io)
52
- origin_stream = stream_io.dup
53
-
54
- Tempfile.open("captured_stream") do |captured_stream|
55
- stream_io.reopen(captured_stream)
56
- yield
57
- captured_stream.rewind
58
- return captured_stream.read
59
- end
60
- ensure
61
- stream_io.reopen(origin_stream)
62
- end
63
-
64
- def self.fetch_filenames(stdout)
65
- stdout.split("=>").last.split(" ")
66
- end
67
- end