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() };
}
optional<TextAnchorType> parseProperty<TextAnchorType>(const char* name, const JSValue& value) {
    if (!value.IsString()) {
        Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
        return {};
    }

    return { TextAnchorTypeClass({ value.GetString(), value.GetStringLength() }) };
}
Пример #3
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}};
}