Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable random color picker and use black text #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/mask_word_cloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
rd(std::random_device()()),
vertical_preference(vertical_preference),
words_margin(words_margin),
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/mask_word_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MaskWordCloud {
int words_margin;
int font_step, mini_font_sz;
bool useColorSurface;
bool randColorMode;

Cairo::RefPtr<Cairo::ImageSurface> overlapSurface;
Cairo::RefPtr<Cairo::ImageSurface> wordCloudSurface;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/maskwc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ 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";
}

int main (int argc, char **argv) {
Expand All @@ -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':
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down