Skip to content

Commit

Permalink
Fix multi-line text on PixelOverlayModel
Browse files Browse the repository at this point in the history
(cherry picked from commit 293ed4f48ed4b1b8e4612111903f9f37a3e54e9e)
  • Loading branch information
dkulp committed Jan 28, 2020
1 parent b72af8b commit ac73720
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/PixelOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,18 @@ void PixelOverlayModel::doText(const std::string &msg,
int lines = 1;
int last = 0;
for (int x = 0; x < msg.length(); x++) {
if (msg[x] == '\n') {
if (msg[x] == '\n' || ((x < msg.length() - 1) && msg[x] == '\\' && msg[x+1] == 'n')) {
lines++;
std::string newM = msg.substr(last, x);
Magick::TypeMetric metrics;
image.fontTypeMetrics(newM, &metrics);
maxWid = std::max(maxWid, (int)metrics.textWidth());
totalHi += (int)metrics.textHeight();
last = x + 1;
if (msg[x] == '\n') {
last = x + 1;
} else {
last = x + 2;
}
}
}
std::string newM = msg.substr(last);
Expand Down Expand Up @@ -243,7 +247,6 @@ void PixelOverlayModel::doText(const std::string &msg,
rg /= 255.0f;
rb /= 255.0f;


Magick::Image image2(Magick::Geometry(maxWid, totalHi), Magick::Color("black"));
image2.quiet(true);
image2.depth(8);
Expand Down

0 comments on commit ac73720

Please sign in to comment.