Skip to content

Commit

Permalink
Move reading fonts.conf files to special version on Posix. Update REA…
Browse files Browse the repository at this point in the history
…DME.md. Add License
  • Loading branch information
FreeSlave committed Apr 7, 2015
1 parent 7cbc009 commit f0ac0da
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 58 deletions.
23 changes: 23 additions & 0 deletions LICENSE_1_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ D library for getting standard paths (e.g. Pictures, Music, Documents). Inspired

The library is in early development. API may change in future. Join discussions in Issues if you're interested.

## Compiler and platform support

The library requires at least DMD v2.066 (or other compatible compiler) to compile.
Currently works on Windows, Linux and FreeBSD.

## Examples
Expand Down
16 changes: 16 additions & 0 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,20 @@
"targetType" : "library",

"subPackages" : ["./examples/printdirs", "./examples/findexecutable"],

"configurations" : [
{
"name" : "default"
},
{
"name" : "linkedshell32",
"versions-windows":["LinkedShell32"],
"platforms" : ["windows"]
},
{
"name" : "fontsconf",
"versions-posix" : ["fontsconf"],
"platforms" : ["posix"]
}
]
}
18 changes: 12 additions & 6 deletions examples/printdirs/dub.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "printdirs",
"description": "A minimal D application.",
"copyright": "Copyright © 2015, freeslave",
"authors": ["freeslave"],
"targetPath" : "bin",
"name": "printdirs",
"description": "A minimal D application.",
"copyright": "Copyright © 2015, freeslave",
"authors": ["freeslave"],
"targetPath" : "bin",
"targetType" : "executable",
"targetName" : "printdirs",
"dependencies" : {"standardpaths":"*"},
Expand All @@ -14,7 +14,13 @@
},
{
"name" : "linkedshell32",
"versions-windows":["LinkedShell32"]
"versions-windows":["LinkedShell32"],
"platforms" : ["windows"]
},
{
"name" : "fontsconf",
"versions-posix" : ["fontsconf"],
"platforms" : ["posix"]
}
]
}
130 changes: 78 additions & 52 deletions source/standardpaths.d
Original file line number Diff line number Diff line change
Expand Up @@ -550,63 +550,94 @@ version(Windows) {
return ["/usr/local/share", "/usr/share"];
}

private string[] readFontsConfig(string configFile) nothrow @trusted
{
//Should be changed in future since std.xml is deprecated
import std.xml;

string[] paths;
try {
string contents = cast(string)read(configFile);
check(contents);
auto parser = new DocumentParser(contents);
parser.onEndTag["dir"] = (in Element xml)
{
string path = xml.text;

if (path.length && path[0] == '~') {
path = maybeConcat(homeDir(), path[1..$]);
} else {
const(string)* prefix = "prefix" in xml.tag.attr;
if (prefix && *prefix == "xdg") {
string dataPath = writablePath(StandardPath.Data);
if (dataPath.length) {
path = buildPath(dataPath, path);

version(fontsconf) {
private string[] readFontsConfig(string configFile) nothrow @trusted
{
//Should be changed in future since std.xml is deprecated
import std.xml;

string[] paths;
try {
string contents = cast(string)read(configFile);
check(contents);
auto parser = new DocumentParser(contents);
parser.onEndTag["dir"] = (in Element xml)
{
string path = xml.text;

if (path.length && path[0] == '~') {
path = maybeConcat(homeDir(), path[1..$]);
} else {
const(string)* prefix = "prefix" in xml.tag.attr;
if (prefix && *prefix == "xdg") {
string dataPath = writablePath(StandardPath.Data);
if (dataPath.length) {
path = buildPath(dataPath, path);
}
}
}
}
if (path.length) {
paths ~= path;
}
};
parser.parse();
if (path.length) {
paths ~= path;
}
};
parser.parse();
}
catch(Exception e) {

}
return paths;
}
catch(Exception e) {

private string[] fontPaths() nothrow @trusted
{
string[] paths;

string homeConfig = homeFontsConfig();
if (homeConfig.length) {
paths ~= readFontsConfig(homeConfig);
}

enum configs = ["/etc/fonts/fonts.conf", //path on linux
"/usr/local/etc/fonts/fonts.conf"]; //path on freebsd
foreach(config; configs) {
paths ~= readFontsConfig(config);
}
return paths;
}
return paths;
}

private string[] fontPaths() nothrow @trusted
{
string[] paths;

string homeConfig = homeFontsConfig();
if (homeConfig.length) {
paths ~= readFontsConfig(homeConfig);
private string homeFontsConfig() nothrow @trusted {
return maybeConcat(writablePath(StandardPath.Config), "/fontconfig/fonts.conf");
}

enum configs = ["/etc/fonts/fonts.conf", //path on linux
"/usr/local/etc/fonts/fonts.conf"]; //path on freebsd
foreach(config; configs) {
paths ~= readFontsConfig(config);
private string homeFontsPath() nothrow @trusted {
string[] paths = readFontsConfig(homeFontsConfig());
if (paths.length)
return paths[0];
return null;
}
return paths;

} else {
private string homeFontsPath() nothrow @trusted {
return maybeConcat(homeDir(), "/.fonts");
}

private string[] fontPaths() nothrow @trusted
{
enum localShare = "/usr/local/share/fonts";
enum share = "/usr/share/fonts";

string homeFonts = homeFontsPath();
if (homeFonts.length) {
return [homeFonts, localShare, share];
} else {
return [localShare, share];
}
}

}

private string homeFontsConfig() nothrow @trusted {
return maybeConcat(writablePath(StandardPath.Config), "/fontconfig/fonts.conf");
}


/**
* Returns user's runtime directory determined by $(B XDG_RUNTIME_DIR) environment variable.
Expand Down Expand Up @@ -695,12 +726,7 @@ version(Windows) {
case StandardPath.PublicShare:
return xdgUserDir("PUBLICSHARE", "/Public");
case StandardPath.Fonts:
{
string[] paths = readFontsConfig(homeFontsConfig());
if (paths.length)
return paths[0];
return null;
}
return homeFontsPath();
case StandardPath.Applications:
return maybeConcat(writablePath(StandardPath.Data), "/applications");
}
Expand Down

0 comments on commit f0ac0da

Please sign in to comment.