Merge branch 'private-fonts'

Add support for using application-private fonts.

Closes #13568.

Closes https://github.com/wxWidgets/wxWidgets/pull/591
This commit is contained in:
Vadim Zeitlin
2017-11-24 22:56:29 +01:00
34 changed files with 742 additions and 49 deletions

View File

@@ -21,6 +21,7 @@
$(TOP_SRCDIR)src/osx/carbon/wxmac.icns
</set>
<set var="BUNDLE_RESOURCES" overwrite="0"></set>
<set var="BUNDLE_FONT_RESOURCES" overwrite="0"></set>
<define-tag name="wx-mac-app-bundle" rules="exe">
@@ -44,6 +45,7 @@
<depends-on-file>$(BUNDLE_PLIST)</depends-on-file>
<depends-on-file>$(BUNDLE_ICON)</depends-on-file>
<depends-on-file>$(BUNDLE_RESOURCES)</depends-on-file>
<depends-on-file>$(BUNDLE_FONT_RESOURCES)</depends-on-file>
<command>
<!-- create the directories: -->
@@ -72,6 +74,16 @@
cp -f $(BUNDLE_RESOURCES) $(BUNDLE)/Resources
</command>
</if>
<if cond="BUNDLE_FONT_RESOURCES!=''">
<!--
Special case of font resources, which must be copied into
the Fonts subdirectory used in src/osx/carbon/Info.plist.in file.
-->
<command>
mkdir -p $(BUNDLE)/Resources/Fonts
cp -f $(BUNDLE_FONT_RESOURCES) $(BUNDLE)/Resources/Fonts
</command>
</if>
</modify-target>

123
configure vendored
View File

@@ -978,6 +978,8 @@ X_CFLAGS
XMKMF
DIRECTFB_LIBS
DIRECTFB_CFLAGS
PRIVATE_FONTS_LIBS
PRIVATE_FONTS_CFLAGS
GTK_CONFIG
GTK_LIBS
GTK_CFLAGS
@@ -1268,6 +1270,7 @@ enable_notifmsg
enable_odcombobox
enable_popupwin
enable_prefseditor
enable_privatefonts
enable_radiobox
enable_radiobtn
enable_richmsgdlg
@@ -1366,6 +1369,8 @@ CXX
CXXFLAGS
CCC
PKG_CONFIG
PRIVATE_FONTS_CFLAGS
PRIVATE_FONTS_LIBS
DIRECTFB_CFLAGS
DIRECTFB_LIBS
XMKMF
@@ -2205,6 +2210,7 @@ Optional Features:
--enable-odcombobox use wxOwnerDrawnComboBox class
--enable-popupwin use wxPopUpWindow class
--enable-prefseditor use wxPreferencesEditor class
--enable-privatefonts provide wxFont::AddPrivateFont() method
--enable-radiobox use wxRadioBox class
--enable-radiobtn use wxRadioButton class
--enable-richmsgdlg use wxRichMessageDialog class
@@ -2348,6 +2354,10 @@ Some influential environment variables:
CXX C++ compiler command
CXXFLAGS C++ compiler flags
PKG_CONFIG path to pkg-config utility
PRIVATE_FONTS_CFLAGS
C compiler flags for PRIVATE_FONTS, overriding pkg-config
PRIVATE_FONTS_LIBS
linker flags for PRIVATE_FONTS, overriding pkg-config
DIRECTFB_CFLAGS
C compiler flags for DIRECTFB, overriding pkg-config
DIRECTFB_LIBS
@@ -10184,6 +10194,35 @@ fi
eval "$wx_cv_use_prefseditor"
enablestring=
defaultval=$wxUSE_ALL_FEATURES
if test -z "$defaultval"; then
if test x"$enablestring" = xdisable; then
defaultval=yes
else
defaultval=no
fi
fi
# Check whether --enable-privatefonts was given.
if test "${enable_privatefonts+set}" = set; then :
enableval=$enable_privatefonts;
if test "$enableval" = yes; then
wx_cv_use_privatefonts='wxUSE_PRIVATE_FONTS=yes'
else
wx_cv_use_privatefonts='wxUSE_PRIVATE_FONTS=no'
fi
else
wx_cv_use_privatefonts='wxUSE_PRIVATE_FONTS=${'DEFAULT_wxUSE_PRIVATE_FONTS":-$defaultval}"
fi
eval "$wx_cv_use_privatefonts"
enablestring=
defaultval=$wxUSE_ALL_FEATURES
if test -z "$defaultval"; then
@@ -22471,6 +22510,85 @@ $as_echo "not found" >&6; }
fi
fi
if test "$wxUSE_PRIVATE_FONTS" = "yes"; then
pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PRIVATE_FONTS" >&5
$as_echo_n "checking for PRIVATE_FONTS... " >&6; }
if test -n "$PKG_CONFIG"; then
if test -n "$PRIVATE_FONTS_CFLAGS"; then
pkg_cv_PRIVATE_FONTS_CFLAGS="$PRIVATE_FONTS_CFLAGS"
else
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fontconfig >= 2.8.0 pangoft2 >= 1.38.0\""; } >&5
($PKG_CONFIG --exists --print-errors "fontconfig >= 2.8.0 pangoft2 >= 1.38.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_PRIVATE_FONTS_CFLAGS=`$PKG_CONFIG --cflags "fontconfig >= 2.8.0 pangoft2 >= 1.38.0" 2>/dev/null`
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
fi
if test -n "$PKG_CONFIG"; then
if test -n "$PRIVATE_FONTS_LIBS"; then
pkg_cv_PRIVATE_FONTS_LIBS="$PRIVATE_FONTS_LIBS"
else
if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"fontconfig >= 2.8.0 pangoft2 >= 1.38.0\""; } >&5
($PKG_CONFIG --exists --print-errors "fontconfig >= 2.8.0 pangoft2 >= 1.38.0") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
pkg_cv_PRIVATE_FONTS_LIBS=`$PKG_CONFIG --libs "fontconfig >= 2.8.0 pangoft2 >= 1.38.0" 2>/dev/null`
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
fi
if test $pkg_failed = yes; then
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
_pkg_short_errors_supported=yes
else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
PRIVATE_FONTS_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "fontconfig >= 2.8.0 pangoft2 >= 1.38.0"`
else
PRIVATE_FONTS_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "fontconfig >= 2.8.0 pangoft2 >= 1.38.0"`
fi
# Put the nasty error message in config.log where it belongs
echo "$PRIVATE_FONTS_PKG_ERRORS" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: run-time font loading won't be supported by wxFont" >&5
$as_echo "$as_me: WARNING: run-time font loading won't be supported by wxFont" >&2;}
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: run-time font loading won't be supported by wxFont" >&5
$as_echo "$as_me: WARNING: run-time font loading won't be supported by wxFont" >&2;}
else
PRIVATE_FONTS_CFLAGS=$pkg_cv_PRIVATE_FONTS_CFLAGS
PRIVATE_FONTS_LIBS=$pkg_cv_PRIVATE_FONTS_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define wxUSE_PRIVATE_FONTS 1" >>confdefs.h
CXXFLAGS="$PRIVATE_FONTS_CFLAGS $CXXFLAGS"
GUI_TK_LIBRARY="$GUI_TK_LIBRARY $PRIVATE_FONTS_LIBS"
fi
fi
fi
if test "$wxUSE_DFB" = 1; then
@@ -34286,6 +34404,11 @@ if test "$wxUSE_PREFERENCES_EDITOR" = "yes"; then
SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS preferences"
fi
if test "$wxUSE_PRIVATE_FONTS" = "yes"; then
$as_echo "#define wxUSE_PRIVATE_FONTS 1" >>confdefs.h
fi
if test "$wxUSE_DIALUP_MANAGER" = "yes"; then
if test "$wxUSE_MAC" = 1; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Dialup manager not supported on this platform... disabled" >&5

View File

@@ -925,6 +925,7 @@ WX_ARG_FEATURE(notifmsg, [ --enable-notifmsg use wxNotificationMessage
WX_ARG_FEATURE(odcombobox, [ --enable-odcombobox use wxOwnerDrawnComboBox class], wxUSE_ODCOMBOBOX)
WX_ARG_FEATURE(popupwin, [ --enable-popupwin use wxPopUpWindow class], wxUSE_POPUPWIN)
WX_ARG_FEATURE(prefseditor, [ --enable-prefseditor use wxPreferencesEditor class], wxUSE_PREFERENCES_EDITOR)
WX_ARG_FEATURE(privatefonts,[ --enable-privatefonts provide wxFont::AddPrivateFont() method], wxUSE_PRIVATE_FONTS)
WX_ARG_FEATURE(radiobox, [ --enable-radiobox use wxRadioBox class], wxUSE_RADIOBOX)
WX_ARG_FEATURE(radiobtn, [ --enable-radiobtn use wxRadioButton class], wxUSE_RADIOBTN)
WX_ARG_FEATURE(richmsgdlg, [ --enable-richmsgdlg use wxRichMessageDialog class], wxUSE_RICHMSGDLG)
@@ -2962,6 +2963,16 @@ libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
dnl AC_MSG_RESULT(not found)
dnl fi
fi
if test "$wxUSE_PRIVATE_FONTS" = "yes"; then
PKG_CHECK_MODULES(PRIVATE_FONTS, [fontconfig >= 2.8.0 pangoft2 >= 1.38.0],
[
AC_DEFINE(wxUSE_PRIVATE_FONTS)
CXXFLAGS="$PRIVATE_FONTS_CFLAGS $CXXFLAGS"
GUI_TK_LIBRARY="$GUI_TK_LIBRARY $PRIVATE_FONTS_LIBS"
],
[AC_MSG_WARN([run-time font loading won't be supported by wxFont])])
fi
fi
if test "$wxUSE_DFB" = 1; then
@@ -6896,6 +6907,10 @@ if test "$wxUSE_PREFERENCES_EDITOR" = "yes"; then
SAMPLES_SUBDIRS="$SAMPLES_SUBDIRS preferences"
fi
if test "$wxUSE_PRIVATE_FONTS" = "yes"; then
AC_DEFINE(wxUSE_PRIVATE_FONTS)
fi
if test "$wxUSE_DIALUP_MANAGER" = "yes"; then
if test "$wxUSE_MAC" = 1; then
AC_MSG_WARN([Dialup manager not supported on this platform... disabled])

View File

@@ -109,6 +109,7 @@ All (GUI):
- Allow wxWebView::RunScript() return values (Jose Lorenzo, GSoC 2017).
- Allow using fractional pen widths with wxGraphicsContext (Adrien Tétar).
- Add support for loading fonts from external files (Arthur Norman).
- Improve wxSVGFileDC to support more of wxDC API (Maarten Bent).
- Add support for wxAuiManager and wxAuiPaneInfo to XRC (Andrea Zanellato).
- Add support for wxSL_MIN_MAX_LABELS and wxSL_VALUE_LABEL to XRC (ousnius).

View File

@@ -186,6 +186,7 @@ library:
@itemdef{wxUSE_POSTSCRIPT, Use wxPostScriptPrinter class.}
@itemdef{wxUSE_PRINTF_POS_PARAMS, Use wxVsnprintf which supports positional parameters.}
@itemdef{wxUSE_PRINTING_ARCHITECTURE, Enable printer classes.}
@itemdef{wxUSE_PRIVATE_FONTS, Implement wxFont::AddPrivateFont() method.}
@itemdef{wxUSE_PROGRESSDLG, Enables progress dialog classes.}
@itemdef{wxUSE_PROPGRID, Use wxPropertyGrid library.}
@itemdef{wxUSE_PROTOCOL, Use wxProtocol and derived classes.}

View File

@@ -75,4 +75,16 @@ implemented for Windows and Unix (GTK+ and Motif) ports only, all the methods
are available for all the ports and should be used to make your program work
correctly when they are implemented later.
@section overview_font_privateinfo Private font information
Sometimes an application needs fonts that are not globally installed on the
system. On Macintosh/OSX this can be arranged by placing the desired fonts
within the Application Bundle in Contents/Resources/Fonts and using
the ATSApplicationFontsPath key to point there. The full details of the
procedure there can be found as OSX developer resources. For the GTK+ and
Windows ports it is possible to add TrueType fonts from arbitrary locations at
run-time using wxFont::AddPrivateFont(). Notice that under MSW this function
should be called before creating the first wxGraphicsContext object if you want
the private font to be usable from it.
*/

View File

@@ -794,14 +794,14 @@
// notice that we can't use wxCHECK_VISUALC_VERSION() here as this file is
// included from wx/platform.h before wxCHECK_VISUALC_VERSION() is defined
#ifdef _MSC_VER
# define wxUSE_GRAPHICS_CONTEXT 1
#define wxUSE_GRAPHICS_CONTEXT 1
#else
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
# define wxUSE_GRAPHICS_CONTEXT 0
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
#define wxUSE_GRAPHICS_CONTEXT 0
#endif
// Enable wxGraphicsContext implementation using Cairo library.
@@ -1141,6 +1141,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -983,6 +983,14 @@
# endif
#endif /* !defined(wxUSE_PREFERENCES_EDITOR) */
#ifndef wxUSE_PRIVATE_FONTS
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_PRIVATE_FONTS must be defined, please read comment near the top of this file."
# else
# define wxUSE_PRIVATE_FONTS 0
# endif
#endif /* !defined(wxUSE_PRIVATE_FONTS) */
#ifndef wxUSE_PRINTING_ARCHITECTURE
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_PRINTING_ARCHITECTURE must be defined, please read comment near the top of this file."
@@ -2305,6 +2313,13 @@
# endif
#endif /* wxUSE_PREFERENCES_EDITOR */
#if wxUSE_PRIVATE_FONTS
# if !defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXOSX__)
# undef wxUSE_PRIVATE_FONTS
# define wxUSE_PRIVATE_FONTS 0
# endif
#endif /* wxUSE_PRIVATE_FONTS */
#if wxUSE_MEDIACTRL
# if !wxUSE_LONGLONG
# ifdef wxABORT_ON_CONFIG_ERROR

View File

@@ -328,6 +328,12 @@ public:
// from the string representation of wxNativeFontInfo
static wxFont *New(const wxString& strNativeFontDesc);
// Load the font from the given file and return true on success or false on
// error (an error message will be logged in this case).
#if wxUSE_PRIVATE_FONTS
static bool AddPrivateFont(const wxString& filename);
#endif // wxUSE_PRIVATE_FONTS
// comparison
bool operator==(const wxFont& font) const;
bool operator!=(const wxFont& font) const { return !(*this == font); }

View File

@@ -74,6 +74,11 @@ public:
// in the user's system
static bool IsValidFacename(const wxString &str);
// Invalidate cache used by some of the methods of this class internally.
// This should be called if the list of the fonts available on the system
// changes, for whatever reason.
static void InvalidateCache();
private:
#ifdef wxHAS_UTF8_FONTS
// helper for ports that only use UTF-8 encoding natively

View File

@@ -795,14 +795,14 @@
// notice that we can't use wxCHECK_VISUALC_VERSION() here as this file is
// included from wx/platform.h before wxCHECK_VISUALC_VERSION() is defined
#ifdef _MSC_VER
# define wxUSE_GRAPHICS_CONTEXT 1
#define wxUSE_GRAPHICS_CONTEXT 1
#else
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
# define wxUSE_GRAPHICS_CONTEXT 0
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
#define wxUSE_GRAPHICS_CONTEXT 0
#endif
// Enable wxGraphicsContext implementation using Cairo library.
@@ -1142,6 +1142,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -795,14 +795,14 @@
// notice that we can't use wxCHECK_VISUALC_VERSION() here as this file is
// included from wx/platform.h before wxCHECK_VISUALC_VERSION() is defined
#ifdef _MSC_VER
# define wxUSE_GRAPHICS_CONTEXT 1
#define wxUSE_GRAPHICS_CONTEXT 1
#else
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
# define wxUSE_GRAPHICS_CONTEXT 0
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
#define wxUSE_GRAPHICS_CONTEXT 0
#endif
// Enable wxGraphicsContext implementation using Cairo library.
@@ -1142,6 +1142,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -795,14 +795,14 @@
// notice that we can't use wxCHECK_VISUALC_VERSION() here as this file is
// included from wx/platform.h before wxCHECK_VISUALC_VERSION() is defined
#ifdef _MSC_VER
# define wxUSE_GRAPHICS_CONTEXT 1
#define wxUSE_GRAPHICS_CONTEXT 1
#else
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
# define wxUSE_GRAPHICS_CONTEXT 0
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
#define wxUSE_GRAPHICS_CONTEXT 0
#endif
// Enable wxGraphicsContext implementation using Cairo library.
@@ -1142,6 +1142,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -1148,6 +1148,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -1138,6 +1138,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -794,14 +794,14 @@
// notice that we can't use wxCHECK_VISUALC_VERSION() here as this file is
// included from wx/platform.h before wxCHECK_VISUALC_VERSION() is defined
#ifdef _MSC_VER
# define wxUSE_GRAPHICS_CONTEXT 1
#define wxUSE_GRAPHICS_CONTEXT 1
#else
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
# define wxUSE_GRAPHICS_CONTEXT 0
// Disable support for other Windows compilers, enable it if your compiler
// comes with new enough SDK or you installed the headers manually.
//
// Notice that this will be set by configure under non-Windows platforms
// anyhow so the value there is not important.
#define wxUSE_GRAPHICS_CONTEXT 0
#endif
// Enable wxGraphicsContext implementation using Cairo library.
@@ -1141,6 +1141,16 @@
// Recommended setting: 1 (but can be safely disabled if you don't use it)
#define wxUSE_PREFERENCES_EDITOR 1
// wxFont::AddPrivateFont() allows to use fonts not installed on the system by
// loading them from font files during run-time.
//
// Default is 1 except under Unix where it will be turned off by configure if
// the required libraries are not available or not new enough.
//
// Recommended setting: 1 (but can be safely disabled if you don't use it and
// want to avoid extra dependencies under Linux, for example).
#define wxUSE_PRIVATE_FONTS 1
// wxRichToolTip is a customizable tooltip class which has more functionality
// than the stock (but native, unlike this class) wxToolTip.
//

View File

@@ -664,6 +664,39 @@ public:
const wxNativeFontInfo *GetNativeFontInfo() const;
/**
Specify the name of a file containing a TrueType font to be
made available to the current application.
This method can be used to allow this application to use the font from
the given file even if it is not globally installed on the system.
Under OS X this method actually doesn't do anything other than check
for the existence of the file in the "Fonts" subdirectory of the
application bundle "Resources" directory. You are responsible for
actually making the font file available in this directory and setting
@c ATSApplicationFontsPath to @c Fonts value in your @c Info.plist
file. See also wxStandardPaths::GetResourcesDir().
Under MSW this method must be called before any wxGraphicsContext
objects have been created, otherwise the private font won't be usable
from them.
Under Unix this method requires Pango 1.38 or later and will return @a
false and log an error message explaining the problem if this
requirement is not satisfied either at compile- or run-time.
Currently this method is implemented for all major platforms (subject
to having Pango 1.38 or later when running configure under Unix) and
@c wxUSE_PRIVATE_FONTS is always set to 0 under the other platforms,
making this function unavailable at compile-time.
@return @true if the font was added and can now be used.
@since 3.1.1
*/
static bool AddPrivateFont(const wxString& filename);
/**
Gets the point size.

View File

@@ -73,6 +73,17 @@ public:
*/
static bool IsValidFacename(const wxString& facename);
/**
Invalidate cache used by some of the methods of this class internally.
This method should be called if the list of the fonts available on the
system changes, for whatever reason. In particular, it is called
automatically by wxFont::AddPrivateFont().
@since 3.1.1
*/
static void InvalidateCache();
/**
Called by EnumerateFacenames() for each match.

View File

@@ -128,7 +128,7 @@ COND_wxUSE_REGEX_builtin___LIB_REGEX_p = \
### Targets: ###
all: font$(EXEEXT) $(__font_bundle___depname)
all: font$(EXEEXT) $(__font_bundle___depname) data
install:
@@ -149,7 +149,7 @@ font$(EXEEXT): $(FONT_OBJECTS) $(__font___win32rc)
$(CXX) -o $@ $(FONT_OBJECTS) -L$(LIBDIRNAME) $(LDFLAGS_GUI) $(SAMPLES_RPATH_FLAG) $(LDFLAGS) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) $(EXTRALIBS_FOR_GUI) $(__LIB_ZLIB_p) $(__LIB_REGEX_p) $(__LIB_EXPAT_p) $(EXTRALIBS_FOR_BASE) $(LIBS)
$(__font___os2_emxbindcmd)
@COND_PLATFORM_MACOSX_1@font.app/Contents/PkgInfo: font$(EXEEXT) $(top_srcdir)/src/osx/carbon/Info.plist.in $(top_srcdir)/src/osx/carbon/wxmac.icns
@COND_PLATFORM_MACOSX_1@font.app/Contents/PkgInfo: font$(EXEEXT) $(top_srcdir)/src/osx/carbon/Info.plist.in $(top_srcdir)/src/osx/carbon/wxmac.icns $(srcdir)/wxprivate.ttf
@COND_PLATFORM_MACOSX_1@ mkdir -p font.app/Contents
@COND_PLATFORM_MACOSX_1@ mkdir -p font.app/Contents/MacOS
@COND_PLATFORM_MACOSX_1@ mkdir -p font.app/Contents/Resources
@@ -168,9 +168,23 @@ font$(EXEEXT): $(FONT_OBJECTS) $(__font___win32rc)
@COND_PLATFORM_MACOSX_1@
@COND_PLATFORM_MACOSX_1@
@COND_PLATFORM_MACOSX_1@ cp -f $(top_srcdir)/src/osx/carbon/wxmac.icns font.app/Contents/Resources/wxmac.icns
@COND_PLATFORM_MACOSX_1@ mkdir -p font.app/Contents/Resources/Fonts
@COND_PLATFORM_MACOSX_1@ cp -f $(srcdir)/wxprivate.ttf font.app/Contents/Resources/Fonts
@COND_PLATFORM_MACOSX_1@font_bundle: $(____font_BUNDLE_TGT_REF_DEP)
data:
@mkdir -p .
@for f in wxprivate.ttf; do \
if test ! -f ./$$f -a ! -d ./$$f ; \
then x=yep ; \
else x=`find $(srcdir)/$$f -newer ./$$f -print` ; \
fi; \
case "$$x" in ?*) \
cp -pRf $(srcdir)/$$f . ;; \
esac; \
done
font_sample_rc.o: $(srcdir)/../../samples/sample.rc
$(WINDRES) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) --include-dir $(srcdir) $(__DLLFLAG_p_1) --include-dir $(srcdir)/../../samples $(__RCDEFDIR_p) --include-dir $(top_srcdir)/include
@@ -181,4 +195,4 @@ font_font.o: $(srcdir)/font.cpp
# Include dependency info, if present:
@IF_GNU_MAKE@-include ./.deps/*.d
.PHONY: all install uninstall clean distclean font_bundle
.PHONY: all install uninstall clean distclean font_bundle data

View File

@@ -1,6 +1,8 @@
<?xml version="1.0" ?>
<makefile>
<set var="BUNDLE_FONT_RESOURCES">$(SRCDIR)/wxprivate.ttf</set>
<include file="../../build/bakefiles/common_samples.bkl"/>
<exe id="font" template="wx_sample" template_append="wx_append">
@@ -9,4 +11,11 @@
<wx-lib>base</wx-lib>
</exe>
<wx-data id="data">
<files>
wxprivate.ttf
</files>
</wx-data>
</makefile>

View File

@@ -29,6 +29,7 @@
#include "wx/fontmap.h"
#include "wx/encconv.h"
#include "wx/splitter.h"
#include "wx/stdpaths.h"
#include "wx/textfile.h"
#include "wx/settings.h"
@@ -130,6 +131,7 @@ public:
void OnSetFamily(wxCommandEvent& event);
void OnSetFaceName(wxCommandEvent& event);
void OnSetEncoding(wxCommandEvent& event);
void OnPrivateFont(wxCommandEvent& event);
protected:
bool DoEnumerateFamilies(bool fixedWidthOnly,
@@ -212,6 +214,8 @@ enum
Font_SetFamily,
Font_SetFaceName,
Font_SetEncoding,
Font_Private,
Font_Max
};
@@ -265,6 +269,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings)
EVT_MENU(Font_Private, MyFrame::OnPrivateFont)
wxEND_EVENT_TABLE()
// Create a new application object: this macro will allow wxWidgets to create
@@ -287,6 +292,7 @@ bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
wxString privfont = argv[0].BeforeLast('/');
// Create the main application window
MyFrame *frame = new MyFrame(wxT("Font wxWidgets demo"),
@@ -381,7 +387,6 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
wxT("Default font for user interface objects such as menus and dialog boxes. "));
menuSelect->Append(Font_SystemSettings, wxT("System fonts"), menuSettingFonts);
menuSelect->AppendSeparator();
menuSelect->Append(Font_EnumFamilies, wxT("Enumerate font &families\tCtrl-F"));
menuSelect->Append(Font_EnumFixedFamilies,
@@ -392,6 +397,45 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
wxT("Find font for en&coding...\tCtrl-C"),
wxT("Find font families for given encoding"));
#if wxUSE_PRIVATE_FONTS
// Try to use a private font, under most platforms we just look for it in
// the current directory but under OS X it must be in a specific location
// so look for it there.
//
// For OS X you also need to ensure that you actually do put wxprivate.ttf
// in font.app/Contents/Resources/Fonts and add the following snippet
//
// <plist version="0.9">
// <dict>
// ...
// <key>ATSApplicationFontsPath</key>
// <string>Fonts</string>
// ...
// </dict>
// </plist>
//
// to your font.app/Contents/Info.plist.
wxString privfont;
#ifdef __WXOSX__
privfont << wxStandardPaths::Get().GetResourcesDir() << "/Fonts/";
#endif
privfont << "wxprivate.ttf";
if ( !wxFont::AddPrivateFont(privfont) )
{
wxLogWarning("Failed to add private font from \"%s\"", privfont);
}
else
{
menuSelect->AppendSeparator();
menuSelect->Append(Font_Private,
"Select private font",
"Select a font available only in this application");
}
#endif // wxUSE_PRIVATE_FONTS
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, wxT("&File"));
@@ -873,6 +917,20 @@ void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
}
}
void MyFrame::OnPrivateFont(wxCommandEvent& WXUNUSED(event))
{
wxFont font(GetCanvas()->GetTextFont());
if (font.SetFaceName("wxprivate"))
{
wxASSERT_MSG( font.IsOk(), wxT("The font should now be valid")) ;
DoChangeFont(font);
}
else
{
wxLogError("Failed to use private font.");
}
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
// true is to force the frame to close

View File

@@ -213,7 +213,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\font.exe
all: $(OBJS)\font.exe data
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -231,6 +231,10 @@ $(OBJS)\font.exe: $(FONT_OBJECTS) $(OBJS)\font_sample.res
c0w32.obj $(FONT_OBJECTS),$@,, $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) ole2w32.lib oleacc.lib import32.lib cw32$(__THREADSFLAG_5)$(__RUNTIME_LIBS_8).lib,, $(OBJS)\font_sample.res
|
data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (wxprivate.ttf) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\font_sample.res: .\..\..\samples\sample.rc
brcc32 -32 -r -fo$@ -i$(BCCDIR)\include -d__WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) -i$(SETUPHDIR) -i.\..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_1_p) -i. $(__DLLFLAG_p_1) -i.\..\..\samples -i$(BCCDIR)\include\windows\sdk -dNOPCH .\..\..\samples\sample.rc

View File

@@ -210,7 +210,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\font.exe
all: $(OBJS)\font.exe data
clean:
-if exist $(OBJS)\*.o del $(OBJS)\*.o
@@ -220,13 +220,17 @@ clean:
$(OBJS)\font.exe: $(FONT_OBJECTS) $(OBJS)\font_sample_rc.o
$(CXX) -o $@ $(FONT_OBJECTS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows $(____CAIRO_LIBDIR_FILENAMES_p) $(LDFLAGS) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lversion -lwsock32 -lwininet -loleacc
data:
if not exist $(OBJS) mkdir $(OBJS)
for %%f in (wxprivate.ttf) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
$(OBJS)\font_sample_rc.o: ./../../samples/sample.rc
$(WINDRES) -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) --include-dir $(SETUPHDIR) --include-dir ./../../include $(__CAIRO_INCLUDEDIR_p) --include-dir . $(__DLLFLAG_p_1) --include-dir ./../../samples --define NOPCH
$(OBJS)\font_font.o: ./font.cpp
$(CXX) -c -o $@ $(FONT_CXXFLAGS) $(CPPDEPS) $<
.PHONY: all clean
.PHONY: all clean data
SHELL := $(COMSPEC)

View File

@@ -339,7 +339,7 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\font.exe
all: $(OBJS)\font.exe data
clean:
-if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -354,6 +354,10 @@ $(OBJS)\font.exe: $(FONT_OBJECTS) $(OBJS)\font_sample.res
$(FONT_OBJECTS) $(FONT_RESOURCES) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib shlwapi.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib version.lib wsock32.lib wininet.lib
<<
data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (wxprivate.ttf) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\font_sample.res: .\..\..\samples\sample.rc
rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_3_p_1) /d _CRT_SECURE_NO_DEPRECATE=1 /d _CRT_NON_CONFORMING_SWPRINTFS=1 /d _SCL_SECURE_NO_WARNINGS=1 $(__NO_VC_CRTDBG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__NDEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) /i $(SETUPHDIR) /i .\..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_1_p) /i . $(__DLLFLAG_p_1) /d _WINDOWS /i .\..\..\samples /d NOPCH .\..\..\samples\sample.rc

BIN
samples/font/wxprivate.ttf Normal file

Binary file not shown.

View File

@@ -194,7 +194,7 @@ data:
data_doc:
@mkdir -p ./doc
@for f in aindex.html down.gif dxxgifs.tex HIER.html icon1.gif icon2.gif index.html logo.gif wx204.htm wx34.htm wxExtHelpController.html wxhelp.map wx.htm; do \
@for f in aindex.html ClassGraph.class ClassGraphPanel.class ClassLayout.class down.gif dxxgifs.tex HIER.html HIERjava.html icon1.gif icon2.gif index.html logo.gif NavigatorButton.class USE_HELP.html wx204.htm wx34.htm wxExtHelpController.html wxhelp.map wx.htm; do \
if test ! -f ./doc/$$f -a ! -d ./doc/$$f ; \
then x=yep ; \
else x=`find $(srcdir)/doc/$$f -newer ./doc/$$f -print` ; \

View File

@@ -468,6 +468,8 @@
#define wxUSE_PREFERENCES_EDITOR 0
#define wxUSE_PRIVATE_FONTS 0
#define wxUSE_RICHTOOLTIP 0
#define wxUSE_SASH 0

View File

@@ -1136,5 +1136,3 @@ bool wxFromString(const wxString& str, wxFontBase *font)
return font->SetNativeFontInfo(str);
}

View File

@@ -26,6 +26,31 @@
#if wxUSE_FONTENUM
#include "wx/fontenum.h"
#include "wx/module.h"
namespace
{
// Cached result of GetFacenames().
wxArrayString gs_allFacenames;
// Module used to ensure the cache is cleared on library shutdown and so is not
// reused if it re-initialized again later.
class wxFontEnumCacheCleanupModule : public wxModule
{
public:
wxFontEnumCacheCleanupModule() { }
bool OnInit() wxOVERRIDE { return true; }
void OnExit() wxOVERRIDE { gs_allFacenames.clear(); }
private:
wxDECLARE_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule);
};
wxIMPLEMENT_DYNAMIC_CLASS(wxFontEnumCacheCleanupModule, wxModule);
} // anonymous namespace
// ============================================================================
// implementation
@@ -79,7 +104,8 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
{
// we cache the result of wxFontEnumerator::GetFacenames supposing that
// the array of face names won't change in the session of this program
static wxArrayString s_arr = wxFontEnumerator::GetFacenames();
if ( gs_allFacenames.empty() )
gs_allFacenames = wxFontEnumerator::GetFacenames();
#ifdef __WXMSW__
// Quoting the MSDN:
@@ -95,12 +121,18 @@ bool wxFontEnumerator::IsValidFacename(const wxString &facename)
#endif
// is given font face name a valid one ?
if (s_arr.Index(facename, false) == wxNOT_FOUND)
if (gs_allFacenames.Index(facename, false) == wxNOT_FOUND)
return false;
return true;
}
/* static */
void wxFontEnumerator::InvalidateCache()
{
gs_allFacenames.clear();
}
#ifdef wxHAS_UTF8_FONTS
bool wxFontEnumerator::EnumerateEncodingsUTF8(const wxString& facename)
{

View File

@@ -20,6 +20,7 @@
#include "wx/font.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/utils.h"
#include "wx/settings.h"
@@ -551,3 +552,101 @@ bool wxFont::GTKSetPangoAttrs(PangoLayout* layout) const
return true;
}
// ----------------------------------------------------------------------------
// Support for adding private fonts
// ----------------------------------------------------------------------------
#if wxUSE_PRIVATE_FONTS
#include "wx/fontenum.h"
#include "wx/module.h"
#include "wx/gtk/private.h"
#include "wx/gtk/private/object.h"
#include <fontconfig/fontconfig.h>
#include <pango/pangofc-fontmap.h>
extern PangoContext* wxGetPangoContext();
namespace
{
FcConfig* gs_fcConfig = NULL;
// Module used to clean up the global FcConfig.
class wxFcConfigDestroyModule : public wxModule
{
public:
wxFcConfigDestroyModule() { }
bool OnInit() wxOVERRIDE { return true; }
void OnExit() wxOVERRIDE
{
if ( gs_fcConfig )
{
FcConfigDestroy(gs_fcConfig);
gs_fcConfig = NULL;
}
}
private:
wxDECLARE_DYNAMIC_CLASS(wxFcConfigDestroyModule);
};
wxIMPLEMENT_DYNAMIC_CLASS(wxFcConfigDestroyModule, wxModule);
} // anonymous namespace
bool wxFontBase::AddPrivateFont(const wxString& filename)
{
// We already checked that we have the required functions at compile-time,
// but we should also check if they're available at run-time in case we use
// older versions of them than the ones we were compiled with.
if ( wx_pango_version_check(1,38,0) != NULL )
{
wxLogError(_("Using private fonts is not supported on this system: "
"Pango library is too old, 1.38 or later required."));
return false;
}
if ( !gs_fcConfig )
{
gs_fcConfig = FcInitLoadConfigAndFonts();
if ( !gs_fcConfig )
{
wxLogError(_("Failed to create font configuration object."));
return false;
}
}
if ( !FcConfigAppFontAddFile(gs_fcConfig,
reinterpret_cast<const FcChar8*>(
static_cast<const char*>(filename.utf8_str())
)) )
{
wxLogError(_("Failed to add custom font \"%s\"."), filename);
return false;
}
wxGtkObject<PangoContext> context(wxGetPangoContext());
PangoFontMap* const fmap = pango_context_get_font_map(context);
if ( !fmap || !PANGO_IS_FC_FONT_MAP(fmap) )
{
wxLogError(_("Failed to register font configuration using private fonts."));
return false;
}
PangoFcFontMap* const fcfmap = PANGO_FC_FONT_MAP(fmap);
pango_fc_font_map_set_config(fcfmap, gs_fcConfig);
// Ensure that the face names defined by private fonts are recognized by
// our SetFaceName() which uses wxFontEnumerator to check if the name is in
// the list of available faces.
wxFontEnumerator::InvalidateCache();
return true;
}
#endif // wxUSE_PRIVATE_FONTS

View File

@@ -30,6 +30,7 @@
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/log.h"
#include "wx/module.h"
#include "wx/msw/private.h"
#endif // WX_PRECOMP
@@ -1083,3 +1084,54 @@ bool wxFont::IsFixedWidth() const
// those meanings are the opposite of what the constant name implies."
return !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
}
// ----------------------------------------------------------------------------
// Private fonts support
// ----------------------------------------------------------------------------
#if wxUSE_PRIVATE_FONTS
namespace
{
// Contains the file names of all fonts added by AddPrivateFont().
wxArrayString gs_privateFontFileNames;
} // anonymous namespace
// Accessor for use in src/msw/graphics.cpp only.
extern const wxArrayString& wxGetPrivateFontFileNames()
{
return gs_privateFontFileNames;
}
// We need to use a module to clean up the list of private fonts when the
// library is shut down.
class wxPrivateFontsListModule : public wxModule
{
public:
wxPrivateFontsListModule() { }
bool OnInit() wxOVERRIDE { return true; }
void OnExit() wxOVERRIDE { gs_privateFontFileNames.clear(); }
private:
wxDECLARE_DYNAMIC_CLASS(wxPrivateFontsListModule);
};
wxIMPLEMENT_DYNAMIC_CLASS(wxPrivateFontsListModule, wxModule);
bool wxFontBase::AddPrivateFont(const wxString& filename)
{
if ( !AddFontResourceEx(filename.t_str(), FR_PRIVATE, 0) )
{
wxLogSysError(_("Font file \"%s\" couldn't be loaded"), filename);
return false;
}
// Remember it for use in wxGDIPlusRenderer::Load().
gs_privateFontFileNames.Add(filename);
return true;
}
#endif // wxUSE_PRIVATE_FONTS

View File

@@ -959,6 +959,25 @@ wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo,
SetGradientStops(brush, stops, true);
}
//-----------------------------------------------------------------------------
// Support for adding private fonts
//-----------------------------------------------------------------------------
#if wxUSE_PRIVATE_FONTS
namespace
{
Gdiplus::PrivateFontCollection* gs_privateFonts = NULL;
Gdiplus::FontFamily* gs_pFontFamily = NULL;
} // anonymous namespace
// This function is defined in src/msw/font.cpp.
extern const wxArrayString& wxGetPrivateFontFileNames();
#endif // wxUSE_PRIVATE_FONTS
//-----------------------------------------------------------------------------
// wxGDIPlusFont implementation
//-----------------------------------------------------------------------------
@@ -970,7 +989,35 @@ wxGDIPlusFontData::Init(const wxString& name,
const wxColour& col,
Unit fontUnit)
{
m_font = new Font(name.wc_str(), size, style, fontUnit);
#if wxUSE_PRIVATE_FONTS
// If the user has registered any private fonts, they should be used in
// preference to any system-wide ones.
m_font = NULL;
if ( gs_privateFonts )
{
const int count = gs_privateFonts->GetFamilyCount();
// We should find all the families, i.e. "found" should be "count".
int found = 0;
gs_privateFonts->GetFamilies(count, gs_pFontFamily, &found);
for ( int j = 0 ; j < found; j++ )
{
wchar_t familyName[LF_FACESIZE];
int rc = gs_pFontFamily[j].GetFamilyName(familyName);
if ( rc == 0 && name == familyName )
{
m_font = new Font(&gs_pFontFamily[j], size, style, fontUnit);
break;
}
}
}
if ( !m_font )
#endif // wxUSE_PRIVATE_FONTS
{
m_font = new Font(name.wc_str(), size, style, fontUnit);
}
m_textBrush = new SolidBrush(wxColourToColor(col));
}
@@ -2275,6 +2322,23 @@ void wxGDIPlusRenderer::Load()
{
wxLogTrace("gdiplus", "successfully initialized GDI+");
m_loaded = 1;
#if wxUSE_PRIVATE_FONTS
// Make private fonts available to GDI+, if any.
const wxArrayString& privateFonts = wxGetPrivateFontFileNames();
const size_t n = privateFonts.size();
if ( n )
{
gs_privateFonts = new Gdiplus::PrivateFontCollection();
for ( size_t i = 0 ; i < n; i++ )
{
const wxString& fname = privateFonts[i];
gs_privateFonts->AddFontFile(fname.t_str());
}
gs_pFontFamily = new Gdiplus::FontFamily[n];
}
#endif // wxUSE_PRIVATE_FONTS
}
else
{
@@ -2289,6 +2353,17 @@ void wxGDIPlusRenderer::Unload()
{
GdiplusShutdown(m_gditoken);
m_gditoken = 0;
#if wxUSE_PRIVATE_FONTS
if ( gs_privateFonts )
{
delete gs_privateFonts;
gs_privateFonts = NULL;
delete[] gs_pFontFamily;
gs_pFontFamily = NULL;
}
#endif // wxUSE_PRIVATE_FONTS
}
m_loaded = -1; // next Load() will try again
}

View File

@@ -41,5 +41,7 @@
<true/>
<key>CSResourcesFileMapped</key>
<true/>
<key>ATSApplicationFontsPath</key>
<string>Fonts</string>
</dict>
</plist>

View File

@@ -24,6 +24,8 @@
#include "wx/fontutil.h"
#include "wx/fontmap.h"
#include "wx/encinfo.h"
#include "wx/filename.h"
#include "wx/stdpaths.h"
#include "wx/tokenzr.h"
@@ -63,6 +65,40 @@ wxString wxNativeEncodingInfo::ToString() const
return s;
}
// ----------------------------------------------------------------------------
// Private Fonts
// ----------------------------------------------------------------------------
#if wxUSE_PRIVATE_FONTS
// On OSX one can provide private fonts simply by putting the font files in
// with the resources in your application bundle. So the API for adding fonts
// does not do anything except checking that the file you pass to it actually
// does exist and is in the correct directory.
bool wxFontBase::AddPrivateFont(const wxString& filename)
{
wxFileName fn(filename);
if ( !fn.FileExists() )
{
wxLogError(_("Font file \"%s\" doesn't exist."), filename);
return false;
}
wxString fontsDir;
fontsDir << wxStandardPaths::Get().GetResourcesDir() << "/Fonts";
if ( fn.GetPath() != fontsDir )
{
wxLogError(_("Font file \"%s\" cannot be used as it is not inside "
"the font directory \"%s\"."), filename, fontsDir);
return false;
}
return true;
}
#endif // wxUSE_PRIVATE_FONTS
// ----------------------------------------------------------------------------
// helper functions
// ----------------------------------------------------------------------------