From e38c8f283da7daf2d6530361ae301cdec8d804bc Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Fri, 2 Sep 2022 17:15:34 +0200 Subject: [PATCH] +fix: try to fix printing scaling issue --- scintilla/src/Editor.cxx | 18 +++++++++++------- scintilla/src/Editor.h | 10 +++++++--- scintilla/src/Platform.h | 4 +++- scintilla/win32/PlatWin.cxx | 27 ++++++++++++++++++--------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 4a4a3ac16..8b4d108dc 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -1846,8 +1846,10 @@ Sci::Position Editor::FormatRange(Scintilla::Message iMessage, Scintilla::uptr_t if (iMessage == Message::FormatRange) { RangeToFormat *pfr = static_cast(ptr); CharacterRangeFull chrg{ pfr->chrg.cpMin,pfr->chrg.cpMax }; - AutoSurface surface(pfr->hdc, this, Technology::Default); - AutoSurface surfaceMeasure(pfr->hdcTarget, this, Technology::Default); + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + AutoSurface surface(pfr->hdc, this, Technology::Default, true); + AutoSurface surfaceMeasure(pfr->hdcTarget, this, Technology::Default, true); + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< if (!surface || !surfaceMeasure) { return 0; } @@ -5767,15 +5769,17 @@ std::unique_ptr Editor::CreateMeasurementSurface() const { return surf; } -std::unique_ptr Editor::CreateDrawingSurface(SurfaceID sid, std::optional technologyOpt) const { +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> +std::unique_ptr Editor::CreateDrawingSurface(SurfaceID sid, std::optional technologyOpt, bool printing) const { if (!wMain.GetID()) { return {}; } std::unique_ptr surf = Surface::Allocate(technologyOpt ? *technologyOpt : technology); - surf->Init(sid, wMain.GetID()); + surf->Init(sid, wMain.GetID(), printing); surf->SetMode(CurrentSurfaceMode()); return surf; } +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< Sci::Line Editor::WrapCount(Sci::Line line) { AutoSurface surface(this); @@ -5903,7 +5907,7 @@ sptr_t Editor::StyleGetMessage(Message iMessage, uptr_t wParam, sptr_t lParam) { // Added strike style, 2020-05-31 case Message::StyleGetStrike: return vs.styles[wParam].strike ? 1 : 0; -// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< case Message::StyleGetCase: return static_cast(vs.styles[wParam].caseForce); case Message::StyleGetCharacterSet: @@ -7087,13 +7091,13 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::GetIMEInteraction: return static_cast(imeInteraction); -// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> case Message::IsIMEOpen: return static_cast(imeIsOpen); case Message::IsIMEModeCJK: return static_cast(imeIsInModeCJK); -// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< case Message::SetBidirectional: // Message::SetBidirectional is implemented on platform subclasses if they support bidirectional text. diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 77d86b741..2a1614d30 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -599,7 +599,9 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual std::string UTF8FromEncoded(std::string_view encoded) const = 0; virtual std::string EncodedFromUTF8(std::string_view utf8) const = 0; virtual std::unique_ptr CreateMeasurementSurface() const; - virtual std::unique_ptr CreateDrawingSurface(SurfaceID sid, std::optional technologyOpt = {}) const; + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + virtual std::unique_ptr CreateDrawingSurface(SurfaceID sid, std::optional technologyOpt = {}, bool printing = false) const; + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< Sci::Line WrapCount(Sci::Line line); void AddStyledText(const char *buffer, Sci::Position appendLength); @@ -695,9 +697,11 @@ public: AutoSurface(const Editor *ed) : surf(ed->CreateMeasurementSurface()) { } - AutoSurface(SurfaceID sid, Editor *ed, std::optional technology = {}) : - surf(ed->CreateDrawingSurface(sid, technology)) { + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + AutoSurface(SurfaceID sid, Editor *ed, std::optional technology = {}, bool printing = false) : + surf(ed->CreateDrawingSurface(sid, technology, printing)) { } + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< // Deleted so AutoSurface objects can not be copied. AutoSurface(const AutoSurface &) = delete; AutoSurface(AutoSurface &&) = delete; diff --git a/scintilla/src/Platform.h b/scintilla/src/Platform.h index eda481a0d..2b0d62947 100644 --- a/scintilla/src/Platform.h +++ b/scintilla/src/Platform.h @@ -199,7 +199,9 @@ public: static std::unique_ptr Allocate(Scintilla::Technology technology); virtual void Init(WindowID wid)=0; - virtual void Init(SurfaceID sid, WindowID wid)=0; +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + virtual void Init(SurfaceID sid, WindowID wid, bool printing = false)=0; +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< virtual std::unique_ptr AllocatePixMap(int width, int height)=0; virtual void SetMode(SurfaceMode mode)=0; diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 39eca1ebc..d439fed27 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -125,11 +125,11 @@ void LoadD2DOnce() noexcept { __uuidof(IDWriteFactory), reinterpret_cast(&pIDWriteFactory)); } - // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> if (SUCCEEDED(hr)) { pIDWriteFactory->GetGdiInterop(&gdiInterop); } - // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< } } @@ -686,7 +686,9 @@ public: ~SurfaceGDI() noexcept override; void Init(WindowID wid) override; - void Init(SurfaceID sid, WindowID wid) override; + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + void Init(SurfaceID sid, WindowID wid, bool printing = false) override; + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< std::unique_ptr AllocatePixMap(int width, int height) override; void SetMode(SurfaceMode mode_) override; @@ -813,14 +815,16 @@ void SurfaceGDI::Init(WindowID wid) { logPixelsY = DpiForWindow(wid); } -void SurfaceGDI::Init(SurfaceID sid, WindowID wid) { +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> +void SurfaceGDI::Init(SurfaceID sid, WindowID wid, bool printing) { Release(); hdc = static_cast(sid); - ::SetTextAlign(hdc, TA_BASELINE); // Windows on screen are scaled but printers are not. - const bool printing = ::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY; + //const bool printing = ::GetDeviceCaps(hdc, TECHNOLOGY) != DT_RASDISPLAY; logPixelsY = printing ? ::GetDeviceCaps(hdc, LOGPIXELSY) : DpiForWindow(wid); + ::SetTextAlign(hdc, TA_BASELINE); } +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< std::unique_ptr SurfaceGDI::AllocatePixMap(int width, int height) { return std::make_unique(hdc, width, height, mode, logPixelsY); @@ -1517,7 +1521,9 @@ public: void SetScale(WindowID wid) noexcept; void Init(WindowID wid) override; - void Init(SurfaceID sid, WindowID wid) override; + // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> + void Init(SurfaceID sid, WindowID wid, bool printing = false) override; + // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< std::unique_ptr AllocatePixMap(int width, int height) override; void SetMode(SurfaceMode mode_) override; @@ -1647,11 +1653,14 @@ void SurfaceD2D::Init(WindowID wid) { SetScale(wid); } -void SurfaceD2D::Init(SurfaceID sid, WindowID wid) { +// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> +void SurfaceD2D::Init(SurfaceID sid, WindowID wid, bool /*printing*/) { Release(); + // printing always using GDI + pRenderTarget = static_cast(sid); SetScale(wid); - pRenderTarget = static_cast(sid); } +// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< std::unique_ptr SurfaceD2D::AllocatePixMap(int width, int height) { std::unique_ptr surf = std::make_unique(pRenderTarget, width, height, mode, logPixelsY);