diff --git a/build/cmake/config.cmake b/build/cmake/config.cmake index 52ae69d3f6..b359560bc0 100644 --- a/build/cmake/config.cmake +++ b/build/cmake/config.cmake @@ -75,8 +75,8 @@ function(wx_write_config_inplace) endif() execute_process( COMMAND - ${CMAKE_COMMAND} -E ${COPY_CMD} - "lib/wx/config/inplace-${TOOLCHAIN_FULLNAME}" + "${CMAKE_COMMAND}" -E ${COPY_CMD} + "${CMAKE_CURRENT_BINARY_DIR}/lib/wx/config/inplace-${TOOLCHAIN_FULLNAME}" "${CMAKE_CURRENT_BINARY_DIR}/wx-config" ) endfunction() diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index d376b4c85e..3ff14ab91f 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -574,6 +574,14 @@ if(wxUSE_GUI) wx_option_force_value(wxUSE_SPELLCHECK OFF) endif() endif() + + if(wxUSE_CAIRO AND NOT WXGTK) + find_package(Cairo) + if(NOT CAIRO_FOUND) + message(WARNING "Cairo not found, Cairo renderer won't be available") + wx_option_force_value(wxUSE_CAIRO OFF) + endif() + endif() endif() # test if precompiled headers are supported using the cotire test project diff --git a/build/cmake/lib/core/CMakeLists.txt b/build/cmake/lib/core/CMakeLists.txt index acdf31a1b3..5080f20cf6 100644 --- a/build/cmake/lib/core/CMakeLists.txt +++ b/build/cmake/lib/core/CMakeLists.txt @@ -103,3 +103,7 @@ if(wxUSE_LIBNOTIFY) wx_lib_include_directories(wxcore ${LIBNOTIFY_INCLUDE_DIRS}) wx_lib_link_libraries(wxcore PUBLIC ${LIBNOTIFY_LIBRARIES}) endif() +if(wxUSE_CAIRO AND NOT WXGTK) + wx_lib_include_directories(wxcore ${CAIRO_INCLUDE_DIRS}) + # no libs, cairo is loaded dynamically +endif() diff --git a/build/cmake/lib/webview/CMakeLists.txt b/build/cmake/lib/webview/CMakeLists.txt index 0408ee7741..d42f6649d2 100644 --- a/build/cmake/lib/webview/CMakeLists.txt +++ b/build/cmake/lib/webview/CMakeLists.txt @@ -71,8 +71,8 @@ elseif(WXMSW) EXPECTED_HASH SHA256=${WEBVIEW2_SHA256}) file(MAKE_DIRECTORY ${WEBVIEW2_PACKAGE_DIR}) execute_process(COMMAND - ${CMAKE_COMMAND} -E tar x ${CMAKE_BINARY_DIR}/webview2.nuget - WORKING_DIRECTORY ${WEBVIEW2_PACKAGE_DIR} + "${CMAKE_COMMAND}" -E tar x "${CMAKE_BINARY_DIR}/webview2.nuget" + WORKING_DIRECTORY "${WEBVIEW2_PACKAGE_DIR}" ) endif() set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_PACKAGE_DIR} CACHE INTERNAL "" FORCE) diff --git a/build/cmake/modules/FindCairo.cmake b/build/cmake/modules/FindCairo.cmake new file mode 100644 index 0000000000..ddb3129bc7 --- /dev/null +++ b/build/cmake/modules/FindCairo.cmake @@ -0,0 +1,83 @@ +# - Try to find Cairo +# Once done, this will define +# +# CAIRO_FOUND - system has Cairo +# CAIRO_INCLUDE_DIRS - the Cairo include directories +# CAIRO_LIBRARIES - link these to use Cairo +# +# Copyright (C) 2012 Raphael Kubo da Costa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_CAIRO QUIET cairo) + +FIND_PATH(CAIRO_INCLUDE_DIRS + NAMES cairo.h + HINTS ${PC_CAIRO_INCLUDEDIR} + ${PC_CAIRO_INCLUDE_DIRS} + PATH_SUFFIXES cairo +) + +FIND_LIBRARY(CAIRO_LIBRARIES + NAMES cairo + HINTS ${PC_CAIRO_LIBDIR} + ${PC_CAIRO_LIBRARY_DIRS} +) + +IF (CAIRO_INCLUDE_DIRS) + IF (EXISTS "${CAIRO_INCLUDE_DIRS}/cairo-version.h") + FILE(READ "${CAIRO_INCLUDE_DIRS}/cairo-version.h" CAIRO_VERSION_CONTENT) + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MAJOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MAJOR "${CMAKE_MATCH_1}") + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MINOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MINOR "${CMAKE_MATCH_1}") + + STRING(REGEX MATCH "#define +CAIRO_VERSION_MICRO +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") + SET(CAIRO_VERSION_MICRO "${CMAKE_MATCH_1}") + + SET(CAIRO_VERSION "${CAIRO_VERSION_MAJOR}.${CAIRO_VERSION_MINOR}.${CAIRO_VERSION_MICRO}") + ENDIF () +ENDIF () + +# FIXME: Should not be needed anymore once we start depending on CMake 2.8.3 +SET(VERSION_OK TRUE) +IF (Cairo_FIND_VERSION) + IF (Cairo_FIND_VERSION_EXACT) + IF ("${Cairo_FIND_VERSION}" VERSION_EQUAL "${CAIRO_VERSION}") + # FIXME: Use IF (NOT ...) with CMake 2.8.2+ to get rid of the ELSE block + ELSE () + SET(VERSION_OK FALSE) + ENDIF () + ELSE () + IF ("${Cairo_FIND_VERSION}" VERSION_GREATER "${CAIRO_VERSION}") + SET(VERSION_OK FALSE) + ENDIF () + ENDIF () +ENDIF () + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cairo DEFAULT_MSG CAIRO_INCLUDE_DIRS CAIRO_LIBRARIES VERSION_OK) + +mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIES) diff --git a/build/cmake/modules/FindGNOMEVFS2.cmake b/build/cmake/modules/FindGNOMEVFS2.cmake index 1313975ea1..0d1b85bf8b 100644 --- a/build/cmake/modules/FindGNOMEVFS2.cmake +++ b/build/cmake/modules/FindGNOMEVFS2.cmake @@ -84,7 +84,6 @@ else (GNOMEVFS2_LIBRARIES AND GNOMEVFS2_INCLUDE_DIRS) endif (GNOMEVFS2_FOUND) # show the GNOMEVFS2_INCLUDE_DIRS and GNOMEVFS2_LIBRARIES variables only in the advanced view - mark_as_advanced(GNOMEVFS2_INCLUDE_DIRS GNOMEVFS2_LIBRARIES) + mark_as_advanced(GNOMEVFS2_INCLUDE_DIRS GNOMEVFS2_LIBRARIES GNOMEVFS2_INCLUDE_DIR GNOMEVFS-2_LIBRARY) endif (GNOMEVFS2_LIBRARIES AND GNOMEVFS2_INCLUDE_DIRS) - diff --git a/build/cmake/modules/FindGTK3.cmake b/build/cmake/modules/FindGTK3.cmake index 8fee6f9f41..d2939a1df5 100644 --- a/build/cmake/modules/FindGTK3.cmake +++ b/build/cmake/modules/FindGTK3.cmake @@ -49,3 +49,5 @@ check_symbol_exists(GDK_WINDOWING_WAYLAND "gdk/gdk.h" wxHAVE_GDK_WAYLAND) check_symbol_exists(GDK_WINDOWING_X11 "gdk/gdk.h" wxHAVE_GDK_X11) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK3 DEFAULT_MSG GTK3_INCLUDE_DIRS GTK3_LIBRARIES VERSION_OK) + +mark_as_advanced(GTK3_INCLUDE_DIRS GTK3_LIBRARIES) diff --git a/build/cmake/modules/FindGTK4.cmake b/build/cmake/modules/FindGTK4.cmake index ea8f07e6c0..7dc1ed09f3 100644 --- a/build/cmake/modules/FindGTK4.cmake +++ b/build/cmake/modules/FindGTK4.cmake @@ -44,3 +44,5 @@ endif () endif () include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK4 DEFAULT_MSG GTK4_INCLUDE_DIRS GTK4_LIBRARIES VERSION_OK) + +mark_as_advanced(GTK4_INCLUDE_DIRS GTK4_LIBRARIES) diff --git a/build/cmake/modules/FindLIBSECRET.cmake b/build/cmake/modules/FindLIBSECRET.cmake index af1e059fcb..6f064cb837 100644 --- a/build/cmake/modules/FindLIBSECRET.cmake +++ b/build/cmake/modules/FindLIBSECRET.cmake @@ -47,3 +47,5 @@ endif () include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBSECRET DEFAULT_MSG LIBSECRET_INCLUDE_DIRS LIBSECRET_LIBRARIES VERSION_OK) + +mark_as_advanced(LIBSECRET_INCLUDE_DIRS LIBSECRET_LIBRARIES) diff --git a/build/cmake/modules/FindWAYLANDEGL.cmake b/build/cmake/modules/FindWAYLANDEGL.cmake index 6ca89ef560..ad23bf94c2 100644 --- a/build/cmake/modules/FindWAYLANDEGL.cmake +++ b/build/cmake/modules/FindWAYLANDEGL.cmake @@ -16,3 +16,5 @@ endif () include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLANDEGL DEFAULT_MSG WAYLANDEGL_LIBRARIES VERSION_OK) + +mark_as_advanced(WAYLANDEGL_LIBRARIES) diff --git a/include/wx/dc.h b/include/wx/dc.h index d6c2881ef2..6ca1742f1d 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -539,7 +539,9 @@ public: virtual double GetContentScaleFactor() const { return m_contentScaleFactor; } - virtual double GetDPIScaleFactor() const { return 1.0; } + virtual wxSize FromDIP(const wxSize& sz) const; + + virtual wxSize ToDIP(const wxSize& sz) const; #ifdef __WXMSW__ // Native Windows functions using the underlying HDC don't honour GDI+ @@ -829,8 +831,29 @@ public: double GetContentScaleFactor() const { return m_pimpl->GetContentScaleFactor(); } - double GetDPIScaleFactor() const - { return m_pimpl->GetDPIScaleFactor(); } + wxSize FromDIP(const wxSize& sz) const + { return m_pimpl->FromDIP(sz); } + wxPoint FromDIP(const wxPoint& pt) const + { + const wxSize sz = FromDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int FromDIP(int d) const + { return FromDIP(wxSize(d, 0)).x; } + + wxSize ToDIP(const wxSize & sz) const + { + return m_pimpl->ToDIP(sz); + } + wxPoint ToDIP(const wxPoint & pt) const + { + const wxSize sz = ToDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int ToDIP(int d) const + { + return ToDIP(wxSize(d, 0)).x; + } // Right-To-Left (RTL) modes diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index a57e8168e1..29671a841b 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -101,7 +101,6 @@ public: virtual bool CanGetTextExtent() const wxOVERRIDE; virtual int GetDepth() const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE; - virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual void SetLogicalFunction(wxRasterOperationMode function) wxOVERRIDE; diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 16cbd185ba..fcdecc036c 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -248,6 +248,10 @@ private: virtual wxSize GetPPI() const wxOVERRIDE; + virtual wxSize FromDIP(const wxSize& sz) const wxOVERRIDE; + + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE; + void Init(const wxString& filename, int width, int height, double dpi, const wxString& title); diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h index 21c615781d..cf3e1356ff 100644 --- a/include/wx/generic/dcpsg.h +++ b/include/wx/generic/dcpsg.h @@ -76,6 +76,10 @@ public: // Resolution in pixels per logical inch wxSize GetPPI() const wxOVERRIDE; + virtual wxSize FromDIP(const wxSize& sz) const wxOVERRIDE; + + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE; + virtual void ComputeScaleAndOrigin() wxOVERRIDE; void SetBackgroundMode(int WXUNUSED(mode)) wxOVERRIDE { } diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 849e5353e9..e6b3b02196 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -739,6 +739,28 @@ public: // returns the resolution of the graphics context in device points per inch virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY) const; + wxSize FromDIP(const wxSize& sz) const; + wxPoint FromDIP(const wxPoint& pt) const + { + const wxSize sz = FromDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int FromDIP(int d) const + { + return FromDIP(wxSize(d, 0)).x; + } + + wxSize ToDIP(const wxSize& sz) const; + wxPoint ToDIP(const wxPoint& pt) const + { + const wxSize sz = ToDIP(wxSize(pt.x, pt.y)); + return wxPoint(sz.x, sz.y); + } + int ToDIP(int d) const + { + return ToDIP(wxSize(d, 0)).x; + } + #if 0 // sets the current alpha on this context virtual void SetAlpha( wxDouble alpha ); @@ -880,7 +902,6 @@ public: void SetContentScaleFactor(double contentScaleFactor); double GetContentScaleFactor() const { return m_contentScaleFactor; } - double GetDPIScaleFactor() const; #ifdef __WXMSW__ virtual WXHDC GetNativeHDC() = 0; diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index ae04c80566..6af3637c97 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -77,7 +77,6 @@ public: virtual bool CanGetTextExtent() const wxOVERRIDE; virtual int GetDepth() const wxOVERRIDE; virtual wxSize GetPPI() const wxOVERRIDE; - virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual void SetMapMode(wxMappingMode mode) wxOVERRIDE; virtual void SetUserScale(double x, double y) wxOVERRIDE; diff --git a/include/wx/msw/dcmemory.h b/include/wx/msw/dcmemory.h index 88547f314d..2fe0fadbce 100644 --- a/include/wx/msw/dcmemory.h +++ b/include/wx/msw/dcmemory.h @@ -22,12 +22,12 @@ public: wxMemoryDCImpl( wxMemoryDC *owner, wxDC *dc ); // Create compatible DC // override some base class virtuals + virtual wxSize GetPPI() const wxOVERRIDE; virtual void SetFont(const wxFont& font) wxOVERRIDE; virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) wxOVERRIDE; virtual void DoGetSize(int* width, int* height) const wxOVERRIDE; virtual void DoSelect(const wxBitmap& bitmap) wxOVERRIDE; - virtual double GetDPIScaleFactor() const wxOVERRIDE; virtual wxBitmap DoGetAsBitmap(const wxRect* subrect) const wxOVERRIDE { return subrect == NULL ? GetSelectedBitmap() : GetSelectedBitmap().GetSubBitmapOfHDC(*subrect, GetHDC() );} diff --git a/include/wx/msw/dcprint.h b/include/wx/msw/dcprint.h index adbfb0c632..845c0d64ab 100644 --- a/include/wx/msw/dcprint.h +++ b/include/wx/msw/dcprint.h @@ -36,6 +36,12 @@ public: virtual wxRect GetPaperRect() const wxOVERRIDE; + virtual wxSize FromDIP(const wxSize& sz) const wxOVERRIDE; + + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE; + + void SetFont(const wxFont& font) wxOVERRIDE; + protected: virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask = false) wxOVERRIDE; diff --git a/interface/wx/dc.h b/interface/wx/dc.h index 6d1b214575..6235811e42 100644 --- a/interface/wx/dc.h +++ b/interface/wx/dc.h @@ -1562,17 +1562,52 @@ public: wxSize GetPPI() const; /** - Returns the DPI scale factor. + Convert DPI-independent pixel values to the value in pixels appropriate + for the DC. - Can be used to scale coordinates and sizes appropriate to the DPI of the - associated wxWindow, if any. + See wxWindow::FromDIP(const wxSize& sz) for more info about converting + device independent pixel values. - See wxWindow::GetDPIScaleFactor() for more details about the DPI scale - factor and its difference with GetContentScaleFactor(). + @since 3.1.7 + */ + wxSize FromDIP(const wxSize& sz) const; - @since 3.1.7 - */ - double GetDPIScaleFactor() const; + /// @overload + wxPoint FromDIP(const wxPoint& pt) const; + + /** + Convert DPI-independent value in pixels to the value in pixels + appropriate for the DC. + + This is the same as FromDIP(const wxSize& sz) overload, but assumes + that the resolution is the same in horizontal and vertical directions. + + @since 3.1.7 + */ + int FromDIP(int d) const; + + /** + Convert pixel values of the current DC to DPI-independent pixel values. + + See wxWindow::ToDIP(const wxSize& sz) for more info about converting + device independent pixel values. + + @since 3.1.7 + */ + wxSize ToDIP(const wxSize& sz) const; + + /// @overload + wxPoint ToDIP(const wxPoint& pt) const; + + /** + Convert pixel values of the current DC to DPI-independent pixel values. + + This is the same as ToDIP(const wxSize& sz) overload, but assumes + that the resolution is the same in horizontal and vertical directions. + + @since 3.1.7 + */ + int ToDIP(int d) const; /** Gets the horizontal and vertical extent of this device context in @e device units. diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 11809fa4f1..adb56efa86 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -1157,12 +1157,54 @@ public: bool OffsetEnabled() const; /** - Get the DPI scale factor. Can be used to scale coordinates and sizes - appropriate to the DPI of the associated wxWindow or wxDC. + Convert DPI-independent pixel values to the value in pixels appropriate + for the graphics context. + + See wxWindow::FromDIP(const wxSize& sz) and wxDC::FromDIP(const wxSize& sz) + for more info about converting device independent pixel values. @since 3.1.7 - */ - double GetDPIScaleFactor() const; + */ + wxSize FromDIP(const wxSize& sz) const; + + /// @overload + wxPoint FromDIP(const wxPoint& pt) const; + + /** + Convert DPI-independent value in pixels to the value in pixels + appropriate for the graphics context. + + This is the same as FromDIP(const wxSize& sz) overload, but assumes + that the resolution is the same in horizontal and vertical directions. + + @since 3.1.7 + */ + int FromDIP(int d) const; + + /** + Convert pixel values of the current graphics context to DPI-independent + pixel values. + + See wxWindow::ToDIP(const wxSize& sz) and wxDC::ToDIP(const wxSize& sz) + for more info about converting device independent pixel values. + + @since 3.1.7 + */ + wxSize ToDIP(const wxSize& sz) const; + + /// @overload + wxPoint ToDIP(const wxPoint& pt) const; + + /** + Convert pixel values of the current graphics context to DPI-independent + pixel values. + + This is the same as ToDIP(const wxSize& sz) overload, but assumes + that the resolution is the same in horizontal and vertical directions. + + @since 3.1.7 + */ + int ToDIP(int d) const; /** @} */ diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 7329efa2ff..b190c1e6c8 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -125,7 +125,7 @@ public: #endif // wxUSE_GRAPHICS_CONTEXT void UseBuffer(bool use) { m_useBuffer = use; Refresh(); } void ShowBoundingBox(bool show) { m_showBBox = show; Refresh(); } - void GetDrawingSize(int* width, int* height) const; + wxSize GetDIPDrawingSize() const; void Draw(wxDC& dc); @@ -175,8 +175,7 @@ private: #endif bool m_useBuffer; bool m_showBBox; - wxCoord m_sizeX; - wxCoord m_sizeY; + wxSize m_sizeDIP; wxDECLARE_EVENT_TABLE(); }; @@ -187,7 +186,7 @@ class MyFrame : public wxFrame { public: // ctor(s) - MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); + MyFrame(const wxString& title); // event handlers (these functions should _not_ be virtual) void OnQuit(wxCommandEvent& event); @@ -461,8 +460,7 @@ bool MyApp::OnInit() #endif // Create the main application window - MyFrame *frame = new MyFrame("Drawing sample", - wxDefaultPosition, wxSize(550, 840)); + MyFrame *frame = new MyFrame("Drawing sample"); // Show it frame->Show(true); @@ -522,8 +520,7 @@ MyCanvas::MyCanvas(MyFrame *parent) #endif m_useBuffer = false; m_showBBox = false; - m_sizeX = 0; - m_sizeY = 0; + m_sizeDIP = wxSize(0, 0); } void MyCanvas::DrawTestBrushes(wxDC& dc) @@ -574,40 +571,38 @@ void MyCanvas::DrawTestPoly(wxDC& dc) wxBrush brushHatch(*wxRED, wxBRUSHSTYLE_FDIAGONAL_HATCH); dc.SetBrush(brushHatch); - double scale = dc.GetDPIScaleFactor(); - wxPoint star[5]; - star[0] = scale * wxPoint(100, 60); - star[1] = scale * wxPoint(60, 150); - star[2] = scale * wxPoint(160, 100); - star[3] = scale * wxPoint(40, 100); - star[4] = scale * wxPoint(140, 150); + star[0] = dc.FromDIP(wxPoint(100, 60)); + star[1] = dc.FromDIP(wxPoint(60, 150)); + star[2] = dc.FromDIP(wxPoint(160, 100)); + star[3] = dc.FromDIP(wxPoint(40, 100)); + star[4] = dc.FromDIP(wxPoint(140, 150)); dc.DrawText("You should see two (irregular) stars below, the left one " - "hatched", scale * 10, scale * 10); + "hatched", dc.FromDIP(10), dc.FromDIP(10)); dc.DrawText("except for the central region and the right " - "one entirely hatched", scale * 10, scale * 30); - dc.DrawText("The third star only has a hatched outline", scale * 10, scale* 50); + "one entirely hatched", dc.FromDIP(10), dc.FromDIP(30)); + dc.DrawText("The third star only has a hatched outline", dc.FromDIP(10), dc.FromDIP(50)); - dc.DrawPolygon(WXSIZEOF(star), star, scale * 0, scale * 30); - dc.DrawPolygon(WXSIZEOF(star), star, scale * 160, scale * 30, wxWINDING_RULE); + dc.DrawPolygon(WXSIZEOF(star), star, 0, dc.FromDIP(30)); + dc.DrawPolygon(WXSIZEOF(star), star, dc.FromDIP(160), dc.FromDIP(30), wxWINDING_RULE); wxBrush brushHatchGreen(*wxGREEN, wxBRUSHSTYLE_FDIAGONAL_HATCH); dc.SetBrush(brushHatchGreen); wxPoint star2[10]; - star2[0] = scale * wxPoint(0, 100); - star2[1] = scale * wxPoint(-59, -81); - star2[2] = scale * wxPoint(95, 31); - star2[3] = scale * wxPoint(-95, 31); - star2[4] = scale * wxPoint(59, -81); - star2[5] = scale * wxPoint(0, 80); - star2[6] = scale * wxPoint(-47, -64); - star2[7] = scale * wxPoint(76, 24); - star2[8] = scale * wxPoint(-76, 24); - star2[9] = scale * wxPoint(47, -64); + star2[0] = dc.FromDIP(wxPoint(0, 100)); + star2[1] = dc.FromDIP(wxPoint(-59, -81)); + star2[2] = dc.FromDIP(wxPoint(95, 31)); + star2[3] = dc.FromDIP(wxPoint(-95, 31)); + star2[4] = dc.FromDIP(wxPoint(59, -81)); + star2[5] = dc.FromDIP(wxPoint(0, 80)); + star2[6] = dc.FromDIP(wxPoint(-47, -64)); + star2[7] = dc.FromDIP(wxPoint(76, 24)); + star2[8] = dc.FromDIP(wxPoint(-76, 24)); + star2[9] = dc.FromDIP(wxPoint(47, -64)); int count[2] = {5, 5}; - dc.DrawPolyPolygon(WXSIZEOF(count), count, star2, scale * 450, scale * 150); + dc.DrawPolyPolygon(WXSIZEOF(count), count, star2, dc.FromDIP(450), dc.FromDIP(150)); } void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) @@ -1810,13 +1805,9 @@ void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime) } } -void MyCanvas::GetDrawingSize(int* width, int* height) const +wxSize MyCanvas::GetDIPDrawingSize() const { - if ( width ) - *width = m_sizeX; - - if ( height ) - *height = m_sizeY; + return m_sizeDIP; } void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) @@ -1836,7 +1827,7 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) void MyCanvas::Draw(wxDC& pdc) { #if wxUSE_GRAPHICS_CONTEXT - wxGCDC gdc(this); + wxGCDC gdc; if ( m_renderer ) { @@ -1896,7 +1887,10 @@ void MyCanvas::Draw(wxDC& pdc) } if ( m_clip ) - dc.SetClippingRegion(100, 100, 100, 100); + { + dc.SetClippingRegion(wxPoint(dc.FromDIP(100), dc.FromDIP(100)), + wxSize(dc.FromDIP(100), dc.FromDIP(100))); + } dc.Clear(); @@ -1904,7 +1898,7 @@ void MyCanvas::Draw(wxDC& pdc) { dc.SetPen(*wxMEDIUM_GREY_PEN); for ( int i = 0; i < 200; i++ ) - dc.DrawLine(0, i*10, i*10, 0); + dc.DrawLine(0, dc.FromDIP(i*10), dc.FromDIP(i*10), 0); } switch ( m_show ) @@ -1999,8 +1993,8 @@ void MyCanvas::Draw(wxDC& pdc) { wxCoord x0, y0; dc.GetDeviceOrigin(&x0, &y0); - m_sizeX = dc.LogicalToDeviceX(dc.MaxX()) - x0 + 1; - m_sizeY = dc.LogicalToDeviceY(dc.MaxY()) - y0 + 1; + m_sizeDIP.x = dc.ToDIP(dc.LogicalToDeviceX(dc.MaxX()) - x0) + 1; + m_sizeDIP.y = dc.ToDIP(dc.LogicalToDeviceY(dc.MaxY()) - y0) + 1; } } @@ -2013,8 +2007,11 @@ void MyCanvas::OnMouseMove(wxMouseEvent &event) m_owner->PrepareDC(dc); wxPoint pos = dc.DeviceToLogical(event.GetPosition()); + wxPoint dipPos = dc.ToDIP(pos); wxString str; - str.Printf( "Current mouse position: %d,%d", pos.x, pos.y ); + str.Printf( "Mouse position: %d,%d", pos.x, pos.y ); + if ( pos != dipPos ) + str += wxString::Format("; DIP position: %d,%d", dipPos.x, dipPos.y); m_owner->SetStatusText( str ); } @@ -2230,8 +2227,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) wxEND_EVENT_TABLE() // frame constructor -MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) +MyFrame::MyFrame(const wxString& title) + : wxFrame(NULL, wxID_ANY, title) { // set the frame icon SetIcon(wxICON(sample)); @@ -2402,6 +2399,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) m_canvas = new MyCanvas( this ); m_canvas->SetScrollbars( 10, 10, 100, 240 ); + + SetSize(FromDIP(wxSize(800, 700))); + Center(wxBOTH); } // event handlers @@ -2467,8 +2467,7 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event)) wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if (dlg.ShowModal() == wxID_OK) { - int width, height; - m_canvas->GetDrawingSize(&width, &height); + wxSize canvasSize = m_canvas->GetDIPDrawingSize(); wxFileName fn(dlg.GetPath()); wxString ext = fn.GetExt().Lower(); #if wxUSE_SVG @@ -2483,7 +2482,11 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event)) wxGraphicsRenderer* tempRenderer = m_canvas->GetRenderer(); m_canvas->UseGraphicRenderer(NULL); #endif - wxSVGFileDC svgdc(dlg.GetPath(), width, height, 72, "Drawing sample"); + wxSVGFileDC svgdc(dlg.GetPath(), + canvasSize.GetWidth(), + canvasSize.GetHeight(), + 72, + "Drawing sample"); svgdc.SetBitmapHandler(new wxSVGBitmapEmbedHandler()); m_canvas->Draw(svgdc); #if wxUSE_GRAPHICS_CONTEXT @@ -2517,7 +2520,7 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event)) // Change the scale temporarily to fit the drawing into the page. int w, h; psdc.GetSize(&w, &h); - double sc = wxMin((double)w / width, (double)h / height); + double sc = wxMin((double)w / canvasSize.GetWidth(), (double)h / canvasSize.GetHeight()); m_xUserScale *= sc; m_yUserScale *= sc; psdc.StartDoc("Drawing sample"); @@ -2538,7 +2541,7 @@ void MyFrame::OnSave(wxCommandEvent& WXUNUSED(event)) #endif // wxUSE_POSTSCRIPT { wxBitmap bmp; - bmp.CreateWithDIPSize(wxSize(width, height), GetDPIScaleFactor()); + bmp.CreateWithDIPSize(canvasSize, GetDPIScaleFactor()); wxMemoryDC mdc(bmp); mdc.SetBackground(*wxWHITE_BRUSH); mdc.Clear(); @@ -2726,7 +2729,7 @@ void MyFrame::PrepareDC(wxDC& dc) dc.SetTransformMatrix(mtx); } #endif // wxUSE_DC_TRANSFORM_MATRIX - dc.SetLogicalOrigin( m_xLogicalOrigin, m_yLogicalOrigin ); + dc.SetLogicalOrigin( dc.FromDIP(m_xLogicalOrigin), dc.FromDIP(m_yLogicalOrigin) ); dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed ); dc.SetUserScale( m_xUserScale, m_yUserScale ); dc.SetMapMode( m_mapMode ); diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 59a546c0f4..8d8b4a361d 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -110,10 +110,7 @@ bool MyApp::OnInit(void) // Create the main frame window // ---------------------------- - MyFrame* frame = new MyFrame((wxFrame *) NULL, "wxWidgets Printing Demo", - wxPoint(0, 0), wxSize(400, 400)); - - frame->Centre(wxBOTH); + MyFrame* frame = new MyFrame("wxWidgets Printing Demo"); frame->Show(); return true; @@ -142,79 +139,79 @@ void MyApp::Draw(wxDC&dc) dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); - dc.DrawRectangle(0, 0, 230, 350); - dc.DrawLine(0, 0, 229, 349); - dc.DrawLine(229, 0, 0, 349); + dc.DrawRectangle(0, 0, dc.FromDIP(230), dc.FromDIP(350)); + dc.DrawLine(0, 0, dc.FromDIP(229), dc.FromDIP(349)); + dc.DrawLine(dc.FromDIP(229), 0, 0, dc.FromDIP(349)); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); - dc.DrawRoundedRectangle(0, 20, 200, 80, 20); + dc.DrawRoundedRectangle(0, dc.FromDIP(20), dc.FromDIP(200), dc.FromDIP(80), 20); - dc.DrawText( "Rectangle 200 by 80", 40, 40); + dc.DrawText( "Rectangle 200 by 80", dc.FromDIP(40), dc.FromDIP(40)); dc.SetPen( wxPen(*wxBLACK, 0, wxPENSTYLE_DOT_DASH) ); - dc.DrawEllipse(50, 140, 100, 50); + dc.DrawEllipse(dc.FromDIP(50), dc.FromDIP(140), dc.FromDIP(100), dc.FromDIP(50)); dc.SetPen(*wxRED_PEN); - dc.DrawText( "Test message: this is in 10 point text", 10, 180); + dc.DrawText( "Test message: this is in 10 point text", dc.FromDIP(10), dc.FromDIP(180)); - dc.DrawRotatedText( "This\nis\na multi-line\ntext", 170, 100, -m_angle/1.5); + dc.DrawRotatedText( "This\nis\na multi-line\ntext", dc.FromDIP(170), dc.FromDIP(100), -m_angle/1.5); #if wxUSE_UNICODE const char *test = "Hebrew שלום -- Japanese (日本語)"; wxString tmp = wxConvUTF8.cMB2WC( test ); - dc.DrawText( tmp, 10, 200 ); + dc.DrawText( tmp, dc.FromDIP(10), dc.FromDIP(200) ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; - points[1].x = 20; + points[1].x = dc.FromDIP(20); points[1].y = 0; - points[2].x = 20; - points[2].y = 20; - points[3].x = 10; - points[3].y = 20; - points[4].x = 10; - points[4].y = -20; - dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); - dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); + points[2].x = dc.FromDIP(20); + points[2].y = dc.FromDIP(20); + points[3].x = dc.FromDIP(10); + points[3].y = dc.FromDIP(20); + points[4].x = dc.FromDIP(10); + points[4].y = dc.FromDIP(-20); + dc.DrawPolygon( 5, points, dc.FromDIP(20), dc.FromDIP(250), wxODDEVEN_RULE ); + dc.DrawPolygon( 5, points, dc.FromDIP(50), dc.FromDIP(250), wxWINDING_RULE ); - dc.DrawArc( 20, 330, 40, 300, 20, 300 ); + dc.DrawArc( dc.FromDIP(20), dc.FromDIP(330), dc.FromDIP(40), dc.FromDIP(300), dc.FromDIP(20), dc.FromDIP(300) ); { wxDCBrushChanger changeBrush(dc, *wxTRANSPARENT_BRUSH); - dc.DrawArc( 60, 330, 80, 300, 60, 300 ); + dc.DrawArc( dc.FromDIP(60), dc.FromDIP(330), dc.FromDIP(80), dc.FromDIP(300), dc.FromDIP(60), dc.FromDIP(300) ); } - dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); + dc.DrawEllipticArc( dc.FromDIP(80), dc.FromDIP(250), dc.FromDIP(60), dc.FromDIP(30), 0.0, 270.0 ); - points[0].x = 150; - points[0].y = 250; - points[1].x = 180; - points[1].y = 250; - points[2].x = 180; - points[2].y = 220; - points[3].x = 200; - points[3].y = 220; + points[0].x = dc.FromDIP(150); + points[0].y = dc.FromDIP(250); + points[1].x = dc.FromDIP(180); + points[1].y = dc.FromDIP(250); + points[2].x = dc.FromDIP(180); + points[2].y = dc.FromDIP(220); + points[3].x = dc.FromDIP(200); + points[3].y = dc.FromDIP(220); dc.DrawSpline( 4, points ); wxString str; int i = 0; str.Printf( "---- Text at angle %d ----", i ); - dc.DrawRotatedText( str, 100, 300, i ); + dc.DrawRotatedText( str, dc.FromDIP(100), dc.FromDIP(300), i ); i = m_angle; str.Printf( "---- Text at angle %d ----", i ); - dc.DrawRotatedText( str, 100, 300, i ); + dc.DrawRotatedText( str, dc.FromDIP(100), dc.FromDIP(300), i ); wxIcon my_icon = wxICON(sample); - dc.DrawIcon( my_icon, 100, 100); + dc.DrawIcon( my_icon, dc.FromDIP(100), dc.FromDIP(100)); if (m_bitmap.IsOk()) - dc.DrawBitmap( m_bitmap, 10, 10 ); + dc.DrawBitmap( m_bitmap, dc.FromDIP(10), dc.FromDIP(10) ); #if wxUSE_GRAPHICS_CONTEXT wxScopedPtr gc(wxGraphicsContext::CreateFromUnknownDC(dc)); @@ -225,26 +222,26 @@ void MyApp::Draw(wxDC&dc) gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); - path.AddCircle( 50.0, 50.0, 50.0 ); - path.MoveToPoint(0.0, 50.0); - path.AddLineToPoint(100.0, 50.0); - path.MoveToPoint(50.0, 0.0); - path.AddLineToPoint(50.0, 100.0 ); + path.AddCircle( gc->FromDIP(50.0), gc->FromDIP(50.0), gc->FromDIP(50.0) ); + path.MoveToPoint(gc->FromDIP(0.0), gc->FromDIP(50.0)); + path.AddLineToPoint(gc->FromDIP(100.0), gc->FromDIP(50.0)); + path.MoveToPoint(gc->FromDIP(50.0), gc->FromDIP(0.0)); + path.AddLineToPoint(gc->FromDIP(50.0), gc->FromDIP(100.0) ); path.CloseSubpath(); - path.AddRectangle(25.0, 25.0, 50.0, 50.0); + path.AddRectangle(gc->FromDIP(25.0), gc->FromDIP(25.0), gc->FromDIP(50.0), gc->FromDIP(50.0)); gc->StrokePath(path); // draw some text wxString text("Text by wxGraphicsContext"); gc->SetFont( m_testFont, *wxBLACK ); - gc->DrawText(text, 25.0, 60.0); + gc->DrawText(text, gc->FromDIP(25.0), gc->FromDIP(60.0)); // draw rectangle around the text double w, h; gc->GetTextExtent(text, &w, &h); gc->SetPen( *wxBLACK_PEN ); - gc->DrawRectangle(25.0, 60.0, w, h); + gc->DrawRectangle(gc->FromDIP(25.0), gc->FromDIP(60.0), w, h); } #endif @@ -277,8 +274,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) MyFrame::OnPreviewFrameModalityKind) wxEND_EVENT_TABLE() -MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const wxSize&size) - : wxFrame(frame, wxID_ANY, title, pos, size) +MyFrame::MyFrame(const wxString& title) + : wxFrame(NULL, wxID_ANY, title) { m_canvas = NULL; m_previewModality = wxPreviewFrame_AppModal; @@ -343,11 +340,13 @@ MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const // create the canvas // ----------------- - m_canvas = new MyCanvas(this, wxPoint(0, 0), wxSize(100, 100), - wxRETAINED|wxHSCROLL|wxVSCROLL); + m_canvas = new MyCanvas(this, wxRETAINED | wxHSCROLL | wxVSCROLL); // Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction m_canvas->SetScrollbars(20, 20, 50, 50); + + SetSize(FromDIP(wxSize(400, 400))); + Centre(wxBOTH); } void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event)) @@ -392,7 +391,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) } wxPreviewFrame *frame = - new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); + new wxPreviewFrame(preview, this, "Demo Print Preview", wxDefaultPosition, FromDIP(wxSize(600, 700))); frame->Centre(wxBOTH); frame->InitializeWithModality(m_previewModality); frame->Show(); @@ -427,7 +426,7 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) wxPrintDialogData printDialogData(* g_printData); wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this), new MyPrintout(this), &printDialogData); wxPreviewFrame *frame = - new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); + new wxPreviewFrame(preview, this, "Demo Print Preview", wxDefaultPosition, FromDIP(wxSize(600, 700))); frame->Centre(wxBOTH); frame->Initialize(); frame->Show(); @@ -491,8 +490,8 @@ wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) // EVT_PAINT(MyCanvas::OnPaint) wxEND_EVENT_TABLE() -MyCanvas::MyCanvas(wxFrame *frame, const wxPoint&pos, const wxSize&size, long style) - : wxScrolledWindow(frame, wxID_ANY, pos, size, style) +MyCanvas::MyCanvas(wxFrame *frame, long style) + : wxScrolledWindow(frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) { SetBackgroundColour(*wxWHITE); } @@ -560,8 +559,8 @@ void MyPrintout::DrawPageOne() // We know the graphic is 230x350. If we didn't know this, we'd need to // calculate it. - wxCoord maxX = 230; - wxCoord maxY = 350; + wxCoord maxX = GetDC()->FromDIP(230); + wxCoord maxY = GetDC()->FromDIP(350); // This sets the user scale and origin of the DC so that the image fits // within the paper rectangle (but the edges could be cut off by printers diff --git a/samples/printing/printing.h b/samples/printing/printing.h index 7d04618673..46747cc2bc 100644 --- a/samples/printing/printing.h +++ b/samples/printing/printing.h @@ -40,7 +40,7 @@ class MyCanvas; class MyFrame: public wxFrame { public: - MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size); + MyFrame(const wxString& title); void OnAngleUp(wxCommandEvent& event); void OnAngleDown(wxCommandEvent& event); @@ -73,7 +73,7 @@ private: class MyCanvas: public wxScrolledWindow { public: - MyCanvas(wxFrame *frame, const wxPoint& pos, const wxSize& size, long style = wxRETAINED); + MyCanvas(wxFrame *frame, long style); //void OnPaint(wxPaintEvent& evt); virtual void OnDraw(wxDC& dc) wxOVERRIDE; diff --git a/samples/sample.rc b/samples/sample.rc index 8d8636a72d..68fe34e2f8 100644 --- a/samples/sample.rc +++ b/samples/sample.rc @@ -26,7 +26,9 @@ sample ICON "sample.ico" #define wxUSE_NO_MANIFEST 0 // To get DPI change events, we need to opt in into per monitor DPI support. +#ifndef wxUSE_DPI_AWARE_MANIFEST #define wxUSE_DPI_AWARE_MANIFEST 2 +#endif // this is not always needed but doesn't hurt (except making the executable // very slightly larger): this file contains the standard icons, cursors, ... diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 82be5c669d..2090be4818 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -36,6 +36,8 @@ #endif #include "wx/private/textmeasure.h" +#include "wx/private/rescale.h" +#include "wx/display.h" #ifdef __WXMSW__ #include "wx/msw/dcclient.h" @@ -604,6 +606,28 @@ void wxDCImpl::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) ComputeScaleAndOrigin(); } +wxSize wxDCImpl::FromDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + const wxSize dpi = GetPPI(); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(baseline).To(dpi); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS +} + +wxSize wxDCImpl::ToDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + const wxSize dpi = GetPPI(); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(dpi).To(baseline); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS +} + bool wxDCImpl::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const { wxTextMeasure tm(GetOwner(), &m_font); @@ -1447,8 +1471,7 @@ float wxDCImpl::GetFontPointSizeAdjustment(float dpi) // are ~6 times smaller when printing. Unfortunately, this bug is so severe // that *all* printing code has to account for it and consequently, other // ports need to emulate this bug too: - const wxSize screenPPI = wxGetDisplayPPI(); - return float(screenPPI.y) / dpi; + return float(wxDisplay::GetStdPPIValue()) / dpi; } double wxDCImpl::GetMMToPXx() const diff --git a/src/common/dcbufcmn.cpp b/src/common/dcbufcmn.cpp index 0dbfcf48de..9b1c1f3159 100644 --- a/src/common/dcbufcmn.cpp +++ b/src/common/dcbufcmn.cpp @@ -52,7 +52,8 @@ public: if ( !ms_buffer || w > ms_buffer->GetLogicalWidth() || - h > ms_buffer->GetLogicalHeight() ) + h > ms_buffer->GetLogicalHeight() || + (dc && dc->GetContentScaleFactor() != ms_buffer->GetScaleFactor()) ) { delete ms_buffer; diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 368ddfed83..0255b5de68 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -160,6 +160,11 @@ void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx ) if ( DoInitContext(ctx) ) { + if (m_graphicContext->GetWindow()) + { + m_window = m_graphicContext->GetWindow(); + } + // Reapply our attributes to the context. m_graphicContext->SetFont( m_font , m_textForegroundColour ); m_graphicContext->SetPen( m_pen ); @@ -490,11 +495,6 @@ wxSize wxGCDCImpl::GetPPI() const return wxDisplay::GetStdPPI(); } -double wxGCDCImpl::GetDPIScaleFactor() const -{ - return m_graphicContext ? m_graphicContext->GetDPIScaleFactor() : 1.0; -} - int wxGCDCImpl::GetDepth() const { return 32; diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 6104c349d3..5e5b20c81a 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -580,6 +580,16 @@ wxSize wxSVGFileDCImpl::GetPPI() const return wxSize(wxRound(m_dpi), wxRound(m_dpi)); } +wxSize wxSVGFileDCImpl::FromDIP(const wxSize& sz) const +{ + return sz; +} + +wxSize wxSVGFileDCImpl::ToDIP(const wxSize& sz) const +{ + return sz; +} + void wxSVGFileDCImpl::Clear() { { diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 59803b8789..f03d1f7dec 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -34,6 +34,7 @@ #endif #include "wx/private/graphics.h" +#include "wx/private/rescale.h" #include "wx/display.h" //----------------------------------------------------------------------------- @@ -613,13 +614,6 @@ void wxGraphicsContext::SetContentScaleFactor(double contentScaleFactor) m_contentScaleFactor = contentScaleFactor; } - double wxGraphicsContext::GetDPIScaleFactor() const -{ - wxDouble x, y; - GetDPI(&x, &y); - return x / (double)wxDisplay::GetStdPPIValue(); -} - #if 0 void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) ) { @@ -633,19 +627,36 @@ wxDouble wxGraphicsContext::GetAlpha() const void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY) const { - if ( m_window ) - { - const wxSize ppi = m_window->GetDPI(); - *dpiX = ppi.x; - *dpiY = ppi.y; - } - else - { - // Use some standard DPI value, it doesn't make much sense for the - // contexts not using any pixels anyhow. - *dpiX = wxDisplay::GetStdPPIValue(); - *dpiY = wxDisplay::GetStdPPIValue(); - } + const wxSize dpi = GetWindow() ? GetWindow()->GetDPI() : wxDisplay::GetStdPPI(); + + if (dpiX) + *dpiX = dpi.x; + if (dpiY) + *dpiY = dpi.y; +} + +wxSize wxGraphicsContext::FromDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + wxRealPoint dpi; + GetDPI(&dpi.x, &dpi.y); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(baseline).To(wxSize((int)dpi.x, (int)dpi.y)); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS +} + +wxSize wxGraphicsContext::ToDIP(const wxSize& sz) const +{ +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + return sz; +#else + wxRealPoint dpi; + GetDPI(&dpi.x, &dpi.y); + const wxSize baseline = wxDisplay::GetStdPPI(); + return wxRescaleCoord(sz).From(wxSize((int)dpi.x, (int)dpi.y)).To(baseline); +#endif // wxHAS_DPI_INDEPENDENT_PIXELS } // sets the pen diff --git a/src/common/prntbase.cpp b/src/common/prntbase.cpp index 96f4ef857c..3089d00202 100644 --- a/src/common/prntbase.cpp +++ b/src/common/prntbase.cpp @@ -45,6 +45,7 @@ #include "wx/print.h" #include "wx/dcprint.h" #include "wx/artprov.h" +#include "wx/display.h" #include #include @@ -638,7 +639,7 @@ bool wxPrintout::SetUp(wxDC& dc) { wxCHECK_MSG( dc.IsOk(), false, "should have a valid DC to set up" ); - SetPPIScreen(wxGetDisplayPPI()); + SetPPIScreen(wxDisplay::GetStdPPI()); // We need to know printer PPI. In most ports, this can be retrieved from // the printer DC, but in others it is computed (probably for legacy @@ -1613,7 +1614,7 @@ void wxPreviewControlBar::CreateButtons() }; int n = WXSIZEOF(choices); - m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(70,wxDefaultCoord), n, choices, 0 ); + m_zoomControl = new wxChoice( this, wxID_PREVIEW_ZOOM, wxDefaultPosition, wxSize(FromDIP(70),wxDefaultCoord), n, choices, 0 ); sizer.Add(m_zoomControl); SetZoomControl(m_printPreview->GetZoom()); diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index a089c8a8d1..62d8d43b91 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -1614,6 +1614,15 @@ wxSize wxPostScriptDCImpl::GetPPI() const return wxSize( DPI, DPI ); } +wxSize wxPostScriptDCImpl::FromDIP(const wxSize& sz) const +{ + return sz; +} + +wxSize wxPostScriptDCImpl::ToDIP(const wxSize& sz) const +{ + return sz; +} bool wxPostScriptDCImpl::StartDoc( const wxString& WXUNUSED(message) ) { diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 84c6d84ad5..c43735010c 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -40,6 +40,7 @@ bool wxCairoInit(); #include "wx/private/graphics.h" #include "wx/rawbmp.h" #include "wx/vector.h" +#include "wx/display.h" #ifdef __WXMSW__ #include "wx/msw/enhmeta.h" #endif @@ -332,7 +333,10 @@ protected: class wxCairoFontData : public wxGraphicsObjectRefData { public: - wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col ); + wxCairoFontData( wxGraphicsRenderer* renderer, + const wxFont &font, + const wxRealPoint& dpi, + const wxColour& col ); wxCairoFontData(wxGraphicsRenderer* renderer, double sizeInPixels, const wxString& facename, @@ -508,6 +512,8 @@ public: virtual void PopState() wxOVERRIDE; virtual void Flush() wxOVERRIDE; + void GetDPI(wxDouble* dpiX, wxDouble* dpiY) const wxOVERRIDE; + virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, wxDouble *descent, wxDouble *externalLeading ) const wxOVERRIDE; virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const wxOVERRIDE; @@ -1124,7 +1130,7 @@ wxCairoFontData::InitFontComponents(const wxString& facename, } wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &font, - const wxColour& col ) + const wxRealPoint& dpi, const wxColour& col ) : wxGraphicsObjectRefData(renderer) #ifdef __WXGTK__ , m_wxfont(font) @@ -1132,12 +1138,24 @@ wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &fo { InitColour(col); - m_size = font.GetPointSize(); - -#ifdef __WXMAC__ - m_font = cairo_quartz_font_face_create_for_cgfont( font.OSXGetCGFont() ); -#elif defined(__WXGTK__) +#ifdef __WXMSW__ + // Font is 72 DPI, screen is 96-based, and font needs a correction + // for screens with higher DPI (similar to gdi+ and d2d renderers). + m_size = !dpi.y + ? double(font.GetPixelSize().GetHeight()) + : (font.GetFractionalPointSize() * dpi.y / 72); #else + // On macOS, font and screen both are 72 DPI, and macOS font size does + // not need a correction for retina displays. + // GTK does not use m_size, but initialize it anyway and mark dpi as unused + // so we don't get any compiler warnings. + wxUnusedVar(dpi); + m_size = font.GetFractionalPointSize() * wxDisplay::GetStdPPIValue() / 72; +#ifdef __WXMAC__ + m_font = cairo_quartz_font_face_create_for_cgfont(font.OSXGetCGFont()); +#endif +#endif + InitFontComponents ( font.GetFaceName(), @@ -1146,7 +1164,6 @@ wxCairoFontData::wxCairoFontData( wxGraphicsRenderer* renderer, const wxFont &fo font.GetWeight() == wxFONTWEIGHT_BOLD ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL ); -#endif } wxCairoFontData::wxCairoFontData(wxGraphicsRenderer* renderer, @@ -2237,7 +2254,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& #endif #ifdef __WXMAC__ - CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef(); + CGContextRef cgcontext = (CGContextRef)dc.GetGraphicsContext()->GetNativeContext(); cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height); Init( cairo_create( surface ) ); cairo_surface_destroy( surface ); @@ -2749,6 +2766,17 @@ void wxCairoContext::Flush() #endif } +void wxCairoContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const +{ + const wxSize dpi = GetWindow() ? GetWindow()->GetDPI() : + (wxDisplay::GetStdPPI() * GetContentScaleFactor()); + + if (dpiX ) + *dpiX = dpi.x; + if ( dpiY ) + *dpiY = dpi.y; +} + void wxCairoContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) { wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp); @@ -3377,13 +3405,7 @@ wxCairoRenderer::CreateRadialGradientBrush(wxDouble startX, wxDouble startY, wxGraphicsFont wxCairoRenderer::CreateFont( const wxFont &font , const wxColour &col ) { - wxGraphicsFont p; - ENSURE_LOADED_OR_RETURN(p); - if ( font.IsOk() ) - { - p.SetRefData(new wxCairoFontData( this , font, col )); - } - return p; + return CreateFontAtDPI(font, wxRealPoint(), col); } wxGraphicsFont @@ -3400,10 +3422,16 @@ wxCairoRenderer::CreateFont(double sizeInPixels, wxGraphicsFont wxCairoRenderer::CreateFontAtDPI(const wxFont& font, - const wxRealPoint& WXUNUSED(dpi), + const wxRealPoint& dpi, const wxColour& col) { - return CreateFont(font, col); + wxGraphicsFont p; + ENSURE_LOADED_OR_RETURN(p); + if ( font.IsOk() ) + { + p.SetRefData(new wxCairoFontData( this, font, dpi, col )); + } + return p; } wxGraphicsBitmap wxCairoRenderer::CreateBitmap( const wxBitmap& bmp ) diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp index c49d24af2a..e9a230e90d 100644 --- a/src/generic/printps.cpp +++ b/src/generic/printps.cpp @@ -38,6 +38,7 @@ #include "wx/generic/prntdlgg.h" #include "wx/progdlg.h" #include "wx/paper.h" +#include "wx/display.h" #include @@ -312,7 +313,7 @@ void wxPostScriptPrintPreview::DetermineScaling() { int resolution = 600; // TODO, this is correct, but get this from wxPSDC somehow - const wxSize screenPPI = wxGetDisplayPPI(); + const wxSize screenPPI = wxDisplay::GetStdPPI(); int logPPIScreenX = screenPPI.GetWidth(); int logPPIScreenY = screenPPI.GetHeight(); int logPPIPrinterX = resolution; diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index e263b23561..97dea834b1 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -29,6 +29,7 @@ #include "wx/dynlib.h" #include "wx/paper.h" #include "wx/modalhook.h" +#include "wx/display.h" #include "wx/gtk/private/wrapgtk.h" @@ -2476,7 +2477,7 @@ void wxGtkPrintPreview::DetermineScaling() if (paper) { - const wxSize screenPPI = wxGetDisplayPPI(); + const wxSize screenPPI = wxDisplay::GetStdPPI(); int logPPIScreenX = screenPPI.GetWidth(); int logPPIScreenY = screenPPI.GetHeight(); int logPPIPrinterX = m_resolution; diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 33cc1cf537..6b72fe8fe4 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -2655,17 +2655,12 @@ wxSize wxMSWDCImpl::GetPPI() const if ( !ppi.x || !ppi.y ) { - ppi = wxGetDPIofHDC(GetHdc())*GetContentScaleFactor(); + ppi = wxGetDPIofHDC(GetHdc()); } return ppi; } -double wxMSWDCImpl::GetDPIScaleFactor() const -{ - return GetPPI().x / 96.0; -} - // ---------------------------------------------------------------------------- // DC caching // ---------------------------------------------------------------------------- diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 83799ff4ed..b648779c34 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -143,9 +143,9 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) SetFont(GetFont()); } -double wxMemoryDCImpl::GetDPIScaleFactor() const +wxSize wxMemoryDCImpl::GetPPI() const { - return m_contentScaleFactor; + return wxDisplay::GetStdPPI() * GetContentScaleFactor(); } void wxMemoryDCImpl::SetFont(const wxFont& font) @@ -154,7 +154,7 @@ void wxMemoryDCImpl::SetFont(const wxFont& font) // use and the default/global scale factor used when creating fonts. wxFont scaledFont = font; if ( scaledFont.IsOk() ) - scaledFont.WXAdjustToPPI(wxDisplay::GetStdPPI()*m_contentScaleFactor); + scaledFont.WXAdjustToPPI(GetPPI()); wxMSWDCImpl::SetFont(scaledFont); } diff --git a/src/msw/dcprint.cpp b/src/msw/dcprint.cpp index 1a8af53d0d..b12aa4c73c 100644 --- a/src/msw/dcprint.cpp +++ b/src/msw/dcprint.cpp @@ -41,6 +41,7 @@ #endif #include "wx/printdlg.h" +#include "wx/display.h" #include "wx/msw/printdlg.h" // mingw32 defines GDI_ERROR incorrectly @@ -230,6 +231,23 @@ wxRect wxPrinterDCImpl::GetPaperRect() const return wxRect(x, y, w, h); } +wxSize wxPrinterDCImpl::FromDIP(const wxSize& sz) const +{ + return sz; +} + +wxSize wxPrinterDCImpl::ToDIP(const wxSize& sz) const +{ + return sz; +} + +void wxPrinterDCImpl::SetFont(const wxFont& font) +{ + wxFont scaledFont = font; + if ( scaledFont.IsOk() ) + scaledFont.WXAdjustToPPI(wxDisplay::GetStdPPI()); + wxMSWDCImpl::SetFont(scaledFont); +} #if !wxUSE_PS_PRINTING diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index aed7dbaad5..c1f2e2f7ef 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -33,6 +33,7 @@ #include "wx/metafile.h" #include "wx/clipbrd.h" +#include "wx/display.h" #include "wx/msw/private.h" @@ -223,6 +224,24 @@ public: const wxString& description ); virtual ~wxEnhMetaFileDCImpl(); + wxSize FromDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + + virtual wxSize ToDIP(const wxSize& sz) const wxOVERRIDE + { + return sz; + } + + void SetFont(const wxFont& font) wxOVERRIDE + { + wxFont scaledFont = font; + if (scaledFont.IsOk()) + scaledFont.WXAdjustToPPI(wxDisplay::GetStdPPI()); + wxMSWDCImpl::SetFont(scaledFont); + } + // obtain a pointer to the new metafile (caller should delete it) wxEnhMetaFile *Close(); diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index c03fca4a1a..0d67bcf7a6 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -2544,12 +2544,10 @@ wxGDIPlusPrintingContext::wxGDIPlusPrintingContext( wxGraphicsRenderer* renderer void wxGDIPlusPrintingContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const { - // override to use same scaling as wxWindowsPrintPreview::DetermineScaling - const wxSize dpi = wxGetDPIofHDC(ScreenHDC()); if ( dpiX ) - *dpiX = dpi.x; + *dpiX = 96.0; if ( dpiY ) - *dpiY = dpi.y; + *dpiY = 96.0; } //----------------------------------------------------------------------------- diff --git a/src/msw/printwin.cpp b/src/msw/printwin.cpp index 051b1f93a1..cf644d3a8f 100644 --- a/src/msw/printwin.cpp +++ b/src/msw/printwin.cpp @@ -46,6 +46,7 @@ #include "wx/msw/private.h" #include "wx/msw/dcprint.h" #include "wx/msw/enhmeta.h" +#include "wx/display.h" #include @@ -310,7 +311,7 @@ bool wxWindowsPrintPreview::Print(bool interactive) void wxWindowsPrintPreview::DetermineScaling() { - const wxSize logPPIScreen = wxGetDPIofHDC(ScreenHDC()); + const wxSize logPPIScreen = wxDisplay::GetStdPPI(); m_previewPrintout->SetPPIScreen(logPPIScreen); // Get a device context for the currently selected printer diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index cd19f3c928..4a7f083d68 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -501,7 +501,7 @@ protected: bool m_isShading; CGFunctionRef m_gradientFunction; CGShadingRef m_shading; - wxMacCoreGraphicsMatrixData* m_shadingMatrix; + wxMacCoreGraphicsMatrixData* m_shadingMatrix; // information about a single gradient component struct GradientComponent @@ -557,7 +557,7 @@ wxMacCoreGraphicsPenBrushDataBase::~wxMacCoreGraphicsPenBrushDataBase() if ( m_shadingMatrix ) delete m_shadingMatrix; - + // an eventual existing m_gradientComponents will be deallocated via the CGFunction callback } @@ -579,9 +579,9 @@ wxMacCoreGraphicsPenBrushDataBase::CreateLinearGradientShading( const wxGraphicsMatrix& matrix) { m_gradientFunction = CreateGradientFunction(stops); - m_shading = CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), + m_shading = CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) x1, (CGFloat) y1), - CGPointMake((CGFloat) x2, (CGFloat) y2), + CGPointMake((CGFloat) x2, (CGFloat) y2), m_gradientFunction, true, true ); m_isShading = true; if ( !matrix.IsNull() ) @@ -600,9 +600,9 @@ wxMacCoreGraphicsPenBrushDataBase::CreateRadialGradientShading( const wxGraphicsMatrix& matrix) { m_gradientFunction = CreateGradientFunction(stops); - m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), + m_shading = CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake((CGFloat) startX, (CGFloat) startY), 0, - CGPointMake((CGFloat) endX, (CGFloat) endY), (CGFloat) radius, + CGPointMake((CGFloat) endX, (CGFloat) endY), (CGFloat) radius, m_gradientFunction, true, true ); m_isShading = true; if ( !matrix.IsNull() ) @@ -666,7 +666,7 @@ CGFunctionRef wxMacCoreGraphicsPenBrushDataBase::CreateGradientFunction(const wxGraphicsGradientStops& stops) { m_gradientComponents = new GradientComponents(); - + static const CGFunctionCallbacks callbacks = { 0, &CalculateShadingValues, &ReleaseComponents }; static const CGFloat input_value_range [2] = { 0, 1 }; static const CGFloat output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 }; @@ -1029,12 +1029,12 @@ protected: wxMacCoreGraphicsColour m_cgColor; }; -wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer* renderer) : +wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer* renderer) : wxMacCoreGraphicsPenBrushDataBase( renderer ) { } -wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : +wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer* renderer, const wxBrush &brush) : wxMacCoreGraphicsPenBrushDataBase( renderer ), m_cgColor( brush ) { @@ -1089,7 +1089,7 @@ private : #endif }; -wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col) +wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col) : wxGraphicsObjectRefData( renderer ), m_colour(col) { @@ -1402,6 +1402,8 @@ public: virtual void Flush() wxOVERRIDE; + void GetDPI(wxDouble* dpiX, wxDouble* dpiY) const wxOVERRIDE; + // push the current state of the context, ie the transformation matrix on a stack virtual void PushState() wxOVERRIDE; @@ -1758,6 +1760,28 @@ void wxMacCoreGraphicsContext::Flush() CGContextFlush(m_cgContext); } +void wxMacCoreGraphicsContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const +{ + if ( GetWindow() ) + { + const wxSize dpi = GetWindow()->GetDPI(); + + if ( dpiX ) + *dpiX = dpi.x; + if ( dpiY ) + *dpiY = dpi.y; + } + else + { + // see wxWindowMac::GetDPI + const double dpi = GetContentScaleFactor() * 72.0; + if ( dpiX ) + *dpiX = dpi; + if ( dpiY ) + *dpiY = dpi; + } +} + bool wxMacCoreGraphicsContext::EnsureIsValid() { CheckInvariants(); @@ -2238,8 +2262,8 @@ void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath &path ) else { CGContextAddPath( m_cgContext, (CGPathRef)path.GetNativePath() ); - CGContextStrokePath( m_cgContext ); - } + CGContextStrokePath( m_cgContext ); + } CheckInvariants(); } diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index 235bea2b57..c69ad4d0cc 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -30,6 +30,7 @@ #include "wx/printdlg.h" #include "wx/paper.h" +#include "wx/display.h" #include "wx/osx/printdlg.h" #include @@ -746,10 +747,7 @@ bool wxMacPrintPreview::Print(bool interactive) void wxMacPrintPreview::DetermineScaling() { - int screenWidth , screenHeight ; - wxDisplaySize( &screenWidth , &screenHeight ) ; - - wxSize ppiScreen = wxGetDisplayPPI(); + wxSize ppiScreen = wxDisplay::GetStdPPI(); wxSize ppiPrinter( 72 , 72 ) ; m_previewPrintout->SetPPIScreen( ppiScreen.x , ppiScreen.y ) ;