#include "formatted.hpp" #include "formatted_section.hpp" namespace mbgl { namespace android { void Formatted::registerNative(jni::JNIEnv& env) { jni::Class::Singleton(env); } jni::Local> Formatted::New(jni::JNIEnv& env, const style::expression::Formatted& value) { static auto& formatted = jni::Class::Singleton(env); static auto formattedConstructor = formatted.GetConstructor>>(env); static auto& formattedSection = jni::Class::Singleton(env); auto sections = jni::Array>::New(env, value.sections.size()); for (std::size_t i = 0; i < value.sections.size(); i++) { auto section = value.sections.at(i); auto text = jni::Make(env, section.text); double fontScale = 1.0; if (section.fontScale) { fontScale = section.fontScale.value(); } if (section.fontStack) { auto fontStack = jni::Array::New(env, section.fontStack.value().size()); for (std::size_t j = 0; j < section.fontStack.value().size(); j++) { fontStack.Set(env, j, jni::Make(env, section.fontStack.value().at(j))); } static auto formattedSectionConstructor = formattedSection.GetConstructor>(env); sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text, fontScale, fontStack)); } else { static auto formattedSectionConstructor = formattedSection.GetConstructor(env); sections.Set(env, i, formattedSection.New(env, formattedSectionConstructor, text, fontScale)); } } return formatted.New(env, formattedConstructor, sections); } } // namespace android } // namespace mbgl