From 3171e698c313b84843aa2f10dd0ac404c55db871 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 24 Nov 2011 18:37:12 +0300 Subject: [PATCH] Remove old code for binary drawing rules processing. Add primary, secondary caption styles getting. --- generator/classif_routine.cpp | 103 -- generator/classif_routine.hpp | 9 - generator/generator.pro | 2 - generator/generator_tool/generator_tool.cpp | 16 +- generator/osm2type.cpp | 399 +----- generator/osm2type.hpp | 2 - indexer/classificator.cpp | 4 +- indexer/classificator_loader.cpp | 8 +- indexer/drawing_rule_def.hpp | 2 - indexer/drawing_rules.cpp | 1367 +------------------ indexer/drawing_rules.hpp | 77 +- map/draw_processor.cpp | 6 +- map/drawer_yg.cpp | 160 +-- map/drawer_yg.hpp | 4 +- map/map.pro | 13 +- map/proto_to_yg_styles.cpp | 88 ++ map/proto_to_yg_styles.hpp | 21 + 17 files changed, 211 insertions(+), 2070 deletions(-) delete mode 100644 generator/classif_routine.cpp delete mode 100644 generator/classif_routine.hpp create mode 100644 map/proto_to_yg_styles.cpp create mode 100644 map/proto_to_yg_styles.hpp diff --git a/generator/classif_routine.cpp b/generator/classif_routine.cpp deleted file mode 100644 index db765038f9..0000000000 --- a/generator/classif_routine.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "classif_routine.hpp" -#include "osm2type.hpp" - -#include "../indexer/classificator.hpp" -#include "../indexer/drawing_rules.hpp" -#include "../indexer/scales.hpp" - -#include "../platform/platform.hpp" - -#include "../coding/file_reader_stream.hpp" - -#include "../base/logging.hpp" - - -namespace classificator -{ - void parse_osm_types(int start, int end, string const & path) - { - for (int i = start; i <= end; ++i) - { - char buf[5] = { 0 }; - sprintf(buf, "%d", i); - - string const inFile = path + buf + ".xml"; - ftype::ParseOSMTypes(inFile.c_str(), i); - } - } - - /* - class DoFindSymbol - { - string m_name; - public: - DoFindSymbol(string const & name) : m_name(name) {} - - void operator() (int s, int t, int i, drule::BaseRule const * p) - { - if (s == 17 && t == drule::symbol) - { - string name; - p->GetSymbol(name); - if (name == m_name) - { - LOG(LINFO, ("Found rule with index = ", i)); - } - } - } - }; - */ - - void GenerateAndWrite(string const & path) - { - using namespace drule; - - // Experimental - add drawing rules in program. - -// // 1. Read rules. -// string const name = "drawing_rules.bin"; -// ReaderPtrStream rulesS(GetPlatform().GetReader(name)); -// ReadRules(rulesS); - -// // 2. Find spesial rule. -// //rules().ForEachRule(DoFindSymbol("supermarket")); - -// // 3. Append rules. -// //int const color = 0; -// int const color = 0xB5D6F1; -// //double const pixWidth = 1.5; -// for (int i = 0; i <= scales::GetUpperScale(); ++i) -// { -// //size_t const ind = rules().AddLineRule(i, color, pixWidth); -// size_t const ind = rules().AddAreaRule(i, color); -// LOG_SHORT(LINFO, ("Scale = ", i, "; Index = ", ind)); -// } -// //size_t const ind = rules().AddSymbolRule(17, "supermarket"); -// //LOG_SHORT(LINFO, ("Index = ", ind)); - -// // 4. Write rules. -// WriteRules((path + name).c_str()); -// // 5. Exit. -// return; - - // 1. generic types - parse_osm_types(0, 11, path + "styles/caption-z"); - parse_osm_types(6, 17, path + "styles/osm-map-features-z"); - - // 2. POI (not used) - //parse_osm_types(12, 17, path + "styles/osm-POI-features-z"); - - // 3. generate map - string const inFile = path + "styles/mapswithme.xml"; - for (int i = 0; i <= 17; ++i) - ftype::ParseOSMTypes(inFile.c_str(), i); - - drule::WriteRules(string(path + "drawing_rules.bin")); - classif().PrintClassificator(string(path + "classificator.txt").c_str()); - } - - void PrepareForFeatureGeneration() - { - classif().SortClassificator(); - } -} diff --git a/generator/classif_routine.hpp b/generator/classif_routine.hpp deleted file mode 100644 index 0dc158a783..0000000000 --- a/generator/classif_routine.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "../std/string.hpp" - -namespace classificator -{ - void GenerateAndWrite(string const & dir); - void PrepareForFeatureGeneration(); -} diff --git a/generator/generator.pro b/generator/generator.pro index de31ebbe8d..aa65d5dd8b 100644 --- a/generator/generator.pro +++ b/generator/generator.pro @@ -20,7 +20,6 @@ SOURCES += \ update_generator.cpp \ statistics.cpp \ osm2type.cpp \ - classif_routine.cpp \ borders_generator.cpp \ osm_xml_parser.cpp \ borders_loader.cpp \ @@ -46,7 +45,6 @@ HEADERS += \ polygonizer.hpp \ world_map_generator.hpp \ osm2type.hpp \ - classif_routine.hpp \ borders_generator.hpp \ osm_xml_parser.hpp \ borders_loader.hpp \ diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 28962f1f1f..843a800d59 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -4,14 +4,12 @@ #include "../update_generator.hpp" #include "../borders_generator.hpp" #include "../borders_loader.hpp" -#include "../classif_routine.hpp" #include "../dumper.hpp" #include "../statistics.hpp" #include "../unpack_mwm.hpp" #include "../generate_info.hpp" #include "../../indexer/classificator_loader.hpp" -#include "../../indexer/drawing_rules.hpp" #include "../../indexer/data_header.hpp" #include "../../indexer/features_vector.hpp" #include "../../indexer/index_builder.hpp" @@ -96,18 +94,6 @@ int main(int argc, char ** argv) // Make a classificator if (FLAGS_generate_classif) { - //classificator::GenerateAndWrite(path); - - /// This is temporary code for rules dumping. - //@{ - classificator::Load(); - - string buffer; - drule::ConvertToProtocolBuffers(buffer); - - FileWriter w(path + "drules_proto.txt"); - w.Write(buffer.c_str(), buffer.size()); - //@} } // Generating intermediate files @@ -127,7 +113,7 @@ int main(int argc, char ** argv) FLAGS_calc_statistics || FLAGS_dump_types || FLAGS_dump_prefixes) { classificator::Load(); - classificator::PrepareForFeatureGeneration(); + classif().SortClassificator(); } // Generate dat file diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index abf43e8e70..0b06319454 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -2,26 +2,19 @@ #include "xml_element.hpp" #include "../indexer/classificator.hpp" -#include "../indexer/drawing_rules.hpp" #include "../indexer/feature_visibility.hpp" -#include "../coding/parse_xml.hpp" -#include "../coding/file_reader.hpp" - #include "../base/assert.hpp" #include "../base/string_utils.hpp" #include "../base/math.hpp" -#include "../std/fstream.hpp" -#include "../std/bind.hpp" #include "../std/vector.hpp" -#include "../std/set.hpp" -#include "../std/algorithm.hpp" #include -namespace ftype { +namespace ftype +{ namespace { /// get value of mark (1 == "yes", -1 == "no", 0 == not a "yes\no") @@ -46,394 +39,6 @@ namespace ftype { return 0; } - class OSMTypesStream - { - /// @name processing elements definitions - //@{ - struct element_t - { - element_t() : pObj(0) {} - - string name; - map attr; - - ClassifObject * pObj; - }; - - vector m_elements; - element_t & current() { return m_elements.back(); } - - int m_priority; - //@} - - /// check if element is a draw rule (commonly it's a leaf in xml) - static bool is_draw_rule(string const & e) - { - static char const * rules[] = { "line", "tunnel", "area", "symbol", "caption", "text", - "circle", "pathText", "wayMarker" }; - return strings::IsInArray(rules, e); - } - - uint8_t get_rule_type() - { - int count = static_cast(m_elements.size()) - 2; - ASSERT ( count >= 0, (count) ); - - string e; - while (e.empty() && count >= 0) - { - e = m_elements[count].attr["e"]; - --count; - } - ASSERT ( !e.empty(), () ); - - strings::SimpleTokenizer it(e, "|"); - uint8_t ret = 0; - while (it) - { - string const & s = *it; - if (s == "node") - ret |= drule::node; - else if (s == "way") - ret |= drule::way; - ++it; - } - - ASSERT ( ret != 0, () ); - return static_cast(ret); - } - - /// check if it's our element to parse - static bool is_our_element(string const & e) - { - static char const * elems[] = { "rules", "rule", "else", "layer", - // addclass appear in small scales (6-11) - // don't skip it during parsing, but we don't process it like a rule - "addclass" }; - return (strings::IsInArray(elems, e) || is_draw_rule(e)); - } - - /// check if it's processing key - static bool is_valid_key(string const & k) - { - static char const * bad[] = { "osmarender:render", "osmarender:rendername", - "osmarender:renderref", "addr:housenumber" }; - return (!k.empty() && !strings::IsInArray(bad, k)); - } - - static bool is_valid_value(string const & v) - { - return !v.empty(); - } - - /// check if key is a 'mark' - static bool is_mark_key(string const & k) - { - static char const * mark[] = { "bridge", "tunnel", "area", "lock", "oneway", "junction", - "embankment", "cutting", "motorroad", "cycleway", - "bicycle", "horse", "capital", "fee" }; - return strings::IsInArray(mark, k); - } - - static bool process_feature_like_mark_from_root(string const & /*k*/, string const & v) - { - static char const * mark[] = { "turning_circle", "dyke", "dike", "levee", "embankment" }; - return strings::IsInArray(mark, v); - } - - static bool process_feature_like_mark(string const & k, string const & v) - { - return (k == "highway" && (v == "construction" || v == "disused")); - } - - /// check if skip whole element by it's key - static bool is_skip_element_by_key(string const & k) - { - static char const * skip[] = { "addr:housenumber", "fixme" }; - return strings::IsInArray(skip, k); - } - - /// skip element and all it's sub-elements - bool m_forceSkip; - - public: - OSMTypesStream() : m_priority(0), m_forceSkip(false) {} - - void CharData(string const &) {} - bool Push(string const & name) - { - if (!m_forceSkip && is_our_element(name)) - { - m_elements.push_back(element_t()); - current().name = name; - return true; - } - - return false; - } - - public: - void AddAttr(string name, string value) - { - // make lower case for equivalent string comparison - strings::MakeLowerCase(name); - strings::MakeLowerCase(value); - - if ((name == "k") && is_skip_element_by_key(value)) - m_forceSkip = true; - else - current().attr[name] = value; - } - - ClassifObject * get_root() { return classif().GetMutableRoot(); } - - void Pop(string const & /*element*/) - { - if (!m_forceSkip) - add_type_recursive(get_root(), 0, vector()); - else - m_forceSkip = false; - - m_elements.pop_back(); - } - - private: - vector make_concat(vector const & v, int intV, string const & s) - { - if (intV == 1) - { - vector vv; - vv.reserve(v.size() + 1); - bool inserted = false; - for (size_t i = 0; i < v.size(); ++i) - { - if (!(v[i] < s) && !inserted) - { - inserted = true; - vv.push_back(s); - } - vv.push_back(v[i]); - } - if (!inserted) vv.push_back(s); - - return vv; - } - else return v; - } - - /// get parent of object (p) in created chain of elements - ClassifObject * get_parent_of(size_t i, ClassifObject * p) - { - ASSERT ( i > 0, () ); - while (--i > 0) - if (m_elements[i].pObj == p) break; - - ASSERT ( i > 0, () ); - while (--i > 0) - if (m_elements[i].pObj) - return m_elements[i].pObj; - - return get_root(); - } - - void clear_states(size_t start) - { - for (size_t i = start; i < m_elements.size(); ++i) - m_elements[i].pObj = 0; - } - - void add_type_recursive(ClassifObject * pParent, - size_t start, - std::vector const & marks) - { - for (size_t i = start; i < m_elements.size(); ++i) - { - element_t & e = m_elements[i]; - - if (e.pObj) continue; - - if (e.name == "rule") - { - // process rule - string k = e.attr["k"]; - if (!is_valid_key(k)) continue; - - string v = e.attr["v"]; - if (!is_valid_value(v)) continue; - - strings::SimpleTokenizer iK(k, "|"); - if (iK.IsLast()) - { - // process one key - ASSERT ( *iK == k, () ); - - int intV = get_mark_value(k, v); - if (is_mark_key(k) && (intV != 0)) - { - // key is a mark, so save it and go futher - add_type_recursive(pParent, i + 1, make_concat(marks, intV, k)); - clear_states(i); - } - else - { - // buildings assume as feature type - bool lets_try = (k == "building" && intV == 1); - - // default access is yes. If "no" - make additional feature type - if (!lets_try && (k == "access" && intV == -1)) - { - lets_try = true; - intV = 0; - v = "no-access"; - } - - if (!lets_try && intV != 0) - { - // skip this keys, because they are dummy - continue; - } - else - { - // add root or criterion - if (pParent == get_root()) - { - pParent = pParent->Add(k); - e.pObj = pParent; - - // use m_elements[1] to hold first parent of futher creation objects - // need for correct working "get_parent_of" function - m_elements[1].pObj = pParent; - } - else - { - // avoid recursion like this: - // - // - // - // - ClassifObject * ppParent = get_parent_of(i, pParent); - if (k != ppParent->GetName()) - { - // do not set criterion like base object - if (k != pParent->GetName() && - !process_feature_like_mark(pParent->GetName(), k)) - pParent->AddCriterion(k); - } - else - pParent = ppParent; - } - - // process values - strings::SimpleTokenizer iV(v, "|"); - while (iV) - { - bool const b1 = process_feature_like_mark_from_root(k, *iV); - if (b1 || process_feature_like_mark(k, *iV)) - { - // process value like mark, so save it and go futher - add_type_recursive( - b1 ? get_root() : pParent, i + 1, make_concat(marks, 1, *iV)); - clear_states(i); - } - else - { - ClassifObject * p = pParent; - if (intV == 0) - p = pParent->Add(*iV); - e.pObj = p; - - add_type_recursive(p, i + 1, marks); - clear_states(i); - } - - ++iV; - } - } - } - } - else - { - char const * aTry[] = { "natural", "landuse" }; - - while (iK) - { - // let's try to add root keys - bool addMode = (pParent == get_root() && strings::IsInArray(aTry, *iK)); - - ClassifObject * p = (addMode ? pParent->Add(*iK) : pParent->Find(*iK)); - if (p && (get_mark_value(*iK, v) == 0)) - { - if (p->IsCriterion()) p = pParent; - - strings::SimpleTokenizer iV(v, "|"); - while (iV) - { - ClassifObject * pp = (addMode ? p->Add(*iV) : p->Find(*iV)); - if (pp) - { - e.pObj = pp; - - add_type_recursive(pp, i + 1, marks); - clear_states(i); - } - ++iV; - } - } - ++iK; - } - } - - return; // processed to the end - exit - } - else if (is_draw_rule(e.name)) - { - ASSERT ( i == m_elements.size()-1, ("drawing rules should be leavs") ); - - // process draw rule - if (pParent != get_root()) - { - if (!marks.empty()) - { - // make final mark string - string res; - for (size_t i = 0; i < marks.size(); ++i) - { - if (!res.empty()) res += '-'; - res += marks[i]; - } - - pParent = pParent->Add(res); - } - - vector keys; - drule::rules().CreateRules(e.name, get_rule_type(), e.attr, keys); - - // if no "layer" tag, then atoi returns 0 - it's ok for us - // 1000 - is a base count of rules for layer - int const layer = atoi(e.attr["layer"].c_str()) * drule::layer_base_priority; - for (size_t i = 0; i < keys.size(); ++i) - keys[i].SetPriority(layer + m_priority++); - - for_each(keys.begin(), keys.end(), bind(&ClassifObject::AddDrawRule, pParent, _1)); - } - } - } - } - }; - } - - void ParseOSMTypes(char const * fPath, int scale) - { - drule::rules().SetParseFile(fPath, scale); - - FileReader reader(fPath); - ReaderSource source(reader); - OSMTypesStream stream; - ParseXML(source, stream); - } - - namespace - { bool is_skip_tag(string const & k) { // skip "cycleway's" tags because they interfer to set a valid types like "highway's" diff --git a/generator/osm2type.hpp b/generator/osm2type.hpp index 0e6b77a225..1653a31321 100644 --- a/generator/osm2type.hpp +++ b/generator/osm2type.hpp @@ -7,8 +7,6 @@ struct XMLElement; namespace ftype { - void ParseOSMTypes(char const * fPath, int scale); - /// Get the types, name and layer for feature with the tree of tags. bool GetNameAndType(XMLElement * p, FeatureParams & params); } diff --git a/indexer/classificator.cpp b/indexer/classificator.cpp index b7ff913e43..47c1f03068 100644 --- a/indexer/classificator.cpp +++ b/indexer/classificator.cpp @@ -81,9 +81,7 @@ void ClassifObject::LoadPolicy::Serialize(string const & s) drule::Key key; key.fromString(s); -#ifndef USE_PROTO_STYLES - p->m_drawRule.push_back(key); -#endif + //p->m_drawRule.push_back(key); // mark as visible in rule's scale p->m_visibility[key.m_scale] = true; diff --git a/indexer/classificator_loader.cpp b/indexer/classificator_loader.cpp index f463b8ba08..bec3a794fc 100644 --- a/indexer/classificator_loader.cpp +++ b/indexer/classificator_loader.cpp @@ -52,15 +52,11 @@ namespace classificator p.GetReader("types.txt")); //LOG(LINFO, ("Reading of drawing rules")); -#ifdef USE_PROTO_STYLES + // Load from protobuffer text file. string buffer; ReaderType(p.GetReader("drules_proto.txt")).ReadAsString(buffer); - drule::rules().LoadFromProto(buffer); -#else - ReaderPtrStream rulesS(p.GetReader("drawing_rules.bin")); - drule::ReadRules(rulesS); -#endif + drule::rules().LoadFromTextProto(buffer); LOG(LINFO, ("Reading of classificator finished")); } diff --git a/indexer/drawing_rule_def.hpp b/indexer/drawing_rule_def.hpp index 1bd1571502..385320e2f8 100644 --- a/indexer/drawing_rule_def.hpp +++ b/indexer/drawing_rule_def.hpp @@ -4,8 +4,6 @@ #include "../std/vector.hpp" -#define USE_PROTO_STYLES 1 - namespace drule { class Key diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp index 0e3e535df7..6d6b29b43e 100644 --- a/indexer/drawing_rules.cpp +++ b/indexer/drawing_rules.cpp @@ -5,20 +5,7 @@ #include "classificator.hpp" #include "drules_struct.pb.h" -#include "../coding/file_writer_stream.hpp" -#include "../coding/file_reader_stream.hpp" - -#include "../base/std_serialization.hpp" -#include "../base/assert.hpp" -#include "../base/macros.hpp" -#include "../base/string_utils.hpp" - #include "../std/bind.hpp" -#include "../std/algorithm.hpp" -#include "../std/tuple.hpp" -#include "../std/fstream.hpp" -#include "../std/exception.hpp" -#include "../std/limits.hpp" #include "../std/iterator_facade.hpp" #include @@ -26,710 +13,6 @@ namespace drule { - unsigned char alpha_opacity(double d) - { - ASSERT ( d >= 0.0 && d <= 1.0, (d) ); - return static_cast(255 * d); - } - - /// @name convertors for standart types - //@{ - template T get_value(string const & s); - - template <> bool get_value(string const & s) - { - return (s == "yes" || s == "1"); - } - template <> double get_value(string const & s) - { - double d; - VERIFY ( strings::to_double(s, d), ("Bad double in drawing rule : ", s) ); - return d; - } - template <> string get_value(string const & s) - { - string ss(s); - strings::MakeLowerCase(ss); - return ss; - } - //@} - - /// parameters tuple initialization - //@{ - class assign_element - { - AttrsMapType const & m_attrs; - string * m_keys; - - public: - assign_element(AttrsMapType const & attrs, string * keys) : m_attrs(attrs), m_keys(keys) {} - - template void operator() (T & t, int n) - { - AttrsMapType::const_iterator i = m_attrs.find(m_keys[n]); - if (i != m_attrs.end()) - t = get_value(i->second); - } - }; - - template - void parse_tuple(Tuple & t, AttrsMapType const & attrs, string (&keys)[N]) - { - STATIC_ASSERT ( N == tuple_length::value ); - assign_element toDo(attrs, keys); - for_each_tuple(t, toDo); - } - //@} - - /// main function for rule creation - template T * create_rule(AttrsMapType const & attrs) - { - T * p = new T(); - parse_tuple(p->m_params, attrs, T::arrKeys); - return p; - } - - /// compare rules - template bool is_equal_rules(T const * p1, BaseRule const * p2) - { - T const * pp2 = dynamic_cast(p2); - if (pp2) - return (p1->IsEqualBase(p2) && (p1->m_params == pp2->m_params)); - return false; - } - - template void write_rules(TArchive & ar, T const * p) - { - p->WriteBase(ar); - serial::save_tuple(ar, p->m_params); - } - template void read_rules(TArchive & ar, T * p) - { - p->ReadBase(ar); - serial::load_tuple(ar, p->m_params); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // px_metric_t - //////////////////////////////////////////////////////////////////////////////////////// - struct px_metric_t - { - double m_v; - px_metric_t(double v = 0.0) : m_v(v) {} - bool operator==(px_metric_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, px_metric_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, px_metric_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> px_metric_t get_value(string const & s) - { - size_t i = s.find("px"); - if (i == string::npos) - i = s.size(); - - return px_metric_t(atof(s.substr(0, i).c_str())); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // color_t - //////////////////////////////////////////////////////////////////////////////////////// - struct color_t - { - int32_t m_v; - enum XXX { none = -1 }; - - color_t(int32_t v = 0) : m_v(v) {} - bool operator==(color_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, color_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, color_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> color_t get_value(string const & s) - { - int v = 0; - if (s[0] == '#') - { - char * dummy; - v = strtol(&s[1], &dummy, 16); - } - else if (s == "none") v = color_t::none; - else if (s == "black") { /*already initialized*/ } - else if (s == "white") v = 0xFFFFFF; - else if (s == "red") v = 0xFF0000; - else if (s == "green") v = 0x00FF00; - else if (s == "blue") v = 0x0000FF; - else if (s == "lightblue") v = 0xADD8E6; - else if (s == "yellow") v = 0xFFFF00; - else - { - ASSERT ( !"check color values", (s) ); - } - return v; - } - - //////////////////////////////////////////////////////////////////////////////////////// - // dash_array_t - //////////////////////////////////////////////////////////////////////////////////////// - struct dash_array_t - { - vector m_v; - void add(string const & s) - { - double const v = atof(s.c_str()); - if (v != 0.0) m_v.push_back(v); - } - - bool operator==(dash_array_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, dash_array_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, dash_array_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> dash_array_t get_value(string const & s) - { - dash_array_t ret; - strings::Tokenize(s, " \tpx,", bind(&dash_array_t::add, ref(ret), _1)); - - /// @see http://www.w3.org/TR/SVG/painting.html stroke-dasharray - size_t const count = ret.m_v.size(); - if (count % 2 != 0) - for (size_t i = 0; i < count; ++i) - { - double const d = ret.m_v[i]; - ret.m_v.push_back(d); - } - - return ret; - } - - //////////////////////////////////////////////////////////////////////////////////////// - // line_cap_t - //////////////////////////////////////////////////////////////////////////////////////// - struct line_cap_t - { - enum { round, butt, square }; - int32_t m_v; - - line_cap_t(int32_t v = round) : m_v(v) {} - bool operator==(line_cap_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, line_cap_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, line_cap_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> line_cap_t get_value(string const & s) - { - int v = line_cap_t::round; - if (s == "round") { /*initialized*/ } - else if (s == "butt") v = line_cap_t::butt; - else if (s == "square") v = line_cap_t::square; - else - { - ASSERT ( !"check stroke-linecap values", (s) ); - } - return line_cap_t(v); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // pattern_url_t - //////////////////////////////////////////////////////////////////////////////////////// - struct pattern_url_t : public color_t - { - string m_pattern; - - pattern_url_t() : color_t(color_t::none) {} - pattern_url_t(string const & s) : color_t(color_t::none), m_pattern(s) {} - pattern_url_t(color_t const & r) : color_t(r) {} - - bool operator==(pattern_url_t const & r) const - { - return (m_v == r.m_v) && (m_pattern == r.m_pattern); - } - }; - - template TArchive & operator << (TArchive & ar, pattern_url_t const & t) - { - ar << t.m_v << t.m_pattern; - return ar; - } - template TArchive & operator >> (TArchive & ar, pattern_url_t & t) - { - ar >> t.m_v >> t.m_pattern; - return ar; - } - - template <> pattern_url_t get_value(string const & s) - { - if (s[0] == 'u') - { - /// @todo make fill pattern by symbol - return pattern_url_t(s); - } - else - return get_value(s); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // position_t - //////////////////////////////////////////////////////////////////////////////////////// - struct position_t - { - enum { center = 0 }; - int32_t m_v; - - position_t(int32_t v = center) : m_v(v) {} - bool operator==(position_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, position_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, position_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> position_t get_value(string const & s) - { - int v = position_t::center; - if (s == "center") { /*initialized*/ } - else - { - ASSERT ( !"check symbol position values", (s) ); - } - - return position_t(v); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // txt_anchor_t - //////////////////////////////////////////////////////////////////////////////////////// - struct txt_anchor_t - { - enum { start, middle, end }; - int32_t m_v; - - txt_anchor_t(int32_t v = start) : m_v(v) {} - bool operator==(txt_anchor_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, txt_anchor_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, txt_anchor_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> txt_anchor_t get_value(string const & s) - { - int v = txt_anchor_t::start; - if (s == "start") { /*initialized*/ } - else if (s == "middle") v = txt_anchor_t::middle; - else if (s == "end") v = txt_anchor_t::end; - else - { - ASSERT ( !"check text-anchor values", (s) ); - } - - return txt_anchor_t(v); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // font_family_t - //////////////////////////////////////////////////////////////////////////////////////// - struct font_family_t - { - string m_v; - font_family_t() : m_v("DejaVu Sans") {} - bool operator==(font_family_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, font_family_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, font_family_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> font_family_t get_value(string const & /*s*/) - { - /// @todo process font (example: "DejaVu Sans",sans-serif) - return font_family_t(); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // percent_t - //////////////////////////////////////////////////////////////////////////////////////// - struct percent_t - { - int32_t m_v; - percent_t(int32_t v = 0) : m_v(v) {} - bool operator==(percent_t const & r) const { return m_v == r.m_v; } - }; - - template TArchive & operator << (TArchive & ar, percent_t const & t) - { - ar << t.m_v; - return ar; - } - template TArchive & operator >> (TArchive & ar, percent_t & t) - { - ar >> t.m_v; - return ar; - } - - template <> percent_t get_value(string const & s) - { - size_t i = s.find_first_of('%'); - if (i == string::npos) - { - ASSERT ( !"percent string has no % mark", (s) ); - i = s.size(); - } - - return percent_t(atoi(s.substr(0, i).c_str())); - } - - //////////////////////////////////////////////////////////////////////////////////////// - // LineRule - //////////////////////////////////////////////////////////////////////////////////////// - struct LineRule : public BaseRule - { - tuple m_params; - - LineRule() - : m_params(make_tuple(false, 1.0, 0.0, std::numeric_limits::max(), - pattern_url_t(), -1.0, dash_array_t(), line_cap_t(), 1.0, - 0.0)) - {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual int GetColor() const { return m_params.get<4>().m_v; } - virtual unsigned char GetAlpha() const { return alpha_opacity(m_params.get<8>()); } - virtual double GetWidth() const - { - double w = m_params.get<5>().m_v; - if (w == -1) return 0.0; - - if (m_params.get<0>()) - { - double minw = m_params.get<2>(); - double maxw = m_params.get<3>(); - - if (w < minw) w = minw; - if (w > maxw) w = maxw; - w *= m_params.get<1>(); - } - return w; - } - virtual void GetPattern(vector & p, double & offset) const - { - offset = m_params.get<9>().m_v; - p = m_params.get<6>().m_v; - } - - static string arrKeys[10]; - }; - string LineRule::arrKeys[] = { - // If it is yes, the line will be drawn with the width reflecting the width=* value, - // if the way has the width tag. - "honor-width", - // Is scale factor from width tag value (meter) to pixel width of the SVG. - "width-scale-factor", - // Specify the minimum and the maximum width. If the way doesn't have the width tag, - // the line is drawn with the width specified by CSS - "minimum-width", "maximum-width", - // The color of the line. - "stroke", - // The width of the line. - "stroke-width", - // Specifying the line style. - "stroke-dasharray", - // How to draw the terminal. Choice one from round, butt or square. - "stroke-linecap", - // The opacity of the line. The value takes from 0.0 (completely invisible) to - // 1.0 (completely overdrawing). - // The default is 1.0 - "stroke-opacity", - - // undocumented - "stroke-dashoffset" - }; - - //////////////////////////////////////////////////////////////////////////////////////// - // AreaRule - //////////////////////////////////////////////////////////////////////////////////////// - struct AreaRule : public BaseRule - { - tuple m_params; - - AreaRule() : m_params(make_tuple(pattern_url_t(), 1.0, pattern_url_t(), 1.0, 1.0)) {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual int GetFillColor() const { return m_params.get<0>().m_v; } - virtual int GetColor() const { return m_params.get<2>().m_v; } - virtual unsigned char GetAlpha() const { return alpha_opacity(m_params.get<1>()); } - virtual double GetWidth() const { return m_params.get<3>().m_v; } - - static string arrKeys[5]; - }; - string AreaRule::arrKeys[] = - { - "fill", "fill-opacity", "stroke", "stroke-width", "stroke-opacity" - }; - - //////////////////////////////////////////////////////////////////////////////////////// - // SymbolRule - //////////////////////////////////////////////////////////////////////////////////////// - struct SymbolRule : public BaseRule - { - tuple m_params; - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual void GetSymbol(string & s) const - { - s = m_params.get<0>(); - if (s.empty()) - { - string const & ss = m_params.get<1>(); - if (!ss.empty()) s = ss.substr(1, ss.size()-1); - } - } - - static string arrKeys[3]; - }; - // "width", "height", "transform" - string SymbolRule::arrKeys[] = { "ref", "xlink:href", "position" }; - - //////////////////////////////////////////////////////////////////////////////////////// - // CaptionRule - //////////////////////////////////////////////////////////////////////////////////////// - struct CaptionRule : public BaseRule - { - tuple m_params; - - CaptionRule() - : m_params(make_tuple("", 0, 0, txt_anchor_t(), - font_family_t(), 2.0, color_t(), 1.0, color_t::none)) - {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual double GetTextHeight() const { return m_params.get<5>().m_v; } - virtual int GetFillColor() const { return m_params.get<6>().m_v; } - virtual unsigned char GetAlpha() const { return alpha_opacity(m_params.get<7>()); } - virtual int GetColor() const { return m_params.get<8>().m_v; } - - static string arrKeys[9]; - }; - string CaptionRule::arrKeys[] = { - // it specified the key of the text instruction (eg k="name" ). - "k", - // Translational length on x or y axis from the center point. - "dx", "dy", - // It specify the anchor point on the text. You can choice form start, middle or end. - // The default value is start. - // It is the same meaning with svg:text-anchor property - "text-anchor", - - "font-family", // The font family of the text. (ex. serif, "DejaVu Sans") - "font-size", // The size of the font. - "fill", // The color of the text. - "fill-opacity", // The opacity of the text. The value takes from 0.0 (completely transparent) - // to 1.0 (completely overdrawing). The default is 1.0 . - "stroke" // The color of the font outline. Usually it should be none. - }; - - //////////////////////////////////////////////////////////////////////////////////////// - // CircleRule - //////////////////////////////////////////////////////////////////////////////////////// - struct CircleRule : public BaseRule - { - tuple m_params; - - CircleRule() : m_params(make_tuple(1, color_t(), 1.0, color_t::none, 0.0, 1.0)) {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual double GetRadius() const { return m_params.get<0>().m_v; } - virtual int GetFillColor() const { return m_params.get<1>().m_v; } - virtual unsigned char GetAlpha() const { return alpha_opacity(m_params.get<2>()); } - - virtual int GetColor() const { return m_params.get<3>().m_v; } - virtual double GetWidth() const { return m_params.get<4>().m_v; } - - static string arrKeys[6]; - }; - string CircleRule::arrKeys[] = { - "r", // The radius of a circle. - "fill", // The color of the filling. - "fill-opacity", // The opacity of the filling. The value takes from 0.0 (completely transparent) - // to 1.0 (completely overdrawing). The default is 1.0 . - "stroke", // The color of the outline. If you don't want to draw the outline, - // set it as none. - "stroke-width", // The width of the outline. - "stroke-opacity" // The opacity of the line. - }; - - //////////////////////////////////////////////////////////////////////////////////////// - // PathTextRule - //////////////////////////////////////////////////////////////////////////////////////// - struct PathTextRule : public BaseRule - { - tuple m_params; - - PathTextRule() - : m_params(make_tuple("", 0, 0, txt_anchor_t(), 0, /*true,*/ - font_family_t(), 2.0, color_t(), 1.0, color_t::none)) - {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - virtual double GetTextHeight() const { return m_params.get<6>().m_v; } - virtual int GetFillColor() const { return m_params.get<7>().m_v; } - virtual unsigned char GetAlpha() const { return alpha_opacity(m_params.get<8>()); } - virtual int GetColor() const { return m_params.get<9>().m_v; } - - static string arrKeys[10]; - }; - string PathTextRule::arrKeys[] = { - // It specified the key of the text instruction (eg k="name" ). - "k", - // Translational length on y axis from the center line of the way. - // Usually this is used for drawing ref=*. - "dx", "dy", - // It specify the anchor point on the text. You can choice form start,middle or end. - // The default value is start. It is the same meaning with svg:text-anchor property - "text-anchor", - // It specify the anchor point on the path. The value is given by %. - // The range is form 0% (start of the path) to 100% - // (end of the path). The default value is 0%. - // It is the same meaning with - "startOffset", - // This works only on or/p now - //"avoid-duplicate", - - "font-family", // The font family of the text. (ex. serif, "DejaVu Sans") - "font-size", // The size of the font. - "fill", // The color of the text. - "fill-opacity", // The opacity of the text. The value takes from 0.0 (completely transparent) - // to 1.0 (completely overdrawing). The default is 1.0 . - "stroke" // The color of the font outline. Usually it should be none. - }; - - //////////////////////////////////////////////////////////////////////////////////////// - // WayMarkerRule - //////////////////////////////////////////////////////////////////////////////////////// - struct WayMarkerRule : public BaseRule - { - tuple m_params; - - WayMarkerRule() : m_params(make_tuple("", color_t(), 1.0, line_cap_t(), 1.0)) {} - - virtual bool IsEqual(BaseRule const * p) const { return is_equal_rules(this, p); } - virtual void Read(ReaderPtrStream & ar) { read_rules(ar, this); } - virtual void Write(FileWriterStream & ar) const { write_rules(ar, this); } - - static string arrKeys[5]; - }; - string WayMarkerRule::arrKeys[] = { - // It specified the key of the way that passes through the node. (eg k="highway" ). - "k", - "stroke", // The color of the line. - "stroke-width", // The width of the line. - "stroke-linecap", // How to draw the terminal. Choice one from round, butt or square. - "stroke-opacity" // The opacity of the line. The value takes from 0.0 (completely invisible) - // to 1.0 (completely overdrawing). The default is 1.0 . - }; - -//////////////////////////////////////////////////////////////////////////////////////////// -// BaseRule implementation -//////////////////////////////////////////////////////////////////////////////////////////// -void BaseRule::ReadBase(ReaderPtrStream & ar) -{ - ar >> m_class >> m_type; -} - -void BaseRule::WriteBase(FileWriterStream & ar) const -{ - ar << m_class << m_type; -} - -namespace -{ - bool find_sub_str(string const & s, char const * p) - { - size_t i = s.find(p); - return (i != string::npos); - } -} - -//////////////////////////////////////////////////////////////////////////////////////////// -// RulesHolder implementation -//////////////////////////////////////////////////////////////////////////////////////////// RulesHolder::~RulesHolder() { Clean(); @@ -748,234 +31,6 @@ void RulesHolder::Clean() m_rules.clear(); } -void RulesHolder::SetParseFile(char const * fPath, int scale) -{ - m_file.clear(); - m_currScale = scale; - -#ifndef OMIM_OS_BADA - ifstream file(fPath); - if (!file.is_open()) return; - - vector v(500); - bool doPush = false; - - // push the part of file to the string buffer - while (!file.eof()) - { - file.getline(&v[0], v.size()); - - if (!doPush) - { - if (find_sub_str(&v[0], "")) - break; - } - } -#else - ASSERT ( false, ("SetParseFile uses only in indexer_tool") ); -#endif -} - -/// parse pairs (:;) for a specified 'class' attribute obj in file buffer -void RulesHolder::PushAttributes(string objClass, AttrsMapType & attrs) -{ - objClass = '.' + objClass; - - size_t objSz = objClass.size(); - size_t buffSz = m_file.size(); - - // find 'objClass' string in buffer - size_t i = 0; - while (i < buffSz) - { - i = m_file.find(objClass, i); - if (i == string::npos) return; - - i += objSz; - if (i >= buffSz) return; - - if (m_file[i] == ' ' || m_file[i] == '\t' || m_file[i] == '{') break; - } - - // parse attributes in {...} scope - while (++i < buffSz) - { - i = m_file.find_first_not_of("{ \t", i); - if (i == string::npos || m_file[i] == '}') return; - - size_t e = m_file.find_first_of(':', i); - if (e == string::npos) return; - - string const k = m_file.substr(i, e-i); - - i = m_file.find_first_not_of(" \t", e + 1); - if (i == string::npos) return; - - e = m_file.find_first_of(';', i); - if (e == string::npos) return; - - string const v = m_file.substr(i, e-i); - - // How to push values, if the params are duplicating? - // Assume that the latest rule is better than previous. - attrs[k] = v; - - i = e; - } -} - -namespace -{ - char const * arrClassTags[] = { "class", "mask-class" }; -} - -void RulesHolder::CreateRules(string const & name, uint8_t type, AttrsMapType const & attrs, - vector & v) -{ - bool added = false; - - for (size_t i = 0; i < ARRAY_SIZE(arrClassTags); ++i) - { - AttrsMapType::const_iterator it = attrs.find(arrClassTags[i]); - if (it != attrs.end()) - { - added = true; - v.push_back(CreateRuleImpl1(name, type, it->second, attrs, i == 1)); - } - } - - if (!added) - v.push_back(CreateRuleImpl2(name, type, "", attrs)); -} - -Key RulesHolder::CreateRuleImpl1(string const & name, - uint8_t type, - string const & clValue, - AttrsMapType const & attrs, - bool isMask) -{ -#ifdef DEBUG - if (clValue.find("highway-pedestrian-area") != string::npos) - { - ASSERT (true, ()); - } -#endif - - AttrsMapType a; - strings::Tokenize(clValue, " \t", bind(&RulesHolder::PushAttributes, this, _1, ref(a))); - - for (AttrsMapType::const_iterator i = attrs.begin(); i != attrs.end(); ++i) - if (!strings::IsInArray(arrClassTags, i->first)) - a[i->first] = i->second; - - // background color (imitation of masks in tunnel patterns) - if (isMask) a["stroke"] = "#ffffff"; - - // patch the tunnel draw rules -> make line draw rule - if (name == "tunnel") - { - AttrsMapType::iterator i = a.find("width"); - if (i != a.end()) - { - a["stroke-width"] = i->second; - a.erase(i); - } - - return CreateRuleImpl2("line", type, clValue, a); - } - else - return CreateRuleImpl2(name, type, clValue, a); -} - -Key RulesHolder::CreateRuleImpl2(string const & name, - uint8_t rType, - string const & clName, - AttrsMapType const & attrs) -{ - BaseRule * pRule = 0; - int type = -1; - - if (name == "line") - { - pRule = create_rule(attrs); - type = line; - } - else if (name == "area") - { - pRule = create_rule(attrs); - type = area; - } - else if (name == "symbol") - { - pRule = create_rule(attrs); - type = symbol; - } - else if (name == "caption" || name == "text") - { - pRule = create_rule(attrs); - type = caption; - } - else if (name == "circle") - { - pRule = create_rule(attrs); - type = circle; - } - else if (name == "pathText") - { - pRule = create_rule(attrs); - type = pathtext; - } - else if (name == "wayMarker") - { - pRule = new WayMarkerRule(); - type = waymarker; - } - - if (pRule) - { - pRule->SetType(rType); - - // find existing equal rule for scale and type - vector & rInd = m_rules[m_currScale][type]; - vector & rCont = m_container[type]; - size_t ind = 0; - for (; ind < rInd.size(); ++ind) - { - ASSERT ( rInd[ind] < rCont.size(), (rInd[ind], rCont.size()) ); - if (rCont[rInd[ind]]->IsEqual(pRule)) - break; - } - - if (ind == rInd.size()) - { - // add new rule - pRule->SetClassName(clName); - - rCont.push_back(pRule); - rInd.push_back(rCont.size()-1); - ind = rInd.size()-1; - } - else - delete pRule; - - return Key(m_currScale, type, ind); - } - else - { - ASSERT ( !"check possible rules", (name) ); - return Key(); - } -} - size_t RulesHolder::AddRule(int scale, rule_type_t type, BaseRule * p) { ASSERT ( 0 <= scale && scale <= scales::GetUpperScale(), (scale) ); @@ -991,28 +46,6 @@ size_t RulesHolder::AddRule(int scale, rule_type_t type, BaseRule * p) return ret; } -size_t RulesHolder::AddLineRule(int scale, int color, double pixWidth) -{ - LineRule * p = new LineRule(); - p->m_params.get<4>() = color_t(color); - p->m_params.get<5>() = pixWidth / scales::GetM2PFactor(scale); - return AddRule(scale, line, p); -} - -size_t RulesHolder::AddAreaRule(int scale, int color) -{ - AreaRule * p = new AreaRule(); - p->m_params.get<0>() = color_t(color); - return AddRule(scale, area, p); -} - -size_t RulesHolder::AddSymbolRule(int scale, string const & sym) -{ - SymbolRule * p = new SymbolRule(); - p->m_params.get<0>() = sym; - return AddRule(scale, symbol, p); -} - BaseRule const * RulesHolder::Find(Key const & k) const { rules_map_t::const_iterator i = m_rules.find(k.m_scale); @@ -1027,54 +60,10 @@ BaseRule const * RulesHolder::Find(Key const & k) const return 0; } -FileWriterStream & operator << (FileWriterStream & ar, BaseRule * p) +void RulesHolder::ClearCaches() { - p->Write(ar); - return ar; -} - -void do_load(ReaderPtrStream & ar, size_t ind, BaseRule * & p) -{ - switch (ind) - { - case line: p = new LineRule(); break; - case area: p = new AreaRule(); break; - case symbol: p = new SymbolRule(); break; - case caption: p = new CaptionRule(); break; - case circle: p = new CircleRule(); break; - case pathtext: p = new PathTextRule(); break; - case waymarker: p = new WayMarkerRule(); break; - default: - ASSERT ( !"Incorrect draw rule type for reading.", (ind) ); - throw std::out_of_range("Bad draw rule index"); - } - - p->Read(ar); -} - -void RulesHolder::Read(ReaderPtrStream & s) -{ - Clean(); - - serial::do_load(s, m_container); - s >> m_rules; -} - -void RulesHolder::Write(FileWriterStream & s) -{ - s << m_container << m_rules; -} - -void WriteRules(string const & fPath) -{ - FileWriterStream file(fPath); - rules().Write(file); -} - -void ReadRules(ReaderPtrStream & s) -{ - rules().Clean(); - rules().Read(s); + ForEachRule(bind(&BaseRule::MakeEmptyID, _4)); + ForEachRule(bind(&BaseRule::MakeEmptyID2, _4)); } RulesHolder & rules() @@ -1083,291 +72,35 @@ RulesHolder & rules() return holder; } -namespace -{ - class RulesConvertor - { - RulesHolder & m_rules; - ContainerProto & m_cont; - - double m_factor; - - double ToPixels(double d) const - { - return d * m_factor; - } - - static int32_t GetStoringAlpha(BaseRule const * pSrc) - { - // 255 is default value for BaseRule - completely visible - // when storing alpha, 0 - is default value for visible - int32_t r = 255 - pSrc->GetAlpha(); - r = r << 24; - return r; - } - - static int32_t GetColor(BaseRule const * pSrc) - { - return (pSrc->GetColor() | GetStoringAlpha(pSrc)); - } - static int32_t GetFillColor(BaseRule const * pSrc) - { - return (pSrc->GetFillColor() | GetStoringAlpha(pSrc)); - } - - template - void ConvertLineStyle(BaseRule const * pSrc, T * pDest) const - { - pDest->set_width(ToPixels(pSrc->GetWidth())); - pDest->set_color(GetColor(pSrc)); - - vector dd; - double offset; - pSrc->GetPattern(dd, offset); - if (!dd.empty()) - { - DashDotProto * p = pDest->mutable_dashdot(); - - for (size_t i = 0; i < dd.size(); ++i) - p->add_dd(ToPixels(dd[i])); - - if (offset != 0.0) - p->set_offset(ToPixels(offset)); - } - } - - void ConvertImpl(BaseRule const * pSrc, LineRuleProto * pDest) const - { - ConvertLineStyle(pSrc, pDest); - } - - void ConvertImpl(BaseRule const * pSrc, AreaRuleProto * pDest) const - { - pDest->set_color(GetFillColor(pSrc)); - if (pSrc->GetColor() != -1) - ConvertLineStyle(pSrc, pDest->mutable_border()); - } - - void ConvertImpl(BaseRule const * pSrc, SymbolRuleProto * pDest) const - { - string s; - pSrc->GetSymbol(s); - pDest->set_name(s); - } - - template - void ConvertCaptionStyle(BaseRule const * pSrc, T * pDest) const - { - pDest->set_height(ToPixels(pSrc->GetTextHeight())); - pDest->set_color((pSrc->GetFillColor() != -1) ? GetFillColor(pSrc) : 0); - - if (pSrc->GetColor() != -1) - pDest->set_stroke_color(GetColor(pSrc)); - } - - void ConvertImpl(BaseRule const * pSrc, CaptionRuleProto * pDest) const - { - ConvertCaptionStyle(pSrc, pDest->mutable_primary()); - } - - void ConvertImpl(BaseRule const * pSrc, PathTextRuleProto * pDest) const - { - ConvertCaptionStyle(pSrc, pDest->mutable_primary()); - } - - void ConvertImpl(BaseRule const * pSrc, CircleRuleProto * pDest) const - { - pDest->set_radius(ToPixels(pSrc->GetRadius())); - pDest->set_color(GetFillColor(pSrc)); - } - - template - void Convert(BaseRule const * pSrc, int priority, T * pDest) const - { - pDest->set_priority(priority); - ConvertImpl(pSrc, pDest); - } - - vector m_parents; - - string GetFullName(ClassifObject const & o) const - { - string res; - for (size_t i = 0; i < m_parents.size(); ++i) - res = res + m_parents[i] + "-"; - res = res + o.GetName(); - return res; - } - - public: - RulesConvertor(ContainerProto & cont) - : m_rules(drule::rules()), m_cont(cont) - { - } - - void operator() (ClassifObject const & o) - { - using namespace drule; - - vector keys = o.GetDrawingRules(); - MakeUnique(keys); - SortByScaleTypeDepth(keys); - - if (!keys.empty()) - { - ClassifElementProto * pCE = m_cont.add_cont(); - pCE->set_name(GetFullName(o)); - - DrawElementProto * pDE = 0; - for (size_t i = 0; i < keys.size(); ++i) - { - // skip unnecessary trash - if (keys[i].m_type == waymarker) - continue; - - if (pDE == 0 || pDE->scale() != keys[i].m_scale) - { - pDE = pCE->add_element(); - pDE->set_scale(keys[i].m_scale); - m_factor = scales::GetM2PFactor(keys[i].m_scale); - } - - BaseRule const * pRule = m_rules.Find(keys[i]); - if (pRule->GetAlpha() == 0) continue; - - switch (keys[i].m_type) - { - case line: - Convert(pRule, keys[i].m_priority, pDE->add_lines()); - break; - case area: - Convert(pRule, keys[i].m_priority, pDE->mutable_area()); - break; - case symbol: - Convert(pRule, keys[i].m_priority, pDE->mutable_symbol()); - break; - case caption: - Convert(pRule, keys[i].m_priority, pDE->mutable_caption()); - break; - case circle: - Convert(pRule, keys[i].m_priority, pDE->mutable_circle()); - break; - case pathtext: - Convert(pRule, keys[i].m_priority, pDE->mutable_path_text()); - } - } - } - - m_parents.push_back(o.GetName()); - o.ForEachObjectConst(*this); - m_parents.pop_back(); - } - }; -} - -void ConvertToProtocolBuffers(string & res) -{ - ContainerProto cont; - RulesConvertor conv(cont); - classif().GetRoot()->ForEachObjectConst(conv); - - google::protobuf::TextFormat::PrintToString(cont, &res); -} - namespace { namespace proto_rules { - unsigned char AlphaFromColor(int c) - { - c = c >> 24; - return (255 - c); - } - - template - void GetPattern(T const & ln, vector & v, double & offset) - { - offset = 0.0; - if (ln.has_dashdot()) - { - DashDotProto const & dd = ln.dashdot(); - - int const count = dd.dd_size(); - v.reserve(count); - for (int i = 0; i < count; ++i) - v.push_back(dd.dd(i)); - - if (dd.has_offset()) - offset = dd.offset(); - } - } - - class MyBase : public BaseRule + class Line : public BaseRule { + LineDefProto m_line; public: - virtual bool IsEqual(BaseRule const *) const { return false; } - virtual void Read(ReaderPtrStream &) {} - virtual void Write(FileWriterStream &) const {} + Line(LineRuleProto const & r) + { + m_line.set_color(r.color()); + m_line.set_width(r.width()); + if (r.has_dashdot()) + *(m_line.mutable_dashdot()) = r.dashdot(); + } + + virtual LineDefProto const * GetLine() const { return &m_line; } }; - class Line : public MyBase - { - LineRuleProto m_line; - public: - Line(LineRuleProto const & r) : m_line(r) {} - - virtual int GetColor() const - { - return m_line.color(); - } - virtual unsigned char GetAlpha() const - { - return AlphaFromColor(GetColor()); - } - virtual double GetWidth() const - { - return m_line.width(); - } - virtual void GetPattern(vector & v, double & offset) const - { - proto_rules::GetPattern(m_line, v, offset); - } - }; - - class Area : public MyBase + class Area : public BaseRule { AreaRuleProto m_area; public: Area(AreaRuleProto const & r) : m_area(r) {} - virtual int GetColor() const - { - if (m_area.has_border()) - return m_area.border().color(); - return -1; - } - virtual int GetFillColor() const - { - return m_area.color(); - } - virtual unsigned char GetAlpha() const - { - return AlphaFromColor(GetFillColor()); - } - virtual double GetWidth() const - { - if (m_area.has_border()) - return m_area.border().width(); - return -1; - } - virtual void GetPattern(vector & v, double & offset) const - { - if (m_area.has_border()) - proto_rules::GetPattern(m_area.border(), v, offset); - } + virtual AreaRuleProto const * GetArea() const { return &m_area; } }; - class Symbol : public MyBase + class Symbol : public BaseRule { SymbolRuleProto m_symbol; public: @@ -1377,69 +110,41 @@ namespace SetType(r.apply_for_type()); } - virtual void GetSymbol(string & name) const - { - name = m_symbol.name(); - } + virtual SymbolRuleProto const * GetSymbol() const { return &m_symbol; } }; - template class CaptionT : public MyBase + template class CaptionT : public BaseRule { T m_caption; - inline CaptionDefProto const & primary() const { return m_caption.primary(); } public: CaptionT(T const & r) : m_caption(r) {} - virtual int GetColor() const + virtual CaptionDefProto const * GetCaption(int i) const { - if (primary().has_stroke_color()) - return primary().stroke_color(); - return -1; - } - virtual int GetFillColor() const - { - return primary().color(); - } - virtual double GetTextHeight() const - { - return primary().height(); - } - virtual unsigned char GetAlpha() const - { - return AlphaFromColor(GetFillColor()); - } - virtual unsigned char GetStrokeAlpha() const - { - return AlphaFromColor(GetColor()); + if (i == 0) + return &m_caption.primary(); + else + { + ASSERT_EQUAL ( i, 1, () ); + if (m_caption.has_secondary()) + return &m_caption.secondary(); + else + return 0; + } } }; typedef CaptionT Caption; typedef CaptionT PathText; - class Circle : public MyBase + class Circle : public BaseRule { CircleRuleProto m_circle; public: Circle(CircleRuleProto const & r) : m_circle(r) {} - virtual int GetFillColor() const - { - return m_circle.color(); - } - virtual double GetRadius() const - { - return m_circle.radius(); - } - virtual unsigned char GetAlpha() const - { - return AlphaFromColor(GetFillColor()); - } - virtual unsigned char GetStrokeAlpha() const - { - return AlphaFromColor(GetColor()); - } + virtual CircleRuleProto const * GetCircle() const { return &m_circle; } }; } @@ -1562,7 +267,7 @@ namespace }; } -void RulesHolder::LoadFromProto(string const & buffer) +void RulesHolder::LoadFromTextProto(string const & buffer) { Clean(); @@ -1571,10 +276,4 @@ void RulesHolder::LoadFromProto(string const & buffer) classif().GetMutableRoot()->ForEachObject(bind(ref(doSet), _1)); } -void RulesHolder::ClearCaches() -{ - ForEachRule(bind(&BaseRule::MakeEmptyID, _4)); - ForEachRule(bind(&BaseRule::MakeEmptyID2, _4)); -} - } diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp index c8f5b585c2..15b66cfb86 100644 --- a/indexer/drawing_rules.hpp +++ b/indexer/drawing_rules.hpp @@ -10,17 +10,17 @@ #include "../std/string.hpp" -class ReaderPtrStream; -class FileWriterStream; +class LineDefProto; +class AreaRuleProto; +class SymbolRuleProto; +class CaptionDefProto; +class CircleRuleProto; + namespace drule { - typedef map AttrsMapType; - class BaseRule { - string m_class; // for debug use only, can be removed - mutable buffer_vector m_id1, m_id2; char m_type; // obsolete for new styles, can be removed @@ -30,11 +30,8 @@ namespace drule BaseRule() : m_type(node | way) { } - virtual ~BaseRule() {} - /// @todo Rewrite this. Make an array of IDs. - //@{ void CheckSize(buffer_vector & v, size_t s) const { if (v.size() < s) @@ -88,34 +85,15 @@ namespace drule for (size_t i = 0; i < m_id2.size(); ++i) MakeEmptyID2(i); } - //@} - void SetClassName(string const & cl) { m_class = cl; } void SetType(char type) { m_type = type; } inline char GetType() const { return m_type; } - bool IsEqualBase(BaseRule const * p) const { return (m_type == p->m_type); } - void ReadBase(ReaderPtrStream & ar); - void WriteBase(FileWriterStream & ar) const; - - virtual bool IsEqual(BaseRule const * p) const = 0; - virtual void Read(ReaderPtrStream & ar) = 0; - virtual void Write(FileWriterStream & ar) const = 0; - - /// @name This functions can tell us about the type of rule. - //@{ - virtual int GetColor() const { return -1; } ///< path "line" color - virtual int GetFillColor() const { return -1; } ///< fill "area" color - virtual double GetTextHeight() const { return -1.0; } ///< text height of "caption" - virtual double GetRadius() const { return -1; } ///< radius "circle" - virtual void GetSymbol(string &) const {} ///< name of "symbol" - //@} - - virtual unsigned char GetAlpha() const { return 255; } - virtual unsigned char GetStrokeAlpha() const { return 255; } - - virtual double GetWidth() const { return -1; } - virtual void GetPattern(vector &, double &) const {} + virtual LineDefProto const * GetLine() const { return 0; } + virtual AreaRuleProto const * GetArea() const { return 0; } + virtual SymbolRuleProto const * GetSymbol() const { return 0; } + virtual CaptionDefProto const * GetCaption(int) const { return 0; } + virtual CircleRuleProto const * GetCircle() const { return 0; } }; class RulesHolder @@ -128,42 +106,18 @@ namespace drule typedef map, count_of_rules> > rules_map_t; rules_map_t m_rules; - /// @name temporary for search rules parameters by 'class' attribute - //@{ - string m_file; - int m_currScale; - //@} - - void PushAttributes(string objClass, AttrsMapType & attrs); - - Key CreateRuleImpl1(string const & name, uint8_t type, string const & clValue, - AttrsMapType const & attrs, bool isMask); - Key CreateRuleImpl2(string const & name, uint8_t type, string const & clName, - AttrsMapType const & attrs); - public: ~RulesHolder(); size_t AddRule(int scale, rule_type_t type, BaseRule * p); - size_t AddLineRule(int scale, int color, double pixWidth); - size_t AddAreaRule(int scale, int color); - size_t AddSymbolRule(int scale, string const & sym); void Clean(); - void SetParseFile(char const * fPath, int scale); - - void CreateRules(string const & name, uint8_t type, - AttrsMapType const & attrs, vector & v); + void ClearCaches(); BaseRule const * Find(Key const & k) const; - int GetScale() const { return m_currScale; } - - void Read(ReaderPtrStream & s); - void Write(FileWriterStream & s); - void LoadFromProto(string const & buffer); - void ClearCaches(); + void LoadFromTextProto(string const & buffer); template void ForEachRule(ToDo toDo) { @@ -182,10 +136,5 @@ namespace drule } }; - void WriteRules(string const & fPath); - void ReadRules(ReaderPtrStream & s); - RulesHolder & rules(); - - void ConvertToProtocolBuffers(string & res); } diff --git a/map/draw_processor.cpp b/map/draw_processor.cpp index 10fe2bc3ac..92a5dd689d 100644 --- a/map/draw_processor.cpp +++ b/map/draw_processor.cpp @@ -360,11 +360,11 @@ namespace fwork if (!ptr->m_name.empty()) { - double fontSize = 0; + uint8_t fontSize = 0; for (size_t i = 0; i < count; ++i) { - if (pDrawer->filter_text_size(rules[i].m_rule)) - fontSize = max((uint8_t)fontSize, pDrawer->get_text_font_size(rules[i].m_rule)); + if (!pDrawer->filter_text_size(rules[i].m_rule)) + fontSize = max(fontSize, pDrawer->get_text_font_size(rules[i].m_rule)); } if (fontSize != 0) diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 7c5e0c19ab..6323ac35e0 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -1,4 +1,5 @@ #include "drawer_yg.hpp" +#include "proto_to_yg_styles.hpp" #include "../std/bind.hpp" @@ -9,14 +10,13 @@ #include "../yg/screen.hpp" #include "../yg/skin.hpp" #include "../yg/resource_manager.hpp" -#include "../yg/circle_info.hpp" -#include "../yg/pen_info.hpp" #include "../geometry/screenbase.hpp" #include "../base/logging.hpp" #include "../base/buffer_vector.hpp" + DrawerYG::Params::Params() : m_dynamicPagesCount(2), m_textPagesCount(2), @@ -120,41 +120,16 @@ void DrawerYG::drawSymbol(m2::PointD const & pt, string const & symbolName, yg:: void DrawerYG::drawCircle(m2::PointD const & pt, rule_ptr_t pRule, yg::EPosition pos, int depth) { - double const radius = min(max(pRule->GetRadius() * m_scale, 3.0), 6.0) * m_visualScale; - int const lineC = pRule->GetColor(); - double const width = (lineC != -1) ? min(max(pRule->GetWidth() * m_scale * m_visualScale, 1.0), 3.0) : 1.0; - - yg::CircleInfo ci(radius, - yg::Color::fromXRGB(pRule->GetFillColor(), pRule->GetAlpha()), - lineC != -1, - width, - yg::Color::fromXRGB(lineC, pRule->GetStrokeAlpha())); + yg::CircleInfo ci; + ConvertStyle(pRule->GetCircle(), m_visualScale, ci); m_pScreen->drawCircle(pt, ci, pos, depth); } void DrawerYG::drawSymbol(m2::PointD const & pt, rule_ptr_t pRule, yg::EPosition pos, int depth) { - // Use BaseRule::m_id to cache for point draw rule. - // This rules doesn't mix with other rule-types. - -// uint32_t id = pRule->GetID(m_threadID); - string name; - pRule->GetSymbol(name); - -/* if (id == drule::BaseRule::empty_id) - { - id = m_pSkin->mapSymbol(name.c_str()); - - if (id != drule::BaseRule::empty_id) - pRule->SetID(m_threadID, id); - else - { - //ASSERT ( false, ("Can't find symbol by id = ", (name)) ); - return; - } - }*/ + ConvertStyle(pRule->GetSymbol(), name); m_pScreen->drawSymbol(pt, name, pos, depth); } @@ -180,18 +155,11 @@ void DrawerYG::drawPath(di::PathInfo const & info, di::DrawRule const * rules, s // collect yg::PenInfo into array and pack them as a whole for (size_t i = 0; i < count; ++i) { - rule_ptr_t pRule = rules[i].m_rule; - vector pattern; - double offset; - pRule->GetPattern(pattern, offset); + ConvertStyle(rules[i].m_rule->GetLine(), m_visualScale, penInfos[i]); - for (size_t j = 0; j < pattern.size(); ++j) - pattern[j] *= m_scale * m_visualScale; + if (rules[i].m_transparent) + penInfos[i].m_color.a = 100; - penInfos[i] = yg::PenInfo( - yg::Color::fromXRGB(pRule->GetColor(), rules[i].m_transparent ? 100 : pRule->GetAlpha()), - max(pRule->GetWidth() * m_scale, 1.0) * m_visualScale, - pattern.empty() ? 0 : &pattern[0], pattern.size(), offset * m_scale); styleIDs[i] = m_pSkin->invalidHandle(); } @@ -218,75 +186,54 @@ void DrawerYG::drawArea(vector const & pts, rule_ptr_t pRule, int de // DO NOT cache 'id' in pRule, because one rule can use in drawPath and drawArea. // Leave CBaseRule::m_id for drawPath. mapColor working fast enough. - uint32_t const id = m_pSkin->mapColor(yg::Color::fromXRGB(pRule->GetFillColor(), pRule->GetAlpha())); + yg::Color color; + ConvertStyle(pRule->GetArea(), color); + uint32_t const id = m_pSkin->mapColor(color); ASSERT ( id != -1, () ); m_pScreen->drawTrianglesList(&pts[0], pts.size()/*, res*/, id, depth); } -namespace -{ - double const min_text_height_filtered = 2; - double const min_text_height = 12; // 8 - //double const min_text_height_mask = 9.99; // 10 -} - uint8_t DrawerYG::get_text_font_size(rule_ptr_t pRule) const { - double const h = pRule->GetTextHeight() * m_scale; - return my::rounds(max(h, min_text_height) * m_visualScale); + return GetFontSize(pRule->GetCaption(0)) * m_visualScale; } bool DrawerYG::filter_text_size(rule_ptr_t pRule) const { - return pRule->GetTextHeight() * m_scale <= min_text_height_filtered; -} - -yg::FontDesc DrawerYG::get_text_font(rule_ptr_t pRule) const -{ - int c = pRule->GetFillColor(); - yg::Color color = (c != -1 ? yg::Color::fromXRGB(c, pRule->GetAlpha()) : - yg::Color(0, 0, 0, 0)); - - // to prevent white text on white outline - //if (color == yg::Color(255, 255, 255, 255)) - // color = yg::Color(0, 0, 0, 0); - - c = pRule->GetColor(); - - bool const hasStroke = (c != -1); - yg::Color strokeColor = (hasStroke ? yg::Color::fromXRGB(c, pRule->GetStrokeAlpha()) : - yg::Color(255, 255, 255, 255)); - - return yg::FontDesc(get_text_font_size(pRule), color, hasStroke, strokeColor); + if (pRule->GetCaption(0)) + return (GetFontSize(pRule->GetCaption(0)) < 3); + else + { + // this rule is not a caption at all + return true; + } } void DrawerYG::drawText(m2::PointD const & pt, di::DrawInfo const * pInfo, rule_ptr_t pRule, yg::EPosition pos, int depth) { - yg::FontDesc fontDesc(get_text_font(pRule)); - fontDesc.SetRank(pInfo->m_rank); + yg::FontDesc font; + ConvertStyle(pRule->GetCaption(0), m_visualScale, font); + font.SetRank(pInfo->m_rank); - yg::FontDesc smallFontDesc(fontDesc); - smallFontDesc.m_size *= 0.75; + yg::FontDesc smallFont; + if (pRule->GetCaption(1)) + { + ConvertStyle(pRule->GetCaption(1), m_visualScale, smallFont); + smallFont.SetRank(pInfo->m_rank); + } - if (!filter_text_size(pRule)) - m_pScreen->drawTextEx( - fontDesc, - smallFontDesc, - pt, - pos, - pInfo->m_name, - pInfo->m_secondaryName, - depth, - true, - true); + m_pScreen->drawTextEx(font, smallFont, pt, pos, + pInfo->m_name, pInfo->m_secondaryName, + depth, true, true); } bool DrawerYG::drawPathText(di::PathInfo const & info, di::DrawInfo const * pInfo, rule_ptr_t pRule, int depth) { - yg::FontDesc primaryFont(get_text_font(pRule)); + yg::FontDesc font; + ConvertStyle(pRule->GetCaption(0), m_visualScale, font); - return m_pScreen->drawPathText(primaryFont, + return m_pScreen->drawPathText(font, &info.m_path[0], info.m_path.size(), pInfo->GetPathName(), @@ -334,12 +281,6 @@ double DrawerYG::VisualScale() const void DrawerYG::SetScale(int level) { m_level = level; - -#ifdef USE_PROTO_STYLES - m_scale = 1.0; -#else - m_scale = scales::GetM2PFactor(level); -#endif } void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t count) @@ -353,13 +294,11 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size for (unsigned i = 0; i < count; ++i) { rule_ptr_t pRule = rules[i].m_rule; - string symbol; - pRule->GetSymbol(symbol); - bool const hasSymbol = !symbol.empty(); - bool const isCaption = pRule->GetTextHeight() >= 0.0; + bool const hasSymbol = pRule->GetSymbol() != 0; + bool const isCaption = pRule->GetCaption(0) != 0; - if (!isCaption && isPath && !hasSymbol && (pRule->GetColor() != -1)) + if (!isCaption && isPath && !hasSymbol && (pRule->GetLine() != 0)) pathRules.push_back(rules[i]); } @@ -378,28 +317,16 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size rule_ptr_t pRule = rules[i].m_rule; int const depth = rules[i].m_depth; - bool const isCaption = pRule->GetTextHeight() >= 0.0; - - string symbol; - pRule->GetSymbol(symbol); - bool const hasSymbol = !symbol.empty(); - - bool const isCircle = (pRule->GetRadius() != -1); + bool const isCaption = pRule->GetCaption(0) != 0; + bool const hasSymbol = pRule->GetSymbol() != 0; + bool const isCircle = pRule->GetCircle() != 0; if (!isCaption) { - // path is drawn separately in the code above - // draw path - //if (isPath && !isSymbol && (pRule->GetColor() != -1)) - //{ - // for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) - // drawPath(*i, pRule, depth); - //} - // draw area if (isArea) { - bool const isFill = pRule->GetFillColor() != -1; + bool const isFill = pRule->GetArea() != 0; bool const hasSym = hasSymbol && ((pRule->GetType() & drule::way) != 0); for (list::const_iterator i = pInfo->m_areas.begin(); i != pInfo->m_areas.end(); ++i) @@ -437,12 +364,7 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size if (isPath && !isArea && isN && !filter_text_size(pRule)) { for (list::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i) - { - if (filter_text_size(pRule)) - continue; - drawPathText(*i, pInfo, pRule, depth); - } } // draw point text diff --git a/map/drawer_yg.hpp b/map/drawer_yg.hpp index bdeae02371..f91dad6457 100644 --- a/map/drawer_yg.hpp +++ b/map/drawer_yg.hpp @@ -69,7 +69,6 @@ class DrawerYG { typedef di::DrawRule::rule_ptr_t rule_ptr_t; - double m_scale; double m_visualScale; int m_level; size_t m_threadID; @@ -125,7 +124,6 @@ public: void Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size_t count); - uint8_t get_text_font_size(rule_ptr_t pRule) const; - yg::FontDesc get_text_font(rule_ptr_t pRule) const; bool filter_text_size(rule_ptr_t pRule) const; + uint8_t get_text_font_size(rule_ptr_t pRule) const; }; diff --git a/map/map.pro b/map/map.pro index b28baaac90..7adf2afb80 100644 --- a/map/map.pro +++ b/map/map.pro @@ -3,6 +3,7 @@ TARGET = map TEMPLATE = lib CONFIG += staticlib +INCLUDEPATH += ../3party/protobuf/src ROOT_DIR = .. DEPENDENCIES = search yg indexer geometry coding base expat @@ -40,7 +41,8 @@ HEADERS += \ benchmark_render_policy_mt.hpp \ ruler.hpp \ measurement_utils.hpp \ - partial_render_policy.hpp + partial_render_policy.hpp \ + proto_to_yg_styles.hpp \ SOURCES += \ feature_vec_model.cpp \ @@ -71,16 +73,11 @@ SOURCES += \ ruler.cpp \ measurement_utils.cpp \ window_handle.cpp \ - partial_render_policy.cpp + partial_render_policy.cpp \ + proto_to_yg_styles.cpp \ !iphone*:!bada*:!android* { HEADERS += qgl_render_context.hpp SOURCES += qgl_render_context.cpp QT += opengl } - - - - - - diff --git a/map/proto_to_yg_styles.cpp b/map/proto_to_yg_styles.cpp new file mode 100644 index 0000000000..dc69381f35 --- /dev/null +++ b/map/proto_to_yg_styles.cpp @@ -0,0 +1,88 @@ +#include "proto_to_yg_styles.hpp" + +#include "../indexer/drules_struct.pb.h" + +#include "../std/algorithm.hpp" + + +namespace +{ + yg::Color ConvertColor(int c) + { + return yg::Color::fromXRGB(c, 255 - (c >> 24)); + } + + double ConvertWidth(double w, double scale) + { + return max(w, 1.0) * scale; + } +} + + +void ConvertStyle(LineDefProto const * pSrc, double scale, yg::PenInfo & dest) +{ + double offset = 0.0; + vector v; + + if (pSrc->has_dashdot()) + { + DashDotProto const & dd = pSrc->dashdot(); + + int const count = dd.dd_size(); + v.reserve(count); + for (int i = 0; i < count; ++i) + v.push_back(dd.dd(i) * scale); + + if (dd.has_offset()) + offset = dd.offset() * scale; + } + + dest = yg::PenInfo( + ConvertColor(pSrc->color()), + ConvertWidth(pSrc->width(), scale), + v.empty() ? 0 : &v[0], v.size(), offset); +} + +void ConvertStyle(AreaRuleProto const * pSrc, yg::Color & dest) +{ + dest = ConvertColor(pSrc->color()); +} + +void ConvertStyle(SymbolRuleProto const * pSrc, string & dest) +{ + dest = pSrc->name(); +} + +void ConvertStyle(CircleRuleProto const * pSrc, double scale, yg::CircleInfo & dest) +{ + dest = yg::CircleInfo(min(max(pSrc->radius(), 3.0), 6.0) * scale, + ConvertColor(pSrc->color())); + + if (pSrc->has_border()) + { + yg::PenInfo pen; + ConvertStyle(&(pSrc->border()), scale, pen); + + dest.m_isOutlined = true; + dest.m_outlineColor = pen.m_color; + dest.m_outlineWidth = pen.m_w; + } +} + +void ConvertStyle(CaptionDefProto const * pSrc, double scale, yg::FontDesc & dest) +{ + uint8_t const h = max(static_cast(pSrc->height() * scale), 12); + + dest = yg::FontDesc(h, ConvertColor(pSrc->color())); + + if (pSrc->has_stroke_color()) + { + dest.m_isMasked = true; + dest.m_maskColor = ConvertColor(pSrc->stroke_color()); + } +} + +uint8_t GetFontSize(CaptionDefProto const * pSrc) +{ + return pSrc->height(); +} diff --git a/map/proto_to_yg_styles.hpp b/map/proto_to_yg_styles.hpp new file mode 100644 index 0000000000..ace0f16ec0 --- /dev/null +++ b/map/proto_to_yg_styles.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "../yg/pen_info.hpp" +#include "../yg/circle_info.hpp" +#include "../yg/font_desc.hpp" + + +class LineDefProto; +class AreaRuleProto; +class SymbolRuleProto; +class CaptionDefProto; +class CircleRuleProto; + + +void ConvertStyle(LineDefProto const * pSrc, double scale, yg::PenInfo & dest); +void ConvertStyle(AreaRuleProto const * pSrc, yg::Color & dest); +void ConvertStyle(SymbolRuleProto const * pSrc, string & dest); +void ConvertStyle(CircleRuleProto const * pSrc, double scale, yg::CircleInfo & dest); +void ConvertStyle(CaptionDefProto const * pSrc, double scale, yg::FontDesc & dest); + +uint8_t GetFontSize(CaptionDefProto const * pSrc);