How to use the mapnik.fonts function in mapnik

To help you get started, we’ve selected a few mapnik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapbox / mapbox-studio-classic / lib / tm.js View on Github external
tm.font = function(name, text, fontdir, callback) {
    tm.fonts = tm.fonts || mapnik.fonts();
    if (tm.fonts.indexOf(name) === -1 && fontdir === undefined) return callback(new Error('Invalid font ' + name));

    // Attempt to retrieve from cache.
    var xml = tm.templates.xrayfont({fontdir: fontdir, name:name, text:text||name});

    var ckey = 'font-' + crypto.createHash('md5').update(xml).digest('hex').substr(0,8) + '.png';
    var file = path.join(tm.config().cache,ckey);
    fs.readFile(file, function(err, buffer) {
        if (err && err.code !== 'ENOENT') return callback(err);
        if (buffer) {
            buffer.hit = true;
            return callback(null, buffer);
        }

        var map = new mapnik.Map(500,60);
        map.extent = [-180,-10,180,10];
github tilemill-project / tilemill / shared / models.js View on Github external
validateAsync: function(attributes, options) {
        // If client-side, pass-through.
        if (typeof require === 'undefined') {
            return options.success(this, null);
        }

        var carto = require('carto'),
            mapnik = require('mapnik'),
            that = this,
            stylesheets = this.get('Stylesheet'),
            env = {
                returnErrors: true,
                errors: [],
                validation_data: {
                    fonts: mapnik.fonts()
                },
                deferred_externals: [],
                only_validate: true,
                effects: []
            };

        // Hard clone the model JSON before rendering as rendering will change
        // properties (e.g. localize a datasource URL to the filesystem).
        var data = JSON.parse(JSON.stringify(attributes));
        new carto.Renderer(env)
            .render(data, function(err, output) {
            if (err) {
                options.error(that, err);
            } else {
                options.success(that, null);
            }
github mapbox / mapbox-studio-classic / lib / tm.js View on Github external
tm.fontfamilies = function() {
    if (tm._fontfamilies) return tm._fontfamilies;

    var fonts = require('mapnik').fonts();
    fonts.sort();

    // Overrides are custom exceptions -- regexes for known font family
    // names that cannot otherwise be autodetected.
    var overrides = {
        'Call': /^Call (One|Two|Three|Four|Five|Six|Seven|Eight|Nine)/,
        'Komika': /^Komika (Hand|Parch|Title)/
    };
    // Keywords are ordered by "display priority" -- e.g. fonts
    // containing earlier words should be favored for being a preview
    // of the family as a whole.
    var keywords = [
        'medium',
        'normal',
        'regular',
        'book',
github tilemill-project / tilemill / shared / models.js View on Github external
validateAsync: function(options) {
        // If client-side, pass-through.
        if (typeof require === 'undefined') {
            return options.success(this, null);
        }

        var carto = require('carto'),
            mapnik = require('mapnik'),
            that = this,
            stylesheets = this.get('Stylesheet'),
            env = {
                returnErrors: true,
                errors: [],
                validation_data: {
                    fonts: mapnik.fonts()
                },
                deferred_externals: [],
                only_validate: true,
                effects: []
            };

        // Hard clone the model JSON before rendering as rendering will change
        // properties (e.g. localize a datasource URL to the filesystem).
        var data = JSON.parse(JSON.stringify(this.toJSON()));
        new carto.Renderer(env)
            .render(data, function(err, output) {
            if (err) {
                options.error(that, err);
            } else {
                options.success(that, null);
            }
github mapbox / mapbox-studio-default-fonts / bin / generate-font-families.js View on Github external
function getFontFamilies() {
    const fonts = mapnik.fonts();
    fonts.sort();
    let level1 = {};
    for (let i = 0; i < fonts.length; i++) {
        let parts = fonts[i].split(' ');
        while (parts.length) {
            let word = parts[parts.length - 1];
            if (keywords.indexOf(word.toLowerCase()) === -1) break;
            parts.pop();
        }
        let family = parts.join(' ');
        level1[family] = level1[family] || [];
        level1[family].push(fonts[i]);
    }
    let level2 = {};
    for (let fam in level1) {
        if (level1[fam].length > 1) continue;
github mapbox / tilelive / lib / tilelive / map.js View on Github external
function(err, data) {
            if (err) return this(err);
            if (that.language === 'carto') {
                var renderer = new carto.Renderer({
                    data_dir: that.mapfile_dir,
                    optimization: false,
                    validation_data: { fonts: mapnik.fonts() }
                });
                renderer.render(data, this);
            } else {
                this(null, data);
            }
        },
        function(err, compiled) {
github mapbox / tilelive-mapnik / lib / map.js View on Github external
function(err, data) {
            if (err) throw err;
            if (that.language === 'carto') {
                var renderer = new carto.Renderer({
                    alias: true,
                    data_dir: that.data_dir,
                    local_data_dir: that.local_data_dir,
                    validation_data: { fonts: mapnik.fonts() }
                });
                renderer.render(data, this);
            } else {
                this(null, data);
            }
        },
        callback
github mapbox / mapbox-studio-classic / index.js View on Github external
app.get('/:style(style):history()', function(req, res, next) {
    res.set({'content-type':'text/html'});
    try {
        var page = tm.templates.style({
            cwd: process.env.HOME,
            fontsRef: require('mapnik').fonts(),
            cartoRef: require('carto').tree.Reference.data,
            sources: [req.style._backend._source.data],
            style: req.style.data,
            history: req.history
        })
    } catch(err) {
        return next(new Error('style template: ' + err.message));
    }
    return res.send(page);
});