extract_ttc 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/.github/workflows/macosx.yml +30 -0
- data/.github/workflows/ubuntu.yml +30 -0
- data/.github/workflows/windows.yml +32 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.adoc +13 -0
- data/README.adoc +121 -0
- data/Rakefile +23 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/setup +7 -0
- data/ext/stripttc/LICENSE +31 -0
- data/ext/stripttc/Makefile +16 -0
- data/ext/stripttc/extconf.rb +1 -0
- data/ext/stripttc/stripttc.c +181 -0
- data/extract_ttc.gemspec +36 -0
- data/lib/extract_ttc.rb +67 -0
- data/lib/extract_ttc/version.rb +3 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6d17daa99ebfce9bef022ad42667c35c183a687e0aac23436971dd946a98d45
|
4
|
+
data.tar.gz: 0e08cddcb9547b00eb95fd54f1df55669cfc5e3572604874f0f208ad93e36034
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b94ad46a8aa508e7a48d310a88de0888ca39cb9c7e0b4e58b9a68327332ce036f82c69fd60ca0da2f00dc828e87b1cc689eecf48b3c4e474d04ba0538bc608c
|
7
|
+
data.tar.gz: 60d2eec18035282b015ce768900147f2af35852592f050f8c5fa000f1c16da5c0766fe4be2cc279f0b7b13a0100269d48fb4fc4f12567a718a5074a63aaf69bf
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
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
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.adoc
ADDED
@@ -0,0 +1,13 @@
|
|
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
ADDED
@@ -0,0 +1,121 @@
|
|
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
ADDED
@@ -0,0 +1,23 @@
|
|
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
ADDED
@@ -0,0 +1,14 @@
|
|
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
ADDED
@@ -0,0 +1,29 @@
|
|
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
ADDED
@@ -0,0 +1,31 @@
|
|
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.
|
@@ -0,0 +1,16 @@
|
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
# do nothing, Makefile is already here
|
@@ -0,0 +1,181 @@
|
|
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
ADDED
@@ -0,0 +1,36 @@
|
|
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
|
data/lib/extract_ttc.rb
ADDED
@@ -0,0 +1,67 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extract_ttc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.75.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.75.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
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: rubocop-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Extract font collection to separate font files
|
84
|
+
email:
|
85
|
+
- operations@ribose.com
|
86
|
+
executables: []
|
87
|
+
extensions:
|
88
|
+
- ext/stripttc/extconf.rb
|
89
|
+
extra_rdoc_files: []
|
90
|
+
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
|
+
- 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
|
+
homepage: https://github.com/fontist/extract_ttc
|
112
|
+
licenses:
|
113
|
+
- BSD-3-Clause
|
114
|
+
metadata:
|
115
|
+
homepage_uri: https://github.com/fontist/extract_ttc
|
116
|
+
source_code_uri: https://github.com/fontist/extract_ttc
|
117
|
+
changelog_uri: https://github.com/fontist/extract_ttc
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 2.3.0
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubygems_version: 3.0.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Extract TTC file to TTF files
|
137
|
+
test_files: []
|