I'm working on an application primary targeted for Linux, which use a TTF font. I need the font's file name and path, because I have to load it with SDL function TTF_OpenFont(char *file, ...). The problem is that there are a lot of different directories for TTF fonts on different distribution. Which is the best way to deal with this problem? I've came up some solutution, but each of them seems suboptimal for me:
pack the font along with the application, and install it to the application's own /usr/share/ directory.
check the font path with fc-list : file.
hardcode every path variation to the application and try them out when load the file.
Your first and second solutions are quite good, except it may be better to call FcFontList function. Third one is quite unreliable, but it highly depends on application type (it can be ok in some cases, if you have this path configurable by user).
Related
I have written a set of customized tkinter widgets, defined as classes, and loaded into the main app as modules. I am working in Windows 10, but have specific concerns in three areas in regard to compatibility with Linux and Mac. These are shown below.
Fonts
I am sticking with tkinter default fonts, and defining the desired font within each individual custom widget. I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example.
font=('TkDefaultFont',11)
font=('TkDefaultFont',10,'bold')
font=('TkDefaultFont',10,'italic')
Would this approach work across Linux and Mac as well as windows?
Importing modules
All of the resources for my main app are stored in a Folder named 'AppAssets' (which is in the same folder as the main app). The custom widgets are stored inside that folder, in another folder named 'TkMods'. In Windows, I am successfully importing these modules as follows, specifying a relative path:
from AppAssets.TkMods import ModButton
Again, would this work across Linux and Mac? If not, is there a line or lines of code that would work instead across all three platforms?
Importing image files
Many of the modules use custom image files (such as a rounded button image, for example). I am importing these as follows, again specifying a relative path.
btnimg = tk.PhotoImage(file="AppAssets/TkMods/Button.png")
Again, would this work cross-platform? If not, is there a single solution that would work across Windows, Mac and Linux?
Any advice appreciated.
I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example...
Would this approach work across Linux and Mac as well as windows?
It works, but probably not the way you think. You could use 'NotARealFont' instead of 'TkDefaultFont' and get the same results. The first parameter when defining a font as a tuple is a font family, and TkDefaultFont is not the name of a valid font family. It's the name of an internal font object, which is not the same thing. When you don't give a valid font family, tkinter will fall back to using the font defined by TkDefaultFont.
I am successfully importing these modules as follows... Again, would this work across Linux and Mac?
Yes, importing python modules works the same on platforms. This isn't anything unique to tkinter.
Many of the modules use custom image files ... I am importing these as follows, again specifying a relative path... Again, would this work cross-platform?
It should work the same on all platforms. Note that "work the same" also means it will fail in the same way on all platforms. The path is relative to the current working directory which may or may not be the same as the directory with the script.
I'm new to web development and currently learning Pixi.js and I noticed there are few versions:
Pixi.js
Pixi.js.map
Pixi.min.js
Pixi.min.js.map
May I know is there any differences between these in terms of features?
they're not at all different version, it's just a common convention in javascript programming: "min.js" files are the "minified" lib source, that's mean the same ".js" file where spaces, end of line and other unnecessary (for the browser) characters are cut off, and also variables names were changed with shorter ones, to obtain a lighter source file, less heavy to download and easier to execute for the browser. This file is obviously automatically generated from tools like gulp and grunt and is the source file you have to upload to the server and finally serve to the user. ".map" files instead are, whell, maps who link minified files to their full size counterpart, whit just min and map files, chrome debugger can reconstruct the original source and show it to you in the inspector.
To answer your question: No they are exactly the same, when it comes to features.
A *.min.js file is just the original.js file but "minified".
That means names were shortened (e.g function getName changed to n).
It's size (bytes) is also reduced.
While using linux system I encounter that that many file extensions are in capital as well as small letters like
myfile.JPG and myfile.jpg
I know Linux file system is case sensitive, but what's the difference in these two files? and why sometimes they get saved saved as capital or sometimes in small.
I have seen the same for other file too like
.ttf vs .TTF
Thanks
There is no difference if you name the file myfile.jpg or myfile.JPG or myfile.jpeg. Linux doesn't care.
The extension might be used by some programs running on linux and by humans to easily identify the filetype but it doen't affects the file in any way. You can even call it myfile.dog or just leave it without extension and would be the same image file and for linux it wouldn't make any difference.
If you have an image file and you want to tell what kind of image file it is you can use the file command or if you have imagemagick installed you can use the identify command.
Try renaming some jpeg file and give it a png extension, the run file image.png, you will see that it still is a jpeg file and that the png extension is there only to confuse you.
You might find this usefull: https://www.quora.com/How-do-Linux-identify-file-types-without-extensions-And-why-cant-Windows-do-so
Basically I am trying to get list of programs in Linux which are installed and can open particular file extension .jpg for example. If not all, At-least default program should get listed.
Linux (the kernel) has no knowledge on file types to application mapping. If you want to use Gnome programs you can look at https://people.gnome.org/~shaunm/admin-guide/mimetypes-7.html. For KDE there is another mechanism. Each toolkit can define it as it likes. And the programmer can use the defaults or not. So it is simply application specific!
What do you want to achieve?
If you (double) click with a explorer/browser application on an icon or file name, exactly the explorer/browser looks for the file type. Typically this is realized via mime type dictionary. But how a program looks for the file type and maybe execute another program is only related to the programmer who writes that program. The GUI tool-chains like Gnome and KDE have a lot of support for that topic and so you have basic conformity for each family of applications.
If you want to know how a application do the job, start it with strace. But it is quite hard to dig into the huge amount of data.
Also you can take a look for xdg-open. Many programs use this helper to start applications. As an example: If you start Dolphin with strace you will find a line like lstat64("/etc/xdg", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 after clicking on a file.
you can run from command line with:
xdg-open <file-name>
You maybe also want to have a look for applications which registers for file types: /usr/share/applications/*.desktop
Here you can find in each desktop file some mime-types which are registered for the applications. E.g. for audiacity is:
MimeType=application/x-audacity-project;audio/flac;audio/x-flac;audio/basic;audio/x-aiff;audio/x-wav;application/ogg;audio/x-vorbis+ogg;
For your example with jpg:
$ xdg-mime query filetype <any-jpg-file>
image/jpeg
$ grep 'image/jpeg' -R /usr/share/applications/*
...
/usr/share/applications/mimeinfo.cache:image/jpeg2000=kde4-kolourpaint.desktop;gimp.desktop;
So you can see that gimp is one of the default applications for jpg
The place to start looking is at the mailcap (/etc/mailcap) and MIME-types, e.g., in /etc/mime.types in Debian (the filename and path will vary according to who provides it).
The mailcap file gives some rules for opening a file, while MIME-types lists the known filetypes with a tag that allows multiple applications to know about the file types.
Except for embedded or reduced-functionality systems (such as those based on busybox), you would find these files on almost every UNIX-like system.
In the interest of making my emacs setup more portable, I'd like to be able to set the current font by specifying a file rather than a font name, i.e. "Load ~/config/myfont.ttf and use size 12". Is there a way to do that in my .emacs? All the instructions I've found assume the font is already installed on the system. I'm using the XFT support on Linux, so a linux specific hack would be OK but I'd prefer something that would work on all targets.
Update: To be clear, I'm using a font that isn't standard on Windows / OS X / Linux. I'm not just looking to set a different font based on platform, but to specify a specific font file that I have (TTFs work on Windows and Linux, if not on Mac I'll get another version of the file but I still want to specify the font via file rather than name).
Unfortunately, you can't.
Emacs on different platforms uses different windowing toolkits, all of which take care of font handling for it. I don't believe you can specify a font filename in Emacs on any platform - it just doesn't work that way.
As for how to find the font:
On Linux, you could use XFT's support for a user-specific font config file which is usually ~/.fonts.conf (but check /etc/fonts/font.conf to be sure) to add whatever directory you place your fonts into.
On a Mac, you can add the font into ~/Library/Fonts. TTFs work fine on Macs, BTW.
On Windows, I think you'd just have to add it to the system fonts directory.
From there, you then go and tell Emacs (through customize or not) to use your font. You'll find the naming schemes to be different on each platform (not sure what Windows looks like), but customize should help take care of this for you - just keep a separate customize file per machine if need be.
...so basically your portable Emacs setup has to encompass more than just an Emacs config file (which, given that you're carrying a font file around, it already does).