diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-03-03 03:26:53 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:36:21 +0300 |
commit | 0efb895a364703a5ca596bf2af0688da53c48f74 (patch) | |
tree | c127dba8b66d19bc8b2f2ffc0f4fd121ce4f7b13 /skin_generator | |
parent | 0f6a2d7aea51f598d2d4b86b8df4116707515d18 (diff) |
generating icons for search categories.
Diffstat (limited to 'skin_generator')
-rw-r--r-- | skin_generator/main.cpp | 11 | ||||
-rw-r--r-- | skin_generator/skin_generator.cpp | 66 | ||||
-rw-r--r-- | skin_generator/skin_generator.hpp | 6 |
3 files changed, 83 insertions, 0 deletions
diff --git a/skin_generator/main.cpp b/skin_generator/main.cpp index 6530c821fb..7abd0ece3d 100644 --- a/skin_generator/main.cpp +++ b/skin_generator/main.cpp @@ -15,6 +15,10 @@ DEFINE_int32(symbolWidth, 24, "width of the rendered symbol"); DEFINE_int32(symbolHeight, 24, "height of the rendered symbol"); DEFINE_string(skinName, "../../data/basic", "prefix for the skin and skinImage file name"); DEFINE_string(skinSuffix, "ldpi", "suffix for skinName<suffix>.skn and symbols<suffix>.png"); +DEFINE_string(searchIconsPath, "../../data/search-icons", "output path for search category icons"); +DEFINE_string(searchCategories, "../../data/categories-icons.txt", "path to file that contains mapping between category and icon names"); +DEFINE_int32(searchIconWidth, 42, "width of the search category icon"); +DEFINE_int32(searchIconHeight, 42, "height of the search category icon"); int main(int argc, char *argv[]) { @@ -29,7 +33,14 @@ int main(int argc, char *argv[]) std::vector<std::string> suffixes; suffixes.push_back(FLAGS_skinSuffix); + gen.processSearchIcons(FLAGS_symbolsDir, + FLAGS_searchCategories, + FLAGS_searchIconsPath, + FLAGS_searchIconWidth, + FLAGS_searchIconHeight); + gen.processSymbols(FLAGS_symbolsDir, FLAGS_skinName, symbolSizes, suffixes); + gen.renderPages(); gen.writeToFile(FLAGS_skinName + "_" + FLAGS_skinSuffix); diff --git a/skin_generator/skin_generator.cpp b/skin_generator/skin_generator.cpp index 67753a6d02..8e57066822 100644 --- a/skin_generator/skin_generator.cpp +++ b/skin_generator/skin_generator.cpp @@ -205,6 +205,72 @@ namespace tools } }; + void SkinGenerator::processSearchIcons(string const & symbolsDir, + string const & searchCategories, + string const & searchIconsPath, + int searchIconWidth, + int searchIconHeight) + { + ifstream fin(searchCategories.c_str()); + QDir().mkpath(QString(searchIconsPath.c_str())); + + while (true) + { + string category; + string icon; + fin >> category; + fin >> icon; + if (!fin) + break; + + QString fullFileName((symbolsDir + "/" + icon + ".svg").c_str()); + + if (m_svgRenderer.load(fullFileName)) + { + QRect viewBox = m_svgRenderer.viewBox(); + QSize defaultSize = m_svgRenderer.defaultSize(); + + QSize size = defaultSize * (searchIconWidth / 24.0); + + /// fitting symbol into symbolSize, saving aspect ratio + + if (size.width() > searchIconWidth) + { + size.setHeight((float)size.height() * searchIconWidth / (float)size.width()); + size.setWidth(searchIconWidth); + } + + if (size.height() > searchIconHeight) + { + size.setWidth((float)size.width() * searchIconHeight / (float)size.height()); + size.setHeight(searchIconHeight); + } + + gil::bgra8_image_t gilImage(size.width(), size.height()); + gil::fill_pixels(gil::view(gilImage), gil::rgba8_pixel_t(0, 0, 0, 0)); + QImage img((uchar*)&gil::view(gilImage)(0, 0), size.width(), size.height(), QImage::Format_ARGB32); + QPainter painter(&img); + + m_svgRenderer.render(&painter, QRect(0, 0, size.width(), size.height())); + + img.save((searchIconsPath + "/" + category + ".png").c_str()); + + { + size *= 2; + gil::bgra8_image_t gilImage(size.width(), size.height()); + gil::fill_pixels(gil::view(gilImage), gil::rgba8_pixel_t(0, 0, 0, 0)); + QImage img((uchar*)&gil::view(gilImage)(0, 0), size.width(), size.height(), QImage::Format_ARGB32); + QPainter painter(&img); + + m_svgRenderer.render(&painter, QRect(0, 0, size.width(), size.height())); + img.save((searchIconsPath + "/" + category + "@2x.png").c_str()); + } + } + else + LOG(LERROR, ("hasn't found icon", icon, "for category", category)); + }; + } + void SkinGenerator::processSymbols(string const & svgDataDir, string const & skinName, vector<QSize> const & symbolSizes, diff --git a/skin_generator/skin_generator.hpp b/skin_generator/skin_generator.hpp index c0cec52a6c..96e81d428c 100644 --- a/skin_generator/skin_generator.hpp +++ b/skin_generator/skin_generator.hpp @@ -98,6 +98,12 @@ namespace tools string const & skinName, vector<QSize> const & symbolSizes, vector<string> const & suffix); + + void processSearchIcons(string const & symbolsDir, + string const & searchCategories, + string const & searchIconsPath, + int searchIconWidth, + int searchIconHeight); void renderPages(); bool writeToFile(string const & skinName); }; |