From a453cc74747f7b017dfff9c8f5534ac032f68019 Mon Sep 17 00:00:00 2001 From: Dmitry Teplyakov Date: Mon, 21 Oct 2019 03:46:29 +0300 Subject: [PATCH 1/3] Disable random color picker and use black text --- src/mask_word_cloud.cc | 7 +++++-- src/mask_word_cloud.h | 3 ++- src/maskwc.cc | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mask_word_cloud.cc b/src/mask_word_cloud.cc index 4c55f5f..09a6736 100644 --- a/src/mask_word_cloud.cc +++ b/src/mask_word_cloud.cc @@ -26,7 +26,7 @@ MaskWordCloud::MaskWordCloud(const char *maskFilename, int R, int G, int B, int vertical_preference, int words_margin, - int font_step, int mini_font_sz) : + int font_step, int mini_font_sz, bool colorMode = true) : rd(std::random_device()()), vertical_preference(vertical_preference), words_margin(words_margin), @@ -43,6 +43,7 @@ MaskWordCloud::MaskWordCloud(const char *maskFilename, maxwidthrow = new int[height](); // initialized to zero useColorSurface = (colorFilename!=0 && strlen(colorFilename)>0); + randColorMode = colorMode; if (useColorSurface) { colorSurface = Cairo::ImageSurface::create_from_png(colorFilename); assert(width == colorSurface->get_width()); @@ -282,8 +283,10 @@ bool MaskWordCloud::paintWord(const char *text, double initialFontSz) { if (useColorSurface) { // expects upper left corner getMeanColor(bbposx,bbposy-bbHeight,bbWidth,bbHeight,r,g,b); - } else { + } else if(randColorMode) { pickRandomColor(r,g,b); + } else { + r = g = b = 0.0; } overlapCxt->move_to(textposx,textposy); diff --git a/src/mask_word_cloud.h b/src/mask_word_cloud.h index 50a6231..e830a1d 100644 --- a/src/mask_word_cloud.h +++ b/src/mask_word_cloud.h @@ -23,6 +23,7 @@ class MaskWordCloud { int words_margin; int font_step, mini_font_sz; bool useColorSurface; + bool randColorMode; Cairo::RefPtr overlapSurface; Cairo::RefPtr wordCloudSurface; @@ -74,7 +75,7 @@ class MaskWordCloud { int R, int G, int B, int vertical_preference, int words_margin, - int font_step, int mini_font_sz); + int font_step, int mini_font_sz, bool colorMode); ~MaskWordCloud(); bool paintWord(const char *text, double initialFontSz); void writeImage(const char *filename); diff --git a/src/maskwc.cc b/src/maskwc.cc index 6da117e..cbe4e40 100644 --- a/src/maskwc.cc +++ b/src/maskwc.cc @@ -38,6 +38,7 @@ void usage(const char *programname) { "\t[-d words_margin] \\ (default value is 2)\n" "\t[-v vertical_preference] \\ (value between 0 and 100, default is 50)\n" "\twords.txt (an ordered list of pairs word initial_size)\n"; + "\t[-С colorMode] \\ (Use random color pick: 0 - (using black text), (default: 1)\n"; } int main (int argc, char **argv) { @@ -55,8 +56,9 @@ int main (int argc, char **argv) { int font_step=2; int mini_font_size=2; int words_margin=2; + bool colorMode = 1; int opt; - while ((opt = getopt(argc, argv, "hr:g:b:m:R:G:B:c:f:s:M:o:d:v:")) != -1) { + while ((opt = getopt(argc, argv, "hr:g:b:m:R:G:B:c:f:s:M:o:d:v:C:")) != -1) { switch (opt) { case 'h': @@ -104,6 +106,9 @@ int main (int argc, char **argv) { case 'v': vertical_preference = atoi(optarg); break; + case 'C': + colorMode = atoi(optarg); + break; default: /* '?' */ usage(argv[0]); exit(EXIT_FAILURE); @@ -130,7 +135,7 @@ int main (int argc, char **argv) { R,G,B, vertical_preference, words_margin, - font_step,mini_font_size); + font_step,mini_font_size, colorMode); std::ifstream fs; fs.open(termsfilename); From 144fd48e44795615e25a5abf819936546b31a32c Mon Sep 17 00:00:00 2001 From: Dmitry Teplyakov Date: Mon, 21 Oct 2019 03:52:30 +0300 Subject: [PATCH 2/3] Remove diplcate default param --- src/mask_word_cloud.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mask_word_cloud.cc b/src/mask_word_cloud.cc index 09a6736..a759510 100644 --- a/src/mask_word_cloud.cc +++ b/src/mask_word_cloud.cc @@ -26,7 +26,7 @@ MaskWordCloud::MaskWordCloud(const char *maskFilename, int R, int G, int B, int vertical_preference, int words_margin, - int font_step, int mini_font_sz, bool colorMode = true) : + int font_step, int mini_font_sz, bool colorMode) : rd(std::random_device()()), vertical_preference(vertical_preference), words_margin(words_margin), From 2ecc3322234e288a52043fac416fda31aeddb06f Mon Sep 17 00:00:00 2001 From: Dmitry Teplyakov Date: Mon, 21 Oct 2019 03:54:35 +0300 Subject: [PATCH 3/3] Enable param to help --- src/maskwc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maskwc.cc b/src/maskwc.cc index cbe4e40..dfd7a18 100644 --- a/src/maskwc.cc +++ b/src/maskwc.cc @@ -37,7 +37,7 @@ void usage(const char *programname) { "\t[-o output_prefix] \\ (default \"output\" generate \"output.svg\" \"output.png\" and \"output.pdf\") \n" "\t[-d words_margin] \\ (default value is 2)\n" "\t[-v vertical_preference] \\ (value between 0 and 100, default is 50)\n" - "\twords.txt (an ordered list of pairs word initial_size)\n"; + "\twords.txt (an ordered list of pairs word initial_size)\n" "\t[-С colorMode] \\ (Use random color pick: 0 - (using black text), (default: 1)\n"; }