optional<std::string> parseProperty(const char* name, const JSValue& value) {
    if (std::string { "text-font" } == name) {
        if (!value.IsArray()) {
            Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name);
            return {};
        }

        std::string result = "";
        for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
            const JSValue& stop = value[i];
            if (stop.IsString()) {
                result += stop.GetString();
                if (i < value.Size()-1) {
                    result += ",";
                }
            } else {
                Log::Warning(Event::ParseStyle, "text-font members must be strings");
                return {};
            }
        }
        return result;
    }

    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    return std::string { value.GetString(), value.GetStringLength() };
}
optional<RotateAnchorType> parseProperty<RotateAnchorType>(const char* name, const JSValue& value) {
    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    return { RotateAnchorTypeClass({ value.GetString(), value.GetStringLength() }) };
}
optional<std::string> parseConstant(const char* name, const JSValue& value) {
    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    return std::string { value.GetString(), value.GetStringLength() };
}
예제 #4
0
optional<LineCapType> parseConstant<LineCapType>(const char* name, const JSValue& value) {
    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    return { LineCapTypeClass({ value.GetString(), value.GetStringLength() }) };
}
optional<Color> parseProperty(const char* name, const JSValue& value) {
    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    CSSColorParser::Color css_color = CSSColorParser::parse({ value.GetString(), value.GetStringLength() });

    // Premultiply the color.
    const float factor = css_color.a / 255;

    return Color{{(float)css_color.r * factor,
                  (float)css_color.g * factor,
                  (float)css_color.b * factor,
                  css_color.a}};
}