Skip to content

Commit

Permalink
Bug 1227058 - Include the woff2 library in the gecko build. b=1227058…
Browse files Browse the repository at this point in the history
…, r=jfkthame
  • Loading branch information
fred-wang committed Feb 2, 2016
1 parent 6cc1afd commit 6490d76
Show file tree
Hide file tree
Showing 30 changed files with 4,734 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/external/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ if CONFIG['MOZ_UPDATER']:
if not CONFIG['MOZ_NATIVE_BZ2']:
external_dirs += ['modules/libbz2']

# There's no "native brotli" yet, but probably in the future...
# There's no "native" brotli or woff2 yet, but probably in the future...
external_dirs += ['modules/brotli']
external_dirs += ['modules/woff2']

if CONFIG['MOZ_VORBIS']:
external_dirs += ['media/libvorbis']
Expand Down
18 changes: 18 additions & 0 deletions modules/woff2/README.mozilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This is the woff2 library from
https://github.com/google/woff2.

Upstream code can be viewed at
https://github.com/google/woff2/tree/master/src

and cloned by
git clone https://github.com/google/woff2

The in-tree copy is updated by running
sh update.sh
from within the modules/woff2 directory.

Current version: [commit ee1b44e0b4fd29a33bdef5f1ec3769325862d615].

redefine-unique_ptr.patch redefines the class std::unique_ptr to workaround a
build issue with missing C++11 features.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1227058
21 changes: 21 additions & 0 deletions modules/woff2/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

EXPORTS += [
'src/woff2_dec.h',
]

UNIFIED_SOURCES += [
'src/table_tags.cc',
'src/variable_length.cc',
'src/woff2_common.cc',
'src/woff2_dec.cc',
]

# We allow warnings for third-party code that can be updated from upstream.
ALLOW_COMPILER_WARNINGS = True

Library('woff2')
28 changes: 28 additions & 0 deletions modules/woff2/redefine-unique_ptr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/modules/woff2/src/woff2_dec.cc b/modules/woff2/src/woff2_dec.cc
--- a/modules/woff2/src/woff2_dec.cc
+++ b/modules/woff2/src/woff2_dec.cc
@@ -20,16 +20,24 @@
#include <algorithm>
#include <complex>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <map>
#include <memory>
+#include "mozilla/UniquePtr.h"
+namespace std
+{
+ using mozilla::DefaultDelete;
+ using mozilla::UniquePtr;
+ #define default_delete DefaultDelete
+ #define unique_ptr UniquePtr
+}

#include "./buffer.h"
#include "./decode.h"
#include "./port.h"
#include "./round.h"
#include "./store_bytes.h"
#include "./table_tags.h"
#include "./variable_length.h"
172 changes: 172 additions & 0 deletions modules/woff2/src/buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The parts of ots.h & opentype-sanitiser.h that we need, taken from the
// https://code.google.com/p/ots/ project.

#ifndef WOFF2_BUFFER_H_
#define WOFF2_BUFFER_H_

#if defined(_WIN32)
#include <stdlib.h>
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define ntohl(x) _byteswap_ulong (x)
#define ntohs(x) _byteswap_ushort (x)
#define htonl(x) _byteswap_ulong (x)
#define htons(x) _byteswap_ushort (x)
#else
#include <arpa/inet.h>
#include <stdint.h>
#endif

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <limits>

namespace woff2 {

#if defined(_MSC_VER) || !defined(FONT_COMPRESSION_DEBUG)
#define FONT_COMPRESSION_FAILURE() false
#else
#define FONT_COMPRESSION_FAILURE() \
woff2::Failure(__FILE__, __LINE__, __PRETTY_FUNCTION__)
inline bool Failure(const char *f, int l, const char *fn) {
fprintf(stderr, "ERROR at %s:%d (%s)\n", f, l, fn);
fflush(stderr);
return false;
}
#endif

// -----------------------------------------------------------------------------
// Buffer helper class
//
// This class perform some trival buffer operations while checking for
// out-of-bounds errors. As a family they return false if anything is amiss,
// updating the current offset otherwise.
// -----------------------------------------------------------------------------
class Buffer {
public:
Buffer(const uint8_t *buffer, size_t len)
: buffer_(buffer),
length_(len),
offset_(0) { }

bool Skip(size_t n_bytes) {
return Read(NULL, n_bytes);
}

bool Read(uint8_t *buffer, size_t n_bytes) {
if (n_bytes > 1024 * 1024 * 1024) {
return FONT_COMPRESSION_FAILURE();
}
if ((offset_ + n_bytes > length_) ||
(offset_ > length_ - n_bytes)) {
return FONT_COMPRESSION_FAILURE();
}
if (buffer) {
std::memcpy(buffer, buffer_ + offset_, n_bytes);
}
offset_ += n_bytes;
return true;
}

inline bool ReadU8(uint8_t *value) {
if (offset_ + 1 > length_) {
return FONT_COMPRESSION_FAILURE();
}
*value = buffer_[offset_];
++offset_;
return true;
}

bool ReadU16(uint16_t *value) {
if (offset_ + 2 > length_) {
return FONT_COMPRESSION_FAILURE();
}
std::memcpy(value, buffer_ + offset_, sizeof(uint16_t));
*value = ntohs(*value);
offset_ += 2;
return true;
}

bool ReadS16(int16_t *value) {
return ReadU16(reinterpret_cast<uint16_t*>(value));
}

bool ReadU24(uint32_t *value) {
if (offset_ + 3 > length_) {
return FONT_COMPRESSION_FAILURE();
}
*value = static_cast<uint32_t>(buffer_[offset_]) << 16 |
static_cast<uint32_t>(buffer_[offset_ + 1]) << 8 |
static_cast<uint32_t>(buffer_[offset_ + 2]);
offset_ += 3;
return true;
}

bool ReadU32(uint32_t *value) {
if (offset_ + 4 > length_) {
return FONT_COMPRESSION_FAILURE();
}
std::memcpy(value, buffer_ + offset_, sizeof(uint32_t));
*value = ntohl(*value);
offset_ += 4;
return true;
}

bool ReadS32(int32_t *value) {
return ReadU32(reinterpret_cast<uint32_t*>(value));
}

bool ReadTag(uint32_t *value) {
if (offset_ + 4 > length_) {
return FONT_COMPRESSION_FAILURE();
}
std::memcpy(value, buffer_ + offset_, sizeof(uint32_t));
offset_ += 4;
return true;
}

bool ReadR64(uint64_t *value) {
if (offset_ + 8 > length_) {
return FONT_COMPRESSION_FAILURE();
}
std::memcpy(value, buffer_ + offset_, sizeof(uint64_t));
offset_ += 8;
return true;
}

const uint8_t *buffer() const { return buffer_; }
size_t offset() const { return offset_; }
size_t length() const { return length_; }

void set_offset(size_t newoffset) { offset_ = newoffset; }

private:
const uint8_t * const buffer_;
const size_t length_;
size_t offset_;
};

} // namespace woff2

#endif // WOFF2_BUFFER_H_
40 changes: 40 additions & 0 deletions modules/woff2/src/file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// File IO helpers

#ifndef WOFF2_FILE_H_
#define WOFF2_FILE_H_

#include <fstream>
#include <iterator>

namespace woff2 {

inline std::string GetFileContent(std::string filename) {
std::ifstream ifs(filename.c_str(), std::ios::binary);
return std::string(
std::istreambuf_iterator<char>(ifs.rdbuf()),
std::istreambuf_iterator<char>());
}

inline void SetFileContents(std::string filename, std::string content) {
std::ofstream ofs(filename.c_str(), std::ios::binary);
std::copy(content.begin(),
content.end(),
std::ostream_iterator<char>(ofs));
}

} // namespace woff2
#endif // WOFF2_FILE_H_
Loading

0 comments on commit 6490d76

Please sign in to comment.