Commit Graph

190 Commits

Author SHA1 Message Date
Graham Dawes
b0eca3bdde Fix some more uninitialised wxCairoContext fields in wxQt
Closes https://github.com/wxWidgets/wxWidgets/pull/1084
2018-12-17 17:46:38 +01:00
Graham Dawes
8fa32a40a9 Fix m_qtPainter not being initialised in wxCairoContext ctor
For some reason one of the overloads of the c'tor left the m_qtPainter
field set to NULL rather than asking the wxDC for it's painter.

The rest of the class assumes the painter is not NULL.

Closes https://github.com/wxWidgets/wxWidgets/pull/1075
2018-12-14 17:41:55 +01:00
Graham Dawes
6c5c9e578b wxCarioContext:Flush now draws back to the QT image
wxCairoContext::Flush was flushing back to the internal image but this
image wasn't drawn back to the QPainter until the wxCarioContext
instance was destroyed.

This fix ensure that after a call to Flush, anything drawn by Cario is
drawn back to the QImage.

Closes https://github.com/wxWidgets/wxWidgets/pull/1068
2018-12-12 18:12:36 +01:00
Vadim Zeitlin
5e53b22bd4 Add wxGraphicsContext::GetWindow()
This method allows to retrieve the window this context is associated
with, if any.

Add "wxWindow*" argument to wxGraphicsContext ctor and provide the
window pointer to it when available, i.e. when creating the context from
a wxWindow directly or from wxWindowDC, which is also associated with a
window, in platform-specific code.

No real changes yet.
2018-11-06 03:36:53 +01:00
Vadim Zeitlin
713a7ab895 Move wxUSE_ENH_METAFILE check inside wx/msw/enhmeta.h itself
This is more consistent with the other headers, which are safe to
include even when the corresponding feature is turned off.

Also remove the now redundant wxUSE_ENH_METAFILE checks in the source
code including this header.

See https://github.com/wxWidgets/wxWidgets/pull/951
2018-09-26 14:47:45 +02:00
Paul Cornett
85bdd1be9f Update Cairo version check.
Should presumably have been part of 3f18576dee.
2018-08-03 09:53:36 -07:00
Paul Cornett
6907a59bc3 Remove unneeded compile-time Cairo version checks.
The code will compile with any Cairo version.
2018-08-03 09:39:38 -07:00
Artur Wieczorek
3f18576dee Apply workaround in creating wxGraphicContext from native DC only for Cairo < 1.15.12 (wxMSW).
Cairo bug 96482 was fixed in 1.15.12 so the workaround needs to be applied
only for older Cairo versions.
2018-07-28 12:20:26 +02:00
Artur Wieczorek
e25ab3e421 Fix getting extents of wxGraphicsPath (Cairo)
Graphics path is actually a line with null width so its bounding box
should be obtained with cairo_path_extents() function which assumes
that line width is 0.
2018-07-28 11:41:07 +02:00
Vadim Zeitlin
8ebcfebc5c Fix wxGTK 1 build after gtk/gtk.h wrapper header addition
Changes of c0b0562533 to common code broke
wxGTK1 build, as wx/gtk/private/wrapgtk.h is for wxGTK 2+ only.

Fix this by handling wxGTK 1 separately and including gtk/gtk.h directly
for it.

Hopefully this code will be removed, together with the rest of wxGTK1
support, in some not so distant future.
2018-07-10 14:54:19 +02:00
Vadim Zeitlin
c0b0562533 Avoid many -Wparentheses warnings from gtk/gtk.h with gcc8
Add wx/gtk/private/wrapgtk.h wrapping gtk/gtk.h in pragmas disabling
these warnings and include it everywhere instead of directly including
gtk/gtk.h.

Also include wx/gtk/private/gtk2-compat.h from this wrapper header as it
was included by 90% of the files including gtk/gtk.h itself and it seems
to be better and simpler to just always include it.
2018-05-21 12:34:04 +02:00
Jan Niklas Hasse
496da2e550 Remove trailing whitespace from several files
No real changes.

See https://github.com/wxWidgets/wxWidgets/pull/787
2018-04-18 15:45:42 +02:00
Vadim Zeitlin
4265e671fd Fix wxGTK compilation with Cairo 1.2
Avoid using cairo_clip_extents() function, which was added in 1.4,
unless we have at least this version at both compile- and run-time.

This allows the library to be compiled under CentOS 5, which only has
Cairo 1.2 and which is, unfortunately, still in use.
2018-02-16 13:18:02 +01:00
Vadim Zeitlin
aa4d51d579 Fix font creation using font flags in Cairo wxGraphicsContext
Don't crash trying to use an uninitialized font in
GetPartialTextExtents() later if the font was created using
CreateFont(sizeInPixels, facename, flags) overload.

Closes #18021.
2017-12-09 16:31:28 +01:00
Vadim Zeitlin
38c67b68e3 Remove unnecessary "virtual" keywords from Cairo code
Several methods were virtual for no apparent reason, just don't make
them virtual unnecessarily.

No real changes.
2017-12-06 14:46:26 +01:00
Vadim Zeitlin
7ee73c9332 Slightly clean up font handling in wxGraphicsContext in wxGTK
Returning true/false from wxCairoFontData::Apply() to indicate whether
Pango should or not be used was not very clear, so prefer to test for
the font explicitly in the code calling Apply() and make Apply() itself
void, consistently with the method with the same name in the other
classes.

Also avoid calling it at all from GetTextExtent() when using Pango, this
is completely unnecessary as the text colour doesn't have any bearing on
its extents.

Also use static_cast and const_cast as appropriate instead of C-style
casts.
2017-12-06 14:41:21 +01:00
Vadim Zeitlin
80a11ae17f Use wxGtkObject instead of g_object_unref() calls in Cairo code
Make the code safer and shorter.

No real changes.
2017-11-07 16:32:36 +01:00
Vadim Zeitlin
3b76e590d4 Return descent from Cairo GetTextExtent() even for empty strings
This method still needs to return the correct descent in this case.

Fixes MeasuringTextTestCase::LeadingAndDescent() unit test failure with
GTK+ 3.
2017-11-07 16:26:12 +01:00
Vadim Zeitlin
76fd05b147 Leave only wxGraphicsRenderer::CreatePen(wxGraphicsPenInfo) overload
It doesn't make much sense to require all the graphics backends to
create wxGraphicsPen from either wxPen or wxGraphicsPenInfo when the
former can be handled just once in the common code.

So do just this, leaving CreatePen() overload taking wxGraphicsPenInfo
where the real pen construction takes place and implementing
wxGraphicsPen creation from wxPen in the common wxGraphicsContext code.

This is not 100% backwards-compatible as any code inheriting from
wxGraphicsRenderer and overriding its CreatePen() will now be broken,
however this should be extremely rare (there is no good reason to
inherit from this class in the user code) and result in compile errors
if it does happen.
2017-09-10 01:48:30 +02:00
Vadim Zeitlin
cc91a7d6d4 Minor formatting and style changes in wxPenInfo code
Use more standard formatting, wrap some overlong lines.
2017-09-10 01:11:06 +02:00
Adrien Tétar
999c750ca7 Review feedback 2017-09-10 01:02:21 +02:00
Adrien Tétar
2305604565 Introduce wxGraphicsPenInfo class 2017-09-10 01:02:20 +02:00
Stefan Csomor
62052e365e Do not offset coordinates in case of filling 2017-06-28 07:34:53 +02:00
Stefan Csomor
d9228f471c Optimize rectangle drawing under Cairo 2017-06-26 09:55:17 +02:00
Stefan Csomor
4cce63d904 Support transparency and masks under macOS / Cairo 2017-06-26 09:49:39 +02:00
Stefan Csomor
6dfa897b4a Adding a native implementation for clearing bitmap/window contexts
Filling a bitmap surface is filled with ARGB 0,0,0,0. This way eg buffered transparent layers can be properly cleared.
2017-06-25 22:48:58 +02:00
Artur Wieczorek
e811c0640a Optimize creating wxCairoContext from wxMemoryDC associated with ARGB wxBitmap (MSW)
Legacy API cairo_win32_surface_create() can create only 24 bpp RGB surfaces but new API cairo_win32_surface_create_with_format() introduced in 1.15.4 supports creating also 32 bpp ARGB surfaces.
So, this new API can be used to create ARGB surface directly from ARGB bitmap (HDC), superseding current implementation based on the access to the bitmap data with cairo_image_surface_create_for_data().
Unfortunately, 0RGB bitmaps are not supported by cairo_win32_surface_create_with_format() and for such bitmaps surface has to be still created from bitmap data.
2017-01-10 21:34:51 +01:00
Václav Slavík
e71be91ebe Add API to create wxGraphicsContext from win32 HDC
Add wxGraphicsContext::CreateFromNativeHDC() and wxGraphicsRenderer::
CreateContextFromNativeHDC() to allow creation not only from native
renderer object, but also from HDC, which is something universally
supported by win32 implementations.
2017-01-06 14:35:09 +01:00
Graham Dawes
d639e4ffce Fix wxQt build errors when using gcc 4.4
Closes #17733.
2016-11-30 16:13:46 +01:00
Artur Wieczorek
4d6d73eab3 Fix wxGraphicsMatrix concatenation (Cairo)
The parameter matrix in wxGraphicsMatrixData::Concat() should be a multiplicand, not a multiplier.

Closes #17670.
2016-09-18 23:07:59 +02:00
Artur Wieczorek
f68dad69cc Implement Flush() method for Cairo graphics context
wxCairoContext implementation for wxMSW and wxQT use internally helper surface so there is a need to flush it on demand.
2016-09-08 19:34:46 +02:00
Artur Wieczorek
480a003c00 Add wxGraphicsContext::GetClipBox() function
This method returns bounding box of the current clipping region.
Added declaration, documentation and implemented for GDI+, Direct2D, Cairo renderers.
2016-08-21 20:57:40 +02:00
Artur Wieczorek
47791737db Revert code commented out by mistake in f06bfe37.
We need to restore HDC after Cairo operations.
2016-06-23 22:23:05 +02:00
Artur Wieczorek
f06bfe37ae Fixed creating wxGraphicContext from native DC with Cairo renderer (MSW).
When x- or y-coordinate of DC origin > 0 then surface created with cairo_win32_surface_create() is not fully operational (for some Cairo operations memory access violation errors occur - see Cairo bug 96482) so in this case we would need to apply a workaround and pass non-transformed DC to Cairo and next apply original DC transformation to the Cairo context operations on our own.

Closes #17564
2016-06-11 23:20:12 +02:00
Artur Wieczorek
a5d4a99bb0 Use native methods to draw some geometric figures using Cairo renderer
There are straightforward ways to draw rectangles, circles and ellipses using native methods provided by Cairo renderer and they should be used instead of generic implementations.

See #17554
2016-05-31 21:31:15 +02:00
Artur Wieczorek
32d76cefe2 Refactored code to get access to wxBitmap's bit values in wxCairoContext ctor (MSW).
Use simpler version of wxAlphaPixelData and wxNativePixelData ctors and invoke respective accessors to obtain bitmap size.
2016-04-17 19:15:49 +02:00
Artur Wieczorek
be6f93d725 Fixed initialization sequence in wxCairoContext ctor.
Shared method Init should be invoked to initialize the context to assure consistency with other ctors.
2016-04-17 19:15:32 +02:00
Artur Wieczorek
fdc2189808 Move duplicated code to the shared function.
Code to store initial Cairo transformation settings can be moved from wxCairoContext ctor bodies to the shared method wxCairoContext::Init.
2016-04-17 19:15:12 +02:00
Artur Wieczorek
ca7670d2fc Fixed creating wxGraphicsContext from Cairo context.
Reference count of the source Cairo context should be increased to prevent source context from being destroyed in wxGraphicsContex dtor (where cairo_destroy is invoked).
2016-04-16 21:34:08 +02:00
Artur Wieczorek
495a88ba73 Fixed creating wxPrinterDC from wxGraphicsContext with Cairo renderer (GTK).
When wxGraphicsContext is created from wxPrinterDC then also logical scaling factor applied to the source wxPrinterDC has to be explicitly applied to the Cairo context.
All inherited transformation settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes.

Closes #17496.
2016-04-16 21:23:21 +02:00
Artur Wieczorek
9a215bb393 Fixed creating wxGraphicsContext from wxPrinterDC with Cairo (MSW).
Modification of the mapping mode of underlying DC encapsulated in wxPrinterDC (from MM_ANISOTROPIC to MM_TEXT) which is done prior to creating Cairo context affects the value of device origin which needs to be applied to the Cairo context. Due to the change of the mapping mode it has to be rescaled based on the current scaling factor value.

See #17496.
2016-04-16 21:06:03 +02:00
Artur Wieczorek
a662e306be Fixed reporting transformation settings for wxGraphicsContext with Cairo renderer.
When wxGraphicsContext is created from "native" Cairo context (cairo_t*) then transformation settings applied initially to the underlying source Cairo context need to be stored (in a dedicated variable) to make possible determining what transformations were applied to wxGC instance since its creation. Only these explicitly applied transformations are reported by GetTransform().
2016-04-14 20:49:07 +02:00
Artur Wieczorek
a1a3f7309b Fixes and optimizations for determining wxCairoContext size (wxMSW).
1. Because Cairo uses internally GetClipBox Win API to determine surface size so we can employ the same approach in wxGraphicsRenderer::CreateContextFromNativeContext and just call this API instead of executing complicated code to determine size of underlying objects selected into DC.
2. Determine context size (and initialize respective data members with proper values) for wxCairoContext created from wxWindow.
3. Initialize respective data members with 0 values for generic wxCairoContext (with no source object provided).
2016-04-14 20:47:41 +02:00
Artur Wieczorek
0ae78d608a Restore source DC state when wxCairoContext is destroyed (wxMSW).
Since raw DC (encapsulated in source wxDC) can be modified in wxCairoContext explicitly (e.g. when context is instantiated from wxPrinterDC or wxEnhMetaFileDC) or implicitly (by some Cairo functions) we have to store its state in ctor and restore it in dtor to assure consistent state of the source wxDC.
2016-04-14 20:45:42 +02:00
Artur Wieczorek
c911f737e3 Implemented wxGraphicsContext created from wxEnhMetaFileDC for Cairo renderer (wxMSW). 2016-04-14 20:44:35 +02:00
Artur Wieczorek
0ee25aaa76 Fixed creating Cairo bitmap from wxBitmap (wxMSW).
Iterating over bit values with wxAlphaPixelData sets the internal wxBitmap's "has alpha" flag but we want to left it unchanged so we have to save its original value and restore it afterward.
2016-04-11 18:06:42 +02:00
Artur Wieczorek
c7e7c3873d Fixed determining wxCairoContext size (wxMSW).
Determine actual size of wxCairoContext created from native DC and HWND. This allows to report proper size of wxGraphicsContext created by wxGraphicsRenderer::CreateContextFromNativeContext / CreateContextFromNativeWindow.
2016-04-10 20:41:53 +02:00
Artur Wieczorek
c7a498a163 Fixed reporting transformation settings from wxGraphicsContext with Cairo renderer (GTK+ 3).
When wxGraphicsContext is created from wxWindowDC or wxMemoryDC then transformation settings applied initially to the underlying source Cairo context need to be stored (in a dedicated variable) in order to have ability to determine what transformations were applied to wxGC instance since its creation. Only these explicitly applied transformations are reported by GetTransform().

Closes #17491.
2016-04-10 20:40:33 +02:00
Artur Wieczorek
cc628f5e87 Fixed wxCairoContext::SetTransform
Actual transformation is a concatenation of internal (hidden) transformation and requested one.
2016-04-09 23:51:42 +02:00
Artur Wieczorek
42c08aae12 Fixed creating wxGraphicsContext from wxMemoryDC with Cairo renderer (wxMSW).
Create RGB Cairo surface as a fallback if we failed to create ARGB surface for 32bpp wxBitmap.
2016-04-09 23:47:58 +02:00