summaryrefslogtreecommitdiff
path: root/wx+/image_tools.cpp
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-04-18 09:47:11 -0400
committerB. Stack <bgstack15@gmail.com>2022-04-18 09:47:40 -0400
commitb4b2e4a096fe8fe1ad530a4c181729be05834595 (patch)
tree84e67ca0a1fb045a12d015fcffca9cd8087c9332 /wx+/image_tools.cpp
parentMerge branch 'b11.18' into 'master' (diff)
downloadFreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.tar.gz
FreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.tar.bz2
FreeFileSync-b4b2e4a096fe8fe1ad530a4c181729be05834595.zip
add upstream 11.20
Diffstat (limited to 'wx+/image_tools.cpp')
-rw-r--r--wx+/image_tools.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/wx+/image_tools.cpp b/wx+/image_tools.cpp
index b8876dc3..335cf7b9 100644
--- a/wx+/image_tools.cpp
+++ b/wx+/image_tools.cpp
@@ -7,6 +7,7 @@
#include "image_tools.h"
#include <zen/string_tools.h>
#include <zen/zstring.h>
+#include <zen/scope_guard.h>
#include <wx/app.h>
#include <xBRZ/src/xbrz_tools.h>
@@ -113,19 +114,6 @@ void copyImageLayover(const wxImage& src,
}
}
}
-
-
-std::vector<std::pair<wxString, wxSize>> getTextExtentInfo(const wxString& text, const wxFont& font)
-{
- wxMemoryDC dc; //the context used for bitmaps
- dc.SetFont(font); //the font parameter of GetMultiLineTextExtent() is not evaluated on OS X, wxWidgets 2.9.5, so apply it to the DC directly!
-
- std::vector<std::pair<wxString, wxSize>> lineInfo; //text + extent
- for (const wxString& line : split(text, L'\n', SplitOnEmpty::allow))
- lineInfo.emplace_back(line, line.empty() ? wxSize() : dc.GetTextExtent(line));
-
- return lineInfo;
-}
}
@@ -180,7 +168,13 @@ wxImage zen::stackImages(const wxImage& img1, const wxImage& img2, ImageStackLay
wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const wxColor& col, ImageStackAlignment textAlign)
{
- const std::vector<std::pair<wxString, wxSize>> lineInfo = getTextExtentInfo(text, font);
+ wxMemoryDC dc; //the context used for bitmaps
+ dc.SetFont(font); //the font parameter of GetMultiLineTextExtent() is not evaluated on OS X, wxWidgets 2.9.5, so apply it to the DC directly!
+
+ std::vector<std::pair<wxString, wxSize>> lineInfo; //text + extent
+ for (const wxString& line : split(text, L'\n', SplitOnEmpty::allow))
+ lineInfo.emplace_back(line, line.empty() ? wxSize() : dc.GetTextExtent(line));
+ //------------------------------------------------------------------------------------------------
int maxWidth = 0;
int lineHeight = 0;
@@ -194,7 +188,8 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const
wxBitmap newBitmap(maxWidth, lineHeight * lineInfo.size()); //seems we don't need to pass 24-bit depth here even for high-contrast color schemes
{
- wxMemoryDC dc(newBitmap);
+ dc.SelectObject(newBitmap);
+ ZEN_ON_SCOPE_EXIT(dc.SelectObject(wxNullBitmap));
if (wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft)
dc.SetLayoutDirection(wxLayout_RightToLeft); //handle e.g. "weak" bidi characters: -> arrows in hebrew/arabic
@@ -204,7 +199,6 @@ wxImage zen::createImageFromText(const wxString& text, const wxFont& font, const
dc.SetTextForeground(*wxBLACK); //for proper alpha-channel calculation
dc.SetTextBackground(*wxWHITE); //
- dc.SetFont(font);
int posY = 0;
for (const auto& [lineText, lineSize] : lineInfo)
bgstack15