woff 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aac5fde700c6ecb380c9fa475dd2c8364ab3e4dc
4
+ data.tar.gz: c3506228f9f1456f4f0637fc1d98f1100735deab
5
+ SHA512:
6
+ metadata.gz: e31a2ba4d6151915362fbcd80e3cf581552082c2cc49977ab78aeb13a036dd84e75f41b4241adb4510b8c2445905276848b6c33a4d701a5188792388f97dd317
7
+ data.tar.gz: 5e8d0e69cc1e126d2adf1e597e1dd0ee14cdc1d0514097580cb77df4da72bfd699ac1ca7a0aae3c80f9e3dd635c77036cff8ae2439e0d6a3f7d6c88ec1d09081
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in woff.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Josh Hepworth
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Woff
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'woff'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install woff
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ module WOFF
2
+ # Used in generation of WOFF files. Currently only modifies licensee
3
+ # information and writes to a file. In the future it should stream
4
+ # the output for use in one time use downloads.
5
+ #
6
+ # woff = WOFF::Builder.new("/Users/Josh/Desktop/sample.woff")
7
+ # woff.font_with_licensee("The Friends")
8
+ #
9
+ class Builder
10
+ def initialize(file)
11
+ @location = file
12
+ end
13
+
14
+ def font_with_licensee_and_id(name, id)
15
+ metadata_xml = ::Zlib::Inflate.inflate(data.metadata)
16
+ metadata_doc = REXML::Document.new(metadata_xml)
17
+
18
+ if metadata_doc.root.elements["licensee"]
19
+ metadata_doc.root.elements["licensee"].attributes["name"] = name
20
+ else
21
+ metadata_doc.root.add_element "licensee", { "name" => name }
22
+ end
23
+
24
+ if metadata_doc.root.elements["license"]
25
+ metadata_doc.root.elements["license"].attributes["id"] = id
26
+ else
27
+ metadata_doc.root.add_element "license", { "id" => id }
28
+ end
29
+
30
+ compressed_metadata = ::Zlib::Deflate.deflate(metadata_doc.to_s)
31
+
32
+ data.meta_orig_length = metadata_doc.to_s.bytesize
33
+ data.metadata = compressed_metadata
34
+ data.meta_length = compressed_metadata.bytesize
35
+ data.data_length = data.num_bytes
36
+
37
+ data.to_binary_s
38
+ end
39
+
40
+ private
41
+ attr_reader :location
42
+
43
+ def data
44
+ @data ||= WOFF::Data.read(File.open(location))
45
+ end
46
+ end
47
+ end
data/lib/woff/data.rb ADDED
@@ -0,0 +1,44 @@
1
+ module WOFF
2
+ class Data < ::BinData::Record
3
+ endian :big
4
+ count_bytes_remaining :bytes_remaining
5
+
6
+ uint32 :signature
7
+ uint32 :flavor
8
+ uint32 :data_length
9
+ uint16 :num_tables
10
+ uint16 :reserved
11
+ uint32 :total_s_fnt_size
12
+ uint16 :major_version
13
+ uint16 :minor_version
14
+ uint32 :meta_offset
15
+ uint32 :meta_length
16
+ uint32 :meta_orig_length
17
+ uint32 :priv_offset
18
+ uint32 :priv_length
19
+
20
+ array :table_directory, :initial_length => :num_tables do
21
+ uint32 :tag
22
+ uint32 :table_offset
23
+ uint32 :comp_length
24
+ uint32 :orig_length
25
+ uint32 :orig_checksum
26
+ end
27
+
28
+ string :fonts, :read_length => lambda {
29
+ dir = table_directory.sort_by { |entry| entry["table_offset"] }
30
+
31
+ first_table_start = dir.first["table_offset"]
32
+ last_table_end = dir.last["table_offset"] + dir.last["comp_length"]
33
+
34
+ table_length = last_table_end - first_table_start
35
+
36
+ # Next largest number divisible by 4
37
+ (table_length / 4.0).ceil * 4
38
+ }
39
+
40
+ string :metadata, :read_length => :meta_length
41
+
42
+ rest :private_data
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module WOFF
2
+ VERSION = "1.0.0"
3
+ end
data/lib/woff.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "woff/version"
2
+ require "zlib"
3
+ require "bindata"
4
+ require "rexml/document"
5
+ require "woff/builder"
6
+ require "woff/data"
7
+
8
+ module WOFF
9
+ class FontNotFoundError < StandardError
10
+ def initialize(msg = "The font file could not be located. Font building failed.")
11
+ super(msg)
12
+ end
13
+ end
14
+ end
data/woff.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'woff/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "woff"
7
+ gem.version = WOFF::VERSION
8
+ gem.authors = ["Josh Hepworth"]
9
+ gem.licenses = "MIT"
10
+ gem.email = ["josh@friendsoftheweb.com"]
11
+ gem.description = %q{Handles the management and modification of WOFF formatted files.}
12
+ gem.summary = %q{Reading and modifying binary WOFF files.}
13
+ gem.homepage = "https://github.com/friendsoftheweb/woff-rb"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "bindata", "~> 2.3"
21
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: woff
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Hepworth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bindata
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ description: Handles the management and modification of WOFF formatted files.
28
+ email:
29
+ - josh@friendsoftheweb.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/woff.rb
40
+ - lib/woff/builder.rb
41
+ - lib/woff/data.rb
42
+ - lib/woff/version.rb
43
+ - woff.gemspec
44
+ homepage: https://github.com/friendsoftheweb/woff-rb
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.5.1
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Reading and modifying binary WOFF files.
68
+ test_files: []