From dc0ba1f4147333efb4306dc9552db298df83a997 Mon Sep 17 00:00:00 2001 From: Metallicow Date: Mon, 1 Jul 2019 16:46:30 -0500 Subject: [PATCH] AddPrivateFont updated requested changes --- CHANGES.rst | 2 + demo/AddPrivateFont.py | 115 ++++++++++++++++++++++++++++ demo/FontEnumerator.py | 11 --- demo/data/SIL_OPEN_FONT_LICENSE.txt | 4 + demo/demodata.py | 2 + 5 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 demo/AddPrivateFont.py diff --git a/CHANGES.rst b/CHANGES.rst index 961e11f2..be149ed5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,6 +22,8 @@ which is included in the wxPython source archives. New and improved in this release: +* Add wx.Font.AddPrivateFont example to the demo. + * Added wrappers for the OSXEnableAutomaticQuoteSubstitution, OSXEnableAutomaticDashSubstitution, and OSXDisableAllSmartSubstitutions methods in wx.TextCtrl. diff --git a/demo/AddPrivateFont.py b/demo/AddPrivateFont.py new file mode 100644 index 00000000..4efa001b --- /dev/null +++ b/demo/AddPrivateFont.py @@ -0,0 +1,115 @@ +#!/usr/bin/env python + +import os +import sys + +try: + gFileDir = os.path.dirname(os.path.abspath(__file__)) +except: + gFileDir = os.path.dirname(os.path.abspath(sys.argv[0])) +gDataDir = gFileDir + os.sep + 'data' + +import wx + + +FILENAME = 'SourceCodePro-Regular.ttf' + +SAMPLETEXT = """ +SourceCodePro-Regular.ttf + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. + +abcdefghijklmnopqrstyvwxyz +ABCDEFGHIJKLMNOPQRSTYVWXYZ +1234567890.:,:\'"([{<\\|/>}]) +`~!@#$%^&*_+-=? + +Pangrams +The Quick Brown Fox Jumps Over The Lazy Dog. +Grumpy wizards make toxic brew for the evil queen and jack! +""" + +#---------------------------------------------------------------------- + +class TestPanel(wx.Panel): + def __init__(self, parent, log): + wx.Panel.__init__(self, parent, -1) + + # Show how to add a private font to the application at runtime that + # doesn't have to be installed on the user's operating system. + wx.Font.AddPrivateFont(gDataDir + os.sep + 'SourceCodePro-Regular.ttf') + + text1 = "The font used in the text below was dynamically loaded from {filename}." + st1 = wx.StaticText(self, -1, text1, (15, 15)) + + st2 = wx.StaticText(self, -1, SAMPLETEXT, (15, 42)) + f = wx.Font(pointSize=12, + family=wx.FONTFAMILY_DEFAULT, + style=wx.FONTSTYLE_NORMAL, + weight=wx.FONTWEIGHT_NORMAL, + underline=False, + faceName="Source Code Pro", + encoding=wx.FONTENCODING_DEFAULT) + st2.SetFont(f) + + + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(st1, 0, wx.ALL, 10) + sizer.Add(wx.StaticLine(self, style=wx.HORIZONTAL), 0, wx.EXPAND | wx.ALL, 10) + sizer.Add(st2, 0, wx.ALL, 10) + self.SetSizer(sizer) + self.Layout() + + +#---------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + +#---------------------------------------------------------------------- + + + +overview = """ +https://wxpython.org/Phoenix/docs/html/wx.Font.html#wx.Font.AddPrivateFont + +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 ATSApplicationFontsPath to Fonts value +in your Info.plist file. See also wx.StandardPaths.GetResourcesDir . + +Under MSW this method must be called before any wx.GraphicsContext 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 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 +USE_PRIVATE_FONTS is always set to 0 under the other platforms, making +this function unavailable at compile-time. + +Parameters: filename (string) - +Return type: bool +Returns: True if the font was added and can now be used. + +New in version wxWidgets 3.1.1. + + +""" + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) + diff --git a/demo/FontEnumerator.py b/demo/FontEnumerator.py index 2b58d4cc..05c3ce14 100644 --- a/demo/FontEnumerator.py +++ b/demo/FontEnumerator.py @@ -1,13 +1,6 @@ #!/usr/bin/env python # Tags: phoenix-port, py3-port -import os -import sys -try: - gFileDir = os.path.dirname(os.path.abspath(__file__)) -except: - gFileDir = os.path.dirname(os.path.abspath(sys.argv[0])) -gDataDir = gFileDir + os.sep + 'data' import wx @@ -17,10 +10,6 @@ class TestPanel(wx.Panel): def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1) - # Show how to add a private font to the application at runtime that - # doesn't have to be installed on the user's operating system. - wx.Font.AddPrivateFont(gDataDir + os.sep + 'SourceCodePro-Regular.ttf') - # The FontEnumerator handles fonts installed on the user's operating system. e = wx.FontEnumerator() e.EnumerateFacenames() diff --git a/demo/data/SIL_OPEN_FONT_LICENSE.txt b/demo/data/SIL_OPEN_FONT_LICENSE.txt index 11773304..8afe68dc 100644 --- a/demo/data/SIL_OPEN_FONT_LICENSE.txt +++ b/demo/data/SIL_OPEN_FONT_LICENSE.txt @@ -1,3 +1,7 @@ +This license applies to the "SourceCodePro-Regular.ttf" file. +Font Source: https://github.com/adobe-fonts/source-code-pro +------------------------------------------------------------- + Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. This Font Software is licensed under the SIL Open Font License, Version 1.1. diff --git a/demo/demodata.py b/demo/demodata.py index b164cf1b..652245cf 100644 --- a/demo/demodata.py +++ b/demo/demodata.py @@ -43,6 +43,7 @@ _treeList = [ 'DynamicSashWindow', 'TreeListCtrl', 'NotificationMessage', + 'AddPrivateFont', ]), # managed windows == things with a (optional) caption you can close @@ -268,6 +269,7 @@ _treeList = [ 'DrawXXXList', 'FileHistory', 'FontEnumerator', + 'AddPrivateFont', 'GetMouseState', 'GraphicsContext', 'GraphicsGradient',