Esempio n. 1
0
void char_properties::from_xml(xml_node const& node, fontset_map const& fontsets)
{
    optional<double> text_size_ = node.get_opt_attr<double>("size");
    if (text_size_) text_size = *text_size_;
    optional<double> character_spacing_ = node.get_opt_attr<double>("character-spacing");
    if (character_spacing_) character_spacing = *character_spacing_;
    optional<color> fill_ = node.get_opt_attr<color>("fill");
    if (fill_) fill = *fill_;
    optional<color> halo_fill_ = node.get_opt_attr<color>("halo-fill");
    if (halo_fill_) halo_fill = *halo_fill_;
    optional<double> halo_radius_ = node.get_opt_attr<double>("halo-radius");
    if (halo_radius_) halo_radius = *halo_radius_;
    optional<text_transform_e> tconvert_ = node.get_opt_attr<text_transform_e>("text-transform");
    if (tconvert_) text_transform = *tconvert_;
    optional<double> line_spacing_ = node.get_opt_attr<double>("line-spacing");
    if (line_spacing_) line_spacing = *line_spacing_;
    optional<double> opacity_ = node.get_opt_attr<double>("opacity");
    if (opacity_) text_opacity = *opacity_;
    optional<double> halo_opacity_ = node.get_opt_attr<double>("halo-opacity");
    if (halo_opacity_) halo_opacity = *halo_opacity_;
    optional<std::string> wrap_char_ = node.get_opt_attr<std::string>("wrap-character");
    if (wrap_char_ && (*wrap_char_).size() > 0) wrap_char = ((*wrap_char_)[0]);
    optional<std::string> face_name_ = node.get_opt_attr<std::string>("face-name");
    if (face_name_)
    {
        face_name = *face_name_;
    }
    optional<std::string> fontset_name_ = node.get_opt_attr<std::string>("fontset-name");
    if (fontset_name_) {
        std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
        if (itr != fontsets.end())
        {
            fontset = itr->second;
        }
        else
        {
            throw config_error("Unable to find any fontset named '" + *fontset_name_ + "'", node);
        }
    }
    if (!face_name.empty() && fontset)
    {
        throw config_error("Can't have both face-name and fontset-name", node);
    }
    if (face_name.empty() && !fontset)
    {
        throw config_error("Must have face-name or fontset-name", node);
    }
}
Esempio n. 2
0
void format_properties::from_xml(xml_node const& node, fontset_map const& fontsets, bool is_shield)
{
    set_property_from_xml<double>(text_size, "size", node);
    set_property_from_xml<double>(character_spacing, "character-spacing", node);
    set_property_from_xml<double>(line_spacing, "line-spacing", node);
    set_property_from_xml<double>(halo_radius, "halo-radius", node);
    // https://github.com/mapnik/mapnik/issues/2507
    if (is_shield)
    {
        set_property_from_xml<double>(text_opacity, "text-opacity", node);
    }
    else
    {
        set_property_from_xml<double>(text_opacity, "opacity", node);
    }
    set_property_from_xml<double>(halo_opacity, "halo-opacity", node);
    set_property_from_xml<color>(fill, "fill", node);
    set_property_from_xml<color>(halo_fill, "halo-fill", node);
    set_property_from_xml<text_transform_e>(text_transform,"text-transform", node);
    set_property_from_xml<font_feature_settings>(ff_settings, "font-feature-settings", node);

    optional<std::string> face_name_ = node.get_opt_attr<std::string>("face-name");
    if (face_name_) face_name = *face_name_;
    optional<std::string> fontset_name_ = node.get_opt_attr<std::string>("fontset-name");
    if (fontset_name_)
    {
        std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name_);
        if (itr != fontsets.end())
        {
            fontset = itr->second;
        }
        else
        {
            throw config_error("Unable to find any fontset named '" + *fontset_name_ + "'", node);
        }
    }
    if (!face_name.empty() && fontset)
    {
        throw config_error("Can't have both face-name and fontset-name", node);
    }
    if (face_name.empty() && !fontset)
    {
        throw config_error("Must have face-name or fontset-name", node);
    }
}
Esempio n. 3
0
node_ptr format_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
{
    auto n = std::make_shared<format_node>();
    node_ptr child = node::from_xml(xml,fontsets);
    n->set_child(child);

    set_property_from_xml<double>(n->text_size, "size", xml);
    set_property_from_xml<double>(n->character_spacing, "character-spacing", xml);
    set_property_from_xml<double>(n->line_spacing, "line-spacing", xml);
    set_property_from_xml<double>(n->text_opacity, "opacity", xml);
    //set_property_from_xml<double>(n->halo_opacity, "halo-opacity", xml); FIXME
    set_property_from_xml<double>(n->halo_radius, "halo-radius", xml);
    set_property_from_xml<color>(n->fill, "fill", xml);
    set_property_from_xml<color>(n->halo_fill, "halo-fill", xml);
    set_property_from_xml<text_transform_e>(n->text_transform, "text-transform", xml);
    set_property_from_xml<font_feature_settings>(n->ff_settings, "font-feature-settings", xml);

    boost::optional<std::string> face_name = xml.get_opt_attr<std::string>("face-name");
    if (face_name)
    {
        n->face_name = *face_name;
    }
    boost::optional<std::string> fontset_name = xml.get_opt_attr<std::string>("fontset-name");
    if (fontset_name)
    {
        std::map<std::string,font_set>::const_iterator itr = fontsets.find(*fontset_name);
        if (itr != fontsets.end())
        {
            n->fontset = itr->second;
        }
        else
        {
            throw config_error("Unable to find any fontset named '" + *fontset_name + "' for <Format> node", xml);
        }
    }
    if (face_name && !face_name->empty() && n->fontset)
    {
        throw config_error("Can't have both face-name and fontset-name", xml);
    }
    return n;
}