istereo2

changeset 7:a3c4fcc9f8f3

- started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 06:49:25 +0300
parents 3bccfc7d10fe
children 661bf09db398
files .hgignore istereo.xcodeproj/project.pbxproj libs/drawtext/COPYING libs/drawtext/COPYING.LESSER libs/drawtext/README libs/drawtext/drawgl.c libs/drawtext/drawtext.h libs/drawtext/drawtext_impl.h libs/drawtext/font.c libs/drawtext/utf8.c libs/goatkit/theme.cc libs/goatkit/theme.h sdr/font.p.glsl sdr/ui.p.glsl sdr/ui.v.glsl src/android/assman.c src/assman.c src/assman.h src/config.h src/ios/assman.c src/istereo.c src/ui.cc src/uitheme.cc
diffstat 23 files changed, 2789 insertions(+), 37 deletions(-) [+]
line diff
     1.1 --- a/.hgignore	Wed Sep 23 05:44:58 2015 +0300
     1.2 +++ b/.hgignore	Thu Sep 24 06:49:25 2015 +0300
     1.3 @@ -8,3 +8,4 @@
     1.4  ^build/
     1.5  \.png$
     1.6  ^data/
     1.7 +\.DS_Store
     2.1 --- a/istereo.xcodeproj/project.pbxproj	Wed Sep 23 05:44:58 2015 +0300
     2.2 +++ b/istereo.xcodeproj/project.pbxproj	Thu Sep 24 06:49:25 2015 +0300
     2.3 @@ -22,6 +22,14 @@
     2.4  		060ECAF31BB2441600CE9B80 /* color.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF21BB2441600CE9B80 /* color.p.glsl */; settings = {ASSET_TAGS = (); }; };
     2.5  		060ECAF61BB2496100CE9B80 /* ui.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF41BB2496100CE9B80 /* ui.p.glsl */; settings = {ASSET_TAGS = (); }; };
     2.6  		060ECAF71BB2496100CE9B80 /* ui.v.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECAF51BB2496100CE9B80 /* ui.v.glsl */; settings = {ASSET_TAGS = (); }; };
     2.7 +		060ECAFE1BB2BD5C00CE9B80 /* drawgl.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAF91BB2BD5C00CE9B80 /* drawgl.c */; settings = {ASSET_TAGS = (); }; };
     2.8 +		060ECAFF1BB2BD5C00CE9B80 /* font.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAFC1BB2BD5C00CE9B80 /* font.c */; settings = {ASSET_TAGS = (); }; };
     2.9 +		060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECAFD1BB2BD5C00CE9B80 /* utf8.c */; settings = {ASSET_TAGS = (); }; };
    2.10 +		060ECB031BB361C300CE9B80 /* assman.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB011BB361C300CE9B80 /* assman.c */; settings = {ASSET_TAGS = (); }; };
    2.11 +		060ECB051BB361D900CE9B80 /* assman.c in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB041BB361D900CE9B80 /* assman.c */; settings = {ASSET_TAGS = (); }; };
    2.12 +		060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */; settings = {ASSET_TAGS = (); }; };
    2.13 +		060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */ = {isa = PBXBuildFile; fileRef = 060ECB081BB3989500CE9B80 /* uitheme.cc */; settings = {ASSET_TAGS = (); }; };
    2.14 +		060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */ = {isa = PBXBuildFile; fileRef = 060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */; settings = {ASSET_TAGS = (); }; };
    2.15  		0669D67F1BA85DDE00611CFA /* app_delegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67B1BA85DDE00611CFA /* app_delegate.m */; };
    2.16  		0669D6801BA85DDE00611CFA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67C1BA85DDE00611CFA /* main.m */; };
    2.17  		0669D6811BA85DDE00611CFA /* viewctl.m in Sources */ = {isa = PBXBuildFile; fileRef = 0669D67E1BA85DDE00611CFA /* viewctl.m */; };
    2.18 @@ -161,6 +169,17 @@
    2.19  		060ECAF21BB2441600CE9B80 /* color.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = color.p.glsl; path = sdr/color.p.glsl; sourceTree = "<group>"; };
    2.20  		060ECAF41BB2496100CE9B80 /* ui.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.p.glsl; path = sdr/ui.p.glsl; sourceTree = "<group>"; };
    2.21  		060ECAF51BB2496100CE9B80 /* ui.v.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = ui.v.glsl; path = sdr/ui.v.glsl; sourceTree = "<group>"; };
    2.22 +		060ECAF91BB2BD5C00CE9B80 /* drawgl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = drawgl.c; path = libs/drawtext/drawgl.c; sourceTree = "<group>"; };
    2.23 +		060ECAFA1BB2BD5C00CE9B80 /* drawtext_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = drawtext_impl.h; path = libs/drawtext/drawtext_impl.h; sourceTree = "<group>"; };
    2.24 +		060ECAFB1BB2BD5C00CE9B80 /* drawtext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = drawtext.h; path = libs/drawtext/drawtext.h; sourceTree = "<group>"; };
    2.25 +		060ECAFC1BB2BD5C00CE9B80 /* font.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = font.c; path = libs/drawtext/font.c; sourceTree = "<group>"; };
    2.26 +		060ECAFD1BB2BD5C00CE9B80 /* utf8.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = utf8.c; path = libs/drawtext/utf8.c; sourceTree = "<group>"; };
    2.27 +		060ECB011BB361C300CE9B80 /* assman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = assman.c; path = src/assman.c; sourceTree = "<group>"; };
    2.28 +		060ECB021BB361C300CE9B80 /* assman.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = assman.h; path = src/assman.h; sourceTree = "<group>"; };
    2.29 +		060ECB041BB361D900CE9B80 /* assman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = assman.c; path = src/ios/assman.c; sourceTree = "<group>"; };
    2.30 +		060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "linux-libertine_s24.glyphmap"; path = "data/linux-libertine_s24.glyphmap"; sourceTree = "<group>"; };
    2.31 +		060ECB081BB3989500CE9B80 /* uitheme.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = uitheme.cc; path = src/uitheme.cc; sourceTree = "<group>"; };
    2.32 +		060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = font.p.glsl; path = sdr/font.p.glsl; sourceTree = "<group>"; };
    2.33  		0669D6471BA851BE00611CFA /* istereo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = istereo.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.34  		0669D6741BA858BF00611CFA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ios/Info.plist; sourceTree = "<group>"; };
    2.35  		0669D67A1BA85DDE00611CFA /* app_delegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = app_delegate.h; path = src/ios/app_delegate.h; sourceTree = "<group>"; };
    2.36 @@ -364,6 +383,18 @@
    2.37  			name = goatkit;
    2.38  			sourceTree = "<group>";
    2.39  		};
    2.40 +		060ECAF81BB2BD4B00CE9B80 /* drawtext */ = {
    2.41 +			isa = PBXGroup;
    2.42 +			children = (
    2.43 +				060ECAF91BB2BD5C00CE9B80 /* drawgl.c */,
    2.44 +				060ECAFA1BB2BD5C00CE9B80 /* drawtext_impl.h */,
    2.45 +				060ECAFB1BB2BD5C00CE9B80 /* drawtext.h */,
    2.46 +				060ECAFC1BB2BD5C00CE9B80 /* font.c */,
    2.47 +				060ECAFD1BB2BD5C00CE9B80 /* utf8.c */,
    2.48 +			);
    2.49 +			name = drawtext;
    2.50 +			sourceTree = "<group>";
    2.51 +		};
    2.52  		0669D63E1BA851BE00611CFA = {
    2.53  			isa = PBXGroup;
    2.54  			children = (
    2.55 @@ -388,7 +419,10 @@
    2.56  		0669D6761BA858D600611CFA /* src */ = {
    2.57  			isa = PBXGroup;
    2.58  			children = (
    2.59 +				060ECB011BB361C300CE9B80 /* assman.c */,
    2.60 +				060ECB021BB361C300CE9B80 /* assman.h */,
    2.61  				060ECAED1BB22A4400CE9B80 /* ui.cc */,
    2.62 +				060ECB081BB3989500CE9B80 /* uitheme.cc */,
    2.63  				060ECAEE1BB22A4400CE9B80 /* ui.h */,
    2.64  				0669D6821BACDF6C00611CFA /* cam.c */,
    2.65  				0669D6831BACDF6C00611CFA /* cam.h */,
    2.66 @@ -412,6 +446,7 @@
    2.67  		0669D6791BA85DCC00611CFA /* ios */ = {
    2.68  			isa = PBXGroup;
    2.69  			children = (
    2.70 +				060ECB041BB361D900CE9B80 /* assman.c */,
    2.71  				0669D67A1BA85DDE00611CFA /* app_delegate.h */,
    2.72  				0669D67B1BA85DDE00611CFA /* app_delegate.m */,
    2.73  				0669D67C1BA85DDE00611CFA /* main.m */,
    2.74 @@ -424,6 +459,7 @@
    2.75  		0669D6971BAD01C200611CFA /* libs */ = {
    2.76  			isa = PBXGroup;
    2.77  			children = (
    2.78 +				060ECAF81BB2BD4B00CE9B80 /* drawtext */,
    2.79  				060ECAC81BB1A9BA00CE9B80 /* goatkit */,
    2.80  				0669D69C1BAD01EA00611CFA /* vmath */,
    2.81  				0669D69B1BAD01E300611CFA /* imago2 */,
    2.82 @@ -601,6 +637,7 @@
    2.83  		0669D77B1BAD028300611CFA /* sdr */ = {
    2.84  			isa = PBXGroup;
    2.85  			children = (
    2.86 +				060ECB0A1BB3A8DB00CE9B80 /* font.p.glsl */,
    2.87  				060ECAF41BB2496100CE9B80 /* ui.p.glsl */,
    2.88  				060ECAF51BB2496100CE9B80 /* ui.v.glsl */,
    2.89  				0669D77C1BAD02A200611CFA /* test.p.glsl */,
    2.90 @@ -618,6 +655,7 @@
    2.91  		0669D7881BAD02B000611CFA /* data */ = {
    2.92  			isa = PBXGroup;
    2.93  			children = (
    2.94 +				060ECB061BB36FD800CE9B80 /* linux-libertine_s24.glyphmap */,
    2.95  				0669D7891BAD02DC00611CFA /* stonewall_normal.jpg */,
    2.96  				0669D78A1BAD02DC00611CFA /* stonewall.jpg */,
    2.97  				0669D78B1BAD02DC00611CFA /* text.png */,
    2.98 @@ -697,8 +735,10 @@
    2.99  				0669D7901BAD02DC00611CFA /* tiles.jpg in Resources */,
   2.100  				0669D7871BAD02A200611CFA /* tunnel.v.glsl in Resources */,
   2.101  				0669D78F1BAD02DC00611CFA /* text.png in Resources */,
   2.102 +				060ECB0B1BB3A8DB00CE9B80 /* font.p.glsl in Resources */,
   2.103  				0669D7851BAD02A200611CFA /* text.v.glsl in Resources */,
   2.104  				0669D7831BAD02A200611CFA /* test.v.glsl in Resources */,
   2.105 +				060ECB071BB36FD800CE9B80 /* linux-libertine_s24.glyphmap in Resources */,
   2.106  			);
   2.107  			runOnlyForDeploymentPostprocessing = 0;
   2.108  		};
   2.109 @@ -709,6 +749,7 @@
   2.110  			isa = PBXSourcesBuildPhase;
   2.111  			buildActionMask = 2147483647;
   2.112  			files = (
   2.113 +				060ECB001BB2BD5C00CE9B80 /* utf8.c in Sources */,
   2.114  				0669D7121BAD024700611CFA /* jcparam.c in Sources */,
   2.115  				0669D7551BAD025B00611CFA /* pngwio.c in Sources */,
   2.116  				0669D70F1BAD024700611CFA /* jcmarker.c in Sources */,
   2.117 @@ -729,6 +770,7 @@
   2.118  				0669D6B81BAD020B00611CFA /* ray_c.c in Sources */,
   2.119  				0669D71D1BAD024700611CFA /* jddctmgr.c in Sources */,
   2.120  				0669D7571BAD025B00611CFA /* pngwtran.c in Sources */,
   2.121 +				060ECB051BB361D900CE9B80 /* assman.c in Sources */,
   2.122  				0669D7081BAD024700611CFA /* jcapistd.c in Sources */,
   2.123  				0669D72C1BAD024700611CFA /* jidctflt.c in Sources */,
   2.124  				060ECADB1BB1A9CC00CE9B80 /* textbox.cc in Sources */,
   2.125 @@ -739,6 +781,7 @@
   2.126  				0669D7281BAD024700611CFA /* jerror.c in Sources */,
   2.127  				0669D7221BAD024700611CFA /* jdmaster.c in Sources */,
   2.128  				0669D76F1BAD027000611CFA /* adler32.c in Sources */,
   2.129 +				060ECAFF1BB2BD5C00CE9B80 /* font.c in Sources */,
   2.130  				0669D7541BAD025B00611CFA /* pngvcrd.c in Sources */,
   2.131  				0669D72A1BAD024700611CFA /* jfdctfst.c in Sources */,
   2.132  				0669D7791BAD027000611CFA /* uncompr.c in Sources */,
   2.133 @@ -765,7 +808,9 @@
   2.134  				0669D71F1BAD024700611CFA /* jdinput.c in Sources */,
   2.135  				0669D7581BAD025B00611CFA /* pngwutil.c in Sources */,
   2.136  				0669D7261BAD024700611CFA /* jdsample.c in Sources */,
   2.137 +				060ECAFE1BB2BD5C00CE9B80 /* drawgl.c in Sources */,
   2.138  				0669D7701BAD027000611CFA /* compress.c in Sources */,
   2.139 +				060ECB031BB361C300CE9B80 /* assman.c in Sources */,
   2.140  				0669D7111BAD024700611CFA /* jcomapi.c in Sources */,
   2.141  				0669D71A1BAD024700611CFA /* jdatasrc.c in Sources */,
   2.142  				060ECADC1BB1A9CC00CE9B80 /* theme.cc in Sources */,
   2.143 @@ -803,6 +848,7 @@
   2.144  				0669D7751BAD027000611CFA /* inffast.c in Sources */,
   2.145  				0669D7491BAD025B00611CFA /* pngerror.c in Sources */,
   2.146  				0669D7171BAD024700611CFA /* jdapimin.c in Sources */,
   2.147 +				060ECB091BB3989500CE9B80 /* uitheme.cc in Sources */,
   2.148  				0669D7331BAD024700611CFA /* jquant2.c in Sources */,
   2.149  				0669D74D1BAD025B00611CFA /* pngpread.c in Sources */,
   2.150  				0669D7071BAD024700611CFA /* jcapimin.c in Sources */,
   2.151 @@ -915,6 +961,8 @@
   2.152  				GCC_PREPROCESSOR_DEFINITIONS = (
   2.153  					"DEBUG=1",
   2.154  					HAVE_OPENGL_H,
   2.155 +					HAVE_CONFIG_H,
   2.156 +					NO_FREETYPE,
   2.157  				);
   2.158  				HEADER_SEARCH_PATHS = libs;
   2.159  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
   2.160 @@ -931,7 +979,11 @@
   2.161  				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
   2.162  				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
   2.163  				CODE_SIGN_IDENTITY = "iPhone Developer";
   2.164 -				GCC_PREPROCESSOR_DEFINITIONS = HAVE_OPENGL_H;
   2.165 +				GCC_PREPROCESSOR_DEFINITIONS = (
   2.166 +					HAVE_OPENGL_H,
   2.167 +					HAVE_CONFIG_H,
   2.168 +					NO_FREETYPE,
   2.169 +				);
   2.170  				HEADER_SEARCH_PATHS = libs;
   2.171  				INFOPLIST_FILE = "$(SRCROOT)/ios/Info.plist";
   2.172  				IPHONEOS_DEPLOYMENT_TARGET = 6.0;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/libs/drawtext/COPYING	Thu Sep 24 06:49:25 2015 +0300
     3.3 @@ -0,0 +1,674 @@
     3.4 +                    GNU GENERAL PUBLIC LICENSE
     3.5 +                       Version 3, 29 June 2007
     3.6 +
     3.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     3.8 + Everyone is permitted to copy and distribute verbatim copies
     3.9 + of this license document, but changing it is not allowed.
    3.10 +
    3.11 +                            Preamble
    3.12 +
    3.13 +  The GNU General Public License is a free, copyleft license for
    3.14 +software and other kinds of works.
    3.15 +
    3.16 +  The licenses for most software and other practical works are designed
    3.17 +to take away your freedom to share and change the works.  By contrast,
    3.18 +the GNU General Public License is intended to guarantee your freedom to
    3.19 +share and change all versions of a program--to make sure it remains free
    3.20 +software for all its users.  We, the Free Software Foundation, use the
    3.21 +GNU General Public License for most of our software; it applies also to
    3.22 +any other work released this way by its authors.  You can apply it to
    3.23 +your programs, too.
    3.24 +
    3.25 +  When we speak of free software, we are referring to freedom, not
    3.26 +price.  Our General Public Licenses are designed to make sure that you
    3.27 +have the freedom to distribute copies of free software (and charge for
    3.28 +them if you wish), that you receive source code or can get it if you
    3.29 +want it, that you can change the software or use pieces of it in new
    3.30 +free programs, and that you know you can do these things.
    3.31 +
    3.32 +  To protect your rights, we need to prevent others from denying you
    3.33 +these rights or asking you to surrender the rights.  Therefore, you have
    3.34 +certain responsibilities if you distribute copies of the software, or if
    3.35 +you modify it: responsibilities to respect the freedom of others.
    3.36 +
    3.37 +  For example, if you distribute copies of such a program, whether
    3.38 +gratis or for a fee, you must pass on to the recipients the same
    3.39 +freedoms that you received.  You must make sure that they, too, receive
    3.40 +or can get the source code.  And you must show them these terms so they
    3.41 +know their rights.
    3.42 +
    3.43 +  Developers that use the GNU GPL protect your rights with two steps:
    3.44 +(1) assert copyright on the software, and (2) offer you this License
    3.45 +giving you legal permission to copy, distribute and/or modify it.
    3.46 +
    3.47 +  For the developers' and authors' protection, the GPL clearly explains
    3.48 +that there is no warranty for this free software.  For both users' and
    3.49 +authors' sake, the GPL requires that modified versions be marked as
    3.50 +changed, so that their problems will not be attributed erroneously to
    3.51 +authors of previous versions.
    3.52 +
    3.53 +  Some devices are designed to deny users access to install or run
    3.54 +modified versions of the software inside them, although the manufacturer
    3.55 +can do so.  This is fundamentally incompatible with the aim of
    3.56 +protecting users' freedom to change the software.  The systematic
    3.57 +pattern of such abuse occurs in the area of products for individuals to
    3.58 +use, which is precisely where it is most unacceptable.  Therefore, we
    3.59 +have designed this version of the GPL to prohibit the practice for those
    3.60 +products.  If such problems arise substantially in other domains, we
    3.61 +stand ready to extend this provision to those domains in future versions
    3.62 +of the GPL, as needed to protect the freedom of users.
    3.63 +
    3.64 +  Finally, every program is threatened constantly by software patents.
    3.65 +States should not allow patents to restrict development and use of
    3.66 +software on general-purpose computers, but in those that do, we wish to
    3.67 +avoid the special danger that patents applied to a free program could
    3.68 +make it effectively proprietary.  To prevent this, the GPL assures that
    3.69 +patents cannot be used to render the program non-free.
    3.70 +
    3.71 +  The precise terms and conditions for copying, distribution and
    3.72 +modification follow.
    3.73 +
    3.74 +                       TERMS AND CONDITIONS
    3.75 +
    3.76 +  0. Definitions.
    3.77 +
    3.78 +  "This License" refers to version 3 of the GNU General Public License.
    3.79 +
    3.80 +  "Copyright" also means copyright-like laws that apply to other kinds of
    3.81 +works, such as semiconductor masks.
    3.82 +
    3.83 +  "The Program" refers to any copyrightable work licensed under this
    3.84 +License.  Each licensee is addressed as "you".  "Licensees" and
    3.85 +"recipients" may be individuals or organizations.
    3.86 +
    3.87 +  To "modify" a work means to copy from or adapt all or part of the work
    3.88 +in a fashion requiring copyright permission, other than the making of an
    3.89 +exact copy.  The resulting work is called a "modified version" of the
    3.90 +earlier work or a work "based on" the earlier work.
    3.91 +
    3.92 +  A "covered work" means either the unmodified Program or a work based
    3.93 +on the Program.
    3.94 +
    3.95 +  To "propagate" a work means to do anything with it that, without
    3.96 +permission, would make you directly or secondarily liable for
    3.97 +infringement under applicable copyright law, except executing it on a
    3.98 +computer or modifying a private copy.  Propagation includes copying,
    3.99 +distribution (with or without modification), making available to the
   3.100 +public, and in some countries other activities as well.
   3.101 +
   3.102 +  To "convey" a work means any kind of propagation that enables other
   3.103 +parties to make or receive copies.  Mere interaction with a user through
   3.104 +a computer network, with no transfer of a copy, is not conveying.
   3.105 +
   3.106 +  An interactive user interface displays "Appropriate Legal Notices"
   3.107 +to the extent that it includes a convenient and prominently visible
   3.108 +feature that (1) displays an appropriate copyright notice, and (2)
   3.109 +tells the user that there is no warranty for the work (except to the
   3.110 +extent that warranties are provided), that licensees may convey the
   3.111 +work under this License, and how to view a copy of this License.  If
   3.112 +the interface presents a list of user commands or options, such as a
   3.113 +menu, a prominent item in the list meets this criterion.
   3.114 +
   3.115 +  1. Source Code.
   3.116 +
   3.117 +  The "source code" for a work means the preferred form of the work
   3.118 +for making modifications to it.  "Object code" means any non-source
   3.119 +form of a work.
   3.120 +
   3.121 +  A "Standard Interface" means an interface that either is an official
   3.122 +standard defined by a recognized standards body, or, in the case of
   3.123 +interfaces specified for a particular programming language, one that
   3.124 +is widely used among developers working in that language.
   3.125 +
   3.126 +  The "System Libraries" of an executable work include anything, other
   3.127 +than the work as a whole, that (a) is included in the normal form of
   3.128 +packaging a Major Component, but which is not part of that Major
   3.129 +Component, and (b) serves only to enable use of the work with that
   3.130 +Major Component, or to implement a Standard Interface for which an
   3.131 +implementation is available to the public in source code form.  A
   3.132 +"Major Component", in this context, means a major essential component
   3.133 +(kernel, window system, and so on) of the specific operating system
   3.134 +(if any) on which the executable work runs, or a compiler used to
   3.135 +produce the work, or an object code interpreter used to run it.
   3.136 +
   3.137 +  The "Corresponding Source" for a work in object code form means all
   3.138 +the source code needed to generate, install, and (for an executable
   3.139 +work) run the object code and to modify the work, including scripts to
   3.140 +control those activities.  However, it does not include the work's
   3.141 +System Libraries, or general-purpose tools or generally available free
   3.142 +programs which are used unmodified in performing those activities but
   3.143 +which are not part of the work.  For example, Corresponding Source
   3.144 +includes interface definition files associated with source files for
   3.145 +the work, and the source code for shared libraries and dynamically
   3.146 +linked subprograms that the work is specifically designed to require,
   3.147 +such as by intimate data communication or control flow between those
   3.148 +subprograms and other parts of the work.
   3.149 +
   3.150 +  The Corresponding Source need not include anything that users
   3.151 +can regenerate automatically from other parts of the Corresponding
   3.152 +Source.
   3.153 +
   3.154 +  The Corresponding Source for a work in source code form is that
   3.155 +same work.
   3.156 +
   3.157 +  2. Basic Permissions.
   3.158 +
   3.159 +  All rights granted under this License are granted for the term of
   3.160 +copyright on the Program, and are irrevocable provided the stated
   3.161 +conditions are met.  This License explicitly affirms your unlimited
   3.162 +permission to run the unmodified Program.  The output from running a
   3.163 +covered work is covered by this License only if the output, given its
   3.164 +content, constitutes a covered work.  This License acknowledges your
   3.165 +rights of fair use or other equivalent, as provided by copyright law.
   3.166 +
   3.167 +  You may make, run and propagate covered works that you do not
   3.168 +convey, without conditions so long as your license otherwise remains
   3.169 +in force.  You may convey covered works to others for the sole purpose
   3.170 +of having them make modifications exclusively for you, or provide you
   3.171 +with facilities for running those works, provided that you comply with
   3.172 +the terms of this License in conveying all material for which you do
   3.173 +not control copyright.  Those thus making or running the covered works
   3.174 +for you must do so exclusively on your behalf, under your direction
   3.175 +and control, on terms that prohibit them from making any copies of
   3.176 +your copyrighted material outside their relationship with you.
   3.177 +
   3.178 +  Conveying under any other circumstances is permitted solely under
   3.179 +the conditions stated below.  Sublicensing is not allowed; section 10
   3.180 +makes it unnecessary.
   3.181 +
   3.182 +  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
   3.183 +
   3.184 +  No covered work shall be deemed part of an effective technological
   3.185 +measure under any applicable law fulfilling obligations under article
   3.186 +11 of the WIPO copyright treaty adopted on 20 December 1996, or
   3.187 +similar laws prohibiting or restricting circumvention of such
   3.188 +measures.
   3.189 +
   3.190 +  When you convey a covered work, you waive any legal power to forbid
   3.191 +circumvention of technological measures to the extent such circumvention
   3.192 +is effected by exercising rights under this License with respect to
   3.193 +the covered work, and you disclaim any intention to limit operation or
   3.194 +modification of the work as a means of enforcing, against the work's
   3.195 +users, your or third parties' legal rights to forbid circumvention of
   3.196 +technological measures.
   3.197 +
   3.198 +  4. Conveying Verbatim Copies.
   3.199 +
   3.200 +  You may convey verbatim copies of the Program's source code as you
   3.201 +receive it, in any medium, provided that you conspicuously and
   3.202 +appropriately publish on each copy an appropriate copyright notice;
   3.203 +keep intact all notices stating that this License and any
   3.204 +non-permissive terms added in accord with section 7 apply to the code;
   3.205 +keep intact all notices of the absence of any warranty; and give all
   3.206 +recipients a copy of this License along with the Program.
   3.207 +
   3.208 +  You may charge any price or no price for each copy that you convey,
   3.209 +and you may offer support or warranty protection for a fee.
   3.210 +
   3.211 +  5. Conveying Modified Source Versions.
   3.212 +
   3.213 +  You may convey a work based on the Program, or the modifications to
   3.214 +produce it from the Program, in the form of source code under the
   3.215 +terms of section 4, provided that you also meet all of these conditions:
   3.216 +
   3.217 +    a) The work must carry prominent notices stating that you modified
   3.218 +    it, and giving a relevant date.
   3.219 +
   3.220 +    b) The work must carry prominent notices stating that it is
   3.221 +    released under this License and any conditions added under section
   3.222 +    7.  This requirement modifies the requirement in section 4 to
   3.223 +    "keep intact all notices".
   3.224 +
   3.225 +    c) You must license the entire work, as a whole, under this
   3.226 +    License to anyone who comes into possession of a copy.  This
   3.227 +    License will therefore apply, along with any applicable section 7
   3.228 +    additional terms, to the whole of the work, and all its parts,
   3.229 +    regardless of how they are packaged.  This License gives no
   3.230 +    permission to license the work in any other way, but it does not
   3.231 +    invalidate such permission if you have separately received it.
   3.232 +
   3.233 +    d) If the work has interactive user interfaces, each must display
   3.234 +    Appropriate Legal Notices; however, if the Program has interactive
   3.235 +    interfaces that do not display Appropriate Legal Notices, your
   3.236 +    work need not make them do so.
   3.237 +
   3.238 +  A compilation of a covered work with other separate and independent
   3.239 +works, which are not by their nature extensions of the covered work,
   3.240 +and which are not combined with it such as to form a larger program,
   3.241 +in or on a volume of a storage or distribution medium, is called an
   3.242 +"aggregate" if the compilation and its resulting copyright are not
   3.243 +used to limit the access or legal rights of the compilation's users
   3.244 +beyond what the individual works permit.  Inclusion of a covered work
   3.245 +in an aggregate does not cause this License to apply to the other
   3.246 +parts of the aggregate.
   3.247 +
   3.248 +  6. Conveying Non-Source Forms.
   3.249 +
   3.250 +  You may convey a covered work in object code form under the terms
   3.251 +of sections 4 and 5, provided that you also convey the
   3.252 +machine-readable Corresponding Source under the terms of this License,
   3.253 +in one of these ways:
   3.254 +
   3.255 +    a) Convey the object code in, or embodied in, a physical product
   3.256 +    (including a physical distribution medium), accompanied by the
   3.257 +    Corresponding Source fixed on a durable physical medium
   3.258 +    customarily used for software interchange.
   3.259 +
   3.260 +    b) Convey the object code in, or embodied in, a physical product
   3.261 +    (including a physical distribution medium), accompanied by a
   3.262 +    written offer, valid for at least three years and valid for as
   3.263 +    long as you offer spare parts or customer support for that product
   3.264 +    model, to give anyone who possesses the object code either (1) a
   3.265 +    copy of the Corresponding Source for all the software in the
   3.266 +    product that is covered by this License, on a durable physical
   3.267 +    medium customarily used for software interchange, for a price no
   3.268 +    more than your reasonable cost of physically performing this
   3.269 +    conveying of source, or (2) access to copy the
   3.270 +    Corresponding Source from a network server at no charge.
   3.271 +
   3.272 +    c) Convey individual copies of the object code with a copy of the
   3.273 +    written offer to provide the Corresponding Source.  This
   3.274 +    alternative is allowed only occasionally and noncommercially, and
   3.275 +    only if you received the object code with such an offer, in accord
   3.276 +    with subsection 6b.
   3.277 +
   3.278 +    d) Convey the object code by offering access from a designated
   3.279 +    place (gratis or for a charge), and offer equivalent access to the
   3.280 +    Corresponding Source in the same way through the same place at no
   3.281 +    further charge.  You need not require recipients to copy the
   3.282 +    Corresponding Source along with the object code.  If the place to
   3.283 +    copy the object code is a network server, the Corresponding Source
   3.284 +    may be on a different server (operated by you or a third party)
   3.285 +    that supports equivalent copying facilities, provided you maintain
   3.286 +    clear directions next to the object code saying where to find the
   3.287 +    Corresponding Source.  Regardless of what server hosts the
   3.288 +    Corresponding Source, you remain obligated to ensure that it is
   3.289 +    available for as long as needed to satisfy these requirements.
   3.290 +
   3.291 +    e) Convey the object code using peer-to-peer transmission, provided
   3.292 +    you inform other peers where the object code and Corresponding
   3.293 +    Source of the work are being offered to the general public at no
   3.294 +    charge under subsection 6d.
   3.295 +
   3.296 +  A separable portion of the object code, whose source code is excluded
   3.297 +from the Corresponding Source as a System Library, need not be
   3.298 +included in conveying the object code work.
   3.299 +
   3.300 +  A "User Product" is either (1) a "consumer product", which means any
   3.301 +tangible personal property which is normally used for personal, family,
   3.302 +or household purposes, or (2) anything designed or sold for incorporation
   3.303 +into a dwelling.  In determining whether a product is a consumer product,
   3.304 +doubtful cases shall be resolved in favor of coverage.  For a particular
   3.305 +product received by a particular user, "normally used" refers to a
   3.306 +typical or common use of that class of product, regardless of the status
   3.307 +of the particular user or of the way in which the particular user
   3.308 +actually uses, or expects or is expected to use, the product.  A product
   3.309 +is a consumer product regardless of whether the product has substantial
   3.310 +commercial, industrial or non-consumer uses, unless such uses represent
   3.311 +the only significant mode of use of the product.
   3.312 +
   3.313 +  "Installation Information" for a User Product means any methods,
   3.314 +procedures, authorization keys, or other information required to install
   3.315 +and execute modified versions of a covered work in that User Product from
   3.316 +a modified version of its Corresponding Source.  The information must
   3.317 +suffice to ensure that the continued functioning of the modified object
   3.318 +code is in no case prevented or interfered with solely because
   3.319 +modification has been made.
   3.320 +
   3.321 +  If you convey an object code work under this section in, or with, or
   3.322 +specifically for use in, a User Product, and the conveying occurs as
   3.323 +part of a transaction in which the right of possession and use of the
   3.324 +User Product is transferred to the recipient in perpetuity or for a
   3.325 +fixed term (regardless of how the transaction is characterized), the
   3.326 +Corresponding Source conveyed under this section must be accompanied
   3.327 +by the Installation Information.  But this requirement does not apply
   3.328 +if neither you nor any third party retains the ability to install
   3.329 +modified object code on the User Product (for example, the work has
   3.330 +been installed in ROM).
   3.331 +
   3.332 +  The requirement to provide Installation Information does not include a
   3.333 +requirement to continue to provide support service, warranty, or updates
   3.334 +for a work that has been modified or installed by the recipient, or for
   3.335 +the User Product in which it has been modified or installed.  Access to a
   3.336 +network may be denied when the modification itself materially and
   3.337 +adversely affects the operation of the network or violates the rules and
   3.338 +protocols for communication across the network.
   3.339 +
   3.340 +  Corresponding Source conveyed, and Installation Information provided,
   3.341 +in accord with this section must be in a format that is publicly
   3.342 +documented (and with an implementation available to the public in
   3.343 +source code form), and must require no special password or key for
   3.344 +unpacking, reading or copying.
   3.345 +
   3.346 +  7. Additional Terms.
   3.347 +
   3.348 +  "Additional permissions" are terms that supplement the terms of this
   3.349 +License by making exceptions from one or more of its conditions.
   3.350 +Additional permissions that are applicable to the entire Program shall
   3.351 +be treated as though they were included in this License, to the extent
   3.352 +that they are valid under applicable law.  If additional permissions
   3.353 +apply only to part of the Program, that part may be used separately
   3.354 +under those permissions, but the entire Program remains governed by
   3.355 +this License without regard to the additional permissions.
   3.356 +
   3.357 +  When you convey a copy of a covered work, you may at your option
   3.358 +remove any additional permissions from that copy, or from any part of
   3.359 +it.  (Additional permissions may be written to require their own
   3.360 +removal in certain cases when you modify the work.)  You may place
   3.361 +additional permissions on material, added by you to a covered work,
   3.362 +for which you have or can give appropriate copyright permission.
   3.363 +
   3.364 +  Notwithstanding any other provision of this License, for material you
   3.365 +add to a covered work, you may (if authorized by the copyright holders of
   3.366 +that material) supplement the terms of this License with terms:
   3.367 +
   3.368 +    a) Disclaiming warranty or limiting liability differently from the
   3.369 +    terms of sections 15 and 16 of this License; or
   3.370 +
   3.371 +    b) Requiring preservation of specified reasonable legal notices or
   3.372 +    author attributions in that material or in the Appropriate Legal
   3.373 +    Notices displayed by works containing it; or
   3.374 +
   3.375 +    c) Prohibiting misrepresentation of the origin of that material, or
   3.376 +    requiring that modified versions of such material be marked in
   3.377 +    reasonable ways as different from the original version; or
   3.378 +
   3.379 +    d) Limiting the use for publicity purposes of names of licensors or
   3.380 +    authors of the material; or
   3.381 +
   3.382 +    e) Declining to grant rights under trademark law for use of some
   3.383 +    trade names, trademarks, or service marks; or
   3.384 +
   3.385 +    f) Requiring indemnification of licensors and authors of that
   3.386 +    material by anyone who conveys the material (or modified versions of
   3.387 +    it) with contractual assumptions of liability to the recipient, for
   3.388 +    any liability that these contractual assumptions directly impose on
   3.389 +    those licensors and authors.
   3.390 +
   3.391 +  All other non-permissive additional terms are considered "further
   3.392 +restrictions" within the meaning of section 10.  If the Program as you
   3.393 +received it, or any part of it, contains a notice stating that it is
   3.394 +governed by this License along with a term that is a further
   3.395 +restriction, you may remove that term.  If a license document contains
   3.396 +a further restriction but permits relicensing or conveying under this
   3.397 +License, you may add to a covered work material governed by the terms
   3.398 +of that license document, provided that the further restriction does
   3.399 +not survive such relicensing or conveying.
   3.400 +
   3.401 +  If you add terms to a covered work in accord with this section, you
   3.402 +must place, in the relevant source files, a statement of the
   3.403 +additional terms that apply to those files, or a notice indicating
   3.404 +where to find the applicable terms.
   3.405 +
   3.406 +  Additional terms, permissive or non-permissive, may be stated in the
   3.407 +form of a separately written license, or stated as exceptions;
   3.408 +the above requirements apply either way.
   3.409 +
   3.410 +  8. Termination.
   3.411 +
   3.412 +  You may not propagate or modify a covered work except as expressly
   3.413 +provided under this License.  Any attempt otherwise to propagate or
   3.414 +modify it is void, and will automatically terminate your rights under
   3.415 +this License (including any patent licenses granted under the third
   3.416 +paragraph of section 11).
   3.417 +
   3.418 +  However, if you cease all violation of this License, then your
   3.419 +license from a particular copyright holder is reinstated (a)
   3.420 +provisionally, unless and until the copyright holder explicitly and
   3.421 +finally terminates your license, and (b) permanently, if the copyright
   3.422 +holder fails to notify you of the violation by some reasonable means
   3.423 +prior to 60 days after the cessation.
   3.424 +
   3.425 +  Moreover, your license from a particular copyright holder is
   3.426 +reinstated permanently if the copyright holder notifies you of the
   3.427 +violation by some reasonable means, this is the first time you have
   3.428 +received notice of violation of this License (for any work) from that
   3.429 +copyright holder, and you cure the violation prior to 30 days after
   3.430 +your receipt of the notice.
   3.431 +
   3.432 +  Termination of your rights under this section does not terminate the
   3.433 +licenses of parties who have received copies or rights from you under
   3.434 +this License.  If your rights have been terminated and not permanently
   3.435 +reinstated, you do not qualify to receive new licenses for the same
   3.436 +material under section 10.
   3.437 +
   3.438 +  9. Acceptance Not Required for Having Copies.
   3.439 +
   3.440 +  You are not required to accept this License in order to receive or
   3.441 +run a copy of the Program.  Ancillary propagation of a covered work
   3.442 +occurring solely as a consequence of using peer-to-peer transmission
   3.443 +to receive a copy likewise does not require acceptance.  However,
   3.444 +nothing other than this License grants you permission to propagate or
   3.445 +modify any covered work.  These actions infringe copyright if you do
   3.446 +not accept this License.  Therefore, by modifying or propagating a
   3.447 +covered work, you indicate your acceptance of this License to do so.
   3.448 +
   3.449 +  10. Automatic Licensing of Downstream Recipients.
   3.450 +
   3.451 +  Each time you convey a covered work, the recipient automatically
   3.452 +receives a license from the original licensors, to run, modify and
   3.453 +propagate that work, subject to this License.  You are not responsible
   3.454 +for enforcing compliance by third parties with this License.
   3.455 +
   3.456 +  An "entity transaction" is a transaction transferring control of an
   3.457 +organization, or substantially all assets of one, or subdividing an
   3.458 +organization, or merging organizations.  If propagation of a covered
   3.459 +work results from an entity transaction, each party to that
   3.460 +transaction who receives a copy of the work also receives whatever
   3.461 +licenses to the work the party's predecessor in interest had or could
   3.462 +give under the previous paragraph, plus a right to possession of the
   3.463 +Corresponding Source of the work from the predecessor in interest, if
   3.464 +the predecessor has it or can get it with reasonable efforts.
   3.465 +
   3.466 +  You may not impose any further restrictions on the exercise of the
   3.467 +rights granted or affirmed under this License.  For example, you may
   3.468 +not impose a license fee, royalty, or other charge for exercise of
   3.469 +rights granted under this License, and you may not initiate litigation
   3.470 +(including a cross-claim or counterclaim in a lawsuit) alleging that
   3.471 +any patent claim is infringed by making, using, selling, offering for
   3.472 +sale, or importing the Program or any portion of it.
   3.473 +
   3.474 +  11. Patents.
   3.475 +
   3.476 +  A "contributor" is a copyright holder who authorizes use under this
   3.477 +License of the Program or a work on which the Program is based.  The
   3.478 +work thus licensed is called the contributor's "contributor version".
   3.479 +
   3.480 +  A contributor's "essential patent claims" are all patent claims
   3.481 +owned or controlled by the contributor, whether already acquired or
   3.482 +hereafter acquired, that would be infringed by some manner, permitted
   3.483 +by this License, of making, using, or selling its contributor version,
   3.484 +but do not include claims that would be infringed only as a
   3.485 +consequence of further modification of the contributor version.  For
   3.486 +purposes of this definition, "control" includes the right to grant
   3.487 +patent sublicenses in a manner consistent with the requirements of
   3.488 +this License.
   3.489 +
   3.490 +  Each contributor grants you a non-exclusive, worldwide, royalty-free
   3.491 +patent license under the contributor's essential patent claims, to
   3.492 +make, use, sell, offer for sale, import and otherwise run, modify and
   3.493 +propagate the contents of its contributor version.
   3.494 +
   3.495 +  In the following three paragraphs, a "patent license" is any express
   3.496 +agreement or commitment, however denominated, not to enforce a patent
   3.497 +(such as an express permission to practice a patent or covenant not to
   3.498 +sue for patent infringement).  To "grant" such a patent license to a
   3.499 +party means to make such an agreement or commitment not to enforce a
   3.500 +patent against the party.
   3.501 +
   3.502 +  If you convey a covered work, knowingly relying on a patent license,
   3.503 +and the Corresponding Source of the work is not available for anyone
   3.504 +to copy, free of charge and under the terms of this License, through a
   3.505 +publicly available network server or other readily accessible means,
   3.506 +then you must either (1) cause the Corresponding Source to be so
   3.507 +available, or (2) arrange to deprive yourself of the benefit of the
   3.508 +patent license for this particular work, or (3) arrange, in a manner
   3.509 +consistent with the requirements of this License, to extend the patent
   3.510 +license to downstream recipients.  "Knowingly relying" means you have
   3.511 +actual knowledge that, but for the patent license, your conveying the
   3.512 +covered work in a country, or your recipient's use of the covered work
   3.513 +in a country, would infringe one or more identifiable patents in that
   3.514 +country that you have reason to believe are valid.
   3.515 +
   3.516 +  If, pursuant to or in connection with a single transaction or
   3.517 +arrangement, you convey, or propagate by procuring conveyance of, a
   3.518 +covered work, and grant a patent license to some of the parties
   3.519 +receiving the covered work authorizing them to use, propagate, modify
   3.520 +or convey a specific copy of the covered work, then the patent license
   3.521 +you grant is automatically extended to all recipients of the covered
   3.522 +work and works based on it.
   3.523 +
   3.524 +  A patent license is "discriminatory" if it does not include within
   3.525 +the scope of its coverage, prohibits the exercise of, or is
   3.526 +conditioned on the non-exercise of one or more of the rights that are
   3.527 +specifically granted under this License.  You may not convey a covered
   3.528 +work if you are a party to an arrangement with a third party that is
   3.529 +in the business of distributing software, under which you make payment
   3.530 +to the third party based on the extent of your activity of conveying
   3.531 +the work, and under which the third party grants, to any of the
   3.532 +parties who would receive the covered work from you, a discriminatory
   3.533 +patent license (a) in connection with copies of the covered work
   3.534 +conveyed by you (or copies made from those copies), or (b) primarily
   3.535 +for and in connection with specific products or compilations that
   3.536 +contain the covered work, unless you entered into that arrangement,
   3.537 +or that patent license was granted, prior to 28 March 2007.
   3.538 +
   3.539 +  Nothing in this License shall be construed as excluding or limiting
   3.540 +any implied license or other defenses to infringement that may
   3.541 +otherwise be available to you under applicable patent law.
   3.542 +
   3.543 +  12. No Surrender of Others' Freedom.
   3.544 +
   3.545 +  If conditions are imposed on you (whether by court order, agreement or
   3.546 +otherwise) that contradict the conditions of this License, they do not
   3.547 +excuse you from the conditions of this License.  If you cannot convey a
   3.548 +covered work so as to satisfy simultaneously your obligations under this
   3.549 +License and any other pertinent obligations, then as a consequence you may
   3.550 +not convey it at all.  For example, if you agree to terms that obligate you
   3.551 +to collect a royalty for further conveying from those to whom you convey
   3.552 +the Program, the only way you could satisfy both those terms and this
   3.553 +License would be to refrain entirely from conveying the Program.
   3.554 +
   3.555 +  13. Use with the GNU Affero General Public License.
   3.556 +
   3.557 +  Notwithstanding any other provision of this License, you have
   3.558 +permission to link or combine any covered work with a work licensed
   3.559 +under version 3 of the GNU Affero General Public License into a single
   3.560 +combined work, and to convey the resulting work.  The terms of this
   3.561 +License will continue to apply to the part which is the covered work,
   3.562 +but the special requirements of the GNU Affero General Public License,
   3.563 +section 13, concerning interaction through a network will apply to the
   3.564 +combination as such.
   3.565 +
   3.566 +  14. Revised Versions of this License.
   3.567 +
   3.568 +  The Free Software Foundation may publish revised and/or new versions of
   3.569 +the GNU General Public License from time to time.  Such new versions will
   3.570 +be similar in spirit to the present version, but may differ in detail to
   3.571 +address new problems or concerns.
   3.572 +
   3.573 +  Each version is given a distinguishing version number.  If the
   3.574 +Program specifies that a certain numbered version of the GNU General
   3.575 +Public License "or any later version" applies to it, you have the
   3.576 +option of following the terms and conditions either of that numbered
   3.577 +version or of any later version published by the Free Software
   3.578 +Foundation.  If the Program does not specify a version number of the
   3.579 +GNU General Public License, you may choose any version ever published
   3.580 +by the Free Software Foundation.
   3.581 +
   3.582 +  If the Program specifies that a proxy can decide which future
   3.583 +versions of the GNU General Public License can be used, that proxy's
   3.584 +public statement of acceptance of a version permanently authorizes you
   3.585 +to choose that version for the Program.
   3.586 +
   3.587 +  Later license versions may give you additional or different
   3.588 +permissions.  However, no additional obligations are imposed on any
   3.589 +author or copyright holder as a result of your choosing to follow a
   3.590 +later version.
   3.591 +
   3.592 +  15. Disclaimer of Warranty.
   3.593 +
   3.594 +  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
   3.595 +APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
   3.596 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
   3.597 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
   3.598 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   3.599 +PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
   3.600 +IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
   3.601 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   3.602 +
   3.603 +  16. Limitation of Liability.
   3.604 +
   3.605 +  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
   3.606 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
   3.607 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
   3.608 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
   3.609 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
   3.610 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
   3.611 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
   3.612 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
   3.613 +SUCH DAMAGES.
   3.614 +
   3.615 +  17. Interpretation of Sections 15 and 16.
   3.616 +
   3.617 +  If the disclaimer of warranty and limitation of liability provided
   3.618 +above cannot be given local legal effect according to their terms,
   3.619 +reviewing courts shall apply local law that most closely approximates
   3.620 +an absolute waiver of all civil liability in connection with the
   3.621 +Program, unless a warranty or assumption of liability accompanies a
   3.622 +copy of the Program in return for a fee.
   3.623 +
   3.624 +                     END OF TERMS AND CONDITIONS
   3.625 +
   3.626 +            How to Apply These Terms to Your New Programs
   3.627 +
   3.628 +  If you develop a new program, and you want it to be of the greatest
   3.629 +possible use to the public, the best way to achieve this is to make it
   3.630 +free software which everyone can redistribute and change under these terms.
   3.631 +
   3.632 +  To do so, attach the following notices to the program.  It is safest
   3.633 +to attach them to the start of each source file to most effectively
   3.634 +state the exclusion of warranty; and each file should have at least
   3.635 +the "copyright" line and a pointer to where the full notice is found.
   3.636 +
   3.637 +    <one line to give the program's name and a brief idea of what it does.>
   3.638 +    Copyright (C) <year>  <name of author>
   3.639 +
   3.640 +    This program is free software: you can redistribute it and/or modify
   3.641 +    it under the terms of the GNU General Public License as published by
   3.642 +    the Free Software Foundation, either version 3 of the License, or
   3.643 +    (at your option) any later version.
   3.644 +
   3.645 +    This program is distributed in the hope that it will be useful,
   3.646 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.647 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   3.648 +    GNU General Public License for more details.
   3.649 +
   3.650 +    You should have received a copy of the GNU General Public License
   3.651 +    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   3.652 +
   3.653 +Also add information on how to contact you by electronic and paper mail.
   3.654 +
   3.655 +  If the program does terminal interaction, make it output a short
   3.656 +notice like this when it starts in an interactive mode:
   3.657 +
   3.658 +    <program>  Copyright (C) <year>  <name of author>
   3.659 +    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
   3.660 +    This is free software, and you are welcome to redistribute it
   3.661 +    under certain conditions; type `show c' for details.
   3.662 +
   3.663 +The hypothetical commands `show w' and `show c' should show the appropriate
   3.664 +parts of the General Public License.  Of course, your program's commands
   3.665 +might be different; for a GUI interface, you would use an "about box".
   3.666 +
   3.667 +  You should also get your employer (if you work as a programmer) or school,
   3.668 +if any, to sign a "copyright disclaimer" for the program, if necessary.
   3.669 +For more information on this, and how to apply and follow the GNU GPL, see
   3.670 +<http://www.gnu.org/licenses/>.
   3.671 +
   3.672 +  The GNU General Public License does not permit incorporating your program
   3.673 +into proprietary programs.  If your program is a subroutine library, you
   3.674 +may consider it more useful to permit linking proprietary applications with
   3.675 +the library.  If this is what you want to do, use the GNU Lesser General
   3.676 +Public License instead of this License.  But first, please read
   3.677 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/libs/drawtext/COPYING.LESSER	Thu Sep 24 06:49:25 2015 +0300
     4.3 @@ -0,0 +1,165 @@
     4.4 +                   GNU LESSER GENERAL PUBLIC LICENSE
     4.5 +                       Version 3, 29 June 2007
     4.6 +
     4.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     4.8 + Everyone is permitted to copy and distribute verbatim copies
     4.9 + of this license document, but changing it is not allowed.
    4.10 +
    4.11 +
    4.12 +  This version of the GNU Lesser General Public License incorporates
    4.13 +the terms and conditions of version 3 of the GNU General Public
    4.14 +License, supplemented by the additional permissions listed below.
    4.15 +
    4.16 +  0. Additional Definitions.
    4.17 +
    4.18 +  As used herein, "this License" refers to version 3 of the GNU Lesser
    4.19 +General Public License, and the "GNU GPL" refers to version 3 of the GNU
    4.20 +General Public License.
    4.21 +
    4.22 +  "The Library" refers to a covered work governed by this License,
    4.23 +other than an Application or a Combined Work as defined below.
    4.24 +
    4.25 +  An "Application" is any work that makes use of an interface provided
    4.26 +by the Library, but which is not otherwise based on the Library.
    4.27 +Defining a subclass of a class defined by the Library is deemed a mode
    4.28 +of using an interface provided by the Library.
    4.29 +
    4.30 +  A "Combined Work" is a work produced by combining or linking an
    4.31 +Application with the Library.  The particular version of the Library
    4.32 +with which the Combined Work was made is also called the "Linked
    4.33 +Version".
    4.34 +
    4.35 +  The "Minimal Corresponding Source" for a Combined Work means the
    4.36 +Corresponding Source for the Combined Work, excluding any source code
    4.37 +for portions of the Combined Work that, considered in isolation, are
    4.38 +based on the Application, and not on the Linked Version.
    4.39 +
    4.40 +  The "Corresponding Application Code" for a Combined Work means the
    4.41 +object code and/or source code for the Application, including any data
    4.42 +and utility programs needed for reproducing the Combined Work from the
    4.43 +Application, but excluding the System Libraries of the Combined Work.
    4.44 +
    4.45 +  1. Exception to Section 3 of the GNU GPL.
    4.46 +
    4.47 +  You may convey a covered work under sections 3 and 4 of this License
    4.48 +without being bound by section 3 of the GNU GPL.
    4.49 +
    4.50 +  2. Conveying Modified Versions.
    4.51 +
    4.52 +  If you modify a copy of the Library, and, in your modifications, a
    4.53 +facility refers to a function or data to be supplied by an Application
    4.54 +that uses the facility (other than as an argument passed when the
    4.55 +facility is invoked), then you may convey a copy of the modified
    4.56 +version:
    4.57 +
    4.58 +   a) under this License, provided that you make a good faith effort to
    4.59 +   ensure that, in the event an Application does not supply the
    4.60 +   function or data, the facility still operates, and performs
    4.61 +   whatever part of its purpose remains meaningful, or
    4.62 +
    4.63 +   b) under the GNU GPL, with none of the additional permissions of
    4.64 +   this License applicable to that copy.
    4.65 +
    4.66 +  3. Object Code Incorporating Material from Library Header Files.
    4.67 +
    4.68 +  The object code form of an Application may incorporate material from
    4.69 +a header file that is part of the Library.  You may convey such object
    4.70 +code under terms of your choice, provided that, if the incorporated
    4.71 +material is not limited to numerical parameters, data structure
    4.72 +layouts and accessors, or small macros, inline functions and templates
    4.73 +(ten or fewer lines in length), you do both of the following:
    4.74 +
    4.75 +   a) Give prominent notice with each copy of the object code that the
    4.76 +   Library is used in it and that the Library and its use are
    4.77 +   covered by this License.
    4.78 +
    4.79 +   b) Accompany the object code with a copy of the GNU GPL and this license
    4.80 +   document.
    4.81 +
    4.82 +  4. Combined Works.
    4.83 +
    4.84 +  You may convey a Combined Work under terms of your choice that,
    4.85 +taken together, effectively do not restrict modification of the
    4.86 +portions of the Library contained in the Combined Work and reverse
    4.87 +engineering for debugging such modifications, if you also do each of
    4.88 +the following:
    4.89 +
    4.90 +   a) Give prominent notice with each copy of the Combined Work that
    4.91 +   the Library is used in it and that the Library and its use are
    4.92 +   covered by this License.
    4.93 +
    4.94 +   b) Accompany the Combined Work with a copy of the GNU GPL and this license
    4.95 +   document.
    4.96 +
    4.97 +   c) For a Combined Work that displays copyright notices during
    4.98 +   execution, include the copyright notice for the Library among
    4.99 +   these notices, as well as a reference directing the user to the
   4.100 +   copies of the GNU GPL and this license document.
   4.101 +
   4.102 +   d) Do one of the following:
   4.103 +
   4.104 +       0) Convey the Minimal Corresponding Source under the terms of this
   4.105 +       License, and the Corresponding Application Code in a form
   4.106 +       suitable for, and under terms that permit, the user to
   4.107 +       recombine or relink the Application with a modified version of
   4.108 +       the Linked Version to produce a modified Combined Work, in the
   4.109 +       manner specified by section 6 of the GNU GPL for conveying
   4.110 +       Corresponding Source.
   4.111 +
   4.112 +       1) Use a suitable shared library mechanism for linking with the
   4.113 +       Library.  A suitable mechanism is one that (a) uses at run time
   4.114 +       a copy of the Library already present on the user's computer
   4.115 +       system, and (b) will operate properly with a modified version
   4.116 +       of the Library that is interface-compatible with the Linked
   4.117 +       Version.
   4.118 +
   4.119 +   e) Provide Installation Information, but only if you would otherwise
   4.120 +   be required to provide such information under section 6 of the
   4.121 +   GNU GPL, and only to the extent that such information is
   4.122 +   necessary to install and execute a modified version of the
   4.123 +   Combined Work produced by recombining or relinking the
   4.124 +   Application with a modified version of the Linked Version. (If
   4.125 +   you use option 4d0, the Installation Information must accompany
   4.126 +   the Minimal Corresponding Source and Corresponding Application
   4.127 +   Code. If you use option 4d1, you must provide the Installation
   4.128 +   Information in the manner specified by section 6 of the GNU GPL
   4.129 +   for conveying Corresponding Source.)
   4.130 +
   4.131 +  5. Combined Libraries.
   4.132 +
   4.133 +  You may place library facilities that are a work based on the
   4.134 +Library side by side in a single library together with other library
   4.135 +facilities that are not Applications and are not covered by this
   4.136 +License, and convey such a combined library under terms of your
   4.137 +choice, if you do both of the following:
   4.138 +
   4.139 +   a) Accompany the combined library with a copy of the same work based
   4.140 +   on the Library, uncombined with any other library facilities,
   4.141 +   conveyed under the terms of this License.
   4.142 +
   4.143 +   b) Give prominent notice with the combined library that part of it
   4.144 +   is a work based on the Library, and explaining where to find the
   4.145 +   accompanying uncombined form of the same work.
   4.146 +
   4.147 +  6. Revised Versions of the GNU Lesser General Public License.
   4.148 +
   4.149 +  The Free Software Foundation may publish revised and/or new versions
   4.150 +of the GNU Lesser General Public License from time to time. Such new
   4.151 +versions will be similar in spirit to the present version, but may
   4.152 +differ in detail to address new problems or concerns.
   4.153 +
   4.154 +  Each version is given a distinguishing version number. If the
   4.155 +Library as you received it specifies that a certain numbered version
   4.156 +of the GNU Lesser General Public License "or any later version"
   4.157 +applies to it, you have the option of following the terms and
   4.158 +conditions either of that published version or of any later version
   4.159 +published by the Free Software Foundation. If the Library as you
   4.160 +received it does not specify a version number of the GNU Lesser
   4.161 +General Public License, you may choose any version of the GNU Lesser
   4.162 +General Public License ever published by the Free Software Foundation.
   4.163 +
   4.164 +  If the Library as you received it specifies that a proxy can decide
   4.165 +whether future versions of the GNU Lesser General Public License shall
   4.166 +apply, that proxy's public statement of acceptance of any version is
   4.167 +permanent authorization for you to choose that version for the
   4.168 +Library.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/libs/drawtext/README	Thu Sep 24 06:49:25 2015 +0300
     5.3 @@ -0,0 +1,19 @@
     5.4 +libdrawtext - 0.2.1
     5.5 +-------------------
     5.6 +
     5.7 +Libdrawtext is a simple library for fast anti-aliased text rendering in OpenGL.
     5.8 +
     5.9 +Copyright (C) 2011-2014 John Tsiombikas <nuclear@member.fsf.org>
    5.10 +You may freely use, modify and/or redistribute libdrawtext, under the terms of
    5.11 +the GNU Lesser General Public License (LGPL) version 3 (or at your option, any
    5.12 +later version published by the Free Software Foundation). See COPYING, and
    5.13 +COPYING.LESSER for details.
    5.14 +
    5.15 +website: http://nuclear.mutantstargoat.com/sw/libdrawtext
    5.16 +
    5.17 +master repository (hg): http://nuclear.mutantstargoat.com/hg/libdrawtext
    5.18 +mirror repository (git): https://github.com/jtsiomb/libdrawtext.git
    5.19 +
    5.20 +Feel free to send in bug reports, patches, and other comments to
    5.21 +nuclear@member.fsf.org
    5.22 +Only plain text email messages, hard-wrapped at 72 columns will be accepted.
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/libs/drawtext/drawgl.c	Thu Sep 24 06:49:25 2015 +0300
     6.3 @@ -0,0 +1,306 @@
     6.4 +/*
     6.5 +libdrawtext - a simple library for fast text rendering in OpenGL
     6.6 +Copyright (C) 2011-2012  John Tsiombikas <nuclear@member.fsf.org>
     6.7 +
     6.8 +This program is free software: you can redistribute it and/or modify
     6.9 +it under the terms of the GNU Lesser General Public License as published by
    6.10 +the Free Software Foundation, either version 3 of the License, or
    6.11 +(at your option) any later version.
    6.12 +
    6.13 +This program is distributed in the hope that it will be useful,
    6.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 +GNU Lesser General Public License for more details.
    6.17 +
    6.18 +You should have received a copy of the GNU Lesser General Public License
    6.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    6.20 +*/
    6.21 +#ifdef HAVE_CONFIG_H
    6.22 +#include "config.h"
    6.23 +#endif
    6.24 +
    6.25 +#ifndef NO_OPENGL
    6.26 +#include <stdarg.h>
    6.27 +#include <math.h>
    6.28 +#include <ctype.h>
    6.29 +
    6.30 +#include <stdlib.h>
    6.31 +
    6.32 +#ifndef _MSC_VER
    6.33 +#include <alloca.h>
    6.34 +#else
    6.35 +#include <malloc.h>
    6.36 +#endif
    6.37 +
    6.38 +#ifdef TARGET_IPHONE
    6.39 +#include <OpenGLES/ES2/gl.h>
    6.40 +#define GL_ES
    6.41 +#elif defined(ANDROID)
    6.42 +#include <GLES2/gl2.h>
    6.43 +#define GL_ES
    6.44 +#else
    6.45 +#include <GL/glew.h>
    6.46 +#endif
    6.47 +
    6.48 +#include "drawtext.h"
    6.49 +#include "drawtext_impl.h"
    6.50 +
    6.51 +struct vertex {
    6.52 +	float x, y;
    6.53 +	float s, t;
    6.54 +};
    6.55 +
    6.56 +struct quad {
    6.57 +	struct vertex v[6];
    6.58 +};
    6.59 +
    6.60 +static void cleanup(void);
    6.61 +static void add_glyph(struct glyph *g, float x, float y);
    6.62 +
    6.63 +#define QBUF_SZ		512
    6.64 +static struct quad *qbuf;
    6.65 +static int num_quads;
    6.66 +static int vattr = -1;
    6.67 +static int tattr = -1;
    6.68 +static unsigned int font_tex;
    6.69 +static int buf_mode = DTX_NBF;
    6.70 +
    6.71 +
    6.72 +int dtx_gl_init(void)
    6.73 +{
    6.74 +	if(qbuf) {
    6.75 +		return 0;	/* already initialized */
    6.76 +	}
    6.77 +
    6.78 +#ifdef __glew_h__
    6.79 +	glewInit();
    6.80 +#endif
    6.81 +
    6.82 +	if(!(qbuf = malloc(QBUF_SZ * sizeof *qbuf))) {
    6.83 +		return -1;
    6.84 +	}
    6.85 +	num_quads = 0;
    6.86 +
    6.87 +	atexit(cleanup);
    6.88 +	return 0;
    6.89 +}
    6.90 +
    6.91 +static void cleanup(void)
    6.92 +{
    6.93 +	free(qbuf);
    6.94 +}
    6.95 +
    6.96 +
    6.97 +void dtx_vertex_attribs(int vert_attr, int tex_attr)
    6.98 +{
    6.99 +	vattr = vert_attr;
   6.100 +	tattr = tex_attr;
   6.101 +}
   6.102 +
   6.103 +static void set_glyphmap_texture(struct dtx_glyphmap *gmap)
   6.104 +{
   6.105 +	if(!gmap->tex) {
   6.106 +		glGenTextures(1, &gmap->tex);
   6.107 +		glBindTexture(GL_TEXTURE_2D, gmap->tex);
   6.108 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
   6.109 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   6.110 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   6.111 +		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   6.112 +
   6.113 +#ifdef GL_ES
   6.114 +		glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, gmap->xsz, gmap->ysz, 0, GL_ALPHA, GL_UNSIGNED_BYTE, gmap->pixels);
   6.115 +		glGenerateMipmap(GL_TEXTURE_2D);
   6.116 +#else
   6.117 +		gluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, gmap->xsz, gmap->ysz, GL_ALPHA, GL_UNSIGNED_BYTE, gmap->pixels);
   6.118 +#endif
   6.119 +	}
   6.120 +
   6.121 +	if(font_tex != gmap->tex) {
   6.122 +		dtx_flush();
   6.123 +	}
   6.124 +	font_tex = gmap->tex;
   6.125 +}
   6.126 +
   6.127 +void dtx_glyph(int code)
   6.128 +{
   6.129 +	struct dtx_glyphmap *gmap;
   6.130 +
   6.131 +	if(!dtx_font || !(gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code))) {
   6.132 +		return;
   6.133 +	}
   6.134 +	set_glyphmap_texture(gmap);
   6.135 +
   6.136 +	add_glyph(gmap->glyphs + code - gmap->cstart, 0, 0);
   6.137 +	dtx_flush();
   6.138 +}
   6.139 +
   6.140 +static const char *put_char(const char *str, float *pos_x, float *pos_y, int *should_flush)
   6.141 +{
   6.142 +	struct dtx_glyphmap *gmap;
   6.143 +	float px, py;
   6.144 +	int code = dtx_utf8_char_code(str);
   6.145 +	str = dtx_utf8_next_char((char*)str);
   6.146 +
   6.147 +	if(buf_mode == DTX_LBF && code == '\n') {
   6.148 +		*should_flush = 1;
   6.149 +	}
   6.150 +
   6.151 +	px = *pos_x;
   6.152 +	py = *pos_y;
   6.153 +
   6.154 +	if((gmap = dtx_proc_char(code, pos_x, pos_y))) {
   6.155 +		int idx = code - gmap->cstart;
   6.156 +
   6.157 +		set_glyphmap_texture(gmap);
   6.158 +		add_glyph(gmap->glyphs + idx, px, py);
   6.159 +	}
   6.160 +	return str;
   6.161 +}
   6.162 +
   6.163 +void dtx_string(const char *str)
   6.164 +{
   6.165 +	int should_flush = buf_mode == DTX_NBF;
   6.166 +	float pos_x = 0.0f;
   6.167 +	float pos_y = 0.0f;
   6.168 +
   6.169 +	if(!dtx_font) {
   6.170 +		return;
   6.171 +	}
   6.172 +
   6.173 +	while(*str) {
   6.174 +		str = put_char(str, &pos_x, &pos_y, &should_flush);
   6.175 +	}
   6.176 +
   6.177 +	if(should_flush) {
   6.178 +		dtx_flush();
   6.179 +	}
   6.180 +}
   6.181 +
   6.182 +void dtx_printf(const char *fmt, ...)
   6.183 +{
   6.184 +	va_list ap;
   6.185 +	int buf_size;
   6.186 +	char *buf, tmp;
   6.187 +
   6.188 +	if(!dtx_font) {
   6.189 +		return;
   6.190 +	}
   6.191 +
   6.192 +	va_start(ap, fmt);
   6.193 +	buf_size = vsnprintf(&tmp, 0, fmt, ap);
   6.194 +	va_end(ap);
   6.195 +
   6.196 +	if(buf_size == -1) {
   6.197 +		buf_size = 512;
   6.198 +	}
   6.199 +
   6.200 +	buf = alloca(buf_size + 1);
   6.201 +	va_start(ap, fmt);
   6.202 +	vsnprintf(buf, buf_size + 1, fmt, ap);
   6.203 +	va_end(ap);
   6.204 +
   6.205 +	dtx_string(buf);
   6.206 +}
   6.207 +
   6.208 +static void qvertex(struct vertex *v, float x, float y, float s, float t)
   6.209 +{
   6.210 +	v->x = x;
   6.211 +	v->y = y;
   6.212 +	v->s = s;
   6.213 +	v->t = t;
   6.214 +}
   6.215 +
   6.216 +static void add_glyph(struct glyph *g, float x, float y)
   6.217 +{
   6.218 +	struct quad *qptr = qbuf + num_quads;
   6.219 +
   6.220 +	x -= g->orig_x;
   6.221 +	y -= g->orig_y;
   6.222 +
   6.223 +	qvertex(qptr->v + 0, x, y, g->nx, g->ny + g->nheight);
   6.224 +	qvertex(qptr->v + 1, x + g->width, y, g->nx + g->nwidth, g->ny + g->nheight);
   6.225 +	qvertex(qptr->v + 2, x + g->width, y + g->height, g->nx + g->nwidth, g->ny);
   6.226 +
   6.227 +	qvertex(qptr->v + 3, x, y, g->nx, g->ny + g->nheight);
   6.228 +	qvertex(qptr->v + 4, x + g->width, y + g->height, g->nx + g->nwidth, g->ny);
   6.229 +	qvertex(qptr->v + 5, x, y + g->height, g->nx, g->ny);
   6.230 +
   6.231 +	if(++num_quads >= QBUF_SZ) {
   6.232 +		dtx_flush();
   6.233 +	}
   6.234 +}
   6.235 +
   6.236 +void dtx_flush(void)
   6.237 +{
   6.238 +	int vbo;
   6.239 +
   6.240 +	if(!num_quads) {
   6.241 +		return;
   6.242 +	}
   6.243 +
   6.244 +	glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vbo);
   6.245 +	glBindBuffer(GL_ARRAY_BUFFER, 0);
   6.246 +
   6.247 +#ifndef GL_ES
   6.248 +	glPushAttrib(GL_ENABLE_BIT);
   6.249 +	glEnable(GL_TEXTURE_2D);
   6.250 +#endif
   6.251 +	glBindTexture(GL_TEXTURE_2D, font_tex);
   6.252 +
   6.253 +	if(vattr != -1) {
   6.254 +		glEnableVertexAttribArray(vattr);
   6.255 +		glVertexAttribPointer(vattr, 2, GL_FLOAT, 0, sizeof(struct vertex), qbuf);
   6.256 +#ifndef GL_ES
   6.257 +	} else {
   6.258 +		glEnableClientState(GL_VERTEX_ARRAY);
   6.259 +		glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), qbuf);
   6.260 +#endif
   6.261 +	}
   6.262 +	if(tattr != -1) {
   6.263 +		glEnableVertexAttribArray(tattr);
   6.264 +		glVertexAttribPointer(tattr, 2, GL_FLOAT, 0, sizeof(struct vertex), &qbuf->v[0].s);
   6.265 +#ifndef GL_ES
   6.266 +	} else {
   6.267 +		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   6.268 +		glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), &qbuf->v[0].s);
   6.269 +#endif
   6.270 +	}
   6.271 +
   6.272 +	glEnable(GL_BLEND);
   6.273 +	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   6.274 +
   6.275 +	glDepthMask(0);
   6.276 +
   6.277 +	glDrawArrays(GL_TRIANGLES, 0, num_quads * 6);
   6.278 +
   6.279 +	glDepthMask(1);
   6.280 +
   6.281 +	if(vattr != -1) {
   6.282 +		glDisableVertexAttribArray(vattr);
   6.283 +#ifndef GL_ES
   6.284 +	} else {
   6.285 +		glDisableClientState(GL_VERTEX_ARRAY);
   6.286 +#endif
   6.287 +	}
   6.288 +	if(tattr != -1) {
   6.289 +		glDisableVertexAttribArray(tattr);
   6.290 +#ifndef GL_ES
   6.291 +	} else {
   6.292 +		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   6.293 +#endif
   6.294 +	}
   6.295 +
   6.296 +#ifndef GL_ES
   6.297 +	glPopAttrib();
   6.298 +#else
   6.299 +	glDisable(GL_BLEND);
   6.300 +#endif
   6.301 +
   6.302 +	if(vbo) {
   6.303 +		glBindBuffer(GL_ARRAY_BUFFER, vbo);
   6.304 +	}
   6.305 +
   6.306 +	num_quads = 0;
   6.307 +}
   6.308 +
   6.309 +#endif	/* !def NO_OPENGL */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/libs/drawtext/drawtext.h	Thu Sep 24 06:49:25 2015 +0300
     7.3 @@ -0,0 +1,195 @@
     7.4 +/*
     7.5 +libdrawtext - a simple library for fast text rendering in OpenGL
     7.6 +Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     7.7 +
     7.8 +This program is free software: you can redistribute it and/or modify
     7.9 +it under the terms of the GNU Lesser General Public License as published by
    7.10 +the Free Software Foundation, either version 3 of the License, or
    7.11 +(at your option) any later version.
    7.12 +
    7.13 +This program is distributed in the hope that it will be useful,
    7.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 +GNU Lesser General Public License for more details.
    7.17 +
    7.18 +You should have received a copy of the GNU Lesser General Public License
    7.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    7.20 +*/
    7.21 +#ifndef LIBDRAWTEXT_H_
    7.22 +#define LIBDRAWTEXT_H_
    7.23 +
    7.24 +#include <stdio.h>
    7.25 +#include <stdlib.h>
    7.26 +#include "assman.h"
    7.27 +
    7.28 +struct dtx_font;
    7.29 +struct dtx_glyphmap;
    7.30 +
    7.31 +/* draw buffering modes */
    7.32 +enum {
    7.33 +	DTX_NBF,	/* unbuffered */
    7.34 +	DTX_LBF,	/* line buffered */
    7.35 +	DTX_FBF		/* fully buffered */
    7.36 +};
    7.37 +
    7.38 +struct dtx_box {
    7.39 +	float x, y;
    7.40 +	float width, height;
    7.41 +};
    7.42 +
    7.43 +#ifdef __cplusplus
    7.44 +extern "C" {
    7.45 +#endif
    7.46 +
    7.47 +/* Open a truetype/opentype/whatever font.
    7.48 + *
    7.49 + * If sz is non-zero, the default ASCII glyphmap at the requested point size is
    7.50 + * automatically created as well, and ready to use.
    7.51 + *
    7.52 + * To use other unicode ranges and different font sizes you must first call
    7.53 + * dtx_prepare or dtx_prepare_range before issuing any drawing calls, otherwise
    7.54 + * nothing will be rendered.
    7.55 + */
    7.56 +struct dtx_font *dtx_open_font(const char *fname, int sz);
    7.57 +/* open a font by loading a precompiled glyphmap (see: dtx_save_glyphmap)
    7.58 + * this works even when compiled without freetype support
    7.59 + */
    7.60 +struct dtx_font *dtx_open_font_glyphmap(const char *fname);
    7.61 +/* close a font opened by either of the above */
    7.62 +void dtx_close_font(struct dtx_font *fnt);
    7.63 +
    7.64 +/* prepare an ASCII glyphmap for the specified font size */
    7.65 +void dtx_prepare(struct dtx_font *fnt, int sz);
    7.66 +/* prepare an arbitrary unicode range glyphmap for the specified font size */
    7.67 +void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend);
    7.68 +
    7.69 +int dtx_get_font_glyphmap_count(struct dtx_font *fnt);
    7.70 +struct dtx_glyphmap *dtx_get_font_glyphmap_idx(struct dtx_font *fnt, int idx);
    7.71 +
    7.72 +/* Finds the glyphmap that contains the specified character code and matches the requested size
    7.73 + * Returns null if it hasn't been created (you should call dtx_prepare/dtx_prepare_range).
    7.74 + */
    7.75 +struct dtx_glyphmap *dtx_get_font_glyphmap(struct dtx_font *fnt, int sz, int code);
    7.76 +
    7.77 +/* Finds the glyphmap that contains the specified unicode range and matches the requested font size
    7.78 + * Will automatically generate one if it can't find it.
    7.79 + */
    7.80 +struct dtx_glyphmap *dtx_get_font_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend);
    7.81 +
    7.82 +/* Creates and returns a glyphmap for a particular unicode range and font size.
    7.83 + * The generated glyphmap is added to the font's list of glyphmaps.
    7.84 + */
    7.85 +struct dtx_glyphmap *dtx_create_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend);
    7.86 +/* free a glyphmap */
    7.87 +void dtx_free_glyphmap(struct dtx_glyphmap *gmap);
    7.88 +
    7.89 +/* returns a pointer to the raster image of a glyphmap (1 byte per pixel grayscale) */
    7.90 +unsigned char *dtx_get_glyphmap_image(struct dtx_glyphmap *gmap);
    7.91 +/* returns the point size of the glyphmap */
    7.92 +int dtx_get_glyphmap_ptsize(struct dtx_glyphmap *gmap);
    7.93 +/* returns the width of the glyphmap image in pixels */
    7.94 +int dtx_get_glyphmap_width(struct dtx_glyphmap *gmap);
    7.95 +/* returns the height of the glyphmap image in pixels */
    7.96 +int dtx_get_glyphmap_height(struct dtx_glyphmap *gmap);
    7.97 +
    7.98 +/* The following functions can be used even when the library is compiled without
    7.99 + * freetype support.
   7.100 + */
   7.101 +struct dtx_glyphmap *dtx_load_glyphmap(const char *fname);
   7.102 +struct dtx_glyphmap *dtx_load_glyphmap_stream(FILE *fp);
   7.103 +struct dtx_glyphmap *dtx_load_glyphmap_asset(ass_file *fp);
   7.104 +int dtx_save_glyphmap(const char *fname, const struct dtx_glyphmap *gmap);
   7.105 +int dtx_save_glyphmap_stream(FILE *fp, const struct dtx_glyphmap *gmap);
   7.106 +
   7.107 +/* adds a glyphmap to a font */
   7.108 +void dtx_add_glyphmap(struct dtx_font *fnt, struct dtx_glyphmap *gmap);
   7.109 +
   7.110 +/* ---- rendering ---- */
   7.111 +
   7.112 +/* before drawing anything this function must set the font to use */
   7.113 +void dtx_use_font(struct dtx_font *fnt, int sz);
   7.114 +
   7.115 +/* sets the buffering mode
   7.116 + * - DTX_NBUF: every call to dtx_string gets rendered immediately.
   7.117 + * - DTX_LBUF: renders when the buffer is full or the string contains a newline.
   7.118 + * - DTX_FBUF: renders only when the buffer is full (you must call dtx_flush explicitly).
   7.119 + */
   7.120 +void dtx_draw_buffering(int mode);
   7.121 +
   7.122 +/* Sets the vertex attribute indices to use for passing vertex and texture coordinate
   7.123 + * data. By default both are -1 which means you don't have to use a shader, and if you
   7.124 + * do they are accessible through gl_Vertex and gl_MultiTexCoord0, as usual.
   7.125 + *
   7.126 + * NOTE: If you are using OpenGL ES 2.x or OpenGL >= 3.1 pure (non-compatibility) context
   7.127 + * you must specify valid attribute indices.
   7.128 + */
   7.129 +void dtx_vertex_attribs(int vert_attr, int tex_attr);
   7.130 +
   7.131 +/* draws a single glyph at the origin */
   7.132 +void dtx_glyph(int code);
   7.133 +/* draws a utf-8 string starting at the origin. \n \r and \t are handled appropriately. */
   7.134 +void dtx_string(const char *str);
   7.135 +
   7.136 +void dtx_printf(const char *fmt, ...);
   7.137 +
   7.138 +/* render any pending glyphs (see dtx_draw_buffering) */
   7.139 +void dtx_flush(void);
   7.140 +
   7.141 +
   7.142 +/* ---- encodings ---- */
   7.143 +
   7.144 +/* returns a pointer to the next character in a utf-8 stream */
   7.145 +char *dtx_utf8_next_char(char *str);
   7.146 +
   7.147 +/* returns the unicode character codepoint of the utf-8 character starting at str */
   7.148 +int dtx_utf8_char_code(const char *str);
   7.149 +
   7.150 +/* returns the number of bytes of the utf-8 character starting at str */
   7.151 +int dtx_utf8_nbytes(const char *str);
   7.152 +
   7.153 +/* returns the number of utf-8 character in a zero-terminated utf-8 string */
   7.154 +int dtx_utf8_char_count(const char *str);
   7.155 +
   7.156 +/* Converts a unicode code-point to a utf-8 character by filling in the buffer
   7.157 + * passed at the second argument, and returns the number of bytes taken by that
   7.158 + * utf-8 character.
   7.159 + * It's valid to pass a null buffer pointer, in which case only the byte count is
   7.160 + * returned (useful to figure out how much memory to allocate for a buffer).
   7.161 + */
   7.162 +size_t dtx_utf8_from_char_code(int code, char *buf);
   7.163 +
   7.164 +/* Converts a unicode utf-16 wchar_t string to utf-8, filling in the buffer passed
   7.165 + * at the second argument. Returns the size of the resulting string in bytes.
   7.166 + *
   7.167 + * It's valid to pass a null buffer pointer, in which case only the size gets
   7.168 + * calculated and returned, which is useful for figuring out how much memory to
   7.169 + * allocate for the utf-8 buffer.
   7.170 + */
   7.171 +size_t dtx_utf8_from_string(const wchar_t *str, char *buf);
   7.172 +
   7.173 +
   7.174 +/* ---- metrics ---- */
   7.175 +float dtx_line_height(void);
   7.176 +
   7.177 +/* rendered dimensions of a single glyph */
   7.178 +void dtx_glyph_box(int code, struct dtx_box *box);
   7.179 +float dtx_glyph_width(int code);
   7.180 +float dtx_glyph_height(int code);
   7.181 +
   7.182 +/* rendered dimensions of a string */
   7.183 +void dtx_string_box(const char *str, struct dtx_box *box);
   7.184 +float dtx_string_width(const char *str);
   7.185 +float dtx_string_height(const char *str);
   7.186 +
   7.187 +/* returns the horizontal position of the n-th character of the rendered string
   7.188 + * (useful for placing cursors)
   7.189 + */
   7.190 +float dtx_char_pos(const char *str, int n);
   7.191 +
   7.192 +int dtx_char_at_pt(const char *str, float pt);
   7.193 +
   7.194 +#ifdef __cplusplus
   7.195 +}
   7.196 +#endif
   7.197 +
   7.198 +#endif	/* LIBDRAWTEXT_H_ */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/libs/drawtext/drawtext_impl.h	Thu Sep 24 06:49:25 2015 +0300
     8.3 @@ -0,0 +1,73 @@
     8.4 +/*
     8.5 +libdrawtext - a simple library for fast text rendering in OpenGL
     8.6 +Copyright (C) 2011-2012  John Tsiombikas <nuclear@member.fsf.org>
     8.7 +
     8.8 +This program is free software: you can redistribute it and/or modify
     8.9 +it under the terms of the GNU Lesser General Public License as published by
    8.10 +the Free Software Foundation, either version 3 of the License, or
    8.11 +(at your option) any later version.
    8.12 +
    8.13 +This program is distributed in the hope that it will be useful,
    8.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 +GNU Lesser General Public License for more details.
    8.17 +
    8.18 +You should have received a copy of the GNU Lesser General Public License
    8.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    8.20 +*/
    8.21 +#ifndef TEXT_IMPL_H_
    8.22 +#define TEXT_IMPL_H_
    8.23 +
    8.24 +struct glyph {
    8.25 +	int code;
    8.26 +	float x, y, width, height;
    8.27 +	/* normalized coords [0, 1] */
    8.28 +	float nx, ny, nwidth, nheight;
    8.29 +	float orig_x, orig_y;
    8.30 +	float advance;
    8.31 +	struct glyph *next;
    8.32 +};
    8.33 +
    8.34 +struct dtx_glyphmap {
    8.35 +	int ptsize;
    8.36 +
    8.37 +	int xsz, ysz;
    8.38 +	unsigned char *pixels;
    8.39 +	unsigned int tex;
    8.40 +
    8.41 +	int cstart, cend;	/* character range */
    8.42 +	int crange;
    8.43 +
    8.44 +	float line_advance;
    8.45 +
    8.46 +	struct glyph *glyphs;
    8.47 +	struct dtx_glyphmap *next;
    8.48 +};
    8.49 +
    8.50 +struct dtx_font {
    8.51 +	/* freetype FT_Face */
    8.52 +	void *face;
    8.53 +
    8.54 +	/* list of glyphmaps */
    8.55 +	struct dtx_glyphmap *gmaps;
    8.56 +	int num_gmaps;
    8.57 +
    8.58 +	/* last returned glyphmap (cache) */
    8.59 +	struct dtx_glyphmap *last_gmap;
    8.60 +};
    8.61 +
    8.62 +
    8.63 +extern struct dtx_font *dtx_font;
    8.64 +extern int dtx_font_sz;
    8.65 +
    8.66 +
    8.67 +#define fperror(str) \
    8.68 +	fprintf(stderr, "%s: %s: %s\n", __FUNCTION__, (str), strerror(errno))
    8.69 +
    8.70 +int dtx_gl_init(void);
    8.71 +
    8.72 +/* returns zero if it should NOT be printed and modifies xpos/ypos */
    8.73 +/* implemented in font.c */
    8.74 +struct dtx_glyphmap *dtx_proc_char(int code, float *xpos, float *ypos);
    8.75 +
    8.76 +#endif	/* TEXT_IMPL_H_ */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/libs/drawtext/font.c	Thu Sep 24 06:49:25 2015 +0300
     9.3 @@ -0,0 +1,800 @@
     9.4 +/*
     9.5 +libdrawtext - a simple library for fast text rendering in OpenGL
     9.6 +Copyright (C) 2011-2014  John Tsiombikas <nuclear@member.fsf.org>
     9.7 +
     9.8 +This program is free software: you can redistribute it and/or modify
     9.9 +it under the terms of the GNU Lesser General Public License as published by
    9.10 +the Free Software Foundation, either version 3 of the License, or
    9.11 +(at your option) any later version.
    9.12 +
    9.13 +This program is distributed in the hope that it will be useful,
    9.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 +GNU Lesser General Public License for more details.
    9.17 +
    9.18 +You should have received a copy of the GNU Lesser General Public License
    9.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    9.20 +*/
    9.21 +#ifndef NO_FREETYPE
    9.22 +#define USE_FREETYPE
    9.23 +#endif
    9.24 +
    9.25 +#include <stdio.h>
    9.26 +#include <stdlib.h>
    9.27 +#include <string.h>
    9.28 +#include <math.h>
    9.29 +#include <limits.h>
    9.30 +#include <ctype.h>
    9.31 +#include <float.h>
    9.32 +#include <errno.h>
    9.33 +#ifdef USE_FREETYPE
    9.34 +#include <ft2build.h>
    9.35 +#include FT_FREETYPE_H
    9.36 +#endif
    9.37 +#include "assman.h"
    9.38 +#include "drawtext.h"
    9.39 +#include "drawtext_impl.h"
    9.40 +
    9.41 +#define FTSZ_TO_PIXELS(x)	((x) / 64)
    9.42 +#define MAX_IMG_WIDTH		4096
    9.43 +
    9.44 +struct dtx_font *dtx_font;
    9.45 +int dtx_font_sz;
    9.46 +
    9.47 +
    9.48 +#ifdef USE_FREETYPE
    9.49 +static int init_freetype(void);
    9.50 +static void cleanup(void);
    9.51 +
    9.52 +static void calc_best_size(int total_width, int max_gwidth, int max_gheight,
    9.53 +		int padding, int pow2, int *imgw, int *imgh);
    9.54 +static int next_pow2(int x);
    9.55 +
    9.56 +static FT_Library ft;
    9.57 +
    9.58 +
    9.59 +static int init_done;
    9.60 +
    9.61 +static int init_freetype(void)
    9.62 +{
    9.63 +	if(!init_done) {
    9.64 +		if(FT_Init_FreeType(&ft) != 0) {
    9.65 +			return -1;
    9.66 +		}
    9.67 +		atexit(cleanup);
    9.68 +		init_done = 1;
    9.69 +	}
    9.70 +	return 0;
    9.71 +}
    9.72 +
    9.73 +static void cleanup(void)
    9.74 +{
    9.75 +	if(init_done) {
    9.76 +		FT_Done_FreeType(ft);
    9.77 +	}
    9.78 +}
    9.79 +#endif	/* USE_FREETYPE */
    9.80 +
    9.81 +struct dtx_font *dtx_open_font(const char *fname, int sz)
    9.82 +{
    9.83 +	struct dtx_font *fnt = 0;
    9.84 +
    9.85 +#ifdef USE_FREETYPE
    9.86 +	init_freetype();
    9.87 +
    9.88 +	if(!(fnt = calloc(1, sizeof *fnt))) {
    9.89 +		fperror("failed to allocate font structure");
    9.90 +		return 0;
    9.91 +	}
    9.92 +
    9.93 +	if(FT_New_Face(ft, fname, 0, (FT_Face*)&fnt->face) != 0) {
    9.94 +		fprintf(stderr, "failed to open font file: %s\n", fname);
    9.95 +		return 0;
    9.96 +	}
    9.97 +
    9.98 +	/* pre-create the extended ASCII range glyphmap */
    9.99 +	if(sz) {
   9.100 +		dtx_prepare_range(fnt, sz, 0, 256);
   9.101 +
   9.102 +		if(!dtx_font) {
   9.103 +			dtx_use_font(fnt, sz);
   9.104 +		}
   9.105 +	}
   9.106 +#else
   9.107 +	fprintf(stderr, "ignoring call to dtx_open_font: not compiled with freetype support!\n");
   9.108 +#endif
   9.109 +
   9.110 +	return fnt;
   9.111 +}
   9.112 +
   9.113 +struct dtx_font *dtx_open_font_glyphmap(const char *fname)
   9.114 +{
   9.115 +	struct dtx_font *fnt;
   9.116 +	struct dtx_glyphmap *gmap;
   9.117 +
   9.118 +	if(!(fnt = calloc(1, sizeof *fnt))) {
   9.119 +		fperror("failed to allocate font structure");
   9.120 +		return 0;
   9.121 +	}
   9.122 +
   9.123 +	if(fname) {
   9.124 +		if(!(gmap = dtx_load_glyphmap(fname))) {
   9.125 +			free(fnt);
   9.126 +			return 0;
   9.127 +		}
   9.128 +
   9.129 +		dtx_add_glyphmap(fnt, gmap);
   9.130 +
   9.131 +		if(!dtx_font) {
   9.132 +			dtx_use_font(fnt, gmap->ptsize);
   9.133 +		}
   9.134 +	}
   9.135 +	return fnt;
   9.136 +}
   9.137 +
   9.138 +void dtx_close_font(struct dtx_font *fnt)
   9.139 +{
   9.140 +	if(!fnt) return;
   9.141 +
   9.142 +#ifdef USE_FREETYPE
   9.143 +	FT_Done_Face(fnt->face);
   9.144 +#endif
   9.145 +
   9.146 +	/* destroy the glyphmaps */
   9.147 +	while(fnt->gmaps) {
   9.148 +		void *tmp = fnt->gmaps;
   9.149 +		fnt->gmaps = fnt->gmaps->next;
   9.150 +		dtx_free_glyphmap(tmp);
   9.151 +	}
   9.152 +
   9.153 +	free(fnt);
   9.154 +}
   9.155 +
   9.156 +void dtx_prepare(struct dtx_font *fnt, int sz)
   9.157 +{
   9.158 +	if(!dtx_get_font_glyphmap_range(fnt, sz, 0, 256)) {
   9.159 +		fprintf(stderr, "%s: failed (sz: %d, range: 0-255 [ascii])\n", __FUNCTION__, sz);
   9.160 +	}
   9.161 +}
   9.162 +
   9.163 +void dtx_prepare_range(struct dtx_font *fnt, int sz, int cstart, int cend)
   9.164 +{
   9.165 +	if(!dtx_get_font_glyphmap_range(fnt, sz, cstart, cend)) {
   9.166 +		fprintf(stderr, "%s: failed (sz: %d, range: %d-%d)\n", __FUNCTION__, sz, cstart, cend);
   9.167 +	}
   9.168 +}
   9.169 +
   9.170 +int dtx_get_font_glyphmap_count(struct dtx_font *fnt)
   9.171 +{
   9.172 +	return fnt->num_gmaps;
   9.173 +}
   9.174 +
   9.175 +struct dtx_glyphmap *dtx_get_font_glyphmap_idx(struct dtx_font *fnt, int idx)
   9.176 +{
   9.177 +	int i;
   9.178 +	struct dtx_glyphmap *gm = fnt->gmaps;
   9.179 +
   9.180 +	for(i=0; i<idx; i++) {
   9.181 +		gm = gm->next;
   9.182 +		if(!gm) return 0;
   9.183 +	}
   9.184 +	return gm;
   9.185 +}
   9.186 +
   9.187 +struct dtx_glyphmap *dtx_get_font_glyphmap(struct dtx_font *fnt, int sz, int code)
   9.188 +{
   9.189 +	struct dtx_glyphmap *gm;
   9.190 +
   9.191 +	/* check to see if the last we've given out fits the bill */
   9.192 +	if(fnt->last_gmap && code >= fnt->last_gmap->cstart && code < fnt->last_gmap->cend && fnt->last_gmap->ptsize == sz) {
   9.193 +		return fnt->last_gmap;
   9.194 +	}
   9.195 +
   9.196 +	/* otherwise search for the appropriate glyphmap */
   9.197 +	gm = fnt->gmaps;
   9.198 +	while(gm) {
   9.199 +		if(code >= gm->cstart && code < gm->cend && sz == gm->ptsize) {
   9.200 +			fnt->last_gmap = gm;
   9.201 +			return gm;
   9.202 +		}
   9.203 +		gm = gm->next;
   9.204 +	}
   9.205 +	return 0;
   9.206 +}
   9.207 +
   9.208 +struct dtx_glyphmap *dtx_get_font_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend)
   9.209 +{
   9.210 +	struct dtx_glyphmap *gm;
   9.211 +
   9.212 +	/* search the available glyphmaps to see if we've got one that includes
   9.213 +	 * the requested range
   9.214 +	 */
   9.215 +	gm = fnt->gmaps;
   9.216 +	while(gm) {
   9.217 +		if(gm->cstart <= cstart && gm->cend >= cend && gm->ptsize == sz) {
   9.218 +			return gm;
   9.219 +		}
   9.220 +		gm = gm->next;
   9.221 +	}
   9.222 +
   9.223 +	/* not found, create one and add it to the list */
   9.224 +	if(!(gm = dtx_create_glyphmap_range(fnt, sz, cstart, cend))) {
   9.225 +		return 0;
   9.226 +	}
   9.227 +	return gm;
   9.228 +}
   9.229 +
   9.230 +struct dtx_glyphmap *dtx_create_glyphmap_range(struct dtx_font *fnt, int sz, int cstart, int cend)
   9.231 +{
   9.232 +	struct dtx_glyphmap *gmap = 0;
   9.233 +
   9.234 +#ifdef USE_FREETYPE
   9.235 +	FT_Face face = fnt->face;
   9.236 +	int i, j;
   9.237 +	int gx, gy;
   9.238 +	int padding = 4;
   9.239 +	int total_width, max_width, max_height;
   9.240 +
   9.241 +	FT_Set_Char_Size(fnt->face, 0, sz * 64, 72, 72);
   9.242 +
   9.243 +	if(!(gmap = calloc(1, sizeof *gmap))) {
   9.244 +		return 0;
   9.245 +	}
   9.246 +
   9.247 +	gmap->ptsize = sz;
   9.248 +	gmap->cstart = cstart;
   9.249 +	gmap->cend = cend;
   9.250 +	gmap->crange = cend - cstart;
   9.251 +	gmap->line_advance = FTSZ_TO_PIXELS((float)face->size->metrics.height);
   9.252 +
   9.253 +	if(!(gmap->glyphs = malloc(gmap->crange * sizeof *gmap->glyphs))) {
   9.254 +		free(gmap);
   9.255 +		return 0;
   9.256 +	}
   9.257 +
   9.258 +	total_width = padding;
   9.259 +	max_width = max_height = 0;
   9.260 +
   9.261 +	for(i=0; i<gmap->crange; i++) {
   9.262 +		int w, h;
   9.263 +
   9.264 +		FT_Load_Char(face, i + cstart, 0);
   9.265 +		w = FTSZ_TO_PIXELS(face->glyph->metrics.width);
   9.266 +		h = FTSZ_TO_PIXELS(face->glyph->metrics.height);
   9.267 +
   9.268 +		if(w > max_width) max_width = w;
   9.269 +		if(h > max_height) max_height = h;
   9.270 +
   9.271 +		total_width += w + padding;
   9.272 +	}
   9.273 +
   9.274 +	calc_best_size(total_width, max_width, max_height, padding, 1, &gmap->xsz, &gmap->ysz);
   9.275 +
   9.276 +	if(!(gmap->pixels = malloc(gmap->xsz * gmap->ysz))) {
   9.277 +		free(gmap->glyphs);
   9.278 +		free(gmap);
   9.279 +		return 0;
   9.280 +	}
   9.281 +	memset(gmap->pixels, 0, gmap->xsz * gmap->ysz);
   9.282 +
   9.283 +	gx = padding;
   9.284 +	gy = padding;
   9.285 +
   9.286 +	for(i=0; i<gmap->crange; i++) {
   9.287 +		float gwidth, gheight;
   9.288 +		unsigned char *src, *dst;
   9.289 +		FT_GlyphSlot glyph;
   9.290 +
   9.291 +		FT_Load_Char(face, i + cstart, FT_LOAD_RENDER);
   9.292 +		glyph = face->glyph;
   9.293 +		gwidth = FTSZ_TO_PIXELS((float)glyph->metrics.width);
   9.294 +		gheight = FTSZ_TO_PIXELS((float)glyph->metrics.height);
   9.295 +
   9.296 +		if(gx > gmap->xsz - gwidth - padding) {
   9.297 +			gx = padding;
   9.298 +			gy += max_height + padding;
   9.299 +		}
   9.300 +
   9.301 +		src = glyph->bitmap.buffer;
   9.302 +		dst = gmap->pixels + gy * gmap->xsz + gx;
   9.303 +
   9.304 +		for(j=0; j<glyph->bitmap.rows; j++) {
   9.305 +			memcpy(dst, src, glyph->bitmap.width);
   9.306 +			dst += gmap->xsz;
   9.307 +			src += glyph->bitmap.pitch;
   9.308 +		}
   9.309 +
   9.310 +		gmap->glyphs[i].code = i;
   9.311 +		gmap->glyphs[i].x = gx - 1;
   9.312 +		gmap->glyphs[i].y = gy - 1;
   9.313 +		gmap->glyphs[i].width = gwidth + 2;
   9.314 +		gmap->glyphs[i].height = gheight + 2;
   9.315 +		gmap->glyphs[i].orig_x = -FTSZ_TO_PIXELS((float)glyph->metrics.horiBearingX) + 1;
   9.316 +		gmap->glyphs[i].orig_y = FTSZ_TO_PIXELS((float)glyph->metrics.height - glyph->metrics.horiBearingY) + 1;
   9.317 +		gmap->glyphs[i].advance = FTSZ_TO_PIXELS((float)glyph->metrics.horiAdvance);
   9.318 +		/* also precalc normalized */
   9.319 +		gmap->glyphs[i].nx = (float)gmap->glyphs[i].x / (float)gmap->xsz;
   9.320 +		gmap->glyphs[i].ny = (float)gmap->glyphs[i].y / (float)gmap->ysz;
   9.321 +		gmap->glyphs[i].nwidth = (float)gmap->glyphs[i].width / (float)gmap->xsz;
   9.322 +		gmap->glyphs[i].nheight = (float)gmap->glyphs[i].height / (float)gmap->ysz;
   9.323 +
   9.324 +		gx += gwidth + padding;
   9.325 +	}
   9.326 +
   9.327 +	/* add it to the glyphmaps list of the font */
   9.328 +	dtx_add_glyphmap(fnt, gmap);
   9.329 +#endif	/* USE_FREETYPE */
   9.330 +
   9.331 +	return gmap;
   9.332 +}
   9.333 +
   9.334 +void dtx_free_glyphmap(struct dtx_glyphmap *gmap)
   9.335 +{
   9.336 +	if(gmap) {
   9.337 +		free(gmap->pixels);
   9.338 +		free(gmap->glyphs);
   9.339 +		free(gmap);
   9.340 +	}
   9.341 +}
   9.342 +
   9.343 +unsigned char *dtx_get_glyphmap_pixels(struct dtx_glyphmap *gmap)
   9.344 +{
   9.345 +	return gmap->pixels;
   9.346 +}
   9.347 +
   9.348 +int dtx_get_glyphmap_ptsize(struct dtx_glyphmap *gmap)
   9.349 +{
   9.350 +	return gmap->ptsize;
   9.351 +}
   9.352 +
   9.353 +int dtx_get_glyphmap_width(struct dtx_glyphmap *gmap)
   9.354 +{
   9.355 +	return gmap->xsz;
   9.356 +}
   9.357 +
   9.358 +int dtx_get_glyphmap_height(struct dtx_glyphmap *gmap)
   9.359 +{
   9.360 +	return gmap->ysz;
   9.361 +}
   9.362 +
   9.363 +struct dtx_glyphmap *dtx_load_glyphmap(const char *fname)
   9.364 +{
   9.365 +	ass_file *fp;
   9.366 +	struct dtx_glyphmap *gmap;
   9.367 +
   9.368 +	if(!(fp = ass_fopen(fname, "rb"))) {
   9.369 +		return 0;
   9.370 +	}
   9.371 +	gmap = dtx_load_glyphmap_asset(fp);
   9.372 +	ass_fclose(fp);
   9.373 +	return gmap;
   9.374 +}
   9.375 +
   9.376 +struct dtx_glyphmap *dtx_load_glyphmap_asset(ass_file *fp)
   9.377 +{
   9.378 +	char buf[512];
   9.379 +	int hdr_lines = 0;
   9.380 +	struct dtx_glyphmap *gmap;
   9.381 +	struct glyph *glyphs = 0;
   9.382 +	struct glyph *g;
   9.383 +	int min_code = INT_MAX;
   9.384 +	int max_code = INT_MIN;
   9.385 +	int i, max_pixval, num_pixels;
   9.386 +
   9.387 +	if(!(gmap = calloc(1, sizeof *gmap))) {
   9.388 +		fperror("failed to allocate glyphmap");
   9.389 +		return 0;
   9.390 +	}
   9.391 +	gmap->ptsize = -1;
   9.392 +	gmap->line_advance = FLT_MIN;
   9.393 +
   9.394 +	while(hdr_lines < 3) {
   9.395 +		char *line = buf;
   9.396 +		if(!ass_fgets(buf, sizeof buf, fp)) {
   9.397 +			fperror("unexpected end of file");
   9.398 +			goto err;
   9.399 +		}
   9.400 +
   9.401 +		while(isspace(*line)) {
   9.402 +			line++;
   9.403 +		}
   9.404 +
   9.405 +		if(line[0] == '#') {
   9.406 +			int c, res;
   9.407 +			float x, y, xsz, ysz, orig_x, orig_y, adv, line_adv;
   9.408 +			int ptsize;
   9.409 +
   9.410 +			if((res = sscanf(line + 1, " size: %d\n", &ptsize)) == 1) {
   9.411 +				gmap->ptsize = ptsize;
   9.412 +
   9.413 +			} else if((res = sscanf(line + 1, " advance: %f\n", &line_adv)) == 1) {
   9.414 +				gmap->line_advance = line_adv;
   9.415 +
   9.416 +			} else if((res = sscanf(line + 1, " %d: %fx%f+%f+%f o:%f,%f adv:%f\n",
   9.417 +							&c, &xsz, &ysz, &x, &y, &orig_x, &orig_y, &adv)) == 8) {
   9.418 +				if(!(g = malloc(sizeof *g))) {
   9.419 +					fperror("failed to allocate glyph");
   9.420 +					goto err;
   9.421 +				}
   9.422 +				g->code = c;
   9.423 +				g->x = x;
   9.424 +				g->y = y;
   9.425 +				g->width = xsz;
   9.426 +				g->height = ysz;
   9.427 +				g->orig_x = orig_x;
   9.428 +				g->orig_y = orig_y;
   9.429 +				g->advance = adv;
   9.430 +				/* normalized coordinates will be precalculated after everything is loaded */
   9.431 +
   9.432 +				g->next = glyphs;
   9.433 +				glyphs = g;
   9.434 +
   9.435 +				if(c < min_code) {
   9.436 +					min_code = c;
   9.437 +				}
   9.438 +				if(c > max_code) {
   9.439 +					max_code = c;
   9.440 +				}
   9.441 +
   9.442 +			} else {
   9.443 +				fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__);
   9.444 +				goto err;
   9.445 +			}
   9.446 +
   9.447 +		} else {
   9.448 +			switch(hdr_lines) {
   9.449 +			case 0:
   9.450 +				if(0[line] != 'P' || 1[line] != '6') {
   9.451 +					fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__);
   9.452 +					goto err;
   9.453 +				}
   9.454 +				break;
   9.455 +
   9.456 +			case 1:
   9.457 +				if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) {
   9.458 +					fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__);
   9.459 +					goto err;
   9.460 +				}
   9.461 +				break;
   9.462 +
   9.463 +			case 2:
   9.464 +				{
   9.465 +					char *endp;
   9.466 +					max_pixval = strtol(line, &endp, 10);
   9.467 +					if(endp == line) {
   9.468 +						fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__);
   9.469 +						goto err;
   9.470 +					}
   9.471 +				}
   9.472 +				break;
   9.473 +
   9.474 +			default:
   9.475 +				break;	/* can't happen */
   9.476 +			}
   9.477 +			hdr_lines++;
   9.478 +		}
   9.479 +	}
   9.480 +
   9.481 +	if(gmap->ptsize == -1 || gmap->line_advance == FLT_MIN) {
   9.482 +		fprintf(stderr, "%s: invalid glyphmap, insufficient information in ppm comments\n", __FUNCTION__);
   9.483 +		goto err;
   9.484 +	}
   9.485 +
   9.486 +	/* precalculate normalized glyph coordinates */
   9.487 +	g = glyphs;
   9.488 +	while(g) {
   9.489 +		g->nx = g->x / gmap->xsz;
   9.490 +		g->ny = g->y / gmap->ysz;
   9.491 +		g->nwidth = g->width / gmap->xsz;
   9.492 +		g->nheight = g->height / gmap->ysz;
   9.493 +		g = g->next;
   9.494 +	}
   9.495 +
   9.496 +	num_pixels = gmap->xsz * gmap->ysz;
   9.497 +	if(!(gmap->pixels = malloc(num_pixels))) {
   9.498 +		fperror("failed to allocate pixels");
   9.499 +		goto err;
   9.500 +	}
   9.501 +
   9.502 +	for(i=0; i<num_pixels; i++) {
   9.503 +		int c = ass_fgetc(fp);
   9.504 +		if(c == -1) {
   9.505 +			fprintf(stderr, "unexpected end of file while reading pixels (%d/%d)\n", i, num_pixels);
   9.506 +			goto err;
   9.507 +		}
   9.508 +		gmap->pixels[i] = 255 * c / max_pixval;
   9.509 +		ass_fseek(fp, 2, SEEK_CUR);
   9.510 +	}
   9.511 +
   9.512 +	gmap->cstart = min_code;
   9.513 +	gmap->cend = max_code + 1;
   9.514 +	gmap->crange = gmap->cend - gmap->cstart;
   9.515 +
   9.516 +	if(!(gmap->glyphs = calloc(gmap->crange, sizeof *gmap->glyphs))) {
   9.517 +		fperror("failed to allocate glyph info");
   9.518 +		goto err;
   9.519 +	}
   9.520 +
   9.521 +	while(glyphs) {
   9.522 +		struct glyph *g = glyphs;
   9.523 +		glyphs = glyphs->next;
   9.524 +
   9.525 +		gmap->glyphs[g->code - gmap->cstart] = *g;
   9.526 +		free(g);
   9.527 +	}
   9.528 +	return gmap;
   9.529 +
   9.530 +err:
   9.531 +	dtx_free_glyphmap(gmap);
   9.532 +	while(glyphs) {
   9.533 +		void *tmp = glyphs;
   9.534 +		glyphs = glyphs->next;
   9.535 +		free(tmp);
   9.536 +	}
   9.537 +	return 0;
   9.538 +}
   9.539 +
   9.540 +int dtx_save_glyphmap(const char *fname, const struct dtx_glyphmap *gmap)
   9.541 +{
   9.542 +	FILE *fp;
   9.543 +	int res;
   9.544 +
   9.545 +	if(!(fp = fopen(fname, "wb"))) {
   9.546 +		fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno));
   9.547 +		return -1;
   9.548 +	}
   9.549 +	res = dtx_save_glyphmap_stream(fp, gmap);
   9.550 +	fclose(fp);
   9.551 +	return res;
   9.552 +}
   9.553 +
   9.554 +int dtx_save_glyphmap_stream(FILE *fp, const struct dtx_glyphmap *gmap)
   9.555 +{
   9.556 +	int i, num_pixels;
   9.557 +	struct glyph *g = gmap->glyphs;
   9.558 +
   9.559 +	fprintf(fp, "P6\n%d %d\n", gmap->xsz, gmap->ysz);
   9.560 +	fprintf(fp, "# size: %d\n", gmap->ptsize);
   9.561 +	fprintf(fp, "# advance: %g\n", gmap->line_advance);
   9.562 +	for(i=0; i<gmap->crange; i++) {
   9.563 +		fprintf(fp, "# %d: %gx%g+%g+%g o:%g,%g adv:%g\n", g->code, g->width, g->height, g->x, g->y,
   9.564 +				g->orig_x, g->orig_y, g->advance);
   9.565 +		g++;
   9.566 +	}
   9.567 +	fprintf(fp, "255\n");
   9.568 +
   9.569 +	num_pixels = gmap->xsz * gmap->ysz;
   9.570 +	for(i=0; i<num_pixels; i++) {
   9.571 +		int c = gmap->pixels[i];
   9.572 +		fputc(c, fp);
   9.573 +		fputc(c, fp);
   9.574 +		fputc(c, fp);
   9.575 +	}
   9.576 +	return 0;
   9.577 +}
   9.578 +
   9.579 +void dtx_add_glyphmap(struct dtx_font *fnt, struct dtx_glyphmap *gmap)
   9.580 +{
   9.581 +	gmap->next = fnt->gmaps;
   9.582 +	fnt->gmaps = gmap;
   9.583 +	fnt->num_gmaps++;
   9.584 +}
   9.585 +
   9.586 +
   9.587 +void dtx_use_font(struct dtx_font *fnt, int sz)
   9.588 +{
   9.589 +	dtx_gl_init();
   9.590 +
   9.591 +	dtx_font = fnt;
   9.592 +	dtx_font_sz = sz;
   9.593 +}
   9.594 +
   9.595 +float dtx_line_height(void)
   9.596 +{
   9.597 +	struct dtx_glyphmap *gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, '\n');
   9.598 +
   9.599 +	return gmap->line_advance;
   9.600 +}
   9.601 +
   9.602 +void dtx_glyph_box(int code, struct dtx_box *box)
   9.603 +{
   9.604 +	int cidx;
   9.605 +	struct dtx_glyphmap *gmap;
   9.606 +	gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code);
   9.607 +
   9.608 +	cidx = code - gmap->cstart;
   9.609 +
   9.610 +	box->x = gmap->glyphs[cidx].orig_x;
   9.611 +	box->y = gmap->glyphs[cidx].orig_y;
   9.612 +	box->width = gmap->glyphs[cidx].width;
   9.613 +	box->height = gmap->glyphs[cidx].height;
   9.614 +}
   9.615 +
   9.616 +float dtx_glyph_width(int code)
   9.617 +{
   9.618 +	struct dtx_box box;
   9.619 +	dtx_glyph_box(code, &box);
   9.620 +	return box.width;
   9.621 +}
   9.622 +
   9.623 +float dtx_glyph_height(int code)
   9.624 +{
   9.625 +	struct dtx_box box;
   9.626 +	dtx_glyph_box(code, &box);
   9.627 +	return box.height;
   9.628 +}
   9.629 +
   9.630 +void dtx_string_box(const char *str, struct dtx_box *box)
   9.631 +{
   9.632 +	int code;
   9.633 +	float pos_x = 0.0f, pos_y = 0.0f;
   9.634 +	struct glyph *g = 0;
   9.635 +	float x0, y0, x1, y1;
   9.636 +
   9.637 +	x0 = y0 = FLT_MAX;
   9.638 +	x1 = y1 = -FLT_MAX;
   9.639 +
   9.640 +	while(*str) {
   9.641 +		float px, py;
   9.642 +		struct dtx_glyphmap *gmap;
   9.643 +
   9.644 +		code = dtx_utf8_char_code(str);
   9.645 +		str = dtx_utf8_next_char((char*)str);
   9.646 +
   9.647 +		px = pos_x;
   9.648 +		py = pos_y;
   9.649 +
   9.650 +		if((gmap = dtx_proc_char(code, &pos_x, &pos_y))) {
   9.651 +			g = gmap->glyphs + code - gmap->cstart;
   9.652 +
   9.653 +			if(px + g->orig_x < x0) {
   9.654 +				x0 = px + g->orig_x;
   9.655 +			}
   9.656 +			if(py - g->orig_y < y0) {
   9.657 +				y0 = py - g->orig_y;
   9.658 +			}
   9.659 +			if(px + g->orig_x + g->width > x1) {
   9.660 +				x1 = px + g->orig_x + g->width;
   9.661 +			}
   9.662 +			if(py - g->orig_y + g->height > y1) {
   9.663 +				y1 = py - g->orig_y + g->height;
   9.664 +			}
   9.665 +		}
   9.666 +	}
   9.667 +
   9.668 +	box->x = x0;
   9.669 +	box->y = y0;
   9.670 +	box->width = x1 - x0;
   9.671 +	box->height = y1 - y0;
   9.672 +}
   9.673 +
   9.674 +float dtx_string_width(const char *str)
   9.675 +{
   9.676 +	struct dtx_box box;
   9.677 +
   9.678 +	dtx_string_box(str, &box);
   9.679 +	return box.width;
   9.680 +}
   9.681 +
   9.682 +float dtx_string_height(const char *str)
   9.683 +{
   9.684 +	struct dtx_box box;
   9.685 +
   9.686 +	dtx_string_box(str, &box);
   9.687 +	return box.height;
   9.688 +}
   9.689 +
   9.690 +float dtx_char_pos(const char *str, int n)
   9.691 +{
   9.692 +	int i;
   9.693 +	float pos = 0.0;
   9.694 +	struct dtx_glyphmap *gmap;
   9.695 +
   9.696 +	for(i=0; i<n; i++) {
   9.697 +		int code = dtx_utf8_char_code(str);
   9.698 +		str = dtx_utf8_next_char((char*)str);
   9.699 +
   9.700 +		gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code);
   9.701 +		pos += gmap->glyphs[i].advance;
   9.702 +	}
   9.703 +	return pos;
   9.704 +}
   9.705 +
   9.706 +int dtx_char_at_pt(const char *str, float pt)
   9.707 +{
   9.708 +	int i;
   9.709 +	float prev_pos = 0.0f, pos = 0.0f;
   9.710 +	struct dtx_glyphmap *gmap;
   9.711 +
   9.712 +	for(i=0; *str; i++) {
   9.713 +		int code = dtx_utf8_char_code(str);
   9.714 +		str = dtx_utf8_next_char((char*)str);
   9.715 +
   9.716 +		gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code);
   9.717 +		pos += gmap->glyphs[i].advance;
   9.718 +
   9.719 +		if(fabs(pt - prev_pos) < fabs(pt - pos)) {
   9.720 +			break;
   9.721 +		}
   9.722 +		prev_pos = pos;
   9.723 +	}
   9.724 +	return i;
   9.725 +}
   9.726 +
   9.727 +struct dtx_glyphmap *dtx_proc_char(int code, float *xpos, float *ypos)
   9.728 +{
   9.729 +	struct dtx_glyphmap *gmap;
   9.730 +	gmap = dtx_get_font_glyphmap(dtx_font, dtx_font_sz, code);
   9.731 +
   9.732 +	switch(code) {
   9.733 +	case '\n':
   9.734 +		*xpos = 0.0;
   9.735 +		if(gmap) {
   9.736 +			*ypos -= gmap->line_advance;
   9.737 +		}
   9.738 +		return 0;
   9.739 +
   9.740 +	case '\t':
   9.741 +		if(gmap) {
   9.742 +			*xpos = (fmod(*xpos, 4.0) + 4.0) * gmap->glyphs[0].advance;
   9.743 +		}
   9.744 +		return 0;
   9.745 +
   9.746 +	case '\r':
   9.747 +		*xpos = 0.0;
   9.748 +		return 0;
   9.749 +
   9.750 +	default:
   9.751 +		break;
   9.752 +	}
   9.753 +
   9.754 +	if(gmap) {
   9.755 +		*xpos += gmap->glyphs[code - gmap->cstart].advance;
   9.756 +	}
   9.757 +	return gmap;
   9.758 +}
   9.759 +
   9.760 +#ifdef USE_FREETYPE
   9.761 +static void calc_best_size(int total_width, int max_gwidth, int max_gheight, int padding, int pow2, int *imgw, int *imgh)
   9.762 +{
   9.763 +	int xsz, ysz, num_rows;
   9.764 +	float aspect;
   9.765 +
   9.766 +	for(xsz=2; xsz<=MAX_IMG_WIDTH; xsz *= 2) {
   9.767 +		num_rows = total_width / xsz + 1;
   9.768 +
   9.769 +		/* assume worst case, all last glyphs will float to the next line
   9.770 +		 * so let's add extra rows for that. */
   9.771 +		num_rows += (padding + (max_gwidth + padding) * num_rows + xsz - 1) / xsz;
   9.772 +
   9.773 +		ysz = num_rows * (max_gheight + padding) + padding;
   9.774 +		if(pow2) {
   9.775 +			ysz = next_pow2(ysz);
   9.776 +		}
   9.777 +		aspect = (float)xsz / (float)ysz;
   9.778 +
   9.779 +		if(aspect >= 1.0) {
   9.780 +			break;
   9.781 +		}
   9.782 +	}
   9.783 +
   9.784 +	if(xsz > MAX_IMG_WIDTH) {
   9.785 +		xsz = MAX_IMG_WIDTH;
   9.786 +	}
   9.787 +
   9.788 +	*imgw = xsz;
   9.789 +	*imgh = ysz;
   9.790 +}
   9.791 +
   9.792 +
   9.793 +static int next_pow2(int x)
   9.794 +{
   9.795 +	x--;
   9.796 +	x = (x >> 1) | x;
   9.797 +	x = (x >> 2) | x;
   9.798 +	x = (x >> 4) | x;
   9.799 +	x = (x >> 8) | x;
   9.800 +	x = (x >> 16) | x;
   9.801 +	return x + 1;
   9.802 +}
   9.803 +#endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/libs/drawtext/utf8.c	Thu Sep 24 06:49:25 2015 +0300
    10.3 @@ -0,0 +1,154 @@
    10.4 +/*
    10.5 +libdrawtext - a simple library for fast text rendering in OpenGL
    10.6 +Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
    10.7 +
    10.8 +This program is free software: you can redistribute it and/or modify
    10.9 +it under the terms of the GNU Lesser General Public License as published by
   10.10 +the Free Software Foundation, either version 3 of the License, or
   10.11 +(at your option) any later version.
   10.12 +
   10.13 +This program is distributed in the hope that it will be useful,
   10.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 +GNU Lesser General Public License for more details.
   10.17 +
   10.18 +You should have received a copy of the GNU Lesser General Public License
   10.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   10.20 +*/
   10.21 +#include "drawtext.h"
   10.22 +
   10.23 +#define	U8_IS_FIRST(x)		(((((x) >> 7) & 1) == 0) || ((((x) >> 6) & 3) == 3))
   10.24 +
   10.25 +static const char first_mask[] = {
   10.26 +	0,
   10.27 +	0x7f,	/* single byte, 7 bits valid */
   10.28 +	0x1f,	/* two-bytes, 5 bits valid */
   10.29 +	0xf,	/* three-bytes, 4 bits valid */
   10.30 +	0x7		/* four-bytes, 3 bits valid */
   10.31 +};
   10.32 +static const char first_shift[] = { 0, 7, 5, 4, 3 };	/* see above */
   10.33 +
   10.34 +#define CONT_PREFIX	0x80
   10.35 +#define CONT_MASK	0x3f
   10.36 +#define CONT_SHIFT	6
   10.37 +
   10.38 +/* last charcodes for 1, 2, 3 or 4-byte utf8 chars */
   10.39 +static const int utf8_lastcode[] = { 0x7f, 0x7ff, 0xfff, 0x1fffff };
   10.40 +
   10.41 +#define prefix_mask(x)	(~first_mask[x])
   10.42 +#define prefix(x)		((prefix_mask(x) << 1) & 0xff)
   10.43 +
   10.44 +
   10.45 +char *dtx_utf8_next_char(char *str)
   10.46 +{
   10.47 +	return str + dtx_utf8_nbytes(str);
   10.48 +}
   10.49 +
   10.50 +int dtx_utf8_char_code(const char *str)
   10.51 +{
   10.52 +	int i, nbytes, shift, code = 0;
   10.53 +	int mask;
   10.54 +
   10.55 +	if(!U8_IS_FIRST(*str)) {
   10.56 +		return -1;
   10.57 +	}
   10.58 +
   10.59 +	nbytes = dtx_utf8_nbytes(str);
   10.60 +	mask = first_mask[nbytes];
   10.61 +	shift = 0;
   10.62 +
   10.63 +	for(i=0; i<nbytes; i++) {
   10.64 +		if(!*str) {
   10.65 +			break;
   10.66 +		}
   10.67 +
   10.68 +		code = (code << shift) | (*str++ & mask);
   10.69 +		mask = 0x3f;
   10.70 +		shift = 6;
   10.71 +	}
   10.72 +	return code;
   10.73 +}
   10.74 +
   10.75 +int dtx_utf8_nbytes(const char *str)
   10.76 +{
   10.77 +	int i, numset = 0;
   10.78 +	int c = *str;
   10.79 +
   10.80 +	if(!U8_IS_FIRST(c)) {
   10.81 +		for(i=0; !U8_IS_FIRST(str[i]); i++);
   10.82 +		return i;
   10.83 +	}
   10.84 +
   10.85 +	/* count the leading 1s */
   10.86 +	for(i=0; i<4; i++) {
   10.87 +		if(((c >> (7 - i)) & 1) == 0) {
   10.88 +			break;
   10.89 +		}
   10.90 +		numset++;
   10.91 +	}
   10.92 +
   10.93 +	if(!numset) {
   10.94 +		return 1;
   10.95 +	}
   10.96 +	return numset;
   10.97 +}
   10.98 +
   10.99 +int dtx_utf8_char_count(const char *str)
  10.100 +{
  10.101 +	int n = 0;
  10.102 +
  10.103 +	while(*str) {
  10.104 +		n++;
  10.105 +		str = dtx_utf8_next_char((char*)str);
  10.106 +	}
  10.107 +	return n;
  10.108 +}
  10.109 +
  10.110 +size_t dtx_utf8_from_char_code(int code, char *buf)
  10.111 +{
  10.112 +	size_t nbytes = 0;
  10.113 +	int i;
  10.114 +
  10.115 +	for(i=0; i<4; i++) {
  10.116 +		if(code <= utf8_lastcode[i]) {
  10.117 +			nbytes = i + 1;
  10.118 +			break;
  10.119 +		}
  10.120 +	}
  10.121 +
  10.122 +	if(!nbytes && buf) {
  10.123 +		for(i=0; i<(int)nbytes; i++) {
  10.124 +			int idx = nbytes - i - 1;
  10.125 +			int mask, shift, prefix;
  10.126 +
  10.127 +			if(idx > 0) {
  10.128 +				mask = CONT_MASK;
  10.129 +				shift = CONT_SHIFT;
  10.130 +				prefix = CONT_PREFIX;
  10.131 +			} else {
  10.132 +				mask = first_mask[nbytes];
  10.133 +				shift = first_shift[nbytes];
  10.134 +				prefix = prefix(nbytes);
  10.135 +			}
  10.136 +
  10.137 +			buf[idx] = (code & mask) | (prefix & ~mask);
  10.138 +			code >>= shift;
  10.139 +		}
  10.140 +	}
  10.141 +	return nbytes;
  10.142 +}
  10.143 +
  10.144 +size_t dtx_utf8_from_string(const wchar_t *str, char *buf)
  10.145 +{
  10.146 +	size_t nbytes = 0;
  10.147 +	char *ptr = buf;
  10.148 +
  10.149 +	while(*str) {
  10.150 +		int cbytes = dtx_utf8_from_char_code(*str++, ptr);
  10.151 +		if(ptr) {
  10.152 +			ptr += cbytes;
  10.153 +		}
  10.154 +		nbytes += cbytes;
  10.155 +	}
  10.156 +	return nbytes;
  10.157 +}
    11.1 --- a/libs/goatkit/theme.cc	Wed Sep 23 05:44:58 2015 +0300
    11.2 +++ b/libs/goatkit/theme.cc	Thu Sep 24 06:49:25 2015 +0300
    11.3 @@ -103,30 +103,34 @@
    11.4  {
    11.5  	unload();
    11.6  
    11.7 -	std::string fname = std::string(name) + ".gtheme";
    11.8 -	if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) {
    11.9 -		for(size_t i=0; i<search_paths.size(); i++) {
   11.10 -			std::string path = search_paths[i] + "/" + fname;
   11.11 -
   11.12 -			if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
   11.13 -				break;
   11.14 -			}
   11.15 -		}
   11.16 -
   11.17 -		// try the fallback paths
   11.18 -		if(!impl->so) {
   11.19 -			for(int i=0; fallback_paths[i]; i++) {
   11.20 -				std::string path = std::string(fallback_paths[i]) + "/" + fname;
   11.21 +	if(strcmp(name, "GOATKIT_THEME_BUILTIN") == 0) {
   11.22 +		impl->so = RTLD_DEFAULT;
   11.23 +	} else {
   11.24 +		std::string fname = std::string(name) + ".gtheme";
   11.25 +		if(!(impl->so = dlopen(fname.c_str(), RTLD_LAZY))) {
   11.26 +			for(size_t i=0; i<search_paths.size(); i++) {
   11.27 +				std::string path = search_paths[i] + "/" + fname;
   11.28  
   11.29  				if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
   11.30  					break;
   11.31  				}
   11.32  			}
   11.33 -		}
   11.34  
   11.35 -		if(!impl->so) {
   11.36 -			fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name);
   11.37 -			return false;
   11.38 +			// try the fallback paths
   11.39 +			if(!impl->so) {
   11.40 +				for(int i=0; fallback_paths[i]; i++) {
   11.41 +					std::string path = std::string(fallback_paths[i]) + "/" + fname;
   11.42 +
   11.43 +					if((impl->so = dlopen(path.c_str(), RTLD_LAZY))) {
   11.44 +						break;
   11.45 +					}
   11.46 +				}
   11.47 +			}
   11.48 +
   11.49 +			if(!impl->so) {
   11.50 +				fprintf(stderr, "%s: failed to load theme plugin: %s\n", __func__, name);
   11.51 +				return false;
   11.52 +			}
   11.53  		}
   11.54  	}
   11.55  
   11.56 @@ -144,7 +148,9 @@
   11.57  void Theme::unload()
   11.58  {
   11.59  	if(impl->so) {
   11.60 -		dlclose(impl->so);
   11.61 +		if(impl->so != RTLD_DEFAULT) {
   11.62 +			dlclose(impl->so);
   11.63 +		}
   11.64  		impl->so = 0;
   11.65  	}
   11.66  	impl->func_cache.clear();
   11.67 @@ -248,6 +254,9 @@
   11.68  
   11.69  static void *dlsym(void *so, const char *symbol)
   11.70  {
   11.71 +	if(so == RTLD_DEFAULT) {
   11.72 +		so = GetModuleHandle(0);
   11.73 +	}
   11.74  	return (void*)GetProcAddress(so, symbol);
   11.75  }
   11.76  #endif
    12.1 --- a/libs/goatkit/theme.h	Wed Sep 23 05:44:58 2015 +0300
    12.2 +++ b/libs/goatkit/theme.h	Thu Sep 24 06:49:25 2015 +0300
    12.3 @@ -18,6 +18,8 @@
    12.4  #ifndef THEME_H_
    12.5  #define THEME_H_
    12.6  
    12.7 +#define GOATKIT_THEME_BUILTIN	"GOATKIT_THEME_BUILTIN"
    12.8 +
    12.9  namespace goatkit {
   12.10  
   12.11  class Widget;
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/sdr/font.p.glsl	Thu Sep 24 06:49:25 2015 +0300
    13.3 @@ -0,0 +1,15 @@
    13.4 +#ifdef GL_ES
    13.5 +precision mediump float;
    13.6 +#endif
    13.7 +
    13.8 +uniform sampler2D tex;
    13.9 +uniform vec4 ucolor;
   13.10 +
   13.11 +//varying vec4 vcolor;
   13.12 +varying vec2 vtexcoord;
   13.13 +
   13.14 +void main()
   13.15 +{
   13.16 +	vec4 texel = texture2D(tex, vtexcoord);
   13.17 +	gl_FragColor = vec4(ucolor.xyz, texel.a * ucolor.a);
   13.18 +}
    14.1 --- a/sdr/ui.p.glsl	Wed Sep 23 05:44:58 2015 +0300
    14.2 +++ b/sdr/ui.p.glsl	Thu Sep 24 06:49:25 2015 +0300
    14.3 @@ -3,12 +3,13 @@
    14.4  #endif
    14.5  
    14.6  uniform sampler2D tex;
    14.7 +uniform vec4 ucolor;
    14.8  
    14.9 -varying vec4 vcolor;
   14.10 +//varying vec4 vcolor;
   14.11  varying vec2 vtexcoord;
   14.12  
   14.13  void main()
   14.14  {
   14.15  	vec4 texel = texture2D(tex, vtexcoord);
   14.16 -	gl_FragColor = vcolor * texel;
   14.17 +	gl_FragColor = texel * ucolor;
   14.18  }
    15.1 --- a/sdr/ui.v.glsl	Wed Sep 23 05:44:58 2015 +0300
    15.2 +++ b/sdr/ui.v.glsl	Thu Sep 24 06:49:25 2015 +0300
    15.3 @@ -1,15 +1,15 @@
    15.4 -attribute vec4 attr_vertex, attr_color;
    15.5 +attribute vec4 attr_vertex;//, attr_color;
    15.6  attribute vec2 attr_texcoord;
    15.7  
    15.8  uniform mat4 matrix_modelview, matrix_projection;
    15.9  
   15.10 -varying vec4 vcolor;
   15.11 +//varying vec4 vcolor;
   15.12  varying vec2 vtexcoord;
   15.13  
   15.14  void main()
   15.15  {
   15.16  	mat4 mvp = matrix_projection * matrix_modelview;
   15.17  	gl_Position = mvp * attr_vertex;
   15.18 -	vcolor = attr_color;
   15.19 +	//vcolor = attr_color;
   15.20  	vtexcoord = attr_texcoord;
   15.21  }
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/android/assman.c	Thu Sep 24 06:49:25 2015 +0300
    16.3 @@ -0,0 +1,63 @@
    16.4 +#include <fcntl.h>
    16.5 +#include <android/asset_manager.h>
    16.6 +#include "assman.h"
    16.7 +#include "native_glue.h"
    16.8 +#include "amain.h"
    16.9 +
   16.10 +ass_file *ass_fopen(const char *fname, const char *mode)
   16.11 +{
   16.12 +	AAsset *ass;
   16.13 +	unsigned int flags = 0;
   16.14 +	char prev = 0;
   16.15 +
   16.16 +	while(*mode) {
   16.17 +		switch(*mode) {
   16.18 +		case 'r':
   16.19 +			flags |= O_RDONLY;
   16.20 +			break;
   16.21 +
   16.22 +		case 'w':
   16.23 +			flags |= O_WRONLY;
   16.24 +			break;
   16.25 +
   16.26 +		case 'a':
   16.27 +			flags |= O_APPEND;
   16.28 +			break;
   16.29 +
   16.30 +		case '+':
   16.31 +			if(prev == 'w' || prev == 'a') {
   16.32 +				flags |= O_CREAT;
   16.33 +			}
   16.34 +			break;
   16.35 +
   16.36 +		default:
   16.37 +			break;
   16.38 +		}
   16.39 +		prev = *mode++;
   16.40 +	}
   16.41 +
   16.42 +	if(!(ass = AAssetManager_open(app->activity->assetManager, fname, flags))) {
   16.43 +		return 0;
   16.44 +	}
   16.45 +	return (ass_file*)ass;
   16.46 +}
   16.47 +
   16.48 +void ass_fclose(ass_file *fp)
   16.49 +{
   16.50 +	AAsset_close((AAsset*)fp);
   16.51 +}
   16.52 +
   16.53 +long ass_fseek(ass_file *fp, long offs, int whence)
   16.54 +{
   16.55 +	return AAsset_seek((AAsset*)fp, offs, whence);
   16.56 +}
   16.57 +
   16.58 +long ass_ftell(ass_file *fp)
   16.59 +{
   16.60 +	return AAsset_seek((AAsset*)fp, 0, SEEK_SET);
   16.61 +}
   16.62 +
   16.63 +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
   16.64 +{
   16.65 +	return AAsset_read((AAsset*)fp, buf, size * count) / size;
   16.66 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/assman.c	Thu Sep 24 06:49:25 2015 +0300
    17.3 @@ -0,0 +1,31 @@
    17.4 +#include <stdio.h>
    17.5 +#include "assman.h"
    17.6 +
    17.7 +int ass_fgetc(ass_file *fp)
    17.8 +{
    17.9 +	unsigned char c;
   17.10 +
   17.11 +	if(ass_fread(&c, 1, 1, fp) < 1) {
   17.12 +		return -1;
   17.13 +	}
   17.14 +	return (int)c;
   17.15 +}
   17.16 +
   17.17 +char *ass_fgets(char *s, int size, ass_file *fp)
   17.18 +{
   17.19 +	int i, c;
   17.20 +	char *ptr = s;
   17.21 +
   17.22 +	if(!size) return 0;
   17.23 +
   17.24 +	for(i=0; i<size - 1; i++) {
   17.25 +		if((c = ass_fgetc(fp)) == -1) {
   17.26 +			break;
   17.27 +		}
   17.28 +		*ptr++ = c;
   17.29 +
   17.30 +		if(c == '\n') break;
   17.31 +	}
   17.32 +	*ptr = 0;
   17.33 +	return ptr == s ? 0 : s;
   17.34 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/assman.h	Thu Sep 24 06:49:25 2015 +0300
    18.3 @@ -0,0 +1,27 @@
    18.4 +#ifndef ASSMAN_H_
    18.5 +#define ASSMAN_H_
    18.6 +
    18.7 +#include <stdlib.h>
    18.8 +
    18.9 +typedef void ass_file;
   18.10 +
   18.11 +#ifdef __cplusplus
   18.12 +extern "C" {
   18.13 +#endif
   18.14 +
   18.15 +ass_file *ass_fopen(const char *fname, const char *mode);
   18.16 +void ass_fclose(ass_file *fp);
   18.17 +long ass_fseek(ass_file *fp, long offs, int whence);
   18.18 +long ass_ftell(ass_file *fp);
   18.19 +
   18.20 +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp);
   18.21 +
   18.22 +/* convenience functions, derived from the above */
   18.23 +int ass_fgetc(ass_file *fp);
   18.24 +char *ass_fgets(char *s, int size, ass_file *fp);
   18.25 +
   18.26 +#ifdef __cplusplus
   18.27 +}
   18.28 +#endif
   18.29 +
   18.30 +#endif	/* ASSMAN_H_ */
    19.1 --- a/src/config.h	Wed Sep 23 05:44:58 2015 +0300
    19.2 +++ b/src/config.h	Thu Sep 24 06:49:25 2015 +0300
    19.3 @@ -6,6 +6,7 @@
    19.4  
    19.5  #if defined(TARGET_IPHONE_SIMULATOR) || defined(TARGET_OS_IPHONE)
    19.6  #define IPHONE
    19.7 +#define TARGET_IPHONE
    19.8  #endif
    19.9  
   19.10  #endif	/* __APPLE__ */
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/ios/assman.c	Thu Sep 24 06:49:25 2015 +0300
    20.3 @@ -0,0 +1,28 @@
    20.4 +#include <stdio.h>
    20.5 +#include "assman.h"
    20.6 +
    20.7 +ass_file *ass_fopen(const char *fname, const char *mode)
    20.8 +{
    20.9 +	return (ass_file*)fopen(fname, mode);
   20.10 +}
   20.11 +
   20.12 +void ass_fclose(ass_file *fp)
   20.13 +{
   20.14 +	fclose((FILE*)fp);
   20.15 +}
   20.16 +
   20.17 +long ass_fseek(ass_file *fp, long offs, int whence)
   20.18 +{
   20.19 +	fseek((FILE*)fp, offs, whence);
   20.20 +	return ftell((FILE*)fp);
   20.21 +}
   20.22 +
   20.23 +long ass_ftell(ass_file *fp)
   20.24 +{
   20.25 +	return ftell((FILE*)fp);
   20.26 +}
   20.27 +
   20.28 +size_t ass_fread(void *buf, size_t size, size_t count, ass_file *fp)
   20.29 +{
   20.30 +	return fread(buf, size, count, (FILE*)fp);
   20.31 +}
    21.1 --- a/src/istereo.c	Wed Sep 23 05:44:58 2015 +0300
    21.2 +++ b/src/istereo.c	Thu Sep 24 06:49:25 2015 +0300
    21.3 @@ -31,6 +31,7 @@
    21.4  #include "vmath.h"
    21.5  #include "config.h"
    21.6  #include "ui.h"
    21.7 +#include "drawtext.h"
    21.8  
    21.9  static void render(float t);
   21.10  static void draw_tunnel(float t);
   21.11 @@ -41,8 +42,9 @@
   21.12  static unsigned int get_shader_program(const char *vfile, const char *pfile);
   21.13  static float get_sec(void);
   21.14  
   21.15 -unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui;
   21.16 +unsigned int prog, prog_simple, prog_tunnel, prog_text, prog_color, prog_ui, prog_font;
   21.17  unsigned int tex, tex_stones, tex_normal, tex_text;
   21.18 +struct dtx_font *font;
   21.19  
   21.20  int view_xsz, view_ysz;
   21.21  
   21.22 @@ -80,6 +82,9 @@
   21.23  	if(!(prog_ui = get_shader_program("ui.v.glsl", "ui.p.glsl"))) {
   21.24  		return -1;
   21.25  	}
   21.26 +	if(!(prog_font = get_shader_program("ui.v.glsl", "font.p.glsl"))) {
   21.27 +		return -1;
   21.28 +	}
   21.29  
   21.30  	if(!(tex = load_texture(find_resource("tiles.jpg", 0, 0)))) {
   21.31  		return -1;
   21.32 @@ -94,6 +99,13 @@
   21.33  		return -1;
   21.34  	}
   21.35  
   21.36 +	if(!(font = dtx_open_font_glyphmap(find_resource("linux-libertine_s24.glyphmap", 0, 0)))) {
   21.37 +		fprintf(stderr, "failed to load font\n");
   21.38 +		return -1;
   21.39 +	}
   21.40 +	dtx_vertex_attribs(get_attrib_loc(prog_ui, "attr_vertex"), get_attrib_loc(prog_ui, "attr_texcoord"));
   21.41 +	dtx_use_font(font, 24);
   21.42 +
   21.43  	glEnable(GL_DEPTH_TEST);
   21.44  	glEnable(GL_CULL_FACE);
   21.45  
   21.46 @@ -114,6 +126,8 @@
   21.47  	free_program(prog_tunnel);
   21.48  	free_program(prog_color);
   21.49  	free_program(prog_ui);
   21.50 +	free_program(prog_font);
   21.51 +	dtx_close_font(font);
   21.52  }
   21.53  
   21.54  void redraw(void)
   21.55 @@ -184,6 +198,20 @@
   21.56  		render(tsec);
   21.57  	}
   21.58  
   21.59 +	/* TEST */
   21.60 +	/*bind_program(prog_ui);
   21.61 +
   21.62 +	gl_matrix_mode(GL_PROJECTION);
   21.63 +	gl_load_identity();
   21.64 +	gl_ortho(0, view_xsz, 0, view_ysz, -1, 1);
   21.65 +	gl_matrix_mode(GL_MODELVIEW);
   21.66 +	gl_load_identity();
   21.67 +	gl_apply_xform(prog_ui);
   21.68 +
   21.69 +	glDisable(GL_DEPTH_TEST);
   21.70 +	dtx_printf("hello world\n");
   21.71 +	glEnable(GL_DEPTH_TEST);*/
   21.72 +
   21.73  	assert(glGetError() == GL_NO_ERROR);
   21.74  }
   21.75  
    22.1 --- a/src/ui.cc	Wed Sep 23 05:44:58 2015 +0300
    22.2 +++ b/src/ui.cc	Thu Sep 24 06:49:25 2015 +0300
    22.3 @@ -1,3 +1,4 @@
    22.4 +#include <stdio.h>
    22.5  #include "ui.h"
    22.6  #include "goatkit/goatkit.h"
    22.7  #include "opengl.h"
    22.8 @@ -64,8 +65,11 @@
    22.9  	// load the theme
   22.10  	//goatkit::add_theme_path("themes/simple");
   22.11  
   22.12 -	//goatkit::theme = new goatkit::Theme;
   22.13 -	//goatkit::theme->load("simple");
   22.14 +	goatkit::theme = new goatkit::Theme;
   22.15 +	if(!goatkit::theme->load(GOATKIT_THEME_BUILTIN)) {
   22.16 +		fprintf(stderr, "no builitn theme\n");
   22.17 +		return -1;
   22.18 +	}
   22.19  
   22.20  	return 0;
   22.21  }
   22.22 @@ -91,25 +95,28 @@
   22.23  	gl_load_identity();
   22.24  	gl_scalef(2.0 / aspect, 2.0, 1);
   22.25  	gl_translatef(-1, -1, 0);
   22.26 -	gl_scalef(1, -1, 1);
   22.27  	gl_matrix_mode(GL_MODELVIEW);
   22.28  	gl_push_matrix();
   22.29  	gl_load_identity();
   22.30  
   22.31  	glDisable(GL_CULL_FACE);
   22.32  	glDisable(GL_DEPTH_TEST);
   22.33 +	glEnable(GL_BLEND);
   22.34 +	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   22.35  
   22.36 -	/*gl_begin(GL_QUADS);
   22.37 -	gl_color3f(1, 0, 0);
   22.38 +	set_uniform_float4(prog_ui, "ucolor", 0, 0, 0, 0.5);
   22.39 +
   22.40 +	gl_begin(GL_QUADS);
   22.41 +	//gl_color4f(0, 0, 0, 0.5);
   22.42  	gl_vertex3f(0, 0, 0);
   22.43 -	gl_vertex3f(0, 0.5, 0);
   22.44 -	gl_vertex3f(0.5 * aspect, 0.5, 0);
   22.45 -	gl_vertex3f(0.5 * aspect, 0, 0);
   22.46 +	gl_vertex3f(0, 1.0, 0);
   22.47 +	gl_vertex3f(1.0 * aspect, 1.0, 0);
   22.48 +	gl_vertex3f(1.0 * aspect, 0, 0);
   22.49  	gl_end();
   22.50 -	*/
   22.51  
   22.52  	scr.draw();
   22.53  
   22.54 +	glDisable(GL_BLEND);
   22.55  	glEnable(GL_CULL_FACE);
   22.56  	glEnable(GL_DEPTH_TEST);
   22.57  
   22.58 @@ -122,10 +129,10 @@
   22.59  
   22.60  void ui_button(int bn, int press, int x, int y)
   22.61  {
   22.62 -	scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, 1.0 - (float)y / (float)height);
   22.63 +	scr.sysev_mouse_button(bn, press != 0, (float)x / (float)width, (float)y / (float)height);
   22.64  }
   22.65  
   22.66  void ui_motion(int x, int y)
   22.67  {
   22.68 -	scr.sysev_mouse_motion((float)x / (float)width, 1.0 - (float)y / (float)height);
   22.69 +	scr.sysev_mouse_motion((float)x / (float)width, (float)y / (float)height);
   22.70  }
   22.71 \ No newline at end of file
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/uitheme.cc	Thu Sep 24 06:49:25 2015 +0300
    23.3 @@ -0,0 +1,101 @@
    23.4 +#include <map>
    23.5 +#include <string>
    23.6 +#include "goatkit/goatkit.h"
    23.7 +#include "opengl.h"
    23.8 +#include "drawtext.h"
    23.9 +#include "sdr.h"
   23.10 +
   23.11 +#define VIS_THRES	0.005
   23.12 +
   23.13 +using namespace goatkit;
   23.14 +
   23.15 +extern int view_xsz, view_ysz;
   23.16 +extern unsigned int prog_ui, prog_font;
   23.17 +extern struct dtx_font *font;
   23.18 +
   23.19 +static void draw_label(const Widget *w);
   23.20 +static void draw_text(float x, float y, const char *text);
   23.21 +
   23.22 +static struct {
   23.23 +	const char *name;
   23.24 +	WidgetDrawFunc func;
   23.25 +} widget_funcs[] = {
   23.26 +	{ "label", draw_label },
   23.27 +	{0, 0}
   23.28 +};
   23.29 +
   23.30 +static std::map<std::string, WidgetDrawFunc> funcmap;
   23.31 +
   23.32 +extern "C" WidgetDrawFunc get_widget_func(const char *name)
   23.33 +{
   23.34 +	static bool initialized;
   23.35 +
   23.36 +	if(!initialized) {
   23.37 +		for(int i=0; widget_funcs[i].func; i++) {
   23.38 +			funcmap[widget_funcs[i].name] = widget_funcs[i].func;
   23.39 +		}
   23.40 +		initialized = true;
   23.41 +	}
   23.42 +	return funcmap[name];
   23.43 +}
   23.44 +
   23.45 +static void begin_drawing(const Widget *w)
   23.46 +{
   23.47 +	Vec2 pos = w->get_position();
   23.48 +
   23.49 +	glEnable(GL_BLEND);
   23.50 +	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   23.51 +
   23.52 +	gl_matrix_mode(GL_MODELVIEW);
   23.53 +	gl_push_matrix();
   23.54 +	gl_load_identity();
   23.55 +	gl_translatef(pos.x, pos.y, 0);
   23.56 +}
   23.57 +
   23.58 +static void end_drawing(const Widget *w)
   23.59 +{
   23.60 +	gl_matrix_mode(GL_MODELVIEW);
   23.61 +	gl_pop_matrix();
   23.62 +}
   23.63 +
   23.64 +static void draw_label(const Widget *w)
   23.65 +{
   23.66 +	Vec2 pos = w->get_position();
   23.67 +	float vis = w->get_visibility();
   23.68 +	if(vis < VIS_THRES) return;
   23.69 +
   23.70 +	begin_drawing(w);
   23.71 +	draw_text(pos.x, pos.y, w->get_text());
   23.72 +	end_drawing(w);
   23.73 +}
   23.74 +
   23.75 +static void draw_text(float x, float y, const char *text)
   23.76 +{
   23.77 +	struct dtx_glyphmap *gmap = dtx_get_font_glyphmap_idx(font, 0);
   23.78 +	dtx_use_font(font, dtx_get_glyphmap_ptsize(gmap));
   23.79 +
   23.80 +	float aspect = (float)view_xsz / (float)view_ysz;
   23.81 +	float virt_xsz = 420.0 * aspect;
   23.82 +	float virt_ysz = 420.0;
   23.83 +
   23.84 +	gl_matrix_mode(GL_PROJECTION);
   23.85 +	gl_push_matrix();
   23.86 +	gl_load_identity();
   23.87 +	gl_ortho(0, virt_xsz, 0, virt_ysz, -1, 1);
   23.88 +
   23.89 +	gl_matrix_mode(GL_MODELVIEW);
   23.90 +	gl_push_matrix();
   23.91 +	gl_load_identity();
   23.92 +	gl_translatef(x * virt_xsz, y * virt_ysz, 0);
   23.93 +
   23.94 +	bind_program(prog_font);
   23.95 +	set_uniform_float4(prog_font, "ucolor", 1.0, 1.0, 1.0, 1.0);
   23.96 +	gl_apply_xform(prog_ui);
   23.97 +
   23.98 +	dtx_string(text);
   23.99 +
  23.100 +	gl_matrix_mode(GL_PROJECTION);
  23.101 +	gl_pop_matrix();
  23.102 +	gl_matrix_mode(GL_MODELVIEW);
  23.103 +	gl_pop_matrix();
  23.104 +}
  23.105 \ No newline at end of file