diff --git a/src/FontDescriptor.h b/src/FontDescriptor.h index 270d53e..e4f11ae 100644 --- a/src/FontDescriptor.h +++ b/src/FontDescriptor.h @@ -1,14 +1,12 @@ #ifndef FONT_DESCRIPTOR_H #define FONT_DESCRIPTOR_H + #include -#include -#include +#include #include #include #include -using namespace v8; - enum FontWeight { FontWeightUndefined = 0, FontWeightThin = 100, @@ -46,15 +44,15 @@ struct FontDescriptor { bool italic; bool monospace; - FontDescriptor(Local obj) { - path = NULL; - postscriptName = getString(obj, "postscriptName"); - family = getString(obj, "family"); - style = getString(obj, "style"); - weight = (FontWeight) getNumber(obj, "weight"); - width = (FontWidth) getNumber(obj, "width"); - italic = getBool(obj, "italic"); - monospace = getBool(obj, "monospace"); + FontDescriptor(napi_env env, napi_value obj) { + path = nullptr; + postscriptName = getString(env, obj, "postscriptName"); + family = getString(env, obj, "family"); + style = getString(env, obj, "style"); + weight = static_cast(getNumber(env, obj, "weight")); + width = static_cast(getNumber(env, obj, "width")); + italic = getBool(env, obj, "italic"); + monospace = getBool(env, obj, "monospace"); } FontDescriptor() { @@ -109,71 +107,97 @@ struct FontDescriptor { style = NULL; } - Local toJSObject() { - Nan::EscapableHandleScope scope; - Local res = Nan::New(); + napi_value toJSObject(napi_env env) { + napi_value res; + napi_create_object(env, &res); if (path) { - Nan::Set(res, Nan::New("path").ToLocalChecked(), Nan::New(path).ToLocalChecked()); + napi_value pathValue; + napi_create_string_utf8(env, path, NAPI_AUTO_LENGTH, &pathValue); + napi_set_named_property(env, res, "path", pathValue); } - + if (postscriptName) { - Nan::Set(res, Nan::New("postscriptName").ToLocalChecked(), Nan::New(postscriptName).ToLocalChecked()); + napi_value psNameValue; + napi_create_string_utf8(env, postscriptName, NAPI_AUTO_LENGTH, &psNameValue); + napi_set_named_property(env, res, "postscriptName", psNameValue); } - + if (family) { - Nan::Set(res, Nan::New("family").ToLocalChecked(), Nan::New(family).ToLocalChecked()); + napi_value familyValue; + napi_create_string_utf8(env, family, NAPI_AUTO_LENGTH, &familyValue); + napi_set_named_property(env, res, "family", familyValue); } - + if (style) { - Nan::Set(res, Nan::New("style").ToLocalChecked(), Nan::New(style).ToLocalChecked()); + napi_value styleValue; + napi_create_string_utf8(env, style, NAPI_AUTO_LENGTH, &styleValue); + napi_set_named_property(env, res, "style", styleValue); } - - Nan::Set(res, Nan::New("weight").ToLocalChecked(), Nan::New(weight)); - Nan::Set(res, Nan::New("width").ToLocalChecked(), Nan::New(width)); - Nan::Set(res, Nan::New("italic").ToLocalChecked(), Nan::New(italic)); - Nan::Set(res, Nan::New("monospace").ToLocalChecked(), Nan::New(monospace)); - return scope.Escape(res); + + napi_value weightValue; + napi_create_int32(env, weight, &weightValue); + napi_set_named_property(env, res, "weight", weightValue); + + napi_value widthValue; + napi_create_int32(env, width, &widthValue); + napi_set_named_property(env, res, "width", widthValue); + + napi_value italicValue; + napi_get_boolean(env, italic, &italicValue); + napi_set_named_property(env, res, "italic", italicValue); + + napi_value monospaceValue; + napi_get_boolean(env, monospace, &monospaceValue); + napi_set_named_property(env, res, "monospace", monospaceValue); + + return res; } private: char *copyString(const char *input) { - if (!input) - return NULL; - + if (!input) return nullptr; char *str = new char[strlen(input) + 1]; strcpy(str, input); return str; } - char *getString(Local obj, const char *name) { - Nan::HandleScope scope; - MaybeLocal value = Nan::Get(obj, Nan::New(name).ToLocalChecked()); + char *getString(napi_env env, napi_value obj, const char *name) { + napi_value value; + napi_status status = napi_get_named_property(env, obj, name, &value); - if (!value.IsEmpty() && value.ToLocalChecked()->IsString()) { - return copyString(*Nan::Utf8String(value.ToLocalChecked())); + if (status == napi_ok) { + size_t strLength; + napi_get_value_string_utf8(env, value, nullptr, 0, &strLength); + char *str = new char[strLength + 1]; + napi_get_value_string_utf8(env, value, str, strLength + 1, nullptr); + return str; } - return NULL; + return nullptr; } - int getNumber(Local obj, const char *name) { - Nan::HandleScope scope; - MaybeLocal value = Nan::Get(obj, Nan::New(name).ToLocalChecked()); + int getNumber(napi_env env, napi_value obj, const char *name) { + napi_value value; + napi_status status = napi_get_named_property(env, obj, name, &value); - if (!value.IsEmpty() && value.ToLocalChecked()->IsNumber()) { - return value.ToLocalChecked()->Int32Value(Nan::GetCurrentContext()).FromJust(); + if (status == napi_ok) { + int32_t result; + napi_get_value_int32(env, value, &result); + return result; } return 0; } - bool getBool(Local obj, const char *name) { - Nan::HandleScope scope; - MaybeLocal value = Nan::Get(obj, Nan::New(name).ToLocalChecked()); + bool getBool(napi_env env, napi_value obj, const char *name) { + napi_value value; + napi_status status = napi_get_named_property(env, obj, name, &value); - if (!value.IsEmpty() && value.ToLocalChecked()->IsBoolean()) { - return value.ToLocalChecked()->BooleanValue(Nan::GetCurrentContext()).FromJust(); + if (status == napi_ok) { + bool result; + napi_get_value_bool(env, value, &result); + return result; } return false; diff --git a/src/FontManager.cc b/src/FontManager.cc index 9472b06..bfd216d 100644 --- a/src/FontManager.cc +++ b/src/FontManager.cc @@ -1,45 +1,43 @@ #include -#include +#include #include -#include -#include #include "FontDescriptor.h" -using namespace v8; - -// these functions are implemented by the platform -ResultSet *getAvailableFonts(); -ResultSet *findFonts(FontDescriptor *); -FontDescriptor *findFont(FontDescriptor *); -FontDescriptor *substituteFont(char *, char *); +// Platform-specific function declarations +ResultSet* getAvailableFontsImpl(); +ResultSet* findFontsImpl(FontDescriptor*); +FontDescriptor* findFontImpl(FontDescriptor*); +FontDescriptor* substituteFontImpl(char*, char*); // converts a ResultSet to a JavaScript array -Local collectResults(ResultSet *results) { - Nan::EscapableHandleScope scope; - Local res = Nan::New(results->size()); - - int i = 0; - for (ResultSet::iterator it = results->begin(); it != results->end(); it++) { - Nan::Set(res, i++, (*it)->toJSObject()); - } - - delete results; - return scope.Escape(res); +napi_value collectResults(napi_env env, ResultSet* results) { + napi_value resultArray; + napi_create_array_with_length(env, results->size(), &resultArray); + + int i = 0; + for (ResultSet::iterator it = results->begin(); it != results->end(); ++it) { + napi_value jsObject = (*it)->toJSObject(env); + napi_set_element(env, resultArray, i++, jsObject); + } + + delete results; + return resultArray; } -// converts a FontDescriptor to a JavaScript object -Local wrapResult(FontDescriptor *result) { - Nan::EscapableHandleScope scope; - if (result == NULL) - return scope.Escape(Nan::Null()); - - Local res = result->toJSObject(); - delete result; - return scope.Escape(res); +// Helper: Converts a FontDescriptor to a JavaScript object +napi_value wrapResult(napi_env env, FontDescriptor* result) { + if (result == nullptr) { + napi_value nullValue; + napi_get_null(env, &nullValue); + return nullValue; + } + + napi_value jsObject = result->toJSObject(env); + delete result; + return jsObject; } -// holds data about an operation that will be -// performed on a background thread +// Async request structure for passing data struct AsyncRequest { uv_work_t work; FontDescriptor *desc; // used by findFont and findFonts @@ -47,18 +45,19 @@ struct AsyncRequest { char *substitutionString; // ditto FontDescriptor *result; // for functions with a single result ResultSet *results; // for functions with multiple results - Nan::Callback *callback; // the actual JS callback to call when we are done - - AsyncRequest(Local v) { - work.data = (void *)this; - callback = new Nan::Callback(v.As()); - desc = NULL; - postscriptName = NULL; - substitutionString = NULL; - result = NULL; - results = NULL; - } - + napi_ref callback; // the actual JS callback to call when we are done + napi_env env = nullptr; + + AsyncRequest(napi_ref callback_ref) { + work.data = (void *)this; + callback = callback_ref; + desc = nullptr; + postscriptName = nullptr; + substitutionString = nullptr; + result = nullptr; + results = nullptr; + } + ~AsyncRequest() { delete callback; @@ -77,148 +76,275 @@ struct AsyncRequest { // calls the JavaScript callback for a request void asyncCallback(uv_work_t *work) { - Nan::HandleScope scope; AsyncRequest *req = (AsyncRequest *) work->data; - Nan::AsyncResource async("asyncCallback"); - Local info[1]; + napi_value resource_name; + napi_create_string_utf8(req->env, "asyncCallback", NAPI_AUTO_LENGTH, &resource_name); + + napi_async_context async_context; + napi_async_init(req->env, nullptr, resource_name, &async_context); + napi_value argv[1]; if (req->results) { - info[0] = collectResults(req->results); + argv[0] = collectResults(req->env, req->results); } else if (req->result) { - info[0] = wrapResult(req->result); + argv[0] = wrapResult(req->env, req->result); } else { - info[0] = Nan::Null(); + napi_get_null(req->env, &argv[0]); } - req->callback->Call(1, info, &async); + napi_value global; + napi_get_global(req->env, &global); + + napi_value callback; + napi_get_reference_value(req->env, req->callback, &callback); + napi_make_callback(req->env, async_context, global, callback, 1, argv, nullptr); + napi_async_destroy(req->env, async_context); + delete req; } void getAvailableFontsAsync(uv_work_t *work) { AsyncRequest *req = (AsyncRequest *) work->data; - req->results = getAvailableFonts(); + req->results = getAvailableFontsImpl(); } + template -NAN_METHOD(getAvailableFonts) { +napi_value getAvailableFonts(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value argv[1]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (async) { - if (info.Length() < 1 || !info[0]->IsFunction()) - return Nan::ThrowTypeError("Expected a callback"); - - AsyncRequest *req = new AsyncRequest(info[0]); + napi_valuetype type; + napi_typeof(env, argv[0], &type); + if (type != napi_function) { + napi_throw_type_error(env, nullptr, "Expected a callback"); + return nullptr; + } + napi_ref callback_ref; + napi_create_reference(env, argv[0], 1, &callback_ref); + AsyncRequest* req = new AsyncRequest(callback_ref); + req->env = env; uv_queue_work(uv_default_loop(), &req->work, getAvailableFontsAsync, (uv_after_work_cb) asyncCallback); - return; + return nullptr; } else { - info.GetReturnValue().Set(collectResults(getAvailableFonts())); + return collectResults(env, getAvailableFontsImpl()); } } - void findFontsAsync(uv_work_t *work) { AsyncRequest *req = (AsyncRequest *) work->data; - req->results = findFonts(req->desc); + req->results = findFontsImpl(req->desc); } template -NAN_METHOD(findFonts) { - if (info.Length() < 1 || !info[0]->IsObject() || info[0]->IsFunction()) - return Nan::ThrowTypeError("Expected a font descriptor"); +napi_value findFonts(napi_env env, napi_callback_info info) { + size_t argc = 2; + napi_value argv[2]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + if (argc < 1) { + napi_throw_type_error(env, nullptr, "Expected a font descriptor"); + return nullptr; + } - Local desc = info[0].As(); - FontDescriptor *descriptor = new FontDescriptor(desc); + FontDescriptor* descriptor = new FontDescriptor(env, argv[0]); if (async) { - if (info.Length() < 2 || !info[1]->IsFunction()) - return Nan::ThrowTypeError("Expected a callback"); - - AsyncRequest *req = new AsyncRequest(info[1]); + napi_valuetype type; + napi_typeof(env, argv[1], &type); + if (argc < 2 || type != napi_function) { + napi_throw_type_error(env, nullptr, "Expected a callback"); + delete descriptor; + return nullptr; + } + napi_ref callback_ref; + napi_create_reference(env, argv[1], 1, &callback_ref); + AsyncRequest* req = new AsyncRequest(callback_ref); req->desc = descriptor; + req->env = env; uv_queue_work(uv_default_loop(), &req->work, findFontsAsync, (uv_after_work_cb) asyncCallback); - - return; + return nullptr; } else { - Local res = collectResults(findFonts(descriptor)); + napi_value result = collectResults(env, findFontsImpl(descriptor)); delete descriptor; - info.GetReturnValue().Set(res); + return result; } } - void findFontAsync(uv_work_t *work) { AsyncRequest *req = (AsyncRequest *) work->data; - req->result = findFont(req->desc); + req->result = findFontImpl(req->desc); } -template -NAN_METHOD(findFont) { - if (info.Length() < 1 || !info[0]->IsObject() || info[0]->IsFunction()) - return Nan::ThrowTypeError("Expected a font descriptor"); - - Local desc = info[0].As(); - FontDescriptor *descriptor = new FontDescriptor(desc); +template +napi_value findFont(napi_env env, napi_callback_info info) { + size_t argc = 2; + napi_value argv[2]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + napi_valuetype type; + napi_typeof(env, argv[0], &type); + if (type != napi_object || type == napi_function) { + napi_throw_type_error(env, nullptr, "Expected a font descriptor"); + return nullptr; + } + FontDescriptor* descriptor = new FontDescriptor(env, argv[0]); if (async) { - if (info.Length() < 2 || !info[1]->IsFunction()) - return Nan::ThrowTypeError("Expected a callback"); - - AsyncRequest *req = new AsyncRequest(info[1]); + napi_typeof(env, argv[1], &type); + if (type != napi_function) { + napi_throw_type_error(env, nullptr, "Expected a callback"); + return nullptr; + } + napi_ref callback_ref; + napi_create_reference(env, argv[1], 1, &callback_ref); + AsyncRequest* req = new AsyncRequest(callback_ref); + req->env = env; req->desc = descriptor; uv_queue_work(uv_default_loop(), &req->work, findFontAsync, (uv_after_work_cb) asyncCallback); - - return; + return nullptr; } else { - Local res = wrapResult(findFont(descriptor)); + napi_value result = wrapResult(env, findFontImpl(descriptor)); delete descriptor; - info.GetReturnValue().Set(res); + return result; } } void substituteFontAsync(uv_work_t *work) { AsyncRequest *req = (AsyncRequest *) work->data; - req->result = substituteFont(req->postscriptName, req->substitutionString); + req->result = substituteFontImpl(req->postscriptName, req->substitutionString); } template -NAN_METHOD(substituteFont) { - if (info.Length() < 1 || !info[0]->IsString()) - return Nan::ThrowTypeError("Expected postscript name"); - - if (info.Length() < 2 || !info[1]->IsString()) - return Nan::ThrowTypeError("Expected substitution string"); +napi_value substituteFont(napi_env env, napi_callback_info info) { + size_t argc = 3; + napi_value argv[3]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // Validate the first argument (postscriptName) + napi_valuetype type; + size_t postscript_len; + napi_typeof(env, argv[0], &type); + if (argc < 1 || napi_string) { + napi_throw_type_error(env, nullptr, "Expected postscript name"); + return nullptr; + } + napi_get_value_string_utf8(env, argv[0], nullptr, 0, &postscript_len); - Nan::Utf8String postscriptName(info[0]); - Nan::Utf8String substitutionString(info[1]); + size_t substitution_len; + napi_typeof(env, argv[1], &type); + if (argc < 2 || type != napi_string) { + napi_throw_type_error(env, nullptr, "Expected substitution string"); + return nullptr; + } + napi_get_value_string_utf8(env, argv[1], nullptr, 0, &substitution_len); if (async) { - if (info.Length() < 3 || !info[2]->IsFunction()) - return Nan::ThrowTypeError("Expected a callback"); - - // copy the strings since the JS garbage collector might run before the async request is finished - char *ps = new char[postscriptName.length() + 1]; - strcpy(ps, *postscriptName); + + napi_typeof(env, argv[2], &type); + if (argc < 3 || type != napi_function) { + napi_throw_type_error(env, nullptr, "Expected a callback"); + return nullptr; + } + // Allocate memory and copy the strings + char* postscriptName = new char[postscript_len + 1]; + napi_get_value_string_utf8(env, argv[0], postscriptName, postscript_len + 1, nullptr); + + char* substitutionString = new char[substitution_len + 1]; + napi_get_value_string_utf8(env, argv[1], substitutionString, substitution_len + 1, nullptr); + + // Create an async request + napi_ref callback_ref; + napi_create_reference(env, argv[2], 1, &callback_ref); + AsyncRequest* req = new AsyncRequest(callback_ref); + req->postscriptName = postscriptName; + req->substitutionString = substitutionString; + req->env = env; + uv_queue_work(uv_default_loop(), &req->work, substituteFontAsync, (uv_after_work_cb) asyncCallback); + + // Return undefined for async case + napi_value undefined; + napi_get_undefined(env, &undefined); + return nullptr; + } else { + // Synchronous execution + char* postscriptName = new char[postscript_len + 1]; + napi_get_value_string_utf8(env, argv[0], postscriptName, postscript_len + 1, nullptr); - char *sub = new char[substitutionString.length() + 1]; - strcpy(sub, *substitutionString); + char* substitutionString = new char[substitution_len + 1]; + napi_get_value_string_utf8(env, argv[1], substitutionString, substitution_len + 1, nullptr); - AsyncRequest *req = new AsyncRequest(info[2]); - req->postscriptName = ps; - req->substitutionString = sub; - uv_queue_work(uv_default_loop(), &req->work, substituteFontAsync, (uv_after_work_cb) asyncCallback); + delete[] postscriptName; + delete[] substitutionString; - return; - } else { - info.GetReturnValue().Set(wrapResult(substituteFont(*postscriptName, *substitutionString))); + return wrapResult(env, substituteFontImpl(postscriptName, substitutionString)); } } -NAN_MODULE_INIT(Init) { - Nan::Export(target, "getAvailableFonts", getAvailableFonts); - Nan::Export(target, "getAvailableFontsSync", getAvailableFonts); - Nan::Export(target, "findFonts", findFonts); - Nan::Export(target, "findFontsSync", findFonts); - Nan::Export(target, "findFont", findFont); - Nan::Export(target, "findFontSync", findFont); - Nan::Export(target, "substituteFont", substituteFont); - Nan::Export(target, "substituteFontSync", substituteFont); +// Remaining functions (similar pattern) ... + +// Module Initialization +napi_value Init(napi_env env, napi_value exports) { + napi_status status; + + // Add "getAvailableFonts" function + napi_value getAvailableFontsFunction; + status = napi_create_function(env, nullptr, 0, getAvailableFonts, nullptr, &getAvailableFontsFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "getAvailableFonts", getAvailableFontsFunction); + if (status != napi_ok) return nullptr; + + // Add "getAvailableFontsSync" function + napi_value getAvailableFontsSyncFunction; + status = napi_create_function(env, nullptr, 0, getAvailableFonts, nullptr, &getAvailableFontsSyncFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "getAvailableFontsSync", getAvailableFontsSyncFunction); + if (status != napi_ok) return nullptr; + + // Add "findFonts" function + napi_value findFontsFunction; + status = napi_create_function(env, nullptr, 0, findFonts, nullptr, &findFontsFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "findFonts", findFontsFunction); + if (status != napi_ok) return nullptr; + + // Add "findFontsSync" function + napi_value findFontsSyncFunction; + status = napi_create_function(env, nullptr, 0, findFonts, nullptr, &findFontsSyncFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "findFontsSync", findFontsSyncFunction); + if (status != napi_ok) return nullptr; + + // Add "findFont" function + napi_value findFontFunction; + status = napi_create_function(env, nullptr, 0, findFont, nullptr, &findFontFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "findFont", findFontFunction); + if (status != napi_ok) return nullptr; + + // Add "findFontSync" function + napi_value findFontSyncFunction; + status = napi_create_function(env, nullptr, 0, findFont, nullptr, &findFontSyncFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "findFontSync", findFontSyncFunction); + if (status != napi_ok) return nullptr; + + // Add "substituteFont" function + napi_value substituteFontFunction; + status = napi_create_function(env, nullptr, 0, substituteFont, nullptr, &substituteFontFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "substituteFont", substituteFontFunction); + if (status != napi_ok) return nullptr; + + // Add "substituteFontSync" function + napi_value substituteFontSyncFunction; + status = napi_create_function(env, nullptr, 0, substituteFont, nullptr, &substituteFontSyncFunction); + if (status != napi_ok) return nullptr; + status = napi_set_named_property(env, exports, "substituteFontSync", substituteFontSyncFunction); + if (status != napi_ok) return nullptr; + + return exports; } -NODE_MODULE(fontmanager, Init) + +NAPI_MODULE(fontmanager, Init) diff --git a/src/FontManagerLinux.cc b/src/FontManagerLinux.cc index 67dbcb9..1998456 100644 --- a/src/FontManagerLinux.cc +++ b/src/FontManagerLinux.cc @@ -139,7 +139,7 @@ ResultSet *getResultSet(FcFontSet *fs) { return res; } -ResultSet *getAvailableFonts() { +ResultSet *getAvailableFontsImpl() { FcInit(); FcPattern *pattern = FcPatternCreate(); @@ -183,7 +183,7 @@ FcPattern *createPattern(FontDescriptor *desc) { return pattern; } -ResultSet *findFonts(FontDescriptor *desc) { +ResultSet *findFontsImpl((FontDescriptor *desc) { FcPattern *pattern = createPattern(desc); FcObjectSet *os = FcObjectSetBuild(FC_FILE, FC_POSTSCRIPT_NAME, FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_WIDTH, FC_SLANT, FC_SPACING, NULL); FcFontSet *fs = FcFontList(NULL, pattern, os); @@ -196,7 +196,7 @@ ResultSet *findFonts(FontDescriptor *desc) { return res; } -FontDescriptor *findFont(FontDescriptor *desc) { +FontDescriptor *findFontImpl(FontDescriptor *desc) { FcPattern *pattern = createPattern(desc); FcConfigSubstitute(NULL, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); @@ -211,7 +211,7 @@ FontDescriptor *findFont(FontDescriptor *desc) { return res; } -FontDescriptor *substituteFont(char *postscriptName, char *string) { +FontDescriptor *substituteFontImpl((char *postscriptName, char *string) { FcInit(); // create a pattern with the postscript name diff --git a/src/FontManagerMac.mm b/src/FontManagerMac.mm index a9d5666..d20f5e8 100644 --- a/src/FontManagerMac.mm +++ b/src/FontManagerMac.mm @@ -68,7 +68,7 @@ static int convertWidth(float unit) { return res; } -ResultSet *getAvailableFonts() { +ResultSet *getAvailableFontsImpl() { // cache font collection for fast use in future calls static CTFontCollectionRef collection = NULL; if (collection == NULL) @@ -155,7 +155,7 @@ int metricForMatch(CTFontDescriptorRef match, FontDescriptor *desc) { return metric; } -ResultSet *findFonts(FontDescriptor *desc) { +ResultSet *findFontsImpl(FontDescriptor *desc) { CTFontDescriptorRef descriptor = getFontDescriptor(desc); NSArray *matches = (NSArray *) CTFontDescriptorCreateMatchingFontDescriptors(descriptor, NULL); ResultSet *results = new ResultSet(); @@ -201,7 +201,7 @@ CTFontDescriptorRef findBest(FontDescriptor *desc, NSArray *matches) { return best; } -FontDescriptor *findFont(FontDescriptor *desc) { +FontDescriptor *findFontImpl(FontDescriptor *desc) { FontDescriptor *res = NULL; CTFontDescriptorRef descriptor = getFontDescriptor(desc); NSArray *matches = (NSArray *) CTFontDescriptorCreateMatchingFontDescriptors(descriptor, NULL); @@ -226,7 +226,7 @@ CTFontDescriptorRef findBest(FontDescriptor *desc, NSArray *matches) { return res; } -FontDescriptor *substituteFont(char *postscriptName, char *string) { +FontDescriptor *substituteFontImpl(char *postscriptName, char *string) { FontDescriptor *res = NULL; // create a font descriptor to find the font by its postscript name diff --git a/src/FontManagerWindows.cc b/src/FontManagerWindows.cc index 0ccd14a..61c516d 100644 --- a/src/FontManagerWindows.cc +++ b/src/FontManagerWindows.cc @@ -159,7 +159,7 @@ FontDescriptor *resultFromFont(IDWriteFont *font) { return res; } -ResultSet *getAvailableFonts() { +ResultSet *getAvailableFontsImpl() { ResultSet *res = new ResultSet(); int count = 0; @@ -233,8 +233,8 @@ bool resultMatches(FontDescriptor *result, FontDescriptor *desc) { return true; } -ResultSet *findFonts(FontDescriptor *desc) { - ResultSet *fonts = getAvailableFonts(); +ResultSet *findFontsImpl(FontDescriptor *desc) { + ResultSet *fonts = getAvailableFontsImpl(); for (ResultSet::iterator it = fonts->begin(); it != fonts->end();) { if (!resultMatches(*it, desc)) { @@ -248,8 +248,8 @@ ResultSet *findFonts(FontDescriptor *desc) { return fonts; } -FontDescriptor *findFont(FontDescriptor *desc) { - ResultSet *fonts = findFonts(desc); +FontDescriptor *findFontImpl(FontDescriptor *desc) { + ResultSet *fonts = findFontsImpl(desc); // if we didn't find anything, try again with only the font traits, no string names if (fonts->size() == 0) { @@ -260,14 +260,14 @@ FontDescriptor *findFont(FontDescriptor *desc) { desc->weight, desc->width, desc->italic, false ); - fonts = findFonts(fallback); + fonts = findFontsImpl(fallback); } // ok, nothing. shouldn't happen often. // just return the first available font if (fonts->size() == 0) { delete fonts; - fonts = getAvailableFonts(); + fonts = getAvailableFontsImpl(); } // hopefully we found something now. @@ -399,7 +399,7 @@ class FontFallbackRenderer : public IDWriteTextRenderer { } }; -FontDescriptor *substituteFont(char *postscriptName, char *string) { +FontDescriptor *substituteFontImpl(char *postscriptName, char *string) { FontDescriptor *res = NULL; IDWriteFactory *factory = NULL; @@ -416,7 +416,7 @@ FontDescriptor *substituteFont(char *postscriptName, char *string) { // find the font for the given postscript name FontDescriptor *desc = new FontDescriptor(); desc->postscriptName = postscriptName; - FontDescriptor *font = findFont(desc); + FontDescriptor *font = findFontImpl(desc); // create a text format object for this font IDWriteTextFormat *format = NULL;