diff --git a/.travis.yml b/.travis.yml index baad82dec..48b9905d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,69 @@ language: cpp -os: -- linux -- osx -compiler: -- clang -- gcc + +matrix: + include: + # Coverage + - os: osx + compiler: clang + env: NODE_VERSION="0.10" COVERAGE=true + # Linux + - os: linux + compiler: clang + env: NODE_VERSION="0.10" + - os: linux + compiler: clang + env: NODE_VERSION="0.12" + # OS X + - os: osx + compiler: clang + env: NODE_VERSION="0.10" + - os: osx + compiler: clang + env: NODE_VERSION="0.12" + env: - matrix: - - NODE_NVM_VERSION="0.8.26" - - NODE_NVM_VERSION="0.10" global: - - BUILD: '/tmp/fontnik-build' - - PKG_CONFIG_PATH: '/tmp/fontnik-build/lib/pkgconfig' - - secure: "XV0lekmfgT+D9t0ZTIU+UJF6g+p3cBQMO6T6C9lkoKTC0YbtLtxSFtBahD/4PjL86DMJgTaf1nBmxqOxbrfkcpJUxnLe3r8u4Z2L/+7+QSACLNktlIfWNSO+33WxKNb4mVw6jMFZIo4ZurF016MXYzLzjpxRELW2oO2STUs2m44=" - - secure: "CQNHbxw8yHlAdUVbKokHzHmj7C+duXP3mifWOkZm9GKw4myWsRFhhoSYZmOSkgj9EWfYYkedrqEr9+GaMg9rkVJuO/7jzn6S+M7CFXKJju6MoZEDO6WcFva4M8pw6IFb9q22GcQ+OsE8/i0DwchTokyFkNb3fpwWuwROUPQ/nWg=" + - JOBS: "8" + - BUILD: '/tmp/fontnik-build' + - PKG_CONFIG_PATH: '/tmp/fontnik-build/lib/pkgconfig' + - secure: "XV0lekmfgT+D9t0ZTIU+UJF6g+p3cBQMO6T6C9lkoKTC0YbtLtxSFtBahD/4PjL86DMJgTaf1nBmxqOxbrfkcpJUxnLe3r8u4Z2L/+7+QSACLNktlIfWNSO+33WxKNb4mVw6jMFZIo4ZurF016MXYzLzjpxRELW2oO2STUs2m44=" + - secure: "CQNHbxw8yHlAdUVbKokHzHmj7C+duXP3mifWOkZm9GKw4myWsRFhhoSYZmOSkgj9EWfYYkedrqEr9+GaMg9rkVJuO/7jzn6S+M7CFXKJju6MoZEDO6WcFva4M8pw6IFb9q22GcQ+OsE8/i0DwchTokyFkNb3fpwWuwROUPQ/nWg=" + before_install: -- export platform=$(uname -s | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/") -- export PATH="$BUILD/bin:$PATH" -- if [[ "$platform" == "linux" ]]; then export CXX=g++-4.8; export CC=gcc-4.8; fi -- ./deps/nvm_install.sh -- ./deps/travis_build.sh + - export COVERAGE=${COVERAGE:-false} + # here we set up the node version on the fly based on the matrix value. + # This is done manually so that it is easy to flip the 'language' to + # objective-c in another branch (to run the same travis.yml on OS X) + - git clone https://github.com/creationix/nvm.git ../.nvm + - source ../.nvm/nvm.sh + - nvm install $NODE_VERSION + - nvm use $NODE_VERSION + - node --version + - npm --version + - if [[ ${COVERAGE} == true ]]; then + brew update; + brew install pyenv; + eval "$(pyenv init -)"; + pyenv install 2.7.6; + pyenv global 2.7.6; + pyenv rehash; + pip install cpp-coveralls; + pyenv rehash; + fi; + - export PATH="$BUILD/bin:$PATH" + - ./deps/travis_build.sh + install: -- npm install --build-from-source + - if [[ ${COVERAGE} == true ]]; then + export LDFLAGS="--coverage" && export CXXFLAGS="--coverage" && npm install --build-from-source --debug --clang=1; + else + npm install --build-from-source --clang=1; + fi; + script: -- npm test + - npm test + - if [[ ${COVERAGE} == true ]]; then cpp-coveralls --exclude node_modules --exclude tests --build-root build --gcov-options '\-lp' --exclude doc --exclude build/Debug/obj/gen; fi; + after_success: -- ./deps/travis_publish.sh + - ./deps/travis_publish.sh diff --git a/API.md b/API.md index 7416937ad..7bb1a1160 100644 --- a/API.md +++ b/API.md @@ -2,40 +2,19 @@ ### `range(options: object, callback: function)` -`options` is an object with options: - +Get a range of glyphs as a protocol buffer. `options` is an object with options: +* `file: string` * `start: number` * `end: number` -* `fontstack: ?string` - -Get a range of glyphs as a gzipped protocol buffer. - -### `conf(options: object)` - -`options` is an object with options: - -* `fonts: Array` - -Configure node-fontnik. - -### `getRange(start: number, end: number): Array` - -Generate an array of the numbers from `start` to `end`. `start` must be -less than `end` and both numbers must be in the inclusive range 0 to 65535. - -### `faces(): Array` - -Return an array of supported font faces, as strings. - -## `new fontnik.Glyphs()` - -Create a new Glyphs object. - -### `glyphs.codepoints(face: string): Array` -Get an array of numbers corresponding to unicode points where this font face -has coverage. +`file` is the path to a font file on disk.] -### `glyphs.range(face: string, range: string, chars: Array, callback: function)` +### `load(fontpath: string, callback: function)` -### `glyphs.serialize(): Buffer` +Read a font's metadata. Returns an object like +``` json +"family_name": "Open Sans", +"style_name": "Regular", +"points": [32,33,34,35…] +``` +where `points` is an array of numbers corresponding to unicode points where this font face has coverage. diff --git a/README.md b/README.md index c63983b60..6ab080c80 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # node-fontnik -[![NPM](https://nodei.co/npm/fontnik.png?compact=true)](https://nodei.co/npm/fontnik/) [![Build Status](https://travis-ci.org/mapbox/node-fontnik.svg?branch=master)](https://travis-ci.org/mapbox/node-fontnik) +[![NPM](https://nodei.co/npm/fontnik.png?compact=true)](https://nodei.co/npm/fontnik/) +[![Build Status](https://travis-ci.org/mapbox/node-fontnik.svg?branch=master)](https://travis-ci.org/mapbox/node-fontnik) +[![Coverage Status](https://coveralls.io/repos/mapbox/node-fontnik/badge.svg?branch=coverage)](https://coveralls.io/r/mapbox/node-fontnik?branch=coverage) A library that delivers a range of glyphs rendered as SDFs (signed distance fields) in a protocol buffer. We use these encoded glyphs as the basic blocks of font rendering in [Mapbox GL](https://github.com/mapbox/mapbox-gl-js). SDF encoding is superior to traditional fonts for our usecase terms of scaling, rotation, and quickly deriving halos - WebGL doesn't have built-in font rendering, so the decision is between vectorization, which tends to be slow, and SDF generation. diff --git a/bench/bench.js b/bench/bench.js new file mode 100644 index 000000000..7720d35cf --- /dev/null +++ b/bench/bench.js @@ -0,0 +1,49 @@ +'use strict'; + +var path = require('path'); +var fontnik = require('../'); +var queue = require('queue-async'); +var fs = require('fs'); + +// https://gist.github.com/mourner/96b1335c6a43e68af252 +// https://gist.github.com/fengmk2/4345606 +function now() { + var hr = process.hrtime(); + return hr[0] + hr[1] / 1e9; +} + +function bench(opts,cb) { + var q = queue(opts.concurrency); + var start = now(); + for (var i = 1; i <= opts.iterations; i++) { + q.defer.apply({},opts.args); + } + q.awaitAll(function(error, results) { + var seconds = now() - start; + console.log(opts.name, Math.round(opts.iterations / (seconds)),'ops/sec',opts.iterations,opts.concurrency); + return cb(); + }); +} + +function main() { + var opensans = fs.readFileSync(path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf')); + + var suite = queue(1); + suite.defer(bench, { + name:"fontnik.load", + args:[fontnik.load,opensans], + iterations: 10, + concurrency: 10 + }); + suite.defer(bench, { + name:"fontnik.range", + args:[fontnik.range,{font:opensans,start:0,end:256}], + iterations: 1000, + concurrency: 100 + }); + suite.awaitAll(function(err) { + if (err) throw err; + }) +} + +main(); diff --git a/bench/bench2.js b/bench/bench2.js new file mode 100644 index 000000000..2603babf2 --- /dev/null +++ b/bench/bench2.js @@ -0,0 +1,38 @@ +'use strict'; + +var path = require('path'); +var fontnik = require('../'); +var Benchmark = require('benchmark'); +var fs = require('fs'); + +var opensans = fs.readFileSync(path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf')); + +var suite = new Benchmark.Suite(); + +suite +.add('fontnik.load', { + 'defer': true, + 'fn': function(deferred) { + // avoid test inlining + suite.name; + fontnik.load(opensans,function(err) { + if (err) throw err; + deferred.resolve(); + }); + } +}) +.add('fontnik.range', { + 'defer': true, + 'fn': function(deferred) { + // avoid test inlining + suite.name; + fontnik.range({font:opensans,start:0,end:256},function(err) { + if (err) throw err; + deferred.resolve(); + }); + } +}) +.on('cycle', function(event) { + console.log(String(event.target)); +}) +.run({async:true}); diff --git a/binding.gyp b/binding.gyp index 44742ecc9..854cf0dd1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -24,29 +24,17 @@ 'src/node_fontnik.cpp', 'src/glyphs.cpp', 'vendor/agg/src/agg_curves.cpp', - 'vendor/fontnik/src/glyphs.cpp', - 'vendor/fontnik/src/face.cpp', - 'vendor/mapnik/src/debug.cpp', - 'vendor/mapnik/src/font_engine_freetype.cpp', - 'vendor/mapnik/src/font_set.cpp', - 'vendor/mapnik/src/fs.cpp', - 'vendor/mapnik/src/text/face_set.cpp', '<(SHARED_INTERMEDIATE_DIR)/glyphs.pb.cc' ], 'include_dirs': [ './include', './vendor/agg/include', - './vendor/fontnik/include', - './vendor/mapnik/include', - './vendor/node_mapnik/include', '<(SHARED_INTERMEDIATE_DIR)/', ' - -#include -#include - -namespace node_fontnik -{ - -class Glyphs : public node::ObjectWrap { -public: - static v8::Persistent constructor; - static void Init(v8::Handle target); - static bool HasInstance(v8::Handle val); -protected: - Glyphs(); - Glyphs(const char *data, size_t length); - ~Glyphs(); - - static NAN_METHOD(New); - static NAN_METHOD(Serialize); - static NAN_METHOD(Range); - static NAN_METHOD(Codepoints); - static void AsyncRange(uv_work_t* req); - static void RangeAfter(uv_work_t* req); - - fontnik::Glyphs glyphs; -}; - -} // ns node_fontnik - -#endif // NODE_FONTNIK_GLYPHS_HPP diff --git a/index.js b/index.js index 46232311a..8dfd15c81 100644 --- a/index.js +++ b/index.js @@ -1,36 +1 @@ -var zlib = require('zlib'); -var path = require('path'); -var util = require('util'); -var fontnik = require('./lib/fontnik.node'); - -module.exports = fontnik; -module.exports.range = range; -module.exports.getRange = getRange; - -// Retrieve a range of glyphs as a pbf. -function range(options, callback) { - 'use strict'; - options = options || {}; - options.fontstack = options.fontstack || 'Open Sans Regular'; - - var glyphs = new fontnik.Glyphs(); - glyphs.range(options.fontstack, options.start + '-' + options.end, getRange(options.start, options.end), gzip); - - function gzip(err) { - if (err) return callback(err); - var after = glyphs.serialize(); - zlib.gzip(after, callback); - } -} - -function getRange(start, end) { - if (typeof start !== 'number') throw new Error('start must be a number from 0-65535'); - if (start < 0) throw new Error('start must be a number from 0-65535'); - if (typeof end !== 'number') throw new Error('end must be a number from 0-65535'); - if (end > 65535) throw new Error('end must be a number from 0-65535'); - if (start > end) throw new Error('start must be less than or equal to end'); - var range = []; - for (var i = start; i <= end; i++) range.push(i); - return range; -} - +module.exports = require('./lib/fontnik.node'); diff --git a/package.json b/package.json index e2f9c4ff7..5455816cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fontnik", - "version": "0.2.6", + "version": "1.0.0", "description": "A library that delivers a range of glyphs rendered as SDFs (signed distance fields) in a protobuf.", "keywords": [ "font", @@ -23,9 +23,10 @@ } ], "dependencies": { + "benchmark": "^1.0.0", "minimist": "^0.2.0", - "nan": "^1.2.0", - "node-pre-gyp": "^0.5.31", + "nan": "^1.7.0", + "node-pre-gyp": "~0.6.4", "queue-async": "^1.0.7" }, "bundledDependencies": [ diff --git a/src/glyphs.cpp b/src/glyphs.cpp index 2697bb351..406f9dd32 100644 --- a/src/glyphs.cpp +++ b/src/glyphs.cpp @@ -1,207 +1,672 @@ // fontnik -#include +#include "glyphs.hpp" // node #include #include +#include "agg_curves.h" + +// boost +// undef B0 to workaround https://svn.boost.org/trac/boost/ticket/10467 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-variable" +#undef B0 +#include +#include +#include +#include +#pragma GCC diagnostic pop + +// std +#include // std::sqrt + +namespace bg = boost::geometry; +namespace bgm = bg::model; +namespace bgi = bg::index; +typedef bgm::point Point; +typedef bgm::box Box; +typedef std::vector Points; +typedef std::vector Rings; +typedef std::pair SegmentPair; +typedef std::pair SegmentValue; +typedef bgi::rtree> Tree; + namespace node_fontnik { +struct FaceMetadata { + std::string family_name; + std::string style_name; + std::vector points; + FaceMetadata(std::string const& _family_name, + std::string const& _style_name, + std::vector && _points) : + family_name(_family_name), + style_name(_style_name), + points(std::move(_points)) {} +}; + +struct LoadBaton { + v8::Persistent callback; + v8::Persistent buffer; + const char * font_data; + std::size_t font_size; + std::string error_name; + std::vector faces; + uv_work_t request; + LoadBaton(v8::Local buf, + v8::Local cb) : + font_data(node::Buffer::Data(buf)), + font_size(node::Buffer::Length(buf)), + error_name(), + faces(), + request() { + request.data = this; + NanAssignPersistent(callback, cb.As()); + NanAssignPersistent(buffer, buf.As()); + } + ~LoadBaton() { + NanDisposePersistent(callback); + NanDisposePersistent(buffer); + } +}; + struct RangeBaton { v8::Persistent callback; - Glyphs *glyphs; - std::string fontstack; - std::string range; - std::vector chars; - bool error; + v8::Persistent buffer; + const char * font_data; + std::size_t font_size; std::string error_name; + std::uint32_t start; + std::uint32_t end; + std::vector chars; + std::string message; + uv_work_t request; + RangeBaton(v8::Local buf, + v8::Local cb, + std::uint32_t _start, + std::uint32_t _end) : + font_data(node::Buffer::Data(buf)), + font_size(node::Buffer::Length(buf)), + error_name(), + start(_start), + end(_end), + chars(), + message(), + request() { + request.data = this; + NanAssignPersistent(callback, cb.As()); + NanAssignPersistent(buffer, buf.As()); + } + ~RangeBaton() { + NanDisposePersistent(callback); + NanDisposePersistent(buffer); + } }; -v8::Persistent Glyphs::constructor; +NAN_METHOD(Load) { + NanScope(); -Glyphs::Glyphs() : node::ObjectWrap() { - glyphs = fontnik::Glyphs(); -} + // Validate arguments. + if (!args[0]->IsObject()) { + return NanThrowTypeError("First argument must be a font buffer"); + } + v8::Local obj = args[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { + return NanThrowTypeError("First argument must be a font buffer"); + } -Glyphs::Glyphs(const char *data, size_t length) : node::ObjectWrap() { - glyphs = fontnik::Glyphs(data, length); -} + if (args.Length() < 2 || !args[1]->IsFunction()) { + return NanThrowTypeError("Callback must be a function"); + } -Glyphs::~Glyphs() {} + LoadBaton* baton = new LoadBaton(obj,args[1]); + uv_queue_work(uv_default_loop(), &baton->request, LoadAsync, (uv_after_work_cb)AfterLoad); + NanReturnUndefined(); +} -void Glyphs::Init(v8::Handle target) { +NAN_METHOD(Range) { NanScope(); - v8::Local tpl = NanNew(New); - v8::Local name = NanNew("Glyphs"); + // Validate arguments. + if (args.Length() < 1 || !args[0]->IsObject()) { + return NanThrowTypeError("First argument must be an object of options"); + } + + v8::Local options = args[0].As(); + v8::Local font_buffer = options->Get(NanNew("font")); + if (!font_buffer->IsObject()) { + return NanThrowTypeError("Font buffer is not an object"); + } + v8::Local obj = font_buffer->ToObject(); + v8::Local start = options->Get(NanNew("start")); + v8::Local end = options->Get(NanNew("end")); - NanAssignPersistent(Glyphs::constructor, tpl); + if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { + return NanThrowTypeError("First argument must be a font buffer"); + } - // node::ObjectWrap uses the first internal field to store the wrapped pointer. - tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(name); + if (!start->IsNumber() || start->IntegerValue() < 0) { + return NanThrowTypeError("option `start` must be a number from 0-65535"); + } - // Add all prototype methods, getters and setters here. - NODE_SET_PROTOTYPE_METHOD(tpl, "serialize", Serialize); - NODE_SET_PROTOTYPE_METHOD(tpl, "range", Range); - NODE_SET_PROTOTYPE_METHOD(tpl, "codepoints", Codepoints); + if (!end->IsNumber() || end->IntegerValue() > 65535) { + return NanThrowTypeError("option `end` must be a number from 0-65535"); + } - // This has to be last, otherwise the properties won't show up on the - // object in JavaScript. - target->Set(name, constructor->GetFunction()); + if (end->IntegerValue() < start->IntegerValue()) { + return NanThrowTypeError("`start` must be less than or equal to `end`"); + } + + if (args.Length() < 2 || !args[1]->IsFunction()) { + return NanThrowTypeError("Callback must be a function"); + } + + RangeBaton* baton = new RangeBaton(obj, + args[1], + start->IntegerValue(), + end->IntegerValue()); + uv_queue_work(uv_default_loop(), &baton->request, RangeAsync, (uv_after_work_cb)AfterRange); + NanReturnUndefined(); } -NAN_METHOD(Glyphs::New) { - NanScope(); +struct ft_library_guard { + ft_library_guard(FT_Library * lib) : + library_(lib) {} - if (!args.IsConstructCall()) { - return NanThrowTypeError("Constructor must be called with new keyword"); + ~ft_library_guard() + { + if (library_) FT_Done_FreeType(*library_); } - if (args.Length() > 0 && !node::Buffer::HasInstance(args[0])) { - return NanThrowTypeError("First argument may only be a buffer"); + + FT_Library * library_; +}; + +struct ft_glyph_guard { + ft_glyph_guard(FT_Glyph * glyph) : + glyph_(glyph) {} + + ~ft_glyph_guard() + { + if (glyph_) FT_Done_Glyph(*glyph_); } - Glyphs* glyphs; + FT_Glyph * glyph_; +}; + +void LoadAsync(uv_work_t* req) { + LoadBaton* baton = static_cast(req->data); + + FT_Library library = nullptr; + ft_library_guard library_guard(&library); + FT_Error error = FT_Init_FreeType(&library); + if (error) { + /* LCOV_EXCL_START */ + baton->error_name = std::string("could not open FreeType library"); + return; + /* LCOV_EXCL_END */ + } + FT_Face ft_face = 0; + int num_faces = 0; + for ( int i = 0; ft_face == 0 || i < num_faces; ++i ) + { + FT_Error face_error = FT_New_Memory_Face(library, reinterpret_cast(baton->font_data), static_cast(baton->font_size), i, &ft_face); + if (face_error) { + baton->error_name = std::string("could not open font file"); + return; + } + std::set points; + if (num_faces == 0) + num_faces = ft_face->num_faces; + FT_ULong charcode; + FT_UInt gindex; + charcode = FT_Get_First_Char(ft_face, &gindex); + while (gindex != 0) { + charcode = FT_Get_Next_Char(ft_face, charcode, &gindex); + if (charcode != 0) points.emplace(charcode); + } - if (args.Length() < 1) { - glyphs = new Glyphs(); + std::vector points_vec(points.begin(), points.end()); + baton->faces.emplace_back(ft_face->family_name, ft_face->style_name, std::move(points_vec)); + if (ft_face) { + FT_Done_Face(ft_face); + } + } +}; + +void AfterLoad(uv_work_t* req) { + NanScope(); + LoadBaton* baton = static_cast(req->data); + + if (!baton->error_name.empty()) { + v8::Local argv[1] = { NanError(baton->error_name.c_str()) }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 1, argv); } else { - v8::Local buffer = args[0]->ToObject(); - glyphs = new Glyphs(node::Buffer::Data(buffer), node::Buffer::Length(buffer)); + v8::Local js_faces = NanNew(); + unsigned idx = 0; + for (auto const& face : baton->faces) { + v8::Local js_face = NanNew(); + js_face->Set(NanNew("family_name"),NanNew(face.family_name)); + js_face->Set(NanNew("style_name"),NanNew(face.style_name)); + v8::Local js_points = NanNew(face.points.size()); + unsigned p_idx = 0; + for (auto const& pt : face.points) { + js_points->Set(p_idx++,NanNew(pt)); + } + js_face->Set(NanNew("points"),js_points); + js_faces->Set(idx++,js_face); + } + v8::Local argv[2] = { NanNull(), js_faces }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); } + delete baton; +}; - glyphs->Wrap(args.This()); +void RangeAsync(uv_work_t* req) { + RangeBaton* baton = static_cast(req->data); - NanReturnValue(args.This()); -} + unsigned array_size = baton->end - baton->start; + baton->chars.reserve(array_size); + for (unsigned i=baton->start; i <= array_size; i++) { + baton->chars.emplace_back(i); + } -bool Glyphs::HasInstance(v8::Handle val) { - if (!val->IsObject()) return false; - return constructor->HasInstance(val->ToObject()); -} + FT_Library library = nullptr; + ft_library_guard library_guard(&library); + FT_Error error = FT_Init_FreeType(&library); + if (error) { + /* LCOV_EXCL_START */ + baton->error_name = std::string("could not open FreeType library"); + return; + /* LCOV_EXCL_END */ + } -NAN_METHOD(Glyphs::Serialize) { - NanScope(); - std::string serialized = node::ObjectWrap::Unwrap(args.This())->glyphs.Serialize(); - NanReturnValue(NanNewBufferHandle(serialized.data(), serialized.length())); + FT_Face ft_face = 0; + + llmr::glyphs::glyphs glyphs; + + int num_faces = 0; + for ( int i = 0; ft_face == 0 || i < num_faces; ++i ) + { + FT_Error face_error = FT_New_Memory_Face(library, reinterpret_cast(baton->font_data), static_cast(baton->font_size), i, &ft_face); + if (face_error) { + baton->error_name = std::string("could not open font"); + return; + } + + llmr::glyphs::fontstack *mutable_fontstack = glyphs.add_stacks(); + mutable_fontstack->set_name(std::string(ft_face->family_name) + " " + ft_face->style_name); + mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end)); + + const double scale_factor = 1.0; + + // Set character sizes. + double size = 24 * scale_factor; + FT_Set_Char_Size(ft_face,0,(FT_F26Dot6)(size * (1<<6)),0,0); + + for (std::vector::size_type x = 0; x != baton->chars.size(); x++) { + FT_ULong char_code = baton->chars[x]; + glyph_info glyph; + + // Get FreeType face from face_ptr. + FT_UInt char_index = FT_Get_Char_Index(ft_face, char_code); + + if (!char_index) continue; + + glyph.glyph_index = char_index; + RenderSDF(glyph, 24, 3, 0.25, ft_face); + + // Add glyph to fontstack. + llmr::glyphs::glyph *mutable_glyph = mutable_fontstack->add_glyphs(); + mutable_glyph->set_id(char_code); + mutable_glyph->set_width(glyph.width); + mutable_glyph->set_height(glyph.height); + mutable_glyph->set_left(glyph.left); + mutable_glyph->set_top(glyph.top - glyph.ascender); + mutable_glyph->set_advance(glyph.advance); + + if (glyph.width > 0) { + mutable_glyph->set_bitmap(glyph.bitmap); + } + + } + if (ft_face) { + FT_Done_Face(ft_face); + } + } + + baton->message = glyphs.SerializeAsString(); } -NAN_METHOD(Glyphs::Range) { +void AfterRange(uv_work_t* req) { NanScope(); + RangeBaton* baton = static_cast(req->data); - // Validate arguments. - if (args.Length() < 1 || !args[0]->IsString()) { - return NanThrowTypeError("fontstack must be a string"); + if (!baton->error_name.empty()) { + v8::Local argv[1] = { NanError(baton->error_name.c_str()) }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 1, argv); + } else { + v8::Local js_faces = NanNew(); + unsigned idx = 0; + v8::Local argv[2] = { NanNull(), NanNewBufferHandle(baton->message.data(), baton->message.size()) }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); } - if (args.Length() < 2 || !args[1]->IsString()) { - return NanThrowTypeError("range must be a string"); - } + delete baton; +}; - if (args.Length() < 3 || !args[2]->IsArray()) { - return NanThrowTypeError("chars must be an array"); +struct User { + Rings rings; + Points ring; +}; + +void CloseRing(Points &ring) +{ + const Point &first = ring.front(); + const Point &last = ring.back(); + + if (first.get<0>() != last.get<0>() || + first.get<1>() != last.get<1>()) + { + ring.push_back(first); } +} - if (args.Length() < 4 || !args[3]->IsFunction()) { - return NanThrowTypeError("callback must be a function"); +int MoveTo(const FT_Vector *to, void *ptr) +{ + User *user = (User*)ptr; + if (!user->ring.empty()) { + CloseRing(user->ring); + user->rings.push_back(user->ring); + user->ring.clear(); } + user->ring.push_back(Point { float(to->x) / 64, float(to->y) / 64 }); + return 0; +} - v8::String::Utf8Value fontstack(args[0]->ToString()); - v8::String::Utf8Value range(args[1]->ToString()); - v8::Local charsArray = v8::Local::Cast(args[2]); - v8::Local callback = v8::Local::Cast(args[3]); +int LineTo(const FT_Vector *to, void *ptr) +{ + User *user = (User*)ptr; + user->ring.push_back(Point { float(to->x) / 64, float(to->y) / 64 }); + return 0; +} - unsigned array_size = charsArray->Length(); - std::vector chars; - for (unsigned i=0; i < array_size; i++) { - chars.push_back(charsArray->Get(i)->IntegerValue()); +int ConicTo(const FT_Vector *control, + const FT_Vector *to, + void *ptr) +{ + User *user = (User*)ptr; + + Point prev = user->ring.back(); + + // pop off last point, duplicate of first point in bezier curve + user->ring.pop_back(); + + agg_fontnik::curve3_div curve(prev.get<0>(), prev.get<1>(), + float(control->x) / 64, float(control->y) / 64, + float(to->x) / 64, float(to->y) / 64); + + curve.rewind(0); + double x, y; + unsigned cmd; + + while (agg_fontnik::path_cmd_stop != (cmd = curve.vertex(&x, &y))) { + user->ring.push_back(Point {x, y}); } - Glyphs *glyphs = node::ObjectWrap::Unwrap(args.This()); + return 0; +} + +int CubicTo(const FT_Vector *c1, + const FT_Vector *c2, + const FT_Vector *to, + void *ptr) +{ + User *user = (User*)ptr; - RangeBaton* baton = new RangeBaton(); - baton->callback = v8::Persistent::New(callback); - baton->glyphs = glyphs; - baton->fontstack = *fontstack; - baton->range = *range; - baton->chars = chars; + Point prev = user->ring.back(); - uv_work_t *req = new uv_work_t(); - req->data = baton; + // pop off last point, duplicate of first point in bezier curve + user->ring.pop_back(); - int status = uv_queue_work(uv_default_loop(), req, AsyncRange, (uv_after_work_cb)RangeAfter); - assert(status == 0); + agg_fontnik::curve4_div curve(prev.get<0>(), prev.get<1>(), + float(c1->x) / 64, float(c1->y) / 64, + float(c2->x) / 64, float(c2->y) / 64, + float(to->x) / 64, float(to->y) / 64); - NanReturnUndefined(); + curve.rewind(0); + double x, y; + unsigned cmd; + + while (agg_fontnik::path_cmd_stop != (cmd = curve.vertex(&x, &y))) { + user->ring.push_back(Point {x, y}); + } + + return 0; } -NAN_METHOD(Glyphs::Codepoints) { - NanScope(); +// point in polygon ray casting algorithm +bool PolyContainsPoint(const Rings &rings, const Point &p) +{ + bool c = false; - // Validate arguments. - if (args.Length() < 1 || !args[0]->IsString()) { - return NanThrowTypeError("fontstack must be a string"); + for (const Points &ring : rings) { + auto p1 = ring.begin(); + auto p2 = p1 + 1; + + for (; p2 != ring.end(); p1++, p2++) { + if (((p1->get<1>() > p.get<1>()) != (p2->get<1>() > p.get<1>())) && (p.get<0>() < (p2->get<0>() - p1->get<0>()) * (p.get<1>() - p1->get<1>()) / (p2->get<1>() - p1->get<1>()) + p1->get<0>())) { + c = !c; + } + } } - v8::String::Utf8Value param1(args[0]->ToString()); - std::string from = std::string(*param1); - try { - std::vector points = fontnik::Glyphs::Codepoints(from); + return c; +} + +double SquaredDistance(const Point &v, const Point &w) +{ + const double a = v.get<0>() - w.get<0>(); + const double b = v.get<1>() - w.get<1>(); + return a * a + b * b; +} + +Point ProjectPointOnLineSegment(const Point &p, + const Point &v, + const Point &w) +{ + const double l2 = SquaredDistance(v, w); + if (l2 == 0) return v; - v8::Handle result = v8::Array::New(points.size()); + const double t = ((p.get<0>() - v.get<0>()) * (w.get<0>() - v.get<0>()) + (p.get<1>() - v.get<1>()) * (w.get<1>() - v.get<1>())) / l2; + if (t < 0) return v; + if (t > 1) return w; - for (size_t i = 0; i < points.size(); i++) { - result->Set(i, NanNew(points[i])); + return Point { + v.get<0>() + t * (w.get<0>() - v.get<0>()), + v.get<1>() + t * (w.get<1>() - v.get<1>()) + }; +} + +double SquaredDistanceToLineSegment(const Point &p, + const Point &v, + const Point &w) +{ + const Point s = ProjectPointOnLineSegment(p, v, w); + return SquaredDistance(p, s); +} + +double MinDistanceToLineSegment(const Tree &tree, + const Point &p, + int radius) +{ + const int squared_radius = radius * radius; + + std::vector results; + tree.query(bgi::intersects( + Box{ + Point{p.get<0>() - radius, p.get<1>() - radius}, + Point{p.get<0>() + radius, p.get<1>() + radius} + }), + std::back_inserter(results)); + + double sqaured_distance = std::numeric_limits::infinity(); + + for (const auto &value : results) { + const SegmentPair &segment = value.second; + const double dist = SquaredDistanceToLineSegment(p, + segment.first, + segment.second); + if (dist < sqaured_distance && dist < squared_radius) { + sqaured_distance = dist; } - NanReturnValue(result); - } catch (std::exception const& ex) { - return NanThrowTypeError(ex.what()); } - NanReturnUndefined(); + + return std::sqrt(sqaured_distance); } -void Glyphs::AsyncRange(uv_work_t* req) { - RangeBaton* baton = static_cast(req->data); +void RenderSDF(glyph_info &glyph, + int size, + int buffer, + float cutoff, + FT_Face ft_face) +{ - try { - baton->glyphs->glyphs.Range(baton->fontstack, baton->range, baton->chars); - } catch(const std::runtime_error &e) { - baton->error = true; - baton->error_name = e.what(); + if (FT_Load_Glyph (ft_face, glyph.glyph_index, FT_LOAD_NO_HINTING)) { return; } -} -void Glyphs::RangeAfter(uv_work_t* req) { - NanScope(); - RangeBaton* baton = static_cast(req->data); + FT_Glyph ft_glyph = nullptr; + ft_glyph_guard glyph_guard(&ft_glyph); + if (FT_Get_Glyph(ft_face->glyph, &ft_glyph)) return; + + int advance = ft_face->glyph->metrics.horiAdvance / 64; + int ascender = ft_face->size->metrics.ascender / 64; + int descender = ft_face->size->metrics.descender / 64; + + glyph.line_height = ft_face->size->metrics.height; + glyph.advance = advance; + glyph.ascender = ascender; + glyph.descender = descender; + + FT_Outline_Funcs func_interface = { + .move_to = &MoveTo, + .line_to = &LineTo, + .conic_to = &ConicTo, + .cubic_to = &CubicTo, + .shift = 0, + .delta = 0 + }; + + User user; + + // Decompose outline into bezier curves and line segments + FT_Outline outline = ((FT_OutlineGlyph)ft_glyph)->outline; + if (FT_Outline_Decompose(&outline, &func_interface, &user)) return; + + if (!user.ring.empty()) { + CloseRing(user.ring); + user.rings.push_back(user.ring); + } - const unsigned argc = 1; + if (user.rings.empty()) return; - v8::TryCatch try_catch; - v8::Local ctx = NanGetCurrentContext(); + // Calculate the real glyph bbox. + double bbox_xmin = std::numeric_limits::infinity(), + bbox_ymin = std::numeric_limits::infinity(); - if (baton->error) { - v8::Local argv[argc] = { - v8::Exception::Error(NanNew(baton->error_name.c_str())) - }; - baton->callback->Call(ctx->Global(), argc, argv); - } else { - v8::Local argv[argc] = { - NanNull() - }; - baton->callback->Call(ctx->Global(), argc, argv); + double bbox_xmax = -std::numeric_limits::infinity(), + bbox_ymax = -std::numeric_limits::infinity(); + + for (const Points &ring : user.rings) { + for (const Point &point : ring) { + if (point.get<0>() > bbox_xmax) bbox_xmax = point.get<0>(); + if (point.get<0>() < bbox_xmin) bbox_xmin = point.get<0>(); + if (point.get<1>() > bbox_ymax) bbox_ymax = point.get<1>(); + if (point.get<1>() < bbox_ymin) bbox_ymin = point.get<1>(); + } + } + + bbox_xmin = std::round(bbox_xmin); + bbox_ymin = std::round(bbox_ymin); + bbox_xmax = std::round(bbox_xmax); + bbox_ymax = std::round(bbox_ymax); + + // Offset so that glyph outlines are in the bounding box. + for (Points &ring : user.rings) { + for (Point &point : ring) { + point.set<0>(point.get<0>() + -bbox_xmin + buffer); + point.set<1>(point.get<1>() + -bbox_ymin + buffer); + } } - if (try_catch.HasCaught()) { - node::FatalException(try_catch); + if (bbox_xmax - bbox_xmin == 0 || bbox_ymax - bbox_ymin == 0) return; + + glyph.left = bbox_xmin; + glyph.top = bbox_ymax; + glyph.width = bbox_xmax - bbox_xmin; + glyph.height = bbox_ymax - bbox_ymin; + + Tree tree; + float offset = 0.5; + int radius = 8; + + for (const Points &ring : user.rings) { + auto p1 = ring.begin(); + auto p2 = p1 + 1; + + for (; p2 != ring.end(); p1++, p2++) { + const int segment_x1 = std::min(p1->get<0>(), p2->get<0>()); + const int segment_x2 = std::max(p1->get<0>(), p2->get<0>()); + const int segment_y1 = std::min(p1->get<1>(), p2->get<1>()); + const int segment_y2 = std::max(p1->get<1>(), p2->get<1>()); + + tree.insert(SegmentValue { + Box { + Point {segment_x1, segment_y1}, + Point {segment_x2, segment_y2} + }, + SegmentPair { + Point {p1->get<0>(), p1->get<1>()}, + Point {p2->get<0>(), p2->get<1>()} + } + }); + } } - baton->callback.Dispose(); + // Loop over every pixel and determine the positive/negative distance to the outline. + unsigned int buffered_width = glyph.width + 2 * buffer; + unsigned int buffered_height = glyph.height + 2 * buffer; + unsigned int bitmap_size = buffered_width * buffered_height; + glyph.bitmap.resize(bitmap_size); - delete baton; - delete req; + for (unsigned int y = 0; y < buffered_height; y++) { + for (unsigned int x = 0; x < buffered_width; x++) { + unsigned int ypos = buffered_height - y - 1; + unsigned int i = ypos * buffered_width + x; + + double d = MinDistanceToLineSegment(tree, Point {x + offset, y + offset}, radius) * (256 / radius); + + // Invert if point is inside. + const bool inside = PolyContainsPoint(user.rings, Point { x + offset, y + offset }); + if (inside) { + d = -d; + } + + // Shift the 0 so that we can fit a few negative values + // into our 8 bits. + d += cutoff * 256; + + // Clamp to 0-255 to prevent overflows or underflows. + int n = d > 255 ? 255 : d; + n = n < 0 ? 0 : n; + + glyph.bitmap[i] = static_cast(255 - n); + } + } } } // ns node_fontnik diff --git a/src/glyphs.hpp b/src/glyphs.hpp new file mode 100644 index 000000000..22e02c57f --- /dev/null +++ b/src/glyphs.hpp @@ -0,0 +1,68 @@ +#ifndef NODE_FONTNIK_GLYPHS_HPP +#define NODE_FONTNIK_GLYPHS_HPP + +#include "glyphs.pb.h" + +#include +#include + +// freetype2 +extern "C" +{ +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H +#include FT_OUTLINE_H +} + +namespace node_fontnik +{ + +NAN_METHOD(Load); +void LoadAsync(uv_work_t* req); +void AfterLoad(uv_work_t* req); +NAN_METHOD(Range); +void RangeAsync(uv_work_t* req); +void AfterRange(uv_work_t* req); +struct glyph_info; +void RenderSDF(glyph_info &glyph, + int size, + int buffer, + float cutoff, + FT_Face ft_face); + +struct glyph_info +{ + glyph_info() + : glyph_index(0), + bitmap(""), + char_index(0), + left(0), + top(0), + width(0), + height(0), + advance(0.0), + line_height(0.0), + ascender(0.0), + descender(0.0) {} + unsigned glyph_index; + std::string bitmap; + // Position in the string of all characters i.e. before itemizing + unsigned char_index; + int32_t left; + int32_t top; + uint32_t width; + uint32_t height; + double advance; + // Line height returned by FreeType, includes normal font + // line spacing, but not additional user defined spacing + double line_height; + // Ascender and descender from baseline returned by FreeType + double ascender; + double descender; +}; + + +} // ns node_fontnik + +#endif // NODE_FONTNIK_GLYPHS_HPP diff --git a/src/node_fontnik.cpp b/src/node_fontnik.cpp index 59ac4bfeb..9f1627ab6 100644 --- a/src/node_fontnik.cpp +++ b/src/node_fontnik.cpp @@ -1,8 +1,5 @@ -// node-mapnik -#include "mapnik_fonts.hpp" - // fontnik -#include +#include "glyphs.hpp" // node #include @@ -12,11 +9,9 @@ namespace node_fontnik { void RegisterModule(v8::Handle target) { - NODE_SET_METHOD(target, "register_fonts", node_mapnik_fontnik::register_fonts); - NODE_SET_METHOD(target, "faces", node_mapnik_fontnik::available_font_faces); - NODE_SET_METHOD(target, "files", node_mapnik_fontnik::available_font_files); + NODE_SET_METHOD(target, "load", node_fontnik::Load); + NODE_SET_METHOD(target, "range", node_fontnik::Range); - Glyphs::Init(target); } NODE_MODULE(fontnik, RegisterModule); diff --git a/test/expected/chars.json b/test/expected/chars.json deleted file mode 100644 index d05ee74f0..000000000 --- a/test/expected/chars.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "stacks": { - "Open Sans Regular": { - "glyphs": { - "97": { - "id": 97, - "width": 10, - "height": 13, - "left": 1, - "top": -13, - "advance": 13 - }, - "122": { - "id": 122, - "width": 9, - "height": 13, - "left": 1, - "top": -13, - "advance": 11 - } - }, - "name": "Open Sans Regular", - "range": "a-and-z" - } - } -} \ No newline at end of file diff --git a/test/expected/load.json b/test/expected/load.json new file mode 100644 index 000000000..75bdfa03f --- /dev/null +++ b/test/expected/load.json @@ -0,0 +1 @@ +[{"family_name":"Fira Sans","style_name":"Medium","points":[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,402,508,509,510,511,536,537,538,539,567,700,710,711,728,729,730,731,732,733,768,769,770,771,772,774,775,776,778,779,780,787,788,806,807,900,901,902,904,905,906,908,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1122,1123,1138,1139,1140,1141,1168,1169,1170,1171,1174,1175,1176,1177,1178,1179,1180,1181,1184,1185,1186,1187,1194,1195,1196,1197,1198,1199,1200,1201,1202,1203,1206,1207,1208,1209,1210,1211,1216,1217,1218,1227,1228,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1242,1243,1244,1245,1246,1247,1250,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1273,1308,1309,1316,1317,1318,1319,7808,7809,7810,7811,7812,7813,7922,7923,8048,8049,8050,8051,8052,8053,8054,8055,8056,8057,8058,8059,8060,8061,8112,8113,8118,8120,8121,8122,8123,8128,8134,8136,8137,8138,8139,8144,8145,8146,8147,8150,8151,8152,8153,8154,8155,8160,8161,8162,8163,8166,8167,8168,8169,8170,8171,8182,8184,8185,8186,8187,8199,8200,8203,8204,8205,8206,8207,8210,8211,8212,8213,8216,8217,8218,8220,8221,8222,8224,8225,8226,8230,8240,8249,8250,8260,8304,8308,8309,8310,8311,8312,8313,8314,8315,8316,8317,8318,8320,8321,8322,8323,8324,8325,8326,8327,8328,8329,8330,8331,8332,8333,8334,8364,8470,8482,8486,8494,8531,8532,8533,8534,8535,8536,8537,8538,8539,8540,8541,8542,8543,8592,8593,8594,8595,8596,8597,8598,8599,8600,8601,8678,8679,8680,8681,8682,8706,8709,8710,8719,8721,8722,8725,8729,8730,8734,8747,8776,8800,8804,8805,8901,8998,8999,9000,9003,9166,9647,9674,10145,11013,11014,11015,57344,57345,57346,57347,64257,64258,65279,127760]}] diff --git a/test/test.js b/test/test.js index 91f1c3059..9cd3dbe36 100644 --- a/test/test.js +++ b/test/test.js @@ -1,7 +1,7 @@ var fontnik = require('../index.js'); var assert = require('assert'); -var zlib = require('zlib'); var fs = require('fs'); +var zlib = require('zlib'); var path = require('path'); var zdata = fs.readFileSync(__dirname + '/fixtures/range.0.256.pbf'); var Protobuf = require('pbf'); @@ -17,169 +17,135 @@ function jsonEqual(key, json) { assert.deepEqual(json, require('./expected/'+key+'.json')); } -fontnik.register_fonts(path.resolve(__dirname + '/../fonts/'), { recurse: true }); - -describe('glyphs', function() { - var data; - before(function(done) { - zlib.inflate(zdata, function(err, d) { +var expected = JSON.parse(fs.readFileSync(__dirname + '/expected/load.json').toString()); +var firasans = fs.readFileSync(path.resolve(__dirname + '/../fonts/firasans-medium/FiraSans-Medium.ttf')); +var opensans = fs.readFileSync(path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf')); +describe('load', function() { + it('loads: fira sans', function(done) { + fontnik.load(firasans, function(err, faces) { assert.ifError(err); - data = d; + assert.deepEqual(faces,expected); done(); }); }); - it('serialize', function(done) { - // On disk fixture generated with the following code. - if (UPDATE) { - fontnik.range({ - fontstack:'Open Sans Regular', - start: 0, - end: 256 - }, function(err, zdata) { - if (err) throw err; - fs.writeFileSync(__dirname + '/fixtures/range.0.256.pbf', zdata); - done(); - }); - } - var glyphs = new fontnik.Glyphs(data); - var vt = new Glyphs(new Protobuf(new Uint8Array(glyphs.serialize()))); - var json = JSON.parse(JSON.stringify(vt, nobuffer)); - jsonEqual('range', json); - done(); - }); - - it('range', function(done) { - var glyphs = new fontnik.Glyphs(); - glyphs.range('Open Sans Regular', '0-256', fontnik.getRange(0, 256), function(err) { + it('loads: open sans', function(done) { + fontnik.load(opensans, function(err, faces) { assert.ifError(err); - var vt = new Glyphs(new Protobuf(new Uint8Array(glyphs.serialize()))); - var json = JSON.parse(JSON.stringify(vt, nobuffer)); - jsonEqual('range', json); + assert.equal(faces[0].points.length, 882); + assert.equal(faces[0].family_name, 'Open Sans'); + assert.equal(faces[0].style_name, 'Regular'); done(); }); }); - // Render a long range of characters which can cause segfaults - // with V8 arrays ... not sure yet why. - it('longrange', function(done) { - var glyphs = new fontnik.Glyphs(); - glyphs.range('Open Sans Regular', '0-1024', fontnik.getRange(0, 1024), function(err) { - assert.ifError(err); - done(); - }); + it('invalid font loading', function(done) { + var baloneysans; + assert.throws(function() { + fontnik.load(baloneysans, function(err, faces) {}); + }, /First argument must be a font buffer/); + done(); }); - it('range (chars input)', function(done) { - var glyphs = new fontnik.Glyphs(); - glyphs.range('Open Sans Regular', 'a-and-z', [('a').charCodeAt(0), ('z').charCodeAt(0)], function(err) { - assert.ifError(err); - var vt = new Glyphs(new Protobuf(new Uint8Array(glyphs.serialize()))); - var json = JSON.parse(JSON.stringify(vt, nobuffer)); - jsonEqual('chars', json); + it('non existent font loading', function(done) { + var doesnotexistsans = new Buffer('baloney'); + fontnik.load(doesnotexistsans, function(err, faces) { + assert.ok(err.message.indexOf('Font buffer is not an object')); done(); }); }); - it('range typeerror fontstack', function(done) { - var glyphs = new fontnik.Glyphs(); - assert.throws(function() { - glyphs.range(0, '0-256', fontnik.getRange(0, 256), function() {}); - }, /fontstack must be a string/); - done(); - }); - - it('range typeerror range', function(done) { - var glyphs = new fontnik.Glyphs(); + it('load typeerror callback', function(done) { assert.throws(function() { - glyphs.range('Open Sans Regular', 0, fontnik.getRange(0, 256), function() {}); - }, /range must be a string/); + fontnik.load(firasans); + }, /Callback must be a function/); done(); }); - it('range typeerror chars', function(done) { - var glyphs = new fontnik.Glyphs(); - assert.throws(function() { - glyphs.range('Open Sans Regular', '0-256', 'foo', function() {}); - }, /chars must be an array/); - done(); - }); +}); - it('range typeerror callback', function(done) { - var glyphs = new fontnik.Glyphs(); - assert.throws(function() { - glyphs.range('Open Sans Regular', '0-256', fontnik.getRange(0, 256), ''); - }, /callback must be a function/); - done(); - }); +describe('range', function() { + var data; + before(function(done) { + zlib.inflate(zdata, function(err, d) { + assert.ifError(err); + data = d; + done(); + }); + }); - it('range for fontstack with 0 matching fonts', function(done) { - var glyphs = new fontnik.Glyphs(); - glyphs.range('doesnotexist', '0-256', fontnik.getRange(0, 256), function(err) { - assert.ok(err); - assert.equal("Error: Failed to find face 'doesnotexist' in font set 'doesnotexist'", err.toString()); + it('ranges', function(done) { + this.timeout(10000); + fontnik.range({font: opensans, start: 0, end: 256}, function(err, res) { + assert.ifError(err); + assert.ok(res); + assert.deepEqual(res, data); + var vt = new Glyphs(new Protobuf(new Uint8Array(res))); + var json = JSON.parse(JSON.stringify(vt, nobuffer)); + jsonEqual('range', json); done(); }); }); - it('range for fontstack with 1 bad font', function(done) { - var glyphs = new fontnik.Glyphs(); - glyphs.range('Open Sans Regular, doesnotexist', '0-256', fontnik.getRange(0, 256), function(err) { - assert.ok(err); - assert.equal("Error: Failed to find face 'doesnotexist' in font set 'Open Sans Regular, doesnotexist'", err.toString()); + it('longrange', function(done) { + this.timeout(10000); + fontnik.range({font: opensans, start: 0, end: 1024}, function(err, data) { + assert.ifError(err); + assert.ok(data); done(); }); }); - // Should error because start is < 0 - it('getRange error start < 0', function() { + + it('range typeerror options', function(done) { assert.throws(function() { - fontnik.getRange(-128, 256); - }, 'Error: start must be a number from 0-65535'); + fontnik.range(opensans, function(err, data) {}); + }, /Font buffer is not an object/); + done(); }); - // Should error because end < start - it('getRange error end < start', function() { - assert.throws(function() { - fontnik.getRange(256, 0); - }, 'Error: start must be less than or equal to end'); + it('range filepath does not exist', function(done) { + var doesnotexistsans = new Buffer('baloney'); + fontnik.range({font: doesnotexistsans, start: 0, end: 256}, function(err, faces) { + assert.ok(err.message.indexOf('Font buffer is not an object')); + done(); + }); }); - // Should error because end > 65535 - it('getRange error end > 65535', function() { + it('range typeerror start', function(done) { + assert.throws(function() { + fontnik.range({font: opensans, start: 'x', end: 256}, function(err, data) {}); + }, /option `start` must be a number from 0-65535/); assert.throws(function() { - fontnik.getRange(0, 65536); - }, 'Error: end must be a number from 0-65535'); + fontnik.range({font: opensans, start: -3, end: 256}, function(err, data) {}); + }, /option `start` must be a number from 0-65535/); + done(); }); -}); -describe('codepoints', function() { - it('basic scanning: open sans', function() { - var glyphs = new fontnik.Glyphs(); - var cp = glyphs.codepoints('Open Sans Regular'); - assert.equal(cp.length, 882); - }); - it('basic scanning: fira sans', function() { - var glyphs = new fontnik.Glyphs(); - var cp = glyphs.codepoints('Fira Sans Medium'); - assert.equal(cp.length, 789); - }); - it('basic scanning: fira sans + open sans', function() { - var glyphs = new fontnik.Glyphs(); - var cp = glyphs.codepoints('Fira Sans Medium, Open Sans Regular'); - assert.equal(cp.length, 1021); + it('range typeerror end', function(done) { + assert.throws(function() { + fontnik.range({font: opensans, start: 0, end: 'y'}, function(err, data) {}); + }, /option `end` must be a number from 0-65535/); + assert.throws(function() { + fontnik.range({font: opensans, start: 0, end: 10000000}, function(err, data) {}); + }, /option `end` must be a number from 0-65535/); + done(); }); - it('invalid font face', function() { - var glyphs = new fontnik.Glyphs(); + + it('range typeerror lt', function(done) { assert.throws(function() { - glyphs.codepoints('foo-bar-invalid'); - }); + fontnik.range({font: opensans, start: 256, end: 0}, function(err, data) {}); + }, /`start` must be less than or equal to `end`/); + done(); }); -}); -describe('faces', function() { - it('list faces', function() { - var faces = fontnik.faces(); - assert.deepEqual(faces, ['Fira Sans Medium', 'Open Sans Regular']); + it('range typeerror callback', function(done) { + assert.throws(function() { + fontnik.range({font: opensans, start: 0, end: 256}, ''); + }, /Callback must be a function/); + assert.throws(function() { + fontnik.range({font: opensans, start: 0, end: 256}); + }, /Callback must be a function/); + done(); }); }); diff --git a/vendor/fontnik/COPYING b/vendor/fontnik/COPYING deleted file mode 100644 index e5ab03e12..000000000 --- a/vendor/fontnik/COPYING +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/vendor/fontnik/include/fontnik/face.hpp b/vendor/fontnik/include/fontnik/face.hpp deleted file mode 100644 index 2ad7567a7..000000000 --- a/vendor/fontnik/include/fontnik/face.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************** - * - * Copyright (C) 2014 Mapbox - * - * This file is part of Fontnik. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef FONTNIK_FACE_HPP -#define FONTNIK_FACE_HPP - -// mapnik -#include - -// boost -// undef B0 to workaround https://svn.boost.org/trac/boost/ticket/10467 -#undef B0 -#include -#include -#include -#include - -// stl -#include - -// freetype2 -extern "C" -{ -#include -#include FT_FREETYPE_H -#include FT_GLYPH_H -#include FT_OUTLINE_H -} - -namespace bg = boost::geometry; -namespace bgm = bg::model; -namespace bgi = bg::index; -typedef bgm::point Point; -typedef bgm::box Box; -typedef std::vector Points; -typedef std::vector Rings; -typedef std::pair SegmentPair; -typedef std::pair SegmentValue; -typedef bgi::rtree> Tree; - -namespace fontnik -{ - -class Face -{ - -public: - using glyph_info_cache_type = std::unordered_map; - - Face(FT_Face ft_face); - ~Face(); - - FT_Face get_face() const - { - return ft_face_; - } - - bool set_character_sizes(double size); - bool set_unscaled_character_sizes(); - - void RenderSDF(mapnik_fontnik::glyph_info &glyph, - int size, - int buffer, - float cutoff) const; - -private: - FT_Face ft_face_; - mutable glyph_info_cache_type glyph_info_cache_; - mutable double char_height_; -}; -typedef std::shared_ptr face_ptr; - -} // ns fontnik - -#endif // FONTNIK_FACE_HPP diff --git a/vendor/fontnik/include/fontnik/glyphs.hpp b/vendor/fontnik/include/fontnik/glyphs.hpp deleted file mode 100644 index e66775181..000000000 --- a/vendor/fontnik/include/fontnik/glyphs.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/***************************************************************************** - * - * Copyright (C) 2014 Mapbox - * - * This file is part of Fontnik. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef FONTNIK_GLYPHS_HPP -#define FONTNIK_GLYPHS_HPP - -#include -#include "glyphs.pb.h" - -namespace fontnik -{ - -class Glyphs -{ - -public: - Glyphs(); - Glyphs(const char *data, size_t length); - ~Glyphs(); - - std::string Serialize(); - void Range(std::string fontstack, - std::string range, - std::vector chars); - - static std::vector Codepoints(std::string fontstack); - - static std::string Trim(std::string str, std::string whitespace); - -public: - llmr::glyphs::glyphs glyphs; - -}; - -} // ns fontnik - -#endif // FONTNIK_GLYPHS_HPP diff --git a/vendor/fontnik/src/face.cpp b/vendor/fontnik/src/face.cpp deleted file mode 100644 index 2392a1218..000000000 --- a/vendor/fontnik/src/face.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/***************************************************************************** - * - * Copyright (C) 2014 Mapbox - * - * This file is part of Fontnik. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// fontnik -#include - -// agg -#include "agg_curves.h" - -#include - -namespace fontnik -{ - -struct User { - Rings rings; - Points ring; -}; - -Face::Face(FT_Face ft_face) - : ft_face_(ft_face), - char_height_(0.0) -{ -} - -Face::~Face() -{ - FT_Done_Face(ft_face_); -} - -bool Face::set_character_sizes(double size) -{ - char_height_ = 0.0; - return !FT_Set_Char_Size(ft_face_,0,(FT_F26Dot6)(size * (1<<6)),0,0); -} - -bool Face::set_unscaled_character_sizes() -{ - char_height_ = 0.0; - return !FT_Set_Char_Size(ft_face_,0,ft_face_->units_per_EM,0,0); -} - -void CloseRing(Points &ring) -{ - const Point &first = ring.front(); - const Point &last = ring.back(); - - if (first.get<0>() != last.get<0>() || - first.get<1>() != last.get<1>()) - { - ring.push_back(first); - } -} - -int MoveTo(const FT_Vector *to, void *ptr) -{ - User *user = (User*)ptr; - if (!user->ring.empty()) { - CloseRing(user->ring); - user->rings.push_back(user->ring); - user->ring.clear(); - } - user->ring.push_back(Point { float(to->x) / 64, float(to->y) / 64 }); - return 0; -} - -int LineTo(const FT_Vector *to, void *ptr) -{ - User *user = (User*)ptr; - user->ring.push_back(Point { float(to->x) / 64, float(to->y) / 64 }); - return 0; -} - -int ConicTo(const FT_Vector *control, - const FT_Vector *to, - void *ptr) -{ - User *user = (User*)ptr; - - Point prev = user->ring.back(); - - // pop off last point, duplicate of first point in bezier curve - user->ring.pop_back(); - - agg_fontnik::curve3_div curve(prev.get<0>(), prev.get<1>(), - float(control->x) / 64, float(control->y) / 64, - float(to->x) / 64, float(to->y) / 64); - - curve.rewind(0); - double x, y; - unsigned cmd; - - while (agg_fontnik::path_cmd_stop != (cmd = curve.vertex(&x, &y))) { - user->ring.push_back(Point {x, y}); - } - - return 0; -} - -int CubicTo(const FT_Vector *c1, - const FT_Vector *c2, - const FT_Vector *to, - void *ptr) -{ - User *user = (User*)ptr; - - Point prev = user->ring.back(); - - // pop off last point, duplicate of first point in bezier curve - user->ring.pop_back(); - - agg_fontnik::curve4_div curve(prev.get<0>(), prev.get<1>(), - float(c1->x) / 64, float(c1->y) / 64, - float(c2->x) / 64, float(c2->y) / 64, - float(to->x) / 64, float(to->y) / 64); - - curve.rewind(0); - double x, y; - unsigned cmd; - - while (agg_fontnik::path_cmd_stop != (cmd = curve.vertex(&x, &y))) { - user->ring.push_back(Point {x, y}); - } - - return 0; -} - -// point in polygon ray casting algorithm -bool PolyContainsPoint(const Rings &rings, const Point &p) -{ - bool c = false; - - for (const Points &ring : rings) { - auto p1 = ring.begin(); - auto p2 = p1 + 1; - - for (; p2 != ring.end(); p1++, p2++) { - if (((p1->get<1>() > p.get<1>()) != (p2->get<1>() > p.get<1>())) && (p.get<0>() < (p2->get<0>() - p1->get<0>()) * (p.get<1>() - p1->get<1>()) / (p2->get<1>() - p1->get<1>()) + p1->get<0>())) { - c = !c; - } - } - } - - return c; -} - -double SquaredDistance(const Point &v, const Point &w) -{ - const double a = v.get<0>() - w.get<0>(); - const double b = v.get<1>() - w.get<1>(); - return a * a + b * b; -} - -Point ProjectPointOnLineSegment(const Point &p, - const Point &v, - const Point &w) -{ - const double l2 = SquaredDistance(v, w); - if (l2 == 0) return v; - - const double t = ((p.get<0>() - v.get<0>()) * (w.get<0>() - v.get<0>()) + (p.get<1>() - v.get<1>()) * (w.get<1>() - v.get<1>())) / l2; - if (t < 0) return v; - if (t > 1) return w; - - return Point { - v.get<0>() + t * (w.get<0>() - v.get<0>()), - v.get<1>() + t * (w.get<1>() - v.get<1>()) - }; -} - -double SquaredDistanceToLineSegment(const Point &p, - const Point &v, - const Point &w) -{ - const Point s = ProjectPointOnLineSegment(p, v, w); - return SquaredDistance(p, s); -} - -double MinDistanceToLineSegment(const Tree &tree, - const Point &p, - int radius) -{ - const int squared_radius = radius * radius; - - std::vector results; - tree.query(bgi::intersects( - Box{ - Point{p.get<0>() - radius, p.get<1>() - radius}, - Point{p.get<0>() + radius, p.get<1>() + radius} - }), - std::back_inserter(results)); - - double sqaured_distance = std::numeric_limits::infinity(); - - for (const auto &value : results) { - const SegmentPair &segment = value.second; - const double dist = SquaredDistanceToLineSegment(p, - segment.first, - segment.second); - if (dist < sqaured_distance && dist < squared_radius) { - sqaured_distance = dist; - } - } - - return std::sqrt(sqaured_distance); -} - -void Face::RenderSDF(mapnik_fontnik::glyph_info &glyph, - int size, - int buffer, - float cutoff) const -{ - // Check if char is already in cache - glyph_info_cache_type::const_iterator itr; - itr = glyph_info_cache_.find(glyph.glyph_index); - if (itr != glyph_info_cache_.end()) { - glyph = itr->second; - return; - } - - if (FT_Load_Glyph (ft_face_, glyph.glyph_index, FT_LOAD_NO_HINTING)) { - return; - } - - FT_Glyph ft_glyph; - if (FT_Get_Glyph(ft_face_->glyph, &ft_glyph)) return; - - int advance = ft_face_->glyph->metrics.horiAdvance / 64; - int ascender = ft_face_->size->metrics.ascender / 64; - int descender = ft_face_->size->metrics.descender / 64; - - glyph.line_height = ft_face_->size->metrics.height; - glyph.advance = advance; - glyph.ascender = ascender; - glyph.descender = descender; - - FT_Outline_Funcs func_interface = { - .move_to = &MoveTo, - .line_to = &LineTo, - .conic_to = &ConicTo, - .cubic_to = &CubicTo, - .shift = 0, - .delta = 0 - }; - - User user; - - // Decompose outline into bezier curves and line segments - FT_Outline outline = ((FT_OutlineGlyph)ft_glyph)->outline; - if (FT_Outline_Decompose(&outline, &func_interface, &user)) return; - - if (!user.ring.empty()) { - CloseRing(user.ring); - user.rings.push_back(user.ring); - } - - if (user.rings.empty()) return; - - // Calculate the real glyph bbox. - double bbox_xmin = std::numeric_limits::infinity(), - bbox_ymin = std::numeric_limits::infinity(); - - double bbox_xmax = -std::numeric_limits::infinity(), - bbox_ymax = -std::numeric_limits::infinity(); - - for (const Points &ring : user.rings) { - for (const Point &point : ring) { - if (point.get<0>() > bbox_xmax) bbox_xmax = point.get<0>(); - if (point.get<0>() < bbox_xmin) bbox_xmin = point.get<0>(); - if (point.get<1>() > bbox_ymax) bbox_ymax = point.get<1>(); - if (point.get<1>() < bbox_ymin) bbox_ymin = point.get<1>(); - } - } - - bbox_xmin = std::round(bbox_xmin); - bbox_ymin = std::round(bbox_ymin); - bbox_xmax = std::round(bbox_xmax); - bbox_ymax = std::round(bbox_ymax); - - // Offset so that glyph outlines are in the bounding box. - for (Points &ring : user.rings) { - for (Point &point : ring) { - point.set<0>(point.get<0>() + -bbox_xmin + buffer); - point.set<1>(point.get<1>() + -bbox_ymin + buffer); - } - } - - if (bbox_xmax - bbox_xmin == 0 || bbox_ymax - bbox_ymin == 0) return; - - glyph.left = bbox_xmin; - glyph.top = bbox_ymax; - glyph.width = bbox_xmax - bbox_xmin; - glyph.height = bbox_ymax - bbox_ymin; - - Tree tree; - float offset = 0.5; - int radius = 8; - - for (const Points &ring : user.rings) { - auto p1 = ring.begin(); - auto p2 = p1 + 1; - - for (; p2 != ring.end(); p1++, p2++) { - const int segment_x1 = std::min(p1->get<0>(), p2->get<0>()); - const int segment_x2 = std::max(p1->get<0>(), p2->get<0>()); - const int segment_y1 = std::min(p1->get<1>(), p2->get<1>()); - const int segment_y2 = std::max(p1->get<1>(), p2->get<1>()); - - tree.insert(SegmentValue { - Box { - Point {segment_x1, segment_y1}, - Point {segment_x2, segment_y2} - }, - SegmentPair { - Point {p1->get<0>(), p1->get<1>()}, - Point {p2->get<0>(), p2->get<1>()} - } - }); - } - } - - // Loop over every pixel and determine the positive/negative distance to the outline. - unsigned int buffered_width = glyph.width + 2 * buffer; - unsigned int buffered_height = glyph.height + 2 * buffer; - unsigned int bitmap_size = buffered_width * buffered_height; - glyph.bitmap.resize(bitmap_size); - - for (unsigned int y = 0; y < buffered_height; y++) { - for (unsigned int x = 0; x < buffered_width; x++) { - unsigned int ypos = buffered_height - y - 1; - unsigned int i = ypos * buffered_width + x; - - double d = MinDistanceToLineSegment(tree, Point {x + offset, y + offset}, radius) * (256 / radius); - - // Invert if point is inside. - const bool inside = PolyContainsPoint(user.rings, Point { x + offset, y + offset }); - if (inside) { - d = -d; - } - - // Shift the 0 so that we can fit a few negative values - // into our 8 bits. - d += cutoff * 256; - - // Clamp to 0-255 to prevent overflows or underflows. - int n = d > 255 ? 255 : d; - n = n < 0 ? 0 : n; - - glyph.bitmap[i] = static_cast(255 - n); - } - } - - FT_Done_Glyph(ft_glyph); - - glyph_info_cache_.emplace(glyph.glyph_index, glyph); -} - -} // ns fontnik diff --git a/vendor/fontnik/src/glyphs.cpp b/vendor/fontnik/src/glyphs.cpp deleted file mode 100644 index 4ff84c2b1..000000000 --- a/vendor/fontnik/src/glyphs.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/***************************************************************************** - * - * Copyright (C) 2014 Mapbox - * - * This file is part of Fontnik. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -// fontnik -#include -#include -#include - -// stl -#include -#include -#include - -// freetype2 -extern "C" -{ -#include -#include FT_FREETYPE_H -} - -namespace fontnik -{ - -Glyphs::Glyphs() {} - -Glyphs::Glyphs(const char *data, size_t length) -{ - glyphs.ParseFromArray(data, length); -} - -Glyphs::~Glyphs() {} - -std::string Glyphs::Serialize() -{ - return glyphs.SerializeAsString(); -} - -void Glyphs::Range(std::string fontstack, - std::string range, - std::vector chars) -{ - mapnik_fontnik::freetype_engine font_engine_; - mapnik_fontnik::face_manager_freetype font_manager(font_engine_); - - mapnik_fontnik::font_set font_set(fontstack); - std::stringstream stream(fontstack); - std::string face_name; - - // TODO: better to split on delim and font_names_.reserve() then add? - while (std::getline(stream, face_name, ',')) { - font_set.add_face_name(Trim(face_name, " \t")); - } - - mapnik_fontnik::face_set_ptr face_set; - - // This may throw. - face_set = font_manager.get_face_set(font_set); - - llmr::glyphs::fontstack *mutable_fontstack = glyphs.add_stacks(); - mutable_fontstack->set_name(fontstack); - mutable_fontstack->set_range(range); - - const double scale_factor = 1.0; - - // Set character sizes. - double size = 24 * scale_factor; - face_set->set_character_sizes(size); - - for (std::vector::size_type i = 0; i != chars.size(); i++) { - FT_ULong char_code = chars[i]; - mapnik_fontnik::glyph_info glyph; - - for (auto const& face : *face_set) { - // Get FreeType face from face_ptr. - FT_Face ft_face = face->get_face(); - FT_UInt char_index = FT_Get_Char_Index(ft_face, char_code); - - // Try next font in fontset. - if (!char_index) continue; - - glyph.glyph_index = char_index; - face->RenderSDF(glyph, 24, 3, 0.25); - - // Add glyph to fontstack. - llmr::glyphs::glyph *mutable_glyph = mutable_fontstack->add_glyphs(); - mutable_glyph->set_id(char_code); - mutable_glyph->set_width(glyph.width); - mutable_glyph->set_height(glyph.height); - mutable_glyph->set_left(glyph.left); - mutable_glyph->set_top(glyph.top - glyph.ascender); - mutable_glyph->set_advance(glyph.advance); - - if (glyph.width > 0) { - mutable_glyph->set_bitmap(glyph.bitmap); - } - - // Glyph added, continue to next char_code. - break; - } - } -} - -std::vector Glyphs::Codepoints(std::string fontstack) -{ - std::vector points; - mapnik_fontnik::freetype_engine font_engine_; - mapnik_fontnik::face_manager_freetype font_manager(font_engine_); - - mapnik_fontnik::font_set font_set(fontstack); - std::stringstream stream(fontstack); - std::string face_name; - - while (std::getline(stream, face_name, ',')) { - font_set.add_face_name(Trim(face_name, " \t")); - } - - mapnik_fontnik::face_set_ptr face_set; - - // This may throw. - face_set = font_manager.get_face_set(font_set); - for (auto const& face : *face_set) { - FT_Face ft_face = face->get_face(); - FT_ULong charcode; - FT_UInt gindex; - charcode = FT_Get_First_Char(ft_face, &gindex); - while (gindex != 0) { - charcode = FT_Get_Next_Char(ft_face, charcode, &gindex); - if (charcode != 0) points.push_back(charcode); - } - } - - // for font sets, eliminate duplicates of codepoints - // that are shared. - std::sort(points.begin(), points.end()); - auto last = std::unique(points.begin(), points.end()); - points.erase(last, points.end()); - - return points; -} - -std::string Glyphs::Trim(std::string str, std::string whitespace) -{ - const auto strBegin = str.find_first_not_of(whitespace); - - if (strBegin == std::string::npos) { - return ""; - } - - const auto strEnd = str.find_last_not_of(whitespace); - const auto strRange = strEnd - strBegin + 1; - - return str.substr(strBegin, strRange); -} - -} // ns fontnik diff --git a/vendor/mapnik/COPYING b/vendor/mapnik/COPYING deleted file mode 100644 index e5ab03e12..000000000 --- a/vendor/mapnik/COPYING +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/vendor/mapnik/README.fontserver b/vendor/mapnik/README.fontserver deleted file mode 100644 index 59680e7fe..000000000 --- a/vendor/mapnik/README.fontserver +++ /dev/null @@ -1,25 +0,0 @@ -Name: mapnik -URL: https://github.com/mapnik/mapnik -Version: 3.x -License: LGPL 2.1 -Description: Mapnik is an open source toolkit for developing mapping applications -Local Modifications: -- font_engine_freetype.hpp - - Assume MAPNIK_THREADSAFE - - Remove FT_Stroker -- text/face_set.hpp - - Split out font_face_set class from face.hpp - - Replace mapnik::face_ptr with fontnik::face_ptr -- text/glyph_info.hpp - - Store signed distance field in std::string bitmap - - Add left, top, width, height, advance, ascender and descender metrics - - Set metrics directly rather than calculating from unscaled values - - Add operator< overload for sorting -- font_engine_freetype.cpp - - More verbose error logging - - Assume MAPNIK_THREADSAFE and MAPNIK_LOG - - Replace mapnik::face_ptr with fontnik::face_ptr - - Remove FT_Stroker -- text/face_set.cpp - - Split out font_face_set class from face.cpp - - Replace mapnik::face_ptr with fontnik::face_ptr diff --git a/vendor/mapnik/include/mapnik/config.hpp b/vendor/mapnik/include/mapnik/config.hpp deleted file mode 100644 index 6e4fe6858..000000000 --- a/vendor/mapnik/include/mapnik/config.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2011 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_CONFIG_HPP -#define MAPNIK_CONFIG_HPP - -// Windows DLL support - -#ifdef _WINDOWS -# define MAPNIK_EXP __declspec (dllexport) -# define MAPNIK_IMP __declspec (dllimport) -# ifdef MAPNIK_EXPORTS -# define MAPNIK_DECL __declspec (dllexport) -# else -# define MAPNIK_DECL __declspec (dllimport) -# endif -# pragma warning( disable: 4251 ) -# pragma warning( disable: 4275 ) -# if (_MSC_VER >= 1400) // vc8 -# pragma warning(disable : 4996) //_CRT_SECURE_NO_DEPRECATE -# endif -#else -# if __GNUC__ >= 4 -# define MAPNIK_EXP __attribute__ ((visibility ("default"))) -# define MAPNIK_DECL __attribute__ ((visibility ("default"))) -# define MAPNIK_IMP __attribute__ ((visibility ("default"))) -# else -# define MAPNIK_EXP -# define MAPNIK_DECL -# define MAPNIK_IMP -# endif -#endif - -#define PROJ_ENVELOPE_POINTS 20 - -#endif // MAPNIK_CONFIG_HPP diff --git a/vendor/mapnik/include/mapnik/debug.hpp b/vendor/mapnik/include/mapnik/debug.hpp deleted file mode 100644 index 41223366e..000000000 --- a/vendor/mapnik/include/mapnik/debug.hpp +++ /dev/null @@ -1,330 +0,0 @@ -/***************************************************************************** - * - * This file is part of Mapnik (c++ mapping toolkit) - * - * Copyright (C) 2011 Artem Pavlenko - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ - -#ifndef MAPNIK_DEBUG_HPP -#define MAPNIK_DEBUG_HPP - -// mapnik (should not depend on anything that need to use this) -#include -#include -#include -#include - -// std -#include -#include -#include -#include -#include -#include -#ifdef MAPNIK_THREADSAFE -#include -#endif - -namespace mapnik_fontnik { - - /* - Global logger class that holds the configuration of severity, format - and file/console redirection. - */ - class MAPNIK_DECL logger : - public singleton, - private mapnik_fontnik::noncopyable - { - public: - enum severity_type - { - debug = 0, - warn = 1, - error = 2, - none = 3 - }; - - using severity_map = std::unordered_map; - - // global security level - static severity_type get_severity() - { - return severity_level_; - } - - static void set_severity(severity_type const& severity_level) - { -#ifdef MAPNIK_THREADSAFE - mapnik_fontnik::scoped_lock lock(severity_mutex_); -#endif - - severity_level_ = severity_level; - } - - // per object security levels - static severity_type get_object_severity(std::string const& object_name) - { - severity_map::iterator it = object_severity_level_.find(object_name); - if (object_name.empty() || it == object_severity_level_.end()) - { - return severity_level_; - } - else - { - return it->second; - } - } - - static void set_object_severity(std::string const& object_name, - severity_type const& security_level) - { -#ifdef MAPNIK_THREADSAFE - mapnik_fontnik::scoped_lock lock(severity_mutex_); -#endif - if (! object_name.empty()) - { - object_severity_level_[object_name] = security_level; - } - } - - static void clear_object_severity() - { -#ifdef MAPNIK_THREADSAFE - mapnik_fontnik::scoped_lock lock(severity_mutex_); -#endif - - object_severity_level_.clear(); - } - - // format - static std::string get_format() - { - return format_; - } - - static void set_format(std::string const& format) - { -#ifdef MAPNIK_THREADSAFE - mapnik_fontnik::scoped_lock lock(format_mutex_); -#endif - format_ = format; - } - - // interpolate the format string for output - static std::string str(); - - // output - static void use_file(std::string const& filepath); - static void use_console(); - - private: - static severity_type severity_level_; - static severity_map object_severity_level_; - static bool severity_env_check_; - - static std::string format_; - static bool format_env_check_; - - static std::ofstream file_output_; - static std::string file_name_; - static std::streambuf* saved_buf_; - -#ifdef MAPNIK_THREADSAFE - static std::mutex severity_mutex_; - static std::mutex format_mutex_; -#endif - }; - - - namespace detail { - - /* - Default sink, it regulates access to clog - */ - template - class clog_sink - { - public: - using stream_buffer = std::basic_ostringstream; - - void operator()(logger::severity_type const& /*severity*/, stream_buffer const& s) - { -#ifdef MAPNIK_THREADSAFE - static std::mutex mutex; - mapnik_fontnik::scoped_lock lock(mutex); -#endif - std::clog << logger::str() << " " << s.str() << std::endl; - } - }; - - - /* - Base log class, should not log anything when no MAPNIK_LOG is defined - - This is used for debug/warn reporting that should not output - anything when not compiling for speed. - */ - template