Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node_mapnik namespace for header only code, and move fonts and plugin…
…s to own compilation united
- Loading branch information
Dane Springmeyer
committed
Jun 14, 2011
1 parent
2e69d87
commit ca19ae4
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#ifndef __NODE_MAPNIK_FONTS_H__ | ||
#define __NODE_MAPNIK_FONTS_H__ | ||
|
||
|
||
// v8 | ||
#include <v8.h> | ||
|
||
// node | ||
#include <node.h> | ||
|
||
// mapnik | ||
#include <mapnik/font_engine_freetype.hpp> | ||
|
||
// stl | ||
#include <vector> | ||
|
||
#include "utils.hpp" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
namespace node_mapnik { | ||
|
||
static inline Handle<Value> register_fonts(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
|
||
if (!args.Length() >= 1 || !args[0]->IsString()) | ||
return ThrowException(Exception::TypeError( | ||
String::New("first argument must be a path to a directory of fonts"))); | ||
|
||
bool found = false; | ||
|
||
std::vector<std::string> const names_before = mapnik::freetype_engine::face_names(); | ||
|
||
// option hash | ||
if (args.Length() == 2){ | ||
if (!args[1]->IsObject()) | ||
return ThrowException(Exception::TypeError( | ||
String::New("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }"))); | ||
|
||
Local<Object> options = args[1]->ToObject(); | ||
if (options->Has(String::New("recurse"))) | ||
{ | ||
Local<Value> recurse_opt = options->Get(String::New("recurse")); | ||
if (!recurse_opt->IsBoolean()) | ||
return ThrowException(Exception::TypeError( | ||
String::New("'recurse' must be a Boolean"))); | ||
|
||
bool recurse = recurse_opt->BooleanValue(); | ||
std::string const& path = TOSTR(args[0]); | ||
found = mapnik::freetype_engine::register_fonts(path,recurse); | ||
} | ||
} | ||
else | ||
{ | ||
std::string const& path = TOSTR(args[0]); | ||
found = mapnik::freetype_engine::register_fonts(path); | ||
} | ||
|
||
std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names(); | ||
if (names_after.size() == names_before.size()) | ||
found = false; | ||
|
||
return scope.Close(Boolean::New(found)); | ||
} | ||
|
||
static inline Handle<Value> available_font_faces(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
std::vector<std::string> const& names = mapnik::freetype_engine::face_names(); | ||
Local<Array> a = Array::New(names.size()); | ||
for (unsigned i = 0; i < names.size(); ++i) | ||
{ | ||
a->Set(i, String::New(names[i].c_str())); | ||
} | ||
return scope.Close(a); | ||
} | ||
|
||
} | ||
|
||
#endif // __NODE_MAPNIK_FONTS_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifndef __NODE_MAPNIK_PLUGINS_H__ | ||
#define __NODE_MAPNIK_PLUGINS_H__ | ||
|
||
|
||
// v8 | ||
#include <v8.h> | ||
|
||
// node | ||
#include <node.h> | ||
|
||
/* dlopen(), dlsym() */ | ||
#include <dlfcn.h> | ||
|
||
// mapnik | ||
#include <mapnik/datasource_cache.hpp> | ||
|
||
// stl | ||
#include <vector> | ||
|
||
#include "utils.hpp" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
namespace node_mapnik { | ||
|
||
static inline Handle<Value> make_mapnik_symbols_visible(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
if (args.Length() != 1 || !args[0]->IsString()) | ||
return ThrowException(Exception::TypeError( | ||
String::New("first argument must be a path to a directory holding _mapnik.node"))); | ||
String::Utf8Value filename(args[0]->ToString()); | ||
void *handle = dlopen(*filename, RTLD_NOW|RTLD_GLOBAL); | ||
if (handle == NULL) { | ||
return False(); | ||
} | ||
else | ||
{ | ||
dlclose(handle); | ||
return True(); | ||
} | ||
} | ||
|
||
static inline Handle<Value> available_input_plugins(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
std::vector<std::string> const& names = mapnik::datasource_cache::plugin_names(); | ||
Local<Array> a = Array::New(names.size()); | ||
for (unsigned i = 0; i < names.size(); ++i) | ||
{ | ||
a->Set(i, String::New(names[i].c_str())); | ||
} | ||
return scope.Close(a); | ||
} | ||
|
||
|
||
static inline Handle<Value> register_datasources(const Arguments& args) | ||
{ | ||
HandleScope scope; | ||
if (args.Length() != 1 || !args[0]->IsString()) | ||
return ThrowException(Exception::TypeError( | ||
String::New("first argument must be a path to a directory of mapnik input plugins"))); | ||
|
||
std::vector<std::string> const names_before = mapnik::datasource_cache::plugin_names(); | ||
std::string const& path = TOSTR(args[0]); | ||
mapnik::datasource_cache::instance()->register_datasources(path); | ||
std::vector<std::string> const& names_after = mapnik::datasource_cache::plugin_names(); | ||
if (names_after.size() > names_before.size()) | ||
return scope.Close(Boolean::New(true)); | ||
return scope.Close(Boolean::New(false)); | ||
} | ||
|
||
|
||
} | ||
|
||
#endif // __NODE_MAPNIK_PLUGINS_H__ |