Commit Graph

218 Commits

Author SHA1 Message Date
Vadim Zeitlin
e7bb37436a Warn if wxCairoContext(wxPrinterDC) ctor is not implemented
Use an explicit #warning to explain the problem. This is more
informative and avoids errors when building with -Werror (but also
-Wno-error=cpp).
2020-07-06 12:54:15 +02:00
Paul Cornett
9d4bb47050 Don't compile Cairo dynamic linking code with GTK
It's useless as Cairo is always linked to any program using GTK
2020-04-30 09:11:37 -07:00
Paul Cornett
948ddc6e0f Eliminate -Wcast-qual warnings with GCC and Clang
Use const_cast, mutable, and various other changes to avoid -Wcast-qual
2020-02-02 22:50:32 -08:00
Artur Wieczorek
9fbf97ae97 Check __WXOSX_COCOA__ instead of wxOSX_USE_COCOA
wxOSX_USE_COCOA is available only in wxOSX files.
2019-12-06 21:09:36 +01:00
Artur Wieczorek
1d45886c8f Don't attempt to get RGB components of invalid colour 2019-12-06 20:44:18 +01:00
Artur Wieczorek
67b64ee70f Add support for creating Cairo pen from wxPen with non-solid colour
Cairo colour patterns support only RGBA colours and therefore it is not
possible to create a colour pattern from wxPen with non-RGB colour
(non-solid colour). As a workaround under wxOSX for solid wxPen with
non-solid colour we can convert it to Cairo surface pattern (stiple)
because under wxOSX non-solid colour is actually represented by a pattern
image.
2019-12-06 20:40:57 +01:00
Artur Wieczorek
55478d95a5 Add support for creating Cairo brush from wxBrush with non-solid colour
Cairo colour patterns support only RGBA colours and therefore it is not
possible to create a colour pattern from wxBrush with non-RGB colour
(non-solid colour). However under wxOSX, when we have a solid wxBrush with
non-solid colour, we can convert it to Cairo surface pattern (stiple)
because under wxOSX non-solid colour is actually represented by a pattern
image.
2019-12-06 20:34:57 +01:00
Vadim Zeitlin
56bf5282d7 Merge branch 'gtk-fractional-font-scaling'
Apply system's fractional font scaling parameter when displaying text in
wxGTK.

See https://github.com/wxWidgets/wxWidgets/pull/1650
2019-11-29 05:04:56 +01:00
Artur Wieczorek
bdee154c96 Fix build with wxUSE_CAIRO==1 under wxMSW/wxOSX
'bmpSource' is declared later but we can check
original bitmap 'bmp' for 'alpha flag' instead
because 'bmpSource' is just a non-const copy
of 'bmp'.
2019-11-17 22:17:27 +01:00
Vadim Zeitlin
ac14c3ffbc Only use font scaling code with GTK 3 or later
It's useless to do it for GTK 2 which doesn't support font scaling
anyhow.
2019-11-16 12:00:40 +01:00
Vadim Zeitlin
4d4e3e71a5 Use helper function for applying scaled font to PangoLayout
Don't scale, or even copy, the font object unnecessarily in the common
case when the font scaling factor is 1.0 anyhow.

No real changes, just make the code slightly more efficient and also a
bit more concise after the changes of the previous commit.
2019-11-16 12:00:40 +01:00
iwbnwif
fbc75ec8e0 Add support for fractional font scaling to wxGTK3
Respect the system font scaling parameter (e.g. "Fonts->Scaling Factor"
in Gnome Tweaks, "Force font DPI" in KDE System Settings or
GDK_DPI_SCALE environment variable) when drawing text using wxFont.

This ensures that generic widgets have their text scaled appropriately
to be consistent with native widgets.

Closes https://github.com/wxWidgets/wxWidgets/pull/1635
2019-11-16 12:00:40 +01:00
Vadim Zeitlin
c433d3d0fd Use wxALPHA_XXX constants instead of 0 and 255
No real changes, just try to improve the code clarity.
2019-11-10 17:56:44 +01:00
Vadim Zeitlin
d6d5375fe9 Try to simply alpha handling in wxCairoBitmapData a bit more
Don't use hasAlpha under platforms where it's always true.
2019-11-10 17:51:55 +01:00
Vadim Zeitlin
c81021e850 Simplify condition in wxCairoBitmapData ctor
Don't test for "bufferFormat == CAIRO_FORMAT_ARGB32" which will be
always true in this branch if hasAlpha is true anyhow.

No real changes.

See #18570.
2019-11-10 17:44:48 +01:00
Artur Wieczorek
4f7dde18ca Fix creating wxCairoBitmapData from wxBitmap under wxOSX
Under wxOSX bitmap pixel values are already premultiplied so bitmap data
can be copied to the target surface directly.
Since 992b594c wxMask bitmap colours are no longer inverted and have
the same meaning as for another ports.
2019-11-10 15:55:07 +01:00
Artur Wieczorek
1b9f7fcd29 Fix creating wxCairoBitmapData from wxBitmap under wxGTK2
wxAlphaPixelData can be only used to access pixel data in 32 bpp bitmaps.
Also, because bitmaps can have both alpha values and mask, the mask should
be applied to the created surface even if alpha channel exists. Masked
pixels become fully transparent and unmasked pixels should retain original
alpha values.

Closes #18570.
2019-11-10 15:54:20 +01:00
Maarten Bent
c538e8f9d6 Add wxGraphicsRenderer::CreateFontAtDPI to support font with fractional pixel-size 2019-10-09 22:24:28 +02:00
Robin Dunn
a8a19e25ee Various typo and coding style fixes 2019-09-05 13:33:15 -07:00
Robin Dunn
1afb4afe25 Fix typo 2019-09-04 15:01:22 -07:00
Robin Dunn
f7896d4dff Use new parameter names in the existing CreateRadialGradientBrush methods too 2019-09-04 14:19:24 -07:00
Robin Dunn
80f24d9e74 User more easily understandable names for the radial gradient coordinate parameters in wxGraphicsPenInfo 2019-09-04 14:19:24 -07:00
Robin Dunn
7c33d3f969 Gradients can have matrix transforms too. Updates for Cairo. 2019-09-04 14:19:23 -07:00
Robin Dunn
b98ab8b56d Switch to a switch statement 2019-09-04 14:19:23 -07:00
Robin Dunn
c860d50888 Rename some *GradientBrush to *GradientPattern 2019-09-04 14:19:23 -07:00
Robin Dunn
694b7e11fc Move the new methods to the wxCairoPenBrushBaseData section of the file 2019-09-04 14:19:23 -07:00
Robin Dunn
59ce48924a Add gradient pen support for Cairo 2019-09-04 14:19:23 -07:00
Jay Nabonne
1d117b75f7 Add wxGraphicsContext implementation for wxQt
Add graphics renderer using Qt classes and use it by default in wxQt
port under MSW.

Closes https://github.com/wxWidgets/wxWidgets/pull/1139
2019-01-17 00:50:47 +01:00
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