[pangomm] Add the CairoFontMapImpl class
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pangomm] Add the CairoFontMapImpl class
- Date: Mon, 11 Oct 2021 13:54:54 +0000 (UTC)
commit c27227177a19fb8d5095cc24ce974dd00a88c1bf
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Mon Oct 11 15:48:46 2021 +0200
Add the CairoFontMapImpl class
* pango/pangomm/.gitignore:
* pango/pangomm/filelist.am:
* pango/pangomm/meson.build: Add cairofontmapimpl.
* pango/src/cairofontmap.hg: Improve the documentation of get_default().
* pango/src/fontmap.[ccg|hg]: Add a custom wrap_new(). Wrap in a
CairoFontMapImpl if the PangoFontMap object implements PangoCairoFontMap.
* pango/pangomm/cairofontmapimpl.[cc|h]: New files. A CairoFontMapImpl
derives from FontMap and implements CairoFontMap.
Fixes #15
pango/pangomm/.gitignore | 2 ++
pango/pangomm/cairofontmapimpl.cc | 41 +++++++++++++++++++++++++
pango/pangomm/cairofontmapimpl.h | 63 +++++++++++++++++++++++++++++++++++++++
pango/pangomm/filelist.am | 10 +++++--
pango/pangomm/meson.build | 2 ++
pango/src/cairofontmap.hg | 33 +++++++++++++++++++-
pango/src/fontmap.ccg | 12 +++++++-
pango/src/fontmap.hg | 16 ++++++----
8 files changed, 170 insertions(+), 9 deletions(-)
---
diff --git a/pango/pangomm/.gitignore b/pango/pangomm/.gitignore
index 05b228b..29f0415 100644
--- a/pango/pangomm/.gitignore
+++ b/pango/pangomm/.gitignore
@@ -1,6 +1,8 @@
/*.cc
+!/cairofontmapimpl.cc
!/init.cc
/*.h
+!/cairofontmapimpl.h
!/init.h
!/types.h
!/wrap_init.h
diff --git a/pango/pangomm/cairofontmapimpl.cc b/pango/pangomm/cairofontmapimpl.cc
new file mode 100644
index 0000000..a76441b
--- /dev/null
+++ b/pango/pangomm/cairofontmapimpl.cc
@@ -0,0 +1,41 @@
+/* Copyright (C) 2021 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <pangomm/cairofontmapimpl.h>
+#include <utility> // std::move()
+
+namespace Pango
+{
+CairoFontMapImpl::CairoFontMapImpl(PangoFontMap* castitem)
+: Glib::ObjectBase(nullptr), FontMap(castitem)
+{}
+
+CairoFontMapImpl::CairoFontMapImpl(CairoFontMapImpl&& src) noexcept
+: CairoFontMap(std::move(src)),
+ FontMap(std::move(src))
+{}
+
+CairoFontMapImpl& CairoFontMapImpl::operator=(CairoFontMapImpl&& src) noexcept
+{
+ CairoFontMap::operator=(std::move(src));
+ FontMap::operator=(std::move(src));
+ return *this;
+}
+
+CairoFontMapImpl::~CairoFontMapImpl() noexcept
+{}
+
+} // namespace Pango
diff --git a/pango/pangomm/cairofontmapimpl.h b/pango/pangomm/cairofontmapimpl.h
new file mode 100644
index 0000000..9b06122
--- /dev/null
+++ b/pango/pangomm/cairofontmapimpl.h
@@ -0,0 +1,63 @@
+#ifndef _PANGO_CAIROFONTMAPIMPL_H
+#define _PANGO_CAIROFONTMAPIMPL_H
+
+/* Copyright (C) 2021 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <pangommconfig.h>
+#include <pangomm/cairofontmap.h>
+#include <pangomm/fontmap.h>
+
+namespace Pango
+{
+
+/** %Gdk::CairoFontMapImpl is a Pango::FontMap that implements the Pango::CairoFontMap interface.
+ *
+ * The PangoCairoFontMap interface can be implemented by C classes that
+ * derive from PangoFontMap. No public %Pango class implements PangoCairoFontMap.
+ * Some %Pango functions, such as pango_cairo_font_map_get_default(), return an object
+ * of a class which is derived from PangoFontMap and implements PangoCairoFontMap.
+ * Since that C class is not public, it's not wrapped in a C++ class.
+ * A C object of such a class can be wrapped in a %Pango::CairoFontMapImpl object.
+ * %Pango::CairoFontMapImpl does not directly correspond to any %Pango class.
+ *
+ * This class is intended only for wrapping C objects returned from %Pango functions.
+ *
+ * @see Pango::CairoFontMap::get_default()
+ * @newin{2,50}
+ */
+class PANGOMM_API CairoFontMapImpl : public CairoFontMap, public FontMap
+{
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+protected:
+ explicit CairoFontMapImpl(PangoFontMap* castitem);
+ friend class FontMap_Class;
+
+ // noncopyable
+ CairoFontMapImpl(const CairoFontMapImpl&) = delete;
+ CairoFontMapImpl& operator=(const CairoFontMapImpl&) = delete;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+public:
+ CairoFontMapImpl(CairoFontMapImpl&& src) noexcept;
+ CairoFontMapImpl& operator=(CairoFontMapImpl&& src) noexcept;
+
+ ~CairoFontMapImpl() noexcept override;
+};
+
+} // namespace Pango
+
+#endif /* _PANGO_CAIROFONTMAPIMPL_H */
diff --git a/pango/pangomm/filelist.am b/pango/pangomm/filelist.am
index 9bf9b89..2138b30 100644
--- a/pango/pangomm/filelist.am
+++ b/pango/pangomm/filelist.am
@@ -2,6 +2,12 @@
files_built_cc = $(files_hg:.hg=.cc) wrap_init.cc
files_built_h = $(files_hg:.hg=.h)
-files_extra_cc = init.cc
-files_extra_h = init.h types.h wrap_init.h
+files_extra_cc = \
+ cairofontmapimpl.cc \
+ init.cc
+files_extra_h = \
+ cairofontmapimpl.h \
+ init.h \
+ types.h \
+ wrap_init.h
files_extra_ph =
diff --git a/pango/pangomm/meson.build b/pango/pangomm/meson.build
index e6c869a..76deea7 100644
--- a/pango/pangomm/meson.build
+++ b/pango/pangomm/meson.build
@@ -51,10 +51,12 @@ hg_ccg_basenames = [
]
extra_cc_files = [
+ 'cairofontmapimpl.cc',
'init.cc',
]
extra_h_files = [
+ 'cairofontmapimpl.h',
'init.h',
'types.h',
'wrap_init.h',
diff --git a/pango/src/cairofontmap.hg b/pango/src/cairofontmap.hg
index a500c0b..40f303d 100644
--- a/pango/src/cairofontmap.hg
+++ b/pango/src/cairofontmap.hg
@@ -34,14 +34,45 @@ typedef struct _PangoCairoFontMapIface PangoCairoFontMapIface;
namespace Pango
{
-/** A Pango::CairoFontMap represents the set of fonts available for a particular rendering system.
+/** %Pango::CairoFontMap is an interface implemented by font maps for use with Cairo.
+ *
+ * The actual type of the font map will depend on the particular
+ * font technology Cairo was compiled to use.
*/
class PANGOMM_API CairoFontMap : public Glib::Interface
{
_CLASS_INTERFACE(CairoFontMap, PangoCairoFontMap, PANGO_CAIRO_FONT_MAP, PangoCairoFontMapIface, , ,
PANGOMM_API)
public:
+ /** Gets a default %Pango::CairoFontMap to use with Cairo.
+ *
+ * Note that the type of the returned object will depend
+ * on the particular font backend Cairo was compiled to use.
+ * You generally should only use the Pango::FontMap and
+ * %Pango::CairoFontMap API on the returned object.
+ *
+ * The default Cairo fontmap can be changed by using
+ * set_default(). This can be used to change the Cairo font backend
+ * that the default fontmap uses for example.
+ *
+ * Note that since %Pango 1.32.6, the default fontmap is per-thread.
+ * Each thread gets its own default fontmap. In this way,
+ * PangoCairo can be used safely from multiple threads.
+ *
+ * To use %Pango::CairoFontMap API, do something like
+ * @code
+ * auto font_map = Pango::CairoFontMap::get_default();
+ * auto cairo_font_map = std::dynamic_pointer_cast<Pango::CairoFontMap>(font_map);
+ * if (cairo_font_map)
+ * cairo_font_map->do_something();
+ * @endcode
+ *
+ * @newin{1,10}
+ *
+ * @return The default PangoCairo fontmap for the current thread.
+ */
_WRAP_METHOD(static Glib::RefPtr<FontMap> get_default(), pango_cairo_font_map_get_default, refreturn)
+
_WRAP_METHOD(void set_default(), pango_cairo_font_map_set_default)
#m4 _CONVERSION(`cairo_font_type_t',`Cairo::FontType',`static_cast<Cairo::FontType>($3)')
diff --git a/pango/src/fontmap.ccg b/pango/src/fontmap.ccg
index 0dae2af..e4d9ea6 100644
--- a/pango/src/fontmap.ccg
+++ b/pango/src/fontmap.ccg
@@ -16,11 +16,22 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <pangomm/cairofontmapimpl.h>
#include <pangomm/context.h>
+#include <pango/pangocairo.h>
namespace Pango
{
+// Custom wrap_new() because we want to create
+// a CairoFontMapImpl if the underlying C class implements the PangoCairoFontMap interface.
+Glib::ObjectBase* FontMap_Class::wrap_new(GObject* object)
+{
+ if (PANGO_IS_CAIRO_FONT_MAP(object))
+ return new CairoFontMapImpl((PangoFontMap*)object);
+ return new FontMap((PangoFontMap*)object);
+}
+
std::vector<Glib::RefPtr<FontFamily>> FontMap::list_families() const
{
//Get the array:
@@ -33,4 +44,3 @@ std::vector<Glib::RefPtr<FontFamily>> FontMap::list_families() const
}
} /* namespace Pango */
-
diff --git a/pango/src/fontmap.hg b/pango/src/fontmap.hg
index 353f559..79526d8 100644
--- a/pango/src/fontmap.hg
+++ b/pango/src/fontmap.hg
@@ -32,13 +32,19 @@ namespace Pango
class PANGOMM_API Context;
-/** A Pango::FontMap represents the set of fonts available for a particular rendering system.
+/** A %Pango::FontMap represents the set of fonts available for a particular rendering system.
+ *
+ * This is an abstract base class with implementations being specific to
+ * particular rendering systems.
+ *
+ * @see Pango::CairoFontMap::get_default()
*/
class PANGOMM_API FontMap : public Glib::Object, public Gio::ListModel
{
- _CLASS_GOBJECT(FontMap, PangoFontMap, PANGO_FONT_MAP, Glib::Object, GObject, , , PANGOMM_API)
- _IMPLEMENTS_INTERFACE(Gio::ListModel)
- _IGNORE(pango_font_map_list_families)
+ _CLASS_GOBJECT(FontMap, PangoFontMap, PANGO_FONT_MAP, Glib::Object, GObject, , , PANGOMM_API)
+ _IMPLEMENTS_INTERFACE(Gio::ListModel)
+ _CUSTOM_WRAP_NEW
+ _IGNORE(pango_font_map_list_families)
public:
_WRAP_METHOD(Glib::RefPtr<Font> load_font(const Glib::RefPtr<Context>& context, const FontDescription&
desc) const, pango_font_map_load_font)
@@ -53,7 +59,7 @@ public:
_WRAP_METHOD(guint get_serial() const, pango_font_map_get_serial)
- _IGNORE(pango_font_map_changed)
+ _IGNORE(pango_font_map_changed)dnl// Shall not be used by applications
};
} /* namespace Pango */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]