Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-13 Thread Steven D'Aprano
On Fri, 12 Jul 2013 23:38:18 -0700, Metallicow wrote:

> On Saturday, July 13, 2013 12:36:45 AM UTC-5, Tim Roberts wrote:
>> Really?  Because Windows is the ONLY one of the major operating systems
>> 
>> that actually has a dedicated system fonts directory.  Linux doesn't
>> even
>> 
>> have a dedicated windowing system.
> 
> So... Is it expected to install duplicates to multiple locations with
> Mac and Linux...?

No. Mac does have dedicated font locations. There are five official 
locations, with distinct meanings:

http://support.apple.com/kb/ht2435


(I do not know if OS-X ever localises directory names according to the 
user's language.) There is no need to install fonts in multiple locations.


Linux does not expect to have fonts installed *at all*. A graphical 
interface is entirely optional for Linux, so Linux may have no fonts.

There are two standard font systems available on Linux. The 15+ year old 
X Font Server ("xfs") technology is still in use, but many Linux distros 
are moving towards the newer Fontconfig system. Fontconfig allows you to 
define as many font directories as you want, although there are a few de-
facto standard locations.

For more information, see for example:

http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-x-fonts.html



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-12 Thread Metallicow
On Saturday, July 13, 2013 12:36:45 AM UTC-5, Tim Roberts wrote:
> Really?  Because Windows is the ONLY one of the major operating systems
> 
> that actually has a dedicated system fonts directory.  Linux doesn't even
> 
> have a dedicated windowing system.

So... Is it expected to install duplicates to multiple locations with Mac and 
Linux...?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-12 Thread Tim Roberts
Metallicow  wrote:
>
>If the OS doesn't *have* a dedicated system fonts dir that is accessable 
>by the user, then I am not that much interested in dealing with it. 

Really?  Because Windows is the ONLY one of the major operating systems
that actually has a dedicated system fonts directory.  Linux doesn't even
have a dedicated windowing system.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Steven D'Aprano
On Thu, 11 Jul 2013 21:24:00 -0700, Metallicow wrote:

> Forgot to add >>> part. Is there any way to edit posts? 

Not unless thousands of people give you access to their computer so you 
can edit the emails in their inboxes.

When you send a post to a public mailing list, its out their on fifty 
thousand computers and a dozen public archives. No, you can't change your 
mind and edit what you've already said.


> Don't see an edit linky anywhere. Is there something
> wrong with using os.environ...? win32api stuff is another dependency. Is
> it really needed?

If you want to do it the right way, yes.

In principle, any Windows machine could set the font directory to any 
valid directory. The only way to be sure you have got the right one is to 
ask Windows for the font directory, and that requires win32api.

If you intend for this to be usable everywhere, my approach would be this:

1) You need a separate function for each platform you intend to support. 
At the very least, you should support Windows (2000, XP, Vista, 7 and 8), 
OS-X (Mac), Linux. You should also strongly consider supporting Android, 
FreeBSD, OpenBSD, and Solaris. If you intend running under older versions 
of Python, you should also consider supporting Windows CE. You might even 
like to support iOS.

2) Some of these (Windows, probably Mac and iOS) will require a call to 
the OS to find the current directory. That means a win32api or equivalent 
call.

3) If win32api is not available, you might like to fall back on a 
heuristic to guess the right directory. But remember that is only a 
little bit better than hard-coding a directory.

4) For Linux and Free- and OpenBSD, there is no standard font directory. 
You may be able to make a call to the GUI toolkit to ask what it thinks 
the font directory (or directories!) is, but there are many different 
toolkits, and they can all be active at the same time. E.g. I might run a 
Gnome app and a KDE app both under XFCE, plus OpenOffice, and all three 
might disagree as to what fonts I have available.

The standard way to locate fonts in Linux is to look at two files, 
/etc/fonts/fonts.conf and /etc/fonts/local.conf, which list the locations 
you should check. Either, or both, files may be missing. Standard 
locations include: 

/usr/share/fonts
/usr/local/share/fonts
/home//.fonts
/usr/X11R6/lib/X11/fonts
/usr/share/X11/fonts/Type1
/usr/share/X11/fonts/OTF

And of course, applications like OpenOffice might keep their own, 
private, font directory, just because.

5) Now that you have a function for each OS you support, you can create a 
master function that detects the OS and calls the appropriate one. Now at 
last you have a simple function get_font_directory() that works 
everywhere.

Now that you see how complex it is to write this "simple" function, are 
you surprised that one doesn't yet exist?


:-)



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris Angelico
On Fri, Jul 12, 2013 at 2:24 PM, Metallicow  wrote:
> On Thursday, July 11, 2013 8:27:04 PM UTC-5, Christian Heimes wrote:
>> Am 11.07.2013 19:19, schrieb Metallicow:
>>
>> > @ Chris �Kwpolska� Warrick
>>
>> > Thanks, that is a start anyway.
>>
>> > a Pure-Python way was what I was wanting, not win32api stuff.
>>
>> >
>>
>> > "C:\Windows\Fonts"
>>
>> > The windows path proves valid. Works on XP, Vista, 7. Not sure about 
>> > win8?
>>
>>
>>
>> That's the wrong way to do it. You have to use the proper Windows API to
>>
>> get to the font directory. It's SHGetKnownFolderPath() with
>>
>> FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.
>>
>>
>>
>> See http://bugs.python.org/issue1763
>>
>>
>>
>> Christian
>
> typo'd instead of copy/pasted. What I meant was... Chris's code...
>
 FONTDIRS = os.path.join(os.environ['WINDIR'], 'Fonts')
> 'C:\\WINDOWS\\Fonts'
>
> returned valid as returned string. Forgot to add >>> part.
> Is there any way to edit posts? Don't see an edit linky anywhere.
> Is there something wrong with using os.environ...?
> win32api stuff is another dependency. Is it really needed?

No, you fundamentally cannot edit posts. This is a Usenet newsgroup
and a mailing list; once your post is sent, it gets carried by lots of
different servers separately. Just send a followup, same as you did
there.

Since you seem to be using Google Groups, please read this to learn
how to avoid antagonizing a significant proportion of the list's best
responders:

http://wiki.python.org/moin/GoogleGroupsPython

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
On Thursday, July 11, 2013 8:27:04 PM UTC-5, Christian Heimes wrote:
> Am 11.07.2013 19:19, schrieb Metallicow:
> 
> > @ Chris �Kwpolska� Warrick
> 
> > Thanks, that is a start anyway. 
> 
> > a Pure-Python way was what I was wanting, not win32api stuff.
> 
> > 
> 
> > "C:\Windows\Fonts"
> 
> > The windows path proves valid. Works on XP, Vista, 7. Not sure about 
> > win8?
> 
> 
> 
> That's the wrong way to do it. You have to use the proper Windows API to
> 
> get to the font directory. It's SHGetKnownFolderPath() with
> 
> FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.
> 
> 
> 
> See http://bugs.python.org/issue1763
> 
> 
> 
> Christian

typo'd instead of copy/pasted. What I meant was... Chris's code...

>>> FONTDIRS = os.path.join(os.environ['WINDIR'], 'Fonts') 
'C:\\WINDOWS\\Fonts'

returned valid as returned string. Forgot to add >>> part.
Is there any way to edit posts? Don't see an edit linky anywhere.
Is there something wrong with using os.environ...?
win32api stuff is another dependency. Is it really needed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Christian Heimes
Am 11.07.2013 19:19, schrieb Metallicow:
> @ Chris “Kwpolska” Warrick
> Thanks, that is a start anyway. 
> a Pure-Python way was what I was wanting, not win32api stuff.
> 
> "C:\Windows\Fonts"
> The windows path proves valid. Works on XP, Vista, 7. Not sure about win8?

That's the wrong way to do it. You have to use the proper Windows API to
get to the font directory. It's SHGetKnownFolderPath() with
FOLDERID_Font or SHGetFolderPath() with CSIDL_FONTS.

See http://bugs.python.org/issue1763

Christian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
On Thursday, July 11, 2013 12:47:01 PM UTC-5, Nobody wrote:
> 
> What makes you think the system *has* a system font directory?

Way back when I was kid, I remember a computer that had two colors and 1 
built-in font and no mouse. Heck the keyboard was even attached in front a tube 
screen box. 
Wow... those were the days. And to think I hated that thing...

If the OS doesn't *have* a dedicated system fonts dir that is accessable by the 
user, then I am not that much interested in dealing with it. Rendering a font 
from a other location will eventually be worked in, but that isn't the problem 
at hand.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Nobody
On Thu, 11 Jul 2013 08:32:34 -0700, Metallicow wrote:

> How do I get the OS System Font Directory(Cross-Platform) in python?

What makes you think the system *has* a system font directory?

In the traditional X11 model, the only program which needs fonts is the X
server, and that can be configured to get its fonts from a font server
rather than from a local directory. Even if it doesn't use a font server,
the font directory will be on the system running the X server, not the one
running the client.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
@ Chris “Kwpolska” Warrick
Thanks, that is a start anyway. 
a Pure-Python way was what I was wanting, not win32api stuff.

"C:\Windows\Fonts"
The windows path proves valid. Works on XP, Vista, 7. Not sure about win8...?

Don't have a mac handy, but the link should be enough to help write some code 
before testing. I don't own a mac, but IIRC macs come with python installed, so 
a trip to the apple shop might be in order.

As far as linux goes, basically Ubuntu/Kubuntu(dirivs), Mandriva/Mageia, Mint, 
and some of the more popular distros is all I am really looking for. Checking 
for these is VirtualBox shouldn't be too hard with your instructions and 
platform.linux_distribution()

Thanks again.
Here is the 'Open Font License 1.1 (OFL 1.1)' Fonts I will be using.
http://sourceforge.net/projects/sourcecodepro.adobe/
http://sourceforge.net/projects/sourcesans.adobe/

Also found these links that might help with pathing.
http://www.fontation.com/feature/
http://www.yearbooks.biz/?event=FAQ.Detail&faq=3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris “Kwpolska” Warrick
On Thu, Jul 11, 2013 at 08:54:17AM -0700, Metallicow wrote:
> For a portable font install tool.
> 
> Finding if a particular font exists,
> useful when testing apps in virtual environent,
> rendering text from a font,
> Font file manipulations,
> etc..
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Then do a nice little `if` checking the user’s OS.

http://docs.python.org/2/library/sys.html#sys.platform hints what to use,
and you need to do:

if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
FONTDIRS = [os.path.join(os.environ['WINDIR'], 'Fonts')
elif sys.platform.startswith('darwin'):
# [see below and devise it yourself]
else: # linux, *bsd and everything else
# [see below, commit suicide and develop this bit]

Windows:
The easiest of those three, all the fonts are in %WINDIR%/Fonts.
In Python: os.path.join(os.environ['WINDIR'], 'Fonts')

Mac OS X:
http://support.apple.com/kb/ht2435 (and not all of them are
guaranteed to exist).  `os.expanduser()` may be useful for
that first one.

Linux, and everything else running that fancy open stuff (eg. *BSD):
Hardcore.  You just need to parse a nice tiny 155-line XML file.

It’s /etc/fonts/fonts.conf, and it has some  tags.
Some of them may have a `prefix="xdg"` attribute which makes you
prepend the value with $XDG_DATA_HOME (~/.local/share if that is
empty).  You also need `os.expanduser()`.

Oh: and you need to go recursively through them, as subdirectories
are also checked for fonts (and it probably goes further)

-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html


pgpyE7rGDxSU2.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
For a portable font install tool.

Finding if a particular font exists,
useful when testing apps in virtual environent,
rendering text from a font,
Font file manipulations,
etc..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Chris “Kwpolska” Warrick
On Thu, Jul 11, 2013 at 5:32 PM, Metallicow  wrote:
> How do I get the OS System Font Directory(Cross-Platform) in python?
>
> Need a simple script for
> Windows, Linux, Mac, etc..
>
> Or using wxPython.
>
> I can't seem to find anything that works, and I don't want to hard-code paths.
> --
> http://mail.python.org/mailman/listinfo/python-list

Why do you want the paths to the fonts?  You do not need them 99.9% of
the time.  So, what *exactly* are you trying to accomplish?
--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I get the OS System Font Directory(Cross-Platform) in python?

2013-07-11 Thread Metallicow
How do I get the OS System Font Directory(Cross-Platform) in python?

Need a simple script for
Windows, Linux, Mac, etc..

Or using wxPython.

I can't seem to find anything that works, and I don't want to hard-code paths.
-- 
http://mail.python.org/mailman/listinfo/python-list