libdrawtext

changeset 72:9fd4bf11cc1e

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Mar 2013 06:06:26 +0200
parents e0eb231ca9ed aca73aa1944f
children 850335344428
files
diffstat 7 files changed, 275 insertions(+), 26 deletions(-) [+]
line diff
     1.1 --- a/examples/Makefile	Mon Aug 27 05:04:19 2012 +0300
     1.2 +++ b/examples/Makefile	Mon Mar 18 06:06:26 2013 +0200
     1.3 @@ -12,6 +12,7 @@
     1.4  	cd linlibertine; tar xzvf ../LinLibertineTTF_5.1.3_2011_06_21.tgz
     1.5  	rm -f LinLibertineTTF_5.1.3_2011_06_21.tgz
     1.6  	cp linlibertine/LinLibertine_R.ttf $@
     1.7 +	rm -rf linlibertine
     1.8  
     1.9  fonts/sazanami-mincho.ttf:
    1.10  	mkdir -p fonts
    1.11 @@ -19,6 +20,7 @@
    1.12  	tar xjvf sazanami-20040629.tar.bz2
    1.13  	rm -f sazanami-20040629.tar.bz2
    1.14  	cp sazanami-20040629/sazanami-mincho.ttf $@
    1.15 +	rm -rf sazanami-20040629
    1.16  
    1.17  fonts/klingon.ttf:
    1.18  	mkdir -p fonts
    1.19 @@ -26,3 +28,4 @@
    1.20  	unzip -o tlh_2D00_pIqaD_2D00_US.zip
    1.21  	rm -f tlh_2D00_pIqaD_2D00_US.zip
    1.22  	cp tlh-pIqaD-US/pIqaD.ttf $@
    1.23 +	rm -rf tlh-pIqaD-US
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/libdrawtext.sln	Mon Mar 18 06:06:26 2013 +0200
     2.3 @@ -0,0 +1,20 @@
     2.4 +
     2.5 +Microsoft Visual Studio Solution File, Format Version 10.00
     2.6 +# Visual C++ Express 2008
     2.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libdrawtext", "libdrawtext.vcproj", "{F6241CAB-984D-457D-A7EA-E66A57889490}"
     2.8 +EndProject
     2.9 +Global
    2.10 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    2.11 +		Debug|Win32 = Debug|Win32
    2.12 +		Release|Win32 = Release|Win32
    2.13 +	EndGlobalSection
    2.14 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    2.15 +		{F6241CAB-984D-457D-A7EA-E66A57889490}.Debug|Win32.ActiveCfg = Debug|Win32
    2.16 +		{F6241CAB-984D-457D-A7EA-E66A57889490}.Debug|Win32.Build.0 = Debug|Win32
    2.17 +		{F6241CAB-984D-457D-A7EA-E66A57889490}.Release|Win32.ActiveCfg = Release|Win32
    2.18 +		{F6241CAB-984D-457D-A7EA-E66A57889490}.Release|Win32.Build.0 = Release|Win32
    2.19 +	EndGlobalSection
    2.20 +	GlobalSection(SolutionProperties) = preSolution
    2.21 +		HideSolutionNode = FALSE
    2.22 +	EndGlobalSection
    2.23 +EndGlobal
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/libdrawtext.vcproj	Mon Mar 18 06:06:26 2013 +0200
     3.3 @@ -0,0 +1,185 @@
     3.4 +<?xml version="1.0" encoding="Windows-1252"?>
     3.5 +<VisualStudioProject
     3.6 +	ProjectType="Visual C++"
     3.7 +	Version="9.00"
     3.8 +	Name="libdrawtext"
     3.9 +	ProjectGUID="{F6241CAB-984D-457D-A7EA-E66A57889490}"
    3.10 +	RootNamespace="libdrawtext"
    3.11 +	Keyword="Win32Proj"
    3.12 +	TargetFrameworkVersion="196613"
    3.13 +	>
    3.14 +	<Platforms>
    3.15 +		<Platform
    3.16 +			Name="Win32"
    3.17 +		/>
    3.18 +	</Platforms>
    3.19 +	<ToolFiles>
    3.20 +	</ToolFiles>
    3.21 +	<Configurations>
    3.22 +		<Configuration
    3.23 +			Name="Debug|Win32"
    3.24 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
    3.25 +			IntermediateDirectory="$(ConfigurationName)"
    3.26 +			ConfigurationType="4"
    3.27 +			CharacterSet="1"
    3.28 +			>
    3.29 +			<Tool
    3.30 +				Name="VCPreBuildEventTool"
    3.31 +			/>
    3.32 +			<Tool
    3.33 +				Name="VCCustomBuildTool"
    3.34 +			/>
    3.35 +			<Tool
    3.36 +				Name="VCXMLDataGeneratorTool"
    3.37 +			/>
    3.38 +			<Tool
    3.39 +				Name="VCWebServiceProxyGeneratorTool"
    3.40 +			/>
    3.41 +			<Tool
    3.42 +				Name="VCMIDLTool"
    3.43 +			/>
    3.44 +			<Tool
    3.45 +				Name="VCCLCompilerTool"
    3.46 +				Optimization="0"
    3.47 +				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
    3.48 +				MinimalRebuild="true"
    3.49 +				BasicRuntimeChecks="3"
    3.50 +				RuntimeLibrary="3"
    3.51 +				UsePrecompiledHeader="0"
    3.52 +				WarningLevel="3"
    3.53 +				DebugInformationFormat="4"
    3.54 +				DisableSpecificWarnings="4996"
    3.55 +			/>
    3.56 +			<Tool
    3.57 +				Name="VCManagedResourceCompilerTool"
    3.58 +			/>
    3.59 +			<Tool
    3.60 +				Name="VCResourceCompilerTool"
    3.61 +			/>
    3.62 +			<Tool
    3.63 +				Name="VCPreLinkEventTool"
    3.64 +			/>
    3.65 +			<Tool
    3.66 +				Name="VCLibrarianTool"
    3.67 +				AdditionalDependencies="freetype.lib opengl32.lib"
    3.68 +			/>
    3.69 +			<Tool
    3.70 +				Name="VCALinkTool"
    3.71 +			/>
    3.72 +			<Tool
    3.73 +				Name="VCXDCMakeTool"
    3.74 +			/>
    3.75 +			<Tool
    3.76 +				Name="VCBscMakeTool"
    3.77 +			/>
    3.78 +			<Tool
    3.79 +				Name="VCFxCopTool"
    3.80 +			/>
    3.81 +			<Tool
    3.82 +				Name="VCPostBuildEventTool"
    3.83 +			/>
    3.84 +		</Configuration>
    3.85 +		<Configuration
    3.86 +			Name="Release|Win32"
    3.87 +			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
    3.88 +			IntermediateDirectory="$(ConfigurationName)"
    3.89 +			ConfigurationType="4"
    3.90 +			CharacterSet="1"
    3.91 +			WholeProgramOptimization="1"
    3.92 +			>
    3.93 +			<Tool
    3.94 +				Name="VCPreBuildEventTool"
    3.95 +			/>
    3.96 +			<Tool
    3.97 +				Name="VCCustomBuildTool"
    3.98 +			/>
    3.99 +			<Tool
   3.100 +				Name="VCXMLDataGeneratorTool"
   3.101 +			/>
   3.102 +			<Tool
   3.103 +				Name="VCWebServiceProxyGeneratorTool"
   3.104 +			/>
   3.105 +			<Tool
   3.106 +				Name="VCMIDLTool"
   3.107 +			/>
   3.108 +			<Tool
   3.109 +				Name="VCCLCompilerTool"
   3.110 +				Optimization="2"
   3.111 +				EnableIntrinsicFunctions="true"
   3.112 +				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
   3.113 +				RuntimeLibrary="2"
   3.114 +				EnableFunctionLevelLinking="true"
   3.115 +				UsePrecompiledHeader="0"
   3.116 +				WarningLevel="3"
   3.117 +				DebugInformationFormat="3"
   3.118 +				DisableSpecificWarnings="4996"
   3.119 +			/>
   3.120 +			<Tool
   3.121 +				Name="VCManagedResourceCompilerTool"
   3.122 +			/>
   3.123 +			<Tool
   3.124 +				Name="VCResourceCompilerTool"
   3.125 +			/>
   3.126 +			<Tool
   3.127 +				Name="VCPreLinkEventTool"
   3.128 +			/>
   3.129 +			<Tool
   3.130 +				Name="VCLibrarianTool"
   3.131 +				AdditionalDependencies="freetype.lib opengl32.lib"
   3.132 +			/>
   3.133 +			<Tool
   3.134 +				Name="VCALinkTool"
   3.135 +			/>
   3.136 +			<Tool
   3.137 +				Name="VCXDCMakeTool"
   3.138 +			/>
   3.139 +			<Tool
   3.140 +				Name="VCBscMakeTool"
   3.141 +			/>
   3.142 +			<Tool
   3.143 +				Name="VCFxCopTool"
   3.144 +			/>
   3.145 +			<Tool
   3.146 +				Name="VCPostBuildEventTool"
   3.147 +			/>
   3.148 +		</Configuration>
   3.149 +	</Configurations>
   3.150 +	<References>
   3.151 +	</References>
   3.152 +	<Files>
   3.153 +		<Filter
   3.154 +			Name="Source Files"
   3.155 +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
   3.156 +			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
   3.157 +			>
   3.158 +			<File
   3.159 +				RelativePath=".\src\drawgl.c"
   3.160 +				>
   3.161 +			</File>
   3.162 +			<File
   3.163 +				RelativePath=".\src\font.c"
   3.164 +				>
   3.165 +			</File>
   3.166 +			<File
   3.167 +				RelativePath=".\src\utf8.c"
   3.168 +				>
   3.169 +			</File>
   3.170 +		</Filter>
   3.171 +		<Filter
   3.172 +			Name="Header Files"
   3.173 +			Filter="h;hpp;hxx;hm;inl;inc;xsd"
   3.174 +			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
   3.175 +			>
   3.176 +			<File
   3.177 +				RelativePath=".\src\drawtext.h"
   3.178 +				>
   3.179 +			</File>
   3.180 +			<File
   3.181 +				RelativePath=".\src\drawtext_impl.h"
   3.182 +				>
   3.183 +			</File>
   3.184 +		</Filter>
   3.185 +	</Files>
   3.186 +	<Globals>
   3.187 +	</Globals>
   3.188 +</VisualStudioProject>
     4.1 --- a/src/drawgl.c	Mon Aug 27 05:04:19 2012 +0300
     4.2 +++ b/src/drawgl.c	Mon Mar 18 06:06:26 2013 +0200
     4.3 @@ -16,11 +16,18 @@
     4.4  along with this program.  If not, see <http://www.gnu.org/licenses/>.
     4.5  */
     4.6  #ifndef NO_OPENGL
     4.7 +#include <stdarg.h>
     4.8  #include <math.h>
     4.9  #include <ctype.h>
    4.10  
    4.11  #include <stdlib.h>
    4.12  
    4.13 +#ifndef _MSC_VER
    4.14 +#include <alloca.h>
    4.15 +#else
    4.16 +#include <malloc.h>
    4.17 +#endif
    4.18 +
    4.19  #ifdef TARGET_IPHONE
    4.20  #include <OpenGLES/ES2/gl.h>
    4.21  #else
    4.22 @@ -117,9 +124,31 @@
    4.23  	dtx_flush();
    4.24  }
    4.25  
    4.26 +static const char *put_char(const char *str, float *pos_x, float *pos_y, int *should_flush)
    4.27 +{
    4.28 +	struct dtx_glyphmap *gmap;
    4.29 +	float px, py;
    4.30 +	int code = dtx_utf8_char_code(str);
    4.31 +	str = dtx_utf8_next_char((char*)str);
    4.32 +
    4.33 +	if(buf_mode == DTX_LBF && code == '\n') {
    4.34 +		*should_flush = 1;
    4.35 +	}
    4.36 +
    4.37 +	px = *pos_x;
    4.38 +	py = *pos_y;
    4.39 +
    4.40 +	if((gmap = dtx_proc_char(code, pos_x, pos_y))) {
    4.41 +		int idx = code - gmap->cstart;
    4.42 +
    4.43 +		set_glyphmap_texture(gmap);
    4.44 +		add_glyph(gmap->glyphs + idx, px, py);
    4.45 +	}
    4.46 +	return str;
    4.47 +}
    4.48 +
    4.49  void dtx_string(const char *str)
    4.50  {
    4.51 -	struct dtx_glyphmap *gmap;
    4.52  	int should_flush = buf_mode == DTX_NBF;
    4.53  	float pos_x = 0.0f;
    4.54  	float pos_y = 0.0f;
    4.55 @@ -129,23 +158,7 @@
    4.56  	}
    4.57  
    4.58  	while(*str) {
    4.59 -		float px, py;
    4.60 -		int code = dtx_utf8_char_code(str);
    4.61 -		str = dtx_utf8_next_char((char*)str);
    4.62 -
    4.63 -		if(buf_mode == DTX_LBF && code == '\n') {
    4.64 -			should_flush = 1;
    4.65 -		}
    4.66 -
    4.67 -		px = pos_x;
    4.68 -		py = pos_y;
    4.69 -
    4.70 -		if((gmap = dtx_proc_char(code, &pos_x, &pos_y))) {
    4.71 -			int idx = code - gmap->cstart;
    4.72 -
    4.73 -			set_glyphmap_texture(gmap);
    4.74 -			add_glyph(gmap->glyphs + idx, px, py);
    4.75 -		}
    4.76 +		str = put_char(str, &pos_x, &pos_y, &should_flush);
    4.77  	}
    4.78  
    4.79  	if(should_flush) {
    4.80 @@ -153,6 +166,32 @@
    4.81  	}
    4.82  }
    4.83  
    4.84 +void dtx_printf(const char *fmt, ...)
    4.85 +{
    4.86 +	va_list ap;
    4.87 +	int buf_size;
    4.88 +	char *buf, tmp;
    4.89 +
    4.90 +	if(!dtx_font) {
    4.91 +		return;
    4.92 +	}
    4.93 +
    4.94 +	va_start(ap, fmt);
    4.95 +	buf_size = vsnprintf(&tmp, 0, fmt, ap);
    4.96 +	va_end(ap);
    4.97 +
    4.98 +	if(buf_size == -1) {
    4.99 +		buf_size = 512;
   4.100 +	}
   4.101 +
   4.102 +	buf = alloca(buf_size + 1);
   4.103 +	va_start(ap, fmt);
   4.104 +	vsnprintf(buf, buf_size + 1, fmt, ap);
   4.105 +	va_end(ap);
   4.106 +
   4.107 +	dtx_string(buf);
   4.108 +}
   4.109 +
   4.110  static void qvertex(struct vertex *v, float x, float y, float s, float t)
   4.111  {
   4.112  	v->x = x;
     5.1 --- a/src/drawtext.h	Mon Aug 27 05:04:19 2012 +0300
     5.2 +++ b/src/drawtext.h	Mon Mar 18 06:06:26 2013 +0200
     5.3 @@ -116,6 +116,8 @@
     5.4  /* draws a utf-8 string starting at the origin. \n \r and \t are handled appropriately. */
     5.5  void dtx_string(const char *str);
     5.6  
     5.7 +void dtx_printf(const char *fmt, ...);
     5.8 +
     5.9  /* render any pending glyphs (see dtx_draw_buffering) */
    5.10  void dtx_flush(void);
    5.11  
     6.1 --- a/src/drawtext_impl.h	Mon Aug 27 05:04:19 2012 +0300
     6.2 +++ b/src/drawtext_impl.h	Mon Mar 18 06:06:26 2013 +0200
     6.3 @@ -61,7 +61,7 @@
     6.4  
     6.5  
     6.6  #define fperror(str) \
     6.7 -	fprintf(stderr, "%s: %s: %s\n", __func__, (str), strerror(errno))
     6.8 +	fprintf(stderr, "%s: %s: %s\n", __FUNCTION__, (str), strerror(errno))
     6.9  
    6.10  int dtx_gl_init(void);
    6.11  
     7.1 --- a/src/font.c	Mon Aug 27 05:04:19 2012 +0300
     7.2 +++ b/src/font.c	Mon Mar 18 06:06:26 2013 +0200
     7.3 @@ -331,12 +331,12 @@
     7.4  
     7.5  		if(line[0] == '#') {
     7.6  			struct glyph *g;
     7.7 -			int c;
     7.8 -			float x, y, xsz, ysz, res;
     7.9 +			int c, res;
    7.10 +			float x, y, xsz, ysz;
    7.11  
    7.12  			res = sscanf(line + 1, "%d: %fx%f+%f+%f\n", &c, &xsz, &ysz, &x, &y);
    7.13  			if(res != 5) {
    7.14 -				fprintf(stderr, "%s: invalid glyph info line\n", __func__);
    7.15 +				fprintf(stderr, "%s: invalid glyph info line\n", __FUNCTION__);
    7.16  				goto err;
    7.17  			}
    7.18  
    7.19 @@ -362,14 +362,14 @@
    7.20  			switch(hdr_lines) {
    7.21  			case 0:
    7.22  				if(0[line] != 'P' || 1[line] != '6') {
    7.23 -					fprintf(stderr, "%s: invalid file format (magic)\n", __func__);
    7.24 +					fprintf(stderr, "%s: invalid file format (magic)\n", __FUNCTION__);
    7.25  					goto err;
    7.26  				}
    7.27  				break;
    7.28  
    7.29  			case 1:
    7.30  				if(sscanf(line, "%d %d", &gmap->xsz, &gmap->ysz) != 2) {
    7.31 -					fprintf(stderr, "%s: invalid file format (dim)\n", __func__);
    7.32 +					fprintf(stderr, "%s: invalid file format (dim)\n", __FUNCTION__);
    7.33  					goto err;
    7.34  				}
    7.35  				break;
    7.36 @@ -379,7 +379,7 @@
    7.37  					char *endp;
    7.38  					max_pixval = strtol(line, &endp, 10);
    7.39  					if(endp == line) {
    7.40 -						fprintf(stderr, "%s: invalid file format (maxval)\n", __func__);
    7.41 +						fprintf(stderr, "%s: invalid file format (maxval)\n", __FUNCTION__);
    7.42  						goto err;
    7.43  					}
    7.44  				}
    7.45 @@ -442,7 +442,7 @@
    7.46  	int res;
    7.47  
    7.48  	if(!(fp = fopen(fname, "wb"))) {
    7.49 -		fprintf(stderr, "%s: failed to open file: %s: %s\n", __func__, fname, strerror(errno));
    7.50 +		fprintf(stderr, "%s: failed to open file: %s: %s\n", __FUNCTION__, fname, strerror(errno));
    7.51  		return -1;
    7.52  	}
    7.53  	res = dtx_save_glyphmap_stream(fp, gmap);